| 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/base/animation/animation_delegate.h" | |
| 10 #include "ui/base/events/event_constants.h" | 9 #include "ui/base/events/event_constants.h" |
| 10 #include "ui/gfx/animation/animation_delegate.h" |
| 11 #include "ui/views/controls/button/button.h" | 11 #include "ui/views/controls/button/button.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace gfx { |
| 14 class ThrobAnimation; | 14 class ThrobAnimation; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace views { | 17 namespace views { |
| 18 | 18 |
| 19 class CustomButtonStateChangedDelegate; | 19 class CustomButtonStateChangedDelegate; |
| 20 | 20 |
| 21 // A button with custom rendering. The common base class of ImageButton and | 21 // A button with custom rendering. The common base class of ImageButton and |
| 22 // TextButton. | 22 // TextButton. |
| 23 // Note that this type of button is not focusable by default and will not be | 23 // Note that this type of button is not focusable by default and will not be |
| 24 // part of the focus chain. Call set_focusable(true) to make it part of the | 24 // part of the focus chain. Call set_focusable(true) to make it part of the |
| 25 // focus chain. | 25 // focus chain. |
| 26 class VIEWS_EXPORT CustomButton : public Button, | 26 class VIEWS_EXPORT CustomButton : public Button, |
| 27 public ui::AnimationDelegate { | 27 public gfx::AnimationDelegate { |
| 28 public: | 28 public: |
| 29 // The menu button's class name. | 29 // The menu button's class name. |
| 30 static const char kViewClassName[]; | 30 static const char kViewClassName[]; |
| 31 | 31 |
| 32 virtual ~CustomButton(); | 32 virtual ~CustomButton(); |
| 33 | 33 |
| 34 // Get/sets the current display state of the button. | 34 // Get/sets the current display state of the button. |
| 35 ButtonState state() const { return state_; } | 35 ButtonState state() const { return state_; } |
| 36 void SetState(ButtonState state); | 36 void SetState(ButtonState state); |
| 37 | 37 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 77 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
| 78 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; | 78 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; |
| 79 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 79 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 80 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 80 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
| 81 virtual void ShowContextMenu(const gfx::Point& p, | 81 virtual void ShowContextMenu(const gfx::Point& p, |
| 82 ui::MenuSourceType source_type) OVERRIDE; | 82 ui::MenuSourceType source_type) OVERRIDE; |
| 83 virtual void OnDragDone() OVERRIDE; | 83 virtual void OnDragDone() OVERRIDE; |
| 84 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 84 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 85 virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE; | 85 virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE; |
| 86 | 86 |
| 87 // Overridden from ui::AnimationDelegate: | 87 // Overridden from gfx::AnimationDelegate: |
| 88 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 88 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
| 89 | 89 |
| 90 // Takes ownership of the delegate. | 90 // Takes ownership of the delegate. |
| 91 void set_state_changed_delegate(CustomButtonStateChangedDelegate* delegate) { | 91 void set_state_changed_delegate(CustomButtonStateChangedDelegate* delegate) { |
| 92 state_changed_delegate_.reset(delegate); | 92 state_changed_delegate_.reset(delegate); |
| 93 } | 93 } |
| 94 | 94 |
| 95 protected: | 95 protected: |
| 96 // Construct the Button with a Listener. See comment for Button's ctor. | 96 // Construct the Button with a Listener. See comment for Button's ctor. |
| 97 explicit CustomButton(ButtonListener* listener); | 97 explicit CustomButton(ButtonListener* listener); |
| 98 | 98 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 113 | 113 |
| 114 // Overridden from View: | 114 // Overridden from View: |
| 115 virtual void ViewHierarchyChanged( | 115 virtual void ViewHierarchyChanged( |
| 116 const ViewHierarchyChangedDetails& details) OVERRIDE; | 116 const ViewHierarchyChangedDetails& details) OVERRIDE; |
| 117 virtual void OnBlur() OVERRIDE; | 117 virtual void OnBlur() OVERRIDE; |
| 118 | 118 |
| 119 // The button state (defined in implementation) | 119 // The button state (defined in implementation) |
| 120 ButtonState state_; | 120 ButtonState state_; |
| 121 | 121 |
| 122 // Hover animation. | 122 // Hover animation. |
| 123 scoped_ptr<ui::ThrobAnimation> hover_animation_; | 123 scoped_ptr<gfx::ThrobAnimation> hover_animation_; |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 // Should we animate when the state changes? Defaults to true. | 126 // Should we animate when the state changes? Defaults to true. |
| 127 bool animate_on_state_change_; | 127 bool animate_on_state_change_; |
| 128 | 128 |
| 129 // Is the hover animation running because StartThrob was invoked? | 129 // Is the hover animation running because StartThrob was invoked? |
| 130 bool is_throbbing_; | 130 bool is_throbbing_; |
| 131 | 131 |
| 132 // Mouse event flags which can trigger button actions. | 132 // Mouse event flags which can trigger button actions. |
| 133 int triggerable_event_flags_; | 133 int triggerable_event_flags_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 149 protected: | 149 protected: |
| 150 CustomButtonStateChangedDelegate() {} | 150 CustomButtonStateChangedDelegate() {} |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 DISALLOW_COPY_AND_ASSIGN(CustomButtonStateChangedDelegate); | 153 DISALLOW_COPY_AND_ASSIGN(CustomButtonStateChangedDelegate); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 } // namespace views | 156 } // namespace views |
| 157 | 157 |
| 158 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 158 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
| OLD | NEW |