Bug 1422197 - Add fast path to get DocGroup in binding code for [CEReactions]

Tag #1375
This commit is contained in:
Matt A. Tobin 2020-04-17 07:29:57 -04:00 • committed by Roy Tam
commit ca09afd0b0
30 changed files with 206 additions and 44 deletions

View file

@ -453,6 +453,12 @@ nsISupports* CustomElementRegistry::GetParentObject() const
return mWindow; return mWindow;
} }
DocGroup*
CustomElementRegistry::GetDocGroup() const
{
return mWindow ? mWindow->GetDocGroup() : nullptr;
}
static const char* kLifeCycleCallbackNames[] = { static const char* kLifeCycleCallbackNames[] = {
"connectedCallback", "connectedCallback",
"disconnectedCallback", "disconnectedCallback",

View file

@ -27,6 +27,7 @@ struct CustomElementData;
struct ElementDefinitionOptions; struct ElementDefinitionOptions;
class CallbackFunction; class CallbackFunction;
class CustomElementReaction; class CustomElementReaction;
class DocGroup;
class Function; class Function;
class Promise; class Promise;
@ -513,6 +514,8 @@ private:
public: public:
nsISupports* GetParentObject() const; nsISupports* GetParentObject() const;
DocGroup* GetDocGroup() const;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
void Define(const nsAString& aName, Function& aFunctionConstructor, void Define(const nsAString& aName, Function& aFunctionConstructor,

View file

@ -524,3 +524,9 @@ nsDOMAttributeMap::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{ {
return NamedNodeMapBinding::Wrap(aCx, this, aGivenProto); return NamedNodeMapBinding::Wrap(aCx, this, aGivenProto);
} }
DocGroup*
nsDOMAttributeMap::GetDocGroup() const
{
return mContent ? mContent->OwnerDoc()->GetDocGroup() : nullptr;
}

View file

@ -22,6 +22,11 @@
class nsIAtom; class nsIAtom;
class nsIDocument; class nsIDocument;
namespace mozilla {
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla
/** /**
* Structure used as a key for caching Attrs in nsDOMAttributeMap's mAttributeCache. * Structure used as a key for caching Attrs in nsDOMAttributeMap's mAttributeCache.
@ -87,6 +92,7 @@ class nsDOMAttributeMap final : public nsIDOMMozNamedAttrMap
{ {
public: public:
typedef mozilla::dom::Attr Attr; typedef mozilla::dom::Attr Attr;
typedef mozilla::dom::DocGroup DocGroup;
typedef mozilla::dom::Element Element; typedef mozilla::dom::Element Element;
typedef mozilla::ErrorResult ErrorResult; typedef mozilla::ErrorResult ErrorResult;
@ -135,6 +141,7 @@ public:
return mContent; return mContent;
} }
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
DocGroup* GetDocGroup() const;
// WebIDL // WebIDL
Attr* GetNamedItem(const nsAString& aAttrName); Attr* GetNamedItem(const nsAString& aAttrName);

View file

@ -366,6 +366,12 @@ nsDOMTokenList::Stringify(nsAString& aResult)
mElement->GetAttr(kNameSpaceID_None, mAttrAtom, aResult); mElement->GetAttr(kNameSpaceID_None, mAttrAtom, aResult);
} }
DocGroup*
nsDOMTokenList::GetDocGroup() const
{
return mElement ? mElement->OwnerDoc()->GetDocGroup() : nullptr;
}
JSObject* JSObject*
nsDOMTokenList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) nsDOMTokenList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
{ {

View file

@ -22,7 +22,9 @@
namespace mozilla { namespace mozilla {
class ErrorResult; class ErrorResult;
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla } // namespace mozilla
class nsAttrValue; class nsAttrValue;
@ -35,6 +37,7 @@ class nsDOMTokenList : public nsISupports,
{ {
protected: protected:
typedef mozilla::dom::Element Element; typedef mozilla::dom::Element Element;
typedef mozilla::dom::DocGroup DocGroup;
typedef nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> typedef nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
WhitespaceTokenizer; WhitespaceTokenizer;
@ -52,6 +55,8 @@ public:
return mElement; return mElement;
} }
DocGroup* GetDocGroup() const;
uint32_t Length(); uint32_t Length();
void Item(uint32_t aIndex, nsAString& aResult) void Item(uint32_t aIndex, nsAString& aResult)
{ {

View file

@ -3132,3 +3132,9 @@ nsINode::IsStyledByServo() const
return OwnerDoc()->IsStyledByServo(); return OwnerDoc()->IsStyledByServo();
} }
#endif #endif
DocGroup*
nsINode::GetDocGroup() const
{
return OwnerDoc()->GetDocGroup();
}

View file

@ -72,6 +72,7 @@ inline bool IsSpaceCharacter(char aChar) {
class AccessibleNode; class AccessibleNode;
struct BoxQuadOptions; struct BoxQuadOptions;
struct ConvertCoordinateOptions; struct ConvertCoordinateOptions;
class DocGroup;
class DOMPoint; class DOMPoint;
class DOMQuad; class DOMQuad;
class DOMRectReadOnly; class DOMRectReadOnly;
@ -299,6 +300,7 @@ class nsINode : public mozilla::dom::EventTarget
public: public:
typedef mozilla::dom::BoxQuadOptions BoxQuadOptions; typedef mozilla::dom::BoxQuadOptions BoxQuadOptions;
typedef mozilla::dom::ConvertCoordinateOptions ConvertCoordinateOptions; typedef mozilla::dom::ConvertCoordinateOptions ConvertCoordinateOptions;
typedef mozilla::dom::DocGroup DocGroup;
typedef mozilla::dom::DOMPoint DOMPoint; typedef mozilla::dom::DOMPoint DOMPoint;
typedef mozilla::dom::DOMPointInit DOMPointInit; typedef mozilla::dom::DOMPointInit DOMPointInit;
typedef mozilla::dom::DOMQuad DOMQuad; typedef mozilla::dom::DOMQuad DOMQuad;
@ -613,6 +615,11 @@ public:
return mNodeInfo->NamespaceID() == aNamespace; return mNodeInfo->NamespaceID() == aNamespace;
} }
/**
* Returns the DocGroup of the "node document" of this node.
*/
DocGroup* GetDocGroup() const;
/** /**
* Print a debugger friendly descriptor of this element. This will describe * Print a debugger friendly descriptor of this element. This will describe
* the position of this element in the document. * the position of this element in the document.

View file

@ -49,6 +49,12 @@ nsRange::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return RangeBinding::Wrap(aCx, this, aGivenProto); return RangeBinding::Wrap(aCx, this, aGivenProto);
} }
DocGroup*
nsRange::GetDocGroup() const
{
return mOwner ? mOwner->GetDocGroup() : nullptr;
}
/****************************************************** /******************************************************
* stack based utilty class for managing monitor * stack based utilty class for managing monitor
******************************************************/ ******************************************************/

View file

@ -26,6 +26,7 @@ namespace mozilla {
class ErrorResult; class ErrorResult;
namespace dom { namespace dom {
struct ClientRectsAndTexts; struct ClientRectsAndTexts;
class DocGroup;
class DocumentFragment; class DocumentFragment;
class DOMRect; class DOMRect;
class DOMRectList; class DOMRectList;
@ -38,6 +39,7 @@ class nsRange final : public nsIDOMRange,
public nsWrapperCache public nsWrapperCache
{ {
typedef mozilla::ErrorResult ErrorResult; typedef mozilla::ErrorResult ErrorResult;
typedef mozilla::dom::DocGroup DocGroup;
typedef mozilla::dom::DOMRect DOMRect; typedef mozilla::dom::DOMRect DOMRect;
typedef mozilla::dom::DOMRectList DOMRectList; typedef mozilla::dom::DOMRectList DOMRectList;
@ -280,6 +282,7 @@ public:
nsINode* GetParentObject() const { return mOwner; } nsINode* GetParentObject() const { return mOwner; }
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override final; virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override final;
DocGroup* GetDocGroup() const;
private: private:
// no copy's or assigns // no copy's or assigns

View file

@ -3406,28 +3406,6 @@ GetDesiredProto(JSContext* aCx, const JS::CallArgs& aCallArgs,
return true; return true;
} }
CustomElementReactionsStack*
GetCustomElementReactionsStack(JS::Handle<JSObject*> aObj)
{
// This might not be the right object, if there are wrappers. Unwrap if we can.
JSObject* obj = js::CheckedUnwrap(aObj);
if (!obj) {
return nullptr;
}
nsGlobalWindow* window = xpc::WindowGlobalOrNull(obj);
if (!window) {
return nullptr;
}
DocGroup* docGroup = window->AsInner()->GetDocGroup();
if (!docGroup) {
return nullptr;
}
return docGroup->CustomElementReactionsStack();
}
// https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor // https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor
already_AddRefed<nsGenericHTMLElement> already_AddRefed<nsGenericHTMLElement>
CreateHTMLElement(const GlobalObject& aGlobal, const JS::CallArgs& aCallArgs, CreateHTMLElement(const GlobalObject& aGlobal, const JS::CallArgs& aCallArgs,

View file

@ -3422,12 +3422,6 @@ bool
GetDesiredProto(JSContext* aCx, const JS::CallArgs& aCallArgs, GetDesiredProto(JSContext* aCx, const JS::CallArgs& aCallArgs,
JS::MutableHandle<JSObject*> aDesiredProto); JS::MutableHandle<JSObject*> aDesiredProto);
// Get the CustomElementReactionsStack for the docgroup of the global
// of the underlying object of aObj. This can be null if aObj can't
// be CheckUnwrapped, or if the global of the result has no docgroup
// (e.g. because it's not a Window global).
CustomElementReactionsStack*
GetCustomElementReactionsStack(JS::Handle<JSObject*> aObj);
// This function is expected to be called from the constructor function for an // This function is expected to be called from the constructor function for an
// HTML element interface; the global/callargs need to be whatever was passed to // HTML element interface; the global/callargs need to be whatever was passed to
// that constructor function. // that constructor function.

View file

@ -7680,14 +7680,14 @@ class CGPerSignatureCall(CGThing):
if (idlNode.getExtendedAttribute('CEReactions') is not None and if (idlNode.getExtendedAttribute('CEReactions') is not None and
not getter): not getter):
cgThings.append(CGGeneric(fill( cgThings.append(CGGeneric(dedent(
""" """
CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(${obj}); Maybe<AutoCEReaction> ceReaction;
Maybe<AutoCEReaction> ceReaction; DocGroup* docGroup = self->GetDocGroup();
if (reactionsStack) { if (docGroup) {
ceReaction.emplace(reactionsStack, cx); ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
} }
""", obj=objectName))) """)))
# If this is a method that was generated by a maplike/setlike # If this is a method that was generated by a maplike/setlike
# interface, use the maplike/setlike generator to fill in the body. # interface, use the maplike/setlike generator to fill in the body.
@ -13786,6 +13786,8 @@ class CGForwardDeclarations(CGWrapper):
builder.add(d.nativeType + "Atoms", isStruct=True) builder.add(d.nativeType + "Atoms", isStruct=True)
for t in getTypesFromDescriptor(d): for t in getTypesFromDescriptor(d):
builder.forwardDeclareForType(t, config) builder.forwardDeclareForType(t, config)
if d.hasCEReactions():
builder.addInMozillaDom("DocGroup")
for d in dictionaries: for d in dictionaries:
if len(d.members) > 0: if len(d.members) > 0:
@ -13857,18 +13859,15 @@ class CGBindingRoot(CGThing):
iface = desc.interface iface = desc.interface
return any(m.getExtendedAttribute("Deprecated") for m in iface.members + [iface]) return any(m.getExtendedAttribute("Deprecated") for m in iface.members + [iface])
def descriptorHasCEReactions(desc):
iface = desc.interface
return any(m.getExtendedAttribute("CEReactions") for m in iface.members + [iface])
bindingHeaders["nsIDocument.h"] = any( bindingHeaders["nsIDocument.h"] = any(
descriptorDeprecated(d) for d in descriptors) descriptorDeprecated(d) for d in descriptors)
bindingHeaders["mozilla/Preferences.h"] = any( bindingHeaders["mozilla/Preferences.h"] = any(
descriptorRequiresPreferences(d) for d in descriptors) descriptorRequiresPreferences(d) for d in descriptors)
bindingHeaders["mozilla/dom/DOMJSProxyHandler.h"] = any( bindingHeaders["mozilla/dom/DOMJSProxyHandler.h"] = any(
d.concrete and d.proxy for d in descriptors) d.concrete and d.proxy for d in descriptors)
bindingHeaders["mozilla/dom/CustomElementRegistry.h"] = any( hasCEReactions = any(d.hasCEReactions() for d in descriptors)
descriptorHasCEReactions(d) for d in descriptors) bindingHeaders["mozilla/dom/CustomElementRegistry.h"] = hasCEReactions
bindingHeaders["mozilla/dom/DocGroup.h"] = hasCEReactions
def descriptorHasChromeOnly(desc): def descriptorHasChromeOnly(desc):
ctor = desc.interface.ctor() ctor = desc.interface.ctor()
@ -14704,6 +14703,12 @@ class CGBindingImplClass(CGClass):
breakAfterReturnDecl=" ", breakAfterReturnDecl=" ",
override=descriptor.wrapperCache, override=descriptor.wrapperCache,
body=self.getWrapObjectBody())) body=self.getWrapObjectBody()))
if descriptor.hasCEReactions():
self.methodDecls.insert(0,
ClassMethod("GetDocGroup", "DocGroup*", [],
const=True,
breakAfterReturnDecl=" ",
body=self.getGetDocGroupBody()))
if wantGetParent: if wantGetParent:
self.methodDecls.insert(0, self.methodDecls.insert(0,
ClassMethod("GetParentObject", ClassMethod("GetParentObject",
@ -14724,6 +14729,9 @@ class CGBindingImplClass(CGClass):
def getGetParentObjectBody(self): def getGetParentObjectBody(self):
return None return None
def getGetDocGroupBody(self):
return None
def deps(self): def deps(self):
return self._deps return self._deps
@ -14863,6 +14871,8 @@ class CGExampleRoot(CGThing):
self.root = CGNamespace.build(["mozilla", "dom"], self.root) self.root = CGNamespace.build(["mozilla", "dom"], self.root)
builder = ForwardDeclarationBuilder() builder = ForwardDeclarationBuilder()
if descriptor.hasCEReactions():
builder.addInMozillaDom("DocGroup")
for member in descriptor.interface.members: for member in descriptor.interface.members:
if not member.isAttr() and not member.isMethod(): if not member.isAttr() and not member.isMethod():
continue continue
@ -15174,7 +15184,7 @@ class CGJSImplClass(CGBindingImplClass):
private: private:
RefPtr<${jsImplName}> mImpl; RefPtr<${jsImplName}> mImpl;
nsCOMPtr<nsISupports> mParent; nsCOMPtr<nsIGlobalObject> mParent;
""", """,
isupportsDecl=isupportsDecl, isupportsDecl=isupportsDecl,
@ -15253,6 +15263,16 @@ class CGJSImplClass(CGBindingImplClass):
def getGetParentObjectBody(self): def getGetParentObjectBody(self):
return "return mParent;\n" return "return mParent;\n"
def getGetDocGroupBody(self):
return dedent(
"""
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mParent);
if (!window) {
return nullptr;
}
return window->GetDocGroup();
""")
def getCreateFromExistingBody(self): def getCreateFromExistingBody(self):
# XXXbz we could try to get parts of this (e.g. the argument # XXXbz we could try to get parts of this (e.g. the argument
# conversions) auto-generated by somehow creating an IDLMethod and # conversions) auto-generated by somehow creating an IDLMethod and

View file

@ -631,6 +631,9 @@ class Descriptor(DescriptorProvider):
not self.interface.isExposedInWindow()) or not self.interface.isExposedInWindow()) or
self.interface.isExposedInSomeButNotAllWorkers()) self.interface.isExposedInSomeButNotAllWorkers())
def hasCEReactions(self):
return any(m.getExtendedAttribute("CEReactions") for m in self.interface.members)
def isExposedConditionally(self): def isExposedConditionally(self):
return (self.interface.isExposedConditionally() or return (self.interface.isExposedConditionally() or
self.interface.isExposedInSomeButNotAllWorkers()) self.interface.isExposedInSomeButNotAllWorkers())

View file

@ -21,6 +21,7 @@
// this one for it, for ParentDict. Hopefully it won't begin to rely on it in more fundamental ways. // this one for it, for ParentDict. Hopefully it won't begin to rely on it in more fundamental ways.
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class DocGroup;
class TestExternalInterface; class TestExternalInterface;
class Promise; class Promise;
} // namespace dom } // namespace dom
@ -46,8 +47,9 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_RENAMED_INTERFACE_IID) NS_DECLARE_STATIC_IID_ACCESSOR(NS_RENAMED_INTERFACE_IID)
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// We need a GetParentObject to make binding codegen happy // We need a GetParentObject and GetDocGroup to make binding codegen happy
virtual nsISupports* GetParentObject(); virtual nsISupports* GetParentObject();
DocGroup* GetDocGroup() const;
}; };
NS_DEFINE_STATIC_IID_ACCESSOR(nsRenamedInterface, NS_RENAMED_INTERFACE_IID) NS_DEFINE_STATIC_IID_ACCESSOR(nsRenamedInterface, NS_RENAMED_INTERFACE_IID)
@ -64,8 +66,9 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INDIRECTLY_IMPLEMENTED_INTERFACE_IID) NS_DECLARE_STATIC_IID_ACCESSOR(NS_INDIRECTLY_IMPLEMENTED_INTERFACE_IID)
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// We need a GetParentObject to make binding codegen happy // We need a GetParentObject and GetDocGroup to make binding codegen happy
virtual nsISupports* GetParentObject(); virtual nsISupports* GetParentObject();
DocGroup* GetDocGroup() const;
bool IndirectlyImplementedProperty(); bool IndirectlyImplementedProperty();
void IndirectlyImplementedProperty(bool); void IndirectlyImplementedProperty(bool);

View file

@ -239,6 +239,12 @@ HTMLOptionsCollection::GetParentObject()
return mSelect; return mSelect;
} }
DocGroup*
HTMLOptionsCollection::GetDocGroup() const
{
return mSelect ? mSelect->GetDocGroup() : nullptr;
}
NS_IMETHODIMP NS_IMETHODIMP
HTMLOptionsCollection::NamedItem(const nsAString& aName, HTMLOptionsCollection::NamedItem(const nsAString& aName,
nsIDOMNode** aReturn) nsIDOMNode** aReturn)

View file

@ -23,6 +23,7 @@ class nsIDOMHTMLOptionElement;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class DocGroup;
class HTMLElementOrLong; class HTMLElementOrLong;
class HTMLOptionElementOrHTMLOptGroupElement; class HTMLOptionElementOrHTMLOptGroupElement;
class HTMLSelectElement; class HTMLSelectElement;
@ -62,6 +63,7 @@ public:
virtual Element* GetElementAt(uint32_t aIndex) override; virtual Element* GetElementAt(uint32_t aIndex) override;
virtual nsINode* GetParentObject() override; virtual nsINode* GetParentObject() override;
DocGroup* GetDocGroup() const;
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(HTMLOptionsCollection, NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(HTMLOptionsCollection,
nsIHTMLCollection) nsIHTMLCollection)

View file

@ -62,6 +62,12 @@ nsDOMStringMap::~nsDOMStringMap()
} }
} }
DocGroup*
nsDOMStringMap::GetDocGroup() const
{
return mElement ? mElement->GetDocGroup() : nullptr;
}
/* virtual */ /* virtual */
JSObject* JSObject*
nsDOMStringMap::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) nsDOMStringMap::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)

