summaryrefslogtreecommitdiffstats
path: root/WebCore/html/HTMLFormControlElement.cpp
diff options
context:
space:
mode:
authorRussell Brenner <russellbrenner@google.com>2010-11-18 17:33:13 -0800
committerRussell Brenner <russellbrenner@google.com>2010-12-02 13:47:21 -0800
commit6b70adc33054f8aee8c54d0f460458a9df11b8a5 (patch)
tree103a13998c33944d6ab3b8318c509a037e639460 /WebCore/html/HTMLFormControlElement.cpp
parentbdf4ebc8e70b2d221b6ee7a65660918ecb1d33aa (diff)
downloadexternal_webkit-6b70adc33054f8aee8c54d0f460458a9df11b8a5.zip
external_webkit-6b70adc33054f8aee8c54d0f460458a9df11b8a5.tar.gz
external_webkit-6b70adc33054f8aee8c54d0f460458a9df11b8a5.tar.bz2
Merge WebKit at r72274: Initial merge by git.
Change-Id: Ie51f0b4a16da82942bd516dce59cfb79ebbe25fb
Diffstat (limited to 'WebCore/html/HTMLFormControlElement.cpp')
-rw-r--r--WebCore/html/HTMLFormControlElement.cpp57
1 files changed, 57 insertions, 0 deletions
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<HTMLFormElement*>(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<HTMLFormElement*>(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.