Title: [176630] trunk
Revision
176630
Author
commit-qu...@webkit.org
Date
2014-12-02 02:50:11 -0800 (Tue, 02 Dec 2014)

Log Message

Source/WebCore:
Missing support for innerHTML on SVGElement
https://bugs.webkit.org/show_bug.cgi?id=136903

Patch by Sylvain Galineau <galin...@adobe.com> on 2014-12-02
Reviewed by Dean Jackson.

Two parts to this patch:
1. Move innerHTML/outerHTML to Element so SVG elements can inherit them, per https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#innerhtml
2. Make sure fragment insertion is processed relative to the proper node, per http://www.whatwg.org/specs/web-apps/current-work/#adjusted-current-node

The latter part was ported over from Blink.

Test: svg/in-html/svg-inner-html.html

* bindings/objc/PublicDOMInterfaces.h: Move innerHTML/outerHTML to Element.
* dom/Element.cpp:
(WebCore::Element::mergeWithNextTextNode): Helper used by Element::innerHTML/outerHTML as well as HTMLElement::innerText/outerText; moved to Element as protected static.
(WebCore::Element::innerHTML): Moved from HTMLElement.
(WebCore::Element::outerHTML): Moved from HTMLElement.
(WebCore::Element::setOuterHTML): Moved from HTMLElement.
(WebCore::Element::setInnerHTML): Moved from HTMLElement.
* dom/Element.h:
* dom/Element.idl:
* html/HTMLElement.cpp:
(WebCore::HTMLElement::innerHTML): Deleted.
(WebCore::HTMLElement::outerHTML): Deleted.
(WebCore::HTMLElement::setInnerHTML): Deleted.
(WebCore::mergeWithNextTextNode): Deleted.
(WebCore::HTMLElement::setOuterHTML): Deleted.
* html/HTMLElement.h:
* html/HTMLElement.idl:
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::FragmentParsingContext::FragmentParsingContext): no more m_contextElement.
(WebCore::HTMLTreeBuilder::constructTree): read namespace from adjusted current node.
(WebCore::HTMLTreeBuilder::resetInsertionModeAppropriately): use contextElementStackItem for insertion.
(WebCore::HTMLTreeBuilder::adjustedCurrentStackItem): compute adjusted current node.
(WebCore::HTMLTreeBuilder::shouldProcessTokenInForeignContent): use adjusted current node for context.
(WebCore::HTMLTreeBuilder::processTokenInForeignContent): use adjusted current node to read namespace.
* html/parser/HTMLTreeBuilder.h:
(WebCore::HTMLTreeBuilder::FragmentParsingContext::contextElement): Deleted. Read from contextElementStackItem.
(WebCore::HTMLTreeBuilder::FragmentParsingContext::contextElementStackItem): Added.

LayoutTests:
    Missing support for innerHTML on SVGElement
    https://bugs.webkit.org/show_bug.cgi?id=136903

Patch by Sylvain Galineau <galin...@adobe.com> on 2014-12-02
Reviewed by Dean Jackson.

* js/dom/dom-static-property-for-in-iteration-expected.txt: The property enumeration order is different now that inner/outerHTML are inherited from Element
* platform/mac/svg/in-html/svg-inner-html-expected.png: Added.
* svg/css/svg-attribute-length-parsing-expected.txt:
Now that innerHTML works, the output should start with 'Test'
* svg/in-html/svg-inner-html-expected.txt: Added.
* svg/in-html/svg-inner-html.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (176629 => 176630)


--- trunk/LayoutTests/ChangeLog	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/LayoutTests/ChangeLog	2014-12-02 10:50:11 UTC (rev 176630)
@@ -1,3 +1,17 @@
+2014-12-02  Sylvain Galineau  <galin...@adobe.com>
+
+    Missing support for innerHTML on SVGElement
+    https://bugs.webkit.org/show_bug.cgi?id=136903
+
+        Reviewed by Dean Jackson.
+
+        * js/dom/dom-static-property-for-in-iteration-expected.txt: The property enumeration order is different now that inner/outerHTML are inherited from Element
+        * platform/mac/svg/in-html/svg-inner-html-expected.png: Added.
+        * svg/css/svg-attribute-length-parsing-expected.txt:
+        Now that innerHTML works, the output should start with 'Test'
+        * svg/in-html/svg-inner-html-expected.txt: Added.
+        * svg/in-html/svg-inner-html.html: Added.
+
 2014-12-02  Andrzej Badowski  <a.badow...@samsung.com>
 
         REGRESSION(r176122): [GTK] Layout Test platform/gtk/accessibility/table-hierarchy.html fails.

Modified: trunk/LayoutTests/js/dom/dom-static-property-for-in-iteration-expected.txt (176629 => 176630)


--- trunk/LayoutTests/js/dom/dom-static-property-for-in-iteration-expected.txt	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/LayoutTests/js/dom/dom-static-property-for-in-iteration-expected.txt	2014-12-02 10:50:11 UTC (rev 176630)
@@ -37,9 +37,7 @@
 PASS a["webkitdropzone"] is 
 PASS a["hidden"] is false
 PASS a["accessKey"] is 
-PASS a["innerHTML"] is nerget
 PASS a["innerText"] is nerget
-PASS a["outerHTML"] is <a id="foo" href=""
 PASS a["outerText"] is nerget
 PASS a["children"] is [object HTMLCollection]
 PASS a["contentEditable"] is inherit
@@ -50,7 +48,7 @@
 PASS a["style"] is [object CSSStyleDeclaration]
 PASS a["id"] is foo
 PASS a["offsetLeft"] is 8
-PASS a["offsetTop"] is 789
+PASS a["offsetTop"] is 759
 PASS a["offsetWidth"] is 39
 PASS a["offsetHeight"] is 18
 PASS a["clientLeft"] is 0
@@ -62,6 +60,8 @@
 PASS a["scrollWidth"] is 0
 PASS a["scrollHeight"] is 0
 PASS a["offsetParent"] is [object HTMLBodyElement]
+PASS a["innerHTML"] is nerget
+PASS a["outerHTML"] is <a id="foo" href=""
 PASS a["className"] is 
 PASS a["classList"] is 
 PASS a["dataset"] is [object DOMStringMap]

Modified: trunk/LayoutTests/svg/css/svg-attribute-length-parsing-expected.txt (176629 => 176630)


--- trunk/LayoutTests/svg/css/svg-attribute-length-parsing-expected.txt	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/LayoutTests/svg/css/svg-attribute-length-parsing-expected.txt	2014-12-02 10:50:11 UTC (rev 176630)
@@ -1,3 +1,4 @@
+Test
 Test CSS parsing on SVG presentation attributes.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".

Added: trunk/LayoutTests/svg/in-html/svg-inner-html-expected.txt (0 => 176630)


--- trunk/LayoutTests/svg/in-html/svg-inner-html-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/svg/in-html/svg-inner-html-expected.txt	2014-12-02 10:50:11 UTC (rev 176630)
@@ -0,0 +1,2 @@
+PASS <path d="M 0 0 L 259 0 259 148 0 148 z" stroke="#fff" stroke-width="1" fill="#00ff00"></path>
+

Added: trunk/LayoutTests/svg/in-html/svg-inner-html.html (0 => 176630)


--- trunk/LayoutTests/svg/in-html/svg-inner-html.html	                        (rev 0)
+++ trunk/LayoutTests/svg/in-html/svg-inner-html.html	2014-12-02 10:50:11 UTC (rev 176630)
@@ -0,0 +1,25 @@
+<!doctype html>
+<head>
+<script src=""
+<script>
+    if (window.testRunner)
+       testRunner.dumpAsText();
+</script>
+</head>
+<body>
+    <div id="console"></div>
+    <svg x="0px" y="0px" width="400px" height="300px">
+            <defs id="svg-defs"></defs>
+            <rect fill="url(#pattern)" height="148" width="259" y="1" x="1" stroke="#000000" />
+    </svg>
+    <script>
+        var defs = document.getElementById('svg-defs');
+
+        var newPattern = '<pattern id="svg-pattern" width="259" height="148" patternUnits="userSpaceOnUse"><path d="M 0 0 L 259 0 259 148 0 148 z" stroke="#fff" stroke-width="1" fill="#00ff00"></path></pattern>';
+
+        defs.innerHTML = newPattern;
+
+        var verify = document.getElementById('svg-pattern');
+        testPassed(verify.innerHTML);
+    </script>
+</body>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (176629 => 176630)


