| OLD | NEW |
| 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_SLIDER_H_ | 5 #ifndef UI_VIEWS_CONTROLS_SLIDER_H_ |
| 6 #define UI_VIEWS_CONTROLS_SLIDER_H_ | 6 #define UI_VIEWS_CONTROLS_SLIDER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "ui/gfx/animation/animation_delegate.h" | 9 #include "ui/gfx/animation/animation_delegate.h" |
| 10 #include "ui/gfx/animation/slide_animation.h" |
| 10 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
| 11 #include "ui/views/views_export.h" | 12 #include "ui/views/views_export.h" |
| 12 | 13 |
| 13 typedef unsigned int SkColor; | 14 typedef unsigned int SkColor; |
| 14 | 15 |
| 15 namespace gfx { | |
| 16 class SlideAnimation; | |
| 17 } | |
| 18 | |
| 19 namespace views { | 16 namespace views { |
| 20 | 17 |
| 21 namespace test { | 18 namespace test { |
| 22 class SliderTestApi; | 19 class SliderTestApi; |
| 23 } | 20 } |
| 24 | 21 |
| 25 class Slider; | 22 class Slider; |
| 26 | 23 |
| 27 enum SliderChangeReason { | 24 enum SliderChangeReason { |
| 28 VALUE_CHANGED_BY_USER, // value was changed by the user (by clicking, e.g.) | 25 VALUE_CHANGED_BY_USER, // value was changed by the user (by clicking, e.g.) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 | 40 |
| 44 protected: | 41 protected: |
| 45 virtual ~SliderListener() {} | 42 virtual ~SliderListener() {} |
| 46 }; | 43 }; |
| 47 | 44 |
| 48 class VIEWS_EXPORT Slider : public View, public gfx::AnimationDelegate { | 45 class VIEWS_EXPORT Slider : public View, public gfx::AnimationDelegate { |
| 49 public: | 46 public: |
| 50 // Internal class name. | 47 // Internal class name. |
| 51 static const char kViewClassName[]; | 48 static const char kViewClassName[]; |
| 52 | 49 |
| 53 // Based on the bool |is_material_design|, either a md version or a non-md | 50 explicit Slider(SliderListener* listener); |
| 54 // version of the slider will be created. | |
| 55 static Slider* CreateSlider(bool is_material_design, | |
| 56 SliderListener* listener); | |
| 57 ~Slider() override; | 51 ~Slider() override; |
| 58 | 52 |
| 59 float value() const { return value_; } | 53 float value() const { return value_; } |
| 60 void SetValue(float value); | 54 void SetValue(float value); |
| 61 | 55 |
| 62 void SetAccessibleName(const base::string16& name); | 56 void SetAccessibleName(const base::string16& name); |
| 63 | 57 |
| 64 void set_enable_accessibility_events(bool enabled) { | 58 void set_enable_accessibility_events(bool enabled) { |
| 65 accessibility_events_enabled_ = enabled; | 59 accessibility_events_enabled_ = enabled; |
| 66 } | 60 } |
| 67 | 61 |
| 68 // Update UI based on control on/off state. | 62 // Update UI based on control on/off state. |
| 69 virtual void UpdateState(bool control_on) = 0; | 63 void UpdateState(bool control_on); |
| 70 | 64 |
| 71 protected: | 65 protected: |
| 72 explicit Slider(SliderListener* listener); | |
| 73 | |
| 74 // Returns the current position of the thumb on the slider. | 66 // Returns the current position of the thumb on the slider. |
| 75 float GetAnimatingValue() const; | 67 float GetAnimatingValue() const; |
| 76 | 68 |
| 77 // Shows or hides the highlight on the slider thumb. The default | 69 // Shows or hides the highlight on the slider thumb. The default |
| 78 // implementation does nothing. | 70 // implementation does nothing. |
| 79 virtual void SetHighlighted(bool is_highlighted); | 71 void SetHighlighted(bool is_highlighted); |
| 80 | |
| 81 // Gets the size of the slider's thumb. | |
| 82 virtual int GetThumbWidth() = 0; | |
| 83 | |
| 84 // views::View: | |
| 85 void OnPaint(gfx::Canvas* canvas) override; | |
| 86 | 72 |
| 87 // gfx::AnimationDelegate: | 73 // gfx::AnimationDelegate: |
| 88 void AnimationProgressed(const gfx::Animation* animation) override; | 74 void AnimationProgressed(const gfx::Animation* animation) override; |
| 89 void AnimationEnded(const gfx::Animation* animation) override; | 75 void AnimationEnded(const gfx::Animation* animation) override; |
| 90 | 76 |
| 91 private: | 77 private: |
| 92 friend class test::SliderTestApi; | 78 friend class test::SliderTestApi; |
| 93 | 79 |
| 94 void SetValueInternal(float value, SliderChangeReason reason); | 80 void SetValueInternal(float value, SliderChangeReason reason); |
| 95 | 81 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 110 void OnSliderDragEnded(); | 96 void OnSliderDragEnded(); |
| 111 | 97 |
| 112 // views::View: | 98 // views::View: |
| 113 const char* GetClassName() const override; | 99 const char* GetClassName() const override; |
| 114 gfx::Size GetPreferredSize() const override; | 100 gfx::Size GetPreferredSize() const override; |
| 115 bool OnMousePressed(const ui::MouseEvent& event) override; | 101 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 116 bool OnMouseDragged(const ui::MouseEvent& event) override; | 102 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| 117 void OnMouseReleased(const ui::MouseEvent& event) override; | 103 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 118 bool OnKeyPressed(const ui::KeyEvent& event) override; | 104 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 119 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 105 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 106 void OnPaint(gfx::Canvas* canvas) override; |
| 120 void OnFocus() override; | 107 void OnFocus() override; |
| 121 void OnBlur() override; | 108 void OnBlur() override; |
| 122 | 109 |
| 123 // ui::EventHandler: | 110 // ui::EventHandler: |
| 124 void OnGestureEvent(ui::GestureEvent* event) override; | 111 void OnGestureEvent(ui::GestureEvent* event) override; |
| 125 | 112 |
| 126 void set_listener(SliderListener* listener) { | 113 void set_listener(SliderListener* listener) { |
| 127 listener_ = listener; | 114 listener_ = listener; |
| 128 } | 115 } |
| 129 | 116 |
| 130 SliderListener* listener_; | 117 SliderListener* listener_; |
| 131 | 118 |
| 132 std::unique_ptr<gfx::SlideAnimation> move_animation_; | 119 std::unique_ptr<gfx::SlideAnimation> move_animation_; |
| 133 | 120 |
| 134 float value_; | 121 float value_ = 0.f; |
| 135 float keyboard_increment_; | 122 float keyboard_increment_ = 0.1f; |
| 136 float initial_animating_value_; | 123 float initial_animating_value_ = 0.f; |
| 137 bool value_is_valid_; | 124 bool value_is_valid_ = false; |
| 138 base::string16 accessible_name_; | 125 base::string16 accessible_name_; |
| 139 bool accessibility_events_enabled_; | 126 bool accessibility_events_enabled_ = true; |
| 140 | 127 |
| 141 // Relative position of the mouse cursor (or the touch point) on the slider's | 128 // Relative position of the mouse cursor (or the touch point) on the slider's |
| 142 // button. | 129 // button. |
| 143 int initial_button_offset_; | 130 int initial_button_offset_ = 0; |
| 131 |
| 132 // Record whether the slider is in the active state or the disabled state. |
| 133 bool is_active_ = true; |
| 134 |
| 135 // Animating value of the current radius of the thumb's highlight. |
| 136 float thumb_highlight_radius_ = 0.f; |
| 137 |
| 138 gfx::SlideAnimation highlight_animation_; |
| 144 | 139 |
| 145 DISALLOW_COPY_AND_ASSIGN(Slider); | 140 DISALLOW_COPY_AND_ASSIGN(Slider); |
| 146 }; | 141 }; |
| 147 | 142 |
| 148 } // namespace views | 143 } // namespace views |
| 149 | 144 |
| 150 #endif // UI_VIEWS_CONTROLS_SLIDER_H_ | 145 #endif // UI_VIEWS_CONTROLS_SLIDER_H_ |
| OLD | NEW |