| 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 "ui/base/animation/throb_animation.h" | 7 #include "ui/base/animation/throb_animation.h" |
| 8 #include "ui/base/keycodes/keyboard_codes.h" | 8 #include "ui/base/keycodes/keyboard_codes.h" |
| 9 #include "views/screen.h" | 9 #include "views/screen.h" |
| 10 | 10 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 state_(BS_NORMAL), | 118 state_(BS_NORMAL), |
| 119 animate_on_state_change_(true), | 119 animate_on_state_change_(true), |
| 120 is_throbbing_(false), | 120 is_throbbing_(false), |
| 121 triggerable_event_flags_(MouseEvent::EF_LEFT_BUTTON_DOWN), | 121 triggerable_event_flags_(MouseEvent::EF_LEFT_BUTTON_DOWN), |
| 122 request_focus_on_press_(true) { | 122 request_focus_on_press_(true) { |
| 123 hover_animation_.reset(new ui::ThrobAnimation(this)); | 123 hover_animation_.reset(new ui::ThrobAnimation(this)); |
| 124 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); | 124 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool CustomButton::IsTriggerableEvent(const MouseEvent& e) { | 127 bool CustomButton::IsTriggerableEvent(const MouseEvent& e) { |
| 128 return (triggerable_event_flags_ & e.GetFlags()) != 0; | 128 return (triggerable_event_flags_ & e.flags()) != 0; |
| 129 } | 129 } |
| 130 | 130 |
| 131 //////////////////////////////////////////////////////////////////////////////// | 131 //////////////////////////////////////////////////////////////////////////////// |
| 132 // CustomButton, View overrides (protected): | 132 // CustomButton, View overrides (protected): |
| 133 | 133 |
| 134 bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) { | 134 bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) { |
| 135 if (!enabled_) | 135 if (!enabled_) |
| 136 return false; | 136 return false; |
| 137 | 137 |
| 138 SetState(BS_NORMAL); | 138 SetState(BS_NORMAL); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 SetState(BS_NORMAL); | 196 SetState(BS_NORMAL); |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool CustomButton::OnKeyPressed(const KeyEvent& e) { | 199 bool CustomButton::OnKeyPressed(const KeyEvent& e) { |
| 200 if (state_ == BS_DISABLED) | 200 if (state_ == BS_DISABLED) |
| 201 return false; | 201 return false; |
| 202 | 202 |
| 203 // Space sets button state to pushed. Enter clicks the button. This matches | 203 // Space sets button state to pushed. Enter clicks the button. This matches |
| 204 // the Windows native behavior of buttons, where Space clicks the button on | 204 // the Windows native behavior of buttons, where Space clicks the button on |
| 205 // KeyRelease and Enter clicks the button on KeyPressed. | 205 // KeyRelease and Enter clicks the button on KeyPressed. |
| 206 if (e.GetKeyCode() == ui::VKEY_SPACE) { | 206 if (e.key_code() == ui::VKEY_SPACE) { |
| 207 SetState(BS_PUSHED); | 207 SetState(BS_PUSHED); |
| 208 } else if (e.GetKeyCode() == ui::VKEY_RETURN) { | 208 } else if (e.key_code() == ui::VKEY_RETURN) { |
| 209 SetState(BS_NORMAL); | 209 SetState(BS_NORMAL); |
| 210 NotifyClick(e); | 210 NotifyClick(e); |
| 211 } else { | 211 } else { |
| 212 return false; | 212 return false; |
| 213 } | 213 } |
| 214 return true; | 214 return true; |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool CustomButton::OnKeyReleased(const KeyEvent& e) { | 217 bool CustomButton::OnKeyReleased(const KeyEvent& e) { |
| 218 if ((state_ == BS_DISABLED) || (e.GetKeyCode() != ui::VKEY_SPACE)) | 218 if ((state_ == BS_DISABLED) || (e.key_code() != ui::VKEY_SPACE)) |
| 219 return false; | 219 return false; |
| 220 | 220 |
| 221 SetState(BS_NORMAL); | 221 SetState(BS_NORMAL); |
| 222 NotifyClick(e); | 222 NotifyClick(e); |
| 223 return true; | 223 return true; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void CustomButton::OnDragDone() { | 226 void CustomButton::OnDragDone() { |
| 227 SetState(BS_NORMAL); | 227 SetState(BS_NORMAL); |
| 228 } | 228 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 266 |
| 267 void CustomButton::AnimationProgressed(const ui::Animation* animation) { | 267 void CustomButton::AnimationProgressed(const ui::Animation* animation) { |
| 268 SchedulePaint(); | 268 SchedulePaint(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 bool CustomButton::ShouldEnterPushedState(const MouseEvent& e) { | 271 bool CustomButton::ShouldEnterPushedState(const MouseEvent& e) { |
| 272 return IsTriggerableEvent(e); | 272 return IsTriggerableEvent(e); |
| 273 } | 273 } |
| 274 | 274 |
| 275 } // namespace views | 275 } // namespace views |
| OLD | NEW |