--- trunk/Source/WebCore/ChangeLog	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/ChangeLog	2014-12-02 10:50:11 UTC (rev 176630)
@@ -1,3 +1,46 @@
+2014-12-02  Sylvain Galineau  <galin...@adobe.com>
+
+        Missing support for innerHTML on SVGElement
+        https://bugs.webkit.org/show_bug.cgi?id=136903
+
+        Reviewed by Dean Jackson.
+
+        Two parts to this patch:
+        1. Move innerHTML/outerHTML to Element so SVG elements can inherit them, per https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#innerhtml
+        2. Make sure fragment insertion is processed relative to the proper node, per http://www.whatwg.org/specs/web-apps/current-work/#adjusted-current-node
+
+        The latter part was ported over from Blink. 
+
+        Test: svg/in-html/svg-inner-html.html
+
+        * bindings/objc/PublicDOMInterfaces.h: Move innerHTML/outerHTML to Element.
+        * dom/Element.cpp:
+        (WebCore::Element::mergeWithNextTextNode): Helper used by Element::innerHTML/outerHTML as well as HTMLElement::innerText/outerText; moved to Element as protected static.
+        (WebCore::Element::innerHTML): Moved from HTMLElement.
+        (WebCore::Element::outerHTML): Moved from HTMLElement.
+        (WebCore::Element::setOuterHTML): Moved from HTMLElement.
+        (WebCore::Element::setInnerHTML): Moved from HTMLElement.
+        * dom/Element.h: 
+        * dom/Element.idl:
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::innerHTML): Deleted.
+        (WebCore::HTMLElement::outerHTML): Deleted.
+        (WebCore::HTMLElement::setInnerHTML): Deleted.
+        (WebCore::mergeWithNextTextNode): Deleted.
+        (WebCore::HTMLElement::setOuterHTML): Deleted.
+        * html/HTMLElement.h:
+        * html/HTMLElement.idl:
+        * html/parser/HTMLTreeBuilder.cpp:
+        (WebCore::HTMLTreeBuilder::FragmentParsingContext::FragmentParsingContext): no more m_contextElement.
+        (WebCore::HTMLTreeBuilder::constructTree): read namespace from adjusted current node.
+        (WebCore::HTMLTreeBuilder::resetInsertionModeAppropriately): use contextElementStackItem for insertion.
+        (WebCore::HTMLTreeBuilder::adjustedCurrentStackItem): compute adjusted current node.
+        (WebCore::HTMLTreeBuilder::shouldProcessTokenInForeignContent): use adjusted current node for context.
+        (WebCore::HTMLTreeBuilder::processTokenInForeignContent): use adjusted current node to read namespace.
+        * html/parser/HTMLTreeBuilder.h:
+        (WebCore::HTMLTreeBuilder::FragmentParsingContext::contextElement): Deleted. Read from contextElementStackItem.
+        (WebCore::HTMLTreeBuilder::FragmentParsingContext::contextElementStackItem): Added.
+
 2014-11-20  Jeffrey Pfau  <jp...@apple.com>
 
         Add cancelable version of willSendRequest

Modified: trunk/Source/WebCore/bindings/objc/PublicDOMInterfaces.h (176629 => 176630)


--- trunk/Source/WebCore/bindings/objc/PublicDOMInterfaces.h	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/bindings/objc/PublicDOMInterfaces.h	2014-12-02 10:50:11 UTC (rev 176630)
@@ -195,6 +195,8 @@
 @property (readonly) int clientLeft WEBKIT_AVAILABLE_MAC(10_5);
 @property (readonly) int clientTop WEBKIT_AVAILABLE_MAC(10_5);
 @property (readonly, copy) NSString *innerText WEBKIT_AVAILABLE_MAC(10_5);
+@property (copy) NSString *innerHTML;
+@property (copy) NSString *outerHTML;
 @property (readonly, strong) DOMElement *firstElementChild WEBKIT_AVAILABLE_MAC(10_6);
 @property (readonly, strong) DOMElement *lastElementChild WEBKIT_AVAILABLE_MAC(10_6);
 @property (readonly, strong) DOMElement *previousElementSibling WEBKIT_AVAILABLE_MAC(10_6);
@@ -476,9 +478,7 @@
 @property (copy) NSString *idName;
 @property (copy) NSString *lang;
 @property (copy) NSString *dir;
-@property (copy) NSString *innerHTML;
 @property (copy) NSString *innerText;
-@property (copy) NSString *outerHTML;
 @property (copy) NSString *outerText;
 @property (readonly, strong) DOMHTMLCollection *children;
 @property (copy) NSString *contentEditable;

Modified: trunk/Source/WebCore/dom/Element.cpp (176629 => 176630)


--- trunk/Source/WebCore/dom/Element.cpp	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/dom/Element.cpp	2014-12-02 10:50:11 UTC (rev 176630)
@@ -54,6 +54,7 @@
 #include "HTMLParserIdioms.h"
 #include "HTMLSelectElement.h"
 #include "HTMLTableRowsCollection.h"
+#include "HTMLTemplateElement.h"
 #include "InsertionPoint.h"
 #include "KeyboardEvent.h"
 #include "MutationObserverInterestGroup.h"
@@ -81,6 +82,7 @@
 #include "XMLNSNames.h"
 #include "XMLNames.h"
 #include "htmlediting.h"
+#include "markup.h"
 #include <wtf/BitVector.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/text/CString.h>
@@ -2022,7 +2024,68 @@
     EventDispatcher::dispatchEvent(this, event.release());
 }
 
+void Element::mergeWithNextTextNode(Text& node, ExceptionCode& ec)
+{
+    Node* next = node.nextSibling();
+    if (!is<Text>(next))
+        return;
 
+    Ref<Text> textNode(node);
+    Ref<Text> textNext(downcast<Text>(*next));
+    textNode->appendData(textNext->data(), ec);
+    if (ec)
+        return;
+    textNext->remove(ec);
+}
+
+String Element::innerHTML() const
+{
+    return createMarkup(*this, ChildrenOnly);
+}
+
+String Element::outerHTML() const
+{
+    return createMarkup(*this);
+}
+
+void Element::setOuterHTML(const String& html, ExceptionCode& ec)
+{
+    Element* p = parentElement();
+    if (!is<HTMLElement>(p)) {
+        ec = NO_MODIFICATION_ALLOWED_ERR;
+        return;
+    }
+    RefPtr<HTMLElement> parent = downcast<HTMLElement>(p);
+    RefPtr<Node> prev = previousSibling();
+    RefPtr<Node> next = nextSibling();
+
+    RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, parent.get(), AllowScriptingContent, ec);
+    if (ec)
+        return;
+    
+    parent->replaceChild(fragment.release(), this, ec);
+    RefPtr<Node> node = next ? next->previousSibling() : nullptr;
+    if (!ec && is<Text>(node.get()))
+        mergeWithNextTextNode(downcast<Text>(*node), ec);
+    if (!ec && is<Text>(prev.get()))
+        mergeWithNextTextNode(downcast<Text>(*prev), ec);
+}
+
+
+void Element::setInnerHTML(const String& html, ExceptionCode& ec)
+{
+    if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, ec)) {
+        ContainerNode* container = this;
+
+#if ENABLE(TEMPLATE_ELEMENT)
+        if (is<HTMLTemplateElement>(*this))
+            container = downcast<HTMLTemplateElement>(*this).content();
+#endif
+
+        replaceChildrenWithFragment(*container, fragment.release(), ec);
+    }
+}
+
 String Element::innerText()
 {
     // We need to update layout, since plainText uses line boxes in the render tree.

Modified: trunk/Source/WebCore/dom/Element.h (176629 => 176630)


--- trunk/Source/WebCore/dom/Element.h	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/dom/Element.h	2014-12-02 10:50:11 UTC (rev 176630)
@@ -395,6 +395,10 @@
     virtual void updateFocusAppearance(bool restorePreviousSelection);
     virtual void blur();
 
+    String innerHTML() const;
+    String outerHTML() const;
+    void setInnerHTML(const String&, ExceptionCode&);
+    void setOuterHTML(const String&, ExceptionCode&);
     WEBCORE_EXPORT String innerText();
     String outerText();
  
@@ -572,6 +576,8 @@
     // parseAttribute (called via setAttribute()) and
     // svgAttributeChanged (called when element.className.baseValue is set)
     void classAttributeChanged(const AtomicString& newClassString);
+    
+    static void mergeWithNextTextNode(Text& node, ExceptionCode& ec);
 
 private:
     bool isTextNode() const;

Modified: trunk/Source/WebCore/dom/Element.idl (176629 => 176630)


--- trunk/Source/WebCore/dom/Element.idl	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/dom/Element.idl	2014-12-02 10:50:11 UTC (rev 176630)
@@ -108,6 +108,9 @@
 
     // HTML 5
     NodeList getElementsByClassName([Default=Undefined] optional DOMString name);
+    [TreatNullAs=NullString, SetterRaisesException] attribute DOMString innerHTML;
+    [TreatNullAs=NullString, SetterRaisesException] attribute DOMString outerHTML;
+             
 
     [Reflect=class] attribute DOMString className;
     readonly attribute DOMTokenList classList;

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (176629 => 176630)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2014-12-02 10:50:11 UTC (rev 176630)
@@ -48,7 +48,6 @@
 #include "HTMLFormElement.h"
 #include "HTMLNames.h"
 #include "HTMLParserIdioms.h"
-#include "HTMLTemplateElement.h"
 #include "HTMLTextFormControlElement.h"
 #include "NodeTraversal.h"
 #include "RenderElement.h"
@@ -414,65 +413,6 @@
     }
 }
 
-String HTMLElement::innerHTML() const
-{
-    return createMarkup(*this, ChildrenOnly);
-}
-
-String HTMLElement::outerHTML() const
-{
-    return createMarkup(*this);
-}
-
-void HTMLElement::setInnerHTML(const String& html, ExceptionCode& ec)
-{
-    if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, ec)) {
-        ContainerNode* container = this;
-#if ENABLE(TEMPLATE_ELEMENT)
-        if (is<HTMLTemplateElement>(*this))
-            container = downcast<HTMLTemplateElement>(*this).content();
-#endif
-        replaceChildrenWithFragment(*container, fragment.release(), ec);
-    }
-}
-
-static void mergeWithNextTextNode(Text& node, ExceptionCode& ec)
-{
-    Node* next = node.nextSibling();
-    if (!is<Text>(next))
-        return;
-
-    Ref<Text> textNode(node);
-    Ref<Text> textNext(downcast<Text>(*next));
-    textNode->appendData(textNext->data(), ec);
-    if (ec)
-        return;
-    textNext->remove(ec);
-}
-
-void HTMLElement::setOuterHTML(const String& html, ExceptionCode& ec)
-{
-    Element* p = parentElement();
-    if (!is<HTMLElement>(p)) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return;
-    }
-    RefPtr<HTMLElement> parent = downcast<HTMLElement>(p);
-    RefPtr<Node> prev = previousSibling();
-    RefPtr<Node> next = nextSibling();
-
-    RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, parent.get(), AllowScriptingContent, ec);
-    if (ec)
-        return;
-      
-    parent->replaceChild(fragment.release(), this, ec);
-    RefPtr<Node> node = next ? next->previousSibling() : nullptr;
-    if (!ec && is<Text>(node.get()))
-        mergeWithNextTextNode(downcast<Text>(*node), ec);
-    if (!ec && is<Text>(prev.get()))
-        mergeWithNextTextNode(downcast<Text>(*prev), ec);
-}
-
 RefPtr<DocumentFragment> HTMLElement::textToFragment(const String& text, ExceptionCode& ec)
 {
     RefPtr<DocumentFragment> fragment = DocumentFragment::create(document());

Modified: trunk/Source/WebCore/html/HTMLElement.h (176629 => 176630)


--- trunk/Source/WebCore/html/HTMLElement.h	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/html/HTMLElement.h	2014-12-02 10:50:11 UTC (rev 176630)
@@ -48,10 +48,6 @@
 
     virtual short tabIndex() const override;
 
-    String innerHTML() const;
-    String outerHTML() const;
-    void setInnerHTML(const String&, ExceptionCode&);
-    void setOuterHTML(const String&, ExceptionCode&);
     void setInnerText(const String&, ExceptionCode&);
     void setOuterText(const String&, ExceptionCode&);
 

Modified: trunk/Source/WebCore/html/HTMLElement.idl (176629 => 176630)


--- trunk/Source/WebCore/html/HTMLElement.idl	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/html/HTMLElement.idl	2014-12-02 10:50:11 UTC (rev 176630)
@@ -38,11 +38,9 @@
              [Reflect] attribute DOMString accessKey;
 
     // Extensions
-             [TreatNullAs=NullString, SetterRaisesException] attribute DOMString innerHTML;
-             [TreatNullAs=NullString, SetterRaisesException] attribute DOMString innerText;
-             [TreatNullAs=NullString, SetterRaisesException] attribute DOMString outerHTML;
-             [TreatNullAs=NullString, SetterRaisesException] attribute DOMString outerText;
-
+    [TreatNullAs=NullString, SetterRaisesException] attribute DOMString innerText;
+    [TreatNullAs=NullString, SetterRaisesException] attribute DOMString outerText;
+             
     [RaisesException] Element insertAdjacentElement([Default=Undefined] optional DOMString where,
                                   [Default=Undefined] optional Element element);
     [RaisesException] void insertAdjacentHTML([Default=Undefined] optional DOMString where,

Modified: trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp (176629 => 176630)


--- trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp	2014-12-02 10:50:11 UTC (rev 176630)
@@ -320,15 +320,14 @@
 
 HTMLTreeBuilder::FragmentParsingContext::FragmentParsingContext()
     : m_fragment(0)
-    , m_contextElement(0)
 {
 }
 
 HTMLTreeBuilder::FragmentParsingContext::FragmentParsingContext(DocumentFragment& fragment, Element* contextElement)
     : m_fragment(&fragment)
-    , m_contextElement(contextElement)
 {
     ASSERT(!fragment.hasChildNodes());
+    m_contextElementStackItem = HTMLStackItem::create(contextElement, HTMLStackItem::ItemForContextElement);
 }
 
 HTMLTreeBuilder::FragmentParsingContext::~FragmentParsingContext()
@@ -356,7 +355,7 @@
 
     if (m_parser.tokenizer()) {
         bool inForeignContent = !m_tree.isEmpty()
-            && !m_tree.currentStackItem()->isInHTMLNamespace()
+            && !adjustedCurrentStackItem()->isInHTMLNamespace()
             && !HTMLElementStack::isHTMLIntegrationPoint(m_tree.currentStackItem())
             && !HTMLElementStack::isMathMLTextIntegrationPoint(m_tree.currentStackItem());
 
@@ -1617,7 +1616,7 @@
             bool shouldCreateItem = true;
 #endif
             if (shouldCreateItem)
-                item = HTMLStackItem::create(m_fragmentContext.contextElement(), HTMLStackItem::ItemForContextElement);
+                item = m_fragmentContext.contextElementStackItem();
         }
 #if ENABLE(TEMPLATE_ELEMENT)
         if (item->hasTagName(templateTag))
@@ -2840,16 +2839,27 @@
 
     setInsertionMode(InsertionMode::Text);
 }
+    
+// http://www.whatwg.org/specs/web-apps/current-work/#adjusted-current-node
+HTMLStackItem* HTMLTreeBuilder::adjustedCurrentStackItem() const
+{
+    ASSERT(!m_tree.isEmpty());
+    if (isParsingFragment() && m_tree.openElements()->hasOnlyOneElement())
+        return m_fragmentContext.contextElementStackItem();
+        
+    return m_tree.currentStackItem();
+}
 
+
 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#tree-construction
 bool HTMLTreeBuilder::shouldProcessTokenInForeignContent(AtomicHTMLToken* token)
 {
     if (m_tree.isEmpty())
         return false;
-    HTMLStackItem* item = m_tree.currentStackItem();
-    if (item->isInHTMLNamespace())
+    HTMLStackItem* adjustedCurrentNode = adjustedCurrentStackItem();
+    if (adjustedCurrentNode->isInHTMLNamespace())
         return false;
-    if (HTMLElementStack::isMathMLTextIntegrationPoint(item)) {
+    if (HTMLElementStack::isMathMLTextIntegrationPoint(adjustedCurrentNode)) {
         if (token->type() == HTMLToken::StartTag
             && token->name() != MathMLNames::mglyphTag
             && token->name() != MathMLNames::malignmarkTag)
@@ -2857,11 +2867,11 @@
         if (token->type() == HTMLToken::Character)
             return false;
     }
-    if (item->hasTagName(MathMLNames::annotation_xmlTag)
+    if (adjustedCurrentNode->hasTagName(MathMLNames::annotation_xmlTag)
         && token->type() == HTMLToken::StartTag
         && token->name() == SVGNames::svgTag)
         return false;
-    if (HTMLElementStack::isHTMLIntegrationPoint(item)) {
+    if (HTMLElementStack::isHTMLIntegrationPoint(adjustedCurrentNode)) {
         if (token->type() == HTMLToken::StartTag)
             return false;
         if (token->type() == HTMLToken::Character)
@@ -2874,6 +2884,8 @@
 
 void HTMLTreeBuilder::processTokenInForeignContent(AtomicHTMLToken* token)
 {
+    HTMLStackItem* adjustedCurrentNode = adjustedCurrentStackItem();
+    
     switch (token->type()) {
     case HTMLToken::Uninitialized:
         ASSERT_NOT_REACHED();
@@ -2927,7 +2939,7 @@
             processStartTag(token);
             return;
         }
-        const AtomicString& currentNamespace = m_tree.currentStackItem()->namespaceURI();
+        const AtomicString& currentNamespace = adjustedCurrentNode->namespaceURI();
         if (currentNamespace == MathMLNames::mathmlNamespaceURI)
             adjustMathMLAttributes(*token);
         if (currentNamespace == SVGNames::svgNamespaceURI) {
@@ -2939,7 +2951,7 @@
         break;
     }
     case HTMLToken::EndTag: {
-        if (m_tree.currentStackItem()->namespaceURI() == SVGNames::svgNamespaceURI)
+        if (adjustedCurrentNode->namespaceURI() == SVGNames::svgNamespaceURI)
             adjustSVGTagNameCase(*token);
 
         if (token->name() == SVGNames::scriptTag && m_tree.currentStackItem()->hasTagName(SVGNames::scriptTag)) {

Modified: trunk/Source/WebCore/html/parser/HTMLTreeBuilder.h (176629 => 176630)


--- trunk/Source/WebCore/html/parser/HTMLTreeBuilder.h	2014-12-02 10:36:47 UTC (rev 176629)
+++ trunk/Source/WebCore/html/parser/HTMLTreeBuilder.h	2014-12-02 10:50:11 UTC (rev 176630)
@@ -32,6 +32,7 @@
 #include "HTMLElementStack.h"
 #include "HTMLFormattingElementList.h"
 #include "HTMLParserOptions.h"
+#include "HTMLStackItem.h"
 #include "HTMLTokenizer.h"
 #include <wtf/Noncopyable.h>
 #include <wtf/PassRefPtr.h>
@@ -170,6 +171,8 @@
 
     inline bool shouldProcessTokenInForeignContent(AtomicHTMLToken*);
     void processTokenInForeignContent(AtomicHTMLToken*);
+    
+    inline HTMLStackItem* adjustedCurrentStackItem() const;
 
     Vector<Attribute> attributesForIsindexInput(AtomicHTMLToken*);
 
@@ -201,11 +204,12 @@
         ~FragmentParsingContext();
 
         DocumentFragment* fragment() const { return m_fragment; }
-        Element* contextElement() const { ASSERT(m_fragment); return m_contextElement; }
+        Element* contextElement() const { ASSERT(m_fragment); return m_contextElementStackItem->element(); }
+        HTMLStackItem* contextElementStackItem() const { ASSERT(m_fragment); return m_contextElementStackItem.get(); }
 
     private:
         DocumentFragment* m_fragment;
-        Element* m_contextElement;
+        RefPtr<HTMLStackItem> m_contextElementStackItem;
     };
 
     bool m_framesetOk;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to