Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: ui/views/controls/button/label_button.h

Issue 15061006: views: Switch Checkbox over to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes per review Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.
(...skipping 18 matching lines...) Expand all
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 const char* GetClassName() const OVERRIDE; 67 virtual const char* GetClassName() const OVERRIDE;
68 68
69 protected:
70 // Fill |params| with information about the button.
71 virtual void GetExtraParams(ui::NativeTheme::ExtraParams* params) const;
72
73 // The image shown in the button.
74 ImageView* image_;
msw 2013/05/21 02:24:11 nit: revert this change to expose |image_|, I thin
75
69 private: 76 private:
70 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); 77 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init);
71 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); 78 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label);
72 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); 79 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image);
73 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); 80 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage);
74 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Font); 81 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Font);
75 82
76 // Resets colors from the NativeTheme, explicitly set colors are unchanged. 83 // Resets colors from the NativeTheme, explicitly set colors are unchanged.
77 void ResetColorsFromNativeTheme(); 84 void ResetColorsFromNativeTheme();
78 85
79 // Overridden from CustomButton: 86 // Overridden from CustomButton:
80 virtual void StateChanged() OVERRIDE; 87 virtual void StateChanged() OVERRIDE;
81 88
82 // Overridden from View: 89 // Overridden from View:
83 virtual void Layout() OVERRIDE; 90 virtual void Layout() OVERRIDE;
84 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; 91 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
85 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; 92 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE;
86 93
87 // Overridden from NativeThemeDelegate: 94 // Overridden from NativeThemeDelegate:
88 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; 95 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE;
89 virtual gfx::Rect GetThemePaintRect() const OVERRIDE; 96 virtual gfx::Rect GetThemePaintRect() const OVERRIDE;
90 virtual ui::NativeTheme::State GetThemeState( 97 virtual ui::NativeTheme::State GetThemeState(
91 ui::NativeTheme::ExtraParams* params) const OVERRIDE; 98 ui::NativeTheme::ExtraParams* params) const OVERRIDE;
92 virtual const ui::Animation* GetThemeAnimation() const OVERRIDE; 99 virtual const ui::Animation* GetThemeAnimation() const OVERRIDE;
93 virtual ui::NativeTheme::State GetBackgroundThemeState( 100 virtual ui::NativeTheme::State GetBackgroundThemeState(
94 ui::NativeTheme::ExtraParams* params) const OVERRIDE; 101 ui::NativeTheme::ExtraParams* params) const OVERRIDE;
95 virtual ui::NativeTheme::State GetForegroundThemeState( 102 virtual ui::NativeTheme::State GetForegroundThemeState(
96 ui::NativeTheme::ExtraParams* params) const OVERRIDE; 103 ui::NativeTheme::ExtraParams* params) const OVERRIDE;
97 104
98 // Fill |params| with information about the button. 105 // The label shown in the button.
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_; 106 Label* label_;
104 107
105 // The images and colors for each button state. 108 // The images and colors for each button state.
106 gfx::ImageSkia button_state_images_[STATE_COUNT]; 109 gfx::ImageSkia button_state_images_[STATE_COUNT];
107 SkColor button_state_colors_[STATE_COUNT]; 110 SkColor button_state_colors_[STATE_COUNT];
108 111
109 // Used to track whether SetTextColor() has been invoked. 112 // Used to track whether SetTextColor() has been invoked.
110 bool explicitly_set_colors_[STATE_COUNT]; 113 bool explicitly_set_colors_[STATE_COUNT];
111 114
112 // |min_size_| increases monotonically with the preferred size. 115 // |min_size_| increases monotonically with the preferred size.
113 gfx::Size min_size_; 116 gfx::Size min_size_;
114 // |max_size_| may be set to clamp the preferred size. 117 // |max_size_| may be set to clamp the preferred size.
115 gfx::Size max_size_; 118 gfx::Size max_size_;
116 119
117 // Flag indicating default handling of the return key via an accelerator. 120 // 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 121 // Whether or not the button appears or behaves as the default button in its
119 // current context; 122 // current context;
120 bool is_default_; 123 bool is_default_;
121 124
122 // The button's overall style. 125 // The button's overall style.
123 ButtonStyle style_; 126 ButtonStyle style_;
124 127
125 DISALLOW_COPY_AND_ASSIGN(LabelButton); 128 DISALLOW_COPY_AND_ASSIGN(LabelButton);
126 }; 129 };
127 130
128 } // namespace views 131 } // namespace views
129 132
130 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ 133 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698