Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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); |
|
msw
2011/09/09 23:03:24
Is it possible that the text could end with a non-
xji
2011/09/12 21:31:48
We do not allow that.
When I choose whether to use
| |
| 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 } |
| 207 size_t MinOfSelection() const { | 209 size_t MinOfSelection() const { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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); | |
| 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 |
| 308 // Sets the selection model, the argument is assumed to be valid. | 317 // Sets the selection model, the argument is assumed to be valid. |
| 309 void SetSelectionModel(const SelectionModel& selection_model); | 318 void SetSelectionModel(const SelectionModel& selection_model); |
| 310 | 319 |
| 311 // Set the cursor to |position|, with the caret trailing the previous | 320 // Set the cursor to |position|, with the caret trailing the previous |
| 312 // grapheme, or if there is no previous grapheme, leading the cursor position. | 321 // 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. | 322 // If |select| is false, the selection start is moved to the same position. |
| 323 // If the |position| is not a cursorable position (not on grapheme boundary), | |
| 324 // it is a NO-OP. | |
| 314 void MoveCursorTo(size_t position, bool select); | 325 void MoveCursorTo(size_t position, bool select); |
| 315 | 326 |
| 316 bool IsPositionAtWordSelectionBoundary(size_t pos); | |
| 317 | |
| 318 // Update the cached bounds and display offset to ensure that the current | 327 // Update the cached bounds and display offset to ensure that the current |
| 319 // cursor is within the visible display area. | 328 // cursor is within the visible display area. |
| 320 void UpdateCachedBoundsAndOffset(); | 329 void UpdateCachedBoundsAndOffset(); |
| 321 | 330 |
| 322 // Returns the selection model of selection_start_. | 331 // Returns the selection model of selection_start_. |
| 323 // The returned value represents a cursor/caret position without a selection. | 332 // The returned value represents a cursor/caret position without a selection. |
| 324 SelectionModel GetSelectionModelForSelectionStart(); | 333 SelectionModel GetSelectionModelForSelectionStart(); |
| 325 | 334 |
| 326 // Logical UTF-16 string data to be drawn. | 335 // Logical UTF-16 string data to be drawn. |
| 327 string16 text_; | 336 string16 text_; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 356 // The cached bounds and offset are invalidated by changes to the cursor, | 365 // The cached bounds and offset are invalidated by changes to the cursor, |
| 357 // selection, font, and other operations that adjust the visible text bounds. | 366 // selection, font, and other operations that adjust the visible text bounds. |
| 358 bool cached_bounds_and_offset_valid_; | 367 bool cached_bounds_and_offset_valid_; |
| 359 | 368 |
| 360 DISALLOW_COPY_AND_ASSIGN(RenderText); | 369 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 361 }; | 370 }; |
| 362 | 371 |
| 363 } // namespace gfx | 372 } // namespace gfx |
| 364 | 373 |
| 365 #endif // UI_GFX_RENDER_TEXT_H_ | 374 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |