2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2000-06-22 04:36:19 +04:00
|
|
|
|
2007-02-17 02:02:08 +03:00
|
|
|
#ifndef nsXBLBinding_h_
|
|
|
|
#define nsXBLBinding_h_
|
|
|
|
|
2013-02-08 18:24:20 +04:00
|
|
|
#include "nsXBLService.h"
|
2000-06-22 04:36:19 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2009-01-29 22:46:18 +03:00
|
|
|
#include "nsINodeList.h"
|
2005-02-26 01:07:01 +03:00
|
|
|
#include "nsIStyleRuleProcessor.h"
|
2006-09-19 01:35:21 +04:00
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsTArray.h"
|
2007-05-24 18:10:02 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2010-04-01 22:05:40 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2013-08-28 06:59:14 +04:00
|
|
|
#include "js/TypeDecls.h"
|
2000-06-22 04:36:19 +04:00
|
|
|
|
2005-02-26 01:07:01 +03:00
|
|
|
class nsXBLPrototypeBinding;
|
2000-06-22 04:36:19 +04:00
|
|
|
class nsIContent;
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2000-06-22 04:36:19 +04:00
|
|
|
class nsIDocument;
|
2013-07-02 02:09:37 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2017-06-14 02:38:16 +03:00
|
|
|
class ServoStyleSet;
|
2013-07-02 02:09:37 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2013-12-02 14:26:11 +04:00
|
|
|
class ShadowRoot;
|
2013-07-02 02:09:37 +04:00
|
|
|
class XBLChildrenElement;
|
|
|
|
|
2013-12-02 14:26:11 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-07-02 02:09:37 +04:00
|
|
|
|
2013-05-02 02:50:08 +04:00
|
|
|
class nsAnonymousContentList;
|
2000-06-22 04:36:19 +04:00
|
|
|
|
|
|
|
// *********************************************************************/
|
|
|
|
// The XBLBinding class
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXBLBinding final
|
2000-06-22 04:36:19 +04:00
|
|
|
{
|
2005-02-26 01:07:01 +03:00
|
|
|
public:
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit nsXBLBinding(nsXBLPrototypeBinding* aProtoBinding);
|
2013-12-02 14:26:11 +04:00
|
|
|
nsXBLBinding(mozilla::dom::ShadowRoot* aShadowRoot, nsXBLPrototypeBinding* aProtoBinding);
|
2005-02-26 01:07:01 +03: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 20:50:06 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsXBLBinding)
|
2005-02-26 01:07:01 +03:00
|
|
|
|
2007-05-24 18:10:02 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding)
|
|
|
|
|
2013-07-19 08:13:35 +04:00
|
|
|
nsXBLPrototypeBinding* PrototypeBinding() const { return mPrototypeBinding; }
|
2007-02-17 02:02:08 +03:00
|
|
|
nsIContent* GetAnonymousContent() { return mContent.get(); }
|
2013-05-02 02:50:08 +04:00
|
|
|
nsXBLBinding* GetBindingWithContent();
|
2005-02-26 01:07:01 +03:00
|
|
|
|
2013-07-19 08:13:35 +04:00
|
|
|
nsXBLBinding* GetBaseBinding() const { return mNextBinding; }
|
2005-02-26 01:07:01 +03:00
|
|
|
void SetBaseBinding(nsXBLBinding *aBinding);
|
|
|
|
|
2017-12-05 20:05:51 +03:00
|
|
|
mozilla::dom::Element* GetBoundElement() { return mBoundElement; }
|
|
|
|
void SetBoundElement(mozilla::dom::Element* aElement);
|
2005-02-26 01:07:01 +03:00
|
|
|
|
2013-02-08 18:24:21 +04: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 22:16:19 +04: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 18:24:21 +04:00
|
|
|
*/
|
2013-11-11 12:04:41 +04:00
|
|
|
bool LookupMember(JSContext* aCx, JS::Handle<jsid> aId,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> aDesc);
|
2013-02-08 18:24:21 +04:00
|
|
|
|
2013-02-08 18:24:22 +04:00
|
|
|
/*
|
|
|
|
* Determines whether the binding has a field with the given name.
|
|
|
|
*/
|
|
|
|
bool HasField(nsString& aName);
|
|
|
|
|
2013-02-08 18:24:21 +04:00
|
|
|
protected:
|
|
|
|
|
2014-06-23 23:56:07 +04:00
|
|
|
~nsXBLBinding();
|
|
|
|
|
2013-02-08 18:24:21 +04:00
|
|
|
/*
|
2013-02-13 22:16:19 +04:00
|
|
|
* Internal version. Requires that aCx is in appropriate xbl scope.
|
2013-02-08 18:24:21 +04:00
|
|
|
*/
|
2013-11-11 12:04:41 +04:00
|
|
|
bool LookupMemberInternal(JSContext* aCx, nsString& aName,
|
|
|
|
JS::Handle<jsid> aNameAsId,
|
2016-01-28 13:28:04 +03:00
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> aDesc,
|
2013-08-12 15:09:14 +04:00
|
|
|
JS::Handle<JSObject*> aXBLScope);
|
2013-02-08 18:24:21 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2005-02-26 01:07:01 +03:00
|
|
|
void MarkForDeath();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool MarkedForDeath() const { return mMarkedForDeath; }
|
2005-02-26 01:07:01 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasStyleSheets() const;
|
|
|
|
bool InheritsStyle() const;
|
|
|
|
bool ImplementsInterface(REFNSIID aIID) const;
|
2005-02-26 01:07:01 +03:00
|
|
|
|
|
|
|
void GenerateAnonymousContent();
|
2017-09-11 14:11:01 +03:00
|
|
|
void BindAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement,
|
|
|
|
bool aNativeAnon);
|
|
|
|
static void UnbindAnonymousContent(nsIDocument* aDocument,
|
2017-09-08 15:59:04 +03:00
|
|
|
nsIContent* aAnonParent,
|
|
|
|
bool aNullParent = true);
|
2008-03-15 02:08:57 +03:00
|
|
|
void InstallEventHandlers();
|
|
|
|
nsresult InstallImplementation();
|
2000-06-22 04:36:19 +04:00
|
|
|
|
2005-02-26 01:07:01 +03:00
|
|
|
void ExecuteAttachedHandler();
|
|
|
|
void ExecuteDetachedHandler();
|
|
|
|
void UnhookEventHandlers();
|
2000-06-22 04:36:19 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* GetBaseTag(int32_t* aNameSpaceID);
|
2005-02-26 01:07:01 +03:00
|
|
|
nsXBLBinding* RootBinding();
|
2000-08-12 10:28:02 +04:00
|
|
|
|
2007-09-28 17:45:01 +04: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 17:21:03 +04:00
|
|
|
bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const;
|
2007-09-28 17:45:01 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
void AttributeChanged(nsAtom* aAttribute, int32_t aNameSpaceID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRemoveFlag, bool aNotify);
|
2000-12-07 13:11:21 +03:00
|
|
|
|
2005-02-26 01:07:01 +03:00
|
|
|
void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument);
|
2000-06-22 04:36:19 +04:00
|
|
|
|
2005-02-26 01:07:01 +03:00
|
|
|
void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);
|
2000-06-22 04:36:19 +04:00
|
|
|
|
2017-08-03 09:58:23 +03:00
|
|
|
mozilla::ServoStyleSet* GetServoStyleSet() const;
|
2017-06-05 09:00:27 +03:00
|
|
|
|
2014-03-19 20:35:45 +04:00
|
|
|
static nsresult DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> obj,
|
2017-06-20 12:19:05 +03:00
|
|
|
const nsString& aClassName,
|
2007-09-28 17:45:01 +04:00
|
|
|
nsXBLPrototypeBinding* aProtoBinding,
|
2013-04-05 17:21:01 +04:00
|
|
|
JS::MutableHandle<JSObject*> aClassObject,
|
|
|
|
bool* aNew);
|
2002-06-22 00:55:17 +04:00
|
|
|
|
2013-12-13 20:54:04 +04:00
|
|
|
bool AllowScripts();
|
2007-05-22 02:26:48 +04:00
|
|
|
|
2013-07-02 02:09:37 +04:00
|
|
|
mozilla::dom::XBLChildrenElement* FindInsertionPointFor(nsIContent* aChild);
|
2013-05-02 02:50:08 +04:00
|
|
|
|
|
|
|
bool HasFilteredInsertionPoints()
|
|
|
|
{
|
|
|
|
return !mInsertionPoints.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2013-07-02 02:09:37 +04:00
|
|
|
mozilla::dom::XBLChildrenElement* GetDefaultInsertionPoint()
|
2013-05-02 02:50:08 +04: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 15:07:29 +04:00
|
|
|
|
2016-09-20 09:13:13 +03:00
|
|
|
nsIURI* GetSourceDocURI();
|
|
|
|
|
2000-06-22 04:36:19 +04:00
|
|
|
// MEMBER VARIABLES
|
|
|
|
protected:
|
2007-10-27 04:14:43 +04:00
|
|
|
|
2012-04-17 23:23:11 +04:00
|
|
|
bool mMarkedForDeath;
|
2014-06-03 05:04:21 +04:00
|
|
|
bool mUsingContentXBLScope;
|
2014-09-27 02:07:40 +04:00
|
|
|
bool mIsShadowRootBinding;
|
2012-04-17 23:23:11 +04:00
|
|
|
|
2004-02-15 22:24:42 +03:00
|
|
|
nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
|
2000-06-22 04:36:19 +04:00
|
|
|
nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings.
|
2013-05-02 02:50:08 +04:00
|
|
|
|
2017-12-05 20:05:51 +03:00
|
|
|
mozilla::dom::Element* mBoundElement; // [WEAK] We have a reference, but we don't own it.
|
2013-05-02 02:50:08 +04: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.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::XBLChildrenElement> mDefaultInsertionPoint;
|
|
|
|
nsTArray<RefPtr<mozilla::dom::XBLChildrenElement> > mInsertionPoints;
|
|
|
|
RefPtr<nsAnonymousContentList> mAnonymousContentList;
|
2013-05-02 02:50:08 +04:00
|
|
|
|
2013-07-02 02:09:37 +04:00
|
|
|
mozilla::dom::XBLChildrenElement* FindInsertionPointForInternal(nsIContent* aChild);
|
2000-06-22 04:36:19 +04:00
|
|
|
};
|
2007-02-17 02:02:08 +03:00
|
|
|
|
|
|
|
#endif // nsXBLBinding_h_
|