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 const gfx::ImageSkia& GetFocusedImage(ButtonState for_state); | |
31 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); | 32 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); |
33 void SetFocusedImage(ButtonState for_state, const gfx::ImageSkia& image); | |
32 | 34 |
33 // Get or set the text shown on the button. | 35 // Get or set the text shown on the button. |
34 const string16& GetText() const; | 36 const string16& GetText() const; |
35 void SetText(const string16& text); | 37 void SetText(const string16& text); |
36 | 38 |
37 // Set the text color shown for the specified button state. | 39 // Set the text color shown for the specified button state. |
38 void SetTextColor(ButtonState for_state, SkColor color); | 40 void SetTextColor(ButtonState for_state, SkColor color); |
39 | 41 |
40 // Get or set the text's multi-line property to break on '\n', etc. | 42 // Get or set the text's multi-line property to break on '\n', etc. |
41 bool GetTextMultiLine() const; | 43 bool GetTextMultiLine() const; |
(...skipping 17 matching lines...) Expand all Loading... | |
59 void SetIsDefault(bool is_default); | 61 void SetIsDefault(bool is_default); |
60 | 62 |
61 // Get or set the button's overall style; the default is |STYLE_TEXTBUTTON|. | 63 // Get or set the button's overall style; the default is |STYLE_TEXTBUTTON|. |
62 ButtonStyle style() const { return style_; } | 64 ButtonStyle style() const { return style_; } |
63 void SetStyle(ButtonStyle style); | 65 void SetStyle(ButtonStyle style); |
64 | 66 |
65 // Overridden from View: | 67 // Overridden from View: |
66 virtual gfx::Size GetPreferredSize() OVERRIDE; | 68 virtual gfx::Size GetPreferredSize() OVERRIDE; |
67 virtual const char* GetClassName() const OVERRIDE; | 69 virtual const char* GetClassName() const OVERRIDE; |
68 | 70 |
71 protected: | |
72 // Fill |params| with information about the button. | |
73 virtual void GetExtraParams(ui::NativeTheme::ExtraParams* params) const; | |
74 | |
75 // The image shown in the button. | |
76 ImageView* image_; | |
77 | |
69 private: | 78 private: |
70 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); | 79 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); |
71 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); | 80 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); |
72 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); | 81 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); |
73 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); | 82 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); |
74 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Font); | 83 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Font); |
75 | 84 |
76 // Resets colors from the NativeTheme, explicitly set colors are unchanged. | 85 // Resets colors from the NativeTheme, explicitly set colors are unchanged. |
77 void ResetColorsFromNativeTheme(); | 86 void ResetColorsFromNativeTheme(); |
78 | 87 |
79 // Overridden from CustomButton: | 88 // Overridden from CustomButton: |
80 virtual void StateChanged() OVERRIDE; | 89 virtual void StateChanged() OVERRIDE; |
81 | 90 |
82 // Overridden from View: | 91 // Overridden from View: |
83 virtual void Layout() OVERRIDE; | 92 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. | 107 // The image shown in the button. |
msw
2013/05/18 03:46:30
nit: s/image/label/
tfarina
2013/05/18 18:43:23
Done.
| |
99 virtual void GetExtraParams(ui::NativeTheme::ExtraParams* params) const; | |
100 | |
101 // The image and label shown in the button. | |
102 ImageView* image_; | |
103 Label* label_; | 108 Label* label_; |
104 | 109 |
105 // The images and colors for each button state. | 110 // The images and colors for each button state. |
106 gfx::ImageSkia button_state_images_[STATE_COUNT]; | 111 gfx::ImageSkia button_state_images_[2][STATE_COUNT]; |
107 SkColor button_state_colors_[STATE_COUNT]; | 112 SkColor button_state_colors_[STATE_COUNT]; |
108 | 113 |
109 // Used to track whether SetTextColor() has been invoked. | 114 // Used to track whether SetTextColor() has been invoked. |
110 bool explicitly_set_colors_[STATE_COUNT]; | 115 bool explicitly_set_colors_[STATE_COUNT]; |
111 | 116 |
112 // |min_size_| increases monotonically with the preferred size. | 117 // |min_size_| increases monotonically with the preferred size. |
113 gfx::Size min_size_; | 118 gfx::Size min_size_; |
114 // |max_size_| may be set to clamp the preferred size. | 119 // |max_size_| may be set to clamp the preferred size. |
115 gfx::Size max_size_; | 120 gfx::Size max_size_; |
116 | 121 |
117 // Flag indicating default handling of the return key via an accelerator. | 122 // Flag indicating default handling of the return key via an accelerator. |
118 // Whether or not the button appears or behaves as the default button in its | 123 // Whether or not the button appears or behaves as the default button in its |
119 // current context; | 124 // current context; |
120 bool is_default_; | 125 bool is_default_; |
121 | 126 |
122 // The button's overall style. | 127 // The button's overall style. |
123 ButtonStyle style_; | 128 ButtonStyle style_; |
124 | 129 |
125 DISALLOW_COPY_AND_ASSIGN(LabelButton); | 130 DISALLOW_COPY_AND_ASSIGN(LabelButton); |
126 }; | 131 }; |
127 | 132 |
128 } // namespace views | 133 } // namespace views |
129 | 134 |
130 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | 135 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
OLD | NEW |