Chromium Code Reviews| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 59 // |ink_drop_delegate_| is invalid here since it is owned, and destroyed by |
| 60 // methods on |this| via InkDropHost. | 60 // descendant classes. |
|
Peter Kasting
2015/12/18 18:44:03
I wouldn't add this comment, since there's no reas
bruthig
2015/12/21 16:54:34
Done.
| |
| 61 DCHECK(!ink_drop_delegate_); | |
| 62 } | 61 } |
| 63 | 62 |
| 64 void CustomButton::SetState(ButtonState state) { | 63 void CustomButton::SetState(ButtonState state) { |
| 65 if (state == state_) | 64 if (state == state_) |
| 66 return; | 65 return; |
| 67 | 66 |
| 68 if (animate_on_state_change_ && | 67 if (animate_on_state_change_ && |
| 69 (!is_throbbing_ || !hover_animation_->is_animating())) { | 68 (!is_throbbing_ || !hover_animation_->is_animating())) { |
| 70 is_throbbing_ = false; | 69 is_throbbing_ = false; |
| 71 if ((state_ == STATE_HOVERED) && (state == STATE_NORMAL)) { | 70 if ((state_ == STATE_HOVERED) && (state == STATE_NORMAL)) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 SetState(STATE_DISABLED); | 135 SetState(STATE_DISABLED); |
| 137 } | 136 } |
| 138 | 137 |
| 139 const char* CustomButton::GetClassName() const { | 138 const char* CustomButton::GetClassName() const { |
| 140 return kViewClassName; | 139 return kViewClassName; |
| 141 } | 140 } |
| 142 | 141 |
| 143 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { | 142 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { |
| 144 if (state_ == STATE_DISABLED) | 143 if (state_ == STATE_DISABLED) |
| 145 return true; | 144 return true; |
| 146 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) | 145 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) { |
| 147 SetState(STATE_PRESSED); | 146 SetState(STATE_PRESSED); |
| 147 if (ink_drop_delegate_) | |
| 148 ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING); | |
| 149 } | |
| 148 if (request_focus_on_press_) | 150 if (request_focus_on_press_) |
| 149 RequestFocus(); | 151 RequestFocus(); |
| 150 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) { | 152 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) { |
| 151 NotifyClick(event); | 153 NotifyClick(event); |
| 152 // NOTE: We may be deleted at this point (by the listener's notification | 154 // NOTE: We may be deleted at this point (by the listener's notification |
| 153 // handler). | 155 // handler). |
| 154 } | 156 } |
| 155 return true; | 157 return true; |
| 156 } | 158 } |
| 157 | 159 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 // CustomButton, protected: | 337 // CustomButton, protected: |
| 336 | 338 |
| 337 CustomButton::CustomButton(ButtonListener* listener) | 339 CustomButton::CustomButton(ButtonListener* listener) |
| 338 : Button(listener), | 340 : Button(listener), |
| 339 state_(STATE_NORMAL), | 341 state_(STATE_NORMAL), |
| 340 animate_on_state_change_(true), | 342 animate_on_state_change_(true), |
| 341 is_throbbing_(false), | 343 is_throbbing_(false), |
| 342 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), | 344 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), |
| 343 request_focus_on_press_(true), | 345 request_focus_on_press_(true), |
| 344 ink_drop_delegate_(nullptr), | 346 ink_drop_delegate_(nullptr), |
| 345 notify_action_(NOTIFY_ON_RELEASE) { | 347 notify_action_(NOTIFY_ON_RELEASE), |
| 348 has_ink_drop_action_on_click_(false), | |
| 349 ink_drop_action_on_click_(InkDropState::QUICK_ACTION) { | |
| 346 hover_animation_.reset(new gfx::ThrobAnimation(this)); | 350 hover_animation_.reset(new gfx::ThrobAnimation(this)); |
| 347 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); | 351 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); |
| 348 } | 352 } |
| 349 | 353 |
| 350 void CustomButton::StateChanged() { | 354 void CustomButton::StateChanged() { |
| 351 } | 355 } |
| 352 | 356 |
| 353 bool CustomButton::IsTriggerableEvent(const ui::Event& event) { | 357 bool CustomButton::IsTriggerableEvent(const ui::Event& event) { |
| 354 return event.type() == ui::ET_GESTURE_TAP_DOWN || | 358 return event.type() == ui::ET_GESTURE_TAP_DOWN || |
| 355 event.type() == ui::ET_GESTURE_TAP || | 359 event.type() == ui::ET_GESTURE_TAP || |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 const ViewHierarchyChangedDetails& details) { | 402 const ViewHierarchyChangedDetails& details) { |
| 399 if (!details.is_add && state_ != STATE_DISABLED) | 403 if (!details.is_add && state_ != STATE_DISABLED) |
| 400 SetState(STATE_NORMAL); | 404 SetState(STATE_NORMAL); |
| 401 } | 405 } |
| 402 | 406 |
| 403 void CustomButton::OnBlur() { | 407 void CustomButton::OnBlur() { |
| 404 if (IsHotTracked()) | 408 if (IsHotTracked()) |
| 405 SetState(STATE_NORMAL); | 409 SetState(STATE_NORMAL); |
| 406 } | 410 } |
| 407 | 411 |
| 412 void CustomButton::NotifyClick(const ui::Event& event) { | |
| 413 if (ink_drop_delegate() && has_ink_drop_action_on_click_) | |
| 414 ink_drop_delegate()->OnAction(ink_drop_action_on_click_); | |
| 415 Button::NotifyClick(event); | |
| 416 } | |
| 417 | |
| 418 void CustomButton::OnClickCanceled(const ui::Event& event) { | |
| 419 if (ink_drop_delegate()) | |
| 420 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); | |
| 421 Button::OnClickCanceled(event); | |
| 422 } | |
| 423 | |
| 408 bool CustomButton::IsChildWidget() const { | 424 bool CustomButton::IsChildWidget() const { |
| 409 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | 425 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); |
| 410 } | 426 } |
| 411 | 427 |
| 412 bool CustomButton::FocusInChildWidget() const { | 428 bool CustomButton::FocusInChildWidget() const { |
| 413 return GetWidget() && | 429 return GetWidget() && |
| 414 GetWidget()->GetRootView()->Contains( | 430 GetWidget()->GetRootView()->Contains( |
| 415 GetFocusManager()->GetFocusedView()); | 431 GetFocusManager()->GetFocusedView()); |
| 416 } | 432 } |
| 417 | 433 |
| 418 } // namespace views | 434 } // namespace views |
| OLD | NEW |