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: |
28 enum Alignment { ALIGN_LEFT = 0, | |
29 ALIGN_CENTER, | |
30 ALIGN_RIGHT }; | |
31 | |
32 // The following enum is used to indicate whether using the Chrome UI's | 29 // 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 | 30 // directionality as the label's directionality, or auto-detecting the label's |
34 // directionality. | 31 // directionality. |
35 // | 32 // |
36 // If the label text originates from the Chrome UI, we should use the Chrome | 33 // If the label text originates from the Chrome UI, we should use the Chrome |
37 // UI's directionality as the label's directionality. | 34 // UI's directionality as the label's directionality. |
38 // | 35 // |
39 // If the text originates from a web page, its directionality is determined | 36 // If the text originates from a web page, its directionality is determined |
40 // based on its first character with strong directionality, disregarding what | 37 // based on its first character with strong directionality, disregarding what |
41 // directionality the Chrome UI is. | 38 // directionality the Chrome UI is. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Disables shadows. | 87 // Disables shadows. |
91 void ClearEmbellishing(); | 88 void ClearEmbellishing(); |
92 | 89 |
93 // Sets horizontal alignment. If the locale is RTL, and the directionality | 90 // Sets horizontal alignment. If the locale is RTL, and the directionality |
94 // mode is USE_UI_DIRECTIONALITY, the alignment is flipped around. | 91 // mode is USE_UI_DIRECTIONALITY, the alignment is flipped around. |
95 // | 92 // |
96 // Caveat: for labels originating from a web page, the directionality mode | 93 // Caveat: for labels originating from a web page, the directionality mode |
97 // should be reset to AUTO_DETECT_DIRECTIONALITY before the horizontal | 94 // should be reset to AUTO_DETECT_DIRECTIONALITY before the horizontal |
98 // alignment is set. Otherwise, the label's alignment specified as a parameter | 95 // alignment is set. Otherwise, the label's alignment specified as a parameter |
99 // will be flipped in RTL locales. | 96 // will be flipped in RTL locales. |
100 void SetHorizontalAlignment(Alignment alignment); | 97 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); |
101 | 98 |
102 Alignment horizontal_alignment() const { return horiz_alignment_; } | 99 gfx::HorizontalAlignment horizontal_alignment() const { |
| 100 return horizontal_alignment_; |
| 101 } |
103 | 102 |
104 // Sets the directionality mode. The directionality mode is initialized to | 103 // Sets the directionality mode. The directionality mode is initialized to |
105 // USE_UI_DIRECTIONALITY when the label is constructed. USE_UI_DIRECTIONALITY | 104 // USE_UI_DIRECTIONALITY when the label is constructed. USE_UI_DIRECTIONALITY |
106 // applies to every label that originates from the Chrome UI. However, if the | 105 // applies to every label that originates from the Chrome UI. However, if the |
107 // label originates from a web page, its directionality is auto-detected. | 106 // label originates from a web page, its directionality is auto-detected. |
108 void set_directionality_mode(DirectionalityMode mode) { | 107 void set_directionality_mode(DirectionalityMode mode) { |
109 directionality_mode_ = mode; | 108 directionality_mode_ = mode; |
110 } | 109 } |
111 | 110 |
112 DirectionalityMode directionality_mode() const { | 111 DirectionalityMode directionality_mode() const { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 SkColor actual_enabled_color_; | 219 SkColor actual_enabled_color_; |
221 SkColor requested_disabled_color_; | 220 SkColor requested_disabled_color_; |
222 SkColor actual_disabled_color_; | 221 SkColor actual_disabled_color_; |
223 SkColor background_color_; | 222 SkColor background_color_; |
224 bool auto_color_readability_; | 223 bool auto_color_readability_; |
225 mutable gfx::Size text_size_; | 224 mutable gfx::Size text_size_; |
226 mutable bool text_size_valid_; | 225 mutable bool text_size_valid_; |
227 bool is_multi_line_; | 226 bool is_multi_line_; |
228 bool allow_character_break_; | 227 bool allow_character_break_; |
229 ElideBehavior elide_behavior_; | 228 ElideBehavior elide_behavior_; |
230 Alignment horiz_alignment_; | 229 gfx::HorizontalAlignment horizontal_alignment_; |
231 string16 tooltip_text_; | 230 string16 tooltip_text_; |
232 // Whether to collapse the label when it's not visible. | 231 // Whether to collapse the label when it's not visible. |
233 bool collapse_when_hidden_; | 232 bool collapse_when_hidden_; |
234 // The following member variable is used to control whether the | 233 // The following member variable is used to control whether the |
235 // directionality is auto-detected based on first strong directionality | 234 // directionality is auto-detected based on first strong directionality |
236 // character or is determined by chrome UI's locale. | 235 // character or is determined by chrome UI's locale. |
237 DirectionalityMode directionality_mode_; | 236 DirectionalityMode directionality_mode_; |
238 // When embedded in a larger control that is focusable, setting this flag | 237 // When embedded in a larger control that is focusable, setting this flag |
239 // allows this view to reserve space for a focus border that it otherwise | 238 // allows this view to reserve space for a focus border that it otherwise |
240 // might not have because it is not itself focusable. | 239 // might not have because it is not itself focusable. |
241 bool has_focus_border_; | 240 bool has_focus_border_; |
242 | 241 |
243 // Colors for shadow. | 242 // Colors for shadow. |
244 SkColor enabled_shadow_color_; | 243 SkColor enabled_shadow_color_; |
245 SkColor disabled_shadow_color_; | 244 SkColor disabled_shadow_color_; |
246 | 245 |
247 // Space between text and shadow. | 246 // Space between text and shadow. |
248 gfx::Point shadow_offset_; | 247 gfx::Point shadow_offset_; |
249 | 248 |
250 // Should a shadow be drawn behind the text? | 249 // Should a shadow be drawn behind the text? |
251 bool has_shadow_; | 250 bool has_shadow_; |
252 | 251 |
253 DISALLOW_COPY_AND_ASSIGN(Label); | 252 DISALLOW_COPY_AND_ASSIGN(Label); |
254 }; | 253 }; |
255 | 254 |
256 } // namespace views | 255 } // namespace views |
257 | 256 |
258 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 257 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
OLD | NEW |