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> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
16 #include "ui/base/range/range.h" | 16 #include "ui/base/range/range.h" |
17 #include "ui/gfx/font.h" | 17 #include "ui/gfx/font.h" |
18 #include "ui/gfx/point.h" | 18 #include "ui/gfx/point.h" |
19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
20 #include "ui/gfx/selection_model.h" | 20 #include "ui/gfx/selection_model.h" |
21 | 21 |
22 namespace gfx { | 22 namespace gfx { |
23 | 23 |
24 // Color settings for text, backgrounds and cursor. | |
25 // These are tentative, and should be derived from theme, system | |
26 // settings and current settings. | |
27 // TODO(oshima): Change this to match the standard chrome | |
28 // before dogfooding textfield views. | |
29 const SkColor kSelectedTextColor = SK_ColorWHITE; | |
30 const SkColor kFocusedSelectionColor = SkColorSetRGB(30, 144, 255); | |
31 const SkColor kUnfocusedSelectionColor = SK_ColorLTGRAY; | |
32 const SkColor kCursorColor = SK_ColorBLACK; | |
33 | |
34 class Canvas; | 24 class Canvas; |
35 class RenderTextTest; | 25 class RenderTextTest; |
36 | 26 |
37 // A visual style applicable to a range of text. | 27 // A visual style applicable to a range of text. |
38 struct UI_EXPORT StyleRange { | 28 struct UI_EXPORT StyleRange { |
39 StyleRange(); | 29 StyleRange(); |
40 | 30 |
41 Font font; | 31 Font font; |
42 SkColor foreground; | 32 SkColor foreground; |
43 bool strike; | 33 bool strike; |
(...skipping 22 matching lines...) Expand all Loading... | |
66 class UI_EXPORT RenderText { | 56 class UI_EXPORT RenderText { |
67 public: | 57 public: |
68 virtual ~RenderText(); | 58 virtual ~RenderText(); |
69 | 59 |
70 // Creates a platform-specific RenderText instance. | 60 // Creates a platform-specific RenderText instance. |
71 static RenderText* CreateRenderText(); | 61 static RenderText* CreateRenderText(); |
72 | 62 |
73 const string16& text() const { return text_; } | 63 const string16& text() const { return text_; } |
74 void SetText(const string16& text); | 64 void SetText(const string16& text); |
75 | 65 |
66 // Like text() except that it returns asterisks or bullets if this is an | |
67 // obscured field. | |
68 string16 GetObscuredText() const; | |
69 | |
76 const SelectionModel& selection_model() const { return selection_model_; } | 70 const SelectionModel& selection_model() const { return selection_model_; } |
77 | 71 |
78 bool cursor_visible() const { return cursor_visible_; } | 72 bool cursor_visible() const { return cursor_visible_; } |
79 void set_cursor_visible(bool visible) { cursor_visible_ = visible; } | 73 void set_cursor_visible(bool visible) { cursor_visible_ = visible; } |
80 | 74 |
81 bool insert_mode() const { return insert_mode_; } | 75 bool insert_mode() const { return insert_mode_; } |
82 void ToggleInsertMode(); | 76 void ToggleInsertMode(); |
83 | 77 |
84 bool focused() const { return focused_; } | 78 bool focused() const { return focused_; } |
85 void set_focused(bool focused) { focused_ = focused; } | 79 void set_focused(bool focused) { focused_ = focused; } |
86 | 80 |
87 const StyleRange& default_style() const { return default_style_; } | 81 const StyleRange& default_style() const { return default_style_; } |
88 void set_default_style(StyleRange style) { default_style_ = style; } | 82 void set_default_style(StyleRange style) { default_style_ = style; } |
89 | 83 |
84 // In an obscured (password) field, all text is drawn as asterisks or bullets. | |
85 bool is_obscured() const { return obscured_; } | |
86 void SetIsObscured(bool obscured); | |
oshima
2011/12/06 23:57:18
SetObscured
benrg
2011/12/08 21:40:55
Done.
| |
87 | |
90 const Rect& display_rect() const { return display_rect_; } | 88 const Rect& display_rect() const { return display_rect_; } |
91 void SetDisplayRect(const Rect& r); | 89 void SetDisplayRect(const Rect& r); |
92 | 90 |
93 // This cursor position corresponds to SelectionModel::selection_end. In | 91 // This cursor position corresponds to SelectionModel::selection_end. In |
94 // addition to representing the selection end, it's also where logical text | 92 // addition to representing the selection end, it's also where logical text |
95 // edits take place, and doesn't necessarily correspond to | 93 // edits take place, and doesn't necessarily correspond to |
96 // SelectionModel::caret_pos. | 94 // SelectionModel::caret_pos. |
97 size_t GetCursorPosition() const; | 95 size_t GetCursorPosition() const; |
98 void SetCursorPosition(size_t position); | 96 void SetCursorPosition(size_t position); |
99 | 97 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 | 147 |
150 // Apply |style_range| to the internal style model. | 148 // Apply |style_range| to the internal style model. |
151 void ApplyStyleRange(StyleRange style_range); | 149 void ApplyStyleRange(StyleRange style_range); |
152 | 150 |
153 // Apply |default_style_| over the entire text range. | 151 // Apply |default_style_| over the entire text range. |
154 void ApplyDefaultStyle(); | 152 void ApplyDefaultStyle(); |
155 | 153 |
156 virtual base::i18n::TextDirection GetTextDirection(); | 154 virtual base::i18n::TextDirection GetTextDirection(); |
157 | 155 |
158 // Get the width of the entire string. | 156 // Get the width of the entire string. |
159 virtual int GetStringWidth(); | 157 virtual int GetStringWidth() = 0; |
160 | 158 |
161 virtual void Draw(Canvas* canvas); | 159 virtual void Draw(Canvas* canvas); |
162 | 160 |
163 // Gets the SelectionModel from a visual point in local coordinates. | 161 // Gets the SelectionModel from a visual point in local coordinates. |
164 virtual SelectionModel FindCursorPosition(const Point& point); | 162 virtual SelectionModel FindCursorPosition(const Point& point) = 0; |
165 | 163 |
166 // Get the visual bounds of a cursor at |selection|. These bounds typically | 164 // Get the visual bounds of a cursor at |selection|. These bounds typically |
167 // represent a vertical line, but if |insert_mode| is true they contain the | 165 // represent a vertical line, but if |insert_mode| is true they contain the |
168 // bounds of the associated glyph. These bounds are in local coordinates, but | 166 // bounds of the associated glyph. These bounds are in local coordinates, but |
169 // may be outside the visible region if the text is longer than the textfield. | 167 // may be outside the visible region if the text is longer than the textfield. |
170 // Subsequent text, cursor, or bounds changes may invalidate returned values. | 168 // Subsequent text, cursor, or bounds changes may invalidate returned values. |
171 virtual Rect GetCursorBounds(const SelectionModel& selection, | 169 virtual Rect GetCursorBounds(const SelectionModel& selection, |
172 bool insert_mode) = 0; | 170 bool insert_mode) = 0; |
173 | 171 |
174 // Compute the current cursor bounds, panning the text to show the cursor in | 172 // Compute the current cursor bounds, panning the text to show the cursor in |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 bool focused_; | 287 bool focused_; |
290 | 288 |
291 // Composition text range. | 289 // Composition text range. |
292 ui::Range composition_range_; | 290 ui::Range composition_range_; |
293 | 291 |
294 // List of style ranges. Elements in the list never overlap each other. | 292 // List of style ranges. Elements in the list never overlap each other. |
295 StyleRanges style_ranges_; | 293 StyleRanges style_ranges_; |
296 // The default text style. | 294 // The default text style. |
297 StyleRange default_style_; | 295 StyleRange default_style_; |
298 | 296 |
297 // True if this is a password field. | |
oshima
2011/12/06 23:57:18
update the comment
benrg
2011/12/08 21:40:55
Done.
| |
298 bool obscured_; | |
299 | |
299 // The local display area for rendering the text. | 300 // The local display area for rendering the text. |
300 Rect display_rect_; | 301 Rect display_rect_; |
301 // The offset for the text to be drawn, relative to the display area. | 302 // The offset for the text to be drawn, relative to the display area. |
302 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). | 303 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). |
303 Point display_offset_; | 304 Point display_offset_; |
304 | 305 |
305 // The cached bounds and offset are invalidated by changes to the cursor, | 306 // The cached bounds and offset are invalidated by changes to the cursor, |
306 // selection, font, and other operations that adjust the visible text bounds. | 307 // selection, font, and other operations that adjust the visible text bounds. |
307 bool cached_bounds_and_offset_valid_; | 308 bool cached_bounds_and_offset_valid_; |
308 | 309 |
309 DISALLOW_COPY_AND_ASSIGN(RenderText); | 310 DISALLOW_COPY_AND_ASSIGN(RenderText); |
310 }; | 311 }; |
311 | 312 |
312 } // namespace gfx | 313 } // namespace gfx |
313 | 314 |
314 #endif // UI_GFX_RENDER_TEXT_H_ | 315 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |