| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/keyboard_codes.h" |
| 7 #include "app/throb_animation.h" | 8 #include "app/throb_animation.h" |
| 8 #include "base/keyboard_codes.h" | |
| 9 #include "views/screen.h" | 9 #include "views/screen.h" |
| 10 | 10 |
| 11 namespace views { | 11 namespace views { |
| 12 | 12 |
| 13 // How long the hover animation takes if uninterrupted. | 13 // How long the hover animation takes if uninterrupted. |
| 14 static const int kHoverFadeDurationMs = 150; | 14 static const int kHoverFadeDurationMs = 150; |
| 15 | 15 |
| 16 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
| 17 // CustomButton, public: | 17 // CustomButton, public: |
| 18 | 18 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 SetState(BS_NORMAL); | 185 SetState(BS_NORMAL); |
| 186 } | 186 } |
| 187 | 187 |
| 188 bool CustomButton::OnKeyPressed(const KeyEvent& e) { | 188 bool CustomButton::OnKeyPressed(const KeyEvent& e) { |
| 189 if (state_ == BS_DISABLED) | 189 if (state_ == BS_DISABLED) |
| 190 return false; | 190 return false; |
| 191 | 191 |
| 192 // Space sets button state to pushed. Enter clicks the button. This matches | 192 // Space sets button state to pushed. Enter clicks the button. This matches |
| 193 // the Windows native behavior of buttons, where Space clicks the button on | 193 // the Windows native behavior of buttons, where Space clicks the button on |
| 194 // KeyRelease and Enter clicks the button on KeyPressed. | 194 // KeyRelease and Enter clicks the button on KeyPressed. |
| 195 if (e.GetKeyCode() == base::VKEY_SPACE) { | 195 if (e.GetKeyCode() == app::VKEY_SPACE) { |
| 196 SetState(BS_PUSHED); | 196 SetState(BS_PUSHED); |
| 197 } else if (e.GetKeyCode() == base::VKEY_RETURN) { | 197 } else if (e.GetKeyCode() == app::VKEY_RETURN) { |
| 198 SetState(BS_NORMAL); | 198 SetState(BS_NORMAL); |
| 199 NotifyClick(e); | 199 NotifyClick(e); |
| 200 } | 200 } |
| 201 return true; | 201 return true; |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool CustomButton::OnKeyReleased(const KeyEvent& e) { | 204 bool CustomButton::OnKeyReleased(const KeyEvent& e) { |
| 205 if ((state_ == BS_DISABLED) || (e.GetKeyCode() != base::VKEY_SPACE)) | 205 if ((state_ == BS_DISABLED) || (e.GetKeyCode() != app::VKEY_SPACE)) |
| 206 return false; | 206 return false; |
| 207 | 207 |
| 208 SetState(BS_NORMAL); | 208 SetState(BS_NORMAL); |
| 209 NotifyClick(e); | 209 NotifyClick(e); |
| 210 return true; | 210 return true; |
| 211 } | 211 } |
| 212 | 212 |
| 213 void CustomButton::OnDragDone() { | 213 void CustomButton::OnDragDone() { |
| 214 SetState(BS_NORMAL); | 214 SetState(BS_NORMAL); |
| 215 } | 215 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 253 |
| 254 void CustomButton::AnimationProgressed(const Animation* animation) { | 254 void CustomButton::AnimationProgressed(const Animation* animation) { |
| 255 SchedulePaint(); | 255 SchedulePaint(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 bool CustomButton::ShouldEnterPushedState(const MouseEvent& e) { | 258 bool CustomButton::ShouldEnterPushedState(const MouseEvent& e) { |
| 259 return IsTriggerableEvent(e); | 259 return IsTriggerableEvent(e); |
| 260 } | 260 } |
| 261 | 261 |
| 262 } // namespace views | 262 } // namespace views |
| OLD | NEW |