OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SELECTION_MODEL_H_ | 5 #ifndef UI_GFX_SELECTION_MODEL_H_ |
6 #define UI_GFX_SELECTION_MODEL_H_ | 6 #define UI_GFX_SELECTION_MODEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ui/base/range/range.h" | |
11 #include "ui/gfx/gfx_export.h" | 10 #include "ui/gfx/gfx_export.h" |
| 11 #include "ui/gfx/range/range.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 | 14 |
15 // VisualCursorDirection and LogicalCursorDirection represent directions of | 15 // VisualCursorDirection and LogicalCursorDirection represent directions of |
16 // motion of the cursor in BiDi text. The combinations that make sense are: | 16 // motion of the cursor in BiDi text. The combinations that make sense are: |
17 // | 17 // |
18 // base::i18n::TextDirection VisualCursorDirection LogicalCursorDirection | 18 // base::i18n::TextDirection VisualCursorDirection LogicalCursorDirection |
19 // LEFT_TO_RIGHT CURSOR_LEFT CURSOR_BACKWARD | 19 // LEFT_TO_RIGHT CURSOR_LEFT CURSOR_BACKWARD |
20 // LEFT_TO_RIGHT CURSOR_RIGHT CURSOR_FORWARD | 20 // LEFT_TO_RIGHT CURSOR_RIGHT CURSOR_FORWARD |
21 // RIGHT_TO_LEFT CURSOR_RIGHT CURSOR_BACKWARD | 21 // RIGHT_TO_LEFT CURSOR_RIGHT CURSOR_BACKWARD |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 public: | 60 public: |
61 // Create a default SelectionModel to be overwritten later. | 61 // Create a default SelectionModel to be overwritten later. |
62 SelectionModel(); | 62 SelectionModel(); |
63 // Create a SelectionModel representing a caret |position| without a | 63 // Create a SelectionModel representing a caret |position| without a |
64 // selection. The |affinity| is meaningful only when the caret is positioned | 64 // selection. The |affinity| is meaningful only when the caret is positioned |
65 // between bidi runs that are not visually contiguous: in that case, it | 65 // between bidi runs that are not visually contiguous: in that case, it |
66 // indicates the run to which the caret is attached for display purposes. | 66 // indicates the run to which the caret is attached for display purposes. |
67 SelectionModel(size_t position, LogicalCursorDirection affinity); | 67 SelectionModel(size_t position, LogicalCursorDirection affinity); |
68 // Create a SelectionModel representing a selection (which may be empty). | 68 // Create a SelectionModel representing a selection (which may be empty). |
69 // The caret position is the end of the range. | 69 // The caret position is the end of the range. |
70 SelectionModel(ui::Range selection, LogicalCursorDirection affinity); | 70 SelectionModel(gfx::Range selection, LogicalCursorDirection affinity); |
71 | 71 |
72 const ui::Range& selection() const { return selection_; } | 72 const gfx::Range& selection() const { return selection_; } |
73 size_t caret_pos() const { return selection_.end(); } | 73 size_t caret_pos() const { return selection_.end(); } |
74 LogicalCursorDirection caret_affinity() const { return caret_affinity_; } | 74 LogicalCursorDirection caret_affinity() const { return caret_affinity_; } |
75 | 75 |
76 bool operator==(const SelectionModel& sel) const; | 76 bool operator==(const SelectionModel& sel) const; |
77 bool operator!=(const SelectionModel& sel) const { return !(*this == sel); } | 77 bool operator!=(const SelectionModel& sel) const { return !(*this == sel); } |
78 | 78 |
79 std::string ToString() const; | 79 std::string ToString() const; |
80 | 80 |
81 private: | 81 private: |
82 friend class RenderText; | 82 friend class RenderText; |
83 | 83 |
84 // TODO(benrg): Generally the selection start should not be changed without | 84 // TODO(benrg): Generally the selection start should not be changed without |
85 // considering the effect on the caret affinity. This setter is exposed only | 85 // considering the effect on the caret affinity. This setter is exposed only |
86 // to RenderText to discourage misuse, and should probably be removed. | 86 // to RenderText to discourage misuse, and should probably be removed. |
87 void set_selection_start(size_t pos) { selection_.set_start(pos); } | 87 void set_selection_start(size_t pos) { selection_.set_start(pos); } |
88 | 88 |
89 // Logical selection. The logical caret position is the end of the selection. | 89 // Logical selection. The logical caret position is the end of the selection. |
90 ui::Range selection_; | 90 gfx::Range selection_; |
91 | 91 |
92 // The logical direction from the caret position (selection_.end()) to the | 92 // The logical direction from the caret position (selection_.end()) to the |
93 // character it is attached to for display purposes. This matters only when | 93 // character it is attached to for display purposes. This matters only when |
94 // the surrounding characters are not visually contiguous, which happens only | 94 // the surrounding characters are not visually contiguous, which happens only |
95 // in bidi text (and only at bidi run boundaries). The text is treated as | 95 // in bidi text (and only at bidi run boundaries). The text is treated as |
96 // though it was surrounded on both sides by runs in the dominant text | 96 // though it was surrounded on both sides by runs in the dominant text |
97 // direction. For example, supposing the dominant direction is LTR and the | 97 // direction. For example, supposing the dominant direction is LTR and the |
98 // logical text is "abcDEF", where DEF is right-to-left text, the visual | 98 // logical text is "abcDEF", where DEF is right-to-left text, the visual |
99 // cursor will display as follows: | 99 // cursor will display as follows: |
100 // caret position CURSOR_BACKWARD affinity CURSOR_FORWARD affinity | 100 // caret position CURSOR_BACKWARD affinity CURSOR_FORWARD affinity |
101 // 0 |abcFED |abcFED | 101 // 0 |abcFED |abcFED |
102 // 1 a|bcFED a|bcFED | 102 // 1 a|bcFED a|bcFED |
103 // 2 ab|cFED ab|cFED | 103 // 2 ab|cFED ab|cFED |
104 // 3 abc|FED abcFED| | 104 // 3 abc|FED abcFED| |
105 // 4 abcFE|D abcFE|D | 105 // 4 abcFE|D abcFE|D |
106 // 5 abcF|ED abcF|ED | 106 // 5 abcF|ED abcF|ED |
107 // 6 abc|FED abcFED| | 107 // 6 abc|FED abcFED| |
108 LogicalCursorDirection caret_affinity_; | 108 LogicalCursorDirection caret_affinity_; |
109 }; | 109 }; |
110 | 110 |
111 } // namespace gfx | 111 } // namespace gfx |
112 | 112 |
113 #endif // UI_GFX_SELECTION_MODEL_H_ | 113 #endif // UI_GFX_SELECTION_MODEL_H_ |
OLD | NEW |