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[]; |
| 24 |
23 LabelButton(ButtonListener* listener, const string16& text); | 25 LabelButton(ButtonListener* listener, const string16& text); |
24 virtual ~LabelButton(); | 26 virtual ~LabelButton(); |
25 | 27 |
26 // Get or set the image shown for the specified button state. | 28 // Get or set the image shown for the specified button state. |
27 // 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. |
28 const gfx::ImageSkia& GetImage(ButtonState for_state); | 30 const gfx::ImageSkia& GetImage(ButtonState for_state); |
29 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); | 31 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); |
30 | 32 |
31 // Get or set the text shown on the button. | 33 // Get or set the text shown on the button. |
32 const string16& GetText() const; | 34 const string16& GetText() const; |
(...skipping 16 matching lines...) Expand all Loading... |
49 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); | 51 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); |
50 | 52 |
51 // 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. |
52 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; } |
53 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; } |
54 | 56 |
55 // 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. |
56 bool default_button() const { return default_button_; } | 58 bool default_button() const { return default_button_; } |
57 void SetDefaultButton(bool default_button); | 59 void SetDefaultButton(bool default_button); |
58 | 60 |
59 // Get or set the option to use a native button appearance; false by default. | 61 // Get or set the button's overall style; the default is |STYLE_TEXTBUTTON|. |
60 bool native_theme() const { return native_theme_; } | 62 ButtonStyle style() const { return style_; } |
61 void SetNativeTheme(bool native_theme); | 63 void SetStyle(ButtonStyle style); |
62 | 64 |
63 // Overridden from View: | 65 // Overridden from View: |
64 virtual gfx::Size GetPreferredSize() OVERRIDE; | 66 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 67 virtual std::string GetClassName() const OVERRIDE; |
65 | 68 |
66 private: | 69 private: |
67 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); | 70 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); |
68 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); | 71 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); |
69 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); | 72 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); |
70 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); | 73 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); |
71 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Font); | 74 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Font); |
72 | 75 |
73 // Resets colors from the NativeTheme, explicitly set colors are unchanged. | 76 // Resets colors from the NativeTheme, explicitly set colors are unchanged. |
74 void ResetColorsFromNativeTheme(); | 77 void ResetColorsFromNativeTheme(); |
75 | 78 |
76 // Overridden from CustomButton: | 79 // Overridden from CustomButton: |
77 virtual void StateChanged() OVERRIDE; | 80 virtual void StateChanged() OVERRIDE; |
78 | 81 |
79 // Overridden from View: | 82 // Overridden from View: |
80 virtual void Layout() OVERRIDE; | 83 virtual void Layout() OVERRIDE; |
81 virtual std::string GetClassName() const OVERRIDE; | |
82 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 84 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
83 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; | 85 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; |
84 | 86 |
85 // Overridden from NativeThemeDelegate: | 87 // Overridden from NativeThemeDelegate: |
86 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; | 88 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; |
87 virtual gfx::Rect GetThemePaintRect() const OVERRIDE; | 89 virtual gfx::Rect GetThemePaintRect() const OVERRIDE; |
88 virtual ui::NativeTheme::State GetThemeState( | 90 virtual ui::NativeTheme::State GetThemeState( |
89 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | 91 ui::NativeTheme::ExtraParams* params) const OVERRIDE; |
90 virtual const ui::Animation* GetThemeAnimation() const OVERRIDE; | 92 virtual const ui::Animation* GetThemeAnimation() const OVERRIDE; |
91 virtual ui::NativeTheme::State GetBackgroundThemeState( | 93 virtual ui::NativeTheme::State GetBackgroundThemeState( |
(...skipping 16 matching lines...) Expand all Loading... |
108 bool explicitly_set_colors_[STATE_COUNT]; | 110 bool explicitly_set_colors_[STATE_COUNT]; |
109 | 111 |
110 // |min_size_| increases monotonically with the preferred size. | 112 // |min_size_| increases monotonically with the preferred size. |
111 gfx::Size min_size_; | 113 gfx::Size min_size_; |
112 // |max_size_| may be set to clamp the preferred size. | 114 // |max_size_| may be set to clamp the preferred size. |
113 gfx::Size max_size_; | 115 gfx::Size max_size_; |
114 | 116 |
115 // Flag indicating default handling of the return key via an accelerator. | 117 // Flag indicating default handling of the return key via an accelerator. |
116 bool default_button_; | 118 bool default_button_; |
117 | 119 |
118 // Flag indicating native theme styling (or Views styling) of the button. | 120 // The button's overall style. |
119 bool native_theme_; | 121 ButtonStyle style_; |
120 | 122 |
121 DISALLOW_COPY_AND_ASSIGN(LabelButton); | 123 DISALLOW_COPY_AND_ASSIGN(LabelButton); |
122 }; | 124 }; |
123 | 125 |
124 } // namespace views | 126 } // namespace views |
125 | 127 |
126 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | 128 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
OLD | NEW |