Index: third_party/WebKit/Source/core/html/HTMLDialogElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLDialogElement.cpp b/third_party/WebKit/Source/core/html/HTMLDialogElement.cpp |
index 9edc5883e4ea38e02f6a61618fe0434fdac93113..118d713e9420f0c19b72dc86e517a1caebda40af 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLDialogElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLDialogElement.cpp |
@@ -42,39 +42,27 @@ using namespace HTMLNames; |
// This function chooses the focused element when show() or showModal() is |
// invoked, as described in their spec. |
static void setFocusForDialog(HTMLDialogElement* dialog) { |
- Element* focusableDescendant = 0; |
Node* next = 0; |
for (Node* node = dialog->firstChild(); node; node = next) { |
- if (isHTMLDialogElement(*node)) |
- next = NodeTraversal::nextSkippingChildren(*node, dialog); |
- else |
- next = NodeTraversal::next(*node, dialog); |
+ next = isHTMLDialogElement(*node) |
+ ? NodeTraversal::nextSkippingChildren(*node, dialog) |
+ : NodeTraversal::next(*node, dialog); |
if (!node->isElementNode()) |
continue; |
- Element* element = toElement(node); |
- if (element->isFormControlElement()) { |
- HTMLFormControlElement* control = toHTMLFormControlElement(node); |
- if (control->isAutofocusable() && control->isFocusable()) { |
- control->focus(); |
- return; |
- } |
- } |
- if (!focusableDescendant && element->isFocusable()) |
- focusableDescendant = element; |
- } |
- if (focusableDescendant) { |
- focusableDescendant->focus(); |
- return; |
- } |
+ Element* element = toElement(node); |
+ if (!element->isFormControlElement()) |
+ continue; |
- if (dialog->isFocusable()) { |
- dialog->focus(); |
- return; |
+ HTMLFormControlElement* control = toHTMLFormControlElement(node); |
+ if (control->isAutofocusable() && control->isFocusable()) { |
+ control->focus(); |
+ return; |
+ } |
} |
- dialog->document().clearFocusedElement(); |
+ dialog->focus(); |
} |
static void inertSubtreesChanged(Document& document) { |
@@ -212,4 +200,12 @@ void HTMLDialogElement::defaultEventHandler(Event* event) { |
HTMLElement::defaultEventHandler(event); |
} |
+bool HTMLDialogElement::supportsFocus() const { |
+ return true; |
+} |
+ |
+int HTMLDialogElement::tabIndex() const { |
+ return hasTabIndex() ? getIntegralAttribute(tabindexAttr) : -1; |
+} |
+ |
} // namespace blink |