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

Unified Diff: third_party/WebKit/Source/core/html/HTMLDialogElement.cpp

Issue 2532983004: Re-work <dialog>#show*() focus algorithm (Closed)
Patch Set: starting to mess with tests Created 4 years 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
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLDialogElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLDialogElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698