From a2ff640daa9f3e7ef7f59ddf137815207ce1a48c Mon Sep 17 00:00:00 2001 From: William Chen Date: Thu, 2 Oct 2014 01:31:45 -0700 Subject: [PATCH] Bug 1073043 - Fix mouse events trapped in shadow DOM. r=smaug --- content/base/public/nsContentUtils.h | 4 +++- content/base/src/nsContentUtils.cpp | 10 ++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 86860aee6dfc..f53c8bf323c6 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -187,6 +187,7 @@ public: /** * Returns the parent node of aChild crossing document boundaries. + * Uses the parent node in the composed document. */ static nsINode* GetCrossDocParentNode(nsINode* aChild); @@ -217,7 +218,8 @@ public: /** * Similar to ContentIsDescendantOf except it crosses document boundaries, - * also crosses ShadowRoot boundaries from ShadowRoot to its host. + * this function uses ancestor/descendant relations in the composed document + * (see shadow DOM spec). */ static bool ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant, nsINode* aPossibleAncestor); diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index c4adf16fdc07..015f26156e24 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -2025,6 +2025,10 @@ nsContentUtils::GetCrossDocParentNode(nsINode* aChild) NS_PRECONDITION(aChild, "The child is null!"); nsINode* parent = aChild->GetParentNode(); + if (parent && parent->IsContent() && aChild->IsContent()) { + parent = aChild->AsContent()->GetFlattenedTreeParent(); + } + if (parent || !aChild->IsNodeOfType(nsINode::eDOCUMENT)) return parent; @@ -2083,12 +2087,6 @@ nsContentUtils::ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant, if (aPossibleDescendant == aPossibleAncestor) return true; - // Step over shadow root to the host node. - ShadowRoot* shadowRoot = ShadowRoot::FromNode(aPossibleDescendant); - if (shadowRoot) { - aPossibleDescendant = shadowRoot->GetHost(); - } - aPossibleDescendant = GetCrossDocParentNode(aPossibleDescendant); } while (aPossibleDescendant);