Index: ui/gfx/render_text.h |
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h |
index d90be42165ae22d362f459396a28d4da5303b61f..7d66cb8d5dc87f934140b63f72bcd4bf151e2bad 100644 |
--- a/ui/gfx/render_text.h |
+++ b/ui/gfx/render_text.h |
@@ -171,9 +171,7 @@ class UI_EXPORT RenderText { |
void set_default_style(StyleRange style) { default_style_ = style; } |
const Rect& display_rect() const { return display_rect_; } |
- virtual void set_display_rect(const Rect& r); |
- |
- const Point& display_offset() const { return display_offset_; } |
+ virtual void SetDisplayRect(const Rect& r); |
// This cursor position corresponds to SelectionModel::selection_end. In |
// addition to representing the selection end, it's also where logical text |
@@ -242,24 +240,30 @@ class UI_EXPORT RenderText { |
// Get the visual bounds containing the logical substring within |from| to |
// |to|. These bounds could be visually discontinuous if the logical |
- // selection range is split by an odd number of LTR/RTL level change. |
+ // selection range is split by an odd number of LTR/RTL level change. These |
+ // bounds are offset by the text's display rect and display offset. |
virtual std::vector<Rect> GetSubstringBounds( |
- size_t from, size_t to) const; |
+ size_t from, size_t to); |
// Get the visual bounds describing the cursor at |selection|. These bounds |
// typically represent a vertical line, but if |insert_mode| is true they |
- // contain the bounds of the associated glyph. |
+ // contain the bounds of the associated glyph. These bounds are offset by the |
+ // text's display rect and display offset. |
virtual Rect GetCursorBounds(const SelectionModel& selection, |
bool insert_mode); |
- // Compute cursor_bounds_ and update display_offset_ when necessary. Cache |
- // the values for later use and return cursor_bounds_. |
- const Rect& CursorBounds(); |
+ // Get the current cursor bounds, updating the cached rect if necessary. These |
+ // bounds are offset by the text's display rect and display offset. |
+ const Rect& GetUpdatedCursorBounds(); |
protected: |
RenderText(); |
- void set_cursor_bounds_valid(bool valid) { cursor_bounds_valid_ = valid; } |
+ const Point& GetUpdatedDisplayOffset(); |
+ |
+ void set_cached_bounds_and_offset_valid(bool valid) { |
+ cached_bounds_and_offset_valid_ = valid; |
+ } |
const StyleRanges& style_ranges() const { return style_ranges_; } |
@@ -290,7 +294,9 @@ class UI_EXPORT RenderText { |
bool IsPositionAtWordSelectionBoundary(size_t pos); |
- void UpdateCursorBoundsAndDisplayOffset(); |
+ // Update the cached bounds and display offset to ensure that the current |
+ // cursor is within the visible display area. |
+ void UpdateCachedBoundsAndOffset(); |
// Logical UTF-16 string data to be drawn. |
string16 text_; |
@@ -298,12 +304,8 @@ class UI_EXPORT RenderText { |
// Logical selection range and visual cursor position. |
SelectionModel selection_model_; |
- // The cached cursor bounds. |
+ // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. |
Rect cursor_bounds_; |
- // cursor_bounds_ is computed when needed and cached afterwards. And it is |
- // invalidated in operations such as SetCursorPosition, SetSelection, Font |
- // related style change, and other operations that trigger re-layout. |
- bool cursor_bounds_valid_; |
// The cursor visibility and insert mode. |
bool cursor_visible_; |
@@ -323,8 +325,14 @@ class UI_EXPORT RenderText { |
// The local display area for rendering the text. |
Rect display_rect_; |
// The offset for the text to be drawn, relative to the display area. |
+ // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). |
Point display_offset_; |
+ // The cached bounds and offset are invalidated by operations such as |
+ // SetCursorPosition, SetSelection, Font related style change, and other |
+ // operations that adjust the visible text bounds. |
+ bool cached_bounds_and_offset_valid_; |
+ |
DISALLOW_COPY_AND_ASSIGN(RenderText); |
}; |