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

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

Issue 2801583002: Use views::style for buttons, bootstrap ash_typography to do so. (Closed)
Patch Set: placate gn check. new_avatar_button now just avatar_button Created 3 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
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 <array> 8 #include <array>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/image/image_skia.h" 15 #include "ui/gfx/image/image_skia.h"
16 #include "ui/views/controls/button/custom_button.h" 16 #include "ui/views/controls/button/custom_button.h"
17 #include "ui/views/controls/image_view.h" 17 #include "ui/views/controls/image_view.h"
18 #include "ui/views/controls/label.h" 18 #include "ui/views/controls/label.h"
19 #include "ui/views/native_theme_delegate.h" 19 #include "ui/views/native_theme_delegate.h"
20 #include "ui/views/style/typography.h"
20 21
21 namespace views { 22 namespace views {
22 23
23 class InkDropContainerView; 24 class InkDropContainerView;
24 class LabelButtonBorder; 25 class LabelButtonBorder;
25 class Painter; 26 class Painter;
26 27
27 // LabelButton is a button with text and an icon, it's not focusable by default. 28 // LabelButton is a button with text and an icon, it's not focusable by default.
28 class VIEWS_EXPORT LabelButton : public CustomButton, 29 class VIEWS_EXPORT LabelButton : public CustomButton,
29 public NativeThemeDelegate { 30 public NativeThemeDelegate {
30 public: 31 public:
31 // The length of the hover fade animation. 32 // The length of the hover fade animation.
32 static const int kHoverAnimationDurationMs; 33 static const int kHoverAnimationDurationMs;
33 34
34 static const char kViewClassName[]; 35 static const char kViewClassName[];
35 36
36 LabelButton(ButtonListener* listener, const base::string16& text); 37 // Creates a LabelButton with ButtonPressed() events sent to |listener| and
38 // label |text|. |button_context| is a value from views::style::TextContext
39 // and determines the appearance of |text|.
40 LabelButton(ButtonListener* listener,
41 const base::string16& text,
42 int button_context = style::CONTEXT_BUTTON);
37 ~LabelButton() override; 43 ~LabelButton() override;
38 44
39 // Gets or sets the image shown for the specified button state. 45 // Gets or sets the image shown for the specified button state.
40 // GetImage returns the image for STATE_NORMAL if the state's image is empty. 46 // GetImage returns the image for STATE_NORMAL if the state's image is empty.
41 virtual gfx::ImageSkia GetImage(ButtonState for_state) const; 47 virtual gfx::ImageSkia GetImage(ButtonState for_state) const;
42 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); 48 void SetImage(ButtonState for_state, const gfx::ImageSkia& image);
43 49
44 // Gets or sets the text shown on the button. 50 // Gets or sets the text shown on the button.
45 const base::string16& GetText() const; 51 const base::string16& GetText() const;
46 virtual void SetText(const base::string16& text); 52 virtual void SetText(const base::string16& text);
47 53
48 // Sets the text color shown for the specified button |for_state| to |color|. 54 // Sets the text color shown for the specified button |for_state| to |color|.
49 void SetTextColor(ButtonState for_state, SkColor color); 55 void SetTextColor(ButtonState for_state, SkColor color);
50 56
51 // Sets the text colors shown for the non-disabled states to |color|. 57 // Sets the text colors shown for the non-disabled states to |color|.
52 virtual void SetEnabledTextColors(SkColor color); 58 virtual void SetEnabledTextColors(SkColor color);
53 59
54 // Sets drop shadows underneath the text. 60 // Sets drop shadows underneath the text.
55 void SetTextShadows(const gfx::ShadowValues& shadows); 61 void SetTextShadows(const gfx::ShadowValues& shadows);
56 62
57 // Sets whether subpixel rendering is used on the label. 63 // Sets whether subpixel rendering is used on the label.
58 void SetTextSubpixelRenderingEnabled(bool enabled); 64 void SetTextSubpixelRenderingEnabled(bool enabled);
59 65
60 // Adjusts the font size up or down by the given amount.
61 virtual void AdjustFontSize(int font_size_delta);
62
63 // Sets the elide behavior of this button. 66 // Sets the elide behavior of this button.
64 void SetElideBehavior(gfx::ElideBehavior elide_behavior); 67 void SetElideBehavior(gfx::ElideBehavior elide_behavior);
65 68
66 // Sets the horizontal alignment used for the button; reversed in RTL. The 69 // Sets the horizontal alignment used for the button; reversed in RTL. The
67 // optional image will lead the text, unless the button is right-aligned. 70 // optional image will lead the text, unless the button is right-aligned.
68 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); 71 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment);
69 72
70 // Call SetMinSize(gfx::Size()) to clear the monotonically increasing size. 73 // Call SetMinSize(gfx::Size()) to clear the monotonically increasing size.
71 void SetMinSize(const gfx::Size& min_size); 74 void SetMinSize(const gfx::Size& min_size);
72 void SetMaxSize(const gfx::Size& max_size); 75 void SetMaxSize(const gfx::Size& max_size);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 117 }
115 118
116 bool explicitly_set_normal_color() const { 119 bool explicitly_set_normal_color() const {
117 return explicitly_set_colors_[STATE_NORMAL]; 120 return explicitly_set_colors_[STATE_NORMAL];
118 } 121 }
119 122
120 // Returns the available area for the label and image. Subclasses can change 123 // Returns the available area for the label and image. Subclasses can change
121 // these bounds if they need room to do manual painting. 124 // these bounds if they need room to do manual painting.
122 virtual gfx::Rect GetChildAreaBounds(); 125 virtual gfx::Rect GetChildAreaBounds();
123 126
124 // Sets the font list used by this button.
125 virtual void SetFontList(const gfx::FontList& font_list);
126
127 // Returns true if the CreateInkDrop*() methods should create flood fill ink 127 // Returns true if the CreateInkDrop*() methods should create flood fill ink
128 // drop components. 128 // drop components.
129 virtual bool ShouldUseFloodFillInkDrop() const; 129 virtual bool ShouldUseFloodFillInkDrop() const;
130 130
131 // View: 131 // View:
132 void OnPaint(gfx::Canvas* canvas) override; 132 void OnPaint(gfx::Canvas* canvas) override;
133 void OnFocus() override; 133 void OnFocus() override;
134 void OnBlur() override; 134 void OnBlur() override;
135 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; 135 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
136 136
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 // The image and label shown in the button. 192 // The image and label shown in the button.
193 ImageView* image_; 193 ImageView* image_;
194 Label* label_; 194 Label* label_;
195 195
196 // A separate view is necessary to hold the ink drop layer so that it can 196 // A separate view is necessary to hold the ink drop layer so that it can
197 // be stacked below |image_| and on top of |label_|, without resorting to 197 // be stacked below |image_| and on top of |label_|, without resorting to
198 // drawing |label_| on a layer (which can mess with subpixel anti-aliasing). 198 // drawing |label_| on a layer (which can mess with subpixel anti-aliasing).
199 InkDropContainerView* ink_drop_container_; 199 InkDropContainerView* ink_drop_container_;
200 200
201 // The cached font lists in the normal and bold style. 201 // The cached font lists in the normal and default button style. The latter
202 // may be bold.
202 gfx::FontList cached_normal_font_list_; 203 gfx::FontList cached_normal_font_list_;
203 gfx::FontList cached_bold_font_list_; 204 gfx::FontList cached_default_button_font_list_;
204 205
205 // The images and colors for each button state. 206 // The images and colors for each button state.
206 gfx::ImageSkia button_state_images_[STATE_COUNT]; 207 gfx::ImageSkia button_state_images_[STATE_COUNT];
207 SkColor button_state_colors_[STATE_COUNT]; 208 SkColor button_state_colors_[STATE_COUNT];
208 209
209 // Used to track whether SetTextColor() has been invoked. 210 // Used to track whether SetTextColor() has been invoked.
210 std::array<bool, STATE_COUNT> explicitly_set_colors_; 211 std::array<bool, STATE_COUNT> explicitly_set_colors_;
211 212
212 // |min_size_| increases monotonically with the preferred size. 213 // |min_size_| increases monotonically with the preferred size.
213 mutable gfx::Size min_size_; 214 mutable gfx::Size min_size_;
(...skipping 25 matching lines...) Expand all
239 gfx::HorizontalAlignment horizontal_alignment_; 240 gfx::HorizontalAlignment horizontal_alignment_;
240 241
241 std::unique_ptr<Painter> focus_painter_; 242 std::unique_ptr<Painter> focus_painter_;
242 243
243 DISALLOW_COPY_AND_ASSIGN(LabelButton); 244 DISALLOW_COPY_AND_ASSIGN(LabelButton);
244 }; 245 };
245 246
246 } // namespace views 247 } // namespace views
247 248
248 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ 249 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698