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

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

Issue 112553002: Implement new focusing steps for modal <dialog>. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: drop inert ancestors change Created 7 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 | « LayoutTests/fast/dom/HTMLDialogElement/show-modal-focusing-steps-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLDialogElement.cpp
diff --git a/Source/core/html/HTMLDialogElement.cpp b/Source/core/html/HTMLDialogElement.cpp
index 4113b3089ce79479a4e814c4931b770b4f84674e..59d5bc04a5e2789c70139cbf99358d29267ecef9 100644
--- a/Source/core/html/HTMLDialogElement.cpp
+++ b/Source/core/html/HTMLDialogElement.cpp
@@ -39,11 +39,21 @@ namespace WebCore {
using namespace HTMLNames;
-static void runAutofocus(HTMLDialogElement* dialog)
+// This function chooses the focused element when showModal() is invoked, as described in the spec for showModal().
+static void setFocusForModalDialog(HTMLDialogElement* dialog)
{
+ Element* focusableDescendant = 0;
Node* next = 0;
for (Node* node = dialog->firstChild(); node; node = next) {
- if (node->isElementNode() && toElement(node)->isFormControlElement()) {
+ if (node->hasTagName(dialogTag))
+ next = NodeTraversal::nextSkippingChildren(*node, dialog);
+ else
+ next = NodeTraversal::next(*node, dialog);
+
+ if (!node->isElementNode())
+ continue;
+ Element* element = toElement(node);
+ if (element->isFormControlElement()) {
HTMLFormControlElement* control = toHTMLFormControlElement(node);
if (control->isAutofocusable()) {
control->focus();
@@ -51,11 +61,21 @@ static void runAutofocus(HTMLDialogElement* dialog)
return;
}
}
- if (node->hasTagName(dialogTag))
- next = NodeTraversal::nextSkippingChildren(*node, dialog);
- else
- next = NodeTraversal::next(*node, dialog);
+ if (!focusableDescendant && element->isFocusable())
+ focusableDescendant = element;
}
+
+ if (focusableDescendant) {
+ focusableDescendant->focus();
+ return;
+ }
+
+ if (dialog->isFocusable()) {
+ dialog->focus();
+ return;
+ }
+
+ dialog->document().setFocusedElement(0);
}
static void inertSubtreesChanged(Document& document)
@@ -140,9 +160,12 @@ void HTMLDialogElement::showModal(ExceptionState& exceptionState)
document().addToTopLayer(this);
setBooleanAttribute(openAttr, true);
- runAutofocus(this);
- forceLayoutForCentering();
+ // Throw away the AX cache first, so the subsequent steps don't have a chance of queuing up
+ // AX events on objects that would be invalidated when the cache is thrown away.
inertSubtreesChanged(document());
+
+ forceLayoutForCentering();
+ setFocusForModalDialog(this);
}
void HTMLDialogElement::setCentered(LayoutUnit centeredPosition)
« no previous file with comments | « LayoutTests/fast/dom/HTMLDialogElement/show-modal-focusing-steps-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698