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_BUTTON_LABEL_BUTTON_H_ | 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
6 #define UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | 6 #define UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
10 #include "ui/gfx/font.h" | 10 #include "ui/gfx/font.h" |
11 #include "ui/gfx/image/image_skia.h" | 11 #include "ui/gfx/image/image_skia.h" |
12 #include "ui/views/controls/button/custom_button.h" | 12 #include "ui/views/controls/button/custom_button.h" |
13 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
14 #include "ui/views/controls/label.h" | 14 #include "ui/views/controls/label.h" |
15 #include "ui/views/native_theme_delegate.h" | 15 #include "ui/views/native_theme_delegate.h" |
16 | 16 |
17 namespace views { | 17 namespace views { |
18 | 18 |
19 // LabelButton is an alternative to TextButton, it's not focusable by default. | 19 // LabelButton is an alternative to TextButton, it's not focusable by default. |
20 class VIEWS_EXPORT LabelButton : public CustomButton, | 20 class VIEWS_EXPORT LabelButton : public CustomButton, |
21 public NativeThemeDelegate { | 21 public NativeThemeDelegate { |
22 public: | 22 public: |
23 static const char kViewClassName[]; | 23 static const char kViewClassName[]; |
24 | 24 |
25 LabelButton(ButtonListener* listener, const string16& text); | 25 LabelButton(ButtonListener* listener, const string16& text); |
26 virtual ~LabelButton(); | 26 virtual ~LabelButton(); |
27 | 27 |
28 // Get or set the image shown for the specified button state. | 28 // Get or set the image shown for the specified button state. |
29 // GetImage returns the image for STATE_NORMAL if the state's image is empty. | 29 // GetImage returns the image for STATE_NORMAL if the state's image is empty. |
30 const gfx::ImageSkia& GetImage(ButtonState for_state); | 30 virtual const gfx::ImageSkia& GetImage(ButtonState for_state); |
31 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); | 31 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); |
32 | 32 |
33 // Get or set the text shown on the button. | 33 // Get or set the text shown on the button. |
34 const string16& GetText() const; | 34 const string16& GetText() const; |
35 void SetText(const string16& text); | 35 void SetText(const string16& text); |
36 | 36 |
37 // Set the text color shown for the specified button state. | 37 // Set the text color shown for the specified button state. |
38 void SetTextColor(ButtonState for_state, SkColor color); | 38 void SetTextColor(ButtonState for_state, SkColor color); |
39 | 39 |
40 // Get or set the text's multi-line property to break on '\n', etc. | 40 // Get or set the text's multi-line property to break on '\n', etc. |
41 bool GetTextMultiLine() const; | 41 bool GetTextMultiLine() const; |
42 void SetTextMultiLine(bool text_multi_line); | 42 void SetTextMultiLine(bool text_multi_line); |
43 | 43 |
44 // Get or set the font used by this button. | 44 // Get or set the font used by this button. |
45 const gfx::Font& GetFont() const; | 45 const gfx::Font& GetFont() const; |
46 void SetFont(const gfx::Font& font); | 46 void SetFont(const gfx::Font& font); |
47 | 47 |
48 // Get or set the horizontal alignment used for the button. | 48 // Get or set the horizontal alignment used for the button; reversed in RTL. |
49 // The optional image will lead the text, unless the button is right-aligned. | 49 // The optional image will lead the text, unless the button is right-aligned. |
50 gfx::HorizontalAlignment GetHorizontalAlignment() const; | 50 gfx::HorizontalAlignment GetHorizontalAlignment() const; |
51 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); | 51 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); |
52 | 52 |
53 // Call set_min_size(gfx::Size()) to clear the monotonically increasing size. | 53 // Call set_min_size(gfx::Size()) to clear the monotonically increasing size. |
54 void set_min_size(const gfx::Size& min_size) { min_size_ = min_size; } | 54 void set_min_size(const gfx::Size& min_size) { min_size_ = min_size; } |
55 void set_max_size(const gfx::Size& max_size) { max_size_ = max_size; } | 55 void set_max_size(const gfx::Size& max_size) { max_size_ = max_size; } |
56 | 56 |
57 // Get or set the option to handle the return key; false by default. | 57 // Get or set the option to handle the return key; false by default. |
58 bool is_default() const { return is_default_; } | 58 bool is_default() const { return is_default_; } |
59 void SetIsDefault(bool is_default); | 59 void SetIsDefault(bool is_default); |
60 | 60 |
61 // Get or set the button's overall style; the default is |STYLE_TEXTBUTTON|. | 61 // Get or set the button's overall style; the default is |STYLE_TEXTBUTTON|. |
62 ButtonStyle style() const { return style_; } | 62 ButtonStyle style() const { return style_; } |
63 void SetStyle(ButtonStyle style); | 63 void SetStyle(ButtonStyle style); |
64 | 64 |
65 // Overridden from View: | 65 // Overridden from View: |
66 virtual gfx::Size GetPreferredSize() OVERRIDE; | 66 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 67 virtual void Layout() OVERRIDE; |
67 virtual const char* GetClassName() const OVERRIDE; | 68 virtual const char* GetClassName() const OVERRIDE; |
68 | 69 |
| 70 protected: |
| 71 Label* label() const { return label_; } |
| 72 |
| 73 // Fill |params| with information about the button. |
| 74 virtual void GetExtraParams(ui::NativeTheme::ExtraParams* params) const; |
| 75 |
| 76 // Updates the image view to contain the appropriate button state image. |
| 77 void UpdateImage(); |
| 78 |
69 private: | 79 private: |
70 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); | 80 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); |
71 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); | 81 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); |
72 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); | 82 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); |
73 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); | 83 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); |
74 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Font); | 84 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Font); |
75 | 85 |
76 // Resets colors from the NativeTheme, explicitly set colors are unchanged. | 86 // Resets colors from the NativeTheme, explicitly set colors are unchanged. |
77 void ResetColorsFromNativeTheme(); | 87 void ResetColorsFromNativeTheme(); |
78 | 88 |
79 // Overridden from CustomButton: | 89 // Overridden from CustomButton: |
80 virtual void StateChanged() OVERRIDE; | 90 virtual void StateChanged() OVERRIDE; |
81 | 91 |
82 // Overridden from View: | 92 // Overridden from View: |
83 virtual void Layout() OVERRIDE; | |
84 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 93 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
85 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; | 94 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; |
86 | 95 |
87 // Overridden from NativeThemeDelegate: | 96 // Overridden from NativeThemeDelegate: |
88 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; | 97 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; |
89 virtual gfx::Rect GetThemePaintRect() const OVERRIDE; | 98 virtual gfx::Rect GetThemePaintRect() const OVERRIDE; |
90 virtual ui::NativeTheme::State GetThemeState( | 99 virtual ui::NativeTheme::State GetThemeState( |
91 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | 100 ui::NativeTheme::ExtraParams* params) const OVERRIDE; |
92 virtual const ui::Animation* GetThemeAnimation() const OVERRIDE; | 101 virtual const ui::Animation* GetThemeAnimation() const OVERRIDE; |
93 virtual ui::NativeTheme::State GetBackgroundThemeState( | 102 virtual ui::NativeTheme::State GetBackgroundThemeState( |
94 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | 103 ui::NativeTheme::ExtraParams* params) const OVERRIDE; |
95 virtual ui::NativeTheme::State GetForegroundThemeState( | 104 virtual ui::NativeTheme::State GetForegroundThemeState( |
96 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | 105 ui::NativeTheme::ExtraParams* params) const OVERRIDE; |
97 | 106 |
98 // Fill |params| with information about the button. | |
99 virtual void GetExtraParams(ui::NativeTheme::ExtraParams* params) const; | |
100 | |
101 // The image and label shown in the button. | 107 // The image and label shown in the button. |
102 ImageView* image_; | 108 ImageView* image_; |
103 Label* label_; | 109 Label* label_; |
104 | 110 |
105 // The images and colors for each button state. | 111 // The images and colors for each button state. |
106 gfx::ImageSkia button_state_images_[STATE_COUNT]; | 112 gfx::ImageSkia button_state_images_[STATE_COUNT]; |
107 SkColor button_state_colors_[STATE_COUNT]; | 113 SkColor button_state_colors_[STATE_COUNT]; |
108 | 114 |
109 // Used to track whether SetTextColor() has been invoked. | 115 // Used to track whether SetTextColor() has been invoked. |
110 bool explicitly_set_colors_[STATE_COUNT]; | 116 bool explicitly_set_colors_[STATE_COUNT]; |
(...skipping 10 matching lines...) Expand all Loading... |
121 | 127 |
122 // The button's overall style. | 128 // The button's overall style. |
123 ButtonStyle style_; | 129 ButtonStyle style_; |
124 | 130 |
125 DISALLOW_COPY_AND_ASSIGN(LabelButton); | 131 DISALLOW_COPY_AND_ASSIGN(LabelButton); |
126 }; | 132 }; |
127 | 133 |
128 } // namespace views | 134 } // namespace views |
129 | 135 |
130 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | 136 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
OLD | NEW |