| 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/base/material_design/material_design_controller.h" | 8 #include "ui/base/material_design/material_design_controller.h" |
| 9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 10 #include "ui/events/event_utils.h" | 10 #include "ui/events/event_utils.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 ink_drop()->GetTargetInkDropState() == | 177 ink_drop()->GetTargetInkDropState() == |
| 178 views::InkDropState::ACTION_PENDING) { | 178 views::InkDropState::ACTION_PENDING) { |
| 179 AnimateInkDrop(views::InkDropState::HIDDEN, &event); | 179 AnimateInkDrop(views::InkDropState::HIDDEN, &event); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 return true; | 183 return true; |
| 184 } | 184 } |
| 185 | 185 |
| 186 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { | 186 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 187 const bool was_pressed = state_ == STATE_PRESSED; |
| 188 |
| 187 if (state_ != STATE_DISABLED) { | 189 if (state_ != STATE_DISABLED) { |
| 188 if (!HitTestPoint(event.location())) { | 190 if (!HitTestPoint(event.location())) { |
| 189 SetState(STATE_NORMAL); | 191 SetState(STATE_NORMAL); |
| 190 } else { | 192 } else { |
| 191 SetState(STATE_HOVERED); | 193 SetState(STATE_HOVERED); |
| 192 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_RELEASE) { | 194 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_RELEASE) { |
| 193 NotifyClick(event); | 195 NotifyClick(event); |
| 194 // NOTE: We may be deleted at this point (by the listener's notification | 196 // NOTE: We may be deleted at this point (by the listener's notification |
| 195 // handler). | 197 // handler). |
| 196 return; | 198 return; |
| 197 } | 199 } |
| 198 } | 200 } |
| 199 } | 201 } |
| 200 if (notify_action_ == NOTIFY_ON_RELEASE) | 202 if (notify_action_ == NOTIFY_ON_RELEASE && was_pressed) |
| 201 OnClickCanceled(event); | 203 OnClickCanceled(event); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void CustomButton::OnMouseCaptureLost() { | 206 void CustomButton::OnMouseCaptureLost() { |
| 205 // Starting a drag results in a MouseCaptureLost. Reset button state. | 207 // Starting a drag results in a MouseCaptureLost. Reset button state. |
| 206 // TODO(varkha) While in drag only reset the state with Material Design. | 208 // TODO(varkha) While in drag only reset the state with Material Design. |
| 207 // The same logic may applies everywhere so gather any feedback and update. | 209 // The same logic may applies everywhere so gather any feedback and update. |
| 208 bool reset_button_state = | 210 bool reset_button_state = |
| 209 !InDrag() || ui::MaterialDesignController::IsModeMaterial(); | 211 !InDrag() || ui::MaterialDesignController::IsModeMaterial(); |
| 210 if (state_ != STATE_DISABLED && reset_button_state) | 212 if (state_ != STATE_DISABLED && reset_button_state) |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 Button::NotifyClick(event); | 471 Button::NotifyClick(event); |
| 470 } | 472 } |
| 471 | 473 |
| 472 void CustomButton::OnClickCanceled(const ui::Event& event) { | 474 void CustomButton::OnClickCanceled(const ui::Event& event) { |
| 473 AnimateInkDrop(views::InkDropState::HIDDEN, | 475 AnimateInkDrop(views::InkDropState::HIDDEN, |
| 474 ui::LocatedEvent::FromIfValid(&event)); | 476 ui::LocatedEvent::FromIfValid(&event)); |
| 475 Button::OnClickCanceled(event); | 477 Button::OnClickCanceled(event); |
| 476 } | 478 } |
| 477 | 479 |
| 478 } // namespace views | 480 } // namespace views |
| OLD | NEW |