2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsXBLBinding_h_
|
|
|
|
#define nsXBLBinding_h_
|
|
|
|
|
2013-02-08 06:24:20 -08:00
|
|
|
#include "nsXBLService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2009-01-29 11:46:18 -08:00
|
|
|
#include "nsINodeList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIStyleRuleProcessor.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsTArray.h"
|
2007-05-24 07:10:02 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2010-04-01 11:05:40 -07:00
|
|
|
#include "nsISupportsImpl.h"
|
2013-08-27 19:59:14 -07:00
|
|
|
#include "js/TypeDecls.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsXBLPrototypeBinding;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIAtom;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIScriptContext;
|
2013-07-01 15:09:37 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-12-02 02:26:11 -08:00
|
|
|
class ShadowRoot;
|
2013-07-01 15:09:37 -07:00
|
|
|
class XBLChildrenElement;
|
|
|
|
|
2013-12-02 02:26:11 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-07-01 15:09:37 -07:00
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
class nsAnonymousContentList;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// *********************************************************************/
|
|
|
|
// The XBLBinding class
|
|
|
|
|
2014-03-04 09:49:39 -08:00
|
|
|
class nsXBLBinding MOZ_FINAL
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-08-05 06:19:51 -07:00
|
|
|
explicit nsXBLBinding(nsXBLPrototypeBinding* aProtoBinding);
|
2013-12-02 02:26:11 -08:00
|
|
|
nsXBLBinding(mozilla::dom::ShadowRoot* aShadowRoot, nsXBLPrototypeBinding* aProtoBinding);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* XBLBindings are refcounted. They are held onto in 3 ways:
|
|
|
|
* 1. The binding manager's binding table holds onto all bindings that are
|
|
|
|
* currently attached to a content node.
|
|
|
|
* 2. Bindings hold onto their base binding. This is important since
|
|
|
|
* the base binding itself may not be attached to anything.
|
|
|
|
* 3. The binding manager holds an additional reference to bindings
|
|
|
|
* which are queued to fire their constructors.
|
|
|
|
*/
|
|
|
|
|
2012-08-24 09:50:06 -07:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsXBLBinding)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding)
|
|
|
|
|
2013-07-18 21:13:35 -07:00
|
|
|
nsXBLPrototypeBinding* PrototypeBinding() const { return mPrototypeBinding; }
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* GetAnonymousContent() { return mContent.get(); }
|
2013-05-01 15:50:08 -07:00
|
|
|
nsXBLBinding* GetBindingWithContent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-18 21:13:35 -07:00
|
|
|
nsXBLBinding* GetBaseBinding() const { return mNextBinding; }
|
2007-03-22 10:30:00 -07:00
|
|
|
void SetBaseBinding(nsXBLBinding *aBinding);
|
|
|
|
|
|
|
|
nsIContent* GetBoundElement() { return mBoundElement; }
|
|
|
|
void SetBoundElement(nsIContent *aElement);
|
|
|
|
|
2013-02-08 06:24:21 -08:00
|
|
|
/*
|
|
|
|
* Does a lookup for a method or attribute provided by one of the bindings'
|
|
|
|
* prototype implementation. If found, |desc| will be set up appropriately,
|
|
|
|
* and wrapped into cx->compartment.
|
2013-02-13 10:16:19 -08:00
|
|
|
*
|
|
|
|
* May only be called when XBL code is being run in a separate scope, because
|
|
|
|
* otherwise we don't have untainted data with which to do a proper lookup.
|
2013-02-08 06:24:21 -08:00
|
|
|
*/
|
2013-11-11 00:04:41 -08:00
|
|
|
bool LookupMember(JSContext* aCx, JS::Handle<jsid> aId,
|
|
|
|
JS::MutableHandle<JSPropertyDescriptor> aDesc);
|
2013-02-08 06:24:21 -08:00
|
|
|
|
2013-02-08 06:24:22 -08:00
|
|
|
/*
|
|
|
|
* Determines whether the binding has a field with the given name.
|
|
|
|
*/
|
|
|
|
bool HasField(nsString& aName);
|
|
|
|
|
2013-02-08 06:24:21 -08:00
|
|
|
protected:
|
|
|
|
|
2014-06-23 12:56:07 -07:00
|
|
|
~nsXBLBinding();
|
|
|
|
|
2013-02-08 06:24:21 -08:00
|
|
|
/*
|
2013-02-13 10:16:19 -08:00
|
|
|
* Internal version. Requires that aCx is in appropriate xbl scope.
|
2013-02-08 06:24:21 -08:00
|
|
|
*/
|
2013-11-11 00:04:41 -08:00
|
|
|
bool LookupMemberInternal(JSContext* aCx, nsString& aName,
|
|
|
|
JS::Handle<jsid> aNameAsId,
|
2013-08-12 04:09:14 -07:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> aDesc,
|
|
|
|
JS::Handle<JSObject*> aXBLScope);
|
2013-02-08 06:24:21 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void MarkForDeath();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool MarkedForDeath() const { return mMarkedForDeath; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasStyleSheets() const;
|
|
|
|
bool InheritsStyle() const;
|
|
|
|
bool ImplementsInterface(REFNSIID aIID) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void GenerateAnonymousContent();
|
2012-10-10 12:04:42 -07:00
|
|
|
void InstallAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement,
|
|
|
|
bool aNativeAnon);
|
2009-01-06 11:37:28 -08:00
|
|
|
static void UninstallAnonymousContent(nsIDocument* aDocument,
|
|
|
|
nsIContent* aAnonParent);
|
2008-03-14 16:08:57 -07:00
|
|
|
void InstallEventHandlers();
|
|
|
|
nsresult InstallImplementation();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void ExecuteAttachedHandler();
|
|
|
|
void ExecuteDetachedHandler();
|
|
|
|
void UnhookEventHandlers();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsIAtom* GetBaseTag(int32_t* aNameSpaceID);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLBinding* RootBinding();
|
|
|
|
|
2007-09-28 06:45:01 -07:00
|
|
|
// Resolve all the fields for this binding and all ancestor bindings on the
|
|
|
|
// object |obj|. False return means a JS exception was set.
|
2013-04-05 06:21:03 -07:00
|
|
|
bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const;
|
2007-09-28 06:45:01 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void AttributeChanged(nsIAtom* aAttribute, int32_t aNameSpaceID,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRemoveFlag, bool aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument);
|
|
|
|
|
|
|
|
void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);
|
|
|
|
|
2014-03-19 09:35:45 -07:00
|
|
|
static nsresult DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> obj,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAFlatCString& aClassName,
|
2007-09-28 06:45:01 -07:00
|
|
|
nsXBLPrototypeBinding* aProtoBinding,
|
2013-04-05 06:21:01 -07:00
|
|
|
JS::MutableHandle<JSObject*> aClassObject,
|
|
|
|
bool* aNew);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-13 08:54:04 -08:00
|
|
|
bool AllowScripts();
|
2007-05-21 15:26:48 -07:00
|
|
|
|
2013-07-01 15:09:37 -07:00
|
|
|
mozilla::dom::XBLChildrenElement* FindInsertionPointFor(nsIContent* aChild);
|
2013-05-01 15:50:08 -07:00
|
|
|
|
|
|
|
bool HasFilteredInsertionPoints()
|
|
|
|
{
|
|
|
|
return !mInsertionPoints.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2013-07-01 15:09:37 -07:00
|
|
|
mozilla::dom::XBLChildrenElement* GetDefaultInsertionPoint()
|
2013-05-01 15:50:08 -07:00
|
|
|
{
|
|
|
|
return mDefaultInsertionPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Removes all inserted node from <xbl:children> insertion points under us.
|
|
|
|
void ClearInsertionPoints();
|
|
|
|
|
|
|
|
// Returns a live node list that iterates over the anonymous nodes generated
|
|
|
|
// by this binding.
|
|
|
|
nsAnonymousContentList* GetAnonymousNodeList();
|
2007-10-12 04:07:29 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// MEMBER VARIABLES
|
|
|
|
protected:
|
2007-10-26 17:14:43 -07:00
|
|
|
|
2012-04-17 12:23:11 -07:00
|
|
|
bool mMarkedForDeath;
|
2014-06-02 18:04:21 -07:00
|
|
|
bool mUsingContentXBLScope;
|
2014-09-26 15:07:40 -07:00
|
|
|
bool mIsShadowRootBinding;
|
2012-04-17 12:23:11 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
|
|
|
|
nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.
|
|
|
|
nsRefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings.
|
2013-05-01 15:50:08 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* mBoundElement; // [WEAK] We have a reference, but we don't own it.
|
2013-05-01 15:50:08 -07:00
|
|
|
|
|
|
|
// The <xbl:children> elements that we found in our <xbl:content> when we
|
|
|
|
// processed this binding. The default insertion point has no includes
|
|
|
|
// attribute and all other insertion points must have at least one includes
|
|
|
|
// attribute. These points must be up-to-date with respect to their parent's
|
|
|
|
// children, even if their parent has another binding attached to it,
|
|
|
|
// preventing us from rendering their contents directly.
|
2013-07-01 15:09:37 -07:00
|
|
|
nsRefPtr<mozilla::dom::XBLChildrenElement> mDefaultInsertionPoint;
|
|
|
|
nsTArray<nsRefPtr<mozilla::dom::XBLChildrenElement> > mInsertionPoints;
|
2013-05-01 15:50:08 -07:00
|
|
|
nsRefPtr<nsAnonymousContentList> mAnonymousContentList;
|
|
|
|
|
2013-07-01 15:09:37 -07:00
|
|
|
mozilla::dom::XBLChildrenElement* FindInsertionPointForInternal(nsIContent* aChild);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXBLBinding_h_
|