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 "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // LabelButton is a button with text and an icon, it's not focusable by default. | 22 // LabelButton is a button with text and an icon, it's not focusable by default. |
23 class VIEWS_EXPORT LabelButton : public CustomButton, | 23 class VIEWS_EXPORT LabelButton : public CustomButton, |
24 public NativeThemeDelegate { | 24 public NativeThemeDelegate { |
25 public: | 25 public: |
26 // The length of the hover fade animation. | 26 // The length of the hover fade animation. |
27 static const int kHoverAnimationDurationMs; | 27 static const int kHoverAnimationDurationMs; |
28 | 28 |
29 static const char kViewClassName[]; | 29 static const char kViewClassName[]; |
30 | 30 |
31 LabelButton(ButtonListener* listener, const base::string16& text); | 31 LabelButton(ButtonListener* listener, const base::string16& text); |
32 virtual ~LabelButton(); | 32 ~LabelButton() override; |
33 | 33 |
34 // Get or set the image shown for the specified button state. | 34 // Get or set the image shown for the specified button state. |
35 // GetImage returns the image for STATE_NORMAL if the state's image is empty. | 35 // GetImage returns the image for STATE_NORMAL if the state's image is empty. |
36 virtual const gfx::ImageSkia& GetImage(ButtonState for_state); | 36 virtual const gfx::ImageSkia& GetImage(ButtonState for_state); |
37 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); | 37 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); |
38 | 38 |
39 // Get or set the text shown on the button. | 39 // Get or set the text shown on the button. |
40 const base::string16& GetText() const; | 40 const base::string16& GetText() const; |
41 virtual void SetText(const base::string16& text); | 41 virtual void SetText(const base::string16& text); |
42 | 42 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 // Set the spacing between the image and the text. Shrinking the spacing | 80 // Set the spacing between the image and the text. Shrinking the spacing |
81 // will not shrink the overall button size, as it is monotonically increasing. | 81 // will not shrink the overall button size, as it is monotonically increasing. |
82 // Call SetMinSize(gfx::Size()) to clear the size if needed. | 82 // Call SetMinSize(gfx::Size()) to clear the size if needed. |
83 void SetImageLabelSpacing(int spacing); | 83 void SetImageLabelSpacing(int spacing); |
84 | 84 |
85 void SetFocusPainter(scoped_ptr<Painter> focus_painter); | 85 void SetFocusPainter(scoped_ptr<Painter> focus_painter); |
86 Painter* focus_painter() { return focus_painter_.get(); } | 86 Painter* focus_painter() { return focus_painter_.get(); } |
87 | 87 |
88 // View: | 88 // View: |
89 virtual void SetBorder(scoped_ptr<Border> border) override; | 89 void SetBorder(scoped_ptr<Border> border) override; |
90 virtual gfx::Size GetPreferredSize() const override; | 90 gfx::Size GetPreferredSize() const override; |
91 virtual int GetHeightForWidth(int w) const override; | 91 int GetHeightForWidth(int w) const override; |
92 virtual void Layout() override; | 92 void Layout() override; |
93 virtual const char* GetClassName() const override; | 93 const char* GetClassName() const override; |
94 | 94 |
95 protected: | 95 protected: |
96 ImageView* image() const { return image_; } | 96 ImageView* image() const { return image_; } |
97 Label* label() const { return label_; } | 97 Label* label() const { return label_; } |
98 | 98 |
99 // Returns the available area for the label and image. Subclasses can change | 99 // Returns the available area for the label and image. Subclasses can change |
100 // these bounds if they need room to do manual painting. | 100 // these bounds if they need room to do manual painting. |
101 virtual gfx::Rect GetChildAreaBounds(); | 101 virtual gfx::Rect GetChildAreaBounds(); |
102 | 102 |
103 // View: | 103 // View: |
104 virtual void OnPaint(gfx::Canvas* canvas) override; | 104 void OnPaint(gfx::Canvas* canvas) override; |
105 virtual void OnFocus() override; | 105 void OnFocus() override; |
106 virtual void OnBlur() override; | 106 void OnBlur() override; |
107 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 107 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
108 | 108 |
109 // Fill |params| with information about the button. | 109 // Fill |params| with information about the button. |
110 virtual void GetExtraParams(ui::NativeTheme::ExtraParams* params) const; | 110 virtual void GetExtraParams(ui::NativeTheme::ExtraParams* params) const; |
111 | 111 |
112 // Resets colors from the NativeTheme, explicitly set colors are unchanged. | 112 // Resets colors from the NativeTheme, explicitly set colors are unchanged. |
113 virtual void ResetColorsFromNativeTheme(); | 113 virtual void ResetColorsFromNativeTheme(); |
114 | 114 |
115 // Creates the default border for this button. This can be overridden by | 115 // Creates the default border for this button. This can be overridden by |
116 // subclasses or by LinuxUI. | 116 // subclasses or by LinuxUI. |
117 virtual scoped_ptr<LabelButtonBorder> CreateDefaultBorder() const; | 117 virtual scoped_ptr<LabelButtonBorder> CreateDefaultBorder() const; |
118 | 118 |
119 // Updates the image view to contain the appropriate button state image. | 119 // Updates the image view to contain the appropriate button state image. |
120 void UpdateImage(); | 120 void UpdateImage(); |
121 | 121 |
122 // Updates the border as per the NativeTheme, unless a different border was | 122 // Updates the border as per the NativeTheme, unless a different border was |
123 // set with SetBorder. | 123 // set with SetBorder. |
124 void UpdateThemedBorder(); | 124 void UpdateThemedBorder(); |
125 | 125 |
126 // NativeThemeDelegate: | 126 // NativeThemeDelegate: |
127 virtual gfx::Rect GetThemePaintRect() const override; | 127 gfx::Rect GetThemePaintRect() const override; |
128 | 128 |
129 private: | 129 private: |
130 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); | 130 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); |
131 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); | 131 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Label); |
132 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); | 132 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image); |
133 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); | 133 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage); |
134 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, FontList); | 134 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, FontList); |
135 | 135 |
136 // CustomButton: | 136 // CustomButton: |
137 virtual void StateChanged() override; | 137 void StateChanged() override; |
138 | 138 |
139 // View: | 139 // View: |
140 virtual void ChildPreferredSizeChanged(View* child) override; | 140 void ChildPreferredSizeChanged(View* child) override; |
141 | 141 |
142 // NativeThemeDelegate: | 142 // NativeThemeDelegate: |
143 virtual ui::NativeTheme::Part GetThemePart() const override; | 143 ui::NativeTheme::Part GetThemePart() const override; |
144 virtual ui::NativeTheme::State GetThemeState( | 144 ui::NativeTheme::State GetThemeState( |
145 ui::NativeTheme::ExtraParams* params) const override; | 145 ui::NativeTheme::ExtraParams* params) const override; |
146 virtual const gfx::Animation* GetThemeAnimation() const override; | 146 const gfx::Animation* GetThemeAnimation() const override; |
147 virtual ui::NativeTheme::State GetBackgroundThemeState( | 147 ui::NativeTheme::State GetBackgroundThemeState( |
148 ui::NativeTheme::ExtraParams* params) const override; | 148 ui::NativeTheme::ExtraParams* params) const override; |
149 virtual ui::NativeTheme::State GetForegroundThemeState( | 149 ui::NativeTheme::State GetForegroundThemeState( |
150 ui::NativeTheme::ExtraParams* params) const override; | 150 ui::NativeTheme::ExtraParams* params) const override; |
151 | 151 |
152 // Resets |cached_preferred_size_| and marks |cached_preferred_size_valid_| | 152 // Resets |cached_preferred_size_| and marks |cached_preferred_size_valid_| |
153 // as false. | 153 // as false. |
154 void ResetCachedPreferredSize(); | 154 void ResetCachedPreferredSize(); |
155 | 155 |
156 // The image and label shown in the button. | 156 // The image and label shown in the button. |
157 ImageView* image_; | 157 ImageView* image_; |
158 Label* label_; | 158 Label* label_; |
159 | 159 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 int image_label_spacing_; | 192 int image_label_spacing_; |
193 | 193 |
194 scoped_ptr<Painter> focus_painter_; | 194 scoped_ptr<Painter> focus_painter_; |
195 | 195 |
196 DISALLOW_COPY_AND_ASSIGN(LabelButton); | 196 DISALLOW_COPY_AND_ASSIGN(LabelButton); |
197 }; | 197 }; |
198 | 198 |
199 } // namespace views | 199 } // namespace views |
200 | 200 |
201 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | 201 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ |
OLD | NEW |