Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: ui/gfx/render_text.h

Issue 7466048: Fix RenderText cached bounds and offset logic; update clients. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Expand touch_selection_controller_impl_unittest textfield bounds to avoid unexpected text overrun. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | ui/gfx/render_text.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text.h
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index d90be42165ae22d362f459396a28d4da5303b61f..35c9b7babdd357dbd74d9bd651bcd20c05729888 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_;
@@ -300,10 +306,6 @@ class UI_EXPORT RenderText {
// The cached cursor bounds.
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_;
@@ -325,6 +327,11 @@ class UI_EXPORT RenderText {
// The offset for the text to be drawn, relative to the display area.
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);
};
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | ui/gfx/render_text.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698