Changeset 160182 in webkit


Ignore:
Timestamp:
Dec 5, 2013 11:45:29 AM (10 years ago)
Author:
rniwa@webkit.org
Message:

Change how the form element pointer affects parsing template elements, to reduce weirdness in templates
https://bugs.webkit.org/show_bug.cgi?id=125279

Reviewed by Antti Koivisto.

Source/WebCore:

Faithfully update the HTML5 parser after http://html5.org/tools/web-apps-tracker?from=8330&to=8331.

Test: fast/dom/HTMLTemplateElement/no-form-association-2.html

  • html/parser/HTMLConstructionSite.cpp:

(WebCore::HTMLConstructionSite::insertHTMLFormElement): Don't the form element pointer if the context
element or its ancestor is a template element.
(WebCore::HTMLConstructionSite::insideTemplateElement): Added.
(WebCore::HTMLConstructionSite::createHTMLElement): Renamed openElementsContainTemplateElement to
insideTemplateElement to reflect the true semantics of the boolean.

  • html/parser/HTMLConstructionSite.h:
  • html/parser/HTMLTreeBuilder.cpp:

(WebCore::HTMLTreeBuilder::processIsindexStartTagForInBody): Ignore the form element pointer if there
is a template element on the stack of open elements. This faithfully reflects what's being said in the
specification. We should probably make isParsingTemplateContents more efficient by storing a boolean
and then wrap from() in some helper function but that should probbaly happen in a separate patch.
(WebCore::HTMLTreeBuilder::processStartTagForInBody): Ditto.
(WebCore::HTMLTreeBuilder::processStartTagForInTable): Ditto.
(WebCore::HTMLTreeBuilder::processEndTagForInBody): Don't unset or rely on the form element pointer
when there is a template element on the stack of open elements.

  • html/parser/HTMLTreeBuilder.h:

(WebCore::HTMLTreeBuilder::isParsingTemplateContents): Added a trivial implementation for when
TEMPLATE_ELEMENT is disabled.
(WebCore::HTMLTreeBuilder::isParsingFragmentOrTemplateContents): Merged two implementations.

LayoutTests:

