| 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 "chrome/views/base_button.h" | 5 #include "chrome/views/base_button.h" |
| 6 | 6 |
| 7 #include "base/base_drag_source.h" | 7 #include "base/base_drag_source.h" |
| 8 #include "chrome/browser/drag_utils.h" | 8 #include "chrome/browser/drag_utils.h" |
| 9 #include "chrome/common/drag_drop_types.h" | 9 #include "chrome/common/drag_drop_types.h" |
| 10 #include "chrome/common/gfx/chrome_canvas.h" | 10 #include "chrome/common/gfx/chrome_canvas.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 void BaseButton::NotifyClick(int mouse_event_flags) { | 210 void BaseButton::NotifyClick(int mouse_event_flags) { |
| 211 mouse_event_flags_ = mouse_event_flags; | 211 mouse_event_flags_ = mouse_event_flags; |
| 212 if (listener_ != NULL) | 212 if (listener_ != NULL) |
| 213 listener_->ButtonPressed(this); | 213 listener_->ButtonPressed(this); |
| 214 // NOTE: don't attempt to reset mouse_event_flags_ as the listener may have | 214 // NOTE: don't attempt to reset mouse_event_flags_ as the listener may have |
| 215 // deleted us. | 215 // deleted us. |
| 216 } | 216 } |
| 217 | 217 |
| 218 bool BaseButton::OnKeyPressed(const KeyEvent& e) { | 218 bool BaseButton::OnKeyPressed(const KeyEvent& e) { |
| 219 if (state_ != BS_DISABLED) { | 219 if (state_ != BS_DISABLED) { |
| 220 if ((e.GetCharacter() == VK_SPACE) || (e.GetCharacter() == VK_RETURN)) { | 220 // Space sets button state to pushed. Enter clicks the button. This matches |
| 221 // the Windows native behavior of buttons, where Space clicks the button |
| 222 // on KeyRelease and Enter clicks the button on KeyPressed. |
| 223 if (e.GetCharacter() == VK_SPACE) { |
| 221 SetState(BS_PUSHED); | 224 SetState(BS_PUSHED); |
| 222 return true; | 225 return true; |
| 226 } else if (e.GetCharacter() == VK_RETURN) { |
| 227 SetState(BS_NORMAL); |
| 228 NotifyClick(0); |
| 229 return true; |
| 223 } | 230 } |
| 224 } | 231 } |
| 225 return false; | 232 return false; |
| 226 } | 233 } |
| 227 | 234 |
| 228 bool BaseButton::OnKeyReleased(const KeyEvent& e) { | 235 bool BaseButton::OnKeyReleased(const KeyEvent& e) { |
| 229 if (state_ != BS_DISABLED) { | 236 if (state_ != BS_DISABLED) { |
| 230 if ((e.GetCharacter() == VK_SPACE) || (e.GetCharacter() == VK_RETURN)) { | 237 if (e.GetCharacter() == VK_SPACE) { |
| 231 SetState(BS_NORMAL); | 238 SetState(BS_NORMAL); |
| 232 NotifyClick(0); | 239 NotifyClick(0); |
| 233 return true; | 240 return true; |
| 234 } | 241 } |
| 235 } | 242 } |
| 236 return false; | 243 return false; |
| 237 } | 244 } |
| 238 | 245 |
| 239 void BaseButton::ShowContextMenu(int x, int y, bool is_mouse_gesture) { | 246 void BaseButton::ShowContextMenu(int x, int y, bool is_mouse_gesture) { |
| 240 if (GetContextMenuController()) { | 247 if (GetContextMenuController()) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 void BaseButton::Paint(ChromeCanvas* canvas) { | 309 void BaseButton::Paint(ChromeCanvas* canvas) { |
| 303 View::Paint(canvas); | 310 View::Paint(canvas); |
| 304 } | 311 } |
| 305 | 312 |
| 306 void BaseButton::Paint(ChromeCanvas* canvas, bool for_drag) { | 313 void BaseButton::Paint(ChromeCanvas* canvas, bool for_drag) { |
| 307 Paint(canvas); | 314 Paint(canvas); |
| 308 } | 315 } |
| 309 | 316 |
| 310 } // namespace views | 317 } // namespace views |
| 311 | 318 |
| OLD | NEW |