OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 bool insert_mode() const { return insert_mode_; } | 146 bool insert_mode() const { return insert_mode_; } |
147 void ToggleInsertMode(); | 147 void ToggleInsertMode(); |
148 | 148 |
149 bool focused() const { return focused_; } | 149 bool focused() const { return focused_; } |
150 void set_focused(bool focused) { focused_ = focused; } | 150 void set_focused(bool focused) { focused_ = focused; } |
151 | 151 |
152 const StyleRange& default_style() const { return default_style_; } | 152 const StyleRange& default_style() const { return default_style_; } |
153 void set_default_style(const StyleRange& style) { default_style_ = style; } | 153 void set_default_style(const StyleRange& style) { default_style_ = style; } |
154 | 154 |
| 155 // In an obscured (password) field, all text is drawn as asterisks or bullets. |
| 156 bool is_obscured() const { return obscured_; } |
| 157 void SetObscured(bool obscured); |
| 158 |
155 const Rect& display_rect() const { return display_rect_; } | 159 const Rect& display_rect() const { return display_rect_; } |
156 void SetDisplayRect(const Rect& r); | 160 void SetDisplayRect(const Rect& r); |
157 | 161 |
158 void set_fade_head(bool fade_head) { fade_head_ = fade_head; } | 162 void set_fade_head(bool fade_head) { fade_head_ = fade_head; } |
159 bool fade_head() const { return fade_head_; } | 163 bool fade_head() const { return fade_head_; } |
160 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; } | 164 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; } |
161 bool fade_tail() const { return fade_tail_; } | 165 bool fade_tail() const { return fade_tail_; } |
162 | 166 |
163 // This cursor position corresponds to SelectionModel::selection_end. In | 167 // This cursor position corresponds to SelectionModel::selection_end. In |
164 // addition to representing the selection end, it's also where logical text | 168 // addition to representing the selection end, it's also where logical text |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // Update the layout so that the next draw request can correctly | 322 // Update the layout so that the next draw request can correctly |
319 // render the text and its attributes. | 323 // render the text and its attributes. |
320 virtual void UpdateLayout() = 0; | 324 virtual void UpdateLayout() = 0; |
321 | 325 |
322 // Ensure the text is laid out. | 326 // Ensure the text is laid out. |
323 virtual void EnsureLayout() = 0; | 327 virtual void EnsureLayout() = 0; |
324 | 328 |
325 // Draw the text. | 329 // Draw the text. |
326 virtual void DrawVisualText(Canvas* canvas) = 0; | 330 virtual void DrawVisualText(Canvas* canvas) = 0; |
327 | 331 |
| 332 // Like text() except that it returns asterisks or bullets if this is an |
| 333 // obscured field. |
| 334 string16 GetDisplayText() const; |
| 335 |
328 // Apply composition style (underline) to composition range and selection | 336 // Apply composition style (underline) to composition range and selection |
329 // style (foreground) to selection range. | 337 // style (foreground) to selection range. |
330 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges); | 338 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges); |
331 | 339 |
332 // Returns the text origin after applying text alignment and display offset. | 340 // Returns the text origin after applying text alignment and display offset. |
333 Point GetTextOrigin(); | 341 Point GetTextOrigin(); |
334 | 342 |
335 // Convert points from the text space to the view space and back. | 343 // Convert points from the text space to the view space and back. |
336 // Handles the display area, display offset, and the application LTR/RTL mode. | 344 // Handles the display area, display offset, and the application LTR/RTL mode. |
337 Point ToTextPoint(const Point& point); | 345 Point ToTextPoint(const Point& point); |
(...skipping 12 matching lines...) Expand all Loading... |
350 // Applies fade effects to |renderer|. | 358 // Applies fade effects to |renderer|. |
351 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); | 359 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); |
352 | 360 |
353 private: | 361 private: |
354 friend class RenderTextTest; | 362 friend class RenderTextTest; |
355 | 363 |
356 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 364 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
357 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 365 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
358 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); | 366 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); |
359 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); | 367 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); |
| 368 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, PasswordCensorship); |
360 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); | 369 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); |
361 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SelectionModels); | 370 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SelectionModels); |
362 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, OriginForSkiaDrawing); | 371 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, OriginForSkiaDrawing); |
363 | 372 |
364 // Set the cursor to |position|, with the caret trailing the previous | 373 // Set the cursor to |position|, with the caret trailing the previous |
365 // grapheme, or if there is no previous grapheme, leading the cursor position. | 374 // grapheme, or if there is no previous grapheme, leading the cursor position. |
366 // If |select| is false, the selection start is moved to the same position. | 375 // If |select| is false, the selection start is moved to the same position. |
367 // If the |position| is not a cursorable position (not on grapheme boundary), | 376 // If the |position| is not a cursorable position (not on grapheme boundary), |
368 // it is a NO-OP. | 377 // it is a NO-OP. |
369 void MoveCursorTo(size_t position, bool select); | 378 void MoveCursorTo(size_t position, bool select); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 bool focused_; | 412 bool focused_; |
404 | 413 |
405 // Composition text range. | 414 // Composition text range. |
406 ui::Range composition_range_; | 415 ui::Range composition_range_; |
407 | 416 |
408 // List of style ranges. Elements in the list never overlap each other. | 417 // List of style ranges. Elements in the list never overlap each other. |
409 StyleRanges style_ranges_; | 418 StyleRanges style_ranges_; |
410 // The default text style. | 419 // The default text style. |
411 StyleRange default_style_; | 420 StyleRange default_style_; |
412 | 421 |
| 422 // True if this is an obscured (password) field. |
| 423 bool obscured_; |
| 424 |
413 // Fade text head and/or tail, if text doesn't fit into |display_rect_|. | 425 // Fade text head and/or tail, if text doesn't fit into |display_rect_|. |
414 bool fade_head_; | 426 bool fade_head_; |
415 bool fade_tail_; | 427 bool fade_tail_; |
416 | 428 |
417 // The local display area for rendering the text. | 429 // The local display area for rendering the text. |
418 Rect display_rect_; | 430 Rect display_rect_; |
419 | 431 |
420 // The offset for the text to be drawn, relative to the display area. | 432 // The offset for the text to be drawn, relative to the display area. |
421 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). | 433 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). |
422 Point display_offset_; | 434 Point display_offset_; |
423 | 435 |
424 // The cached bounds and offset are invalidated by changes to the cursor, | 436 // The cached bounds and offset are invalidated by changes to the cursor, |
425 // selection, font, and other operations that adjust the visible text bounds. | 437 // selection, font, and other operations that adjust the visible text bounds. |
426 bool cached_bounds_and_offset_valid_; | 438 bool cached_bounds_and_offset_valid_; |
427 | 439 |
428 DISALLOW_COPY_AND_ASSIGN(RenderText); | 440 DISALLOW_COPY_AND_ASSIGN(RenderText); |
429 }; | 441 }; |
430 | 442 |
431 } // namespace gfx | 443 } // namespace gfx |
432 | 444 |
433 #endif // UI_GFX_RENDER_TEXT_H_ | 445 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |