| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 NOTIFY_ON_PRESS, | 30 NOTIFY_ON_PRESS, |
| 31 NOTIFY_ON_RELEASE, | 31 NOTIFY_ON_RELEASE, |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // The menu button's class name. | 34 // The menu button's class name. |
| 35 static const char kViewClassName[]; | 35 static const char kViewClassName[]; |
| 36 | 36 |
| 37 static const CustomButton* AsCustomButton(const View* view); | 37 static const CustomButton* AsCustomButton(const View* view); |
| 38 static CustomButton* AsCustomButton(View* view); | 38 static CustomButton* AsCustomButton(View* view); |
| 39 | 39 |
| 40 // Paint an MD-style focus ring on the given canvas at the given bounds. | |
| 41 static void PaintMdFocusRing(gfx::Canvas* canvas, View* view); | |
| 42 | |
| 43 ~CustomButton() override; | 40 ~CustomButton() override; |
| 44 | 41 |
| 45 // Get/sets the current display state of the button. | 42 // Get/sets the current display state of the button. |
| 46 ButtonState state() const { return state_; } | 43 ButtonState state() const { return state_; } |
| 47 void SetState(ButtonState state); | 44 void SetState(ButtonState state); |
| 48 | 45 |
| 49 // Starts throbbing. See HoverAnimation for a description of cycles_til_stop. | 46 // Starts throbbing. See HoverAnimation for a description of cycles_til_stop. |
| 50 void StartThrobbing(int cycles_til_stop); | 47 void StartThrobbing(int cycles_til_stop); |
| 51 | 48 |
| 52 // Stops throbbing immediately. | 49 // Stops throbbing immediately. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 ui::MenuSourceType source_type) override; | 109 ui::MenuSourceType source_type) override; |
| 113 void OnDragDone() override; | 110 void OnDragDone() override; |
| 114 void GetAccessibleState(ui::AXViewState* state) override; | 111 void GetAccessibleState(ui::AXViewState* state) override; |
| 115 void VisibilityChanged(View* starting_from, bool is_visible) override; | 112 void VisibilityChanged(View* starting_from, bool is_visible) override; |
| 116 std::unique_ptr<InkDropHover> CreateInkDropHover() const override; | 113 std::unique_ptr<InkDropHover> CreateInkDropHover() const override; |
| 117 SkColor GetInkDropBaseColor() const override; | 114 SkColor GetInkDropBaseColor() const override; |
| 118 | 115 |
| 119 // Overridden from gfx::AnimationDelegate: | 116 // Overridden from gfx::AnimationDelegate: |
| 120 void AnimationProgressed(const gfx::Animation* animation) override; | 117 void AnimationProgressed(const gfx::Animation* animation) override; |
| 121 | 118 |
| 122 InkDropDelegate* ink_drop_delegate() const { return ink_drop_delegate_; } | |
| 123 | |
| 124 // Overridden from View: | 119 // Overridden from View: |
| 125 void Layout() override; | |
| 126 void ViewHierarchyChanged( | 120 void ViewHierarchyChanged( |
| 127 const ViewHierarchyChangedDetails& details) override; | 121 const ViewHierarchyChangedDetails& details) override; |
| 128 void OnFocus() override; | |
| 129 void OnBlur() override; | 122 void OnBlur() override; |
| 123 bool ShouldShowInkDropForFocus() const override; |
| 130 | 124 |
| 131 protected: | 125 protected: |
| 132 // Construct the Button with a Listener. See comment for Button's ctor. | 126 // Construct the Button with a Listener. See comment for Button's ctor. |
| 133 explicit CustomButton(ButtonListener* listener); | 127 explicit CustomButton(ButtonListener* listener); |
| 134 | 128 |
| 135 // Invoked from SetState() when SetState() is passed a value that differs from | 129 // Invoked from SetState() when SetState() is passed a value that differs from |
| 136 // the current state. CustomButton's implementation of StateChanged() does | 130 // the current state. CustomButton's implementation of StateChanged() does |
| 137 // nothing; this method is provided for subclasses that wish to do something | 131 // nothing; this method is provided for subclasses that wish to do something |
| 138 // on state changes. | 132 // on state changes. |
| 139 virtual void StateChanged(); | 133 virtual void StateChanged(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 153 void set_has_ink_drop_action_on_click(bool has_ink_drop_action_on_click) { | 147 void set_has_ink_drop_action_on_click(bool has_ink_drop_action_on_click) { |
| 154 has_ink_drop_action_on_click_ = has_ink_drop_action_on_click; | 148 has_ink_drop_action_on_click_ = has_ink_drop_action_on_click; |
| 155 } | 149 } |
| 156 | 150 |
| 157 // Returns true if the button should enter hovered state; that is, if the | 151 // Returns true if the button should enter hovered state; that is, if the |
| 158 // mouse is over the button, and no other window has capture (which would | 152 // mouse is over the button, and no other window has capture (which would |
| 159 // prevent the button from receiving MouseExited events and updating its | 153 // prevent the button from receiving MouseExited events and updating its |
| 160 // state). This does not take into account enabled state. | 154 // state). This does not take into account enabled state. |
| 161 bool ShouldEnterHoveredState(); | 155 bool ShouldEnterHoveredState(); |
| 162 | 156 |
| 163 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) { | |
| 164 ink_drop_delegate_ = ink_drop_delegate; | |
| 165 } | |
| 166 | |
| 167 // When called, creates and uses |md_focus_ring_| instead of a focus painter. | |
| 168 void UseMdFocusRing(); | |
| 169 | |
| 170 // Overridden from Button: | 157 // Overridden from Button: |
| 171 void NotifyClick(const ui::Event& event) override; | 158 void NotifyClick(const ui::Event& event) override; |
| 172 void OnClickCanceled(const ui::Event& event) override; | 159 void OnClickCanceled(const ui::Event& event) override; |
| 173 | 160 |
| 174 const gfx::ThrobAnimation& hover_animation() const { | 161 const gfx::ThrobAnimation& hover_animation() const { |
| 175 return hover_animation_; | 162 return hover_animation_; |
| 176 } | 163 } |
| 177 | 164 |
| 178 private: | 165 private: |
| 179 ButtonState state_; | 166 ButtonState state_; |
| 180 | 167 |
| 181 gfx::ThrobAnimation hover_animation_; | 168 gfx::ThrobAnimation hover_animation_; |
| 182 | 169 |
| 183 // Should we animate when the state changes? Defaults to true. | 170 // Should we animate when the state changes? Defaults to true. |
| 184 bool animate_on_state_change_; | 171 bool animate_on_state_change_; |
| 185 | 172 |
| 186 // Is the hover animation running because StartThrob was invoked? | 173 // Is the hover animation running because StartThrob was invoked? |
| 187 bool is_throbbing_; | 174 bool is_throbbing_; |
| 188 | 175 |
| 189 // Mouse event flags which can trigger button actions. | 176 // Mouse event flags which can trigger button actions. |
| 190 int triggerable_event_flags_; | 177 int triggerable_event_flags_; |
| 191 | 178 |
| 192 // See description above setter. | 179 // See description above setter. |
| 193 bool request_focus_on_press_; | 180 bool request_focus_on_press_; |
| 194 | 181 |
| 195 // Animation delegate for the ink drop ripple effect. It is owned by a | |
| 196 // descendant class and needs to be reset before an instance of the concrete | |
| 197 // CustomButton is destroyed. | |
| 198 InkDropDelegate* ink_drop_delegate_; | |
| 199 | |
| 200 // The event on which the button should notify its listener. | 182 // The event on which the button should notify its listener. |
| 201 NotifyAction notify_action_; | 183 NotifyAction notify_action_; |
| 202 | 184 |
| 203 // True when a button click should trigger an animation action on | 185 // True when a button click should trigger an animation action on |
| 204 // |ink_drop_delegate_|. | 186 // |ink_drop_delegate_|. |
| 205 // TODO(bruthig): Use an InkDropAction enum and drop the flag. | 187 // TODO(bruthig): Use an InkDropAction enum and drop the flag. |
| 206 bool has_ink_drop_action_on_click_; | 188 bool has_ink_drop_action_on_click_; |
| 207 | 189 |
| 208 // The animation action to trigger on the |ink_drop_delegate_| when the button | 190 // The animation action to trigger on ink_drop_delegate() when the button |
| 209 // is clicked. | 191 // is clicked. |
| 210 InkDropState ink_drop_action_on_click_; | 192 InkDropState ink_drop_action_on_click_; |
| 211 | 193 |
| 212 // When true, the ink drop ripple and hover will be hidden prior to showing | 194 // When true, the ink drop ripple and hover will be hidden prior to showing |
| 213 // the context menu. | 195 // the context menu. |
| 214 bool hide_ink_drop_when_showing_context_menu_; | 196 bool hide_ink_drop_when_showing_context_menu_; |
| 215 | 197 |
| 216 // The color of the ripple and hover. | 198 // The color of the ripple and hover. |
| 217 SkColor ink_drop_base_color_; | 199 SkColor ink_drop_base_color_; |
| 218 | 200 |
| 219 // The MD-style focus ring. This is not done via a FocusPainter | |
| 220 // because it needs to paint to a layer so it can extend beyond the bounds of | |
| 221 // |this|. | |
| 222 views::View* md_focus_ring_; | |
| 223 | |
| 224 DISALLOW_COPY_AND_ASSIGN(CustomButton); | 201 DISALLOW_COPY_AND_ASSIGN(CustomButton); |
| 225 }; | 202 }; |
| 226 | 203 |
| 227 } // namespace views | 204 } // namespace views |
| 228 | 205 |
| 229 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ | 206 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ |
| OLD | NEW |