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..1c67787b30c1a9856b3d8b79c54610903febb0ef 100644 |
--- a/Source/core/html/forms/RadioInputType.cpp |
+++ b/Source/core/html/forms/RadioInputType.cpp |
@@ -37,11 +37,10 @@ namespace blink { |
namespace { |
-HTMLElement* nextElement(const HTMLElement& element, bool forward) |
+HTMLElement* nextElement(const HTMLElement& element, HTMLFormElement* stayWithin, bool forward) |
{ |
- return forward ? Traversal<HTMLElement>::next(element) : Traversal<HTMLElement>::previous(element); |
+ return forward ? Traversal<HTMLElement>::next(element, (Node* )stayWithin) : Traversal<HTMLElement>::previous(element, (Node* )stayWithin); |
} |
- |
} // namespace |
using namespace HTMLNames; |
@@ -71,6 +70,20 @@ void RadioInputType::handleClickEvent(MouseEvent* event) |
event->setDefaultHandled(); |
} |
+HTMLInputElement* RadioInputType::findNextFocusableRadioButton(HTMLInputElement* currentHtmlInputElement, bool forward) |
keishi
2014/10/06 10:52:32
nit: currentHtmlInputElement is a pretty long vari
|
+{ |
+ HTMLElement* htmlElement; |
+ for (htmlElement = nextElement(*currentHtmlInputElement, element().form(), forward); htmlElement; htmlElement = nextElement(*htmlElement, element().form(), forward)) { |
+ // Look for more radio buttons. |
+ if (!isHTMLInputElement(*htmlElement)) |
+ continue; |
+ HTMLInputElement* inputElement = toHTMLInputElement(htmlElement); |
+ if (currentHtmlInputElement->form() == inputElement->form() && inputElement->isRadioButton() && inputElement->name() == currentHtmlInputElement->name() && inputElement->isFocusable()) |
Paritosh Kumar
2014/10/06 08:32:24
Unable to call element() method of InputTypeView w
keishi
2014/10/06 10:52:32
I don't understand this, element() is being called
Paritosh Kumar
2014/10/06 12:51:29
Apologize. Yes it's working. Done. Thanks.
|
+ return inputElement; |
+ } |
+ return nullptr; |
+} |
+ |
void RadioInputType::handleKeydownEvent(KeyboardEvent* event) |
{ |
BaseCheckableInputType::handleKeydownEvent(event); |
@@ -93,24 +106,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)) |
- 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; |
+ HTMLInputElement* inputElement = findNextFocusableRadioButton(toHTMLInputElement(&element()), forward); |
+ if (!inputElement) { |
+ // Traverse in reverse direction till last or first radio button |
+ forward = !(forward); |
+ HTMLInputElement* nextInputElement = findNextFocusableRadioButton(toHTMLInputElement(&element()), forward); |
+ while (nextInputElement) { |
+ inputElement = nextInputElement; |
+ nextInputElement = findNextFocusableRadioButton(nextInputElement, forward); |
} |
} |
+ if (inputElement) { |
+ RefPtrWillBeRawPtr<HTMLInputElement> protector(inputElement); |
+ document.setFocusedElement(inputElement); |
+ inputElement->dispatchSimulatedClick(event, SendNoEvents); |
+ event->setDefaultHandled(); |
+ return; |
+ } |
} |
void RadioInputType::handleKeyupEvent(KeyboardEvent* event) |