Chromium Code Reviews| 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 InkDropDelegate; | |
| 20 | |
| 19 // A button with custom rendering. The base of ImageButton and LabelButton. | 21 // A button with custom rendering. The base of ImageButton and LabelButton. |
| 20 // Note that this type of button is not focusable by default and will not be | 22 // Note that this type of button is not focusable by default and will not be |
| 21 // part of the focus chain. Call SetFocusable(true) to make it part of the | 23 // part of the focus chain. Call SetFocusable(true) to make it part of the |
| 22 // focus chain. | 24 // focus chain. |
| 23 class VIEWS_EXPORT CustomButton : public Button, | 25 class VIEWS_EXPORT CustomButton : public Button, |
| 24 public gfx::AnimationDelegate { | 26 public gfx::AnimationDelegate { |
| 25 public: | 27 public: |
| 26 // An enum describing the events on which a button should notify its listener. | 28 // An enum describing the events on which a button should notify its listener. |
| 27 enum NotifyAction { | 29 enum NotifyAction { |
| 28 NOTIFY_ON_PRESS, | 30 NOTIFY_ON_PRESS, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 71 |
| 70 // Sets the event on which the button should notify its listener. | 72 // Sets the event on which the button should notify its listener. |
| 71 void set_notify_action(NotifyAction notify_action) { | 73 void set_notify_action(NotifyAction notify_action) { |
| 72 notify_action_ = notify_action; | 74 notify_action_ = notify_action; |
| 73 } | 75 } |
| 74 | 76 |
| 75 void SetHotTracked(bool is_hot_tracked); | 77 void SetHotTracked(bool is_hot_tracked); |
| 76 bool IsHotTracked() const; | 78 bool IsHotTracked() const; |
| 77 | 79 |
| 78 // Overridden from View: | 80 // Overridden from View: |
| 81 void Layout() override; | |
| 79 void OnEnabledChanged() override; | 82 void OnEnabledChanged() override; |
| 80 const char* GetClassName() const override; | 83 const char* GetClassName() const override; |
| 81 bool OnMousePressed(const ui::MouseEvent& event) override; | 84 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 82 bool OnMouseDragged(const ui::MouseEvent& event) override; | 85 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| 83 void OnMouseReleased(const ui::MouseEvent& event) override; | 86 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 84 void OnMouseCaptureLost() override; | 87 void OnMouseCaptureLost() override; |
| 85 void OnMouseEntered(const ui::MouseEvent& event) override; | 88 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 86 void OnMouseExited(const ui::MouseEvent& event) override; | 89 void OnMouseExited(const ui::MouseEvent& event) override; |
| 87 void OnMouseMoved(const ui::MouseEvent& event) override; | 90 void OnMouseMoved(const ui::MouseEvent& event) override; |
| 88 bool OnKeyPressed(const ui::KeyEvent& event) override; | 91 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 116 // holds the mouse down over the button. For this implementation, | 119 // holds the mouse down over the button. For this implementation, |
| 117 // we simply return IsTriggerableEvent(event). | 120 // we simply return IsTriggerableEvent(event). |
| 118 virtual bool ShouldEnterPushedState(const ui::Event& event); | 121 virtual bool ShouldEnterPushedState(const ui::Event& event); |
| 119 | 122 |
| 120 // Returns true if the button should enter hovered state; that is, if the | 123 // Returns true if the button should enter hovered state; that is, if the |
| 121 // mouse is over the button, and no other window has capture (which would | 124 // mouse is over the button, and no other window has capture (which would |
| 122 // prevent the button from receiving MouseExited events and updating its | 125 // prevent the button from receiving MouseExited events and updating its |
| 123 // state). This does not take into account enabled state. | 126 // state). This does not take into account enabled state. |
| 124 bool ShouldEnterHoveredState(); | 127 bool ShouldEnterHoveredState(); |
| 125 | 128 |
| 129 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate); | |
|
sadrul
2015/11/27 05:59:35
SetInkDropDelegate(scoped_ptr<...>)
to clarify th
varkha
2015/11/27 15:17:02
Done.
| |
| 130 InkDropDelegate* ink_drop_delegate() const { | |
| 131 return ink_drop_delegate_.get(); | |
| 132 } | |
| 133 | |
| 126 // Overridden from View: | 134 // Overridden from View: |
| 135 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | |
| 127 void ViewHierarchyChanged( | 136 void ViewHierarchyChanged( |
| 128 const ViewHierarchyChangedDetails& details) override; | 137 const ViewHierarchyChangedDetails& details) override; |
| 129 void OnBlur() override; | 138 void OnBlur() override; |
| 130 | 139 |
| 131 // The button state (defined in implementation) | 140 // The button state (defined in implementation) |
| 132 ButtonState state_; | 141 ButtonState state_; |
| 133 | 142 |
| 134 // Hover animation. | 143 // Hover animation. |
| 135 scoped_ptr<gfx::ThrobAnimation> hover_animation_; | 144 scoped_ptr<gfx::ThrobAnimation> hover_animation_; |
| 136 | 145 |
| 137 private: | 146 private: |
| 138 // Returns true if this is not a top level widget. Virtual for tests. | 147 // Returns true if this is not a top level widget. Virtual for tests. |
| 139 virtual bool IsChildWidget() const; | 148 virtual bool IsChildWidget() const; |
| 140 // Returns true if the focus is not in a top level widget. Virtual for tests. | 149 // Returns true if the focus is not in a top level widget. Virtual for tests. |
| 141 virtual bool FocusInChildWidget() const; | 150 virtual bool FocusInChildWidget() const; |
| 142 | 151 |
| 143 // Should we animate when the state changes? Defaults to true. | 152 // Should we animate when the state changes? Defaults to true. |
| 144 bool animate_on_state_change_; | 153 bool animate_on_state_change_; |
| 145 | 154 |
| 146 // Is the hover animation running because StartThrob was invoked? | 155 // Is the hover animation running because StartThrob was invoked? |
| 147 bool is_throbbing_; | 156 bool is_throbbing_; |
| 148 | 157 |
| 149 // Mouse event flags which can trigger button actions. | 158 // Mouse event flags which can trigger button actions. |
| 150 int triggerable_event_flags_; | 159 int triggerable_event_flags_; |
| 151 | 160 |
| 152 // See description above setter. | 161 // See description above setter. |
| 153 bool request_focus_on_press_; | 162 bool request_focus_on_press_; |
| 154 | 163 |
| 164 // Animation delegate for the ink drop ripple effect. | |
| 165 scoped_ptr<InkDropDelegate> ink_drop_delegate_; | |
| 166 | |
| 155 // The event on which the button should notify its listener. | 167 // The event on which the button should notify its listener. |
| 156 NotifyAction notify_action_; | 168 NotifyAction notify_action_; |
| 157 | 169 |
| 158 DISALLOW_COPY_AND_ASSIGN(CustomButton); | 170 DISALLOW_COPY_AND_ASSIGN(CustomButton); |
| 159 }; | 171 }; |
| 160 | 172 |
| 161 } // namespace views | 173 } // namespace views |
| 162 | 174 |
| 163 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 175 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
| OLD | NEW |