Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // Calculates and returns the bounding box of all drawn elements including the | |
| 31 // necessary padding but not including any additional border. | |
| 32 gfx::Size GetVisibleSize() const; | |
|
Evan Stade
2016/11/18 00:20:21
I'd prefer exposing GetPreferredSize(). That shoul
varkha
2016/11/18 01:13:40
Done.
| |
| 33 | |
| 26 private: | 34 private: |
| 27 friend class TestToggleButton; | 35 friend class TestToggleButton; |
| 28 class ThumbView; | 36 class ThumbView; |
| 29 | 37 |
| 30 // Calculates the bounding box for the thumb (the circle). | 38 // Calculates and returns the bounding box for the track. |
| 39 gfx::Rect GetTrackBounds() const; | |
| 40 | |
| 41 // Calculates and returns the bounding box for the thumb (the circle). | |
| 31 gfx::Rect GetThumbBounds() const; | 42 gfx::Rect GetThumbBounds() const; |
| 32 | 43 |
| 33 // Updates position and color of the thumb. | 44 // Updates position and color of the thumb. |
| 34 void UpdateThumb(); | 45 void UpdateThumb(); |
| 35 | 46 |
| 36 SkColor GetTrackColor(bool is_on) const; | 47 SkColor GetTrackColor(bool is_on) const; |
| 37 | 48 |
| 38 // CustomButton: | 49 // views::View: |
| 39 gfx::Size GetPreferredSize() const override; | 50 gfx::Size GetPreferredSize() const override; |
| 40 const char* GetClassName() const override; | 51 const char* GetClassName() const override; |
| 41 void OnPaint(gfx::Canvas* canvas) override; | 52 void OnPaint(gfx::Canvas* canvas) override; |
| 42 void NotifyClick(const ui::Event& event) override; | 53 void OnFocus() override; |
| 54 void OnBlur() 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; |
| 58 | |
| 59 // CustomButton: | |
| 60 void NotifyClick(const ui::Event& event) override; | |
| 46 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | 61 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 47 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | 62 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 48 std::unique_ptr<InkDrop> CreateInkDrop() override; | 63 std::unique_ptr<InkDrop> CreateInkDrop() override; |
| 49 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; | 64 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; |
| 50 SkColor GetInkDropBaseColor() const override; | 65 SkColor GetInkDropBaseColor() const override; |
| 51 | 66 |
| 52 // gfx::AnimationDelegate: | 67 // gfx::AnimationDelegate: |
| 53 void AnimationProgressed(const gfx::Animation* animation) override; | 68 void AnimationProgressed(const gfx::Animation* animation) override; |
| 54 | 69 |
| 55 bool is_on_; | 70 bool is_on_; |
| 56 gfx::SlideAnimation slide_animation_; | 71 gfx::SlideAnimation slide_animation_; |
| 57 ThumbView* thumb_view_; | 72 ThumbView* thumb_view_; |
| 73 std::unique_ptr<Painter> focus_painter_; | |
| 58 | 74 |
| 59 DISALLOW_COPY_AND_ASSIGN(ToggleButton); | 75 DISALLOW_COPY_AND_ASSIGN(ToggleButton); |
| 60 }; | 76 }; |
| 61 | 77 |
| 62 } // namespace views | 78 } // namespace views |
| 63 | 79 |
| 64 #endif // UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_ | 80 #endif // UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_ |
| OLD | NEW |