From 38493ba5e9343078ea86b2f14c841f1e97aba6f4 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 30 Oct 2014 17:38:48 -0400 Subject: [PATCH] Bug 1088228 part 1. Introduce an nsINode API for getting the scope chain parent for a given node. r=peterv --- dom/base/Element.cpp | 7 +++++++ dom/base/Element.h | 6 ++++-- dom/base/nsIDocument.h | 4 ++-- dom/base/nsINode.cpp | 5 +++++ dom/base/nsINode.h | 11 +++++++++-- dom/html/HTMLLegendElement.cpp | 2 +- dom/html/HTMLLegendElement.h | 10 ++++++++-- dom/html/nsGenericHTMLElement.cpp | 6 ++++++ dom/html/nsGenericHTMLElement.h | 2 ++ dom/xul/nsXULElement.h | 6 ++++++ 10 files changed, 50 insertions(+), 9 deletions(-) diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 6fa88f22ef63..5c6a65cf94fa 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -500,6 +500,13 @@ Element::WrapObject(JSContext *aCx) return obj; } +/* virtual */ +nsINode* +Element::GetScopeChainParent() const +{ + return OwnerDoc(); +} + nsDOMTokenList* Element::ClassList() { diff --git a/dom/base/Element.h b/dom/base/Element.h index 122274a81650..f3dbe1660a22 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -139,8 +139,8 @@ class DestinationInsertionPointList; // IID for the dom::Element interface #define NS_ELEMENT_IID \ -{ 0xaa79cb98, 0xc785, 0x44c5, \ - { 0x80, 0x80, 0x2e, 0x5f, 0x0c, 0xa5, 0xbd, 0x63 } } +{ 0x31d3f3fb, 0xcdf8, 0x4e40, \ + { 0xb7, 0x09, 0x1a, 0x11, 0x43, 0x93, 0x61, 0x71 } } class Element : public FragmentOrElement { @@ -961,6 +961,8 @@ public: virtual JSObject* WrapObject(JSContext *aCx) MOZ_FINAL MOZ_OVERRIDE; + nsINode* GetScopeChainParent() const MOZ_OVERRIDE; + /** * Locate an nsIEditor rooted at this content node, if there is one. */ diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 0550acdb2441..ff7a10748291 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -136,8 +136,8 @@ typedef CallbackObjectHolder NodeFilterHolder; } // namespace mozilla #define NS_IDOCUMENT_IID \ -{ 0xbab5b447, 0x7e23, 0x4cdd, \ - { 0xac, 0xe5, 0xaa, 0x04, 0x26, 0x87, 0x2b, 0x97 } } +{ 0x6bbf1955, 0xd9c4, 0x4d61, \ + { 0xbf, 0x75, 0x1b, 0xba, 0x55, 0xf7, 0x99, 0xc2 } } // Enum for requesting a particular type of document when creating a doc enum DocumentFlavor { diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index f559e98a05de..e5d01d158501 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -2752,3 +2752,8 @@ nsINode::HasBoxQuadsSupport(JSContext* aCx, JSObject* /* unused */) Preferences::GetBool("layout.css.getBoxQuads.enabled"); } +nsINode* +nsINode::GetScopeChainParent() const +{ + return nullptr; +} diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 9fcfa91dd84b..e1a91f673f48 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -248,8 +248,8 @@ private: // IID for the nsINode interface #define NS_INODE_IID \ -{ 0x8deda3f4, 0x0f45, 0x497a, \ - { 0x89, 0x7c, 0xe6, 0x09, 0x12, 0x8a, 0xad, 0xd8 } } +{ 0x66972940, 0x1d1b, 0x4d15, \ + { 0x93, 0x11, 0x96, 0x72, 0x84, 0x2e, 0xc7, 0x27 } } /** * An internal interface that abstracts some DOMNode-related parts that both @@ -396,6 +396,13 @@ protected: public: mozilla::dom::ParentObject GetParentObject() const; // Implemented in nsIDocument.h + /** + * Return the scope chain parent for this node, for use in things + * like event handler compilation. Returning null means to use the + * global object as the scope chain parent. + */ + virtual nsINode* GetScopeChainParent() const; + /** * Return whether the node is an Element node */ diff --git a/dom/html/HTMLLegendElement.cpp b/dom/html/HTMLLegendElement.cpp index 5d7a06746d8b..69b0ee49ea8d 100644 --- a/dom/html/HTMLLegendElement.cpp +++ b/dom/html/HTMLLegendElement.cpp @@ -22,7 +22,7 @@ HTMLLegendElement::~HTMLLegendElement() NS_IMPL_ELEMENT_CLONE(HTMLLegendElement) nsIContent* -HTMLLegendElement::GetFieldSet() +HTMLLegendElement::GetFieldSet() const { nsIContent* parent = GetParent(); diff --git a/dom/html/HTMLLegendElement.h b/dom/html/HTMLLegendElement.h index da8286eee930..e28ef42f3930 100644 --- a/dom/html/HTMLLegendElement.h +++ b/dom/html/HTMLLegendElement.h @@ -54,7 +54,7 @@ public: virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const MOZ_OVERRIDE; - Element* GetFormElement() + Element* GetFormElement() const { nsCOMPtr fieldsetControl = do_QueryInterface(GetFieldSet()); @@ -83,6 +83,12 @@ public: : nsGenericHTMLElement::GetParentObject(); } + nsINode* GetScopeChainParent() const MOZ_OVERRIDE + { + Element* form = GetFormElement(); + return form ? form : nsGenericHTMLElement::GetScopeChainParent(); + } + protected: virtual ~HTMLLegendElement(); @@ -92,7 +98,7 @@ protected: * Get the fieldset content element that contains this legend. * Returns null if there is no fieldset containing this legend. */ - nsIContent* GetFieldSet(); + nsIContent* GetFieldSet() const; }; } // namespace dom diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 065f691625b0..7ad6941d650b 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -1906,6 +1906,12 @@ nsGenericHTMLFormElement::GetParentObject() const return nsGenericHTMLElement::GetParentObject(); } +nsINode* +nsGenericHTMLFormElement::GetScopeChainParent() const +{ + return mForm ? mForm : nsGenericHTMLElement::GetScopeChainParent(); +} + bool nsGenericHTMLFormElement::IsNodeOfType(uint32_t aFlags) const { diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 9fad29303189..472e429f5804 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -1247,6 +1247,8 @@ public: mozilla::dom::ParentObject GetParentObject() const; + nsINode* GetScopeChainParent() const MOZ_OVERRIDE; + virtual bool IsNodeOfType(uint32_t aFlags) const MOZ_OVERRIDE; virtual void SaveSubtreeState() MOZ_OVERRIDE; diff --git a/dom/xul/nsXULElement.h b/dom/xul/nsXULElement.h index 9374ebe9c92f..c1e04883f69b 100644 --- a/dom/xul/nsXULElement.h +++ b/dom/xul/nsXULElement.h @@ -616,6 +616,12 @@ public: return nsStyledElement::GetParentObject(); } + nsINode* GetScopeChainParent() const MOZ_OVERRIDE + { + Element* parent = GetParentElement(); + return parent ? parent : nsStyledElement::GetScopeChainParent(); + } + protected: ~nsXULElement();