OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 81 } |
82 | 82 |
83 void RadioInputType::handleKeydownEvent(KeyboardEvent* event) | 83 void RadioInputType::handleKeydownEvent(KeyboardEvent* event) |
84 { | 84 { |
85 // TODO(tkent): We should return more earlier. | 85 // TODO(tkent): We should return more earlier. |
86 if (!element().layoutObject()) | 86 if (!element().layoutObject()) |
87 return; | 87 return; |
88 BaseCheckableInputType::handleKeydownEvent(event); | 88 BaseCheckableInputType::handleKeydownEvent(event); |
89 if (event->defaultHandled()) | 89 if (event->defaultHandled()) |
90 return; | 90 return; |
91 const String& key = event->keyIdentifier(); | 91 const String& key = event->key(); |
92 if (key != "Up" && key != "Down" && key != "Left" && key != "Right") | 92 if (key != "ArrowUp" && key != "ArrowDown" && key != "ArrowLeft" && key != "
ArrowRight") |
93 return; | 93 return; |
94 | 94 |
95 if (event->ctrlKey() || event->metaKey() || event->altKey()) | 95 if (event->ctrlKey() || event->metaKey() || event->altKey()) |
96 return; | 96 return; |
97 | 97 |
98 // Left and up mean "previous radio button". | 98 // Left and up mean "previous radio button". |
99 // Right and down mean "next radio button". | 99 // Right and down mean "next radio button". |
100 // Tested in WinIE, and even for RTL, left still means previous radio button | 100 // Tested in WinIE, and even for RTL, left still means previous radio button |
101 // (and so moves to the right). Seems strange, but we'll match it. However, | 101 // (and so moves to the right). Seems strange, but we'll match it. However, |
102 // when using Spatial Navigation, we need to be able to navigate without | 102 // when using Spatial Navigation, we need to be able to navigate without |
103 // changing the selection. | 103 // changing the selection. |
104 Document& document = element().document(); | 104 Document& document = element().document(); |
105 if (isSpatialNavigationEnabled(document.frame())) | 105 if (isSpatialNavigationEnabled(document.frame())) |
106 return; | 106 return; |
107 bool forward = computedTextDirection() == RTL ? (key == "Down" || key == "Le
ft") : (key == "Down" || key == "Right"); | 107 bool forward = computedTextDirection() == RTL ? (key == "ArrowDown" || key =
= "ArrowLeft") : (key == "ArrowDown" || key == "ArrowRight"); |
108 | 108 |
109 // We can only stay within the form's children if the form hasn't been demot
ed to a leaf because | 109 // We can only stay within the form's children if the form hasn't been demot
ed to a leaf because |
110 // of malformed HTML. | 110 // of malformed HTML. |
111 HTMLInputElement* inputElement = findNextFocusableRadioButtonInGroup(toHTMLI
nputElement(&element()), forward); | 111 HTMLInputElement* inputElement = findNextFocusableRadioButtonInGroup(toHTMLI
nputElement(&element()), forward); |
112 if (!inputElement) { | 112 if (!inputElement) { |
113 // Traverse in reverse direction till last or first radio button | 113 // Traverse in reverse direction till last or first radio button |
114 forward = !(forward); | 114 forward = !(forward); |
115 HTMLInputElement* nextInputElement = findNextFocusableRadioButtonInGroup
(toHTMLInputElement(&element()), forward); | 115 HTMLInputElement* nextInputElement = findNextFocusableRadioButtonInGroup
(toHTMLInputElement(&element()), forward); |
116 while (nextInputElement) { | 116 while (nextInputElement) { |
117 inputElement = nextInputElement; | 117 inputElement = nextInputElement; |
118 nextInputElement = findNextFocusableRadioButtonInGroup(nextInputElem
ent, forward); | 118 nextInputElement = findNextFocusableRadioButtonInGroup(nextInputElem
ent, forward); |
119 } | 119 } |
120 } | 120 } |
121 if (inputElement) { | 121 if (inputElement) { |
122 document.setFocusedElement(inputElement, FocusParams(SelectionBehaviorOn
Focus::None, WebFocusTypeNone, nullptr)); | 122 document.setFocusedElement(inputElement, FocusParams(SelectionBehaviorOn
Focus::None, WebFocusTypeNone, nullptr)); |
123 inputElement->dispatchSimulatedClick(event, SendNoEvents); | 123 inputElement->dispatchSimulatedClick(event, SendNoEvents); |
124 event->setDefaultHandled(); | 124 event->setDefaultHandled(); |
125 return; | 125 return; |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 void RadioInputType::handleKeyupEvent(KeyboardEvent* event) | 129 void RadioInputType::handleKeyupEvent(KeyboardEvent* event) |
130 { | 130 { |
131 const String& key = event->keyIdentifier(); | 131 const String& key = event->key(); |
132 if (key != "U+0020") | 132 if (key != " ") |
133 return; | 133 return; |
134 // If an unselected radio is tabbed into (because the entire group has nothi
ng | 134 // If an unselected radio is tabbed into (because the entire group has nothi
ng |
135 // checked, or because of some explicit .focus() call), then allow space to
check it. | 135 // checked, or because of some explicit .focus() call), then allow space to
check it. |
136 if (element().checked()) | 136 if (element().checked()) |
137 return; | 137 return; |
138 dispatchSimulatedClickIfActive(event); | 138 dispatchSimulatedClickIfActive(event); |
139 } | 139 } |
140 | 140 |
141 bool RadioInputType::isKeyboardFocusable() const | 141 bool RadioInputType::isKeyboardFocusable() const |
142 { | 142 { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // TODO(tkent): Comparing name() with == is incorrect. It should be | 217 // TODO(tkent): Comparing name() with == is incorrect. It should be |
218 // case-insensitive. | 218 // case-insensitive. |
219 for (HTMLInputElement* inputElement = nextInputElement(*current, current->fo
rm(), forward); inputElement; inputElement = nextInputElement(*inputElement, cur
rent->form(), forward)) { | 219 for (HTMLInputElement* inputElement = nextInputElement(*current, current->fo
rm(), forward); inputElement; inputElement = nextInputElement(*inputElement, cur
rent->form(), forward)) { |
220 if (current->form() == inputElement->form() && inputElement->type() == I
nputTypeNames::radio && inputElement->name() == current->name()) | 220 if (current->form() == inputElement->form() && inputElement->type() == I
nputTypeNames::radio && inputElement->name() == current->name()) |
221 return inputElement; | 221 return inputElement; |
222 } | 222 } |
223 return nullptr; | 223 return nullptr; |
224 } | 224 } |
225 | 225 |
226 } // namespace blink | 226 } // namespace blink |
OLD | NEW |