| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 Font font; | 43 Font font; |
| 44 SkColor foreground; | 44 SkColor foreground; |
| 45 bool strike; | 45 bool strike; |
| 46 bool underline; | 46 bool underline; |
| 47 ui::Range range; | 47 ui::Range range; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 typedef std::vector<StyleRange> StyleRanges; | 50 typedef std::vector<StyleRange> StyleRanges; |
| 51 | 51 |
| 52 // TODO(msw): Distinguish between logical character and glyph? | 52 // TODO(msw): Distinguish between logical character stops and glyph stops? |
| 53 // CHARACTER_BREAK cursor movements should stop at neighboring characters. |
| 54 // WORD_BREAK cursor movements should stop at the nearest word boundaries. |
| 55 // LINE_BREAK cursor movements should stop at the text ends as shown on screen. |
| 53 enum BreakType { | 56 enum BreakType { |
| 54 CHARACTER_BREAK, | 57 CHARACTER_BREAK, |
| 55 WORD_BREAK, | 58 WORD_BREAK, |
| 56 LINE_BREAK, | 59 LINE_BREAK, |
| 57 }; | 60 }; |
| 58 | 61 |
| 59 // TODO(xji): publish bidi-editing guide line and replace the place holder. | 62 // TODO(xji): publish bidi-editing guide line and replace the place holder. |
| 60 // SelectionModel is used to represent the logical selection and visual | 63 // SelectionModel is used to represent the logical selection and visual |
| 61 // position of cursor. | 64 // position of cursor. |
| 62 // | 65 // |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 size_t GetCursorPosition() const; | 182 size_t GetCursorPosition() const; |
| 180 void SetCursorPosition(const size_t position); | 183 void SetCursorPosition(const size_t position); |
| 181 | 184 |
| 182 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { | 185 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { |
| 183 selection_model_.set_caret_placement(placement); | 186 selection_model_.set_caret_placement(placement); |
| 184 } | 187 } |
| 185 | 188 |
| 186 // Moves the cursor left or right. Cursor movement is visual, meaning that | 189 // Moves the cursor left or right. Cursor movement is visual, meaning that |
| 187 // left and right are relative to screen, not the directionality of the text. | 190 // left and right are relative to screen, not the directionality of the text. |
| 188 // If |select| is false, the selection range is emptied at the new position. | 191 // If |select| is false, the selection range is emptied at the new position. |
| 189 // If |break_type| is CHARACTER_BREAK, move to the neighboring character. | |
| 190 // If |break_type| is WORD_BREAK, move to the nearest word boundary. | |
| 191 // If |break_type| is LINE_BREAK, move to text edge as shown on screen. | |
| 192 void MoveCursorLeft(BreakType break_type, bool select); | 192 void MoveCursorLeft(BreakType break_type, bool select); |
| 193 void MoveCursorRight(BreakType break_type, bool select); | 193 void MoveCursorRight(BreakType break_type, bool select); |
| 194 | 194 |
| 195 // Set the selection_model_ to the value of |selection|. | 195 // Set the selection_model_ to the value of |selection|. |
| 196 // Returns true if the cursor position or selection range changed. | 196 // Returns true if the cursor position or selection range changed. |
| 197 bool MoveCursorTo(const SelectionModel& selection); | 197 bool MoveCursorTo(const SelectionModel& selection); |
| 198 | 198 |
| 199 // Move the cursor to the position associated with the clicked point. | 199 // Move the cursor to the position associated with the clicked point. |
| 200 // If |select| is false, the selection range is emptied at the new position. | 200 // If |select| is false, the selection range is emptied at the new position. |
| 201 bool MoveCursorTo(const Point& point, bool select); | 201 bool MoveCursorTo(const Point& point, bool select); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // the values for later use and return cursor_bounds_. | 256 // the values for later use and return cursor_bounds_. |
| 257 const Rect& CursorBounds(); | 257 const Rect& CursorBounds(); |
| 258 | 258 |
| 259 protected: | 259 protected: |
| 260 RenderText(); | 260 RenderText(); |
| 261 | 261 |
| 262 void set_cursor_bounds_valid(bool valid) { cursor_bounds_valid_ = valid; } | 262 void set_cursor_bounds_valid(bool valid) { cursor_bounds_valid_ = valid; } |
| 263 | 263 |
| 264 const StyleRanges& style_ranges() const { return style_ranges_; } | 264 const StyleRanges& style_ranges() const { return style_ranges_; } |
| 265 | 265 |
| 266 // Get the cursor position that visually neighbors |position|. | 266 // Get the selection model that visually neighbors |position| by |break_type|. |
| 267 // If |move_by_word| is true, return the neighboring word delimiter position. | 267 // The returned value represents a cursor/caret position without a selection. |
| 268 virtual SelectionModel GetLeftCursorPosition(const SelectionModel& current, | 268 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, |
| 269 bool move_by_word); | 269 BreakType break_type); |
| 270 virtual SelectionModel GetRightCursorPosition(const SelectionModel& current, | 270 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, |
| 271 bool move_by_word); | 271 BreakType break_type); |
| 272 |
| 273 // Get the logical index of the grapheme preceeding the argument |position|. |
| 274 virtual size_t GetIndexOfPreviousGrapheme(size_t position) const; |
| 272 | 275 |
| 273 // Apply composition style (underline) to composition range and selection | 276 // Apply composition style (underline) to composition range and selection |
| 274 // style (foreground) to selection range. | 277 // style (foreground) to selection range. |
| 275 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; | 278 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; |
| 276 | 279 |
| 277 private: | 280 private: |
| 278 friend class RenderTextTest; | 281 friend class RenderTextTest; |
| 279 | 282 |
| 280 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 283 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
| 281 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 284 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 Rect display_rect_; | 324 Rect display_rect_; |
| 322 // The offset for the text to be drawn, relative to the display area. | 325 // The offset for the text to be drawn, relative to the display area. |
| 323 Point display_offset_; | 326 Point display_offset_; |
| 324 | 327 |
| 325 DISALLOW_COPY_AND_ASSIGN(RenderText); | 328 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 326 }; | 329 }; |
| 327 | 330 |
| 328 } // namespace gfx | 331 } // namespace gfx |
| 329 | 332 |
| 330 #endif // UI_GFX_RENDER_TEXT_H_ | 333 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |