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

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

Issue 8044004: Clean up of SelectionModel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: add comment about 'next' in ReplaceTextInternal Created 9 years, 2 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 | « chrome/browser/ui/views/omnibox/omnibox_view_views.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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const Rect& display_rect() const { return display_rect_; } 93 const Rect& display_rect() const { return display_rect_; }
94 virtual void SetDisplayRect(const Rect& r); 94 virtual void SetDisplayRect(const Rect& r);
95 95
96 // This cursor position corresponds to SelectionModel::selection_end. In 96 // This cursor position corresponds to SelectionModel::selection_end. In
97 // addition to representing the selection end, it's also where logical text 97 // addition to representing the selection end, it's also where logical text
98 // edits take place, and doesn't necessarily correspond to 98 // edits take place, and doesn't necessarily correspond to
99 // SelectionModel::caret_pos. 99 // SelectionModel::caret_pos.
100 size_t GetCursorPosition() const; 100 size_t GetCursorPosition() const;
101 void SetCursorPosition(size_t position); 101 void SetCursorPosition(size_t position);
102 102
103 void SetCaretPlacement(SelectionModel::CaretPlacement placement) {
104 selection_model_.set_caret_placement(placement);
105 }
106
107 // Moves the cursor left or right. Cursor movement is visual, meaning that 103 // Moves the cursor left or right. Cursor movement is visual, meaning that
108 // left and right are relative to screen, not the directionality of the text. 104 // left and right are relative to screen, not the directionality of the text.
109 // If |select| is false, the selection start is moved to the same position. 105 // If |select| is false, the selection start is moved to the same position.
110 void MoveCursorLeft(BreakType break_type, bool select); 106 void MoveCursorLeft(BreakType break_type, bool select);
111 void MoveCursorRight(BreakType break_type, bool select); 107 void MoveCursorRight(BreakType break_type, bool select);
112 108
113 // Set the selection_model_ to the value of |selection|. 109 // Set the selection_model_ to the value of |selection|.
114 // The selection model components are modified if invalid. 110 // The selection model components are modified if invalid.
115 // Returns true if the cursor position or selection range changed. 111 // Returns true if the cursor position or selection range changed.
116 // If |selectin_start_| or |selection_end_| or |caret_pos_| in 112 // If |selectin_start_| or |selection_end_| or |caret_pos_| in
117 // |selection_model| is not a cursorable position (not on grapheme boundary), 113 // |selection_model| is not a cursorable position (not on grapheme boundary),
118 // it is a NO-OP and returns false. 114 // it is a NO-OP and returns false.
119 bool MoveCursorTo(const SelectionModel& selection_model); 115 bool MoveCursorTo(const SelectionModel& selection_model);
120 116
121 // Move the cursor to the position associated with the clicked point. 117 // Move the cursor to the position associated with the clicked point.
122 // If |select| is false, the selection start is moved to the same position. 118 // If |select| is false, the selection start is moved to the same position.
123 // Returns true if the cursor position or selection range changed. 119 // Returns true if the cursor position or selection range changed.
124 bool MoveCursorTo(const Point& point, bool select); 120 bool MoveCursorTo(const Point& point, bool select);
125 121
122 // Set the selection_model_ based on |range|.
123 // If the |range| start or end is greater than text length, it is modified
124 // to be the text length.
125 // If the |range| start or end is not a cursorable position (not on grapheme
126 // boundary), it is a NO-OP and returns false. Otherwise, returns true.
127 bool SelectRange(const ui::Range& range);
128
126 size_t GetSelectionStart() const { 129 size_t GetSelectionStart() const {
127 return selection_model_.selection_start(); 130 return selection_model_.selection_start();
128 } 131 }
129 size_t MinOfSelection() const { 132 size_t MinOfSelection() const {
130 return std::min(GetSelectionStart(), GetCursorPosition()); 133 return std::min(GetSelectionStart(), GetCursorPosition());
131 } 134 }
132 size_t MaxOfSelection() const { 135 size_t MaxOfSelection() const {
133 return std::max(GetSelectionStart(), GetCursorPosition()); 136 return std::max(GetSelectionStart(), GetCursorPosition());
134 } 137 }
135 bool EmptySelection() const { 138 bool EmptySelection() const {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // The cached bounds and offset are invalidated by changes to the cursor, 292 // The cached bounds and offset are invalidated by changes to the cursor,
290 // selection, font, and other operations that adjust the visible text bounds. 293 // selection, font, and other operations that adjust the visible text bounds.
291 bool cached_bounds_and_offset_valid_; 294 bool cached_bounds_and_offset_valid_;
292 295
293 DISALLOW_COPY_AND_ASSIGN(RenderText); 296 DISALLOW_COPY_AND_ASSIGN(RenderText);
294 }; 297 };
295 298
296 } // namespace gfx 299 } // namespace gfx
297 300
298 #endif // UI_GFX_RENDER_TEXT_H_ 301 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698