dom/xbl/nsXBLBinding.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xbl/nsXBLBinding.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,184 @@
     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 +#ifndef nsXBLBinding_h_
    1.10 +#define nsXBLBinding_h_
    1.11 +
    1.12 +#include "nsXBLService.h"
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsAutoPtr.h"
    1.15 +#include "nsINodeList.h"
    1.16 +#include "nsIStyleRuleProcessor.h"
    1.17 +#include "nsClassHashtable.h"
    1.18 +#include "nsTArray.h"
    1.19 +#include "nsCycleCollectionParticipant.h"
    1.20 +#include "nsISupportsImpl.h"
    1.21 +#include "js/TypeDecls.h"
    1.22 +
    1.23 +class nsXBLPrototypeBinding;
    1.24 +class nsIContent;
    1.25 +class nsIAtom;
    1.26 +class nsIDocument;
    1.27 +class nsIScriptContext;
    1.28 +
    1.29 +namespace mozilla {
    1.30 +namespace dom {
    1.31 +
    1.32 +class ShadowRoot;
    1.33 +class XBLChildrenElement;
    1.34 +
    1.35 +} // namespace dom
    1.36 +} // namespace mozilla
    1.37 +
    1.38 +class nsAnonymousContentList;
    1.39 +
    1.40 +// *********************************************************************/
    1.41 +// The XBLBinding class
    1.42 +
    1.43 +class nsXBLBinding MOZ_FINAL
    1.44 +{
    1.45 +public:
    1.46 +  nsXBLBinding(nsXBLPrototypeBinding* aProtoBinding);
    1.47 +  nsXBLBinding(mozilla::dom::ShadowRoot* aShadowRoot, nsXBLPrototypeBinding* aProtoBinding);
    1.48 +  ~nsXBLBinding();
    1.49 +
    1.50 +  /**
    1.51 +   * XBLBindings are refcounted.  They are held onto in 3 ways:
    1.52 +   * 1. The binding manager's binding table holds onto all bindings that are
    1.53 +   *    currently attached to a content node.
    1.54 +   * 2. Bindings hold onto their base binding.  This is important since
    1.55 +   *    the base binding itself may not be attached to anything.
    1.56 +   * 3. The binding manager holds an additional reference to bindings
    1.57 +   *    which are queued to fire their constructors.
    1.58 +   */
    1.59 +
    1.60 +  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsXBLBinding)
    1.61 +
    1.62 +  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding)
    1.63 +
    1.64 +  nsXBLPrototypeBinding* PrototypeBinding() const { return mPrototypeBinding; }
    1.65 +  nsIContent* GetAnonymousContent() { return mContent.get(); }
    1.66 +  nsXBLBinding* GetBindingWithContent();
    1.67 +
    1.68 +  nsXBLBinding* GetBaseBinding() const { return mNextBinding; }
    1.69 +  void SetBaseBinding(nsXBLBinding *aBinding);
    1.70 +
    1.71 +  nsIContent* GetBoundElement() { return mBoundElement; }
    1.72 +  void SetBoundElement(nsIContent *aElement);
    1.73 +
    1.74 +  /*
    1.75 +   * Does a lookup for a method or attribute provided by one of the bindings'
    1.76 +   * prototype implementation. If found, |desc| will be set up appropriately,
    1.77 +   * and wrapped into cx->compartment.
    1.78 +   *
    1.79 +   * May only be called when XBL code is being run in a separate scope, because
    1.80 +   * otherwise we don't have untainted data with which to do a proper lookup.
    1.81 +   */
    1.82 +  bool LookupMember(JSContext* aCx, JS::Handle<jsid> aId,
    1.83 +                    JS::MutableHandle<JSPropertyDescriptor> aDesc);
    1.84 +
    1.85 +  /*
    1.86 +   * Determines whether the binding has a field with the given name.
    1.87 +   */
    1.88 +  bool HasField(nsString& aName);
    1.89 +
    1.90 +protected:
    1.91 +
    1.92 +  /*
    1.93 +   * Internal version. Requires that aCx is in appropriate xbl scope.
    1.94 +   */
    1.95 +  bool LookupMemberInternal(JSContext* aCx, nsString& aName,
    1.96 +                            JS::Handle<jsid> aNameAsId,
    1.97 +                            JS::MutableHandle<JSPropertyDescriptor> aDesc,
    1.98 +                            JS::Handle<JSObject*> aXBLScope);
    1.99 +
   1.100 +public:
   1.101 +
   1.102 +  void MarkForDeath();
   1.103 +  bool MarkedForDeath() const { return mMarkedForDeath; }
   1.104 +
   1.105 +  bool HasStyleSheets() const;
   1.106 +  bool InheritsStyle() const;
   1.107 +  bool ImplementsInterface(REFNSIID aIID) const;
   1.108 +
   1.109 +  void GenerateAnonymousContent();
   1.110 +  void InstallAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement,
   1.111 +                               bool aNativeAnon);
   1.112 +  static void UninstallAnonymousContent(nsIDocument* aDocument,
   1.113 +                                        nsIContent* aAnonParent);
   1.114 +  void InstallEventHandlers();
   1.115 +  nsresult InstallImplementation();
   1.116 +
   1.117 +  void ExecuteAttachedHandler();
   1.118 +  void ExecuteDetachedHandler();
   1.119 +  void UnhookEventHandlers();
   1.120 +
   1.121 +  nsIAtom* GetBaseTag(int32_t* aNameSpaceID);
   1.122 +  nsXBLBinding* RootBinding();
   1.123 +
   1.124 +  // Resolve all the fields for this binding and all ancestor bindings on the
   1.125 +  // object |obj|.  False return means a JS exception was set.
   1.126 +  bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const;
   1.127 +
   1.128 +  void AttributeChanged(nsIAtom* aAttribute, int32_t aNameSpaceID,
   1.129 +                        bool aRemoveFlag, bool aNotify);
   1.130 +
   1.131 +  void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument);
   1.132 +
   1.133 +  void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);
   1.134 +
   1.135 +  static nsresult DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> obj,
   1.136 +                                const nsAFlatCString& aClassName,
   1.137 +                                nsXBLPrototypeBinding* aProtoBinding,
   1.138 +                                JS::MutableHandle<JSObject*> aClassObject,
   1.139 +                                bool* aNew);
   1.140 +
   1.141 +  bool AllowScripts();
   1.142 +
   1.143 +  mozilla::dom::XBLChildrenElement* FindInsertionPointFor(nsIContent* aChild);
   1.144 +
   1.145 +  bool HasFilteredInsertionPoints()
   1.146 +  {
   1.147 +    return !mInsertionPoints.IsEmpty();
   1.148 +  }
   1.149 +
   1.150 +  mozilla::dom::XBLChildrenElement* GetDefaultInsertionPoint()
   1.151 +  {
   1.152 +    return mDefaultInsertionPoint;
   1.153 +  }
   1.154 +
   1.155 +  // Removes all inserted node from <xbl:children> insertion points under us.
   1.156 +  void ClearInsertionPoints();
   1.157 +
   1.158 +  // Returns a live node list that iterates over the anonymous nodes generated
   1.159 +  // by this binding.
   1.160 +  nsAnonymousContentList* GetAnonymousNodeList();
   1.161 +
   1.162 +// MEMBER VARIABLES
   1.163 +protected:
   1.164 +
   1.165 +  bool mMarkedForDeath;
   1.166 +  bool mUsingXBLScope;
   1.167 +
   1.168 +  nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
   1.169 +  nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.
   1.170 +  nsRefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings.
   1.171 +
   1.172 +  nsIContent* mBoundElement; // [WEAK] We have a reference, but we don't own it.
   1.173 +
   1.174 +  // The <xbl:children> elements that we found in our <xbl:content> when we
   1.175 +  // processed this binding. The default insertion point has no includes
   1.176 +  // attribute and all other insertion points must have at least one includes
   1.177 +  // attribute. These points must be up-to-date with respect to their parent's
   1.178 +  // children, even if their parent has another binding attached to it,
   1.179 +  // preventing us from rendering their contents directly.
   1.180 +  nsRefPtr<mozilla::dom::XBLChildrenElement> mDefaultInsertionPoint;
   1.181 +  nsTArray<nsRefPtr<mozilla::dom::XBLChildrenElement> > mInsertionPoints;
   1.182 +  nsRefPtr<nsAnonymousContentList> mAnonymousContentList;
   1.183 +
   1.184 +  mozilla::dom::XBLChildrenElement* FindInsertionPointForInternal(nsIContent* aChild);
   1.185 +};
   1.186 +
   1.187 +#endif // nsXBLBinding_h_

mercurial