| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/throb_animation.h" | 7 #include "app/throb_animation.h" |
| 8 #include "base/keyboard_codes.h" | 8 #include "base/keyboard_codes.h" |
| 9 | 9 |
| 10 namespace views { | 10 namespace views { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (enabled_) { | 90 if (enabled_) { |
| 91 SetState(BS_NORMAL); | 91 SetState(BS_NORMAL); |
| 92 NotifyClick(0); | 92 NotifyClick(0); |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool CustomButton::OnMousePressed(const MouseEvent& e) { | 98 bool CustomButton::OnMousePressed(const MouseEvent& e) { |
| 99 if (state_ != BS_DISABLED) { | 99 if (state_ != BS_DISABLED) { |
| 100 if (IsTriggerableEvent(e) && HitTest(e.location())) | 100 if (ShouldEnterPushedState(e) && HitTest(e.location())) |
| 101 SetState(BS_PUSHED); | 101 SetState(BS_PUSHED); |
| 102 RequestFocus(); | 102 RequestFocus(); |
| 103 } | 103 } |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool CustomButton::OnMouseDragged(const MouseEvent& e) { | 107 bool CustomButton::OnMouseDragged(const MouseEvent& e) { |
| 108 if (state_ != BS_DISABLED) { | 108 if (state_ != BS_DISABLED) { |
| 109 if (!HitTest(e.location())) | 109 if (!HitTest(e.location())) |
| 110 SetState(BS_NORMAL); | 110 SetState(BS_NORMAL); |
| 111 else if (IsTriggerableEvent(e)) | 111 else if (ShouldEnterPushedState(e)) |
| 112 SetState(BS_PUSHED); | 112 SetState(BS_PUSHED); |
| 113 else | 113 else |
| 114 SetState(BS_HOT); | 114 SetState(BS_HOT); |
| 115 } | 115 } |
| 116 return true; | 116 return true; |
| 117 } | 117 } |
| 118 | 118 |
| 119 void CustomButton::OnMouseReleased(const MouseEvent& e, bool canceled) { | 119 void CustomButton::OnMouseReleased(const MouseEvent& e, bool canceled) { |
| 120 if (InDrag()) { | 120 if (InDrag()) { |
| 121 // Starting a drag results in a MouseReleased, we need to ignore it. | 121 // Starting a drag results in a MouseReleased, we need to ignore it. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 SetState(BS_NORMAL); | 207 SetState(BS_NORMAL); |
| 208 } | 208 } |
| 209 | 209 |
| 210 //////////////////////////////////////////////////////////////////////////////// | 210 //////////////////////////////////////////////////////////////////////////////// |
| 211 // CustomButton, AnimationDelegate implementation: | 211 // CustomButton, AnimationDelegate implementation: |
| 212 | 212 |
| 213 void CustomButton::AnimationProgressed(const Animation* animation) { | 213 void CustomButton::AnimationProgressed(const Animation* animation) { |
| 214 SchedulePaint(); | 214 SchedulePaint(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool CustomButton::ShouldEnterPushedState(const MouseEvent& e) { |
| 218 return IsTriggerableEvent(e); |
| 219 } |
| 220 |
| 217 //////////////////////////////////////////////////////////////////////////////// | 221 //////////////////////////////////////////////////////////////////////////////// |
| 218 // CustomButton, private: | 222 // CustomButton, private: |
| 219 | 223 |
| 220 void CustomButton::SetHighlighted(bool highlighted) { | 224 void CustomButton::SetHighlighted(bool highlighted) { |
| 221 if (highlighted && state_ != BS_DISABLED) { | 225 if (highlighted && state_ != BS_DISABLED) { |
| 222 SetState(BS_HOT); | 226 SetState(BS_HOT); |
| 223 } else if (!highlighted && state_ != BS_DISABLED) { | 227 } else if (!highlighted && state_ != BS_DISABLED) { |
| 224 SetState(BS_NORMAL); | 228 SetState(BS_NORMAL); |
| 225 } | 229 } |
| 226 } | 230 } |
| 227 | 231 |
| 228 bool CustomButton::IsHighlighted() const { | 232 bool CustomButton::IsHighlighted() const { |
| 229 return state_ == BS_HOT; | 233 return state_ == BS_HOT; |
| 230 } | 234 } |
| 231 | 235 |
| 232 bool CustomButton::IsPushed() const { | 236 bool CustomButton::IsPushed() const { |
| 233 return state_ == BS_PUSHED; | 237 return state_ == BS_PUSHED; |
| 234 } | 238 } |
| 235 | 239 |
| 236 } // namespace views | 240 } // namespace views |
| OLD | NEW |