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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // "abcFED|". | 83 // "abcFED|". |
84 // So, besides the logical selection start point and end point, we need extra | 84 // So, besides the logical selection start point and end point, we need extra |
85 // information to specify to which character and on which edge of the character | 85 // information to specify to which character and on which edge of the character |
86 // the visual cursor is bound to. For example, the visual cursor is bound to | 86 // the visual cursor is bound to. For example, the visual cursor is bound to |
87 // the trailing side of the 2nd character 'c' when pointing to right half of | 87 // the trailing side of the 2nd character 'c' when pointing to right half of |
88 // 'c'. And it is bound to the leading edge of the 3rd character 'D' when | 88 // 'c'. And it is bound to the leading edge of the 3rd character 'D' when |
89 // pointing to right of 'D'. | 89 // pointing to right of 'D'. |
90 class UI_EXPORT SelectionModel { | 90 class UI_EXPORT SelectionModel { |
91 public: | 91 public: |
92 enum CaretPlacement { | 92 enum CaretPlacement { |
93 // PREVIOUS_GRAPHEME_TRAILING means cursor is visually attached to the | |
94 // trailing edge of previous grapheme. | |
95 PREVIOUS_GRAPHEME_TRAILING, | |
96 LEADING, | 93 LEADING, |
97 TRAILING, | 94 TRAILING, |
98 }; | 95 }; |
99 | 96 |
100 SelectionModel(); | 97 SelectionModel(); |
101 explicit SelectionModel(size_t pos); | 98 explicit SelectionModel(size_t pos); |
| 99 SelectionModel(size_t start, size_t end); |
102 SelectionModel(size_t end, size_t pos, CaretPlacement status); | 100 SelectionModel(size_t end, size_t pos, CaretPlacement status); |
103 SelectionModel(size_t start, size_t end, size_t pos, CaretPlacement status); | 101 SelectionModel(size_t start, size_t end, size_t pos, CaretPlacement status); |
104 | 102 |
105 virtual ~SelectionModel(); | 103 virtual ~SelectionModel(); |
106 | 104 |
107 size_t selection_start() const { return selection_start_; } | 105 size_t selection_start() const { return selection_start_; } |
108 void set_selection_start(size_t pos) { selection_start_ = pos; } | 106 void set_selection_start(size_t pos) { selection_start_ = pos; } |
109 | 107 |
110 size_t selection_end() const { return selection_end_; } | 108 size_t selection_end() const { return selection_end_; } |
111 void set_selection_end(size_t pos) { selection_end_ = pos; } | 109 void set_selection_end(size_t pos) { selection_end_ = pos; } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 const StyleRanges& style_ranges() const { return style_ranges_; } | 268 const StyleRanges& style_ranges() const { return style_ranges_; } |
271 | 269 |
272 // Get the selection model that visually neighbors |position| by |break_type|. | 270 // Get the selection model that visually neighbors |position| by |break_type|. |
273 // The returned value represents a cursor/caret position without a selection. | 271 // The returned value represents a cursor/caret position without a selection. |
274 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, | 272 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, |
275 BreakType break_type); | 273 BreakType break_type); |
276 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, | 274 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, |
277 BreakType break_type); | 275 BreakType break_type); |
278 | 276 |
279 // Get the logical index of the grapheme preceeding the argument |position|. | 277 // Get the logical index of the grapheme preceeding the argument |position|. |
280 virtual size_t GetIndexOfPreviousGrapheme(size_t position) const; | 278 virtual size_t GetIndexOfPreviousGrapheme(size_t position); |
281 | 279 |
282 // Apply composition style (underline) to composition range and selection | 280 // Apply composition style (underline) to composition range and selection |
283 // style (foreground) to selection range. | 281 // style (foreground) to selection range. |
284 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; | 282 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; |
285 | 283 |
286 private: | 284 private: |
287 friend class RenderTextTest; | 285 friend class RenderTextTest; |
288 | 286 |
289 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 287 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
290 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 288 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // SetCursorPosition, SetSelectionModel, Font related style change, and other | 332 // SetCursorPosition, SetSelectionModel, Font related style change, and other |
335 // operations that adjust the visible text bounds. | 333 // operations that adjust the visible text bounds. |
336 bool cached_bounds_and_offset_valid_; | 334 bool cached_bounds_and_offset_valid_; |
337 | 335 |
338 DISALLOW_COPY_AND_ASSIGN(RenderText); | 336 DISALLOW_COPY_AND_ASSIGN(RenderText); |
339 }; | 337 }; |
340 | 338 |
341 } // namespace gfx | 339 } // namespace gfx |
342 | 340 |
343 #endif // UI_GFX_RENDER_TEXT_H_ | 341 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |