| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Get or set the distance in pixels between baselines of multi-line text. | 125 // Get or set the distance in pixels between baselines of multi-line text. |
| 126 // Default is 0, indicating the distance between lines should be the standard | 126 // Default is 0, indicating the distance between lines should be the standard |
| 127 // one for the label's text, font list, and platform. | 127 // one for the label's text, font list, and platform. |
| 128 int line_height() const { return line_height_; } | 128 int line_height() const { return line_height_; } |
| 129 void SetLineHeight(int height); | 129 void SetLineHeight(int height); |
| 130 | 130 |
| 131 // Get or set if the label text can wrap on multiple lines; default is false. | 131 // Get or set if the label text can wrap on multiple lines; default is false. |
| 132 bool is_multi_line() const { return is_multi_line_; } | 132 bool is_multi_line() const { return is_multi_line_; } |
| 133 void SetMultiLine(bool multi_line); | 133 void SetMultiLine(bool multi_line); |
| 134 | 134 |
| 135 // Get or set if the label text should be obscured before rendering (e.g. |
| 136 // should "Password!" display as "*********"); default is false. |
| 137 bool is_obscured() const { return is_obscured_; } |
| 138 void SetObscured(bool obscured); |
| 139 |
| 140 // Get the text as displayed to the user, respecting the 'obscured' flag. |
| 141 const base::string16& layout_text() const { return layout_text_; } |
| 142 |
| 135 // Sets whether the label text can be split on words. | 143 // Sets whether the label text can be split on words. |
| 136 // Default is false. This only works when is_multi_line is true. | 144 // Default is false. This only works when is_multi_line is true. |
| 137 void SetAllowCharacterBreak(bool allow_character_break); | 145 void SetAllowCharacterBreak(bool allow_character_break); |
| 138 | 146 |
| 139 // Sets whether the label text should be elided in the middle or end (if | 147 // Sets whether the label text should be elided in the middle or end (if |
| 140 // necessary). The default is to elide at the end. | 148 // necessary). The default is to elide at the end. |
| 141 // NOTE: Eliding in the middle is not supported for multi-line strings. | 149 // NOTE: Eliding in the middle is not supported for multi-line strings. |
| 142 void SetElideBehavior(ElideBehavior elide_behavior); | 150 void SetElideBehavior(ElideBehavior elide_behavior); |
| 143 | 151 |
| 144 // Sets the tooltip text. Default behavior for a label (single-line) is to | 152 // Sets the tooltip text. Default behavior for a label (single-line) is to |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // calculations done for drawing text. | 214 // calculations done for drawing text. |
| 207 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString); | 215 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString); |
| 208 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString); | 216 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString); |
| 209 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL); | 217 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL); |
| 210 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL); | 218 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL); |
| 211 FRIEND_TEST_ALL_PREFIXES(LabelTest, AutoDetectDirectionality); | 219 FRIEND_TEST_ALL_PREFIXES(LabelTest, AutoDetectDirectionality); |
| 212 | 220 |
| 213 // Calls ComputeDrawStringFlags(). | 221 // Calls ComputeDrawStringFlags(). |
| 214 FRIEND_TEST_ALL_PREFIXES(LabelTest, DisableSubpixelRendering); | 222 FRIEND_TEST_ALL_PREFIXES(LabelTest, DisableSubpixelRendering); |
| 215 | 223 |
| 224 // Sets both |text_| and |layout_text_| to appropriate values, taking |
| 225 // the label's 'obscured' status into account. |
| 226 void SetTextInternal(const base::string16& text); |
| 227 |
| 216 void Init(const base::string16& text, const gfx::FontList& font_list); | 228 void Init(const base::string16& text, const gfx::FontList& font_list); |
| 217 | 229 |
| 218 void RecalculateColors(); | 230 void RecalculateColors(); |
| 219 | 231 |
| 220 // Returns where the text is drawn, in the receivers coordinate system. | 232 // Returns where the text is drawn, in the receivers coordinate system. |
| 221 gfx::Rect GetTextBounds() const; | 233 gfx::Rect GetTextBounds() const; |
| 222 | 234 |
| 223 int ComputeDrawStringFlags() const; | 235 int ComputeDrawStringFlags() const; |
| 224 | 236 |
| 225 gfx::Rect GetAvailableRect() const; | 237 gfx::Rect GetAvailableRect() const; |
| 226 | 238 |
| 227 // Returns parameters to be used for the DrawString call. | 239 // Returns parameters to be used for the DrawString call. |
| 228 void CalculateDrawStringParams(base::string16* paint_text, | 240 void CalculateDrawStringParams(base::string16* paint_text, |
| 229 gfx::Rect* text_bounds, | 241 gfx::Rect* text_bounds, |
| 230 int* flags) const; | 242 int* flags) const; |
| 231 | 243 |
| 232 // Updates any colors that have not been explicitly set from the theme. | 244 // Updates any colors that have not been explicitly set from the theme. |
| 233 void UpdateColorsFromTheme(const ui::NativeTheme* theme); | 245 void UpdateColorsFromTheme(const ui::NativeTheme* theme); |
| 234 | 246 |
| 235 // Resets |cached_heights_| and |cached_heights_cursor_| and mark | 247 // Resets |cached_heights_| and |cached_heights_cursor_| and mark |
| 236 // |text_size_valid_| as false. | 248 // |text_size_valid_| as false. |
| 237 void ResetCachedSize(); | 249 void ResetCachedSize(); |
| 238 | 250 |
| 239 bool ShouldShowDefaultTooltip() const; | 251 bool ShouldShowDefaultTooltip() const; |
| 240 | 252 |
| 241 base::string16 text_; | 253 base::string16 text_; |
| 254 base::string16 layout_text_; |
| 242 gfx::FontList font_list_; | 255 gfx::FontList font_list_; |
| 243 SkColor requested_enabled_color_; | 256 SkColor requested_enabled_color_; |
| 244 SkColor actual_enabled_color_; | 257 SkColor actual_enabled_color_; |
| 245 SkColor requested_disabled_color_; | 258 SkColor requested_disabled_color_; |
| 246 SkColor actual_disabled_color_; | 259 SkColor actual_disabled_color_; |
| 247 SkColor background_color_; | 260 SkColor background_color_; |
| 248 | 261 |
| 249 // Set to true once the corresponding setter is invoked. | 262 // Set to true once the corresponding setter is invoked. |
| 250 bool enabled_color_set_; | 263 bool enabled_color_set_; |
| 251 bool disabled_color_set_; | 264 bool disabled_color_set_; |
| 252 bool background_color_set_; | 265 bool background_color_set_; |
| 253 | 266 |
| 254 bool auto_color_readability_; | 267 bool auto_color_readability_; |
| 255 mutable gfx::Size text_size_; | 268 mutable gfx::Size text_size_; |
| 256 mutable bool text_size_valid_; | 269 mutable bool text_size_valid_; |
| 257 int line_height_; | 270 int line_height_; |
| 258 bool is_multi_line_; | 271 bool is_multi_line_; |
| 272 bool is_obscured_; |
| 259 bool allow_character_break_; | 273 bool allow_character_break_; |
| 260 ElideBehavior elide_behavior_; | 274 ElideBehavior elide_behavior_; |
| 261 gfx::HorizontalAlignment horizontal_alignment_; | 275 gfx::HorizontalAlignment horizontal_alignment_; |
| 262 base::string16 tooltip_text_; | 276 base::string16 tooltip_text_; |
| 263 // Whether to collapse the label when it's not visible. | 277 // Whether to collapse the label when it's not visible. |
| 264 bool collapse_when_hidden_; | 278 bool collapse_when_hidden_; |
| 265 // The following member variable is used to control whether the | 279 // The following member variable is used to control whether the |
| 266 // directionality is auto-detected based on first strong directionality | 280 // directionality is auto-detected based on first strong directionality |
| 267 // character or is determined by chrome UI's locale. | 281 // character or is determined by chrome UI's locale. |
| 268 DirectionalityMode directionality_mode_; | 282 DirectionalityMode directionality_mode_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 280 // The cached heights to avoid recalculation in GetHeightForWidth(). | 294 // The cached heights to avoid recalculation in GetHeightForWidth(). |
| 281 std::vector<gfx::Size> cached_heights_; | 295 std::vector<gfx::Size> cached_heights_; |
| 282 int cached_heights_cursor_; | 296 int cached_heights_cursor_; |
| 283 | 297 |
| 284 DISALLOW_COPY_AND_ASSIGN(Label); | 298 DISALLOW_COPY_AND_ASSIGN(Label); |
| 285 }; | 299 }; |
| 286 | 300 |
| 287 } // namespace views | 301 } // namespace views |
| 288 | 302 |
| 289 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 303 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
| OLD | NEW |