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 // This view presents a button that has two states: on and off. This is similar | 13 // 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 | 14 // to a checkbox but has no text and looks more like a two-state horizontal |
| 15 // slider. | 15 // slider. |
| 16 class VIEWS_EXPORT ToggleButton : public CustomButton { | 16 class VIEWS_EXPORT ToggleButton : public CustomButton { |
| 17 public: | 17 public: |
| 18 explicit ToggleButton(ButtonListener* listener); | 18 explicit ToggleButton(ButtonListener* listener); |
| 19 ~ToggleButton() override; | 19 ~ToggleButton() override; |
| 20 | 20 |
| 21 void SetIsOn(bool is_on, bool animate); | 21 void SetIsOn(bool is_on, bool animate); |
| 22 bool is_on() const { return is_on_; } | 22 bool is_on() const { return is_on_; } |
| 23 | 23 |
| 24 private: | 24 private: |
| 25 class ThumbView; | |
| 26 | |
| 25 // CustomButton: | 27 // CustomButton: |
| 26 gfx::Size GetPreferredSize() const override; | 28 gfx::Size GetPreferredSize() const override; |
| 29 const char* GetClassName() const override; | |
| 27 void OnPaint(gfx::Canvas* canvas) override; | 30 void OnPaint(gfx::Canvas* canvas) override; |
| 28 void NotifyClick(const ui::Event& event) override; | 31 void NotifyClick(const ui::Event& event) override; |
| 32 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | |
| 29 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 33 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 34 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | |
| 35 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | |
| 30 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; | 36 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; |
| 31 SkColor GetInkDropBaseColor() const override; | 37 SkColor GetInkDropBaseColor() const override; |
| 32 bool ShouldShowInkDropHighlight() const override; | 38 bool ShouldShowInkDropHighlight() const override; |
| 33 | 39 |
| 34 // gfx::AnimationDelegate: | 40 // gfx::AnimationDelegate: |
| 35 void AnimationProgressed(const gfx::Animation* animation) override; | 41 void AnimationProgressed(const gfx::Animation* animation) override; |
| 36 | 42 |
| 37 // Calculates the bounding box for the thumb (the circle). | 43 // Calculates the bounding box for the thumb (the circle). |
| 38 gfx::Rect GetThumbBounds() const; | 44 gfx::Rect GetThumbBounds() const; |
| 39 | 45 |
| 46 // Updates position and color of the thumb. | |
| 47 void UpdateThumb(); | |
|
sadrul
2016/10/13 03:30:23
non-virtuals should be before virtuals (although I
varkha
2016/10/13 17:04:56
Done.
| |
| 48 | |
| 40 bool is_on_; | 49 bool is_on_; |
| 41 gfx::SlideAnimation slide_animation_; | 50 gfx::SlideAnimation slide_animation_; |
| 51 std::unique_ptr<ThumbView> thumb_view_; | |
| 42 | 52 |
| 43 DISALLOW_COPY_AND_ASSIGN(ToggleButton); | 53 DISALLOW_COPY_AND_ASSIGN(ToggleButton); |
| 44 }; | 54 }; |
| 45 | 55 |
| 46 } // namespace views | 56 } // namespace views |
| 47 | 57 |
| 48 #endif // UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_ | 58 #endif // UI_VIEWS_CONTROLS_BUTTON_TOGGLE_BUTTON_H_ |
| OLD | NEW |