summaryrefslogtreecommitdiffstats
path: root/layout/base/PresShell.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'layout/base/PresShell.cpp')
-rw-r--r--layout/base/PresShell.cpp156
1 files changed, 114 insertions, 42 deletions
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> fragmentDirective =
+ mDocument->FragmentDirective();
+
+ nsTArray<RefPtr<nsRange>> textDirectiveRanges =
+ fragmentDirective->FindTextFragmentsInDocument();
+ if (textDirectiveRanges.IsEmpty()) {
+ return false;
+ }
+
+ const RefPtr<Selection> targetTextSelection =
+ GetCurrentSelection(SelectionType::eTargetText);
+ if (!targetTextSelection) {
+ return false;
+ }
+ for (RefPtr<nsRange> 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<nsIContent> 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<nsSynthMouseMoveEvent> ev =
@@ -11220,8 +11298,7 @@ Maybe<MobileViewportManager::ManagerType> 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() {