From 6b70adc33054f8aee8c54d0f460458a9df11b8a5 Mon Sep 17 00:00:00 2001 From: Russell Brenner Date: Thu, 18 Nov 2010 17:33:13 -0800 Subject: Merge WebKit at r72274: Initial merge by git. Change-Id: Ie51f0b4a16da82942bd516dce59cfb79ebbe25fb --- WebCore/html/HTMLFormControlElement.cpp | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'WebCore/html/HTMLFormControlElement.cpp') diff --git a/WebCore/html/HTMLFormControlElement.cpp b/WebCore/html/HTMLFormControlElement.cpp index 8fa000f..2f5d414 100644 --- a/WebCore/html/HTMLFormControlElement.cpp +++ b/WebCore/html/HTMLFormControlElement.cpp @@ -154,6 +154,16 @@ void HTMLFormControlElement::attach() void HTMLFormControlElement::insertedIntoTree(bool deep) { + if (fastHasAttribute(formAttr)) { + document()->registerFormElementWithFormAttribute(this); + Element* element = document()->getElementById(fastGetAttribute(formAttr)); + if (element && element->hasTagName(formTag)) { + if (m_form) + m_form->removeFormElement(this); + m_form = static_cast(element); + m_form->registerFormElement(this); + } + } if (!m_form) { // This handles the case of a new form element being created by // JavaScript and inserted inside a form. In the case of the parser @@ -179,6 +189,9 @@ static inline Node* findRoot(Node* n) void HTMLFormControlElement::removedFromTree(bool deep) { + if (fastHasAttribute(formAttr)) + document()->unregisterFormElementWithFormAttribute(this); + // If the form and element are both in the same tree, preserve the connection to the form. // Otherwise, null out our form and remove ourselves from the form's list of elements. if (m_form && findRoot(this) != findRoot(m_form)) { @@ -431,6 +444,50 @@ void HTMLFormControlElement::removeFromForm() m_form = 0; } +void HTMLFormControlElement::resetFormOwner(HTMLFormElement* form) +{ + if (m_form) { + if (!fastHasAttribute(formAttr)) + return; + m_form->removeFormElement(this); + } + m_form = 0; + if (fastHasAttribute(formAttr)) { + // The HTML5 spec says that the element should be associated with + // the first element in the document to have an ID that equal to + // the value of form attribute, so we put the result of + // document()->getElementById() over the given element. + Element* firstElement = document()->getElementById(fastGetAttribute(formAttr)); + if (firstElement && firstElement->hasTagName(formTag)) + m_form = static_cast(firstElement); + else + m_form = form; + } else + m_form = findFormAncestor(); + if (m_form) + m_form->registerFormElement(this); + else + document()->checkedRadioButtons().addButton(this); +} + +void HTMLFormControlElement::attributeChanged(Attribute* attr, bool preserveDecls) +{ + if (attr->name() == formAttr) { + if (!fastHasAttribute(formAttr)) { + // The form attribute removed. We need to reset form owner here. + if (m_form) + m_form->removeFormElement(this); + m_form = findFormAncestor(); + if (m_form) + m_form->registerFormElement(this); + else + document()->checkedRadioButtons().addButton(this); + } else + resetFormOwner(0); + } + HTMLElement::attributeChanged(attr, preserveDecls); +} + bool HTMLFormControlElement::isLabelable() const { // FIXME: Add meterTag and outputTag to the list once we support them. -- cgit v1.1