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

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: rebase for epic ash file move Created 3 years, 8 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_LABEL);
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 Label* label() const { return label_; } 112 Label* label() const { return label_; }
110 113
111 bool explicitly_set_normal_color() const { 114 bool explicitly_set_normal_color() const {
112 return explicitly_set_colors_[STATE_NORMAL]; 115 return explicitly_set_colors_[STATE_NORMAL];
113 } 116 }
114 117
115 // Returns the available area for the label and image. Subclasses can change 118 // Returns the available area for the label and image. Subclasses can change
116 // these bounds if they need room to do manual painting. 119 // these bounds if they need room to do manual painting.
117 virtual gfx::Rect GetChildAreaBounds(); 120 virtual gfx::Rect GetChildAreaBounds();
118 121
119 // Sets the font list used by this button.
120 virtual void SetFontList(const gfx::FontList& font_list);
121
122 // View: 122 // View:
123 void OnPaint(gfx::Canvas* canvas) override; 123 void OnPaint(gfx::Canvas* canvas) override;
124 void OnFocus() override; 124 void OnFocus() override;
125 void OnBlur() override; 125 void OnBlur() override;
126 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; 126 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
127 127
128 // CustomButton: 128 // CustomButton:
129 void StateChanged(ButtonState old_state) override; 129 void StateChanged(ButtonState old_state) override;
130 130
131 // Fills |params| with information about the button. 131 // Fills |params| with information about the button.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 // The image and label shown in the button. 187 // The image and label shown in the button.
188 ImageView* image_; 188 ImageView* image_;
189 Label* label_; 189 Label* label_;
190 190
191 // A separate view is necessary to hold the ink drop layer so that it can 191 // A separate view is necessary to hold the ink drop layer so that it can
192 // be stacked below |image_| and on top of |label_|, without resorting to 192 // be stacked below |image_| and on top of |label_|, without resorting to
193 // drawing |label_| on a layer (which can mess with subpixel anti-aliasing). 193 // drawing |label_| on a layer (which can mess with subpixel anti-aliasing).
194 InkDropContainerView* ink_drop_container_; 194 InkDropContainerView* ink_drop_container_;
195 195
196 // The cached font lists in the normal and bold style. 196 // The cached font lists in the normal and default button style. The latter
197 // may be bold.
197 gfx::FontList cached_normal_font_list_; 198 gfx::FontList cached_normal_font_list_;
198 gfx::FontList cached_bold_font_list_; 199 gfx::FontList cached_default_button_font_list_;
199 200
200 // The images and colors for each button state. 201 // The images and colors for each button state.
201 gfx::ImageSkia button_state_images_[STATE_COUNT]; 202 gfx::ImageSkia button_state_images_[STATE_COUNT];
202 SkColor button_state_colors_[STATE_COUNT]; 203 SkColor button_state_colors_[STATE_COUNT];
203 204
204 // Used to track whether SetTextColor() has been invoked. 205 // Used to track whether SetTextColor() has been invoked.
205 std::array<bool, STATE_COUNT> explicitly_set_colors_; 206 std::array<bool, STATE_COUNT> explicitly_set_colors_;
206 207
207 // |min_size_| increases monotonically with the preferred size. 208 // |min_size_| increases monotonically with the preferred size.
208 mutable gfx::Size min_size_; 209 mutable gfx::Size min_size_;
(...skipping 25 matching lines...) Expand all
234 gfx::HorizontalAlignment horizontal_alignment_; 235 gfx::HorizontalAlignment horizontal_alignment_;
235 236
236 std::unique_ptr<Painter> focus_painter_; 237 std::unique_ptr<Painter> focus_painter_;
237 238
238 DISALLOW_COPY_AND_ASSIGN(LabelButton); 239 DISALLOW_COPY_AND_ASSIGN(LabelButton);
239 }; 240 };
240 241
241 } // namespace views 242 } // namespace views
242 243
243 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ 244 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698