tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DocumentFragment.h (3592B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_DocumentFragment_h__
      8 #define mozilla_dom_DocumentFragment_h__
      9 
     10 #include "mozilla/dom/BorrowedAttrInfo.h"
     11 #include "mozilla/dom/FragmentOrElement.h"
     12 #include "nsStringFwd.h"
     13 
     14 // XXX Avoid including this here by moving function bodies to the cpp file.
     15 #include "mozilla/dom/Element.h"
     16 
     17 class nsAtom;
     18 class nsIContent;
     19 
     20 namespace mozilla::dom {
     21 
     22 class Document;
     23 class Element;
     24 
     25 class DocumentFragment : public FragmentOrElement {
     26 private:
     27  void Init() {
     28    MOZ_ASSERT(mNodeInfo->NodeType() == DOCUMENT_FRAGMENT_NODE &&
     29                   mNodeInfo->Equals(nsGkAtoms::documentFragmentNodeName,
     30                                     kNameSpaceID_None),
     31               "Bad NodeType in aNodeInfo");
     32  }
     33 
     34 public:
     35  using FragmentOrElement::GetFirstChild;
     36  using nsINode::QuerySelector;
     37  using nsINode::QuerySelectorAll;
     38  // Make sure bindings can see our superclass' protected GetElementById method.
     39  using nsINode::GetElementById;
     40 
     41  // nsISupports
     42  NS_DECL_ISUPPORTS_INHERITED
     43  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocumentFragment, FragmentOrElement)
     44 
     45  explicit DocumentFragment(already_AddRefed<dom::NodeInfo>&& aNodeInfo)
     46      : FragmentOrElement(std::move(aNodeInfo)), mHost(nullptr) {
     47    Init();
     48  }
     49 
     50  explicit DocumentFragment(nsNodeInfoManager* aNodeInfoManager)
     51      : FragmentOrElement(aNodeInfoManager->GetNodeInfo(
     52            nsGkAtoms::documentFragmentNodeName, nullptr, kNameSpaceID_None,
     53            DOCUMENT_FRAGMENT_NODE)),
     54        mHost(nullptr) {
     55    Init();
     56  }
     57 
     58  NS_IMPL_FROMNODE_HELPER(DocumentFragment, IsDocumentFragment());
     59 
     60  JSObject* WrapNode(JSContext* aCx,
     61                     JS::Handle<JSObject*> aGivenProto) override;
     62 
     63  nsresult BindToTree(BindContext&, nsINode& aParent) override {
     64    NS_ASSERTION(false, "Trying to bind a fragment to a tree");
     65    return NS_ERROR_NOT_IMPLEMENTED;
     66  }
     67 
     68  virtual void UnbindFromTree(UnbindContext&) override {
     69    NS_ASSERTION(false, "Trying to unbind a fragment from a tree");
     70  }
     71 
     72  Element* GetNameSpaceElement() override { return nullptr; }
     73 
     74  Element* GetHost() const { return mHost; }
     75 
     76  void SetHost(Element* aHost) { mHost = aHost; }
     77 
     78  void GetInnerHTML(nsAString& aInnerHTML) { GetMarkup(false, aInnerHTML); }
     79  void SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError) {
     80    SetInnerHTMLInternal(aInnerHTML, aError);
     81  }
     82 
     83  static already_AddRefed<DocumentFragment> Constructor(
     84      const GlobalObject& aGlobal, ErrorResult& aRv);
     85 
     86 #ifdef MOZ_DOM_LIST
     87  virtual void List(FILE* out, int32_t aIndent) const override;
     88  virtual void DumpContent(FILE* out, int32_t aIndent,
     89                           bool aDumpAll) const override;
     90 #endif
     91 
     92 protected:
     93  virtual ~DocumentFragment() = default;
     94 
     95  nsresult Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const override;
     96  RefPtr<Element> mHost;
     97 };
     98 
     99 }  // namespace mozilla::dom
    100 
    101 inline mozilla::dom::DocumentFragment* nsINode::AsDocumentFragment() {
    102  MOZ_ASSERT(IsDocumentFragment());
    103  return static_cast<mozilla::dom::DocumentFragment*>(this);
    104 }
    105 
    106 inline const mozilla::dom::DocumentFragment* nsINode::AsDocumentFragment()
    107    const {
    108  MOZ_ASSERT(IsDocumentFragment());
    109  return static_cast<const mozilla::dom::DocumentFragment*>(this);
    110 }
    111 
    112 #endif  // mozilla_dom_DocumentFragment_h__