OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include "core/html/HTMLFormControlElement.h" | 35 #include "core/html/HTMLFormControlElement.h" |
36 #include "core/style/ComputedStyle.h" | 36 #include "core/style/ComputedStyle.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
40 using namespace HTMLNames; | 40 using namespace HTMLNames; |
41 | 41 |
42 // This function chooses the focused element when show() or showModal() is | 42 // This function chooses the focused element when show() or showModal() is |
43 // invoked, as described in their spec. | 43 // invoked, as described in their spec. |
44 static void setFocusForDialog(HTMLDialogElement* dialog) { | 44 static void setFocusForDialog(HTMLDialogElement* dialog) { |
45 Element* focusableDescendant = 0; | |
46 Node* next = 0; | 45 Node* next = 0; |
47 for (Node* node = dialog->firstChild(); node; node = next) { | 46 for (Node* node = dialog->firstChild(); node; node = next) { |
48 if (isHTMLDialogElement(*node)) | 47 next = isHTMLDialogElement(*node) |
49 next = NodeTraversal::nextSkippingChildren(*node, dialog); | 48 ? NodeTraversal::nextSkippingChildren(*node, dialog) |
esprehn
2016/12/01 00:39:58
I think this should probably cross shadow boundari
Dan Beam
2016/12/01 01:37:27
I agree but we talked over chat and you were OK wi
| |
50 else | 49 : NodeTraversal::next(*node, dialog); |
51 next = NodeTraversal::next(*node, dialog); | |
52 | 50 |
53 if (!node->isElementNode()) | 51 if (!node->isElementNode()) |
54 continue; | 52 continue; |
53 | |
55 Element* element = toElement(node); | 54 Element* element = toElement(node); |
56 if (element->isFormControlElement()) { | 55 if (!element->isFormControlElement()) |
57 HTMLFormControlElement* control = toHTMLFormControlElement(node); | 56 continue; |
58 if (control->isAutofocusable() && control->isFocusable()) { | 57 |
59 control->focus(); | 58 HTMLFormControlElement* control = toHTMLFormControlElement(node); |
60 return; | 59 if (control->isAutofocusable() && control->isFocusable()) { |
61 } | 60 control->focus(); |
61 return; | |
62 } | 62 } |
63 if (!focusableDescendant && element->isFocusable()) | |
64 focusableDescendant = element; | |
65 } | 63 } |
66 | 64 |
67 if (focusableDescendant) { | 65 dialog->focus(); |
68 focusableDescendant->focus(); | |
69 return; | |
70 } | |
71 | |
72 if (dialog->isFocusable()) { | |
73 dialog->focus(); | |
74 return; | |
75 } | |
76 | |
77 dialog->document().clearFocusedElement(); | |
78 } | 66 } |
79 | 67 |
80 static void inertSubtreesChanged(Document& document) { | 68 static void inertSubtreesChanged(Document& document) { |
81 // When a modal dialog opens or closes, nodes all over the accessibility | 69 // When a modal dialog opens or closes, nodes all over the accessibility |
82 // tree can change inertness which means they must be added or removed from | 70 // tree can change inertness which means they must be added or removed from |
83 // the tree. The most foolproof way is to clear the entire tree and rebuild | 71 // the tree. The most foolproof way is to clear the entire tree and rebuild |
84 // it, though a more clever way is probably possible. | 72 // it, though a more clever way is probably possible. |
85 document.clearAXObjectCache(); | 73 document.clearAXObjectCache(); |
86 if (AXObjectCache* cache = document.axObjectCache()) | 74 if (AXObjectCache* cache = document.axObjectCache()) |
87 cache->childrenChanged(&document); | 75 cache->childrenChanged(&document); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 | 193 |
206 void HTMLDialogElement::defaultEventHandler(Event* event) { | 194 void HTMLDialogElement::defaultEventHandler(Event* event) { |
207 if (event->type() == EventTypeNames::cancel) { | 195 if (event->type() == EventTypeNames::cancel) { |
208 closeDialog(); | 196 closeDialog(); |
209 event->setDefaultHandled(); | 197 event->setDefaultHandled(); |
210 return; | 198 return; |
211 } | 199 } |
212 HTMLElement::defaultEventHandler(event); | 200 HTMLElement::defaultEventHandler(event); |
213 } | 201 } |
214 | 202 |
203 bool HTMLDialogElement::supportsFocus() const { | |
204 return true; | |
205 } | |
206 | |
207 int HTMLDialogElement::tabIndex() const { | |
208 return hasTabIndex() ? getIntegralAttribute(tabindexAttr) : -1; | |
209 } | |
210 | |
215 } // namespace blink | 211 } // namespace blink |
OLD | NEW |