Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: ui/views/controls/button/custom_button.h

Issue 1534303002: CustomButton cleanup: make protected members private, create accessors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tidy up Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/gfx/animation/throb_animation.h"
11 #include "ui/views/controls/button/button.h" 12 #include "ui/views/controls/button/button.h"
12 13
13 namespace gfx {
14 class ThrobAnimation;
15 }
16
17 namespace views { 14 namespace views {
18 15
19 class InkDropDelegate; 16 class InkDropDelegate;
20 17
21 // A button with custom rendering. The base of ImageButton and LabelButton. 18 // 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 19 // 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 20 // part of the focus chain. Call SetFocusable(true) to make it part of the
24 // focus chain. 21 // focus chain.
25 class VIEWS_EXPORT CustomButton : public Button, 22 class VIEWS_EXPORT CustomButton : public Button,
26 public gfx::AnimationDelegate { 23 public gfx::AnimationDelegate {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // holds the mouse down over the button. For this implementation, 116 // holds the mouse down over the button. For this implementation,
120 // we simply return IsTriggerableEvent(event). 117 // we simply return IsTriggerableEvent(event).
121 virtual bool ShouldEnterPushedState(const ui::Event& event); 118 virtual bool ShouldEnterPushedState(const ui::Event& event);
122 119
123 // Returns true if the button should enter hovered state; that is, if the 120 // Returns true if the button should enter hovered state; that is, if the
124 // mouse is over the button, and no other window has capture (which would 121 // mouse is over the button, and no other window has capture (which would
125 // prevent the button from receiving MouseExited events and updating its 122 // prevent the button from receiving MouseExited events and updating its
126 // state). This does not take into account enabled state. 123 // state). This does not take into account enabled state.
127 bool ShouldEnterHoveredState(); 124 bool ShouldEnterHoveredState();
128 125
129 InkDropDelegate* ink_drop_delegate() const { return ink_drop_delegate_; }
130 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) {
131 ink_drop_delegate_ = ink_drop_delegate;
132 }
133
134 // Overridden from View: 126 // Overridden from View:
135 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 127 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
136 void ViewHierarchyChanged( 128 void ViewHierarchyChanged(
137 const ViewHierarchyChangedDetails& details) override; 129 const ViewHierarchyChangedDetails& details) override;
138 void OnBlur() override; 130 void OnBlur() override;
139 131
140 // The button state (defined in implementation) 132 const gfx::ThrobAnimation& hover_animation() const {
141 ButtonState state_; 133 return hover_animation_;
142 134 }
143 // Hover animation. 135 InkDropDelegate* ink_drop_delegate() const { return ink_drop_delegate_; }
144 scoped_ptr<gfx::ThrobAnimation> hover_animation_; 136 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) {
137 ink_drop_delegate_ = ink_drop_delegate;
138 }
145 139
146 private: 140 private:
147 // Returns true if this is not a top level widget. Virtual for tests. 141 // Returns true if this is not a top level widget. Virtual for tests.
148 virtual bool IsChildWidget() const; 142 virtual bool IsChildWidget() const;
149 // Returns true if the focus is not in a top level widget. Virtual for tests. 143 // Returns true if the focus is not in a top level widget. Virtual for tests.
150 virtual bool FocusInChildWidget() const; 144 virtual bool FocusInChildWidget() const;
151 145
146 // The button state.
147 ButtonState state_;
148
149 // Hover animation.
sadrul 2015/12/21 22:05:31 The comments aren't probably necessary really.
Evan Stade 2015/12/21 22:27:16 Done.
150 gfx::ThrobAnimation hover_animation_;
151
152 // Should we animate when the state changes? Defaults to true. 152 // Should we animate when the state changes? Defaults to true.
153 bool animate_on_state_change_; 153 bool animate_on_state_change_;
154 154
155 // Is the hover animation running because StartThrob was invoked? 155 // Is the hover animation running because StartThrob was invoked?
156 bool is_throbbing_; 156 bool is_throbbing_;
157 157
158 // Mouse event flags which can trigger button actions. 158 // Mouse event flags which can trigger button actions.
159 int triggerable_event_flags_; 159 int triggerable_event_flags_;
160 160
161 // See description above setter. 161 // See description above setter.
162 bool request_focus_on_press_; 162 bool request_focus_on_press_;
163 163
164 // Animation delegate for the ink drop ripple effect. It is owned by a 164 // Animation delegate for the ink drop ripple effect. It is owned by a
165 // descendant class and needs to be reset before an instance of the concrete 165 // descendant class and needs to be reset before an instance of the concrete
166 // CustomButton is destroyed. 166 // CustomButton is destroyed.
167 InkDropDelegate* ink_drop_delegate_; 167 InkDropDelegate* ink_drop_delegate_;
168 168
169 // The event on which the button should notify its listener. 169 // The event on which the button should notify its listener.
170 NotifyAction notify_action_; 170 NotifyAction notify_action_;
171 171
172 DISALLOW_COPY_AND_ASSIGN(CustomButton); 172 DISALLOW_COPY_AND_ASSIGN(CustomButton);
173 }; 173 };
174 174
175 } // namespace views 175 } // namespace views
176 176
177 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_ 177 #endif // UI_VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698