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