Added a regression test. Someone should port this test into web-platform-tests once the latest spec.
change has been refelcted to a working draft version of the HTML5 specification.

  • fast/dom/HTMLTemplateElement/no-form-association-2-expected.txt: Added.
  • fast/dom/HTMLTemplateElement/no-form-association-2.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r160181 r160182  
     12013-12-04  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Change how the form element pointer affects parsing template elements, to reduce weirdness in templates
     4        https://bugs.webkit.org/show_bug.cgi?id=125279
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Added a regression test. Someone should port this test into web-platform-tests once the latest spec.
     9        change has been refelcted to a working draft version of the HTML5 specification.
     10
     11        * fast/dom/HTMLTemplateElement/no-form-association-2-expected.txt: Added.
     12        * fast/dom/HTMLTemplateElement/no-form-association-2.html: Added.
     13
    1142013-12-05  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r160181 r160182  
     12013-12-04  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Change how the form element pointer affects parsing template elements, to reduce weirdness in templates
     4        https://bugs.webkit.org/show_bug.cgi?id=125279
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Faithfully update the HTML5 parser after http://html5.org/tools/web-apps-tracker?from=8330&to=8331.
     9
     10        Test: fast/dom/HTMLTemplateElement/no-form-association-2.html
     11
     12        * html/parser/HTMLConstructionSite.cpp:
     13        (WebCore::HTMLConstructionSite::insertHTMLFormElement): Don't the form element pointer if the context
     14        element or its ancestor is a template element.
     15        (WebCore::HTMLConstructionSite::insideTemplateElement): Added.
     16        (WebCore::HTMLConstructionSite::createHTMLElement): Renamed openElementsContainTemplateElement to
     17        insideTemplateElement to reflect the true semantics of the boolean.
     18
     19        * html/parser/HTMLConstructionSite.h:
     20
     21        * html/parser/HTMLTreeBuilder.cpp:
     22        (WebCore::HTMLTreeBuilder::processIsindexStartTagForInBody): Ignore the form element pointer if there
     23        is a template element on the stack of open elements. This faithfully reflects what's being said in the
     24        specification. We should probably make isParsingTemplateContents more efficient by storing a boolean
     25        and then wrap from() in some helper function but that should probbaly happen in a separate patch.
     26        (WebCore::HTMLTreeBuilder::processStartTagForInBody): Ditto.
     27        (WebCore::HTMLTreeBuilder::processStartTagForInTable): Ditto.
     28        (WebCore::HTMLTreeBuilder::processEndTagForInBody): Don't unset or rely on the form element pointer
     29        when there is a template element on the stack of open elements.
     30
     31        * html/parser/HTMLTreeBuilder.h:
     32        (WebCore::HTMLTreeBuilder::isParsingTemplateContents): Added a trivial implementation for when
     33        TEMPLATE_ELEMENT is disabled.
     34        (WebCore::HTMLTreeBuilder::isParsingFragmentOrTemplateContents): Merged two implementations.
     35
    1362013-12-05  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
    237
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp

    r159909 r160182  
    412412    RefPtr<Element> element = createHTMLElement(token);
    413413    ASSERT(isHTMLFormElement(element.get()));
    414     m_form = static_pointer_cast<HTMLFormElement>(element.release());
    415     m_form->setDemoted(isDemoted);
    416     attachLater(currentNode(), m_form);
    417     m_openElements.push(HTMLStackItem::create(m_form, token));
     414    RefPtr<HTMLFormElement> form = static_pointer_cast<HTMLFormElement>(element.release());
     415    if (!insideTemplateElement())
     416        m_form = form;
     417    form->setDemoted(isDemoted);
     418    attachLater(currentNode(), form);
     419    m_openElements.push(HTMLStackItem::create(form.release(), token));
    418420}
    419421
     
    538540}
    539541
     542inline bool HTMLConstructionSite::insideTemplateElement()
     543{
     544    return !ownerDocumentForCurrentNode().frame();
     545}
     546
    540547PassRefPtr<Element> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token)
    541548{
     
    546553    // http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#create-an-element-for-the-token
    547554    Document& ownerDocument = ownerDocumentForCurrentNode();
    548     bool openElementsContainTemplateElement = !ownerDocument.frame();
    549     RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, openElementsContainTemplateElement ? nullptr : form(), true);
     555    bool insideTemplateElement = !ownerDocument.frame();
     556    RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true);
    550557    setAttributes(element.get(), token, m_parserContentPolicy);
    551558    ASSERT(element->isHTMLElement());
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.h

    r159909 r160182  
    120120    HTMLStackItem* oneBelowTop() const { return m_openElements.oneBelowTop(); }
    121121    Document& ownerDocumentForCurrentNode();
     122    bool insideTemplateElement();
    122123    HTMLElementStack* openElements() const { return &m_openElements; }
    123124    HTMLFormattingElementList* activeFormattingElements() const { return &m_activeFormattingElements; }
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp

    r159610 r160182  
    463463    ASSERT(token->name() == isindexTag);
    464464    parseError(token);
    465     if (m_tree.form())
     465    if (m_tree.form() && !isParsingTemplateContents())
    466466        return;
    467467    notImplemented(); // Acknowledge self-closing flag
     
    701701    }
    702702    if (token->name() == formTag) {
    703         if (m_tree.form()) {
     703        if (m_tree.form() && !isParsingTemplateContents()) {
    704704            parseError(token);
    705705            return;
     
    10521052    if (token->name() == formTag) {
    10531053        parseError(token);
    1054         if (m_tree.form())
     1054        if (m_tree.form() && !isParsingTemplateContents())
    10551055            return;
    10561056        m_tree.insertHTMLFormElement(token, true);
     
    18651865    }
    18661866    if (token->name() == formTag) {
    1867         RefPtr<Element> node = m_tree.takeForm();
    1868         if (!node || !m_tree.openElements()->inScope(node.get())) {
    1869             parseError(token);
    1870             return;
    1871         }
    1872         m_tree.generateImpliedEndTags();
    1873         if (m_tree.currentElement() != node.get())
    1874             parseError(token);
    1875         m_tree.openElements()->remove(node.get());
     1867        if (!isParsingTemplateContents()) {
     1868            RefPtr<Element> node = m_tree.takeForm();
     1869            if (!node || !m_tree.openElements()->inScope(node.get())) {
     1870                parseError(token);
     1871                return;
     1872            }
     1873            m_tree.generateImpliedEndTags();
     1874            if (m_tree.currentNode() != node.get())
     1875                parseError(token);
     1876            m_tree.openElements()->remove(node.get());
     1877        } else {
     1878            if (!m_tree.openElements()->inScope(token->name())) {
     1879                parseError(token);
     1880                return;
     1881            }
     1882            m_tree.generateImpliedEndTags();
     1883            if (!m_tree.currentNode()->hasTagName(formTag))
     1884                parseError(token);
     1885            m_tree.openElements()->popUntilPopped(token->name());
     1886        }
    18761887    }
    18771888    if (token->name() == pTag) {
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.h

    r156980 r160182  
    7373#if ENABLE(TEMPLATE_ELEMENT)
    7474    bool isParsingTemplateContents() const { return m_tree.openElements()->hasTemplateInHTMLScope(); }
     75#else
     76    bool isParsingTemplateContents() const { return false; }
     77#endif
    7578    bool isParsingFragmentOrTemplateContents() const { return isParsingFragment() || isParsingTemplateContents(); }
    76 #else
    77     bool isParsingFragmentOrTemplateContents() const { return isParsingFragment(); }
    78 #endif
    7979
    8080    void detach();
Note: See TracChangeset for help on using the changeset viewer.