View file

@ -16,6 +16,9 @@
namespace mozilla { namespace mozilla {
class ErrorResult; class ErrorResult;
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla } // namespace mozilla
class nsDOMStringMap : public nsStubMutationObserver, class nsDOMStringMap : public nsStubMutationObserver,
@ -32,6 +35,8 @@ public:
return mElement; return mElement;
} }
mozilla::dom::DocGroup* GetDocGroup() const;
explicit nsDOMStringMap(mozilla::dom::Element* aElement); explicit nsDOMStringMap(mozilla::dom::Element* aElement);
// WebIDL API // WebIDL API

View file

@ -1284,6 +1284,11 @@ txMozillaXSLTProcessor::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenP
return XSLTProcessorBinding::Wrap(aCx, this, aGivenProto); return XSLTProcessorBinding::Wrap(aCx, this, aGivenProto);
} }
DocGroup*
txMozillaXSLTProcessor::GetDocGroup() const
{
return mStylesheetDocument ? mStylesheetDocument->GetDocGroup() : nullptr;
}
/* static */ already_AddRefed<txMozillaXSLTProcessor> /* static */ already_AddRefed<txMozillaXSLTProcessor>
txMozillaXSLTProcessor::Constructor(const GlobalObject& aGlobal, txMozillaXSLTProcessor::Constructor(const GlobalObject& aGlobal,

View file

@ -29,6 +29,7 @@ class txIGlobalParameter;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class DocGroup;
class Document; class Document;
class DocumentFragment; class DocumentFragment;
class GlobalObject; class GlobalObject;
@ -103,6 +104,8 @@ public:
return mOwner; return mOwner;
} }
mozilla::dom::DocGroup* GetDocGroup() const;
static already_AddRefed<txMozillaXSLTProcessor> static already_AddRefed<txMozillaXSLTProcessor>
Constructor(const mozilla::dom::GlobalObject& aGlobal, Constructor(const mozilla::dom::GlobalObject& aGlobal,
mozilla::ErrorResult& aRv); mozilla::ErrorResult& aRv);

View file

@ -31,6 +31,9 @@ class nsHTMLCopyEncoder;
namespace mozilla { namespace mozilla {
class ErrorResult; class ErrorResult;
struct AutoPrepareFocusRange; struct AutoPrepareFocusRange;
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla } // namespace mozilla
struct RangeData struct RangeData
@ -73,6 +76,7 @@ public:
nsresult EndBatchChangesInternal(int16_t aReason = nsISelectionListener::NO_REASON); nsresult EndBatchChangesInternal(int16_t aReason = nsISelectionListener::NO_REASON);
nsIDocument* GetParentObject() const; nsIDocument* GetParentObject() const;
DocGroup* GetDocGroup() const;
// utility methods for scrolling the selection into view // utility methods for scrolling the selection into view
nsPresContext* GetPresContext() const; nsPresContext* GetPresContext() const;

View file

@ -3521,6 +3521,18 @@ Selection::GetParentObject() const
return nullptr; return nullptr;
} }
DocGroup*
Selection::GetDocGroup() const
{
nsIPresShell* shell = GetPresShell();
if (!shell) {
return nullptr;
}
nsIDocument* doc = shell->GetDocument();
return doc ? doc->GetDocGroup() : nullptr;
}
NS_IMPL_CYCLE_COLLECTION_CLASS(Selection) NS_IMPL_CYCLE_COLLECTION_CLASS(Selection)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Selection) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Selection)

