| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 const string16& text() const { return text_; } | 153 const string16& text() const { return text_; } |
| 154 virtual void SetText(const string16& text); | 154 virtual void SetText(const string16& text); |
| 155 | 155 |
| 156 const SelectionModel& selection_model() const { return selection_model_; } | 156 const SelectionModel& selection_model() const { return selection_model_; } |
| 157 void SetSelectionModel(const SelectionModel& sel); | 157 void SetSelectionModel(const SelectionModel& sel); |
| 158 | 158 |
| 159 bool cursor_visible() const { return cursor_visible_; } | 159 bool cursor_visible() const { return cursor_visible_; } |
| 160 void set_cursor_visible(bool visible) { cursor_visible_ = visible; } | 160 void set_cursor_visible(bool visible) { cursor_visible_ = visible; } |
| 161 | 161 |
| 162 bool insert_mode() const { return insert_mode_; } | 162 bool insert_mode() const { return insert_mode_; } |
| 163 void toggle_insert_mode() { insert_mode_ = !insert_mode_; } | 163 void ToggleInsertMode(); |
| 164 | 164 |
| 165 bool focused() const { return focused_; } | 165 bool focused() const { return focused_; } |
| 166 void set_focused(bool focused) { focused_ = focused; } | 166 void set_focused(bool focused) { focused_ = focused; } |
| 167 | 167 |
| 168 const StyleRange& default_style() const { return default_style_; } | 168 const StyleRange& default_style() const { return default_style_; } |
| 169 void set_default_style(StyleRange style) { default_style_ = style; } | 169 void set_default_style(StyleRange style) { default_style_ = style; } |
| 170 | 170 |
| 171 const Rect& display_rect() const { return display_rect_; } | 171 const Rect& display_rect() const { return display_rect_; } |
| 172 virtual void SetDisplayRect(const Rect& r); | 172 virtual void SetDisplayRect(const Rect& r); |
| 173 | 173 |
| 174 // This cursor position corresponds to SelectionModel::selection_end. In | 174 // This cursor position corresponds to SelectionModel::selection_end. In |
| 175 // addition to representing the selection end, it's also where logical text | 175 // addition to representing the selection end, it's also where logical text |
| 176 // edits take place, and doesn't necessarily correspond to | 176 // edits take place, and doesn't necessarily correspond to |
| 177 // SelectionModel::caret_pos. | 177 // SelectionModel::caret_pos. |
| 178 size_t GetCursorPosition() const; | 178 size_t GetCursorPosition() const; |
| 179 void SetCursorPosition(const size_t position); | 179 void SetCursorPosition(size_t position); |
| 180 | 180 |
| 181 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { | 181 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { |
| 182 selection_model_.set_caret_placement(placement); | 182 selection_model_.set_caret_placement(placement); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Moves the cursor left or right. Cursor movement is visual, meaning that | 185 // Moves the cursor left or right. Cursor movement is visual, meaning that |
| 186 // left and right are relative to screen, not the directionality of the text. | 186 // left and right are relative to screen, not the directionality of the text. |
| 187 // If |select| is false, the selection range is emptied at the new position. | 187 // If |select| is false, the selection start is moved to the same position. |
| 188 void MoveCursorLeft(BreakType break_type, bool select); | 188 void MoveCursorLeft(BreakType break_type, bool select); |
| 189 void MoveCursorRight(BreakType break_type, bool select); | 189 void MoveCursorRight(BreakType break_type, bool select); |
| 190 | 190 |
| 191 // Set the selection_model_ to the value of |selection|. | 191 // Set the selection_model_ to the value of |selection|. |
| 192 // Returns true if the cursor position or selection range changed. | 192 // Returns true if the cursor position or selection range changed. |
| 193 bool MoveCursorTo(const SelectionModel& selection); | 193 bool MoveCursorTo(const SelectionModel& selection); |
| 194 | 194 |
| 195 // Move the cursor to the position associated with the clicked point. | 195 // Move the cursor to the position associated with the clicked point. |
| 196 // If |select| is false, the selection range is emptied at the new position. | 196 // If |select| is false, the selection start is moved to the same position. |
| 197 // Returns true if the cursor position or selection range changed. |
| 197 bool MoveCursorTo(const Point& point, bool select); | 198 bool MoveCursorTo(const Point& point, bool select); |
| 198 | 199 |
| 199 size_t GetSelectionStart() const { | 200 size_t GetSelectionStart() const { |
| 200 return selection_model_.selection_start(); | 201 return selection_model_.selection_start(); |
| 201 } | 202 } |
| 202 size_t MinOfSelection() const { | 203 size_t MinOfSelection() const { |
| 203 return std::min(GetSelectionStart(), GetCursorPosition()); | 204 return std::min(GetSelectionStart(), GetCursorPosition()); |
| 204 } | 205 } |
| 205 size_t MaxOfSelection() const { | 206 size_t MaxOfSelection() const { |
| 206 return std::max(GetSelectionStart(), GetCursorPosition()); | 207 return std::max(GetSelectionStart(), GetCursorPosition()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; | 283 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; |
| 283 | 284 |
| 284 private: | 285 private: |
| 285 friend class RenderTextTest; | 286 friend class RenderTextTest; |
| 286 | 287 |
| 287 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 288 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
| 288 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 289 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
| 289 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); | 290 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); |
| 290 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); | 291 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); |
| 291 | 292 |
| 292 // Clear out |style_ranges_|. | 293 // Set the cursor to |position|, with the caret trailing the previous |
| 293 void ClearStyleRanges(); | 294 // grapheme, or if there is no previous grapheme, leading the cursor position. |
| 295 // If |select| is false, the selection start is moved to the same position. |
| 296 void MoveCursorTo(size_t position, bool select); |
| 294 | 297 |
| 295 bool IsPositionAtWordSelectionBoundary(size_t pos); | 298 bool IsPositionAtWordSelectionBoundary(size_t pos); |
| 296 | 299 |
| 297 // Update the cached bounds and display offset to ensure that the current | 300 // Update the cached bounds and display offset to ensure that the current |
| 298 // cursor is within the visible display area. | 301 // cursor is within the visible display area. |
| 299 void UpdateCachedBoundsAndOffset(); | 302 void UpdateCachedBoundsAndOffset(); |
| 300 | 303 |
| 301 // Logical UTF-16 string data to be drawn. | 304 // Logical UTF-16 string data to be drawn. |
| 302 string16 text_; | 305 string16 text_; |
| 303 | 306 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 332 // SetCursorPosition, SetSelectionModel, Font related style change, and other | 335 // SetCursorPosition, SetSelectionModel, Font related style change, and other |
| 333 // operations that adjust the visible text bounds. | 336 // operations that adjust the visible text bounds. |
| 334 bool cached_bounds_and_offset_valid_; | 337 bool cached_bounds_and_offset_valid_; |
| 335 | 338 |
| 336 DISALLOW_COPY_AND_ASSIGN(RenderText); | 339 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 337 }; | 340 }; |
| 338 | 341 |
| 339 } // namespace gfx | 342 } // namespace gfx |
| 340 | 343 |
| 341 #endif // UI_GFX_RENDER_TEXT_H_ | 344 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |