From def92d1b8e9d373e2f6f27c366d578d97d8960c6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:50 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- layout/base/PresShell.cpp | 156 +++++++++++++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 42 deletions(-) (limited to 'layout/base/PresShell.cpp') diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 31c21c3377..7674abb3d0 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -14,6 +14,7 @@ #include "mozilla/dom/AncestorIterator.h" #include "mozilla/dom/FontFaceSet.h" #include "mozilla/dom/ElementBinding.h" +#include "mozilla/dom/FragmentDirective.h" #include "mozilla/dom/LargestContentfulPaint.h" #include "mozilla/dom/MouseEventBinding.h" #include "mozilla/dom/PerformanceMainThread.h" @@ -1281,10 +1282,13 @@ void PresShell::Destroy() { ClearApproximatelyVisibleFramesList(Some(OnNonvisible::DiscardImages)); - if (mCaret) { + if (mOriginalCaret) { + mOriginalCaret->Terminate(); + } + if (mCaret && mCaret != mOriginalCaret) { mCaret->Terminate(); - mCaret = nullptr; } + mCaret = mOriginalCaret = nullptr; mFocusedFrameSelection = nullptr; @@ -2238,9 +2242,20 @@ PresShell::GetAccessibleCaretEventHub() const { return eventHub.forget(); } -void PresShell::SetCaret(nsCaret* aNewCaret) { mCaret = aNewCaret; } +void PresShell::SetCaret(nsCaret* aNewCaret) { + if (mCaret == aNewCaret) { + return; + } + if (mCaret) { + mCaret->SchedulePaint(); + } + mCaret = aNewCaret; + if (aNewCaret) { + aNewCaret->SchedulePaint(); + } +} -void PresShell::RestoreCaret() { mCaret = mOriginalCaret; } +void PresShell::RestoreCaret() { SetCaret(mOriginalCaret); } NS_IMETHODIMP PresShell::SetCaretEnabled(bool aInEnable) { bool oldEnabled = mCaretEnabled; @@ -3277,6 +3292,46 @@ nsresult PresShell::ScrollToAnchor() { ScrollAxis(), ScrollFlags::AnchorScrollFlags); } +bool PresShell::HighlightAndGoToTextFragment(bool aScrollToTextFragment) { + MOZ_ASSERT(mDocument); + if (!StaticPrefs::dom_text_fragments_enabled()) { + return false; + } + const RefPtr fragmentDirective = + mDocument->FragmentDirective(); + + nsTArray> textDirectiveRanges = + fragmentDirective->FindTextFragmentsInDocument(); + if (textDirectiveRanges.IsEmpty()) { + return false; + } + + const RefPtr targetTextSelection = + GetCurrentSelection(SelectionType::eTargetText); + if (!targetTextSelection) { + return false; + } + for (RefPtr range : textDirectiveRanges) { + targetTextSelection->AddRangeAndSelectFramesAndNotifyListeners( + *range, IgnoreErrors()); + } + if (!aScrollToTextFragment) { + return false; + } + + // Scroll the last text directive into view. + nsRange* lastRange = textDirectiveRanges.LastElement(); + MOZ_ASSERT(lastRange); + if (RefPtr lastRangeStartContent = + nsIContent::FromNode(lastRange->GetStartContainer())) { + return ScrollContentIntoView( + lastRangeStartContent, + ScrollAxis(WhereToScroll::Center, WhenToScroll::Always), + ScrollAxis(), ScrollFlags::AnchorScrollFlags) == NS_OK; + } + return false; +} + /* * Helper (per-continuation) for ScrollContentIntoView. * @@ -4473,6 +4528,26 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY void PresShell::ElementStateChanged( } } +MOZ_CAN_RUN_SCRIPT_BOUNDARY void PresShell::CustomStatesWillChange( + Element& aElement) { + if (MOZ_UNLIKELY(!mDidInitialize)) { + return; + } + + mPresContext->RestyleManager()->CustomStatesWillChange(aElement); +} + +MOZ_CAN_RUN_SCRIPT_BOUNDARY void PresShell::CustomStateChanged( + Element& aElement, nsAtom* aState) { + MOZ_ASSERT(!mIsDocumentGone, "Unexpected CustomStateChanged"); + MOZ_ASSERT(aState, "Unexpected empty state"); + + if (mDidInitialize) { + nsAutoCauseReflowNotifier crNotifier(this); + mPresContext->RestyleManager()->CustomStateChanged(aElement, aState); + } +} + void PresShell::DocumentStatesChanged(DocumentState aStateMask) { MOZ_ASSERT(!mIsDocumentGone, "Unexpected DocumentStatesChanged"); MOZ_ASSERT(mDocument); @@ -5582,7 +5657,7 @@ nsresult PresShell::SetResolutionAndScaleTo(float aResolution, // GetResolution handles mResolution being nothing by returning 1 so this // is checking that the resolution is actually changing. - bool resolutionUpdated = (aResolution != GetResolution()); + bool resolutionUpdated = aResolution != GetResolution(); mLastResolutionChangeOrigin = aOrigin; @@ -5647,7 +5722,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 +5737,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 ev = @@ -11220,8 +11298,7 @@ Maybe UseMobileViewportManager( if (nsLayoutUtils::ShouldHandleMetaViewport(aDocument)) { return Some(MobileViewportManager::ManagerType::VisualAndMetaViewport); } - if (StaticPrefs::apz_mvm_force_enabled() || - nsLayoutUtils::AllowZoomingForDocument(aDocument)) { + if (nsLayoutUtils::AllowZoomingForDocument(aDocument)) { return Some(MobileViewportManager::ManagerType::VisualViewportOnly); } return Nothing(); @@ -11244,6 +11321,11 @@ void PresShell::MaybeRecreateMobileViewportManager(bool aAfterInitialization) { return; } + if (!mPresContext->IsRootContentDocumentCrossProcess()) { + MOZ_ASSERT(!mMobileViewportManager, "We never create MVMs for subframes"); + return; + } + if (mMobileViewportManager) { // We have one, but we need to either destroy it completely to replace it // with another one of the correct type. So either way, let's destroy the @@ -11253,16 +11335,6 @@ void PresShell::MaybeRecreateMobileViewportManager(bool aAfterInitialization) { mMVMContext = nullptr; ResetVisualViewportSize(); - - // After we clear out the MVM and the MVMContext, also reset the - // resolution to its pre-MVM value. - SetResolutionAndScaleTo(mDocument->GetSavedResolutionBeforeMVM(), - ResolutionChangeOrigin::MainThreadRestore); - - if (aAfterInitialization) { - // Force a reflow to our correct view manager size. - ForceResizeReflowWithCurrentDimensions(); - } } if (mvmType) { @@ -11270,32 +11342,33 @@ void PresShell::MaybeRecreateMobileViewportManager(bool aAfterInitialization) { // have one. MOZ_ASSERT(!mMobileViewportManager); - if (mPresContext->IsRootContentDocumentCrossProcess()) { - // Store the resolution so we can restore to this resolution when - // the MVM is destroyed. - mDocument->SetSavedResolutionBeforeMVM(mResolution.valueOr(1.0f)); - - mMVMContext = new GeckoMVMContext(mDocument, this); - mMobileViewportManager = new MobileViewportManager(mMVMContext, *mvmType); - if (MOZ_UNLIKELY( - MOZ_LOG_TEST(MobileViewportManager::gLog, LogLevel::Debug))) { - nsIURI* uri = mDocument->GetDocumentURI(); - MOZ_LOG(MobileViewportManager::gLog, LogLevel::Debug, - ("Created MVM %p (type %d) for URI %s", - mMobileViewportManager.get(), (int)*mvmType, - uri ? uri->GetSpecOrDefault().get() : "(null)")); - } - - if (aAfterInitialization) { - // Setting the initial viewport will trigger a reflow. - mMobileViewportManager->SetInitialViewport(); - } + mMVMContext = new GeckoMVMContext(mDocument, this); + mMobileViewportManager = new MobileViewportManager(mMVMContext, *mvmType); + if (MOZ_UNLIKELY( + MOZ_LOG_TEST(MobileViewportManager::gLog, LogLevel::Debug))) { + nsIURI* uri = mDocument->GetDocumentURI(); + MOZ_LOG( + MobileViewportManager::gLog, LogLevel::Debug, + ("Created MVM %p (type %d) for URI %s", mMobileViewportManager.get(), + (int)*mvmType, uri ? uri->GetSpecOrDefault().get() : "(null)")); } } + if (aAfterInitialization) { + // Setting the initial viewport will trigger a reflow. + if (mMobileViewportManager) { + mMobileViewportManager->SetInitialViewport(); + } else { + // Force a reflow to our correct view manager size. + ForceResizeReflowWithCurrentDimensions(); + } + // After we clear out the MVM and the MVMContext, also reset the + // resolution to 1. + SetResolutionAndScaleTo(1.0f, ResolutionChangeOrigin::MainThreadRestore); + } } bool PresShell::UsesMobileViewportSizing() const { - return mMobileViewportManager != nullptr && + return mMobileViewportManager && nsLayoutUtils::ShouldHandleMetaViewport(mDocument); } @@ -11708,8 +11781,7 @@ static bool IsTopLevelWidget(nsIWidget* aWidget) { auto windowType = aWidget->GetWindowType(); return windowType == WindowType::TopLevel || - windowType == WindowType::Dialog || windowType == WindowType::Popup || - windowType == WindowType::Sheet; + windowType == WindowType::Dialog || windowType == WindowType::Popup; } PresShell::WindowSizeConstraints PresShell::GetWindowSizeConstraints() { -- cgit v1.2.3