Bug 1867058 - Part 11: Ensure nsIFrame::SelectionStateChanged is called for frames in shadow tree. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D202317
This commit is contained in:
Sean Feng 2024-03-25 13:41:00 +00:00
parent 934bb0536d
commit 3dfa56ace9
2 changed files with 23 additions and 2 deletions

View File

@ -26,6 +26,7 @@
#include "mozilla/dom/SelectionBinding.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/StaticRange.h"
#include "mozilla/dom/ShadowIncludingTreeIterator.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/HTMLEditor.h"
#include "mozilla/IntegerRange.h"
@ -1724,6 +1725,16 @@ nsresult Selection::SelectFramesOfInclusiveDescendantsOfContent(
return NS_OK;
}
void Selection::SelectFramesOfShadowIncludingDescendantsOfContent(
nsIContent* aContent, bool aSelected) const {
MOZ_ASSERT(aContent);
MOZ_ASSERT(StaticPrefs::dom_shadowdom_selection_across_boundary_enabled());
for (nsINode* node : ShadowIncludingTreeIterator(*aContent)) {
nsIContent* innercontent = node->IsContent() ? node->AsContent() : nullptr;
SelectFramesOf(innercontent, aSelected);
}
}
void Selection::SelectFramesInAllRanges(nsPresContext* aPresContext) {
// this method is currently only called in a user-initiated context.
// therefore it is safe to assume that we are not in a Highlight selection
@ -1845,8 +1856,12 @@ nsresult Selection::SelectFrames(nsPresContext* aPresContext,
MOZ_DIAGNOSTIC_ASSERT(subtreeIter.GetCurrentNode());
if (nsIContent* const content =
nsIContent::FromNodeOrNull(subtreeIter.GetCurrentNode())) {
SelectFramesOfInclusiveDescendantsOfContent(postOrderIter, content,
aSelect);
if (StaticPrefs::dom_shadowdom_selection_across_boundary_enabled()) {
SelectFramesOfShadowIncludingDescendantsOfContent(content, aSelect);
} else {
SelectFramesOfInclusiveDescendantsOfContent(postOrderIter, content,
aSelect);
}
}
}

View File

@ -851,6 +851,12 @@ class Selection final : public nsSupportsWeakReference,
PostContentIterator& aPostOrderIter, nsIContent* aContent,
bool aSelected) const;
/**
* https://dom.spec.whatwg.org/#concept-shadow-including-descendant
*/
void SelectFramesOfShadowIncludingDescendantsOfContent(nsIContent* aContent,
bool aSelected) const;
nsresult SelectFrames(nsPresContext* aPresContext, AbstractRange& aRange,
bool aSelect) const;