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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 // (and so moves to the right). Seems strange, but we'll match it. However, | 86 // (and so moves to the right). Seems strange, but we'll match it. However, |
87 // when using Spatial Navigation, we need to be able to navigate without | 87 // when using Spatial Navigation, we need to be able to navigate without |
88 // changing the selection. | 88 // changing the selection. |
89 Document& document = element().document(); | 89 Document& document = element().document(); |
90 if (isSpatialNavigationEnabled(document.frame())) | 90 if (isSpatialNavigationEnabled(document.frame())) |
91 return; | 91 return; |
92 bool forward = (key == "Down" || key == "Right"); | 92 bool forward = (key == "Down" || key == "Right"); |
93 | 93 |
94 // We can only stay within the form's children if the form hasn't been demot ed to a leaf because | 94 // We can only stay within the form's children if the form hasn't been demot ed to a leaf because |
95 // of malformed HTML. | 95 // of malformed HTML. |
96 for (HTMLElement* htmlElement = nextElement(element(), forward); htmlElement ; htmlElement = nextElement(*htmlElement, forward)) { | 96 HTMLElement* htmlElement; |
97 // Once we encounter a form element, we know we're through. | 97 bool reachedAtEnd = false; |
keishi
2014/09/24 04:32:27
nit: I think reachedEnd is better.
| |
98 if (isHTMLFormElement(*htmlElement)) | 98 for (htmlElement = nextElement(element(), forward); ; htmlElement = nextElem ent(*htmlElement, forward)) { |
99 // Once we encounter no element OR an input element of other form | |
100 // OR form element in backward traversal, we know we're through. | |
101 if (!htmlElement) { | |
102 reachedAtEnd = true; | |
99 break; | 103 break; |
104 } | |
105 if ((isHTMLInputElement(*htmlElement) && toHTMLInputElement(htmlElement) ->form() != element().form())) { | |
keishi
2014/09/24 04:32:28
Why do we end the search? I think we should just i
| |
106 reachedAtEnd = true; | |
107 break; | |
108 } | |
109 if (isHTMLFormElement(*htmlElement)) { | |
keishi
2014/09/24 04:32:27
I know this was here from before but this seems wr
| |
110 reachedAtEnd = true; | |
111 break; | |
112 } | |
100 // Look for more radio buttons. | 113 // Look for more radio buttons. |
101 if (!isHTMLInputElement(*htmlElement)) | 114 if (!isHTMLInputElement(*htmlElement)) |
102 continue; | 115 continue; |
103 HTMLInputElement* inputElement = toHTMLInputElement(htmlElement); | 116 HTMLInputElement* inputElement = toHTMLInputElement(htmlElement); |
104 if (inputElement->form() != element().form()) | 117 if (inputElement->form() != element().form()) |
105 break; | 118 break; |
106 if (inputElement->isRadioButton() && inputElement->name() == element().n ame() && inputElement->isFocusable()) { | 119 if (inputElement->isRadioButton() && inputElement->name() == element().n ame() && inputElement->isFocusable()) { |
107 RefPtrWillBeRawPtr<HTMLInputElement> protector(inputElement); | 120 break; |
108 document.setFocusedElement(inputElement); | |
109 inputElement->dispatchSimulatedClick(event, SendNoEvents); | |
110 event->setDefaultHandled(); | |
111 return; | |
112 } | 121 } |
113 } | 122 } |
123 if (reachedAtEnd) { | |
124 // Traverse in reverse direction till last or first radio button | |
125 forward = !(forward); | |
126 htmlElement = &element(); | |
127 HTMLElement* nextHtmlElement = nextElement(*htmlElement, forward); | |
128 HTMLInputElement* inputElement; | |
129 while (nextHtmlElement && !isHTMLFormElement(*nextHtmlElement)) { | |
130 if (isHTMLInputElement(*nextHtmlElement)) { | |
131 inputElement = toHTMLInputElement(nextHtmlElement); | |
132 if (inputElement->form() == element().form() && inputElement->is RadioButton() && inputElement->name() == element().name() && inputElement->isFoc usable()) | |
keishi
2014/09/24 04:32:27
This code is mostly same from the for loop above.
| |
133 htmlElement = nextHtmlElement; | |
134 } | |
135 nextHtmlElement = nextElement(*nextHtmlElement, forward); | |
136 } | |
137 } | |
138 HTMLInputElement* inputElement = toHTMLInputElement(htmlElement); | |
139 if (inputElement->isRadioButton() && inputElement->name() == element().name( ) && inputElement->isFocusable()) { | |
keishi
2014/09/24 04:32:28
Isn't this checking the same thing twice? We alrea
| |
140 RefPtrWillBeRawPtr<HTMLInputElement> protector(inputElement); | |
141 document.setFocusedElement(inputElement); | |
142 inputElement->dispatchSimulatedClick(event, SendNoEvents); | |
143 event->setDefaultHandled(); | |
144 return; | |
145 } | |
114 } | 146 } |
115 | 147 |
116 void RadioInputType::handleKeyupEvent(KeyboardEvent* event) | 148 void RadioInputType::handleKeyupEvent(KeyboardEvent* event) |
117 { | 149 { |
118 const String& key = event->keyIdentifier(); | 150 const String& key = event->keyIdentifier(); |
119 if (key != "U+0020") | 151 if (key != "U+0020") |
120 return; | 152 return; |
121 // If an unselected radio is tabbed into (because the entire group has nothi ng | 153 // If an unselected radio is tabbed into (because the entire group has nothi ng |
122 // checked, or because of some explicit .focus() call), then allow space to check it. | 154 // checked, or because of some explicit .focus() call), then allow space to check it. |
123 if (element().checked()) | 155 if (element().checked()) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 { | 226 { |
195 return true; | 227 return true; |
196 } | 228 } |
197 | 229 |
198 bool RadioInputType::supportsIndeterminateAppearance() const | 230 bool RadioInputType::supportsIndeterminateAppearance() const |
199 { | 231 { |
200 return false; | 232 return false; |
201 } | 233 } |
202 | 234 |
203 } // namespace blink | 235 } // namespace blink |
OLD | NEW |