Chromium Code Reviews| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, | 202 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, |
| 203 BreakType break_type); | 203 BreakType break_type); |
| 204 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, | 204 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, |
| 205 BreakType break_type); | 205 BreakType break_type); |
| 206 | 206 |
| 207 // Get the SelectionModels corresponding to visual text ends. | 207 // Get the SelectionModels corresponding to visual text ends. |
| 208 // The returned value represents a cursor/caret position without a selection. | 208 // The returned value represents a cursor/caret position without a selection. |
| 209 virtual SelectionModel LeftEndSelectionModel(); | 209 virtual SelectionModel LeftEndSelectionModel(); |
| 210 virtual SelectionModel RightEndSelectionModel(); | 210 virtual SelectionModel RightEndSelectionModel(); |
| 211 | 211 |
| 212 // Get the logical index of the grapheme preceeding the argument |position|. | |
| 213 virtual size_t GetIndexOfPreviousGrapheme(size_t position); | |
| 214 | |
| 215 // Get the visual bounds containing the logical substring within |from| to | 212 // Get the visual bounds containing the logical substring within |from| to |
| 216 // |to|. These bounds could be visually discontinuous if the substring is | 213 // |to|. These bounds could be visually discontinuous if the substring is |
| 217 // split by a LTR/RTL level change. These bounds are in local coordinates, but | 214 // split by a LTR/RTL level change. These bounds are in local coordinates, but |
| 218 // may be outside the visible region if the text is longer than the textfield. | 215 // may be outside the visible region if the text is longer than the textfield. |
| 219 // Subsequent text, cursor, or bounds changes may invalidate returned values. | 216 // Subsequent text, cursor, or bounds changes may invalidate returned values. |
| 220 // TODO(msw) Re-evaluate this function's necessity and signature. | |
| 221 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to); | 217 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to); |
|
Alexei Svitkine (slow)
2011/11/28 19:56:14
Maybe change the signature of this to:
virtual vo
xji
2011/11/29 01:37:02
Changed.
It is generally true that changing the si
| |
| 222 | 218 |
| 219 // Sets the selection model, the argument is assumed to be valid. | |
| 220 virtual void SetSelectionModel(const SelectionModel& selection_model); | |
| 221 | |
| 223 // Return true if cursor can appear in front of the character at |position|, | 222 // Return true if cursor can appear in front of the character at |position|, |
| 224 // which means it is a grapheme boundary or the first character in the text. | 223 // which means it is a grapheme boundary or the first character in the text. |
| 225 virtual bool IsCursorablePosition(size_t position) = 0; | 224 virtual bool IsCursorablePosition(size_t position) = 0; |
| 226 | 225 |
| 227 // Updates the layout so that the next draw request can correctly | 226 // Updates the layout so that the next draw request can correctly |
| 228 // render the text and its attributes. | 227 // render the text and its attributes. |
| 229 virtual void UpdateLayout() = 0; | 228 virtual void UpdateLayout() = 0; |
| 230 | 229 |
| 230 // Draw the text. | |
| 231 virtual void DrawVisualText(Canvas* canvas) = 0; | |
| 232 | |
| 233 // Get the logical index of the grapheme preceding the argument |position|. | |
| 234 size_t GetIndexOfPreviousGrapheme(size_t position); | |
| 235 | |
| 231 // Apply composition style (underline) to composition range and selection | 236 // Apply composition style (underline) to composition range and selection |
| 232 // style (foreground) to selection range. | 237 // style (foreground) to selection range. |
| 233 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; | 238 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; |
| 234 | 239 |
| 235 // Convert points from the text space to the view space and back. | 240 // Convert points from the text space to the view space and back. |
| 236 // Handles the display area, display offset, and the application LTR/RTL mode. | 241 // Handles the display area, display offset, and the application LTR/RTL mode. |
| 237 Point ToTextPoint(const Point& point); | 242 Point ToTextPoint(const Point& point); |
| 238 Point ToViewPoint(const Point& point); | 243 Point ToViewPoint(const Point& point); |
| 239 | 244 |
| 240 private: | 245 private: |
| 241 friend class RenderTextTest; | 246 friend class RenderTextTest; |
| 242 | 247 |
| 243 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 248 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
| 244 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 249 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
| 245 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); | 250 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); |
| 246 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); | 251 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); |
| 247 | 252 |
| 248 // Return an index belonging to the |next| or previous logical grapheme. | 253 // Return an index belonging to the |next| or previous logical grapheme. |
| 249 // The return value is bounded by 0 and the text length, inclusive. | 254 // The return value is bounded by 0 and the text length, inclusive. |
| 250 virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) = 0; | 255 virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) = 0; |
| 251 | 256 |
| 252 // Sets the selection model, the argument is assumed to be valid. | |
| 253 void SetSelectionModel(const SelectionModel& selection_model); | |
| 254 | |
| 255 // Set the cursor to |position|, with the caret trailing the previous | 257 // Set the cursor to |position|, with the caret trailing the previous |
| 256 // grapheme, or if there is no previous grapheme, leading the cursor position. | 258 // grapheme, or if there is no previous grapheme, leading the cursor position. |
| 257 // If |select| is false, the selection start is moved to the same position. | 259 // If |select| is false, the selection start is moved to the same position. |
| 258 // If the |position| is not a cursorable position (not on grapheme boundary), | 260 // If the |position| is not a cursorable position (not on grapheme boundary), |
| 259 // it is a NO-OP. | 261 // it is a NO-OP. |
| 260 void MoveCursorTo(size_t position, bool select); | 262 void MoveCursorTo(size_t position, bool select); |
| 261 | 263 |
| 262 // Update the cached bounds and display offset to ensure that the current | 264 // Update the cached bounds and display offset to ensure that the current |
| 263 // cursor is within the visible display area. | 265 // cursor is within the visible display area. |
| 264 void UpdateCachedBoundsAndOffset(); | 266 void UpdateCachedBoundsAndOffset(); |
| 265 | 267 |
| 268 // Draw the selection and cursor. | |
| 269 void DrawSelection(Canvas* canvas); | |
| 270 void DrawCursor(Canvas* canvas); | |
| 271 | |
| 266 // Logical UTF-16 string data to be drawn. | 272 // Logical UTF-16 string data to be drawn. |
| 267 string16 text_; | 273 string16 text_; |
| 268 | 274 |
| 269 // Logical selection range and visual cursor position. | 275 // Logical selection range and visual cursor position. |
| 270 SelectionModel selection_model_; | 276 SelectionModel selection_model_; |
| 271 | 277 |
| 272 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. | 278 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. |
| 273 Rect cursor_bounds_; | 279 Rect cursor_bounds_; |
| 274 | 280 |
| 275 // The cursor visibility and insert mode. | 281 // The cursor visibility and insert mode. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 296 // The cached bounds and offset are invalidated by changes to the cursor, | 302 // The cached bounds and offset are invalidated by changes to the cursor, |
| 297 // selection, font, and other operations that adjust the visible text bounds. | 303 // selection, font, and other operations that adjust the visible text bounds. |
| 298 bool cached_bounds_and_offset_valid_; | 304 bool cached_bounds_and_offset_valid_; |
| 299 | 305 |
| 300 DISALLOW_COPY_AND_ASSIGN(RenderText); | 306 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 301 }; | 307 }; |
| 302 | 308 |
| 303 } // namespace gfx | 309 } // namespace gfx |
| 304 | 310 |
| 305 #endif // UI_GFX_RENDER_TEXT_H_ | 311 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |