| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 // Gets the SelectionModel from a visual point in local coordinates. | 166 // Gets the SelectionModel from a visual point in local coordinates. |
| 167 virtual SelectionModel FindCursorPosition(const Point& point); | 167 virtual SelectionModel FindCursorPosition(const Point& point); |
| 168 | 168 |
| 169 // Get the visual bounds of a cursor at |selection|. These bounds typically | 169 // Get the visual bounds of a cursor at |selection|. These bounds typically |
| 170 // represent a vertical line, but if |insert_mode| is true they contain the | 170 // represent a vertical line, but if |insert_mode| is true they contain the |
| 171 // bounds of the associated glyph. These bounds are in local coordinates, but | 171 // bounds of the associated glyph. These bounds are in local coordinates, but |
| 172 // may be outside the visible region if the text is longer than the textfield. | 172 // may be outside the visible region if the text is longer than the textfield. |
| 173 // Subsequent text, cursor, or bounds changes may invalidate returned values. | 173 // Subsequent text, cursor, or bounds changes may invalidate returned values. |
| 174 virtual Rect GetCursorBounds(const SelectionModel& selection, | 174 virtual Rect GetCursorBounds(const SelectionModel& selection, |
| 175 bool insert_mode); | 175 bool insert_mode) = 0; |
| 176 | 176 |
| 177 // Compute the current cursor bounds, panning the text to show the cursor in | 177 // Compute the current cursor bounds, panning the text to show the cursor in |
| 178 // the display rect if necessary. These bounds are in local coordinates. | 178 // the display rect if necessary. These bounds are in local coordinates. |
| 179 // Subsequent text, cursor, or bounds changes may invalidate returned values. | 179 // Subsequent text, cursor, or bounds changes may invalidate returned values. |
| 180 const Rect& GetUpdatedCursorBounds(); | 180 const Rect& GetUpdatedCursorBounds(); |
| 181 | 181 |
| 182 // Get the logical index of the grapheme following the argument |position|. | 182 // Get the logical index of the grapheme following the argument |position|. |
| 183 size_t GetIndexOfNextGrapheme(size_t position); | 183 size_t GetIndexOfNextGrapheme(size_t position); |
| 184 | 184 |
| 185 // Return a SelectionModel with the cursor at the current selection's start. | 185 // Return a SelectionModel with the cursor at the current selection's start. |
| (...skipping 16 matching lines...) Expand all 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|. | 212 // Sets the selection model, the argument is assumed to be valid. |
| 213 virtual size_t GetIndexOfPreviousGrapheme(size_t position); | 213 virtual void SetSelectionModel(const SelectionModel& selection_model); |
| 214 | 214 |
| 215 // Get the visual bounds containing the logical substring within |from| to | 215 // Get the visual bounds containing the logical substring within |from| to |
| 216 // |to|. These bounds could be visually discontinuous if the substring is | 216 // |to| into |bounds|. These bounds could be visually discontinuous if the |
| 217 // split by a LTR/RTL level change. These bounds are in local coordinates, but | 217 // substring is split by a LTR/RTL level change. These bounds are in local |
| 218 // may be outside the visible region if the text is longer than the textfield. | 218 // coordinates, but may be outside the visible region if the text is longer |
| 219 // Subsequent text, cursor, or bounds changes may invalidate returned values. | 219 // than the textfield. Subsequent text, cursor, or bounds changes may |
| 220 // TODO(msw) Re-evaluate this function's necessity and signature. | 220 // invalidate returned values. |
| 221 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to); | 221 virtual void GetSubstringBounds(size_t from, |
| 222 size_t to, |
| 223 std::vector<Rect>* bounds) = 0; |
| 222 | 224 |
| 223 // Return true if cursor can appear in front of the character at |position|, | 225 // 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. | 226 // which means it is a grapheme boundary or the first character in the text. |
| 225 virtual bool IsCursorablePosition(size_t position) = 0; | 227 virtual bool IsCursorablePosition(size_t position) = 0; |
| 226 | 228 |
| 227 // Updates the layout so that the next draw request can correctly | 229 // Updates the layout so that the next draw request can correctly |
| 228 // render the text and its attributes. | 230 // render the text and its attributes. |
| 229 virtual void UpdateLayout() = 0; | 231 virtual void UpdateLayout() = 0; |
| 230 | 232 |
| 233 // Draw the text. |
| 234 virtual void DrawVisualText(Canvas* canvas) = 0; |
| 235 |
| 236 // Get the logical index of the grapheme preceding the argument |position|. |
| 237 size_t GetIndexOfPreviousGrapheme(size_t position); |
| 238 |
| 231 // Apply composition style (underline) to composition range and selection | 239 // Apply composition style (underline) to composition range and selection |
| 232 // style (foreground) to selection range. | 240 // style (foreground) to selection range. |
| 233 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; | 241 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; |
| 234 | 242 |
| 235 // Convert points from the text space to the view space and back. | 243 // 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. | 244 // Handles the display area, display offset, and the application LTR/RTL mode. |
| 237 Point ToTextPoint(const Point& point); | 245 Point ToTextPoint(const Point& point); |
| 238 Point ToViewPoint(const Point& point); | 246 Point ToViewPoint(const Point& point); |
| 239 | 247 |
| 240 private: | 248 private: |
| 241 friend class RenderTextTest; | 249 friend class RenderTextTest; |
| 242 | 250 |
| 243 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 251 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
| 244 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 252 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
| 245 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); | 253 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); |
| 246 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); | 254 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); |
| 247 | 255 |
| 248 // Return an index belonging to the |next| or previous logical grapheme. | 256 // Return an index belonging to the |next| or previous logical grapheme. |
| 249 // The return value is bounded by 0 and the text length, inclusive. | 257 // The return value is bounded by 0 and the text length, inclusive. |
| 250 virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) = 0; | 258 virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) = 0; |
| 251 | 259 |
| 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 | 260 // Set the cursor to |position|, with the caret trailing the previous |
| 256 // grapheme, or if there is no previous grapheme, leading the cursor position. | 261 // 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. | 262 // 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), | 263 // If the |position| is not a cursorable position (not on grapheme boundary), |
| 259 // it is a NO-OP. | 264 // it is a NO-OP. |
| 260 void MoveCursorTo(size_t position, bool select); | 265 void MoveCursorTo(size_t position, bool select); |
| 261 | 266 |
| 262 // Update the cached bounds and display offset to ensure that the current | 267 // Update the cached bounds and display offset to ensure that the current |
| 263 // cursor is within the visible display area. | 268 // cursor is within the visible display area. |
| 264 void UpdateCachedBoundsAndOffset(); | 269 void UpdateCachedBoundsAndOffset(); |
| 265 | 270 |
| 271 // Draw the selection and cursor. |
| 272 void DrawSelection(Canvas* canvas); |
| 273 void DrawCursor(Canvas* canvas); |
| 274 |
| 266 // Logical UTF-16 string data to be drawn. | 275 // Logical UTF-16 string data to be drawn. |
| 267 string16 text_; | 276 string16 text_; |
| 268 | 277 |
| 269 // Logical selection range and visual cursor position. | 278 // Logical selection range and visual cursor position. |
| 270 SelectionModel selection_model_; | 279 SelectionModel selection_model_; |
| 271 | 280 |
| 272 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. | 281 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. |
| 273 Rect cursor_bounds_; | 282 Rect cursor_bounds_; |
| 274 | 283 |
| 275 // The cursor visibility and insert mode. | 284 // 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, | 305 // The cached bounds and offset are invalidated by changes to the cursor, |
| 297 // selection, font, and other operations that adjust the visible text bounds. | 306 // selection, font, and other operations that adjust the visible text bounds. |
| 298 bool cached_bounds_and_offset_valid_; | 307 bool cached_bounds_and_offset_valid_; |
| 299 | 308 |
| 300 DISALLOW_COPY_AND_ASSIGN(RenderText); | 309 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 301 }; | 310 }; |
| 302 | 311 |
| 303 } // namespace gfx | 312 } // namespace gfx |
| 304 | 313 |
| 305 #endif // UI_GFX_RENDER_TEXT_H_ | 314 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |