diff options
author | Moonchild <moonchild@palemoon.org> | 2020-06-10 01:19:37 +0000 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-06-13 11:50:06 +0200 |
commit | 0e0feed5daa8751b04bda7b4caac3854995cb0c8 (patch) | |
tree | e5292ae865b705e729ca30290820638975cd8df7 /dom/base | |
parent | 7f238b1cf9775b43b119eb9a5e2ea0fe79fa5add (diff) | |
download | UXP-0e0feed5daa8751b04bda7b4caac3854995cb0c8.tar UXP-0e0feed5daa8751b04bda7b4caac3854995cb0c8.tar.gz UXP-0e0feed5daa8751b04bda7b4caac3854995cb0c8.tar.lz UXP-0e0feed5daa8751b04bda7b4caac3854995cb0c8.tar.xz UXP-0e0feed5daa8751b04bda7b4caac3854995cb0c8.zip |
Issue #1585 - Replace node.rootNode with node.getRootNode()
This removes the (default disabled) node.rootNode readonly attribute
and replaces it with a node.getRootNode() function per WhatWG
spec discussion.
Based on work by John Dai <jdai@mozilla.com>
Diffstat (limited to 'dom/base')
-rw-r--r-- | dom/base/nsINode.cpp | 25 | ||||
-rw-r--r-- | dom/base/nsINode.h | 10 |
2 files changed, 31 insertions, 4 deletions
diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index 212110b72..355bf0ebf 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -107,6 +107,7 @@ #include "GeometryUtils.h" #include "nsIAnimationObserver.h" #include "nsChildContentList.h" +#include "mozilla/dom/NodeBinding.h" #ifdef ACCESSIBILITY #include "mozilla/dom/AccessibleNode.h" @@ -250,6 +251,30 @@ nsINode::GetTextEditorRootContent(nsIEditor** aEditor) return nullptr; } +nsINode* nsINode::GetRootNode(const GetRootNodeOptions& aOptions) +{ + if (aOptions.mComposed) { + if (IsInComposedDoc() && GetComposedDoc()) { + return OwnerDoc(); + } + + nsINode* node = this; + ShadowRoot* shadowRootParent = nullptr; + while(node) { + node = node->SubtreeRoot(); + shadowRootParent = ShadowRoot::FromNode(node); + if (!shadowRootParent) { + break; + } + node = shadowRootParent->GetHost(); + } + + return node; + } + + return SubtreeRoot(); +} + nsINode* nsINode::SubtreeRoot() const { diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index d82f5f899..43d44db60 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -83,6 +83,7 @@ template<typename> class Sequence; class Text; class TextOrElementOrDocument; struct DOMPointInit; +struct GetRootNodeOptions; } // namespace dom } // namespace mozilla @@ -942,10 +943,11 @@ public: */ nsINode* SubtreeRoot() const; - nsINode* RootNode() const - { - return SubtreeRoot(); - } + /* + * Get context object's shadow-including root if options's composed is true, + * and context object's root otherwise. + */ + nsINode* GetRootNode(const mozilla::dom::GetRootNodeOptions& aOptions); /** * See nsIDOMEventTarget |