View file

@ -1078,6 +1078,16 @@ public:
return mRule ? mRule->GetDocument() : nullptr; return mRule ? mRule->GetDocument() : nullptr;
} }
virtual DocGroup* GetDocGroup() const override
{
if (!mRule) {
return nullptr;
}
nsIDocument* document = mRule->GetDocument();
return document ? document->GetDocGroup() : nullptr;
}
friend class css::DOMCSSStyleRule; friend class css::DOMCSSStyleRule;
protected: protected:

View file

@ -1515,6 +1515,13 @@ nsCSSFontFaceStyleDecl::GetParentObject()
return ContainingRule()->GetDocument(); return ContainingRule()->GetDocument();
} }
DocGroup*
nsCSSFontFaceStyleDecl::GetDocGroup() const
{
nsIDocument* document = ContainingRule()->GetDocument();
return document ? document->GetDocGroup() : nullptr;
}
JSObject* JSObject*
nsCSSFontFaceStyleDecl::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) nsCSSFontFaceStyleDecl::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
{ {
@ -1991,6 +1998,17 @@ nsCSSKeyframeStyleDeclaration::GetParentObject()
return mRule ? mRule->GetDocument() : nullptr; return mRule ? mRule->GetDocument() : nullptr;
} }
DocGroup*
nsCSSKeyframeStyleDeclaration::GetDocGroup() const
{
if (!mRule) {
return nullptr;
}
nsIDocument* document = mRule->GetDocument();
return document ? document->GetDocGroup() : nullptr;
}
// ------------------------------------------- // -------------------------------------------
// nsCSSKeyframeRule // nsCSSKeyframeRule
// //
@ -2538,6 +2556,17 @@ nsCSSPageStyleDeclaration::GetParentObject()
return mRule ? mRule->GetDocument() : nullptr; return mRule ? mRule->GetDocument() : nullptr;
} }
DocGroup*
nsCSSPageStyleDeclaration::GetDocGroup() const
{
if (!mRule) {
return nullptr;
}
nsIDocument* document = mRule->GetDocument();
return document ? document->GetDocGroup() : nullptr;
}
// ------------------------------------------- // -------------------------------------------
// nsCSSPageRule // nsCSSPageRule
// //

