[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

eric at webkit.org eric at webkit.org
Wed Dec 22 12:06:59 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 5debb0f95c5404b4efc0f0ec0e52b0db5f33015b
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sat Aug 14 21:38:50 2010 +0000

    2010-08-14  Eric Seidel  <eric at webkit.org>
    
            Reviewed by Adam Barth.
    
            Move innerHTML off of Range::createContextualFragment
            https://bugs.webkit.org/show_bug.cgi?id=44011
    
            This makes all the editing tests stop failing under the
            HTML5 TreeBuilder.
    
            In a previous patch Adam disabled some of the (wrong) code
            in createContextualFragment when in html5 treebuilder mode.
            The problem is that the editing code depends on
            createContextualFragment (as well as the Range DOM API),
            so we have to leave this code in until we can figure
            out if it's right or wrong behavior for the Range API.
    
            This patch moves innerHTML/outerHTML off of using
            createContextualFragment and instead calls
            DocumentFragment::parseHTML directly (which is much simpler).
    
            I expect Adam and I will end up turning on the HTML5 TreeBuilder
            in the next couple days, and most of the if branches I added
            here will go away for good.
    
            I renamed Element::createContextualFragment to
            deprecatedCreateContextualFragment, to indicate that it's a
            dead API.  The editing code should move off of it and consider
            using DocumentFragment::parseHTML instead.
    
            * dom/Element.cpp:
            (WebCore::Element::deprecatedCreateContextualFragment):
            * dom/Element.h:
            * dom/Range.cpp:
            (WebCore::Range::createContextualFragment):
            * editing/markup.cpp:
            (WebCore::createFragmentFromMarkup):
            * html/HTMLElement.cpp:
            (WebCore::useLegacyTreeBuilder):
            (WebCore::HTMLElement::deprecatedCreateContextualFragment):
            (WebCore::HTMLElement::setInnerHTML):
            (WebCore::HTMLElement::setOuterHTML):
            * html/HTMLElement.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65372 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 9742a8f..ee15799 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,47 @@
+2010-08-14  Eric Seidel  <eric at webkit.org>
+
+        Reviewed by Adam Barth.
+
+        Move innerHTML off of Range::createContextualFragment
+        https://bugs.webkit.org/show_bug.cgi?id=44011
+
+        This makes all the editing tests stop failing under the
+        HTML5 TreeBuilder.
+
+        In a previous patch Adam disabled some of the (wrong) code
+        in createContextualFragment when in html5 treebuilder mode.
+        The problem is that the editing code depends on
+        createContextualFragment (as well as the Range DOM API),
+        so we have to leave this code in until we can figure
+        out if it's right or wrong behavior for the Range API.
+
+        This patch moves innerHTML/outerHTML off of using
+        createContextualFragment and instead calls
+        DocumentFragment::parseHTML directly (which is much simpler).
+
+        I expect Adam and I will end up turning on the HTML5 TreeBuilder
+        in the next couple days, and most of the if branches I added
+        here will go away for good.
+
+        I renamed Element::createContextualFragment to
+        deprecatedCreateContextualFragment, to indicate that it's a
+        dead API.  The editing code should move off of it and consider
+        using DocumentFragment::parseHTML instead.
+
+        * dom/Element.cpp:
+        (WebCore::Element::deprecatedCreateContextualFragment):
+        * dom/Element.h:
+        * dom/Range.cpp:
+        (WebCore::Range::createContextualFragment):
+        * editing/markup.cpp:
+        (WebCore::createFragmentFromMarkup):
+        * html/HTMLElement.cpp:
+        (WebCore::useLegacyTreeBuilder):
+        (WebCore::HTMLElement::deprecatedCreateContextualFragment):
+        (WebCore::HTMLElement::setInnerHTML):
+        (WebCore::HTMLElement::setOuterHTML):
+        * html/HTMLElement.h:
+
 2010-08-14  Tasuku Suzuki  <tasuku.suzuki at nokia.com>
 
         Reviewed by Antonio Gomes.
diff --git a/WebCore/dom/Element.cpp b/WebCore/dom/Element.cpp
index cc3bf1f..849b900 100644
--- a/WebCore/dom/Element.cpp
+++ b/WebCore/dom/Element.cpp
@@ -91,7 +91,7 @@ NodeRareData* Element::createRareData()
     return new ElementRareData;
 }
 
