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

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

Issue 2506133003: [ash-md] Allows ToggleButton to have a border and adds focus rectangle (Closed)
Patch Set: [ash-md] Allows ToggleButton to have a border and adds focus rectangle (use GetContentBounds to cen… Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_TOGGLE_BUTTON_H_ 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_
6 #define UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_ 6 #define UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_
7 7
8 #include "ui/gfx/animation/slide_animation.h" 8 #include "ui/gfx/animation/slide_animation.h"
9 #include "ui/views/controls/button/custom_button.h" 9 #include "ui/views/controls/button/custom_button.h"
10 10
11 namespace views { 11 namespace views {
12 12
13 class Painter;
14
13 // This view presents a button that has two states: on and off. This is similar 15 // This view presents a button that has two states: on and off. This is similar
14 // to a checkbox but has no text and looks more like a two-state horizontal 16 // to a checkbox but has no text and looks more like a two-state horizontal
15 // slider. 17 // slider.
16 class VIEWS_EXPORT ToggleButton : public CustomButton { 18 class VIEWS_EXPORT ToggleButton : public CustomButton {
17 public: 19 public:
18 static const char kViewClassName[]; 20 static const char kViewClassName[];
19 21
20 explicit ToggleButton(ButtonListener* listener); 22 explicit ToggleButton(ButtonListener* listener);
21 ~ToggleButton() override; 23 ~ToggleButton() override;
22 24
23 void SetIsOn(bool is_on, bool animate); 25 void SetIsOn(bool is_on, bool animate);
24 bool is_on() const { return is_on_; } 26 bool is_on() const { return is_on_; }
25 27
28 void set_focus_painter(std::unique_ptr<Painter> focus_painter);
29
30 protected:
31 // View:
32 void OnFocus() override;
Evan Stade 2016/11/17 23:24:36 nit: put these in the same block as the other over
varkha 2016/11/17 23:40:51 Done. Also split View overrides from the CustomBut
33 void OnBlur() override;
34
26 private: 35 private:
27 friend class TestToggleButton; 36 friend class TestToggleButton;
28 class ThumbView; 37 class ThumbView;
29 38
30 // Calculates the bounding box for the thumb (the circle). 39 // Calculates and returns the bounding box for the track.
40 gfx::Rect GetTrackBounds() const;
41
42 // Calculates and returns the bounding box for the thumb (the circle).
31 gfx::Rect GetThumbBounds() const; 43 gfx::Rect GetThumbBounds() const;
32 44
33 // Updates position and color of the thumb. 45 // Updates position and color of the thumb.
34 void UpdateThumb(); 46 void UpdateThumb();
35 47
36 SkColor GetTrackColor(bool is_on) const; 48 SkColor GetTrackColor(bool is_on) const;
37 49
38 // CustomButton: 50 // CustomButton:
39 gfx::Size GetPreferredSize() const override; 51 gfx::Size GetPreferredSize() const override;
40 const char* GetClassName() const override; 52 const char* GetClassName() const override;
41 void OnPaint(gfx::Canvas* canvas) override; 53 void OnPaint(gfx::Canvas* canvas) override;
42 void NotifyClick(const ui::Event& event) override; 54 void NotifyClick(const ui::Event& event) override;
43 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 55 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
44 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; 56 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
45 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 57 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
46 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; 58 void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
47 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; 59 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
48 std::unique_ptr<InkDrop> CreateInkDrop() override; 60 std::unique_ptr<InkDrop> CreateInkDrop() override;
49 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; 61 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override;
50 SkColor GetInkDropBaseColor() const override; 62 SkColor GetInkDropBaseColor() const override;
51 63
52 // gfx::AnimationDelegate: 64 // gfx::AnimationDelegate:
53 void AnimationProgressed(const gfx::Animation* animation) override; 65 void AnimationProgressed(const gfx::Animation* animation) override;
54 66
55 bool is_on_; 67 bool is_on_;
56 gfx::SlideAnimation slide_animation_; 68 gfx::SlideAnimation slide_animation_;
57 ThumbView* thumb_view_; 69 ThumbView* thumb_view_;
70 std::unique_ptr<Painter> focus_painter_;
58 71
59 DISALLOW_COPY_AND_ASSIGN(ToggleButton); 72 DISALLOW_COPY_AND_ASSIGN(ToggleButton);
60 }; 73 };
61 74
62 } // namespace views 75 } // namespace views
63 76
64 #endif // UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_ 77 #endif // UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698