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

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: After Adding New Method HTMLElement* findNextFocusableRadioButton() 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..e86d16d41a4433ceac9be33a2cfc8fde61280ba0 100644
--- a/Source/core/html/forms/RadioInputType.cpp
+++ b/Source/core/html/forms/RadioInputType.cpp
@@ -71,6 +71,29 @@ void RadioInputType::handleClickEvent(MouseEvent* event)
event->setDefaultHandled();
}
+HTMLElement* RadioInputType::findNextFocusableRadioButton(HTMLInputElement* currentHtmlInputElement, bool forward)
keishi 2014/09/26 04:25:35 I'm sorry. I know I wrote HTMLElement* in my previ
+{
+ HTMLElement* htmlElement;
+ for (htmlElement = nextElement(*currentHtmlInputElement, forward); htmlElement; htmlElement = nextElement(*htmlElement, forward)) {
+ // Once we encounter a form element, we know we're through.
+ if (isHTMLFormElement(*htmlElement)) {
keishi 2014/09/26 04:25:35 No curly braces for single line if statements.
keishi 2014/09/26 04:25:35 As I said in my previous comment, this isn't right
+ return nullptr;
+ }
+ // Look for more radio buttons.
+ if (!isHTMLInputElement(*htmlElement)) {
keishi 2014/09/26 04:25:35 Ditto.
+ continue;
+ }
+ HTMLInputElement* inputElement = toHTMLInputElement(htmlElement);
+ if (inputElement->form() != currentHtmlInputElement->form()) {
keishi 2014/09/26 04:25:35 We should be checking if form equals element().for
keishi 2014/09/26 04:25:35 Ditto.
+ return nullptr;
+ }
+ if (inputElement->isRadioButton() && inputElement->name() == currentHtmlInputElement->name() && inputElement->isFocusable()) {
keishi 2014/09/26 04:25:35 Ditto.
+ return htmlElement;
+ }
+ }
+ return nullptr;
+}
+
void RadioInputType::handleKeydownEvent(KeyboardEvent* event)
{
BaseCheckableInputType::handleKeydownEvent(event);
@@ -93,24 +116,24 @@ 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))
- break;
- // Look for more radio buttons.
- if (!isHTMLInputElement(*htmlElement))
- continue;
- HTMLInputElement* inputElement = toHTMLInputElement(htmlElement);
- 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;
+ HTMLElement* htmlElement = findNextFocusableRadioButton(toHTMLInputElement(&element()), forward);
+ if (!htmlElement) {
+ // Traverse in reverse direction till last or first radio button
+ forward = !(forward);
+ HTMLElement* nextHtmlElement = findNextFocusableRadioButton(toHTMLInputElement(&element()), forward);
+ while (nextHtmlElement) {
+ htmlElement = nextHtmlElement;
+ nextHtmlElement = findNextFocusableRadioButton(toHTMLInputElement(nextHtmlElement), forward);
}
}
+ if (htmlElement) {
+ HTMLInputElement* inputElement = toHTMLInputElement(htmlElement);
+ 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