| 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" |
| 11 #include "ui/views/controls/button/button.h" | 11 #include "ui/views/controls/button/button.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 class ThrobAnimation; | 14 class ThrobAnimation; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace views { | 17 namespace views { |
| 18 | 18 |
| 19 class CustomButtonStateChangedDelegate; | |
| 20 | |
| 21 // A button with custom rendering. The base of ImageButton and LabelButton. | 19 // A button with custom rendering. The base of ImageButton and LabelButton. |
| 22 // Note that this type of button is not focusable by default and will not be | 20 // Note that this type of button is not focusable by default and will not be |
| 23 // part of the focus chain. Call SetFocusable(true) to make it part of the | 21 // part of the focus chain. Call SetFocusable(true) to make it part of the |
| 24 // focus chain. | 22 // focus chain. |
| 25 class VIEWS_EXPORT CustomButton : public Button, | 23 class VIEWS_EXPORT CustomButton : public Button, |
| 26 public gfx::AnimationDelegate { | 24 public gfx::AnimationDelegate { |
| 27 public: | 25 public: |
| 28 // The menu button's class name. | 26 // The menu button's class name. |
| 29 static const char kViewClassName[]; | 27 static const char kViewClassName[]; |
| 30 | 28 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 80 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| 83 void ShowContextMenu(const gfx::Point& p, | 81 void ShowContextMenu(const gfx::Point& p, |
| 84 ui::MenuSourceType source_type) override; | 82 ui::MenuSourceType source_type) override; |
| 85 void OnDragDone() override; | 83 void OnDragDone() override; |
| 86 void GetAccessibleState(ui::AXViewState* state) override; | 84 void GetAccessibleState(ui::AXViewState* state) override; |
| 87 void VisibilityChanged(View* starting_from, bool is_visible) override; | 85 void VisibilityChanged(View* starting_from, bool is_visible) override; |
| 88 | 86 |
| 89 // Overridden from gfx::AnimationDelegate: | 87 // Overridden from gfx::AnimationDelegate: |
| 90 void AnimationProgressed(const gfx::Animation* animation) override; | 88 void AnimationProgressed(const gfx::Animation* animation) override; |
| 91 | 89 |
| 92 // Takes ownership of the delegate. | |
| 93 void set_state_changed_delegate(CustomButtonStateChangedDelegate* delegate) { | |
| 94 state_changed_delegate_.reset(delegate); | |
| 95 } | |
| 96 | |
| 97 protected: | 90 protected: |
| 98 // Construct the Button with a Listener. See comment for Button's ctor. | 91 // Construct the Button with a Listener. See comment for Button's ctor. |
| 99 explicit CustomButton(ButtonListener* listener); | 92 explicit CustomButton(ButtonListener* listener); |
| 100 | 93 |
| 101 // Invoked from SetState() when SetState() is passed a value that differs from | 94 // Invoked from SetState() when SetState() is passed a value that differs from |
| 102 // the current state. CustomButton's implementation of StateChanged() does | 95 // the current state. CustomButton's implementation of StateChanged() does |
| 103 // nothing; this method is provided for subclasses that wish to do something | 96 // nothing; this method is provided for subclasses that wish to do something |
| 104 // on state changes. | 97 // on state changes. |
| 105 virtual void StateChanged(); | 98 virtual void StateChanged(); |
| 106 | 99 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 130 | 123 |
| 131 // Is the hover animation running because StartThrob was invoked? | 124 // Is the hover animation running because StartThrob was invoked? |
| 132 bool is_throbbing_; | 125 bool is_throbbing_; |
| 133 | 126 |
| 134 // Mouse event flags which can trigger button actions. | 127 // Mouse event flags which can trigger button actions. |
| 135 int triggerable_event_flags_; | 128 int triggerable_event_flags_; |
| 136 | 129 |
| 137 // See description above setter. | 130 // See description above setter. |
| 138 bool request_focus_on_press_; | 131 bool request_focus_on_press_; |
| 139 | 132 |
| 140 scoped_ptr<CustomButtonStateChangedDelegate> state_changed_delegate_; | |
| 141 | |
| 142 DISALLOW_COPY_AND_ASSIGN(CustomButton); | 133 DISALLOW_COPY_AND_ASSIGN(CustomButton); |
| 143 }; | 134 }; |
| 144 | 135 |
| 145 // Delegate for actions taken on state changes by CustomButton. | |
| 146 class VIEWS_EXPORT CustomButtonStateChangedDelegate { | |
| 147 public: | |
| 148 virtual ~CustomButtonStateChangedDelegate() {} | |
| 149 virtual void StateChanged(Button::ButtonState state) = 0; | |
| 150 | |
| 151 protected: | |
| 152 CustomButtonStateChangedDelegate() {} | |
| 153 | |
| 154 private: | |
| 155 DISALLOW_COPY_AND_ASSIGN(CustomButtonStateChangedDelegate); | |
| 156 }; | |
| 157 | |
| 158 } // namespace views | 136 } // namespace views |
| 159 | 137 |
| 160 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 138 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
| OLD | NEW |