summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/DocumentFragment.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/DocumentFragment.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/dom/DocumentFragment.cpp')
-rw-r--r--Source/WebCore/dom/DocumentFragment.cpp53
1 files changed, 36 insertions, 17 deletions
diff --git a/Source/WebCore/dom/DocumentFragment.cpp b/Source/WebCore/dom/DocumentFragment.cpp
index b11af5ddb..5c9351d3e 100644
--- a/Source/WebCore/dom/DocumentFragment.cpp
+++ b/Source/WebCore/dom/DocumentFragment.cpp
@@ -24,31 +24,26 @@
#include "DocumentFragment.h"
#include "Document.h"
+#include "ElementDescendantIterator.h"
#include "HTMLDocumentParser.h"
#include "Page.h"
-#include "Settings.h"
#include "XMLDocumentParser.h"
namespace WebCore {
-DocumentFragment::DocumentFragment(Document* document, ConstructionType constructionType)
+DocumentFragment::DocumentFragment(Document& document, ConstructionType constructionType)
: ContainerNode(document, constructionType)
{
}
-PassRefPtr<DocumentFragment> DocumentFragment::create(Document& document)
+Ref<DocumentFragment> DocumentFragment::create(Document& document)
{
- return adoptRef(new DocumentFragment(&document, Node::CreateDocumentFragment));
-}
-
-PassRefPtr<DocumentFragment> DocumentFragment::create(ScriptExecutionContext& context)
-{
- return adoptRef(new DocumentFragment(&toDocument(context), Node::CreateDocumentFragment));
+ return adoptRef(*new DocumentFragment(document, Node::CreateDocumentFragment));
}
String DocumentFragment::nodeName() const
{
- return "#document-fragment";
+ return ASCIILiteral("#document-fragment");
}
Node::NodeType DocumentFragment::nodeType() const
@@ -64,24 +59,30 @@ bool DocumentFragment::childTypeAllowed(NodeType type) const
case COMMENT_NODE:
case TEXT_NODE:
case CDATA_SECTION_NODE:
- case ENTITY_REFERENCE_NODE:
return true;
default:
return false;
}
}
-PassRefPtr<Node> DocumentFragment::cloneNode(bool deep)
+Ref<Node> DocumentFragment::cloneNodeInternal(Document& targetDocument, CloningOperation type)
{
- RefPtr<DocumentFragment> clone = create(document());
- if (deep)
- cloneChildNodes(clone.get());
- return clone.release();
+ Ref<DocumentFragment> clone = create(targetDocument);
+ switch (type) {
+ case CloningOperation::OnlySelf:
+ case CloningOperation::SelfWithTemplateContent:
+ break;
+ case CloningOperation::Everything:
+ cloneChildNodes(clone);
+ break;
+ }
+ return WTFMove(clone);
}
void DocumentFragment::parseHTML(const String& source, Element* contextElement, ParserContentPolicy parserContentPolicy)
{
- HTMLDocumentParser::parseDocumentFragment(source, *this, contextElement, parserContentPolicy);
+ ASSERT(contextElement);
+ HTMLDocumentParser::parseDocumentFragment(source, *this, *contextElement, parserContentPolicy);
}
bool DocumentFragment::parseXML(const String& source, Element* contextElement, ParserContentPolicy parserContentPolicy)
@@ -89,4 +90,22 @@ bool DocumentFragment::parseXML(const String& source, Element* contextElement, P
return XMLDocumentParser::parseDocumentFragment(source, *this, contextElement, parserContentPolicy);
}
+Element* DocumentFragment::getElementById(const AtomicString& id) const
+{
+ if (id.isNull())
+ return nullptr;
+
+ // Fast path for ShadowRoot, where we are both a DocumentFragment and a TreeScope.
+ if (isTreeScope())
+ return treeScope().getElementById(id);
+
+ // Otherwise, fall back to iterating all of the element descendants.
+ for (auto& element : elementDescendants(*this)) {
+ if (element.getIdAttribute() == id)
+ return const_cast<Element*>(&element);
+ }
+
+ return nullptr;
+}
+
}