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

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

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 4 years, 12 months 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 #include "ui/views/controls/button/custom_button.h" 5 #include "ui/views/controls/button/custom_button.h"
6 6
7 #include "ui/accessibility/ax_view_state.h" 7 #include "ui/accessibility/ax_view_state.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
10 #include "ui/events/keycodes/keyboard_codes.h" 10 #include "ui/events/keycodes/keyboard_codes.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // InkDropDelegate needs to be destroyed by now since it may need to call 59 // InkDropDelegate needs to be destroyed by now since it may need to call
60 // methods on |this| via InkDropHost. 60 // methods on |this| via InkDropHost.
61 DCHECK(!ink_drop_delegate_); 61 DCHECK(!ink_drop_delegate_);
62 } 62 }
63 63
64 void CustomButton::SetState(ButtonState state) { 64 void CustomButton::SetState(ButtonState state) {
65 if (state == state_) 65 if (state == state_)
66 return; 66 return;
67 67
68 if (animate_on_state_change_ && 68 if (animate_on_state_change_ &&
69 (!is_throbbing_ || !hover_animation_->is_animating())) { 69 (!is_throbbing_ || !hover_animation_.is_animating())) {
70 is_throbbing_ = false; 70 is_throbbing_ = false;
71 if ((state_ == STATE_HOVERED) && (state == STATE_NORMAL)) { 71 if ((state_ == STATE_HOVERED) && (state == STATE_NORMAL)) {
72 // For HOVERED -> NORMAL, animate from hovered (1) to not hovered (0). 72 // For HOVERED -> NORMAL, animate from hovered (1) to not hovered (0).
73 hover_animation_->Hide(); 73 hover_animation_.Hide();
74 } else if (state != STATE_HOVERED) { 74 } else if (state != STATE_HOVERED) {
75 // For HOVERED -> PRESSED/DISABLED, or any transition not involving 75 // For HOVERED -> PRESSED/DISABLED, or any transition not involving
76 // HOVERED at all, simply set the state to not hovered (0). 76 // HOVERED at all, simply set the state to not hovered (0).
77 hover_animation_->Reset(); 77 hover_animation_.Reset();
78 } else if (state_ == STATE_NORMAL) { 78 } else if (state_ == STATE_NORMAL) {
79 // For NORMAL -> HOVERED, animate from not hovered (0) to hovered (1). 79 // For NORMAL -> HOVERED, animate from not hovered (0) to hovered (1).
80 hover_animation_->Show(); 80 hover_animation_.Show();
81 } else { 81 } else {
82 // For PRESSED/DISABLED -> HOVERED, simply set the state to hovered (1). 82 // For PRESSED/DISABLED -> HOVERED, simply set the state to hovered (1).
83 hover_animation_->Reset(1); 83 hover_animation_.Reset(1);
84 } 84 }
85 } 85 }
86 86
87 state_ = state; 87 state_ = state;
88 StateChanged(); 88 StateChanged();
89 SchedulePaint(); 89 SchedulePaint();
90 } 90 }
91 91
92 void CustomButton::StartThrobbing(int cycles_til_stop) { 92 void CustomButton::StartThrobbing(int cycles_til_stop) {
93 is_throbbing_ = true; 93 is_throbbing_ = true;
94 hover_animation_->StartThrobbing(cycles_til_stop); 94 hover_animation_.StartThrobbing(cycles_til_stop);
95 } 95 }
96 96
97 void CustomButton::StopThrobbing() { 97 void CustomButton::StopThrobbing() {
98 if (hover_animation_->is_animating()) { 98 if (hover_animation_.is_animating()) {
99 hover_animation_->Stop(); 99 hover_animation_.Stop();
100 SchedulePaint(); 100 SchedulePaint();
101 } 101 }
102 } 102 }
103 103
104 void CustomButton::SetAnimationDuration(int duration) { 104 void CustomButton::SetAnimationDuration(int duration) {
105 hover_animation_->SetSlideDuration(duration); 105 hover_animation_.SetSlideDuration(duration);
106 } 106 }
107 107
108 void CustomButton::SetHotTracked(bool is_hot_tracked) { 108 void CustomButton::SetHotTracked(bool is_hot_tracked) {
109 if (state_ != STATE_DISABLED) 109 if (state_ != STATE_DISABLED)
110 SetState(is_hot_tracked ? STATE_HOVERED : STATE_NORMAL); 110 SetState(is_hot_tracked ? STATE_HOVERED : STATE_NORMAL);
111 111
112 if (is_hot_tracked) 112 if (is_hot_tracked)
113 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); 113 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true);
114 } 114 }
115 115
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 Button::OnGestureEvent(event); 237 Button::OnGestureEvent(event);
238 return; 238 return;
239 } 239 }
240 240
241 if (event->type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(*event)) { 241 if (event->type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(*event)) {
242 // Set the button state to hot and start the animation fully faded in. The 242 // Set the button state to hot and start the animation fully faded in. The
243 // GESTURE_END event issued immediately after will set the state to 243 // GESTURE_END event issued immediately after will set the state to
244 // STATE_NORMAL beginning the fade out animation. See 244 // STATE_NORMAL beginning the fade out animation. See
245 // http://crbug.com/131184. 245 // http://crbug.com/131184.
246 SetState(STATE_HOVERED); 246 SetState(STATE_HOVERED);
247 hover_animation_->Reset(1.0); 247 hover_animation_.Reset(1.0);
248 NotifyClick(*event); 248 NotifyClick(*event);
249 event->StopPropagation(); 249 event->StopPropagation();
250 } else if (event->type() == ui::ET_GESTURE_TAP_DOWN && 250 } else if (event->type() == ui::ET_GESTURE_TAP_DOWN &&
251 ShouldEnterPushedState(*event)) { 251 ShouldEnterPushedState(*event)) {
252 SetState(STATE_PRESSED); 252 SetState(STATE_PRESSED);
253 if (request_focus_on_press_) 253 if (request_focus_on_press_)
254 RequestFocus(); 254 RequestFocus();
255 event->StopPropagation(); 255 event->StopPropagation();
256 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || 256 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL ||
257 event->type() == ui::ET_GESTURE_END) { 257 event->type() == ui::ET_GESTURE_END) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 void CustomButton::AnimationProgressed(const gfx::Animation* animation) { 330 void CustomButton::AnimationProgressed(const gfx::Animation* animation) {
331 SchedulePaint(); 331 SchedulePaint();
332 } 332 }
333 333
334 //////////////////////////////////////////////////////////////////////////////// 334 ////////////////////////////////////////////////////////////////////////////////
335 // CustomButton, protected: 335 // CustomButton, protected:
336 336
337 CustomButton::CustomButton(ButtonListener* listener) 337 CustomButton::CustomButton(ButtonListener* listener)
338 : Button(listener), 338 : Button(listener),
339 state_(STATE_NORMAL), 339 state_(STATE_NORMAL),
340 hover_animation_(this),
340 animate_on_state_change_(true), 341 animate_on_state_change_(true),
341 is_throbbing_(false), 342 is_throbbing_(false),
342 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), 343 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON),
343 request_focus_on_press_(true), 344 request_focus_on_press_(true),
344 ink_drop_delegate_(nullptr), 345 ink_drop_delegate_(nullptr),
345 notify_action_(NOTIFY_ON_RELEASE) { 346 notify_action_(NOTIFY_ON_RELEASE) {
346 hover_animation_.reset(new gfx::ThrobAnimation(this)); 347 hover_animation_.SetSlideDuration(kHoverFadeDurationMs);
347 hover_animation_->SetSlideDuration(kHoverFadeDurationMs);
348 } 348 }
349 349
350 void CustomButton::StateChanged() { 350 void CustomButton::StateChanged() {
351 } 351 }
352 352
353 bool CustomButton::IsTriggerableEvent(const ui::Event& event) { 353 bool CustomButton::IsTriggerableEvent(const ui::Event& event) {
354 return event.type() == ui::ET_GESTURE_TAP_DOWN || 354 return event.type() == ui::ET_GESTURE_TAP_DOWN ||
355 event.type() == ui::ET_GESTURE_TAP || 355 event.type() == ui::ET_GESTURE_TAP ||
356 (event.IsMouseEvent() && 356 (event.IsMouseEvent() &&
357 (triggerable_event_flags_ & event.flags()) != 0); 357 (triggerable_event_flags_ & event.flags()) != 0);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); 409 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget();
410 } 410 }
411 411
412 bool CustomButton::FocusInChildWidget() const { 412 bool CustomButton::FocusInChildWidget() const {
413 return GetWidget() && 413 return GetWidget() &&
414 GetWidget()->GetRootView()->Contains( 414 GetWidget()->GetRootView()->Contains(
415 GetFocusManager()->GetFocusedView()); 415 GetFocusManager()->GetFocusedView());
416 } 416 }
417 417
418 } // namespace views 418 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698