OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Library General Public License for more details. | 16 * Library General Public License for more details. |
17 * | 17 * |
18 * You should have received a copy of the GNU Library General Public License | 18 * You should have received a copy of the GNU Library General Public License |
19 * along with this library; see the file COPYING.LIB. If not, write to | 19 * along with this library; see the file COPYING.LIB. If not, write to |
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #include "core/html/FormAssociatedElement.h" | 26 #include "core/html/FormAssociatedElement.h" |
27 | 27 |
28 #include "core/HTMLNames.h" | 28 #include "core/HTMLNames.h" |
29 #include "core/dom/IdTargetObserver.h" | 29 #include "core/dom/IdTargetObserver.h" |
| 30 #include "core/dom/NodeTraversal.h" |
30 #include "core/html/HTMLFormControlElement.h" | 31 #include "core/html/HTMLFormControlElement.h" |
31 #include "core/html/HTMLFormElement.h" | 32 #include "core/html/HTMLFormElement.h" |
32 #include "core/html/HTMLObjectElement.h" | 33 #include "core/html/HTMLObjectElement.h" |
33 #include "core/html/ValidityState.h" | 34 #include "core/html/ValidityState.h" |
34 | 35 |
35 namespace blink { | 36 namespace blink { |
36 | 37 |
37 using namespace HTMLNames; | 38 using namespace HTMLNames; |
38 | 39 |
39 class FormAttributeTargetObserver : public IdTargetObserver { | 40 class FormAttributeTargetObserver : public IdTargetObserver { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 77 |
77 void FormAssociatedElement::didMoveToNewDocument(Document& oldDocument) | 78 void FormAssociatedElement::didMoveToNewDocument(Document& oldDocument) |
78 { | 79 { |
79 HTMLElement* element = toHTMLElement(this); | 80 HTMLElement* element = toHTMLElement(this); |
80 if (element->fastHasAttribute(formAttr)) | 81 if (element->fastHasAttribute(formAttr)) |
81 setFormAttributeTargetObserver(nullptr); | 82 setFormAttributeTargetObserver(nullptr); |
82 } | 83 } |
83 | 84 |
84 void FormAssociatedElement::insertedInto(ContainerNode* insertionPoint) | 85 void FormAssociatedElement::insertedInto(ContainerNode* insertionPoint) |
85 { | 86 { |
86 if (!m_formWasSetByParser || insertionPoint->highestAncestorOrSelf() != m_fo
rm->highestAncestorOrSelf()) | 87 if (!m_formWasSetByParser || NodeTraversal::highestAncestorOrSelf(*insertion
Point) != NodeTraversal::highestAncestorOrSelf(*m_form.get())) |
87 resetFormOwner(); | 88 resetFormOwner(); |
88 | 89 |
89 if (!insertionPoint->inDocument()) | 90 if (!insertionPoint->inDocument()) |
90 return; | 91 return; |
91 | 92 |
92 HTMLElement* element = toHTMLElement(this); | 93 HTMLElement* element = toHTMLElement(this); |
93 if (element->fastHasAttribute(formAttr)) | 94 if (element->fastHasAttribute(formAttr)) |
94 resetFormAttributeTargetObserver(); | 95 resetFormAttributeTargetObserver(); |
95 } | 96 } |
96 | 97 |
97 void FormAssociatedElement::removedFrom(ContainerNode* insertionPoint) | 98 void FormAssociatedElement::removedFrom(ContainerNode* insertionPoint) |
98 { | 99 { |
99 HTMLElement* element = toHTMLElement(this); | 100 HTMLElement* element = toHTMLElement(this); |
100 if (insertionPoint->inDocument() && element->fastHasAttribute(formAttr)) | 101 if (insertionPoint->inDocument() && element->fastHasAttribute(formAttr)) |
101 setFormAttributeTargetObserver(nullptr); | 102 setFormAttributeTargetObserver(nullptr); |
102 // If the form and element are both in the same tree, preserve the connectio
n to the form. | 103 // If the form and element are both in the same tree, preserve the connectio
n to the form. |
103 // Otherwise, null out our form and remove ourselves from the form's list of
elements. | 104 // Otherwise, null out our form and remove ourselves from the form's list of
elements. |
104 if (m_form && element->highestAncestorOrSelf() != m_form->highestAncestorOrS
elf()) | 105 if (m_form && NodeTraversal::highestAncestorOrSelf(*element) != NodeTraversa
l::highestAncestorOrSelf(*m_form.get())) |
105 resetFormOwner(); | 106 resetFormOwner(); |
106 } | 107 } |
107 | 108 |
108 HTMLFormElement* FormAssociatedElement::findAssociatedForm(const HTMLElement* el
ement) | 109 HTMLFormElement* FormAssociatedElement::findAssociatedForm(const HTMLElement* el
ement) |
109 { | 110 { |
110 const AtomicString& formId(element->fastGetAttribute(formAttr)); | 111 const AtomicString& formId(element->fastGetAttribute(formAttr)); |
111 // 3. If the element is reassociateable, has a form content attribute, and | 112 // 3. If the element is reassociateable, has a form content attribute, and |
112 // is itself in a Document, then run these substeps: | 113 // is itself in a Document, then run these substeps: |
113 if (!formId.isNull() && element->inDocument()) { | 114 if (!formId.isNull() && element->inDocument()) { |
114 // 3.1. If the first element in the Document to have an ID that is | 115 // 3.1. If the first element in the Document to have an ID that is |
115 // case-sensitively equal to the element's form content attribute's | 116 // case-sensitively equal to the element's form content attribute's |
116 // value is a form element, then associate the form-associated element | 117 // value is a form element, then associate the form-associated element |
117 // with that form element. | 118 // with that form element. |
118 // 3.2. Abort the "reset the form owner" steps. | 119 // 3.2. Abort the "reset the form owner" steps. |
119 Element* newFormCandidate = element->treeScope().getElementById(formId); | 120 Element* newFormCandidate = element->treeScope().getElementById(formId); |
120 return isHTMLFormElement(newFormCandidate) ? toHTMLFormElement(newFormCa
ndidate) : 0; | 121 return isHTMLFormElement(newFormCandidate) ? toHTMLFormElement(newFormCa
ndidate) : 0; |
121 } | 122 } |
122 // 4. Otherwise, if the form-associated element in question has an ancestor | 123 // 4. Otherwise, if the form-associated element in question has an ancestor |
123 // form element, then associate the form-associated element with the nearest | 124 // form element, then associate the form-associated element with the nearest |
124 // such ancestor form element. | 125 // such ancestor form element. |
125 return element->findFormAncestor(); | 126 return element->findFormAncestor(); |
126 } | 127 } |
127 | 128 |
128 void FormAssociatedElement::formRemovedFromTree(const Node& formRoot) | 129 void FormAssociatedElement::formRemovedFromTree(const Node& formRoot) |
129 { | 130 { |
130 ASSERT(m_form); | 131 ASSERT(m_form); |
131 if (toHTMLElement(this)->highestAncestorOrSelf() == formRoot) | 132 if (NodeTraversal::highestAncestorOrSelf(toHTMLElement(*this)) == formRoot) |
132 return; | 133 return; |
133 resetFormOwner(); | 134 resetFormOwner(); |
134 } | 135 } |
135 | 136 |
136 void FormAssociatedElement::associateByParser(HTMLFormElement* form) | 137 void FormAssociatedElement::associateByParser(HTMLFormElement* form) |
137 { | 138 { |
138 if (form && form->inDocument()) { | 139 if (form && form->inDocument()) { |
139 m_formWasSetByParser = true; | 140 m_formWasSetByParser = true; |
140 setForm(form); | 141 setForm(form); |
141 form->didAssociateByParser(); | 142 form->didAssociateByParser(); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 visitor->trace(m_element); | 343 visitor->trace(m_element); |
343 IdTargetObserver::trace(visitor); | 344 IdTargetObserver::trace(visitor); |
344 } | 345 } |
345 | 346 |
346 void FormAttributeTargetObserver::idTargetChanged() | 347 void FormAttributeTargetObserver::idTargetChanged() |
347 { | 348 { |
348 m_element->formAttributeTargetChanged(); | 349 m_element->formAttributeTargetChanged(); |
349 } | 350 } |
350 | 351 |
351 } // namespace Webcore | 352 } // namespace Webcore |
OLD | NEW |