content/base/src/DocumentFragment.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial