content/base/src/DocumentFragment.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * Implementation of DOM Core's nsIDOMDocumentFragment.
michael@0 8 */
michael@0 9
michael@0 10 #include "mozilla/dom/DocumentFragment.h"
michael@0 11 #include "mozilla/dom/Element.h" // for NS_IMPL_ELEMENT_CLONE
michael@0 12 #include "nsINodeInfo.h"
michael@0 13 #include "nsNodeInfoManager.h"
michael@0 14 #include "nsError.h"
michael@0 15 #include "nsGkAtoms.h"
michael@0 16 #include "nsDOMString.h"
michael@0 17 #include "nsContentUtils.h" // for NS_INTERFACE_MAP_ENTRY_TEAROFF
michael@0 18 #include "mozilla/dom/DocumentFragmentBinding.h"
michael@0 19 #include "nsPIDOMWindow.h"
michael@0 20 #include "nsIDocument.h"
michael@0 21 #include "mozilla/IntegerPrintfMacros.h"
michael@0 22
michael@0 23 namespace mozilla {
michael@0 24 namespace dom {
michael@0 25
michael@0 26 JSObject*
michael@0 27 DocumentFragment::WrapNode(JSContext *aCx)
michael@0 28 {
michael@0 29 return DocumentFragmentBinding::Wrap(aCx, this);
michael@0 30 }
michael@0 31
michael@0 32 bool
michael@0 33 DocumentFragment::IsNodeOfType(uint32_t aFlags) const
michael@0 34 {
michael@0 35 return !(aFlags & ~(eCONTENT | eDOCUMENT_FRAGMENT));
michael@0 36 }
michael@0 37
michael@0 38 nsIAtom*
michael@0 39 DocumentFragment::DoGetID() const
michael@0 40 {
michael@0 41 return nullptr;
michael@0 42 }
michael@0 43
michael@0 44 nsIAtom*
michael@0 45 DocumentFragment::GetIDAttributeName() const
michael@0 46 {
michael@0 47 return nullptr;
michael@0 48 }
michael@0 49
michael@0 50 NS_IMETHODIMP
michael@0 51 DocumentFragment::QuerySelector(const nsAString& aSelector,
michael@0 52 nsIDOMElement **aReturn)
michael@0 53 {
michael@0 54 return nsINode::QuerySelector(aSelector, aReturn);
michael@0 55 }
michael@0 56
michael@0 57 NS_IMETHODIMP
michael@0 58 DocumentFragment::QuerySelectorAll(const nsAString& aSelector,
michael@0 59 nsIDOMNodeList **aReturn)
michael@0 60 {
michael@0 61 return nsINode::QuerySelectorAll(aSelector, aReturn);
michael@0 62 }
michael@0 63
michael@0 64 #ifdef DEBUG
michael@0 65 void
michael@0 66 DocumentFragment::List(FILE* out, int32_t aIndent) const
michael@0 67 {
michael@0 68 int32_t indent;
michael@0 69 for (indent = aIndent; --indent >= 0; ) {
michael@0 70 fputs(" ", out);
michael@0 71 }
michael@0 72
michael@0 73 fprintf(out, "DocumentFragment@%p", (void *)this);
michael@0 74
michael@0 75 fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
michael@0 76 fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get());
michael@0 77
michael@0 78 nsIContent* child = GetFirstChild();
michael@0 79 if (child) {
michael@0 80 fputs("\n", out);
michael@0 81
michael@0 82 for (; child; child = child->GetNextSibling()) {
michael@0 83 child->List(out, aIndent + 1);
michael@0 84 }
michael@0 85
michael@0 86 for (indent = aIndent; --indent >= 0; ) {
michael@0 87 fputs(" ", out);
michael@0 88 }
michael@0 89 }
michael@0 90
michael@0 91 fputs(">\n", out);
michael@0 92 }
michael@0 93
michael@0 94 void
michael@0 95 DocumentFragment::DumpContent(FILE* out, int32_t aIndent,
michael@0 96 bool aDumpAll) const
michael@0 97 {
michael@0 98 int32_t indent;
michael@0 99 for (indent = aIndent; --indent >= 0; ) {
michael@0 100 fputs(" ", out);
michael@0 101 }
michael@0 102
michael@0 103 fputs("<DocumentFragment>", out);
michael@0 104
michael@0 105 if(aIndent) {
michael@0 106 fputs("\n", out);
michael@0 107 }
michael@0 108
michael@0 109 for (nsIContent* child = GetFirstChild();
michael@0 110 child;
michael@0 111 child = child->GetNextSibling()) {
michael@0 112 int32_t indent = aIndent ? aIndent + 1 : 0;
michael@0 113 child->DumpContent(out, indent, aDumpAll);
michael@0 114 }
michael@0 115 for (indent = aIndent; --indent >= 0; ) {
michael@0 116 fputs(" ", out);
michael@0 117 }
michael@0 118 fputs("</DocumentFragment>", out);
michael@0 119
michael@0 120 if(aIndent) {
michael@0 121 fputs("\n", out);
michael@0 122 }
michael@0 123 }
michael@0 124 #endif
michael@0 125
michael@0 126 /* static */ already_AddRefed<DocumentFragment>
michael@0 127 DocumentFragment::Constructor(const GlobalObject& aGlobal,
michael@0 128 ErrorResult& aRv)
michael@0 129 {
michael@0 130 nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
michael@0 131 if (!window || !window->GetDoc()) {
michael@0 132 aRv.Throw(NS_ERROR_FAILURE);
michael@0 133 return nullptr;
michael@0 134 }
michael@0 135
michael@0 136 return window->GetDoc()->CreateDocumentFragment();
michael@0 137 }
michael@0 138
michael@0 139 // QueryInterface implementation for DocumentFragment
michael@0 140 NS_INTERFACE_MAP_BEGIN(DocumentFragment)
michael@0 141 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
michael@0 142 NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(DocumentFragment)
michael@0 143 NS_INTERFACE_MAP_ENTRY(nsIContent)
michael@0 144 NS_INTERFACE_MAP_ENTRY(nsINode)
michael@0 145 NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentFragment)
michael@0 146 NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
michael@0 147 NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
michael@0 148 NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
michael@0 149 NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
michael@0 150 new nsNodeSupportsWeakRefTearoff(this))
michael@0 151 // DOM bindings depend on the identity pointer being the
michael@0 152 // same as nsINode (which nsIContent inherits).
michael@0 153 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
michael@0 154 NS_INTERFACE_MAP_END
michael@0 155
michael@0 156 NS_IMPL_ADDREF_INHERITED(DocumentFragment, FragmentOrElement)
michael@0 157 NS_IMPL_RELEASE_INHERITED(DocumentFragment, FragmentOrElement)
michael@0 158
michael@0 159 NS_IMPL_ELEMENT_CLONE(DocumentFragment)
michael@0 160
michael@0 161 } // namespace dom
michael@0 162 } // namespace mozilla

mercurial