OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 2012 Google Inc. All rights reserved. |
3 * Copyright (C) 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "config.h" | 32 #include "config.h" |
33 #include "core/html/forms/BaseClickableWithKeyInputType.h" | 33 #include "core/html/forms/BaseClickableWithKeyInputType.h" |
34 | 34 |
35 #include "core/events/KeyboardEvent.h" | 35 #include "core/events/KeyboardEvent.h" |
36 #include "core/html/HTMLInputElement.h" | 36 #include "core/html/HTMLInputElement.h" |
37 | 37 |
38 namespace WebCore { | 38 namespace WebCore { |
39 | 39 |
40 using namespace HTMLNames; | 40 using namespace HTMLNames; |
41 | 41 |
42 void BaseClickableWithKeyInputType::handleKeydownEvent(HTMLInputElement* element
, KeyboardEvent* event) | 42 void BaseClickableWithKeyInputType::handleKeydownEvent(HTMLInputElement& element
, KeyboardEvent* event) |
43 { | 43 { |
44 const String& key = event->keyIdentifier(); | 44 const String& key = event->keyIdentifier(); |
45 if (key == "U+0020") { | 45 if (key == "U+0020") { |
46 element->setActive(true, true); | 46 element.setActive(true, true); |
47 // No setDefaultHandled(), because IE dispatches a keypress in this case | 47 // No setDefaultHandled(), because IE dispatches a keypress in this case |
48 // and the caller will only dispatch a keypress if we don't call setDefa
ultHandled(). | 48 // and the caller will only dispatch a keypress if we don't call setDefa
ultHandled(). |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 void BaseClickableWithKeyInputType::handleKeypressEvent(HTMLInputElement* elemen
t, KeyboardEvent* event) | 52 void BaseClickableWithKeyInputType::handleKeypressEvent(HTMLInputElement& elemen
t, KeyboardEvent* event) |
53 { | 53 { |
54 int charCode = event->charCode(); | 54 int charCode = event->charCode(); |
55 if (charCode == '\r') { | 55 if (charCode == '\r') { |
56 element->dispatchSimulatedClick(event); | 56 element.dispatchSimulatedClick(event); |
57 event->setDefaultHandled(); | 57 event->setDefaultHandled(); |
58 return; | 58 return; |
59 } | 59 } |
60 if (charCode == ' ') { | 60 if (charCode == ' ') { |
61 // Prevent scrolling down the page. | 61 // Prevent scrolling down the page. |
62 event->setDefaultHandled(); | 62 event->setDefaultHandled(); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void BaseClickableWithKeyInputType::handleKeyupEvent(InputType& inputType, Keybo
ardEvent* event) | 66 void BaseClickableWithKeyInputType::handleKeyupEvent(InputType& inputType, Keybo
ardEvent* event) |
67 { | 67 { |
68 const String& key = event->keyIdentifier(); | 68 const String& key = event->keyIdentifier(); |
69 if (key != "U+0020") | 69 if (key != "U+0020") |
70 return; | 70 return; |
71 // Simulate mouse click for spacebar for button types. | 71 // Simulate mouse click for spacebar for button types. |
72 inputType.dispatchSimulatedClickIfActive(event); | 72 inputType.dispatchSimulatedClickIfActive(event); |
73 } | 73 } |
74 | 74 |
75 // FIXME: Could share this with BaseCheckableInputType and RangeInputType if we
had a common base class. | 75 // FIXME: Could share this with BaseCheckableInputType and RangeInputType if we
had a common base class. |
76 void BaseClickableWithKeyInputType::accessKeyAction(HTMLInputElement* element, b
ool sendMouseEvents) | 76 void BaseClickableWithKeyInputType::accessKeyAction(HTMLInputElement& element, b
ool sendMouseEvents) |
77 { | 77 { |
78 element->dispatchSimulatedClick(0, sendMouseEvents ? SendMouseUpDownEvents :
SendNoEvents); | 78 element.dispatchSimulatedClick(0, sendMouseEvents ? SendMouseUpDownEvents :
SendNoEvents); |
79 } | 79 } |
80 | 80 |
81 void BaseClickableWithKeyInputType::handleKeydownEvent(KeyboardEvent* event) | 81 void BaseClickableWithKeyInputType::handleKeydownEvent(KeyboardEvent* event) |
82 { | 82 { |
83 handleKeydownEvent(element(), event); | 83 handleKeydownEvent(element(), event); |
84 } | 84 } |
85 | 85 |
86 void BaseClickableWithKeyInputType::handleKeypressEvent(KeyboardEvent* event) | 86 void BaseClickableWithKeyInputType::handleKeypressEvent(KeyboardEvent* event) |
87 { | 87 { |
88 handleKeypressEvent(element(), event); | 88 handleKeypressEvent(element(), event); |
89 } | 89 } |
90 | 90 |
91 void BaseClickableWithKeyInputType::handleKeyupEvent(KeyboardEvent* event) | 91 void BaseClickableWithKeyInputType::handleKeyupEvent(KeyboardEvent* event) |
92 { | 92 { |
93 handleKeyupEvent(*this, event); | 93 handleKeyupEvent(*this, event); |
94 } | 94 } |
95 | 95 |
96 void BaseClickableWithKeyInputType::accessKeyAction(bool sendMouseEvents) | 96 void BaseClickableWithKeyInputType::accessKeyAction(bool sendMouseEvents) |
97 { | 97 { |
98 InputType::accessKeyAction(sendMouseEvents); | 98 InputType::accessKeyAction(sendMouseEvents); |
99 accessKeyAction(element(), sendMouseEvents); | 99 accessKeyAction(element(), sendMouseEvents); |
100 } | 100 } |
101 | 101 |
102 } // namespace WebCore | 102 } // namespace WebCore |
OLD | NEW |