View file

@ -39,6 +39,11 @@ class nsMediaList;
namespace mozilla { namespace mozilla {
namespace dom {
class DocGroup;
class DocGroup;
} // namespace dom
class ErrorResult; class ErrorResult;
namespace css { namespace css {
@ -209,6 +214,7 @@ public:
using nsICSSDeclaration::GetPropertyCSSValue; using nsICSSDeclaration::GetPropertyCSSValue;
virtual nsINode *GetParentObject() override; virtual nsINode *GetParentObject() override;
virtual mozilla::dom::DocGroup* GetDocGroup() const override;
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) override; virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) override;
nsresult GetPropertyValue(nsCSSFontDesc aFontDescID, nsresult GetPropertyValue(nsCSSFontDesc aFontDescID,
@ -366,6 +372,7 @@ public:
nsICSSDeclaration) nsICSSDeclaration)
virtual nsINode* GetParentObject() override; virtual nsINode* GetParentObject() override;
virtual mozilla::dom::DocGroup* GetDocGroup() const override;
protected: protected:
virtual ~nsCSSKeyframeStyleDeclaration(); virtual ~nsCSSKeyframeStyleDeclaration();
@ -496,6 +503,7 @@ public:
nsICSSDeclaration) nsICSSDeclaration)
virtual nsINode *GetParentObject() override; virtual nsINode *GetParentObject() override;
virtual mozilla::dom::DocGroup* GetDocGroup() const override;
protected: protected:
virtual ~nsCSSPageStyleDeclaration(); virtual ~nsCSSPageStyleDeclaration();

