Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(906)

Unified Diff: Source/core/html/forms/RadioInputType.cpp

Issue 546753002: Fix to Handle downkey event on last and first radio button of a radio button list (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/forms/RadioInputType.cpp
diff --git a/Source/core/html/forms/RadioInputType.cpp b/Source/core/html/forms/RadioInputType.cpp
index 4e992f650156e2874b2a8c1e9af574347c232a5a..3cfe703954a62957d096f998c3f10a9dfede02a0 100644
--- a/Source/core/html/forms/RadioInputType.cpp
+++ b/Source/core/html/forms/RadioInputType.cpp
@@ -93,10 +93,23 @@ void RadioInputType::handleKeydownEvent(KeyboardEvent* event)
// We can only stay within the form's children if the form hasn't been demoted to a leaf because
// of malformed HTML.
- for (HTMLElement* htmlElement = nextElement(element(), forward); htmlElement; htmlElement = nextElement(*htmlElement, forward)) {
- // Once we encounter a form element, we know we're through.
- if (isHTMLFormElement(*htmlElement))
+ HTMLElement* htmlElement;
+ bool reachedAtEnd = false;
keishi 2014/09/24 04:32:27 nit: I think reachedEnd is better.
+ for (htmlElement = nextElement(element(), forward); ; htmlElement = nextElement(*htmlElement, forward)) {
+ // Once we encounter no element OR an input element of other form
+ // OR form element in backward traversal, we know we're through.
+ if (!htmlElement) {
+ reachedAtEnd = true;
break;
+ }
+ 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
+ reachedAtEnd = true;
+ break;
+ }
+ if (isHTMLFormElement(*htmlElement)) {
keishi 2014/09/24 04:32:27 I know this was here from before but this seems wr
+ reachedAtEnd = true;
+ break;
+ }
// Look for more radio buttons.
if (!isHTMLInputElement(*htmlElement))
continue;
@@ -104,13 +117,32 @@ void RadioInputType::handleKeydownEvent(KeyboardEvent* event)
if (inputElement->form() != element().form())
break;
if (inputElement->isRadioButton() && inputElement->name() == element().name() && inputElement->isFocusable()) {
- RefPtrWillBeRawPtr<HTMLInputElement> protector(inputElement);
- document.setFocusedElement(inputElement);
- inputElement->dispatchSimulatedClick(event, SendNoEvents);
- event->setDefaultHandled();
- return;
+ break;
+ }
+ }
+ if (reachedAtEnd) {
+ // Traverse in reverse direction till last or first radio button
+ forward = !(forward);
+ htmlElement = &element();
+ HTMLElement* nextHtmlElement = nextElement(*htmlElement, forward);
+ HTMLInputElement* inputElement;
+ while (nextHtmlElement && !isHTMLFormElement(*nextHtmlElement)) {
+ if (isHTMLInputElement(*nextHtmlElement)) {
+ inputElement = toHTMLInputElement(nextHtmlElement);
+ if (inputElement->form() == element().form() && inputElement->isRadioButton() && inputElement->name() == element().name() && inputElement->isFocusable())
keishi 2014/09/24 04:32:27 This code is mostly same from the for loop above.
+ htmlElement = nextHtmlElement;
+ }
+ nextHtmlElement = nextElement(*nextHtmlElement, forward);
}
}
+ HTMLInputElement* inputElement = toHTMLInputElement(htmlElement);
+ 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
+ RefPtrWillBeRawPtr<HTMLInputElement> protector(inputElement);
+ document.setFocusedElement(inputElement);
+ inputElement->dispatchSimulatedClick(event, SendNoEvents);
+ event->setDefaultHandled();
+ return;
+ }
}
void RadioInputType::handleKeyupEvent(KeyboardEvent* event)

Powered by Google App Engine
This is Rietveld 408576698