diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 17:45:59 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 17:45:59 +0000 |
commit | f0ed8a2f0e95ab61f755f3f4c10b0cdd6007fe26 (patch) | |
tree | 2ef39f64782098f912dcb6221943aa1f9ec52d9a /ui/gfx/render_text.h | |
parent | b39c9b201b7a950c647cd9d79494b74692dfeb56 (diff) | |
download | chromium_src-f0ed8a2f0e95ab61f755f3f4c10b0cdd6007fe26.zip chromium_src-f0ed8a2f0e95ab61f755f3f4c10b0cdd6007fe26.tar.gz chromium_src-f0ed8a2f0e95ab61f755f3f4c10b0cdd6007fe26.tar.bz2 |
Add support for horizontal text alignment to RenderText.
Also adds a |cursor_enabled| setting to RenderText to control whether the cursor bounds should be added to the string width for the purposes of layout and gating the |display_offset_| behavior.
BUG=110595
TEST=Moving cursor outside of omnibox bounds under Aura in both LTR and RTL mode - view should pan and follow the cursor. Resizing the window when there is a pan offset, which should consume any new empty space. Also programmatically setting the new alignment modes via some unreleased code and inspecting the results.
Review URL: http://codereview.chromium.org/9252021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118856 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text.h')
-rw-r--r-- | ui/gfx/render_text.h | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h index 47471d3..21fe484 100644 --- a/ui/gfx/render_text.h +++ b/ui/gfx/render_text.h @@ -81,6 +81,13 @@ enum BreakType { LINE_BREAK, }; +// Horizontal text alignment styles. +enum HorizontalAlignment { + ALIGN_LEFT, + ALIGN_CENTER, + ALIGN_RIGHT, +}; + // VisualCursorDirection and LogicalCursorDirection represent directions of // motion of the cursor in BiDi text. The combinations that make sense are: // @@ -112,6 +119,11 @@ class UI_EXPORT RenderText { const string16& text() const { return text_; } void SetText(const string16& text); + HorizontalAlignment horizontal_alignment() const { + return horizontal_alignment_; + } + void SetHorizontalAlignment(HorizontalAlignment alignment); + const FontList& font_list() const { return font_list_; } void SetFontList(const FontList& font_list); @@ -123,6 +135,9 @@ class UI_EXPORT RenderText { const SelectionModel& selection_model() const { return selection_model_; } + bool cursor_enabled() const { return cursor_enabled_; } + void SetCursorEnabled(bool cursor_enabled); + bool cursor_visible() const { return cursor_visible_; } void set_cursor_visible(bool visible) { cursor_visible_ = visible; } @@ -312,21 +327,26 @@ class UI_EXPORT RenderText { // style (foreground) to selection range. void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges); + // Returns the text origin after applying text alignment and display offset. + Point GetTextOrigin(); + // Convert points from the text space to the view space and back. // Handles the display area, display offset, and the application LTR/RTL mode. Point ToTextPoint(const Point& point); Point ToViewPoint(const Point& point); + // Returns the width of content, which reserves room for the cursor if + // |cursor_enabled_| is true. + int GetContentWidth(); + + // Returns display offset based on current text alignment. + Point GetAlignmentOffset(); + // Returns the origin point for drawing text via Skia. Point GetOriginForSkiaDrawing(); - // Applies fade effects to |renderer| and returns a text drawing offset when - // fading the head would cause the text to change alignment. - // TODO(asvitkine): Applying right-alignment in this way doesn't work well - // with drawing the text selection and cursor. Instead, we - // should make RenderText support horizontal alignment - // explicitly. - int ApplyFadeEffects(internal::SkiaTextRenderer* renderer); + // Applies fade effects to |renderer|. + void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); private: friend class RenderTextTest; @@ -357,6 +377,9 @@ class UI_EXPORT RenderText { // Logical UTF-16 string data to be drawn. string16 text_; + // Horizontal alignment of the text with respect to |display_rect_|. + HorizontalAlignment horizontal_alignment_; + // A list of fonts used to render |text_|. FontList font_list_; @@ -366,6 +389,10 @@ class UI_EXPORT RenderText { // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. Rect cursor_bounds_; + // Specifies whether the cursor is enabled. If disabled, no space is reserved + // for the cursor when positioning text. + bool cursor_enabled_; + // The cursor visibility and insert mode. bool cursor_visible_; bool insert_mode_; |