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

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 (rebase) 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
« no previous file with comments | « ash/common/system/tray/tray_popup_utils.cc ('k') | ui/views/controls/button/toggle_button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SetFocusPainter(std::unique_ptr<Painter> focus_painter);
29
30 // views::View:
31 gfx::Size GetPreferredSize() const override;
32
26 private: 33 private:
27 friend class TestToggleButton; 34 friend class TestToggleButton;
28 class ThumbView; 35 class ThumbView;
29 36
30 // Calculates the bounding box for the thumb (the circle). 37 // Calculates and returns the bounding box for the track.
38 gfx::Rect GetTrackBounds() const;
39
40 // Calculates and returns the bounding box for the thumb (the circle).
31 gfx::Rect GetThumbBounds() const; 41 gfx::Rect GetThumbBounds() const;
32 42
33 // Updates position and color of the thumb. 43 // Updates position and color of the thumb.
34 void UpdateThumb(); 44 void UpdateThumb();
35 45
36 SkColor GetTrackColor(bool is_on) const; 46 SkColor GetTrackColor(bool is_on) const;
37 47
38 // CustomButton: 48 // views::View:
39 gfx::Size GetPreferredSize() const override;
40 const char* GetClassName() const override; 49 const char* GetClassName() const override;
41 void OnPaint(gfx::Canvas* canvas) override; 50 void OnPaint(gfx::Canvas* canvas) override;
42 void NotifyClick(const ui::Event& event) override; 51 void OnFocus() override;
52 void OnBlur() override;
43 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 53 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
44 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; 54 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
45 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 55 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
56
57 // CustomButton:
58 void NotifyClick(const ui::Event& event) override;
46 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; 59 void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
47 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; 60 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
48 std::unique_ptr<InkDrop> CreateInkDrop() override; 61 std::unique_ptr<InkDrop> CreateInkDrop() override;
49 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; 62 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override;
50 SkColor GetInkDropBaseColor() const override; 63 SkColor GetInkDropBaseColor() const override;
51 64
52 // gfx::AnimationDelegate: 65 // gfx::AnimationDelegate:
53 void AnimationProgressed(const gfx::Animation* animation) override; 66 void AnimationProgressed(const gfx::Animation* animation) override;
54 67
55 bool is_on_; 68 bool is_on_;
56 gfx::SlideAnimation slide_animation_; 69 gfx::SlideAnimation slide_animation_;
57 ThumbView* thumb_view_; 70 ThumbView* thumb_view_;
71 std::unique_ptr<Painter> focus_painter_;
58 72
59 DISALLOW_COPY_AND_ASSIGN(ToggleButton); 73 DISALLOW_COPY_AND_ASSIGN(ToggleButton);
60 }; 74 };
61 75
62 } // namespace views 76 } // namespace views
63 77
64 #endif // UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_ 78 #endif // UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_
OLDNEW
« no previous file with comments | « ash/common/system/tray/tray_popup_utils.cc ('k') | ui/views/controls/button/toggle_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698