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_VIEWS_CONTROLS_LABEL_H_ | 5 #ifndef UI_VIEWS_CONTROLS_LABEL_H_ |
6 #define UI_VIEWS_CONTROLS_LABEL_H_ | 6 #define UI_VIEWS_CONTROLS_LABEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
14 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font.h" |
15 #include "ui/gfx/text_constants.h" | |
15 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
16 | 17 |
17 namespace views { | 18 namespace views { |
18 | 19 |
19 ///////////////////////////////////////////////////////////////////////////// | 20 ///////////////////////////////////////////////////////////////////////////// |
20 // | 21 // |
21 // Label class | 22 // Label class |
22 // | 23 // |
23 // A label is a view subclass that can display a string. | 24 // A label is a view subclass that can display a string. |
24 // | 25 // |
25 ///////////////////////////////////////////////////////////////////////////// | 26 ///////////////////////////////////////////////////////////////////////////// |
26 class VIEWS_EXPORT Label : public View { | 27 class VIEWS_EXPORT Label : public View { |
27 public: | 28 public: |
29 // TODO(msw): Use gfx::HorizontalAlignment instead. | |
28 enum Alignment { ALIGN_LEFT = 0, | 30 enum Alignment { ALIGN_LEFT = 0, |
29 ALIGN_CENTER, | 31 ALIGN_CENTER, |
30 ALIGN_RIGHT }; | 32 ALIGN_RIGHT }; |
31 | 33 |
32 // The following enum is used to indicate whether using the Chrome UI's | |
33 // directionality as the label's directionality, or auto-detecting the label's | |
34 // directionality. | |
35 // | |
36 // If the label text originates from the Chrome UI, we should use the Chrome | |
37 // UI's directionality as the label's directionality. | |
38 // | |
39 // If the text originates from a web page, its directionality is determined | |
40 // based on its first character with strong directionality, disregarding what | |
41 // directionality the Chrome UI is. | |
42 enum DirectionalityMode { | |
43 USE_UI_DIRECTIONALITY = 0, | |
44 AUTO_DETECT_DIRECTIONALITY | |
45 }; | |
46 | |
47 // The view class name. | 34 // The view class name. |
48 static const char kViewClassName[]; | 35 static const char kViewClassName[]; |
49 | 36 |
50 // The padding for the focus border when rendering focused text. | 37 // The padding for the focus border when rendering focused text. |
51 static const int kFocusBorderPadding; | 38 static const int kFocusBorderPadding; |
52 | 39 |
53 Label(); | 40 Label(); |
54 explicit Label(const string16& text); | 41 explicit Label(const string16& text); |
55 Label(const string16& text, const gfx::Font& font); | 42 Label(const string16& text, const gfx::Font& font); |
56 virtual ~Label(); | 43 virtual ~Label(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 // Enables a drop shadow underneath the text. | 77 // Enables a drop shadow underneath the text. |
91 void SetShadowColors(SkColor enabled_color, SkColor disabled_color); | 78 void SetShadowColors(SkColor enabled_color, SkColor disabled_color); |
92 | 79 |
93 // Sets the drop shadow's offset from the text. | 80 // Sets the drop shadow's offset from the text. |
94 void SetShadowOffset(int x, int y); | 81 void SetShadowOffset(int x, int y); |
95 | 82 |
96 // Disables shadows. | 83 // Disables shadows. |
97 void ClearEmbellishing(); | 84 void ClearEmbellishing(); |
98 | 85 |
99 // Sets horizontal alignment. If the locale is RTL, and the directionality | 86 // Sets horizontal alignment. If the locale is RTL, and the directionality |
100 // mode is USE_UI_DIRECTIONALITY, the alignment is flipped around. | 87 // mode is gfx::DIRECTIONALITY_FROM_UI, the alignment is flipped around. |
101 // | 88 // |
102 // Caveat: for labels originating from a web page, the directionality mode | 89 // Caveat: for labels originating from a web page, the directionality mode |
103 // should be reset to AUTO_DETECT_DIRECTIONALITY before the horizontal | 90 // should be reset to gfx::DIRECTIONALITY_FROM_TEXT before the horizontal |
104 // alignment is set. Otherwise, the label's alignment specified as a parameter | 91 // alignment is set. Otherwise, the label's alignment specified as a parameter |
105 // will be flipped in RTL locales. | 92 // will be flipped in RTL locales. |
106 void SetHorizontalAlignment(Alignment alignment); | 93 void SetHorizontalAlignment(Alignment alignment); |
107 | 94 |
108 Alignment horizontal_alignment() const { return horiz_alignment_; } | 95 Alignment horizontal_alignment() const { return horiz_alignment_; } |
109 | 96 |
110 // Sets the directionality mode. The directionality mode is initialized to | 97 // Sets the directionality mode; initialized to gfx::DIRECTIONALITY_FROM_UI |
111 // USE_UI_DIRECTIONALITY when the label is constructed. USE_UI_DIRECTIONALITY | 98 // when the label is constructed. gfx::DIRECTIONALITY_FROM_UI applies to every |
112 // applies to every label that originates from the Chrome UI. However, if the | 99 // label that originates from the Chrome UI. However, if the label originates |
113 // label originates from a web page, its directionality is auto-detected. | 100 // from a web page, its directionality is auto-detected. |
114 void set_directionality_mode(DirectionalityMode mode) { | 101 void set_directionality_mode(gfx::DirectionalityMode mode) { |
115 directionality_mode_ = mode; | 102 directionality_mode_ = mode; |
116 } | 103 } |
117 | 104 |
118 DirectionalityMode directionality_mode() const { | 105 gfx::DirectionalityMode directionality_mode() const { |
119 return directionality_mode_; | 106 return directionality_mode_; |
120 } | 107 } |
121 | 108 |
122 // Sets whether the label text can wrap on multiple lines. | 109 // Sets whether the label text can wrap on multiple lines. |
123 // Default is false. | 110 // Default is false. |
124 void SetMultiLine(bool multi_line); | 111 void SetMultiLine(bool multi_line); |
125 | 112 |
126 // Returns whether the label text can wrap on multiple lines. | 113 // Returns whether the label text can wrap on multiple lines. |
127 bool is_multi_line() const { return is_multi_line_; } | 114 bool is_multi_line() const { return is_multi_line_; } |
128 | 115 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 bool allow_character_break_; | 254 bool allow_character_break_; |
268 bool elide_in_middle_; | 255 bool elide_in_middle_; |
269 bool is_email_; | 256 bool is_email_; |
270 Alignment horiz_alignment_; | 257 Alignment horiz_alignment_; |
271 string16 tooltip_text_; | 258 string16 tooltip_text_; |
272 // Whether the mouse is over this label. | 259 // Whether the mouse is over this label. |
273 bool contains_mouse_; | 260 bool contains_mouse_; |
274 scoped_ptr<Background> mouse_over_background_; | 261 scoped_ptr<Background> mouse_over_background_; |
275 // Whether to collapse the label when it's not visible. | 262 // Whether to collapse the label when it's not visible. |
276 bool collapse_when_hidden_; | 263 bool collapse_when_hidden_; |
277 // The following member variable is used to control whether the | 264 // Controls whether the base text directionality is inherited from the text's |
278 // directionality is auto-detected based on first strong directionality | 265 // first strong directionality character or from the UI's locale. |
Alexei Svitkine (slow)
2012/07/30 22:29:16
Could also be forced right? Perhaps the comment do
msw
2012/07/31 03:03:06
Reverted this portion of the CL; will address in a
| |
279 // character or is determined by chrome UI's locale. | 266 gfx::DirectionalityMode directionality_mode_; |
280 DirectionalityMode directionality_mode_; | |
281 // When embedded in a larger control that is focusable, setting this flag | 267 // When embedded in a larger control that is focusable, setting this flag |
282 // allows this view to be painted as focused even when it is itself not. | 268 // allows this view to be painted as focused even when it is itself not. |
283 bool paint_as_focused_; | 269 bool paint_as_focused_; |
284 // When embedded in a larger control that is focusable, setting this flag | 270 // When embedded in a larger control that is focusable, setting this flag |
285 // allows this view to reserve space for a focus border that it otherwise | 271 // allows this view to reserve space for a focus border that it otherwise |
286 // might not have because it is not itself focusable. | 272 // might not have because it is not itself focusable. |
287 bool has_focus_border_; | 273 bool has_focus_border_; |
288 | 274 |
289 // Colors for shadow. | 275 // Colors for shadow. |
290 SkColor enabled_shadow_color_; | 276 SkColor enabled_shadow_color_; |
291 SkColor disabled_shadow_color_; | 277 SkColor disabled_shadow_color_; |
292 | 278 |
293 // Space between text and shadow. | 279 // Space between text and shadow. |
294 gfx::Point shadow_offset_; | 280 gfx::Point shadow_offset_; |
295 | 281 |
296 // Should a shadow be drawn behind the text? | 282 // Should a shadow be drawn behind the text? |
297 bool has_shadow_; | 283 bool has_shadow_; |
298 | 284 |
299 | 285 |
300 DISALLOW_COPY_AND_ASSIGN(Label); | 286 DISALLOW_COPY_AND_ASSIGN(Label); |
301 }; | 287 }; |
302 | 288 |
303 } // namespace views | 289 } // namespace views |
304 | 290 |
305 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 291 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
OLD | NEW |