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