Bug 85686 - Mimic Chromium's getSelection().toString() behaviour r=masayuki,dom-core,webidl,smaug

Basically when getSelection().toString() is called, Chromium may
return an serialization on a different content than Firefox.
This patch tries to address this webcompat issue by mimicing
the same behaviour.

We should still address the spec issues, but this seems to be
an acceptable compromise.

Differential Revision: https://phabricator.services.mozilla.com/D239657
This commit is contained in:
Sean Feng
2025-03-17 13:36:16 +00:00
parent 81c8815d7d
commit e46b69d89c
26 changed files with 370 additions and 44 deletions

View File

@@ -1408,7 +1408,10 @@ nsresult nsFrameSelection::TakeFocus(nsIContent& aNewFocus,
__FUNCTION__, &aNewFocus, aContentOffset, aContentEndOffset,
static_cast<int>(aHint), static_cast<int>(aFocusMode)));
mPresShell->FrameSelectionWillTakeFocus(*this);
mPresShell->FrameSelectionWillTakeFocus(
*this, aNewFocus.CanStartSelectionAsWebCompatHack()
? PresShell::CanMoveLastSelectionForToString::Yes
: PresShell::CanMoveLastSelectionForToString::No);
// Clear all table selection data
mTableSelection.mMode = TableSelectionMode::None;
@@ -3115,7 +3118,16 @@ void nsFrameSelection::DisconnectFromPresShell() {
MOZ_ASSERT(mDomSelections[i]);
mDomSelections[i]->Clear(nullptr);
}
mPresShell = nullptr;
if (auto* presshell = mPresShell) {
if (const nsFrameSelection* sel =
presshell->GetLastSelectionForToString()) {
if (sel == this) {
presshell->UpdateLastSelectionForToString(nullptr);
}
}
mPresShell = nullptr;
}
}
#ifdef XP_MACOSX