summaryrefslogtreecommitdiffstats
path: root/dom/base/nsIContentInlines.h
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/nsIContentInlines.h')
-rw-r--r--dom/base/nsIContentInlines.h32
1 files changed, 27 insertions, 5 deletions
diff --git a/dom/base/nsIContentInlines.h b/dom/base/nsIContentInlines.h
index 89cc7b9c30..04e73b75e1 100644
--- a/dom/base/nsIContentInlines.h
+++ b/dom/base/nsIContentInlines.h
@@ -82,10 +82,27 @@ static inline nsINode* GetFlattenedTreeParentNode(const nsINode* aNode) {
return parent;
}
- if (parentAsContent->GetShadowRoot()) {
- // If it's not assigned to any slot it's not part of the flat tree, and thus
- // we return null.
- return content->GetAssignedSlot();
+ // Use GetShadowRootForSelection for the selection case such that
+ // if the content is slotted into a UA shadow tree, use
+ // the parent of content as the flattened tree parent (instead of
+ // the slot element).
+ const nsINode* shadowRootForParent =
+ aType == nsINode::eForSelection
+ ? parentAsContent->GetShadowRootForSelection()
+ : parentAsContent->GetShadowRoot();
+
+ if (shadowRootForParent) {
+ // When aType is not nsINode::eForSelection, If it's not assigned to any
+ // slot it's not part of the flat tree, and thus we return null.
+ auto* assignedSlot = content->GetAssignedSlot();
+ if (assignedSlot || aType != nsINode::eForSelection) {
+ return assignedSlot;
+ }
+
+ MOZ_ASSERT(aType == nsINode::eForSelection);
+ // When aType is nsINode::eForSelection, we use the parent of the
+ // content even if it's not assigned to any slot.
+ return parent;
}
if (parentAsContent->IsInShadowTree()) {
@@ -106,7 +123,7 @@ static inline nsINode* GetFlattenedTreeParentNode(const nsINode* aNode) {
}
inline nsINode* nsINode::GetFlattenedTreeParentNode() const {
- return ::GetFlattenedTreeParentNode<nsINode::eNotForStyle>(this);
+ return ::GetFlattenedTreeParentNode<nsINode::eNormal>(this);
}
inline nsIContent* nsIContent::GetFlattenedTreeParent() const {
@@ -127,6 +144,11 @@ inline nsINode* nsINode::GetFlattenedTreeParentNodeForStyle() const {
return ::GetFlattenedTreeParentNode<nsINode::eForStyle>(this);
}
+inline nsIContent* nsINode::GetFlattenedTreeParentNodeForSelection() const {
+ nsINode* parent = ::GetFlattenedTreeParentNode<nsINode::eForSelection>(this);
+ return (parent && parent->IsContent()) ? parent->AsContent() : nullptr;
+}
+
inline bool nsINode::NodeOrAncestorHasDirAuto() const {
return AncestorHasDirAuto() || (IsElement() && AsElement()->HasDirAuto());
}