| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/button/custom_button.h" | 5 #include "views/controls/button/custom_button.h" |
| 6 | 6 |
| 7 #include "ui/base/accessibility/accessible_view_state.h" | 7 #include "ui/base/accessibility/accessible_view_state.h" |
| 8 #include "ui/base/animation/throb_animation.h" | 8 #include "ui/base/animation/throb_animation.h" |
| 9 #include "ui/base/keycodes/keyboard_codes.h" | 9 #include "ui/base/keycodes/keyboard_codes.h" |
| 10 #include "views/screen.h" | 10 #include "views/screen.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 bool CustomButton::OnMouseDragged(const MouseEvent& event) { | 122 bool CustomButton::OnMouseDragged(const MouseEvent& event) { |
| 123 if (state_ != BS_DISABLED) { | 123 if (state_ != BS_DISABLED) { |
| 124 if (HitTest(event.location())) | 124 if (HitTest(event.location())) |
| 125 SetState(ShouldEnterPushedState(event) ? BS_PUSHED : BS_HOT); | 125 SetState(ShouldEnterPushedState(event) ? BS_PUSHED : BS_HOT); |
| 126 else | 126 else |
| 127 SetState(BS_NORMAL); | 127 SetState(BS_NORMAL); |
| 128 } | 128 } |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void CustomButton::OnMouseReleased(const MouseEvent& event, bool canceled) { | 132 void CustomButton::OnMouseReleased(const MouseEvent& event) { |
| 133 // Starting a drag results in a MouseReleased, we need to ignore it. | 133 if (state_ == BS_DISABLED) |
| 134 if ((state_ == BS_DISABLED) || InDrag()) | |
| 135 return; | 134 return; |
| 136 | 135 |
| 137 if (!HitTest(event.location())) { | 136 if (!HitTest(event.location())) { |
| 138 SetState(BS_NORMAL); | 137 SetState(BS_NORMAL); |
| 139 return; | 138 return; |
| 140 } | 139 } |
| 141 | 140 |
| 142 SetState(BS_HOT); | 141 SetState(BS_HOT); |
| 143 if (!canceled && IsTriggerableEvent(event)) { | 142 if (IsTriggerableEvent(event)) { |
| 144 NotifyClick(event); | 143 NotifyClick(event); |
| 145 // NOTE: We may be deleted at this point (by the listener's notification | 144 // NOTE: We may be deleted at this point (by the listener's notification |
| 146 // handler). | 145 // handler). |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 | 148 |
| 149 void CustomButton::OnMouseCaptureLost() { |
| 150 // Starting a drag results in a MouseCaptureLost, we need to ignore it. |
| 151 if (state_ != BS_DISABLED && !InDrag()) |
| 152 SetState(BS_NORMAL); |
| 153 } |
| 154 |
| 150 void CustomButton::OnMouseEntered(const MouseEvent& event) { | 155 void CustomButton::OnMouseEntered(const MouseEvent& event) { |
| 151 if (state_ != BS_DISABLED) | 156 if (state_ != BS_DISABLED) |
| 152 SetState(BS_HOT); | 157 SetState(BS_HOT); |
| 153 } | 158 } |
| 154 | 159 |
| 155 void CustomButton::OnMouseExited(const MouseEvent& event) { | 160 void CustomButton::OnMouseExited(const MouseEvent& event) { |
| 156 // Starting a drag results in a MouseExited, we need to ignore it. | 161 // Starting a drag results in a MouseExited, we need to ignore it. |
| 157 if (state_ != BS_DISABLED && !InDrag()) | 162 if (state_ != BS_DISABLED && !InDrag()) |
| 158 SetState(BS_NORMAL); | 163 SetState(BS_NORMAL); |
| 159 } | 164 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 bool CustomButton::IsFocusable() const { | 281 bool CustomButton::IsFocusable() const { |
| 277 return (state_ != BS_DISABLED) && View::IsFocusable(); | 282 return (state_ != BS_DISABLED) && View::IsFocusable(); |
| 278 } | 283 } |
| 279 | 284 |
| 280 void CustomButton::OnBlur() { | 285 void CustomButton::OnBlur() { |
| 281 if (IsHotTracked()) | 286 if (IsHotTracked()) |
| 282 SetState(BS_NORMAL); | 287 SetState(BS_NORMAL); |
| 283 } | 288 } |
| 284 | 289 |
| 285 } // namespace views | 290 } // namespace views |
| OLD | NEW |