View file

@ -27,6 +27,7 @@
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class DocGroup;
class Element; class Element;
} // namespace dom } // namespace dom
struct ComputedGridTrackInfo; struct ComputedGridTrackInfo;
@ -84,6 +85,11 @@ public:
return mElement; return mElement;
} }
virtual mozilla::dom::DocGroup* GetDocGroup() const override
{
return mElement ? mElement->GetDocGroup() : nullptr;
}
static already_AddRefed<nsStyleContext> static already_AddRefed<nsStyleContext>
GetStyleContextForElement(mozilla::dom::Element* aElement, nsIAtom* aPseudo, GetStyleContextForElement(mozilla::dom::Element* aElement, nsIAtom* aPseudo,
nsIPresShell* aPresShell, nsIPresShell* aPresShell,

View file

@ -178,6 +178,12 @@ nsDOMCSSAttributeDeclaration::GetParentObject()
return mElement; return mElement;
} }
/* virtual */ DocGroup*
nsDOMCSSAttributeDeclaration::GetDocGroup() const
{
return mElement ? mElement->OwnerDoc()->GetDocGroup() : nullptr;
}
NS_IMETHODIMP NS_IMETHODIMP
nsDOMCSSAttributeDeclaration::SetPropertyValue(const nsCSSPropertyID aPropID, nsDOMCSSAttributeDeclaration::SetPropertyValue(const nsCSSPropertyID aPropID,
const nsAString& aValue) const nsAString& aValue)

