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

Side by Side 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: Update comments. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_GFX_RENDER_TEXT_H_ 5 #ifndef UI_GFX_RENDER_TEXT_H_
6 #define UI_GFX_RENDER_TEXT_H_ 6 #define UI_GFX_RENDER_TEXT_H_
7 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 bool insert_mode() const { return insert_mode_; } 164 bool insert_mode() const { return insert_mode_; }
165 void toggle_insert_mode() { insert_mode_ = !insert_mode_; } 165 void toggle_insert_mode() { insert_mode_ = !insert_mode_; }
166 166
167 bool focused() const { return focused_; } 167 bool focused() const { return focused_; }
168 void set_focused(bool focused) { focused_ = focused; } 168 void set_focused(bool focused) { focused_ = focused; }
169 169
170 const StyleRange& default_style() const { return default_style_; } 170 const StyleRange& default_style() const { return default_style_; }
171 void set_default_style(StyleRange style) { default_style_ = style; } 171 void set_default_style(StyleRange style) { default_style_ = style; }
172 172
173 const Rect& display_rect() const { return display_rect_; } 173 const Rect& display_rect() const { return display_rect_; }
174 virtual void set_display_rect(const Rect& r); 174 virtual void SetDisplayRect(const Rect& r);
175
176 const Point& display_offset() const { return display_offset_; }
177 175
178 // This cursor position corresponds to SelectionModel::selection_end. In 176 // This cursor position corresponds to SelectionModel::selection_end. In
179 // addition to representing the selection end, it's also where logical text 177 // addition to representing the selection end, it's also where logical text
180 // edits take place, and doesn't necessarily correspond to 178 // edits take place, and doesn't necessarily correspond to
181 // SelectionModel::caret_pos. 179 // SelectionModel::caret_pos.
182 size_t GetCursorPosition() const; 180 size_t GetCursorPosition() const;
183 void SetCursorPosition(const size_t position); 181 void SetCursorPosition(const size_t position);
184 182
185 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { 183 void SetCaretPlacement(SelectionModel::CaretPlacement placement) {
186 selection_model_.set_caret_placement(placement); 184 selection_model_.set_caret_placement(placement);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 232
235 // Get the width of the entire string. 233 // Get the width of the entire string.
236 virtual int GetStringWidth(); 234 virtual int GetStringWidth();
237 235
238 virtual void Draw(Canvas* canvas); 236 virtual void Draw(Canvas* canvas);
239 237
240 // Gets the SelectionModel from a visual point in local coordinates. 238 // Gets the SelectionModel from a visual point in local coordinates.
241 virtual SelectionModel FindCursorPosition(const Point& point); 239 virtual SelectionModel FindCursorPosition(const Point& point);
242 240
243 // Get the visual bounds containing the logical substring within |from| to 241 // Get the visual bounds containing the logical substring within |from| to
244 // |to|. These bounds could be visually discontinuous if the logical 242 // |to|. These bounds could be visually discontinuous if the substring is
245 // selection range is split by an odd number of LTR/RTL level change. 243 // split by a LTR/RTL level change. These bounds are in local coordinates, but
246 virtual std::vector<Rect> GetSubstringBounds( 244 // may be outside the visible region if the text is longer than the textfield.
247 size_t from, size_t to) const; 245 // Subsequent text, cursor, or bounds changes may invalidate returned values.
246 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to);
248 247
249 // Get the visual bounds describing the cursor at |selection|. These bounds 248 // Get the visual bounds of a cursor at |selection|. These bounds typically
250 // typically represent a vertical line, but if |insert_mode| is true they 249 // represent a vertical line, but if |insert_mode| is true they contain the
251 // contain the bounds of the associated glyph. 250 // bounds of the associated glyph. These bounds are in local coordinates, but
251 // may be outside the visible region if the text is longer than the textfield.
252 // Subsequent text, cursor, or bounds changes may invalidate returned values.
252 virtual Rect GetCursorBounds(const SelectionModel& selection, 253 virtual Rect GetCursorBounds(const SelectionModel& selection,
253 bool insert_mode); 254 bool insert_mode);
254 255
255 // Compute cursor_bounds_ and update display_offset_ when necessary. Cache 256 // Compute the current cursor bounds, panning the text to show the cursor in
256 // the values for later use and return cursor_bounds_. 257 // the display rect if necessary. These bounds are in local coordinates.
257 const Rect& CursorBounds(); 258 // Subsequent text, cursor, or bounds changes may invalidate returned values.
259 const Rect& GetUpdatedCursorBounds();
258 260
259 protected: 261 protected:
260 RenderText(); 262 RenderText();
261 263
262 void set_cursor_bounds_valid(bool valid) { cursor_bounds_valid_ = valid; } 264 const Point& GetUpdatedDisplayOffset();
265
266 void set_cached_bounds_and_offset_valid(bool valid) {
267 cached_bounds_and_offset_valid_ = valid;
268 }
263 269
264 const StyleRanges& style_ranges() const { return style_ranges_; } 270 const StyleRanges& style_ranges() const { return style_ranges_; }
265 271
266 // Get the selection model that visually neighbors |position| by |break_type|. 272 // Get the selection model that visually neighbors |position| by |break_type|.
267 // The returned value represents a cursor/caret position without a selection. 273 // The returned value represents a cursor/caret position without a selection.
268 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, 274 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current,
269 BreakType break_type); 275 BreakType break_type);
270 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, 276 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current,
271 BreakType break_type); 277 BreakType break_type);
272 278
(...skipping 10 matching lines...) Expand all
283 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); 289 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle);
284 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); 290 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle);
285 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); 291 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange);
286 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); 292 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust);
287 293
288 // Clear out |style_ranges_|. 294 // Clear out |style_ranges_|.
289 void ClearStyleRanges(); 295 void ClearStyleRanges();
290 296
291 bool IsPositionAtWordSelectionBoundary(size_t pos); 297 bool IsPositionAtWordSelectionBoundary(size_t pos);
292 298
293 void UpdateCursorBoundsAndDisplayOffset(); 299 // Update the cached bounds and display offset to ensure that the current
300 // cursor is within the visible display area.
301 void UpdateCachedBoundsAndOffset();
294 302
295 // Logical UTF-16 string data to be drawn. 303 // Logical UTF-16 string data to be drawn.
296 string16 text_; 304 string16 text_;
297 305
298 // Logical selection range and visual cursor position. 306 // Logical selection range and visual cursor position.
299 SelectionModel selection_model_; 307 SelectionModel selection_model_;
300 308
301 // The cached cursor bounds. 309 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds.
302 Rect cursor_bounds_; 310 Rect cursor_bounds_;
303 // cursor_bounds_ is computed when needed and cached afterwards. And it is
304 // invalidated in operations such as SetCursorPosition, SetSelection, Font
305 // related style change, and other operations that trigger re-layout.
306 bool cursor_bounds_valid_;
307 311
308 // The cursor visibility and insert mode. 312 // The cursor visibility and insert mode.
309 bool cursor_visible_; 313 bool cursor_visible_;
310 bool insert_mode_; 314 bool insert_mode_;
311 315
312 // The focus state of the text. 316 // The focus state of the text.
313 bool focused_; 317 bool focused_;
314 318
315 // Composition text range. 319 // Composition text range.
316 ui::Range composition_range_; 320 ui::Range composition_range_;
317 321
318 // List of style ranges. Elements in the list never overlap each other. 322 // List of style ranges. Elements in the list never overlap each other.
319 StyleRanges style_ranges_; 323 StyleRanges style_ranges_;
320 // The default text style. 324 // The default text style.
321 StyleRange default_style_; 325 StyleRange default_style_;
322 326
323 // The local display area for rendering the text. 327 // The local display area for rendering the text.
324 Rect display_rect_; 328 Rect display_rect_;
325 // The offset for the text to be drawn, relative to the display area. 329 // The offset for the text to be drawn, relative to the display area.
330 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value).
326 Point display_offset_; 331 Point display_offset_;
327 332
333 // The cached bounds and offset are invalidated by operations such as
334 // SetCursorPosition, SetSelectionModel, Font related style change, and other
335 // operations that adjust the visible text bounds.
336 bool cached_bounds_and_offset_valid_;
337
328 DISALLOW_COPY_AND_ASSIGN(RenderText); 338 DISALLOW_COPY_AND_ASSIGN(RenderText);
329 }; 339 };
330 340
331 } // namespace gfx 341 } // namespace gfx
332 342
333 #endif // UI_GFX_RENDER_TEXT_H_ 343 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698