| 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_BUTTON_CUSTOM_BUTTON_H_ | 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
| 6 #define UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 6 #define UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "ui/events/event_constants.h" | 9 #include "ui/events/event_constants.h" |
| 10 #include "ui/gfx/animation/animation_delegate.h" | 10 #include "ui/gfx/animation/animation_delegate.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // focus chain. | 24 // focus chain. |
| 25 class VIEWS_EXPORT CustomButton : public Button, | 25 class VIEWS_EXPORT CustomButton : public Button, |
| 26 public gfx::AnimationDelegate { | 26 public gfx::AnimationDelegate { |
| 27 public: | 27 public: |
| 28 // The menu button's class name. | 28 // The menu button's class name. |
| 29 static const char kViewClassName[]; | 29 static const char kViewClassName[]; |
| 30 | 30 |
| 31 static const CustomButton* AsCustomButton(const views::View* view); | 31 static const CustomButton* AsCustomButton(const views::View* view); |
| 32 static CustomButton* AsCustomButton(views::View* view); | 32 static CustomButton* AsCustomButton(views::View* view); |
| 33 | 33 |
| 34 virtual ~CustomButton(); | 34 ~CustomButton() override; |
| 35 | 35 |
| 36 // Get/sets the current display state of the button. | 36 // Get/sets the current display state of the button. |
| 37 ButtonState state() const { return state_; } | 37 ButtonState state() const { return state_; } |
| 38 void SetState(ButtonState state); | 38 void SetState(ButtonState state); |
| 39 | 39 |
| 40 // Starts throbbing. See HoverAnimation for a description of cycles_til_stop. | 40 // Starts throbbing. See HoverAnimation for a description of cycles_til_stop. |
| 41 void StartThrobbing(int cycles_til_stop); | 41 void StartThrobbing(int cycles_til_stop); |
| 42 | 42 |
| 43 // Stops throbbing immediately. | 43 // Stops throbbing immediately. |
| 44 void StopThrobbing(); | 44 void StopThrobbing(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 60 | 60 |
| 61 // See description above field. | 61 // See description above field. |
| 62 void set_animate_on_state_change(bool value) { | 62 void set_animate_on_state_change(bool value) { |
| 63 animate_on_state_change_ = value; | 63 animate_on_state_change_ = value; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void SetHotTracked(bool is_hot_tracked); | 66 void SetHotTracked(bool is_hot_tracked); |
| 67 bool IsHotTracked() const; | 67 bool IsHotTracked() const; |
| 68 | 68 |
| 69 // Overridden from View: | 69 // Overridden from View: |
| 70 virtual void OnEnabledChanged() override; | 70 void OnEnabledChanged() override; |
| 71 virtual const char* GetClassName() const override; | 71 const char* GetClassName() const override; |
| 72 virtual bool OnMousePressed(const ui::MouseEvent& event) override; | 72 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 73 virtual bool OnMouseDragged(const ui::MouseEvent& event) override; | 73 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| 74 virtual void OnMouseReleased(const ui::MouseEvent& event) override; | 74 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 75 virtual void OnMouseCaptureLost() override; | 75 void OnMouseCaptureLost() override; |
| 76 virtual void OnMouseEntered(const ui::MouseEvent& event) override; | 76 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 77 virtual void OnMouseExited(const ui::MouseEvent& event) override; | 77 void OnMouseExited(const ui::MouseEvent& event) override; |
| 78 virtual void OnMouseMoved(const ui::MouseEvent& event) override; | 78 void OnMouseMoved(const ui::MouseEvent& event) override; |
| 79 virtual bool OnKeyPressed(const ui::KeyEvent& event) override; | 79 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 80 virtual bool OnKeyReleased(const ui::KeyEvent& event) override; | 80 bool OnKeyReleased(const ui::KeyEvent& event) override; |
| 81 virtual void OnGestureEvent(ui::GestureEvent* event) override; | 81 void OnGestureEvent(ui::GestureEvent* event) override; |
| 82 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 82 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| 83 virtual void ShowContextMenu(const gfx::Point& p, | 83 void ShowContextMenu(const gfx::Point& p, |
| 84 ui::MenuSourceType source_type) override; | 84 ui::MenuSourceType source_type) override; |
| 85 virtual void OnDragDone() override; | 85 void OnDragDone() override; |
| 86 virtual void GetAccessibleState(ui::AXViewState* state) override; | 86 void GetAccessibleState(ui::AXViewState* state) override; |
| 87 virtual void VisibilityChanged(View* starting_from, bool is_visible) override; | 87 void VisibilityChanged(View* starting_from, bool is_visible) override; |
| 88 | 88 |
| 89 // Overridden from gfx::AnimationDelegate: | 89 // Overridden from gfx::AnimationDelegate: |
| 90 virtual void AnimationProgressed(const gfx::Animation* animation) override; | 90 void AnimationProgressed(const gfx::Animation* animation) override; |
| 91 | 91 |
| 92 // Takes ownership of the delegate. | 92 // Takes ownership of the delegate. |
| 93 void set_state_changed_delegate(CustomButtonStateChangedDelegate* delegate) { | 93 void set_state_changed_delegate(CustomButtonStateChangedDelegate* delegate) { |
| 94 state_changed_delegate_.reset(delegate); | 94 state_changed_delegate_.reset(delegate); |
| 95 } | 95 } |
| 96 | 96 |
| 97 protected: | 97 protected: |
| 98 // Construct the Button with a Listener. See comment for Button's ctor. | 98 // Construct the Button with a Listener. See comment for Button's ctor. |
| 99 explicit CustomButton(ButtonListener* listener); | 99 explicit CustomButton(ButtonListener* listener); |
| 100 | 100 |
| 101 // Invoked from SetState() when SetState() is passed a value that differs from | 101 // Invoked from SetState() when SetState() is passed a value that differs from |
| 102 // the current state. CustomButton's implementation of StateChanged() does | 102 // the current state. CustomButton's implementation of StateChanged() does |
| 103 // nothing; this method is provided for subclasses that wish to do something | 103 // nothing; this method is provided for subclasses that wish to do something |
| 104 // on state changes. | 104 // on state changes. |
| 105 virtual void StateChanged(); | 105 virtual void StateChanged(); |
| 106 | 106 |
| 107 // Returns true if the event is one that can trigger notifying the listener. | 107 // Returns true if the event is one that can trigger notifying the listener. |
| 108 // This implementation returns true if the left mouse button is down. | 108 // This implementation returns true if the left mouse button is down. |
| 109 virtual bool IsTriggerableEvent(const ui::Event& event); | 109 virtual bool IsTriggerableEvent(const ui::Event& event); |
| 110 | 110 |
| 111 // Returns true if the button should become pressed when the user | 111 // Returns true if the button should become pressed when the user |
| 112 // holds the mouse down over the button. For this implementation, | 112 // holds the mouse down over the button. For this implementation, |
| 113 // we simply return IsTriggerableEvent(event). | 113 // we simply return IsTriggerableEvent(event). |
| 114 virtual bool ShouldEnterPushedState(const ui::Event& event); | 114 virtual bool ShouldEnterPushedState(const ui::Event& event); |
| 115 | 115 |
| 116 // Overridden from View: | 116 // Overridden from View: |
| 117 virtual void ViewHierarchyChanged( | 117 void ViewHierarchyChanged( |
| 118 const ViewHierarchyChangedDetails& details) override; | 118 const ViewHierarchyChangedDetails& details) override; |
| 119 virtual void OnBlur() override; | 119 void OnBlur() override; |
| 120 | 120 |
| 121 // The button state (defined in implementation) | 121 // The button state (defined in implementation) |
| 122 ButtonState state_; | 122 ButtonState state_; |
| 123 | 123 |
| 124 // Hover animation. | 124 // Hover animation. |
| 125 scoped_ptr<gfx::ThrobAnimation> hover_animation_; | 125 scoped_ptr<gfx::ThrobAnimation> hover_animation_; |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 // Should we animate when the state changes? Defaults to true. | 128 // Should we animate when the state changes? Defaults to true. |
| 129 bool animate_on_state_change_; | 129 bool animate_on_state_change_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 151 protected: | 151 protected: |
| 152 CustomButtonStateChangedDelegate() {} | 152 CustomButtonStateChangedDelegate() {} |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 DISALLOW_COPY_AND_ASSIGN(CustomButtonStateChangedDelegate); | 155 DISALLOW_COPY_AND_ASSIGN(CustomButtonStateChangedDelegate); |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 } // namespace views | 158 } // namespace views |
| 159 | 159 |
| 160 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 160 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
| OLD | NEW |