| 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 #include <vector> | 9 #include <vector> |
| 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/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
| 15 #include "ui/gfx/font_list.h" | 15 #include "ui/gfx/font_list.h" |
| 16 #include "ui/gfx/text_constants.h" | 16 #include "ui/gfx/text_constants.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 // Internal class name. | |
| 31 static const char kViewClassName[]; | |
| 32 | |
| 33 // The following enum is used to indicate whether using the Chrome UI's | 30 // 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 | 31 // directionality as the label's directionality, or auto-detecting the label's |
| 35 // directionality. | 32 // directionality. |
| 36 // | 33 // |
| 37 // If the label text originates from the Chrome UI, we should use the Chrome | 34 // If the label text originates from the Chrome UI, we should use the Chrome |
| 38 // UI's directionality as the label's directionality. | 35 // UI's directionality as the label's directionality. |
| 39 // | 36 // |
| 40 // If the text originates from a web page, its directionality is determined | 37 // If the text originates from a web page, its directionality is determined |
| 41 // based on its first character with strong directionality, disregarding what | 38 // based on its first character with strong directionality, disregarding what |
| 42 // directionality the Chrome UI is. | 39 // directionality the Chrome UI is. |
| 43 enum DirectionalityMode { | 40 enum DirectionalityMode { |
| 44 USE_UI_DIRECTIONALITY = 0, | 41 USE_UI_DIRECTIONALITY = 0, |
| 45 AUTO_DETECT_DIRECTIONALITY | 42 AUTO_DETECT_DIRECTIONALITY |
| 46 }; | 43 }; |
| 47 | 44 |
| 48 enum ElideBehavior { | 45 enum ElideBehavior { |
| 49 NO_ELIDE, // Do not elide the label text; truncate as needed. | 46 NO_ELIDE, // Do not elide the label text; truncate as needed. |
| 50 ELIDE_IN_MIDDLE, // Add ellipsis in the middle of the string as needed. | 47 ELIDE_IN_MIDDLE, // Add ellipsis in the middle of the string as needed. |
| 51 ELIDE_AT_END, // Add ellipsis at the end of the string as needed. | 48 ELIDE_AT_END, // Add ellipsis at the end of the string as needed. |
| 52 ELIDE_AS_EMAIL, // Elide while retaining username/domain chars as needed. | 49 ELIDE_AS_EMAIL, // Elide while retaining username/domain chars as needed. |
| 53 }; | 50 }; |
| 54 | 51 |
| 52 // Internal class name. |
| 53 static const char kViewClassName[]; |
| 54 |
| 55 // The padding for the focus border when rendering focused text. |
| 56 static const int kFocusBorderPadding; |
| 57 |
| 55 Label(); | 58 Label(); |
| 56 explicit Label(const string16& text); | 59 explicit Label(const string16& text); |
| 57 Label(const string16& text, const gfx::FontList& font_list); | 60 Label(const string16& text, const gfx::FontList& font_list); |
| 58 Label(const string16& text, const gfx::Font& font); // OBSOLETE | 61 Label(const string16& text, const gfx::Font& font); // OBSOLETE |
| 59 virtual ~Label(); | 62 virtual ~Label(); |
| 60 | 63 |
| 61 // Gets or sets the fonts used by this label. | 64 // Gets or sets the fonts used by this label. |
| 62 const gfx::FontList& font_list() const { return font_list_; } | 65 const gfx::FontList& font_list() const { return font_list_; } |
| 63 virtual void SetFontList(const gfx::FontList& font_list); | 66 virtual void SetFontList(const gfx::FontList& font_list); |
| 64 // Obsolete gfx::Font version. Should use gfx::FontList version instead. | 67 // Obsolete gfx::Font version. Should use gfx::FontList version instead. |
| 65 const gfx::Font& font() const; // OBSOLETE | 68 const gfx::Font& font() const; // OBSOLETE |
| 66 virtual void SetFont(const gfx::Font& font); // OBSOLETE | 69 virtual void SetFont(const gfx::Font& font); // OBSOLETE |
| 67 | 70 |
| 68 // Get or set the label text. | 71 // Get or set the label text. |
| 69 const string16& text() const { return text_; } | 72 const string16& text() const { return text_; } |
| 70 void SetText(const string16& text); | 73 virtual void SetText(const string16& text); |
| 71 | 74 |
| 72 // Enables or disables auto-color-readability (enabled by default). If this | 75 // Enables or disables auto-color-readability (enabled by default). If this |
| 73 // is enabled, then calls to set any foreground or background color will | 76 // is enabled, then calls to set any foreground or background color will |
| 74 // trigger an automatic mapper that uses color_utils::GetReadableColor() to | 77 // trigger an automatic mapper that uses color_utils::GetReadableColor() to |
| 75 // ensure that the foreground colors are readable over the background color. | 78 // ensure that the foreground colors are readable over the background color. |
| 76 void SetAutoColorReadabilityEnabled(bool enabled); | 79 void SetAutoColorReadabilityEnabled(bool enabled); |
| 77 | 80 |
| 78 // Sets the color. This will automatically force the color to be readable | 81 // Sets the color. This will automatically force the color to be readable |
| 79 // over the current background color. | 82 // over the current background color. |
| 80 virtual void SetEnabledColor(SkColor color); | 83 virtual void SetEnabledColor(SkColor color); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // |max_width| is the maximum width that will be used (longer lines will be | 156 // |max_width| is the maximum width that will be used (longer lines will be |
| 154 // wrapped). If 0, no maximum width is enforced. | 157 // wrapped). If 0, no maximum width is enforced. |
| 155 void SizeToFit(int max_width); | 158 void SizeToFit(int max_width); |
| 156 | 159 |
| 157 // Gets/sets the flag to determine whether the label should be collapsed when | 160 // Gets/sets the flag to determine whether the label should be collapsed when |
| 158 // it's hidden (not visible). If this flag is true, the label will return a | 161 // it's hidden (not visible). If this flag is true, the label will return a |
| 159 // preferred size of (0, 0) when it's not visible. | 162 // preferred size of (0, 0) when it's not visible. |
| 160 void set_collapse_when_hidden(bool value) { collapse_when_hidden_ = value; } | 163 void set_collapse_when_hidden(bool value) { collapse_when_hidden_ = value; } |
| 161 bool collapse_when_hidden() const { return collapse_when_hidden_; } | 164 bool collapse_when_hidden() const { return collapse_when_hidden_; } |
| 162 | 165 |
| 163 void SetHasFocusBorder(bool has_focus_border); | |
| 164 | |
| 165 // Overridden from View: | 166 // Overridden from View: |
| 166 virtual gfx::Insets GetInsets() const OVERRIDE; | 167 virtual gfx::Insets GetInsets() const OVERRIDE; |
| 167 virtual int GetBaseline() const OVERRIDE; | 168 virtual int GetBaseline() const OVERRIDE; |
| 168 // Overridden to compute the size required to display this label. | 169 // Overridden to compute the size required to display this label. |
| 169 virtual gfx::Size GetPreferredSize() OVERRIDE; | 170 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 171 // Returns the width of an ellipsis if the label is non-empty, or 0 otherwise. |
| 172 virtual gfx::Size GetMinimumSize() OVERRIDE; |
| 170 // Returns the height necessary to display this label with the provided width. | 173 // Returns the height necessary to display this label with the provided width. |
| 171 // This method is used to layout multi-line labels. It is equivalent to | 174 // This method is used to layout multi-line labels. It is equivalent to |
| 172 // GetPreferredSize().height() if the receiver is not multi-line. | 175 // GetPreferredSize().height() if the receiver is not multi-line. |
| 173 virtual int GetHeightForWidth(int w) OVERRIDE; | 176 virtual int GetHeightForWidth(int w) OVERRIDE; |
| 174 virtual const char* GetClassName() const OVERRIDE; | 177 virtual const char* GetClassName() const OVERRIDE; |
| 175 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE; | 178 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE; |
| 176 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE; | 179 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE; |
| 177 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 180 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 178 // Gets the tooltip text for labels that are wider than their bounds, except | 181 // Gets the tooltip text for labels that are wider than their bounds, except |
| 179 // when the label is multiline, in which case it just returns false (no | 182 // when the label is multiline, in which case it just returns false (no |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 bool allow_character_break_; | 261 bool allow_character_break_; |
| 259 ElideBehavior elide_behavior_; | 262 ElideBehavior elide_behavior_; |
| 260 gfx::HorizontalAlignment horizontal_alignment_; | 263 gfx::HorizontalAlignment horizontal_alignment_; |
| 261 string16 tooltip_text_; | 264 string16 tooltip_text_; |
| 262 // Whether to collapse the label when it's not visible. | 265 // Whether to collapse the label when it's not visible. |
| 263 bool collapse_when_hidden_; | 266 bool collapse_when_hidden_; |
| 264 // The following member variable is used to control whether the | 267 // The following member variable is used to control whether the |
| 265 // directionality is auto-detected based on first strong directionality | 268 // directionality is auto-detected based on first strong directionality |
| 266 // character or is determined by chrome UI's locale. | 269 // character or is determined by chrome UI's locale. |
| 267 DirectionalityMode directionality_mode_; | 270 DirectionalityMode directionality_mode_; |
| 268 // When embedded in a larger control that is focusable, setting this flag | |
| 269 // allows this view to reserve space for a focus border that it otherwise | |
| 270 // might not have because it is not itself focusable. | |
| 271 bool has_focus_border_; | |
| 272 | 271 |
| 273 // Colors for shadow. | 272 // Colors for shadow. |
| 274 SkColor enabled_shadow_color_; | 273 SkColor enabled_shadow_color_; |
| 275 SkColor disabled_shadow_color_; | 274 SkColor disabled_shadow_color_; |
| 276 | 275 |
| 277 // Space between text and shadow. | 276 // Space between text and shadow. |
| 278 gfx::Point shadow_offset_; | 277 gfx::Point shadow_offset_; |
| 279 | 278 |
| 280 // Should a shadow be drawn behind the text? | 279 // Should a shadow be drawn behind the text? |
| 281 bool has_shadow_; | 280 bool has_shadow_; |
| 282 | 281 |
| 283 // The cached heights to avoid recalculation in GetHeightForWidth(). | 282 // The cached heights to avoid recalculation in GetHeightForWidth(). |
| 284 std::vector<gfx::Size> cached_heights_; | 283 std::vector<gfx::Size> cached_heights_; |
| 285 int cached_heights_cursor_; | 284 int cached_heights_cursor_; |
| 286 | 285 |
| 287 DISALLOW_COPY_AND_ASSIGN(Label); | 286 DISALLOW_COPY_AND_ASSIGN(Label); |
| 288 }; | 287 }; |
| 289 | 288 |
| 290 } // namespace views | 289 } // namespace views |
| 291 | 290 |
| 292 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 291 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
| OLD | NEW |