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

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

Issue 1478303003: Converted all Views to use an InkDropDelegate instead of a InkDropAnimationController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed CustomButton::set_ink_drop_action_on_click() method. 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
« no previous file with comments | « ui/views/controls/button/custom_button.h ('k') | ui/views/controls/button/menu_button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 !strcmp(classname, ImageButton::kViewClassName) || 48 !strcmp(classname, ImageButton::kViewClassName) ||
49 !strcmp(classname, LabelButton::kViewClassName) || 49 !strcmp(classname, LabelButton::kViewClassName) ||
50 !strcmp(classname, RadioButton::kViewClassName) || 50 !strcmp(classname, RadioButton::kViewClassName) ||
51 !strcmp(classname, MenuButton::kViewClassName)) { 51 !strcmp(classname, MenuButton::kViewClassName)) {
52 return static_cast<CustomButton*>(view); 52 return static_cast<CustomButton*>(view);
53 } 53 }
54 } 54 }
55 return NULL; 55 return NULL;
56 } 56 }
57 57
58 CustomButton::~CustomButton() { 58 CustomButton::~CustomButton() {}
59 // InkDropDelegate needs to be destroyed by now since it may need to call
60 // methods on |this| via InkDropHost.
61 DCHECK(!ink_drop_delegate_);
62 }
63 59
64 void CustomButton::SetState(ButtonState state) { 60 void CustomButton::SetState(ButtonState state) {
65 if (state == state_) 61 if (state == state_)
66 return; 62 return;
67 63
68 if (animate_on_state_change_ && 64 if (animate_on_state_change_ &&
69 (!is_throbbing_ || !hover_animation_->is_animating())) { 65 (!is_throbbing_ || !hover_animation_->is_animating())) {
70 is_throbbing_ = false; 66 is_throbbing_ = false;
71 if ((state_ == STATE_HOVERED) && (state == STATE_NORMAL)) { 67 if ((state_ == STATE_HOVERED) && (state == STATE_NORMAL)) {
72 // For HOVERED -> NORMAL, animate from hovered (1) to not hovered (0). 68 // For HOVERED -> NORMAL, animate from hovered (1) to not hovered (0).
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 SetState(STATE_DISABLED); 132 SetState(STATE_DISABLED);
137 } 133 }
138 134
139 const char* CustomButton::GetClassName() const { 135 const char* CustomButton::GetClassName() const {
140 return kViewClassName; 136 return kViewClassName;
141 } 137 }
142 138
143 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { 139 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) {
144 if (state_ == STATE_DISABLED) 140 if (state_ == STATE_DISABLED)
145 return true; 141 return true;
146 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) 142 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) {
147 SetState(STATE_PRESSED); 143 SetState(STATE_PRESSED);
144 if (ink_drop_delegate_)
145 ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING);
146 }
148 if (request_focus_on_press_) 147 if (request_focus_on_press_)
149 RequestFocus(); 148 RequestFocus();
150 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) { 149 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) {
151 NotifyClick(event); 150 NotifyClick(event);
152 // NOTE: We may be deleted at this point (by the listener's notification 151 // NOTE: We may be deleted at this point (by the listener's notification
153 // handler). 152 // handler).
154 } 153 }
155 return true; 154 return true;
156 } 155 }
157 156
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // CustomButton, protected: 334 // CustomButton, protected:
336 335
337 CustomButton::CustomButton(ButtonListener* listener) 336 CustomButton::CustomButton(ButtonListener* listener)
338 : Button(listener), 337 : Button(listener),
339 state_(STATE_NORMAL), 338 state_(STATE_NORMAL),
340 animate_on_state_change_(true), 339 animate_on_state_change_(true),
341 is_throbbing_(false), 340 is_throbbing_(false),
342 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), 341 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON),
343 request_focus_on_press_(true), 342 request_focus_on_press_(true),
344 ink_drop_delegate_(nullptr), 343 ink_drop_delegate_(nullptr),
345 notify_action_(NOTIFY_ON_RELEASE) { 344 notify_action_(NOTIFY_ON_RELEASE),
345 has_ink_drop_action_on_click_(false),
346 ink_drop_action_on_click_(InkDropState::QUICK_ACTION) {
346 hover_animation_.reset(new gfx::ThrobAnimation(this)); 347 hover_animation_.reset(new gfx::ThrobAnimation(this));
347 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); 348 hover_animation_->SetSlideDuration(kHoverFadeDurationMs);
348 } 349 }
349 350
350 void CustomButton::StateChanged() { 351 void CustomButton::StateChanged() {
351 } 352 }
352 353
353 bool CustomButton::IsTriggerableEvent(const ui::Event& event) { 354 bool CustomButton::IsTriggerableEvent(const ui::Event& event) {
354 return event.type() == ui::ET_GESTURE_TAP_DOWN || 355 return event.type() == ui::ET_GESTURE_TAP_DOWN ||
355 event.type() == ui::ET_GESTURE_TAP || 356 event.type() == ui::ET_GESTURE_TAP ||
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 const ViewHierarchyChangedDetails& details) { 399 const ViewHierarchyChangedDetails& details) {
399 if (!details.is_add && state_ != STATE_DISABLED) 400 if (!details.is_add && state_ != STATE_DISABLED)
400 SetState(STATE_NORMAL); 401 SetState(STATE_NORMAL);
401 } 402 }
402 403
403 void CustomButton::OnBlur() { 404 void CustomButton::OnBlur() {
404 if (IsHotTracked()) 405 if (IsHotTracked())
405 SetState(STATE_NORMAL); 406 SetState(STATE_NORMAL);
406 } 407 }
407 408
409 void CustomButton::NotifyClick(const ui::Event& event) {
410 if (ink_drop_delegate() && has_ink_drop_action_on_click_)
411 ink_drop_delegate()->OnAction(ink_drop_action_on_click_);
412 Button::NotifyClick(event);
413 }
414
415 void CustomButton::OnClickCanceled(const ui::Event& event) {
416 if (ink_drop_delegate())
417 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN);
418 Button::OnClickCanceled(event);
419 }
420
408 bool CustomButton::IsChildWidget() const { 421 bool CustomButton::IsChildWidget() const {
409 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); 422 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget();
410 } 423 }
411 424
412 bool CustomButton::FocusInChildWidget() const { 425 bool CustomButton::FocusInChildWidget() const {
413 return GetWidget() && 426 return GetWidget() &&
414 GetWidget()->GetRootView()->Contains( 427 GetWidget()->GetRootView()->Contains(
415 GetFocusManager()->GetFocusedView()); 428 GetFocusManager()->GetFocusedView());
416 } 429 }
417 430
418 } // namespace views 431 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/custom_button.h ('k') | ui/views/controls/button/menu_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698