content/base/src/DocumentFragment.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/src/DocumentFragment.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,162 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Implementation of DOM Core's nsIDOMDocumentFragment.
    1.11 + */
    1.12 +
    1.13 +#include "mozilla/dom/DocumentFragment.h"
    1.14 +#include "mozilla/dom/Element.h" // for NS_IMPL_ELEMENT_CLONE
    1.15 +#include "nsINodeInfo.h"
    1.16 +#include "nsNodeInfoManager.h"
    1.17 +#include "nsError.h"
    1.18 +#include "nsGkAtoms.h"
    1.19 +#include "nsDOMString.h"
    1.20 +#include "nsContentUtils.h" // for NS_INTERFACE_MAP_ENTRY_TEAROFF
    1.21 +#include "mozilla/dom/DocumentFragmentBinding.h"
    1.22 +#include "nsPIDOMWindow.h"
    1.23 +#include "nsIDocument.h"
    1.24 +#include "mozilla/IntegerPrintfMacros.h"
    1.25 +
    1.26 +namespace mozilla {
    1.27 +namespace dom {
    1.28 +
    1.29 +JSObject*
    1.30 +DocumentFragment::WrapNode(JSContext *aCx)
    1.31 +{
    1.32 +  return DocumentFragmentBinding::Wrap(aCx, this);
    1.33 +}
    1.34 +
    1.35 +bool
    1.36 +DocumentFragment::IsNodeOfType(uint32_t aFlags) const
    1.37 +{
    1.38 +  return !(aFlags & ~(eCONTENT | eDOCUMENT_FRAGMENT));
    1.39 +}
    1.40 +
    1.41 +nsIAtom*
    1.42 +DocumentFragment::DoGetID() const
    1.43 +{
    1.44 +  return nullptr;  
    1.45 +}
    1.46 +
    1.47 +nsIAtom*
    1.48 +DocumentFragment::GetIDAttributeName() const
    1.49 +{
    1.50 +  return nullptr;
    1.51 +}
    1.52 +
    1.53 +NS_IMETHODIMP
    1.54 +DocumentFragment::QuerySelector(const nsAString& aSelector,
    1.55 +                                nsIDOMElement **aReturn)
    1.56 +{
    1.57 +  return nsINode::QuerySelector(aSelector, aReturn);
    1.58 +}
    1.59 +
    1.60 +NS_IMETHODIMP
    1.61 +DocumentFragment::QuerySelectorAll(const nsAString& aSelector,
    1.62 +                                   nsIDOMNodeList **aReturn)
    1.63 +{
    1.64 +  return nsINode::QuerySelectorAll(aSelector, aReturn);
    1.65 +}
    1.66 +
    1.67 +#ifdef DEBUG
    1.68 +void
    1.69 +DocumentFragment::List(FILE* out, int32_t aIndent) const
    1.70 +{
    1.71 +  int32_t indent;
    1.72 +  for (indent = aIndent; --indent >= 0; ) {
    1.73 +    fputs("  ", out);
    1.74 +  }
    1.75 +
    1.76 +  fprintf(out, "DocumentFragment@%p", (void *)this);
    1.77 +
    1.78 +  fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
    1.79 +  fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get());
    1.80 +
    1.81 +  nsIContent* child = GetFirstChild();
    1.82 +  if (child) {
    1.83 +    fputs("\n", out);
    1.84 +
    1.85 +    for (; child; child = child->GetNextSibling()) {
    1.86 +      child->List(out, aIndent + 1);
    1.87 +    }
    1.88 +
    1.89 +    for (indent = aIndent; --indent >= 0; ) {
    1.90 +      fputs("  ", out);
    1.91 +    }
    1.92 +  }
    1.93 +
    1.94 +  fputs(">\n", out);
    1.95 +}
    1.96 +
    1.97 +void
    1.98 +DocumentFragment::DumpContent(FILE* out, int32_t aIndent,
    1.99 +                              bool aDumpAll) const
   1.100 +{
   1.101 +  int32_t indent;
   1.102 +  for (indent = aIndent; --indent >= 0; ) {
   1.103 +    fputs("  ", out);
   1.104 +  }
   1.105 +
   1.106 +  fputs("<DocumentFragment>", out);
   1.107 +
   1.108 +  if(aIndent) {
   1.109 +    fputs("\n", out);
   1.110 +  }
   1.111 +
   1.112 +  for (nsIContent* child = GetFirstChild();
   1.113 +       child;
   1.114 +       child = child->GetNextSibling()) {
   1.115 +    int32_t indent = aIndent ? aIndent + 1 : 0;
   1.116 +    child->DumpContent(out, indent, aDumpAll);
   1.117 +  }
   1.118 +  for (indent = aIndent; --indent >= 0; ) {
   1.119 +    fputs("  ", out);
   1.120 +  }
   1.121 +  fputs("</DocumentFragment>", out);
   1.122 +
   1.123 +  if(aIndent) {
   1.124 +    fputs("\n", out);
   1.125 +  }
   1.126 +}
   1.127 +#endif
   1.128 +
   1.129 +/* static */ already_AddRefed<DocumentFragment>
   1.130 +DocumentFragment::Constructor(const GlobalObject& aGlobal,
   1.131 +                              ErrorResult& aRv)
   1.132 +{
   1.133 +  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
   1.134 +  if (!window || !window->GetDoc()) {
   1.135 +    aRv.Throw(NS_ERROR_FAILURE);
   1.136 +    return nullptr;
   1.137 +  }
   1.138 +
   1.139 +  return window->GetDoc()->CreateDocumentFragment();
   1.140 +}
   1.141 +
   1.142 +// QueryInterface implementation for DocumentFragment
   1.143 +NS_INTERFACE_MAP_BEGIN(DocumentFragment)
   1.144 +  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   1.145 +  NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(DocumentFragment)
   1.146 +  NS_INTERFACE_MAP_ENTRY(nsIContent)
   1.147 +  NS_INTERFACE_MAP_ENTRY(nsINode)
   1.148 +  NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentFragment)
   1.149 +  NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
   1.150 +  NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
   1.151 +  NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
   1.152 +  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
   1.153 +                                 new nsNodeSupportsWeakRefTearoff(this))
   1.154 +  // DOM bindings depend on the identity pointer being the
   1.155 +  // same as nsINode (which nsIContent inherits).
   1.156 +  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
   1.157 +NS_INTERFACE_MAP_END
   1.158 +
   1.159 +NS_IMPL_ADDREF_INHERITED(DocumentFragment, FragmentOrElement)
   1.160 +NS_IMPL_RELEASE_INHERITED(DocumentFragment, FragmentOrElement)
   1.161 +
   1.162 +NS_IMPL_ELEMENT_CLONE(DocumentFragment)
   1.163 +
   1.164 +} // namespace dom
   1.165 +} // namespace mozilla

mercurial