| 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 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 HTMLElement* element = toHTMLElement(this); | 78 HTMLElement* element = toHTMLElement(this); |
| 79 if (element->fastHasAttribute(formAttr)) | 79 if (element->fastHasAttribute(formAttr)) |
| 80 setFormAttributeTargetObserver(nullptr); | 80 setFormAttributeTargetObserver(nullptr); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void FormAssociatedElement::insertedInto(ContainerNode* insertionPoint) | 83 void FormAssociatedElement::insertedInto(ContainerNode* insertionPoint) |
| 84 { | 84 { |
| 85 if (!m_formWasSetByParser || !m_form || NodeTraversal::highestAncestorOrSelf
(*insertionPoint) != NodeTraversal::highestAncestorOrSelf(*m_form.get())) | 85 if (!m_formWasSetByParser || !m_form || NodeTraversal::highestAncestorOrSelf
(*insertionPoint) != NodeTraversal::highestAncestorOrSelf(*m_form.get())) |
| 86 resetFormOwner(); | 86 resetFormOwner(); |
| 87 | 87 |
| 88 if (!insertionPoint->inShadowIncludingDocument()) | 88 if (!insertionPoint->isConnected()) |
| 89 return; | 89 return; |
| 90 | 90 |
| 91 HTMLElement* element = toHTMLElement(this); | 91 HTMLElement* element = toHTMLElement(this); |
| 92 if (element->fastHasAttribute(formAttr)) | 92 if (element->fastHasAttribute(formAttr)) |
| 93 resetFormAttributeTargetObserver(); | 93 resetFormAttributeTargetObserver(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void FormAssociatedElement::removedFrom(ContainerNode* insertionPoint) | 96 void FormAssociatedElement::removedFrom(ContainerNode* insertionPoint) |
| 97 { | 97 { |
| 98 HTMLElement* element = toHTMLElement(this); | 98 HTMLElement* element = toHTMLElement(this); |
| 99 if (insertionPoint->inShadowIncludingDocument() && element->fastHasAttribute
(formAttr)) { | 99 if (insertionPoint->isConnected() && element->fastHasAttribute(formAttr)) { |
| 100 setFormAttributeTargetObserver(nullptr); | 100 setFormAttributeTargetObserver(nullptr); |
| 101 resetFormOwner(); | 101 resetFormOwner(); |
| 102 return; | 102 return; |
| 103 } | 103 } |
| 104 // If the form and element are both in the same tree, preserve the connectio
n to the form. | 104 // If the form and element are both in the same tree, preserve the connectio
n to the form. |
| 105 // Otherwise, null out our form and remove ourselves from the form's list of
elements. | 105 // Otherwise, null out our form and remove ourselves from the form's list of
elements. |
| 106 if (m_form && NodeTraversal::highestAncestorOrSelf(*element) != NodeTraversa
l::highestAncestorOrSelf(*m_form.get())) | 106 if (m_form && NodeTraversal::highestAncestorOrSelf(*element) != NodeTraversa
l::highestAncestorOrSelf(*m_form.get())) |
| 107 resetFormOwner(); | 107 resetFormOwner(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 HTMLFormElement* FormAssociatedElement::findAssociatedForm(const HTMLElement* el
ement) | 110 HTMLFormElement* FormAssociatedElement::findAssociatedForm(const HTMLElement* el
ement) |
| 111 { | 111 { |
| 112 const AtomicString& formId(element->fastGetAttribute(formAttr)); | 112 const AtomicString& formId(element->fastGetAttribute(formAttr)); |
| 113 // 3. If the element is reassociateable, has a form content attribute, and | 113 // 3. If the element is reassociateable, has a form content attribute, and |
| 114 // is itself in a Document, then run these substeps: | 114 // is itself in a Document, then run these substeps: |
| 115 if (!formId.isNull() && element->inShadowIncludingDocument()) { | 115 if (!formId.isNull() && element->isConnected()) { |
| 116 // 3.1. If the first element in the Document to have an ID that is | 116 // 3.1. If the first element in the Document to have an ID that is |
| 117 // case-sensitively equal to the element's form content attribute's | 117 // case-sensitively equal to the element's form content attribute's |
| 118 // value is a form element, then associate the form-associated element | 118 // value is a form element, then associate the form-associated element |
| 119 // with that form element. | 119 // with that form element. |
| 120 // 3.2. Abort the "reset the form owner" steps. | 120 // 3.2. Abort the "reset the form owner" steps. |
| 121 Element* newFormCandidate = element->treeScope().getElementById(formId); | 121 Element* newFormCandidate = element->treeScope().getElementById(formId); |
| 122 return isHTMLFormElement(newFormCandidate) ? toHTMLFormElement(newFormCa
ndidate) : 0; | 122 return isHTMLFormElement(newFormCandidate) ? toHTMLFormElement(newFormCa
ndidate) : 0; |
| 123 } | 123 } |
| 124 // 4. Otherwise, if the form-associated element in question has an ancestor | 124 // 4. Otherwise, if the form-associated element in question has an ancestor |
| 125 // form element, then associate the form-associated element with the nearest | 125 // form element, then associate the form-associated element with the nearest |
| 126 // such ancestor form element. | 126 // such ancestor form element. |
| 127 return element->findFormAncestor(); | 127 return element->findFormAncestor(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void FormAssociatedElement::formRemovedFromTree(const Node& formRoot) | 130 void FormAssociatedElement::formRemovedFromTree(const Node& formRoot) |
| 131 { | 131 { |
| 132 ASSERT(m_form); | 132 ASSERT(m_form); |
| 133 if (NodeTraversal::highestAncestorOrSelf(toHTMLElement(*this)) == formRoot) | 133 if (NodeTraversal::highestAncestorOrSelf(toHTMLElement(*this)) == formRoot) |
| 134 return; | 134 return; |
| 135 resetFormOwner(); | 135 resetFormOwner(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void FormAssociatedElement::associateByParser(HTMLFormElement* form) | 138 void FormAssociatedElement::associateByParser(HTMLFormElement* form) |
| 139 { | 139 { |
| 140 if (form && form->inShadowIncludingDocument()) { | 140 if (form && form->isConnected()) { |
| 141 m_formWasSetByParser = true; | 141 m_formWasSetByParser = true; |
| 142 setForm(form); | 142 setForm(form); |
| 143 form->didAssociateByParser(); | 143 form->didAssociateByParser(); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 void FormAssociatedElement::setForm(HTMLFormElement* newForm) | 147 void FormAssociatedElement::setForm(HTMLFormElement* newForm) |
| 148 { | 148 { |
| 149 if (m_form.get() == newForm) | 149 if (m_form.get() == newForm) |
| 150 return; | 150 return; |
| 151 willChangeForm(); | 151 willChangeForm(); |
| 152 if (m_form) | 152 if (m_form) |
| 153 m_form->disassociate(*this); | 153 m_form->disassociate(*this); |
| 154 if (newForm) { | 154 if (newForm) { |
| 155 m_form = newForm; | 155 m_form = newForm; |
| 156 m_form->associate(*this); | 156 m_form->associate(*this); |
| 157 } else { | 157 } else { |
| 158 m_form = nullptr; | 158 m_form = nullptr; |
| 159 } | 159 } |
| 160 didChangeForm(); | 160 didChangeForm(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void FormAssociatedElement::willChangeForm() | 163 void FormAssociatedElement::willChangeForm() |
| 164 { | 164 { |
| 165 } | 165 } |
| 166 | 166 |
| 167 void FormAssociatedElement::didChangeForm() | 167 void FormAssociatedElement::didChangeForm() |
| 168 { | 168 { |
| 169 if (!m_formWasSetByParser && m_form && m_form->inShadowIncludingDocument())
{ | 169 if (!m_formWasSetByParser && m_form && m_form->isConnected()) { |
| 170 HTMLElement* element = toHTMLElement(this); | 170 HTMLElement* element = toHTMLElement(this); |
| 171 element->document().didAssociateFormControl(element); | 171 element->document().didAssociateFormControl(element); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 void FormAssociatedElement::resetFormOwner() | 175 void FormAssociatedElement::resetFormOwner() |
| 176 { | 176 { |
| 177 m_formWasSetByParser = false; | 177 m_formWasSetByParser = false; |
| 178 HTMLElement* element = toHTMLElement(this); | 178 HTMLElement* element = toHTMLElement(this); |
| 179 const AtomicString& formId(element->fastGetAttribute(formAttr)); | 179 const AtomicString& formId(element->fastGetAttribute(formAttr)); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 { | 277 { |
| 278 if (m_formAttributeTargetObserver) | 278 if (m_formAttributeTargetObserver) |
| 279 m_formAttributeTargetObserver->unregister(); | 279 m_formAttributeTargetObserver->unregister(); |
| 280 m_formAttributeTargetObserver = newObserver; | 280 m_formAttributeTargetObserver = newObserver; |
| 281 } | 281 } |
| 282 | 282 |
| 283 void FormAssociatedElement::resetFormAttributeTargetObserver() | 283 void FormAssociatedElement::resetFormAttributeTargetObserver() |
| 284 { | 284 { |
| 285 HTMLElement* element = toHTMLElement(this); | 285 HTMLElement* element = toHTMLElement(this); |
| 286 const AtomicString& formId(element->fastGetAttribute(formAttr)); | 286 const AtomicString& formId(element->fastGetAttribute(formAttr)); |
| 287 if (!formId.isNull() && element->inShadowIncludingDocument()) | 287 if (!formId.isNull() && element->isConnected()) |
| 288 setFormAttributeTargetObserver(FormAttributeTargetObserver::create(formI
d, this)); | 288 setFormAttributeTargetObserver(FormAttributeTargetObserver::create(formI
d, this)); |
| 289 else | 289 else |
| 290 setFormAttributeTargetObserver(nullptr); | 290 setFormAttributeTargetObserver(nullptr); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void FormAssociatedElement::formAttributeTargetChanged() | 293 void FormAssociatedElement::formAttributeTargetChanged() |
| 294 { | 294 { |
| 295 resetFormOwner(); | 295 resetFormOwner(); |
| 296 } | 296 } |
| 297 | 297 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 visitor->trace(m_element); | 345 visitor->trace(m_element); |
| 346 IdTargetObserver::trace(visitor); | 346 IdTargetObserver::trace(visitor); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void FormAttributeTargetObserver::idTargetChanged() | 349 void FormAttributeTargetObserver::idTargetChanged() |
| 350 { | 350 { |
| 351 m_element->formAttributeTargetChanged(); | 351 m_element->formAttributeTargetChanged(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 } // namespace blink | 354 } // namespace blink |
| OLD | NEW |