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

Side by Side Diff: ui/gfx/render_text.h

Issue 7841056: fix know issues in RenderText (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: fix a capitalization in break_iterator.h Created 9 years, 3 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 | « base/i18n/break_iterator.cc ('k') | 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 // Moves the cursor left or right. Cursor movement is visual, meaning that 187 // Moves the cursor left or right. Cursor movement is visual, meaning that
188 // left and right are relative to screen, not the directionality of the text. 188 // left and right are relative to screen, not the directionality of the text.
189 // If |select| is false, the selection start is moved to the same position. 189 // If |select| is false, the selection start is moved to the same position.
190 void MoveCursorLeft(BreakType break_type, bool select); 190 void MoveCursorLeft(BreakType break_type, bool select);
191 void MoveCursorRight(BreakType break_type, bool select); 191 void MoveCursorRight(BreakType break_type, bool select);
192 192
193 // Set the selection_model_ to the value of |selection|. 193 // Set the selection_model_ to the value of |selection|.
194 // The selection model components are modified if invalid. 194 // The selection model components are modified if invalid.
195 // Returns true if the cursor position or selection range changed. 195 // Returns true if the cursor position or selection range changed.
196 // TODO(xji): need to check the cursor is set at grapheme boundary. 196 // If |selectin_start_| or |selection_end_| or |caret_pos_| in
197 // |selection_model| is not a cursorable position (not on grapheme boundary),
198 // it is a NO-OP and returns false.
197 bool MoveCursorTo(const SelectionModel& selection_model); 199 bool MoveCursorTo(const SelectionModel& selection_model);
198 200
199 // Move the cursor to the position associated with the clicked point. 201 // Move the cursor to the position associated with the clicked point.
200 // If |select| is false, the selection start is moved to the same position. 202 // If |select| is false, the selection start is moved to the same position.
201 // Returns true if the cursor position or selection range changed. 203 // Returns true if the cursor position or selection range changed.
202 bool MoveCursorTo(const Point& point, bool select); 204 bool MoveCursorTo(const Point& point, bool select);
203 205
204 size_t GetSelectionStart() const { 206 size_t GetSelectionStart() const {
205 return selection_model_.selection_start(); 207 return selection_model_.selection_start();
206 } 208 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // may be outside the visible region if the text is longer than the textfield. 249 // may be outside the visible region if the text is longer than the textfield.
248 // Subsequent text, cursor, or bounds changes may invalidate returned values. 250 // Subsequent text, cursor, or bounds changes may invalidate returned values.
249 virtual Rect GetCursorBounds(const SelectionModel& selection, 251 virtual Rect GetCursorBounds(const SelectionModel& selection,
250 bool insert_mode); 252 bool insert_mode);
251 253
252 // Compute the current cursor bounds, panning the text to show the cursor in 254 // Compute the current cursor bounds, panning the text to show the cursor in
253 // the display rect if necessary. These bounds are in local coordinates. 255 // the display rect if necessary. These bounds are in local coordinates.
254 // Subsequent text, cursor, or bounds changes may invalidate returned values. 256 // Subsequent text, cursor, or bounds changes may invalidate returned values.
255 const Rect& GetUpdatedCursorBounds(); 257 const Rect& GetUpdatedCursorBounds();
256 258
259 // Get the logical index of the grapheme following the argument |position|.
260 virtual size_t GetIndexOfNextGrapheme(size_t position);
261
257 protected: 262 protected:
258 RenderText(); 263 RenderText();
259 264
260 const Point& GetUpdatedDisplayOffset(); 265 const Point& GetUpdatedDisplayOffset();
261 266
262 void set_cached_bounds_and_offset_valid(bool valid) { 267 void set_cached_bounds_and_offset_valid(bool valid) {
263 cached_bounds_and_offset_valid_ = valid; 268 cached_bounds_and_offset_valid_ = valid;
264 } 269 }
265 270
266 const StyleRanges& style_ranges() const { return style_ranges_; } 271 const StyleRanges& style_ranges() const { return style_ranges_; }
(...skipping 14 matching lines...) Expand all
281 virtual size_t GetIndexOfPreviousGrapheme(size_t position); 286 virtual size_t GetIndexOfPreviousGrapheme(size_t position);
282 287
283 // Get the visual bounds containing the logical substring within |from| to 288 // Get the visual bounds containing the logical substring within |from| to
284 // |to|. These bounds could be visually discontinuous if the substring is 289 // |to|. These bounds could be visually discontinuous if the substring is
285 // split by a LTR/RTL level change. These bounds are in local coordinates, but 290 // split by a LTR/RTL level change. These bounds are in local coordinates, but
286 // may be outside the visible region if the text is longer than the textfield. 291 // may be outside the visible region if the text is longer than the textfield.
287 // Subsequent text, cursor, or bounds changes may invalidate returned values. 292 // Subsequent text, cursor, or bounds changes may invalidate returned values.
288 // TODO(msw) Re-evaluate this function's necessity and signature. 293 // TODO(msw) Re-evaluate this function's necessity and signature.
289 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to); 294 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to);
290 295
296 // Return true if cursor can appear in front of the character at |position|,
297 // which means it is a grapheme boundary or the first character in the text.
298 virtual bool IsCursorablePosition(size_t position) = 0;
299
291 // Apply composition style (underline) to composition range and selection 300 // Apply composition style (underline) to composition range and selection
292 // style (foreground) to selection range. 301 // style (foreground) to selection range.
293 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; 302 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const;
294 303
295 // Convert points from the text space to the view space and back. 304 // Convert points from the text space to the view space and back.
296 // Handles the display area, display offset, and the application LTR/RTL mode. 305 // Handles the display area, display offset, and the application LTR/RTL mode.
297 Point ToTextPoint(const Point& point); 306 Point ToTextPoint(const Point& point);
298 Point ToViewPoint(const Point& point); 307 Point ToViewPoint(const Point& point);
299 308
300 private: 309 private:
301 friend class RenderTextTest; 310 friend class RenderTextTest;
302 311
303 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); 312 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle);
304 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); 313 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle);
305 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); 314 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange);
306 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); 315 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust);
307 316
317 // Return an index belonging to the |next| or previous logical grapheme.
318 // The return value is bounded by 0 and the text length, inclusive.
319 virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) = 0;
320
308 // Sets the selection model, the argument is assumed to be valid. 321 // Sets the selection model, the argument is assumed to be valid.
309 void SetSelectionModel(const SelectionModel& selection_model); 322 void SetSelectionModel(const SelectionModel& selection_model);
310 323
311 // Set the cursor to |position|, with the caret trailing the previous 324 // Set the cursor to |position|, with the caret trailing the previous
312 // grapheme, or if there is no previous grapheme, leading the cursor position. 325 // grapheme, or if there is no previous grapheme, leading the cursor position.
313 // If |select| is false, the selection start is moved to the same position. 326 // If |select| is false, the selection start is moved to the same position.
327 // If the |position| is not a cursorable position (not on grapheme boundary),
328 // it is a NO-OP.
314 void MoveCursorTo(size_t position, bool select); 329 void MoveCursorTo(size_t position, bool select);
315 330
316 bool IsPositionAtWordSelectionBoundary(size_t pos);
317
318 // Update the cached bounds and display offset to ensure that the current 331 // Update the cached bounds and display offset to ensure that the current
319 // cursor is within the visible display area. 332 // cursor is within the visible display area.
320 void UpdateCachedBoundsAndOffset(); 333 void UpdateCachedBoundsAndOffset();
321 334
322 // Returns the selection model of selection_start_. 335 // Returns the selection model of selection_start_.
323 // The returned value represents a cursor/caret position without a selection. 336 // The returned value represents a cursor/caret position without a selection.
324 SelectionModel GetSelectionModelForSelectionStart(); 337 SelectionModel GetSelectionModelForSelectionStart();
325 338
326 // Logical UTF-16 string data to be drawn. 339 // Logical UTF-16 string data to be drawn.
327 string16 text_; 340 string16 text_;
(...skipping 28 matching lines...) Expand all
356 // The cached bounds and offset are invalidated by changes to the cursor, 369 // The cached bounds and offset are invalidated by changes to the cursor,
357 // selection, font, and other operations that adjust the visible text bounds. 370 // selection, font, and other operations that adjust the visible text bounds.
358 bool cached_bounds_and_offset_valid_; 371 bool cached_bounds_and_offset_valid_;
359 372
360 DISALLOW_COPY_AND_ASSIGN(RenderText); 373 DISALLOW_COPY_AND_ASSIGN(RenderText);
361 }; 374 };
362 375
363 } // namespace gfx 376 } // namespace gfx
364 377
365 #endif // UI_GFX_RENDER_TEXT_H_ 378 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « base/i18n/break_iterator.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698