From 9b273777ea389c6d7faa14c1229c3e0eba06d0c9 Mon Sep 17 00:00:00 2001 From: Stanca Serban Date: Tue, 27 Aug 2024 04:23:16 +0300 Subject: [PATCH] Backed out changeset d77e541eb497 (bug 1900426) for causing mochitests failures in test_drag_drop_shadow_crossing_selection.html. CLOSED TREE --- dom/base/nsContentAreaDragDrop.cpp | 7 +- dom/base/nsContentUtils.h | 2 + dom/base/nsCopySupport.cpp | 7 +- dom/base/nsRange.cpp | 30 +---- dom/base/nsRange.h | 8 -- dom/base/test/mochitest.toml | 2 - ...t_drag_drop_shadow_crossing_selection.html | 119 ------------------ dom/serializers/nsDocumentEncoder.cpp | 19 +-- dom/webidl/Range.webidl | 1 - dom/webidl/Selection.webidl | 4 - layout/base/PresShell.cpp | 58 ++++----- .../mochitest/tests/SimpleTest/EventUtils.js | 8 +- 12 files changed, 39 insertions(+), 226 deletions(-) delete mode 100644 dom/base/test/test_drag_drop_shadow_crossing_selection.html diff --git a/dom/base/nsContentAreaDragDrop.cpp b/dom/base/nsContentAreaDragDrop.cpp index 52afd55fec5a..75bc7b26b32a 100644 --- a/dom/base/nsContentAreaDragDrop.cpp +++ b/dom/base/nsContentAreaDragDrop.cpp @@ -830,12 +830,11 @@ nsresult DragDataProducer::GetDraggableSelectionData( *outImageOrLinkNode = nullptr; *outDragSelectedText = false; - if (!inSelection->AreNormalAndCrossShadowBoundaryRangesCollapsed()) { + if (!inSelection->IsCollapsed()) { if (inSelection->ContainsNode(*inRealTargetNode, false, IgnoreErrors())) { // track down the anchor node, if any, for the url - nsINode* selectionStart = - inSelection->GetMayCrossShadowBoundaryAnchorNode(); - nsINode* selectionEnd = inSelection->GetMayCrossShadowBoundaryFocusNode(); + nsINode* selectionStart = inSelection->GetAnchorNode(); + nsINode* selectionEnd = inSelection->GetFocusNode(); // look for a selection around a single node, like an image. // in this case, drag the image, rather than a serialization of the HTML diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index a38c973eb042..0ff50b70117e 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -3605,6 +3605,8 @@ class nsContentUtils { aCallback); static nsINode* GetCommonAncestorHelper(nsINode* aNode1, nsINode* aNode2); + static nsINode* GetCommonShadowIncludingAncestorHelper(nsINode* aNode1, + nsINode* aNode2); static nsIContent* GetCommonFlattenedTreeAncestorHelper( nsIContent* aContent1, nsIContent* aContent2); diff --git a/dom/base/nsCopySupport.cpp b/dom/base/nsCopySupport.cpp index 294518982079..c5ec3cd206b4 100644 --- a/dom/base/nsCopySupport.cpp +++ b/dom/base/nsCopySupport.cpp @@ -404,12 +404,7 @@ nsresult nsCopySupport::GetTransferableForSelection( NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(aTransferable, NS_ERROR_NULL_POINTER); - const uint32_t additionalFlags = - StaticPrefs::dom_shadowdom_selection_across_boundary_enabled() - ? nsIDocumentEncoder::SkipInvisibleContent | - nsIDocumentEncoder::AllowCrossShadowBoundary - : nsIDocumentEncoder::SkipInvisibleContent; - + const uint32_t additionalFlags = nsIDocumentEncoder::SkipInvisibleContent; return EncodeDocumentWithContextAndCreateTransferable( *aDoc, aSel, additionalFlags, aTransferable); } diff --git a/dom/base/nsRange.cpp b/dom/base/nsRange.cpp index ed837fafc711..bbdc90233dc3 100644 --- a/dom/base/nsRange.cpp +++ b/dom/base/nsRange.cpp @@ -3023,19 +3023,6 @@ already_AddRefed nsRange::GetBoundingClientRect(bool aClampToEdge, already_AddRefed nsRange::GetClientRects(bool aClampToEdge, bool aFlushLayout) { - return GetClientRectsInner(AllowRangeCrossShadowBoundary::No, aClampToEdge, - aFlushLayout); -} - -already_AddRefed nsRange::GetAllowCrossShadowBoundaryClientRects( - bool aClampToEdge, bool aFlushLayout) { - return GetClientRectsInner(AllowRangeCrossShadowBoundary::Yes, aClampToEdge, - aFlushLayout); -} - -already_AddRefed nsRange::GetClientRectsInner( - AllowRangeCrossShadowBoundary aAllowCrossShadowBoundaryRange, - bool aClampToEdge, bool aFlushLayout) { if (!mIsPositioned) { return nullptr; } @@ -3044,20 +3031,11 @@ already_AddRefed nsRange::GetClientRectsInner( nsLayoutUtils::RectListBuilder builder(rectList); - const auto& startRef = - aAllowCrossShadowBoundaryRange == AllowRangeCrossShadowBoundary::Yes - ? MayCrossShadowBoundaryStartRef() - : mStart; - const auto& endRef = - aAllowCrossShadowBoundaryRange == AllowRangeCrossShadowBoundary::Yes - ? MayCrossShadowBoundaryEndRef() - : mEnd; - CollectClientRectsAndText( - &builder, nullptr, this, startRef.Container(), - *startRef.Offset(RangeBoundary::OffsetFilter::kValidOffsets), - endRef.Container(), - *endRef.Offset(RangeBoundary::OffsetFilter::kValidOffsets), aClampToEdge, + &builder, nullptr, this, mStart.Container(), + *mStart.Offset(RangeBoundary::OffsetFilter::kValidOffsets), + mEnd.Container(), + *mEnd.Offset(RangeBoundary::OffsetFilter::kValidOffsets), aClampToEdge, aFlushLayout); return rectList.forget(); } diff --git a/dom/base/nsRange.h b/dom/base/nsRange.h index 0ba5362e0d25..119d5f6ac6d5 100644 --- a/dom/base/nsRange.h +++ b/dom/base/nsRange.h @@ -264,10 +264,6 @@ class nsRange final : public mozilla::dom::AbstractRange, bool aFlushLayout = true); already_AddRefed GetClientRects(bool aClampToEdge = true, bool aFlushLayout = true); - // ChromeOnly - already_AddRefed GetAllowCrossShadowBoundaryClientRects( - bool aClampToEdge = true, bool aFlushLayout = true); - void GetClientRectsAndTexts(mozilla::dom::ClientRectsAndTexts& aResult, ErrorResult& aErr); @@ -372,10 +368,6 @@ class nsRange final : public mozilla::dom::AbstractRange, */ bool IsPartOfOneSelectionOnly() const { return mSelections.Length() == 1; }; - already_AddRefed GetClientRectsInner( - AllowRangeCrossShadowBoundary = AllowRangeCrossShadowBoundary::No, - bool aClampToEdge = true, bool aFlushLayout = true); - public: /** * This helper function gets rects and correlated text for the given range. diff --git a/dom/base/test/mochitest.toml b/dom/base/test/mochitest.toml index 0c3c9e0186fb..b89c39b0f6a8 100644 --- a/dom/base/test/mochitest.toml +++ b/dom/base/test/mochitest.toml @@ -1243,8 +1243,6 @@ skip-if = [ ["test_domwindowutils.html"] skip-if = ["os == 'android'"] # Bug 1525959 -["test_drag_drop_shadow_crossing_selection.html"] - ["test_element.matches.html"] ["test_elementTraversal.html"] diff --git a/dom/base/test/test_drag_drop_shadow_crossing_selection.html b/dom/base/test/test_drag_drop_shadow_crossing_selection.html deleted file mode 100644 index 27b7a000c969..000000000000 --- a/dom/base/test/test_drag_drop_shadow_crossing_selection.html +++ /dev/null @@ -1,119 +0,0 @@ - -Test dnd for shadow-crossing selection - - - - -
- Outer1 -
- -
- Outer2 -
- -
-
- - - diff --git a/dom/serializers/nsDocumentEncoder.cpp b/dom/serializers/nsDocumentEncoder.cpp index ea5c6de77e58..33a2d1843fbe 100644 --- a/dom/serializers/nsDocumentEncoder.cpp +++ b/dom/serializers/nsDocumentEncoder.cpp @@ -1588,8 +1588,9 @@ class nsHTMLCopyEncoder : public nsDocumentEncoder { nsINode* aCommon); static nsCOMPtr GetChildAt(nsINode* aParent, int32_t aOffset); static bool IsMozBR(Element* aNode); - nsresult GetNodeLocation(nsINode* inChild, nsCOMPtr* outParent, - int32_t* outOffset); + static nsresult GetNodeLocation(nsINode* inChild, + nsCOMPtr* outParent, + int32_t* outOffset); bool IsRoot(nsINode* aNode); static bool IsFirstNode(nsINode* aNode); static bool IsLastNode(nsINode* aNode); @@ -2043,15 +2044,7 @@ nsresult nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsINode* aNode, node = parent; rv = GetNodeLocation(node, address_of(parent), &offset); NS_ENSURE_SUCCESS(rv, rv); - - // When node is the shadow root and parent is the shadow host, - // the offset would also be -1, and we'd like to keep going. - const bool isGeneratedContent = - offset == -1 && - ShadowDOMSelectionHelpers::GetShadowRoot( - parent, - mFlags & nsIDocumentEncoder::AllowCrossShadowBoundary) != node; - if (isGeneratedContent) // we hit generated content; STOP + if (offset == -1) // we hit generated content; STOP { // back up a bit parent = node; @@ -2103,9 +2096,7 @@ nsresult nsHTMLCopyEncoder::GetNodeLocation(nsINode* inChild, return NS_ERROR_NULL_POINTER; } - nsINode* parent = mFlags & nsIDocumentEncoder::AllowCrossShadowBoundary - ? child->GetParentOrShadowHostNode() - : child->GetParent(); + nsIContent* parent = child->GetParent(); if (!parent) { return NS_ERROR_NULL_POINTER; } diff --git a/dom/webidl/Range.webidl b/dom/webidl/Range.webidl index eb8fe6f0dcb3..95dff7721ad2 100644 --- a/dom/webidl/Range.webidl +++ b/dom/webidl/Range.webidl @@ -82,7 +82,6 @@ partial interface Range { // http://dvcs.w3.org/hg/csswg/raw-file/tip/cssom-view/Overview.html#extensions-to-the-range-interface partial interface Range { DOMRectList? getClientRects(); - [ChromeOnly] DOMRectList? getAllowCrossShadowBoundaryClientRects(); DOMRect getBoundingClientRect(); }; diff --git a/dom/webidl/Selection.webidl b/dom/webidl/Selection.webidl index 259eb07d8c71..cee1f50ded4f 100644 --- a/dom/webidl/Selection.webidl +++ b/dom/webidl/Selection.webidl @@ -23,10 +23,6 @@ interface Selection { readonly attribute boolean isCollapsed; [ChromeOnly] readonly attribute boolean areNormalAndCrossShadowBoundaryRangesCollapsed; - - [ChromeOnly] - readonly attribute Node? mayCrossShadowBoundaryFocusNode; - /** * Returns the number of ranges in the selection. */ diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 852534ce0b52..3ffe8327cd8b 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -231,6 +231,7 @@ PresShell::CapturingContentInfo PresShell::sCapturingContentInfo; // RangePaintInfo is used to paint ranges to offscreen buffers struct RangePaintInfo { + RefPtr mRange; nsDisplayListBuilder mBuilder; nsDisplayList mList; @@ -242,8 +243,9 @@ struct RangePaintInfo { // to paint them at this resolution. float mResolution = 1.0; - explicit RangePaintInfo(nsIFrame* aFrame) - : mBuilder(aFrame, nsDisplayListBuilderMode::Painting, false), + RangePaintInfo(nsRange* aRange, nsIFrame* aFrame) + : mRange(aRange), + mBuilder(aFrame, nsDisplayListBuilderMode::Painting, false), mList(&mBuilder) { MOZ_COUNT_CTOR(RangePaintInfo); mBuilder.BeginFrame(); @@ -4775,27 +4777,24 @@ nsRect PresShell::ClipListToRange(nsDisplayListBuilder* aBuilder, nsIFrame* frame = i->Frame(); nsIContent* content = frame->GetContent(); if (content) { - bool atStart = - content == aRange->GetMayCrossShadowBoundaryStartContainer(); - bool atEnd = content == aRange->GetMayCrossShadowBoundaryEndContainer(); + bool atStart = (content == aRange->GetStartContainer()); + bool atEnd = (content == aRange->GetEndContainer()); if ((atStart || atEnd) && frame->IsTextFrame()) { auto [frameStartOffset, frameEndOffset] = frame->GetOffsets(); - int32_t highlightStart = - atStart ? std::max(static_cast( - aRange->MayCrossShadowBoundaryStartOffset()), + int32_t hilightStart = + atStart ? std::max(static_cast(aRange->StartOffset()), frameStartOffset) : frameStartOffset; - int32_t highlightEnd = - atEnd ? std::min(static_cast( - aRange->MayCrossShadowBoundaryEndOffset()), + int32_t hilightEnd = + atEnd ? std::min(static_cast(aRange->EndOffset()), frameEndOffset) : frameEndOffset; - if (highlightStart < highlightEnd) { + if (hilightStart < hilightEnd) { // determine the location of the start and end edges of the range. nsPoint startPoint, endPoint; - frame->GetPointFromOffset(highlightStart, &startPoint); - frame->GetPointFromOffset(highlightEnd, &endPoint); + frame->GetPointFromOffset(hilightStart, &startPoint); + frame->GetPointFromOffset(hilightEnd, &endPoint); // The clip rectangle is determined by taking the the start and // end points of the range, offset from the reference frame. @@ -4829,9 +4828,8 @@ nsRect PresShell::ClipListToRange(nsDisplayListBuilder* aBuilder, // Don't try to descend into subdocuments. // If this ever changes we'd need to add handling for subdocuments with // different zoom levels. - else if (content->GetComposedDoc() == - aRange->GetMayCrossShadowBoundaryStartContainer() - ->GetComposedDoc()) { + else if (content->GetUncomposedDoc() == + aRange->GetStartContainer()->GetUncomposedDoc()) { // if the node is within the range, append it to the temporary list bool before, after; nsresult rv = @@ -4876,18 +4874,14 @@ UniquePtr PresShell::CreateRangePaintInfo( // If the start or end of the range is the document, just use the root // frame, otherwise get the common ancestor of the two endpoints of the // range. - nsINode* startContainer = aRange->GetMayCrossShadowBoundaryStartContainer(); - nsINode* endContainer = aRange->GetMayCrossShadowBoundaryEndContainer(); + nsINode* startContainer = aRange->GetStartContainer(); + nsINode* endContainer = aRange->GetEndContainer(); Document* doc = startContainer->GetComposedDoc(); if (startContainer == doc || endContainer == doc) { ancestorFrame = rootFrame; } else { - nsINode* ancestor = - StaticPrefs::dom_shadowdom_selection_across_boundary_enabled() - ? nsContentUtils::GetClosestCommonShadowIncludingInclusiveAncestor( - startContainer, endContainer) - : nsContentUtils::GetClosestCommonInclusiveAncestor(startContainer, - endContainer); + nsINode* ancestor = nsContentUtils::GetClosestCommonInclusiveAncestor( + startContainer, endContainer); NS_ASSERTION(!ancestor || ancestor->IsContent(), "common ancestor is not content"); @@ -4912,7 +4906,7 @@ UniquePtr PresShell::CreateRangePaintInfo( } // get a display list containing the range - auto info = MakeUnique(ancestorFrame); + auto info = MakeUnique(aRange, ancestorFrame); info->mBuilder.SetIncludeAllOutOfFlows(); if (aForPrimarySelection) { info->mBuilder.SetSelectedFramesOnly(); @@ -4920,9 +4914,7 @@ UniquePtr PresShell::CreateRangePaintInfo( info->mBuilder.EnterPresShell(ancestorFrame); ContentSubtreeIterator subtreeIter; - nsresult rv = StaticPrefs::dom_shadowdom_selection_across_boundary_enabled() - ? subtreeIter.InitWithAllowCrossShadowBoundary(aRange) - : subtreeIter.Init(aRange); + nsresult rv = subtreeIter.Init(aRange); if (NS_FAILED(rv)) { return nullptr; } @@ -4945,13 +4937,7 @@ UniquePtr PresShell::CreateRangePaintInfo( } for (; !subtreeIter.IsDone(); subtreeIter.Next()) { nsCOMPtr node = subtreeIter.GetCurrentNode(); - if (StaticPrefs::dom_shadowdom_selection_across_boundary_enabled()) { - for (nsINode* node : ShadowIncludingTreeIterator(*node)) { - BuildDisplayListForNode(node); - } - } else { - BuildDisplayListForNode(node); - } + BuildDisplayListForNode(node); } if (endContainer != startContainer && endContainer->NodeType() == nsINode::TEXT_NODE) { diff --git a/testing/mochitest/tests/SimpleTest/EventUtils.js b/testing/mochitest/tests/SimpleTest/EventUtils.js index 2c2a2c23fe50..8bd794c3d0e5 100644 --- a/testing/mochitest/tests/SimpleTest/EventUtils.js +++ b/testing/mochitest/tests/SimpleTest/EventUtils.js @@ -3386,9 +3386,7 @@ function _nodeIsFlattenedTreeDescendantOf( } function _computeSrcElementFromSrcSelection(aSrcSelection) { - let srcElement = _EU_maybeUnwrap( - _EU_maybeWrap(aSrcSelection).mayCrossShadowBoundaryFocusNode - ); + let srcElement = aSrcSelection.focusNode; while (_EU_maybeWrap(srcElement).isNativeAnonymous) { srcElement = _getFlattenedTreeParentNode(srcElement); } @@ -3490,9 +3488,7 @@ async function synthesizePlainDragAndDrop(aParams) { } // Use last selection client rect because nsIDragSession.sourceNode is // initialized from focus node which is usually in last rect. - let selectionRectList = SpecialPowers.wrap( - srcSelection.getRangeAt(0) - ).getAllowCrossShadowBoundaryClientRects(); + let selectionRectList = srcSelection.getRangeAt(0).getClientRects(); let lastSelectionRect = selectionRectList[selectionRectList.length - 1]; if (logFunc) { logFunc(