Commit f7bf3768 authored by rniwa@webkit.org's avatar rniwa@webkit.org

The code to look for an ancestor form element is duplicated in three different places

https://bugs.webkit.org/show_bug.cgi?id=120391

Reviewed by Darin Adler.

Unduplicated the code by putting a single implementation in HTMLFormElement.cpp.

* WebCore.order:
* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::findAssociatedForm):
(WebCore::FormAssociatedElement::formAttributeChanged):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::virtualForm):
* html/HTMLElement.h:
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::HTMLFormControlElement):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::findClosestFormAncestor):
* html/HTMLFormElement.h:
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::insertedInto):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::HTMLObjectElement):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::HTMLTreeBuilder):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154801 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 00a46b95
2013-08-28 Ryosuke Niwa <rniwa@webkit.org>
The code to look for an ancestor form element is duplicated in three different places
https://bugs.webkit.org/show_bug.cgi?id=120391
Reviewed by Darin Adler.
Unduplicated the code by putting a single implementation in HTMLFormElement.cpp.
* WebCore.order:
* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::findAssociatedForm):
(WebCore::FormAssociatedElement::formAttributeChanged):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::virtualForm):
* html/HTMLElement.h:
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::HTMLFormControlElement):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::findClosestFormAncestor):
* html/HTMLFormElement.h:
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::insertedInto):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::HTMLObjectElement):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
2013-08-28 Ryosuke Niwa <rniwa@webkit.org>
Stop throwing DOM exceptions in internal 'XMLHttpRequest' response getters
......@@ -5486,7 +5486,6 @@ __ZN7WebCore31HTMLFormControlElementWithStateC2ERKNS_13QualifiedNameEPNS_8Docume
__ZN7WebCore22HTMLFormControlElementC2ERKNS_13QualifiedNameEPNS_8DocumentEPNS_15HTMLFormElementE
__ZN7WebCore16LabelableElementC2ERKNS_13QualifiedNameEPNS_8DocumentE
__ZN7WebCore21FormAssociatedElementC2Ev
__ZNK7WebCore11HTMLElement16findFormAncestorEv
__ZN7WebCore21FormAssociatedElement7setFormEPNS_15HTMLFormElementE
__ZN7WebCore9InputType10createTextEPNS_16HTMLInputElementE
__ZN7WebCore13TextInputType6createEPNS_16HTMLInputElementE
......@@ -114,7 +114,7 @@ HTMLFormElement* FormAssociatedElement::findAssociatedForm(const HTMLElement* el
}
if (!currentAssociatedForm)
return element->findFormAncestor();
return HTMLFormElement::findClosestFormAncestor(*element);
return currentAssociatedForm;
}
......@@ -172,7 +172,7 @@ void FormAssociatedElement::formAttributeChanged()
if (!element->fastHasAttribute(formAttr)) {
// The form attribute removed. We need to reset form owner here.
HTMLFormElement* originalForm = m_form;
setForm(element->findFormAncestor());
setForm(HTMLFormElement::findClosestFormAncestor(*element));
HTMLElement* element = toHTMLElement(this);
if (m_form && m_form != originalForm && m_form->inDocument())
element->document()->didAssociateFormControl(element);
......
......@@ -771,18 +771,9 @@ RenderObject* HTMLElement::createRenderer(RenderArena* arena, RenderStyle* style
return RenderObject::createObject(this, style);
}
HTMLFormElement* HTMLElement::findFormAncestor() const
{
for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) {
if (isHTMLFormElement(ancestor))
return toHTMLFormElement(ancestor);
}
return 0;
}
HTMLFormElement* HTMLElement::virtualForm() const
{
return findFormAncestor();
return HTMLFormElement::findClosestFormAncestor(*this);
}
static inline bool elementAffectsDirectionality(const Node* node)
......
......@@ -86,8 +86,6 @@ public:
HTMLFormElement* form() const { return virtualForm(); }
HTMLFormElement* findFormAncestor() const;
bool hasDirectionAuto() const;
TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
......
......@@ -62,7 +62,7 @@ HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName, Doc
, m_wasChangedSinceLastFormControlChangeEvent(false)
, m_hasAutofocused(false)
{
setForm(form ? form : findFormAncestor());
setForm(form ? form : HTMLFormElement::findClosestFormAncestor(*this));
setHasCustomStyleResolveCallbacks();
}
......
......@@ -723,4 +723,13 @@ void HTMLFormElement::copyNonAttributePropertiesFromElement(const Element& sourc
HTMLElement::copyNonAttributePropertiesFromElement(source);
}
HTMLFormElement* HTMLFormElement::findClosestFormAncestor(const Element& startElement)
{
for (Element* element = startElement.parentElement(); element; element = element->parentElement()) {
if (isHTMLFormElement(element))
return toHTMLFormElement(element);
}
return 0;
}
} // namespace
......@@ -106,6 +106,8 @@ public:
void getTextFieldValues(StringPairVector& fieldNamesAndValues) const;
static HTMLFormElement* findClosestFormAncestor(const Element&);
private:
HTMLFormElement(const QualifiedName&, Document*);
......
......@@ -205,15 +205,10 @@ void HTMLImageElement::didAttachRenderers()
Node::InsertionNotificationRequest HTMLImageElement::insertedInto(ContainerNode* insertionPoint)
{
if (!m_form) {
// m_form can be non-null if it was set in constructor.
for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) {
if (isHTMLFormElement(ancestor)) {
m_form = toHTMLFormElement(ancestor);
m_form->registerImgElement(this);
break;
}
}
if (!m_form) { // m_form can be non-null if it was set in constructor.
m_form = HTMLFormElement::findClosestFormAncestor(*this);
if (m_form)
m_form->registerImgElement(this);
}
// If we have been inserted from a renderer-less document,
......
......@@ -63,7 +63,7 @@ inline HTMLObjectElement::HTMLObjectElement(const QualifiedName& tagName, Docume
, m_useFallbackContent(false)
{
ASSERT(hasTagName(objectTag));
setForm(form ? form : findFormAncestor());
setForm(form ? form : HTMLFormElement::findClosestFormAncestor(*this));
}
inline HTMLObjectElement::~HTMLObjectElement()
......
......@@ -136,20 +136,6 @@ static bool isFormattingTag(const AtomicString& tagName)
return tagName == aTag || isNonAnchorFormattingTag(tagName);
}
static HTMLFormElement* closestFormAncestor(Element* element)
{
ASSERT(isMainThread());
while (element) {
if (isHTMLFormElement(element))
return toHTMLFormElement(element);
ContainerNode* parent = element->parentNode();
if (!parent || !parent->isElementNode())
return 0;
element = toElement(parent);
}
return 0;
}
class HTMLTreeBuilder::ExternalCharacterTokenBuffer {
WTF_MAKE_NONCOPYABLE(ExternalCharacterTokenBuffer);
public:
......@@ -313,7 +299,7 @@ HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser, DocumentFragment* f
#endif
resetInsertionModeAppropriately();
m_tree.setForm(closestFormAncestor(contextElement));
m_tree.setForm(!contextElement || isHTMLFormElement(contextElement) ? toHTMLFormElement(contextElement) : HTMLFormElement::findClosestFormAncestor(*contextElement));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment