Diff
Modified: trunk/Source/WebCore/ChangeLog (94515 => 94516)
--- trunk/Source/WebCore/ChangeLog 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebCore/ChangeLog 2011-09-05 07:46:55 UTC (rev 94516)
@@ -1,3 +1,27 @@
+2011-09-05 Kaustubh Atrawalkar <[email protected]>
+
+ Logic from HTMLElement::deprecatedCreateContextualFragment moved into
+ Range::createContextualFragment function.
+ https://bugs.webkit.org/show_bug.cgi?id=67056
+
+ Reviewed by Ryosuke Niwa.
+
+ Code Refactoring for deprecatedCreateContextualFragment.
+
+ No new tests. Code Re-factoring.
+
+ * dom/Element.cpp:
+ * dom/Element.h:
+ * dom/Range.cpp:
+ (WebCore::insertIntoFragment):
+ (WebCore::Range::createDocumentFragmentForElement):
+ (WebCore::Range::createContextualFragment):
+ * dom/Range.h:
+ * editing/markup.cpp:
+ (WebCore::createFragmentFromMarkup):
+ * html/HTMLElement.cpp:
+ * html/HTMLElement.h:
+
2011-09-04 James Kozianski <[email protected]>
Unreviewed, rolling out r94510.
Modified: trunk/Source/WebCore/dom/Element.cpp (94515 => 94516)
--- trunk/Source/WebCore/dom/Element.cpp 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebCore/dom/Element.cpp 2011-09-05 07:46:55 UTC (rev 94516)
@@ -141,48 +141,6 @@
DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, focus);
DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, load);
-PassRefPtr<DocumentFragment> Element::deprecatedCreateContextualFragment(const String& markup, FragmentScriptingPermission scriptingPermission)
-{
- RefPtr<DocumentFragment> fragment = document()->createDocumentFragment();
-
- if (document()->isHTMLDocument())
- fragment->parseHTML(markup, this, scriptingPermission);
- else {
- if (!fragment->parseXML(markup, this, scriptingPermission))
- // FIXME: We should propagate a syntax error exception out here.
- return 0;
- }
-
- // 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(headTag) || node->hasTagName(bodyTag)) {
- HTMLElement* element = toHTMLElement(node.get());
- Node* firstChild = element->firstChild();
- if (firstChild)
- nextNode = firstChild;
- RefPtr<Node> nextChild;
- for (RefPtr<Node> child = firstChild; child; child = nextChild) {
- nextChild = child->nextSibling();
- element->removeChild(child.get(), ignoredExceptionCode);
- ASSERT(!ignoredExceptionCode);
- fragment->insertBefore(child, element, ignoredExceptionCode);
- ASSERT(!ignoredExceptionCode);
- }
- fragment->removeChild(element, ignoredExceptionCode);
- ASSERT(!ignoredExceptionCode);
- }
- }
- return fragment.release();
-}
-
PassRefPtr<Node> Element::cloneNode(bool deep)
{
return deep ? cloneElementWithChildren() : cloneElementWithoutChildren();
Modified: trunk/Source/WebCore/dom/Element.h (94515 => 94516)
--- trunk/Source/WebCore/dom/Element.h 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebCore/dom/Element.h 2011-09-05 07:46:55 UTC (rev 94516)
@@ -108,8 +108,6 @@
DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange);
#endif
- virtual PassRefPtr<DocumentFragment> deprecatedCreateContextualFragment(const String&, FragmentScriptingPermission = FragmentScriptingAllowed);
-
bool hasAttribute(const QualifiedName&) const;
const AtomicString& getAttribute(const QualifiedName&) const;
void setAttribute(const QualifiedName&, const AtomicString& value, ExceptionCode&);
Modified: trunk/Source/WebCore/dom/Range.cpp (94515 => 94516)
--- trunk/Source/WebCore/dom/Range.cpp 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebCore/dom/Range.cpp 2011-09-05 07:46:55 UTC (rev 94516)
@@ -4,6 +4,7 @@
* (C) 2000 Frederik Holljen ([email protected])
* (C) 2001 Peter Kelly ([email protected])
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Motorola Mobility. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -32,6 +33,8 @@
#include "Frame.h"
#include "FrameView.h"
#include "HTMLElement.h"
+#include "HTMLNames.h"
+#include "Node.h"
#include "NodeWithIndex.h"
#include "Page.h"
#include "ProcessingInstruction.h"
@@ -53,6 +56,7 @@
namespace WebCore {
using namespace std;
+using namespace HTMLNames;
#ifndef NDEBUG
static WTF::RefCountedLeakCounter rangeCounter("Range");
@@ -1100,8 +1104,59 @@
return plainText(this);
}
-PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& markup, ExceptionCode& ec) const
+static inline void removeElementPreservingChildren(PassRefPtr<DocumentFragment> fragment, HTMLElement* element)
{
+ ExceptionCode ignoredExceptionCode;
+
+ RefPtr<Node> nextChild;
+ for (RefPtr<Node> child = element->firstChild(); child; child = nextChild) {
+ nextChild = child->nextSibling();
+ element->removeChild(child.get(), ignoredExceptionCode);
+ ASSERT(!ignoredExceptionCode);
+ fragment->insertBefore(child, element, ignoredExceptionCode);
+ ASSERT(!ignoredExceptionCode);
+ }
+ fragment->removeChild(element, ignoredExceptionCode);
+ ASSERT(!ignoredExceptionCode);
+}
+
+PassRefPtr<DocumentFragment> Range::createDocumentFragmentForElement(const String& markup, Element* element, FragmentScriptingPermission scriptingPermission)
+{
+ ASSERT(element);
+ HTMLElement* htmlElement = toHTMLElement(element);
+ if (htmlElement->ieForbidsInsertHTML())
+ return 0;
+
+ if (htmlElement->hasLocalName(colTag) || htmlElement->hasLocalName(colgroupTag) || htmlElement->hasLocalName(framesetTag)
+ || htmlElement->hasLocalName(headTag) || htmlElement->hasLocalName(styleTag) || htmlElement->hasLocalName(titleTag))
+ return 0;
+
+ RefPtr<DocumentFragment> fragment = element->document()->createDocumentFragment();
+
+ if (element->document()->isHTMLDocument())
+ fragment->parseHTML(markup, element, scriptingPermission);
+ else if (!fragment->parseXML(markup, element, scriptingPermission))
+ return 0; // FIXME: We should propagate a syntax error exception out here.
+
+ // 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(headTag) || node->hasTagName(bodyTag)) {
+ HTMLElement* element = toHTMLElement(node.get());
+ if (Node* firstChild = element->firstChild())
+ nextNode = firstChild;
+ removeElementPreservingChildren(fragment, element);
+ }
+ }
+ return fragment.release();
+}
+
+PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& markup, ExceptionCode& ec, FragmentScriptingPermission scriptingPermission)
+{
if (!m_start.container()) {
ec = INVALID_STATE_ERR;
return 0;
@@ -1113,10 +1168,8 @@
return 0;
}
- // 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 = toHTMLElement(element)->deprecatedCreateContextualFragment(markup);
+ RefPtr<DocumentFragment> fragment = createDocumentFragmentForElement(markup, toElement(element), scriptingPermission);
+
if (!fragment) {
ec = NOT_SUPPORTED_ERR;
return 0;
Modified: trunk/Source/WebCore/dom/Range.h (94515 => 94516)
--- trunk/Source/WebCore/dom/Range.h 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebCore/dom/Range.h 2011-09-05 07:46:55 UTC (rev 94516)
@@ -27,6 +27,7 @@
#include "ExceptionCodePlaceholder.h"
#include "FloatRect.h"
+#include "FragmentScriptingPermission.h"
#include "IntRect.h"
#include "Node.h"
#include "RangeBoundaryPoint.h"
@@ -88,7 +89,8 @@
String toHTML() const;
String text() const;
- PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionCode&) const;
+ PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionCode&, FragmentScriptingPermission = FragmentScriptingAllowed);
+ static PassRefPtr<DocumentFragment> createDocumentFragmentForElement(const String& markup, Element*, FragmentScriptingPermission = FragmentScriptingAllowed);
void detach(ExceptionCode&);
PassRefPtr<Range> cloneRange(ExceptionCode&) const;
Modified: trunk/Source/WebCore/editing/markup.cpp (94515 => 94516)
--- trunk/Source/WebCore/editing/markup.cpp 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebCore/editing/markup.cpp 2011-09-05 07:46:55 UTC (rev 94516)
@@ -2,6 +2,7 @@
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
* Copyright (C) 2008, 2009 Google Inc.
* Copyright (C) 2011 Igalia S.L.
+ * Copyright (C) 2011 Motorola Mobility. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -682,12 +683,9 @@
PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document* document, const String& markup, const String& baseURL, FragmentScriptingPermission scriptingPermission)
{
- // We use a fake body element here to trick the HTML parser to using the
- // InBody insertion mode. Really, all this code is wrong and need to be
- // changed not to use deprecatedCreateContextualFragment.
+ // We use a fake body element here to trick the HTML parser to using the InBody insertion mode.
RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(document);
- // FIXME: This should not use deprecatedCreateContextualFragment
- RefPtr<DocumentFragment> fragment = fakeBody->deprecatedCreateContextualFragment(markup, scriptingPermission);
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, fakeBody.get(), scriptingPermission);
if (fragment && !baseURL.isEmpty() && baseURL != blankURL() && baseURL != document->baseURL())
completeURLs(fragment.get(), baseURL);
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (94515 => 94516)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2011-09-05 07:46:55 UTC (rev 94516)
@@ -300,20 +300,6 @@
return createMarkup(this);
}
-// 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 (ieForbidsInsertHTML())
- return 0;
-
- if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(framesetTag)
- || hasLocalName(headTag) || hasLocalName(styleTag) || hasLocalName(titleTag))
- return 0;
-
- return Element::deprecatedCreateContextualFragment(markup, scriptingPermission);
-}
-
static inline bool hasOneChild(ContainerNode* node)
{
Node* firstChild = node->firstChild();
Modified: trunk/Source/WebCore/html/HTMLElement.h (94515 => 94516)
--- trunk/Source/WebCore/html/HTMLElement.h 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebCore/html/HTMLElement.h 2011-09-05 07:46:55 UTC (rev 94516)
@@ -44,8 +44,6 @@
String innerHTML() const;
String outerHTML() const;
- // 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&);
Modified: trunk/Source/WebKit/qt/Api/qwebelement.cpp (94515 => 94516)
--- trunk/Source/WebKit/qt/Api/qwebelement.cpp 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebKit/qt/Api/qwebelement.cpp 2011-09-05 07:46:55 UTC (rev 94516)
@@ -1022,8 +1022,7 @@
if (!m_element->isHTMLElement())
return;
- HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
- RefPtr<DocumentFragment> fragment = htmlElement->Element::deprecatedCreateContextualFragment(markup);
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element));
ExceptionCode exception = 0;
m_element->appendChild(fragment, exception);
@@ -1068,8 +1067,7 @@
if (!m_element->isHTMLElement())
return;
- HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
- RefPtr<DocumentFragment> fragment = htmlElement->deprecatedCreateContextualFragment(markup);
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element));
ExceptionCode exception = 0;
@@ -1120,8 +1118,7 @@
if (!m_element->isHTMLElement())
return;
- HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
- RefPtr<DocumentFragment> fragment = htmlElement->deprecatedCreateContextualFragment(markup);
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element));
ExceptionCode exception = 0;
m_element->parentNode()->insertBefore(fragment, m_element, exception);
@@ -1170,8 +1167,7 @@
if (!m_element->isHTMLElement())
return;
- HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
- RefPtr<DocumentFragment> fragment = htmlElement->deprecatedCreateContextualFragment(markup);
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element));
ExceptionCode exception = 0;
if (!m_element->nextSibling())
@@ -1317,8 +1313,7 @@
if (!m_element->isHTMLElement())
return;
- HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
- RefPtr<DocumentFragment> fragment = htmlElement->deprecatedCreateContextualFragment(markup);
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element));
if (!fragment || !fragment->firstChild())
return;
@@ -1392,8 +1387,7 @@
if (!m_element->isHTMLElement())
return;
- HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
- RefPtr<DocumentFragment> fragment = htmlElement->deprecatedCreateContextualFragment(markup);
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element));
if (!fragment || !fragment->firstChild())
return;
Modified: trunk/Source/WebKit/qt/ChangeLog (94515 => 94516)
--- trunk/Source/WebKit/qt/ChangeLog 2011-09-05 07:38:20 UTC (rev 94515)
+++ trunk/Source/WebKit/qt/ChangeLog 2011-09-05 07:46:55 UTC (rev 94516)
@@ -1,3 +1,21 @@
+2011-09-05 Kaustubh Atrawalkar <[email protected]>
+
+ Logic from HTMLElement::deprecatedCreateContextualFragment moved into
+ Range::createContextualFragment function.
+ https://bugs.webkit.org/show_bug.cgi?id=67056
+
+ Reviewed by Ryosuke Niwa.
+
+ Code Refactoring for deprecatedCreateContextualFragment.
+
+ * Api/qwebelement.cpp:
+ (QWebElement::appendInside):
+ (QWebElement::prependInside):
+ (QWebElement::prependOutside):
+ (QWebElement::appendOutside):
+ (QWebElement::encloseContentsWith):
+ (QWebElement::encloseWith):
+
2011-09-03 Laszlo Gombos <[email protected]>
REGRESSION (r86268): Fix for qt_networkAccessAllowed()