View file

@ -35,6 +35,7 @@ public:
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) override; NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) override;
virtual nsINode* GetParentObject() override; virtual nsINode* GetParentObject() override;
virtual DocGroup* GetDocGroup() const override;
NS_IMETHOD SetPropertyValue(const nsCSSPropertyID aPropID, NS_IMETHOD SetPropertyValue(const nsCSSPropertyID aPropID,
const nsAString& aValue) override; const nsAString& aValue) override;

View file

@ -31,6 +31,11 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
class nsINode; class nsINode;
namespace mozilla {
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla
// dbeabbfa-6cb3-4f5c-aec2-dd558d9d681f // dbeabbfa-6cb3-4f5c-aec2-dd558d9d681f
#define NS_ICSSDECLARATION_IID \ #define NS_ICSSDECLARATION_IID \
@ -62,6 +67,7 @@ public:
const nsAString& aValue) = 0; const nsAString& aValue) = 0;
virtual nsINode *GetParentObject() = 0; virtual nsINode *GetParentObject() = 0;
virtual mozilla::dom::DocGroup* GetDocGroup() const = 0;
// Also have to declare all the nsIDOMCSSStyleDeclaration methods, // Also have to declare all the nsIDOMCSSStyleDeclaration methods,
// since we want to be able to call them from the WebIDL versions. // since we want to be able to call them from the WebIDL versions.