| 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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // UI's directionality as the label's directionality. | 35 // UI's directionality as the label's directionality. |
| 36 // | 36 // |
| 37 // 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 |
| 38 // based on its first character with strong directionality, disregarding what | 38 // based on its first character with strong directionality, disregarding what |
| 39 // directionality the Chrome UI is. | 39 // directionality the Chrome UI is. |
| 40 enum DirectionalityMode { | 40 enum DirectionalityMode { |
| 41 USE_UI_DIRECTIONALITY = 0, | 41 USE_UI_DIRECTIONALITY = 0, |
| 42 AUTO_DETECT_DIRECTIONALITY | 42 AUTO_DETECT_DIRECTIONALITY |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 enum ElideBehavior { | |
| 46 NO_ELIDE, // Do not elide the label text; truncate as needed. | |
| 47 ELIDE_AT_BEGINNING, // Add ellipsis at the start of the string as needed. | |
| 48 ELIDE_IN_MIDDLE, // Add ellipsis in the middle of the string as needed. | |
| 49 ELIDE_AT_END, // Add ellipsis at the end of the string as needed. | |
| 50 ELIDE_AS_EMAIL, // Elide while retaining username/domain chars | |
| 51 // as needed. | |
| 52 }; | |
| 53 | |
| 54 // Internal class name. | 45 // Internal class name. |
| 55 static const char kViewClassName[]; | 46 static const char kViewClassName[]; |
| 56 | 47 |
| 57 // The padding for the focus border when rendering focused text. | 48 // The padding for the focus border when rendering focused text. |
| 58 static const int kFocusBorderPadding; | 49 static const int kFocusBorderPadding; |
| 59 | 50 |
| 60 Label(); | 51 Label(); |
| 61 explicit Label(const base::string16& text); | 52 explicit Label(const base::string16& text); |
| 62 Label(const base::string16& text, const gfx::FontList& font_list); | 53 Label(const base::string16& text, const gfx::FontList& font_list); |
| 63 virtual ~Label(); | 54 virtual ~Label(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 bool is_obscured() const { return is_obscured_; } | 134 bool is_obscured() const { return is_obscured_; } |
| 144 void SetObscured(bool obscured); | 135 void SetObscured(bool obscured); |
| 145 | 136 |
| 146 // Get the text as displayed to the user, respecting the 'obscured' flag. | 137 // Get the text as displayed to the user, respecting the 'obscured' flag. |
| 147 const base::string16& layout_text() const { return layout_text_; } | 138 const base::string16& layout_text() const { return layout_text_; } |
| 148 | 139 |
| 149 // Sets whether the label text can be split on words. | 140 // Sets whether the label text can be split on words. |
| 150 // Default is false. This only works when is_multi_line is true. | 141 // Default is false. This only works when is_multi_line is true. |
| 151 void SetAllowCharacterBreak(bool allow_character_break); | 142 void SetAllowCharacterBreak(bool allow_character_break); |
| 152 | 143 |
| 153 // Sets whether the label text should be elided in the middle or end (if | 144 // Sets the eliding or fading behavior, applied as necessary. The default is |
| 154 // necessary). The default is to elide at the end. | 145 // to elide at the end. Eliding is not well supported for multi-line labels. |
| 155 // NOTE: Eliding in the middle is not supported for multi-line strings. | 146 void SetElideBehavior(gfx::ElideBehavior elide_behavior); |
| 156 void SetElideBehavior(ElideBehavior elide_behavior); | |
| 157 | 147 |
| 158 // Sets the tooltip text. Default behavior for a label (single-line) is to | 148 // Sets the tooltip text. Default behavior for a label (single-line) is to |
| 159 // show the full text if it is wider than its bounds. Calling this overrides | 149 // show the full text if it is wider than its bounds. Calling this overrides |
| 160 // the default behavior and lets you set a custom tooltip. To revert to | 150 // the default behavior and lets you set a custom tooltip. To revert to |
| 161 // default behavior, call this with an empty string. | 151 // default behavior, call this with an empty string. |
| 162 void SetTooltipText(const base::string16& tooltip_text); | 152 void SetTooltipText(const base::string16& tooltip_text); |
| 163 | 153 |
| 164 // Resizes the label so its width is set to the width of the longest line and | 154 // Resizes the label so its width is set to the width of the longest line and |
| 165 // its height deduced accordingly. | 155 // its height deduced accordingly. |
| 166 // This is only intended for multi-line labels and is useful when the label's | 156 // This is only intended for multi-line labels and is useful when the label's |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 bool disabled_color_set_; | 260 bool disabled_color_set_; |
| 271 bool background_color_set_; | 261 bool background_color_set_; |
| 272 | 262 |
| 273 bool auto_color_readability_; | 263 bool auto_color_readability_; |
| 274 mutable gfx::Size text_size_; | 264 mutable gfx::Size text_size_; |
| 275 mutable bool text_size_valid_; | 265 mutable bool text_size_valid_; |
| 276 int line_height_; | 266 int line_height_; |
| 277 bool is_multi_line_; | 267 bool is_multi_line_; |
| 278 bool is_obscured_; | 268 bool is_obscured_; |
| 279 bool allow_character_break_; | 269 bool allow_character_break_; |
| 280 ElideBehavior elide_behavior_; | 270 gfx::ElideBehavior elide_behavior_; |
| 281 gfx::HorizontalAlignment horizontal_alignment_; | 271 gfx::HorizontalAlignment horizontal_alignment_; |
| 282 base::string16 tooltip_text_; | 272 base::string16 tooltip_text_; |
| 283 // Whether to collapse the label when it's not visible. | 273 // Whether to collapse the label when it's not visible. |
| 284 bool collapse_when_hidden_; | 274 bool collapse_when_hidden_; |
| 285 // The following member variable is used to control whether the | 275 // The following member variable is used to control whether the |
| 286 // directionality is auto-detected based on first strong directionality | 276 // directionality is auto-detected based on first strong directionality |
| 287 // character or is determined by chrome UI's locale. | 277 // character or is determined by chrome UI's locale. |
| 288 DirectionalityMode directionality_mode_; | 278 DirectionalityMode directionality_mode_; |
| 289 | 279 |
| 290 // Colors for shadow. | 280 // Colors for shadow. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 306 // The cached heights to avoid recalculation in GetHeightForWidth(). | 296 // The cached heights to avoid recalculation in GetHeightForWidth(). |
| 307 mutable std::vector<gfx::Size> cached_heights_; | 297 mutable std::vector<gfx::Size> cached_heights_; |
| 308 mutable int cached_heights_cursor_; | 298 mutable int cached_heights_cursor_; |
| 309 | 299 |
| 310 DISALLOW_COPY_AND_ASSIGN(Label); | 300 DISALLOW_COPY_AND_ASSIGN(Label); |
| 311 }; | 301 }; |
| 312 | 302 |
| 313 } // namespace views | 303 } // namespace views |
| 314 | 304 |
| 315 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 305 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
| OLD | NEW |