-PassRefPtr<DocumentFragment> Element::createContextualFragment(const String& markup, FragmentScriptingPermission scriptingPermission)
+PassRefPtr<DocumentFragment> Element::deprecatedCreateContextualFragment(const String& markup, FragmentScriptingPermission scriptingPermission)
 {
     RefPtr<DocumentFragment> fragment = document()->createDocumentFragment();
 
@@ -102,36 +102,34 @@ PassRefPtr<DocumentFragment> Element::createContextualFragment(const String& mar
             // FIXME: We should propagate a syntax error exception out here.
             return 0;
     }
-    
-    if (!document()->settings() || !document()->settings()->html5TreeBuilderEnabled()) {
-        // Exceptions are ignored because none ought to happen here.
-        ExceptionCode ignoredExceptionCode;
-        
-        // We need to pop <html> and <body> elements and remove <head> to
-        // accommodate folks passing complete HTML documents to make the
-        // child of an element.
-        
-        RefPtr<Node> nextNode;
-        for (RefPtr<Node> node = fragment->firstChild(); node; node = nextNode) {
-            nextNode = node->nextSibling();
-            if (node->hasTagName(htmlTag) || node->hasTagName(bodyTag)) {
-                Node* firstChild = node->firstChild();
-                if (firstChild)
-                    nextNode = firstChild;
-                RefPtr<Node> nextChild;
-                for (RefPtr<Node> child = firstChild; child; child = nextChild) {
-                    nextChild = child->nextSibling();
-                    node->removeChild(child.get(), ignoredExceptionCode);
-                    ASSERT(!ignoredExceptionCode);
-                    fragment->insertBefore(child, node.get(), ignoredExceptionCode);
-                    ASSERT(!ignoredExceptionCode);
-                }
-                fragment->removeChild(node.get(), ignoredExceptionCode);
+
+    // Exceptions are ignored because none ought to happen here.
+    ExceptionCode ignoredExceptionCode;
+
+    // We need to pop <html> and <body> elements and remove <head> to
+    // accommodate folks passing complete HTML documents to make the
+    // child of an element.
+
+    RefPtr<Node> nextNode;
+    for (RefPtr<Node> node = fragment->firstChild(); node; node = nextNode) {
+        nextNode = node->nextSibling();
+        if (node->hasTagName(htmlTag) || node->hasTagName(bodyTag)) {
+            Node* firstChild = node->firstChild();
+            if (firstChild)
+                nextNode = firstChild;
+            RefPtr<Node> nextChild;
+            for (RefPtr<Node> child = firstChild; child; child = nextChild) {
+                nextChild = child->nextSibling();
+                node->removeChild(child.get(), ignoredExceptionCode);
                 ASSERT(!ignoredExceptionCode);
-            } else if (node->hasTagName(headTag)) {
-                fragment->removeChild(node.get(), ignoredExceptionCode);
+                fragment->insertBefore(child, node.get(), ignoredExceptionCode);
                 ASSERT(!ignoredExceptionCode);
             }
+            fragment->removeChild(node.get(), ignoredExceptionCode);
+            ASSERT(!ignoredExceptionCode);
+        } else if (node->hasTagName(headTag)) {
+            fragment->removeChild(node.get(), ignoredExceptionCode);
+            ASSERT(!ignoredExceptionCode);
         }
     }
     return fragment.release();
diff --git a/WebCore/dom/Element.h b/WebCore/dom/Element.h
index a66809a..694db98 100644
--- a/WebCore/dom/Element.h
+++ b/WebCore/dom/Element.h
@@ -95,7 +95,7 @@ public:
     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
 #endif
 
-    virtual PassRefPtr<DocumentFragment> createContextualFragment(const String&, FragmentScriptingPermission = FragmentScriptingAllowed);
+    virtual PassRefPtr<DocumentFragment> deprecatedCreateContextualFragment(const String&, FragmentScriptingPermission = FragmentScriptingAllowed);
 
     bool hasAttribute(const QualifiedName&) const;
     const AtomicString& getAttribute(const QualifiedName&) const;
diff --git a/WebCore/dom/Range.cpp b/WebCore/dom/Range.cpp
index 33a21bb..d93a58e 100644
--- a/WebCore/dom/Range.cpp
+++ b/WebCore/dom/Range.cpp
@@ -1061,7 +1061,10 @@ PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& marku
         return 0;
     }
 
-    RefPtr<DocumentFragment> fragment = static_cast<HTMLElement*>(element)->createContextualFragment(markup);
+    // Logic from deprecatedCreateContextualFragment should just be moved into
+    // this function.  Range::createContextualFragment semantics do not make
+    // sense for the rest of the DOM implementation to use.
+    RefPtr<DocumentFragment> fragment = static_cast<HTMLElement*>(element)->deprecatedCreateContextualFragment(markup);
     if (!fragment) {
         ec = NOT_SUPPORTED_ERR;
         return 0;
diff --git a/WebCore/editing/markup.cpp b/WebCore/editing/markup.cpp
index 8f82298..f9eeb38 100644
--- a/WebCore/editing/markup.cpp
+++ b/WebCore/editing/markup.cpp
@@ -1043,7 +1043,8 @@ String createMarkup(const Range* range, Vector<Node*>* nodes, EAnnotateForInterc
 
 PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document* document, const String& markup, const String& baseURL, FragmentScriptingPermission scriptingPermission)
 {
-    RefPtr<DocumentFragment> fragment = document->documentElement()->createContextualFragment(markup, scriptingPermission);
+    // FIXME: This should not use deprecatedCreateContextualFragment
+    RefPtr<DocumentFragment> fragment = document->documentElement()->deprecatedCreateContextualFragment(markup, scriptingPermission);
 
     if (fragment && !baseURL.isEmpty() && baseURL != blankURL() && baseURL != document->baseURL())
         completeURLs(fragment.get(), baseURL);
diff --git a/WebCore/html/HTMLElement.cpp b/WebCore/html/HTMLElement.cpp
index b7d45de..ff25e62 100644
--- a/WebCore/html/HTMLElement.cpp
+++ b/WebCore/html/HTMLElement.cpp
@@ -275,20 +275,23 @@ String HTMLElement::outerHTML() const
     return createMarkup(this);
 }
 
-// FIXME: This method is unnecessary with the new HTMLDocumentParser.
-PassRefPtr<DocumentFragment> HTMLElement::createContextualFragment(const String& markup, FragmentScriptingPermission scriptingPermission)
+static bool useLegacyTreeBuilder(Document* document)
 {
-    if (!document()->settings() || !document()->settings()->html5TreeBuilderEnabled()) {
-        // The following is in accordance with the definition as used by IE.
-        if (endTagRequirement() == TagStatusForbidden)
-            return 0;
+    return !document || !document->settings() || !document->settings()->html5TreeBuilderEnabled();
+}
 
-        if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(framesetTag)
-            || hasLocalName(headTag) || hasLocalName(styleTag) || hasLocalName(titleTag))
-            return 0;
-    }
+// FIXME: This logic should move into Range::createContextualFragment
+PassRefPtr<DocumentFragment> HTMLElement::deprecatedCreateContextualFragment(const String& markup, FragmentScriptingPermission scriptingPermission)
+{
+    // The following is in accordance with the definition as used by IE.
+    if (endTagRequirement() == TagStatusForbidden)
+        return 0;
+
+    if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(framesetTag)
+        || hasLocalName(headTag) || hasLocalName(styleTag) || hasLocalName(titleTag))
+        return 0;
 
-    return Element::createContextualFragment(markup, scriptingPermission);
+    return Element::deprecatedCreateContextualFragment(markup, scriptingPermission);
 }
 
 static inline bool hasOneChild(ContainerNode* node)
@@ -341,23 +344,46 @@ static void replaceChildrenWithText(HTMLElement* element, const String& text, Ex
     element->appendChild(textNode.release(), ec);
 }
 
+// We may want to move a version of this function into DocumentFragment.h/cpp
+static PassRefPtr<DocumentFragment> createFragmentFromSource(const String& markup, Element* contextElement, ExceptionCode& ec)
+{
+    Document* document = contextElement->document();
+    RefPtr<DocumentFragment> fragment;
+
+    if (useLegacyTreeBuilder(document)) {
+        fragment = contextElement->deprecatedCreateContextualFragment(markup);
+        if (!fragment)
+            ec = NO_MODIFICATION_ALLOWED_ERR;
+        return fragment;
+    }
+
+    fragment = DocumentFragment::create(document);
+    if (document->isHTMLDocument()) {
+        fragment->parseHTML(markup, contextElement);
+        return fragment;
+    }
+
+    bool wasValid = fragment->parseXML(markup, contextElement);
+    if (!wasValid) {
+        ec = INVALID_STATE_ERR;
+        return 0;
+    }
+    return fragment;
+}
+
 void HTMLElement::setInnerHTML(const String& html, ExceptionCode& ec)
 {
     // FIXME: This code can be removed, it's handled by the HTMLDocumentParser correctly.
-    if (hasLocalName(scriptTag) || hasLocalName(styleTag)) {
+    if (useLegacyTreeBuilder(document()) && (hasLocalName(scriptTag) || hasLocalName(styleTag))) {
         // Script and CSS source shouldn't be parsed as HTML.
         removeChildren();
         appendChild(document()->createTextNode(html), ec);
         return;
     }
 
-    RefPtr<DocumentFragment> fragment = createContextualFragment(html);
-    if (!fragment) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return;
-    }
-
-    replaceChildrenWithFragment(this, fragment.release(), ec);
+    RefPtr<DocumentFragment> fragment = createFragmentFromSource(html, this, ec);
+    if (fragment)
+        replaceChildrenWithFragment(this, fragment.release(), ec);
 }
 
 void HTMLElement::setOuterHTML(const String& html, ExceptionCode& ec)
@@ -367,17 +393,13 @@ void HTMLElement::setOuterHTML(const String& html, ExceptionCode& ec)
         ec = NO_MODIFICATION_ALLOWED_ERR;
         return;
     }
-
     HTMLElement* parent = static_cast<HTMLElement*>(p);
-    RefPtr<DocumentFragment> fragment = parent->createContextualFragment(html);
-    if (!fragment) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return;
-    }
-
-    // FIXME: Why doesn't this have code to merge neighboring text nodes the way setOuterText does?
 
-    parent->replaceChild(fragment.release(), this, ec);
+    RefPtr<DocumentFragment> fragment = createFragmentFromSource(html, parent, ec);
+    if (fragment) {
+        // FIXME: Why doesn't this have code to merge neighboring text nodes the way setOuterText does?
+        parent->replaceChild(fragment.release(), this, ec);
+    }
 }
 
 void HTMLElement::setInnerText(const String& text, ExceptionCode& ec)
diff --git a/WebCore/html/HTMLElement.h b/WebCore/html/HTMLElement.h
index 03449c9..8f54d3e 100644
--- a/WebCore/html/HTMLElement.h
+++ b/WebCore/html/HTMLElement.h
@@ -46,7 +46,8 @@ public:
 
     String innerHTML() const;
     String outerHTML() const;
-    PassRefPtr<DocumentFragment> createContextualFragment(const String&, FragmentScriptingPermission = FragmentScriptingAllowed);
+    // deprecatedCreateContextualFragment logic should be moved into Range::createContextualFragment
+    PassRefPtr<DocumentFragment> deprecatedCreateContextualFragment(const String&, FragmentScriptingPermission = FragmentScriptingAllowed);
     void setInnerHTML(const String&, ExceptionCode&);
     void setOuterHTML(const String&, ExceptionCode&);
     void setInnerText(const String&, ExceptionCode&);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list