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 #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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 SetState(STATE_DISABLED); | 136 SetState(STATE_DISABLED); |
137 } | 137 } |
138 | 138 |
139 const char* CustomButton::GetClassName() const { | 139 const char* CustomButton::GetClassName() const { |
140 return kViewClassName; | 140 return kViewClassName; |
141 } | 141 } |
142 | 142 |
143 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { | 143 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { |
144 if (state_ == STATE_DISABLED) | 144 if (state_ == STATE_DISABLED) |
145 return true; | 145 return true; |
146 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) | 146 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) { |
147 SetState(STATE_PRESSED); | 147 SetState(STATE_PRESSED); |
| 148 if (ink_drop_delegate_) |
| 149 ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING); |
| 150 } |
148 if (request_focus_on_press_) | 151 if (request_focus_on_press_) |
149 RequestFocus(); | 152 RequestFocus(); |
150 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) { | 153 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) { |
151 NotifyClick(event); | 154 NotifyClick(event); |
152 // NOTE: We may be deleted at this point (by the listener's notification | 155 // NOTE: We may be deleted at this point (by the listener's notification |
153 // handler). | 156 // handler). |
154 } | 157 } |
155 return true; | 158 return true; |
156 } | 159 } |
157 | 160 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // CustomButton, protected: | 338 // CustomButton, protected: |
336 | 339 |
337 CustomButton::CustomButton(ButtonListener* listener) | 340 CustomButton::CustomButton(ButtonListener* listener) |
338 : Button(listener), | 341 : Button(listener), |
339 state_(STATE_NORMAL), | 342 state_(STATE_NORMAL), |
340 animate_on_state_change_(true), | 343 animate_on_state_change_(true), |
341 is_throbbing_(false), | 344 is_throbbing_(false), |
342 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), | 345 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), |
343 request_focus_on_press_(true), | 346 request_focus_on_press_(true), |
344 ink_drop_delegate_(nullptr), | 347 ink_drop_delegate_(nullptr), |
345 notify_action_(NOTIFY_ON_RELEASE) { | 348 notify_action_(NOTIFY_ON_RELEASE), |
| 349 has_ink_drop_action_on_click_(false), |
| 350 ink_drop_action_on_click_(InkDropState::QUICK_ACTION) { |
346 hover_animation_.reset(new gfx::ThrobAnimation(this)); | 351 hover_animation_.reset(new gfx::ThrobAnimation(this)); |
347 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); | 352 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); |
348 } | 353 } |
349 | 354 |
350 void CustomButton::StateChanged() { | 355 void CustomButton::StateChanged() { |
351 } | 356 } |
352 | 357 |
353 bool CustomButton::IsTriggerableEvent(const ui::Event& event) { | 358 bool CustomButton::IsTriggerableEvent(const ui::Event& event) { |
354 return event.type() == ui::ET_GESTURE_TAP_DOWN || | 359 return event.type() == ui::ET_GESTURE_TAP_DOWN || |
355 event.type() == ui::ET_GESTURE_TAP || | 360 event.type() == ui::ET_GESTURE_TAP || |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 const ViewHierarchyChangedDetails& details) { | 403 const ViewHierarchyChangedDetails& details) { |
399 if (!details.is_add && state_ != STATE_DISABLED) | 404 if (!details.is_add && state_ != STATE_DISABLED) |
400 SetState(STATE_NORMAL); | 405 SetState(STATE_NORMAL); |
401 } | 406 } |
402 | 407 |
403 void CustomButton::OnBlur() { | 408 void CustomButton::OnBlur() { |
404 if (IsHotTracked()) | 409 if (IsHotTracked()) |
405 SetState(STATE_NORMAL); | 410 SetState(STATE_NORMAL); |
406 } | 411 } |
407 | 412 |
| 413 void CustomButton::NotifyClick(const ui::Event& event) { |
| 414 if (ink_drop_delegate() && has_ink_drop_action_on_click_) |
| 415 ink_drop_delegate()->OnAction(ink_drop_action_on_click_); |
| 416 Button::NotifyClick(event); |
| 417 } |
| 418 |
| 419 void CustomButton::OnClickCanceled(const ui::Event& event) { |
| 420 if (ink_drop_delegate()) |
| 421 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); |
| 422 Button::OnClickCanceled(event); |
| 423 } |
| 424 |
408 bool CustomButton::IsChildWidget() const { | 425 bool CustomButton::IsChildWidget() const { |
409 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | 426 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); |
410 } | 427 } |
411 | 428 |
412 bool CustomButton::FocusInChildWidget() const { | 429 bool CustomButton::FocusInChildWidget() const { |
413 return GetWidget() && | 430 return GetWidget() && |
414 GetWidget()->GetRootView()->Contains( | 431 GetWidget()->GetRootView()->Contains( |
415 GetFocusManager()->GetFocusedView()); | 432 GetFocusManager()->GetFocusedView()); |
416 } | 433 } |
417 | 434 |
418 } // namespace views | 435 } // namespace views |
OLD | NEW |