tor-browser

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

HTMLSlotElement.h (3119B)


      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_HTMLSlotElement_h
      8 #define mozilla_dom_HTMLSlotElement_h
      9 
     10 #include "mozilla/dom/FastFrontRemovableArray.h"
     11 #include "nsGenericHTMLElement.h"
     12 #include "nsTArray.h"
     13 
     14 namespace mozilla::dom {
     15 
     16 struct AssignedNodesOptions;
     17 class OwningElementOrText;
     18 
     19 class HTMLSlotElement final : public nsGenericHTMLElement {
     20 public:
     21  explicit HTMLSlotElement(
     22      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
     23  NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLSlotElement, slot)
     24 
     25  NS_DECL_ISUPPORTS_INHERITED
     26  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLSlotElement,
     27                                           nsGenericHTMLElement)
     28  nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
     29 
     30  // nsIContent
     31  nsresult BindToTree(BindContext&, nsINode& aParent) override;
     32  void UnbindFromTree(UnbindContext&) override;
     33 
     34  void BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName,
     35                     const nsAttrValue* aValue, bool aNotify) override;
     36  void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
     37                    const nsAttrValue* aValue, const nsAttrValue* aOldValue,
     38                    nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
     39 
     40  // WebIDL
     41  void SetName(const nsAString& aName, ErrorResult& aRv) {
     42    SetHTMLAttr(nsGkAtoms::name, aName, aRv);
     43  }
     44 
     45  void GetName(nsAString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); }
     46 
     47  void AssignedNodes(const AssignedNodesOptions& aOptions,
     48                     nsTArray<RefPtr<nsINode>>& aNodes);
     49 
     50  void AssignedElements(const AssignedNodesOptions& aOptions,
     51                        nsTArray<RefPtr<Element>>& aNodes);
     52 
     53  void Assign(const Sequence<OwningElementOrText>& aNodes);
     54 
     55  // Helper methods
     56  Span<const RefPtr<nsINode>> AssignedNodes() const { return mAssignedNodes; }
     57  const nsTArray<nsINode*>& ManuallyAssignedNodes() const;
     58  void InsertAssignedNode(uint32_t aIndex, nsIContent&);
     59  void AppendAssignedNode(nsIContent&);
     60  void RemoveAssignedNode(nsIContent&);
     61  void ClearAssignedNodes();
     62 
     63  void EnqueueSlotChangeEvent();
     64  void RemovedFromSignalSlotList() {
     65    MOZ_ASSERT(mInSignalSlotList);
     66    mInSignalSlotList = false;
     67  }
     68 
     69  void FireSlotChangeEvent();
     70 
     71  void RemoveManuallyAssignedNode(nsIContent&);
     72 
     73  void RecalculateHasSlottedState();
     74 
     75 protected:
     76  virtual ~HTMLSlotElement();
     77  JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
     78 
     79  FastFrontRemovableArray<RefPtr<nsINode>> mAssignedNodes;
     80  nsTArray<nsINode*> mManuallyAssignedNodes;
     81 
     82  // Whether we're in the signal slot list of our unit of related similar-origin
     83  // browsing contexts.
     84  //
     85  // https://dom.spec.whatwg.org/#signal-slot-list
     86  bool mInSignalSlotList = false;
     87 
     88  bool mInManualShadowRoot = false;
     89 };
     90 
     91 }  // namespace mozilla::dom
     92 
     93 #endif  // mozilla_dom_HTMLSlotElement_h