| 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 21 matching lines...) Expand all Loading... |
| 32 #include "core/dom/NodeTraversal.h" | 32 #include "core/dom/NodeTraversal.h" |
| 33 #include "core/html/HTMLFormControlElement.h" | 33 #include "core/html/HTMLFormControlElement.h" |
| 34 #include "core/frame/FrameView.h" | 34 #include "core/frame/FrameView.h" |
| 35 #include "core/rendering/RenderBlock.h" | 35 #include "core/rendering/RenderBlock.h" |
| 36 #include "core/rendering/style/RenderStyle.h" | 36 #include "core/rendering/style/RenderStyle.h" |
| 37 | 37 |
| 38 namespace WebCore { | 38 namespace WebCore { |
| 39 | 39 |
| 40 using namespace HTMLNames; | 40 using namespace HTMLNames; |
| 41 | 41 |
| 42 static void runAutofocus(HTMLDialogElement* dialog) | 42 // This function chooses the focused element when showModal() is invoked, as des
cribed in the spec for showModal(). |
| 43 static void setFocusForModalDialog(HTMLDialogElement* dialog) |
| 43 { | 44 { |
| 45 Element* focusableDescendant = 0; |
| 44 Node* next = 0; | 46 Node* next = 0; |
| 45 for (Node* node = dialog->firstChild(); node; node = next) { | 47 for (Node* node = dialog->firstChild(); node; node = next) { |
| 46 if (node->isElementNode() && toElement(node)->isFormControlElement()) { | 48 if (node->hasTagName(dialogTag)) |
| 49 next = NodeTraversal::nextSkippingChildren(*node, dialog); |
| 50 else |
| 51 next = NodeTraversal::next(*node, dialog); |
| 52 |
| 53 if (!node->isElementNode()) |
| 54 continue; |
| 55 Element* element = toElement(node); |
| 56 if (element->isFormControlElement()) { |
| 47 HTMLFormControlElement* control = toHTMLFormControlElement(node); | 57 HTMLFormControlElement* control = toHTMLFormControlElement(node); |
| 48 if (control->isAutofocusable()) { | 58 if (control->isAutofocusable()) { |
| 49 control->focus(); | 59 control->focus(); |
| 50 control->setAutofocused(); | 60 control->setAutofocused(); |
| 51 return; | 61 return; |
| 52 } | 62 } |
| 53 } | 63 } |
| 54 if (node->hasTagName(dialogTag)) | 64 if (!focusableDescendant && element->isFocusable()) |
| 55 next = NodeTraversal::nextSkippingChildren(*node, dialog); | 65 focusableDescendant = element; |
| 56 else | |
| 57 next = NodeTraversal::next(*node, dialog); | |
| 58 } | 66 } |
| 67 |
| 68 if (focusableDescendant) { |
| 69 focusableDescendant->focus(); |
| 70 return; |
| 71 } |
| 72 |
| 73 if (dialog->isFocusable()) { |
| 74 dialog->focus(); |
| 75 return; |
| 76 } |
| 77 |
| 78 dialog->document().setFocusedElement(0); |
| 59 } | 79 } |
| 60 | 80 |
| 61 static void inertSubtreesChanged(Document& document) | 81 static void inertSubtreesChanged(Document& document) |
| 62 { | 82 { |
| 63 // When a modal dialog opens or closes, nodes all over the accessibility | 83 // When a modal dialog opens or closes, nodes all over the accessibility |
| 64 // tree can change inertness which means they must be added or removed from | 84 // tree can change inertness which means they must be added or removed from |
| 65 // the tree. The most foolproof way is to clear the entire tree and rebuild | 85 // the tree. The most foolproof way is to clear the entire tree and rebuild |
| 66 // it, though a more clever way is probably possible. | 86 // it, though a more clever way is probably possible. |
| 67 Document* topDocument = document.topDocument(); | 87 Document* topDocument = document.topDocument(); |
| 68 topDocument->clearAXObjectCache(); | 88 topDocument->clearAXObjectCache(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 return; | 153 return; |
| 134 } | 154 } |
| 135 if (!inDocument()) { | 155 if (!inDocument()) { |
| 136 exceptionState.throwDOMException(InvalidStateError, "The element is not
in a Document."); | 156 exceptionState.throwDOMException(InvalidStateError, "The element is not
in a Document."); |
| 137 return; | 157 return; |
| 138 } | 158 } |
| 139 | 159 |
| 140 document().addToTopLayer(this); | 160 document().addToTopLayer(this); |
| 141 setBooleanAttribute(openAttr, true); | 161 setBooleanAttribute(openAttr, true); |
| 142 | 162 |
| 143 runAutofocus(this); | 163 // Throw away the AX cache first, so the subsequent steps don't have a chanc
e of queuing up |
| 164 // AX events on objects that would be invalidated when the cache is thrown a
way. |
| 165 inertSubtreesChanged(document()); |
| 166 |
| 144 forceLayoutForCentering(); | 167 forceLayoutForCentering(); |
| 145 inertSubtreesChanged(document()); | 168 setFocusForModalDialog(this); |
| 146 } | 169 } |
| 147 | 170 |
| 148 void HTMLDialogElement::setCentered(LayoutUnit centeredPosition) | 171 void HTMLDialogElement::setCentered(LayoutUnit centeredPosition) |
| 149 { | 172 { |
| 150 ASSERT(m_centeringMode == Uninitialized); | 173 ASSERT(m_centeringMode == Uninitialized); |
| 151 m_centeredPosition = centeredPosition; | 174 m_centeredPosition = centeredPosition; |
| 152 m_centeringMode = Centered; | 175 m_centeringMode = Centered; |
| 153 } | 176 } |
| 154 | 177 |
| 155 void HTMLDialogElement::setNotCentered() | 178 void HTMLDialogElement::setNotCentered() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 179 } | 202 } |
| 180 | 203 |
| 181 bool HTMLDialogElement::shouldBeReparentedUnderRenderView(const RenderStyle* sty
le) const | 204 bool HTMLDialogElement::shouldBeReparentedUnderRenderView(const RenderStyle* sty
le) const |
| 182 { | 205 { |
| 183 if (style && style->position() == AbsolutePosition) | 206 if (style && style->position() == AbsolutePosition) |
| 184 return true; | 207 return true; |
| 185 return Element::shouldBeReparentedUnderRenderView(style); | 208 return Element::shouldBeReparentedUnderRenderView(style); |
| 186 } | 209 } |
| 187 | 210 |
| 188 } // namespace WebCore | 211 } // namespace WebCore |
| OLD | NEW |