Bug 1886506 - Fix caret paint invalidation issues. r=sefeng

The caret position is in the DOM, and sometimes can get out of sync.

While that is an issue, it's not new: The code before the regressing bug
papered over it on a pre-pass before entering DL building.

Instead, deal with it using MarkFramesForDisplay (just like we mark the
caret frame itself, which has the same issue), and invalidate the old
frame more precisely by tracking it in nsCaret directly.

Also, add missing invalidation in PresShell::SetCaret, where the caret
might change and the old caret might not be invalidated properly.

Differential Revision: https://phabricator.services.mozilla.com/D205369
This commit is contained in:
Emilio Cobos Álvarez
2024-03-22 12:20:14 +00:00
parent 88ba84a48f
commit 3948b45eb8
5 changed files with 74 additions and 29 deletions

View File

@@ -2238,9 +2238,16 @@ PresShell::GetAccessibleCaretEventHub() const {
return eventHub.forget();
}
void PresShell::SetCaret(nsCaret* aNewCaret) { mCaret = aNewCaret; }
void PresShell::SetCaret(nsCaret* aNewCaret) {
if (mCaret == aNewCaret) {
return;
}
mCaret->SchedulePaint();
mCaret = aNewCaret;
aNewCaret->SchedulePaint();
}
void PresShell::RestoreCaret() { mCaret = mOriginalCaret; }
void PresShell::RestoreCaret() { SetCaret(mOriginalCaret); }
NS_IMETHODIMP PresShell::SetCaretEnabled(bool aInEnable) {
bool oldEnabled = mCaretEnabled;
@@ -5647,7 +5654,9 @@ void PresShell::SetRenderingState(const RenderingState& aState) {
}
void PresShell::SynthesizeMouseMove(bool aFromScroll) {
if (!StaticPrefs::layout_reflow_synthMouseMove()) return;
if (!StaticPrefs::layout_reflow_synthMouseMove()) {
return;
}
if (mPaintingSuppressed || !mIsActive || !mPresContext) {
return;
@@ -5660,8 +5669,9 @@ void PresShell::SynthesizeMouseMove(bool aFromScroll) {
return;
}
if (mMouseLocation == nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE))
if (mMouseLocation == nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)) {
return;
}
if (!mSynthMouseMoveEvent.IsPending()) {
RefPtr<nsSynthMouseMoveEvent> ev =