dom/xbl/XBLChildrenElement.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xbl/XBLChildrenElement.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,182 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 sw=2 et tw=79: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsXBLChildrenElement_h___
    1.11 +#define nsXBLChildrenElement_h___
    1.12 +
    1.13 +#include "nsIDOMElement.h"
    1.14 +#include "nsINodeList.h"
    1.15 +#include "nsBindingManager.h"
    1.16 +#include "mozilla/dom/nsXMLElement.h"
    1.17 +
    1.18 +class nsAnonymousContentList;
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace dom {
    1.22 +
    1.23 +class ExplicitChildIterator;
    1.24 +
    1.25 +class XBLChildrenElement : public nsXMLElement
    1.26 +{
    1.27 +public:
    1.28 +  friend class mozilla::dom::ExplicitChildIterator;
    1.29 +  friend class nsAnonymousContentList;
    1.30 +  XBLChildrenElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
    1.31 +    : nsXMLElement(aNodeInfo)
    1.32 +  {
    1.33 +  }
    1.34 +  XBLChildrenElement(already_AddRefed<nsINodeInfo>&& aNodeInfo)
    1.35 +    : nsXMLElement(aNodeInfo)
    1.36 +  {
    1.37 +  }
    1.38 +  ~XBLChildrenElement();
    1.39 +
    1.40 +  // nsISupports
    1.41 +  NS_DECL_ISUPPORTS_INHERITED
    1.42 +
    1.43 +  // nsINode interface methods
    1.44 +  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
    1.45 +
    1.46 +  virtual nsXPCClassInfo* GetClassInfo() { return nullptr; }
    1.47 +
    1.48 +  virtual nsIDOMNode* AsDOMNode() { return this; }
    1.49 +
    1.50 +  // nsIContent interface methods
    1.51 +  virtual nsIAtom *GetIDAttributeName() const;
    1.52 +  virtual nsIAtom* DoGetID() const;
    1.53 +  virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
    1.54 +                             bool aNotify);
    1.55 +  virtual bool ParseAttribute(int32_t aNamespaceID,
    1.56 +                              nsIAtom* aAttribute,
    1.57 +                              const nsAString& aValue,
    1.58 +                              nsAttrValue& aResult);
    1.59 +
    1.60 +  void AppendInsertedChild(nsIContent* aChild)
    1.61 +  {
    1.62 +    mInsertedChildren.AppendElement(aChild);
    1.63 +    aChild->SetXBLInsertionParent(GetParent());
    1.64 +  }
    1.65 +
    1.66 +  void InsertInsertedChildAt(nsIContent* aChild, uint32_t aIndex)
    1.67 +  {
    1.68 +    mInsertedChildren.InsertElementAt(aIndex, aChild);
    1.69 +    aChild->SetXBLInsertionParent(GetParent());
    1.70 +  }
    1.71 +
    1.72 +  void RemoveInsertedChild(nsIContent* aChild)
    1.73 +  {
    1.74 +    // Can't use this assertion as we cheat for dynamic insertions and
    1.75 +    // only insert in the innermost insertion point.
    1.76 +    //NS_ASSERTION(mInsertedChildren.Contains(aChild),
    1.77 +    //             "Removing child that's not there");
    1.78 +    mInsertedChildren.RemoveElement(aChild);
    1.79 +  }
    1.80 +
    1.81 +  void ClearInsertedChildren()
    1.82 +  {
    1.83 +    for (uint32_t c = 0; c < mInsertedChildren.Length(); ++c) {
    1.84 +      mInsertedChildren[c]->SetXBLInsertionParent(nullptr);
    1.85 +    }
    1.86 +    mInsertedChildren.Clear();
    1.87 +  }
    1.88 +
    1.89 +  void MaybeSetupDefaultContent()
    1.90 +  {
    1.91 +    if (!HasInsertedChildren()) {
    1.92 +      for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
    1.93 +           child;
    1.94 +           child = child->GetNextSibling()) {
    1.95 +        child->SetXBLInsertionParent(GetParent());
    1.96 +      }
    1.97 +    }
    1.98 +  }
    1.99 +
   1.100 +  void MaybeRemoveDefaultContent()
   1.101 +  {
   1.102 +    if (!HasInsertedChildren()) {
   1.103 +      for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
   1.104 +           child;
   1.105 +           child = child->GetNextSibling()) {
   1.106 +        child->SetXBLInsertionParent(nullptr);
   1.107 +      }
   1.108 +    }
   1.109 +  }
   1.110 +
   1.111 +  uint32_t InsertedChildrenLength()
   1.112 +  {
   1.113 +    return mInsertedChildren.Length();
   1.114 +  }
   1.115 +
   1.116 +  bool HasInsertedChildren()
   1.117 +  {
   1.118 +    return !mInsertedChildren.IsEmpty();
   1.119 +  }
   1.120 +
   1.121 +  enum {
   1.122 +    NoIndex = uint32_t(-1)
   1.123 +  };
   1.124 +  uint32_t IndexOfInsertedChild(nsIContent* aChild)
   1.125 +  {
   1.126 +    return mInsertedChildren.IndexOf(aChild);
   1.127 +  }
   1.128 +
   1.129 +  bool Includes(nsIContent* aChild)
   1.130 +  {
   1.131 +    NS_ASSERTION(!mIncludes.IsEmpty(),
   1.132 +                 "Shouldn't check for includes on default insertion point");
   1.133 +    return mIncludes.Contains(aChild->Tag());
   1.134 +  }
   1.135 +
   1.136 +  bool IsDefaultInsertion()
   1.137 +  {
   1.138 +    return mIncludes.IsEmpty();
   1.139 +  }
   1.140 +
   1.141 +  nsTArray<nsIContent*> mInsertedChildren;
   1.142 +
   1.143 +private:
   1.144 +  nsTArray<nsCOMPtr<nsIAtom> > mIncludes;
   1.145 +};
   1.146 +
   1.147 +} // namespace dom
   1.148 +} // namespace mozilla
   1.149 +
   1.150 +class nsAnonymousContentList : public nsINodeList
   1.151 +{
   1.152 +public:
   1.153 +  nsAnonymousContentList(nsIContent* aParent)
   1.154 +    : mParent(aParent)
   1.155 +  {
   1.156 +    MOZ_COUNT_CTOR(nsAnonymousContentList);
   1.157 +    SetIsDOMBinding();
   1.158 +  }
   1.159 +
   1.160 +  virtual ~nsAnonymousContentList()
   1.161 +  {
   1.162 +    MOZ_COUNT_DTOR(nsAnonymousContentList);
   1.163 +  }
   1.164 +
   1.165 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   1.166 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsAnonymousContentList)
   1.167 +  // nsIDOMNodeList interface
   1.168 +  NS_DECL_NSIDOMNODELIST
   1.169 +
   1.170 +  // nsINodeList interface
   1.171 +  virtual int32_t IndexOf(nsIContent* aContent);
   1.172 +  virtual nsINode* GetParentObject() { return mParent; }
   1.173 +  virtual nsIContent* Item(uint32_t aIndex);
   1.174 +
   1.175 +  virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
   1.176 +
   1.177 +  bool IsListFor(nsIContent* aContent) {
   1.178 +    return mParent == aContent;
   1.179 +  }
   1.180 +
   1.181 +private:
   1.182 +  nsCOMPtr<nsIContent> mParent;
   1.183 +};
   1.184 +
   1.185 +#endif // nsXBLChildrenElement_h___

mercurial