commit ba0e228d4f7b04b68d872b2465eb3fc0488ffa02 parent 585dadcba78a20783fac6dd1aac2aee515c726f2 Author: Emilio Cobos Álvarez <emilio@crisal.io> Date: Fri, 28 Nov 2025 10:45:48 +0000 Bug 2000639 - Remove nsViewManager. r=jwatt After the previous patches, nsViewManager is basically a backpointer to its pres shell. Remove it and just make PresShell manage the root view directly. After this is done, we can decide what to do about nsView (which is itself little more than a widget listener that forwards to pres shell right now). This technically starts listening to mParentWidget slightly later (on pres shell creation), but I think that's ok. Differential Revision: https://phabricator.services.mozilla.com/D272890 Diffstat:
38 files changed, 82 insertions(+), 567 deletions(-)
diff --git a/accessible/generic/DocAccessible.cpp b/accessible/generic/DocAccessible.cpp @@ -33,7 +33,6 @@ #include "nsIInterfaceRequestorUtils.h" #include "nsImageFrame.h" #include "nsIMutationObserver.h" -#include "nsViewManager.h" #include "nsIURI.h" #include "nsIWebNavigation.h" #include "nsFocusManager.h" diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp @@ -234,8 +234,6 @@ #include "nsSubDocumentFrame.h" #include "nsURILoader.h" #include "nsURLHelper.h" -#include "nsView.h" -#include "nsViewManager.h" #include "nsViewSourceHandler.h" #include "nsWebBrowserFind.h" #include "nsWhitespaceTokenizer.h" @@ -7735,9 +7733,6 @@ nsresult nsDocShell::RestoreFromHistory() { pc->RecomputeBrowsingContextDependentData(); } - nsViewManager* newVM = presShell ? presShell->GetViewManager() : nullptr; - nsView* newRootView = newVM ? newVM->GetRootView() : nullptr; - nsCOMPtr<nsPIDOMWindowInner> privWinInner = privWin->GetCurrentInnerWindow(); // If parent is suspended, increase suspension count. @@ -7774,7 +7769,7 @@ nsresult nsDocShell::RestoreFromHistory() { // presentation. If this is not the same size we showed it at last time, // then we need to resize the widget. - if (newRootView) { + if (presShell) { if (!newBounds.IsEmpty() && !newBounds.ToUnknownRect().IsEqualEdges(oldBounds)) { MOZ_LOG(gPageCacheLog, LogLevel::Debug, @@ -7787,11 +7782,6 @@ nsresult nsDocShell::RestoreFromHistory() { } } - // The FinishRestore call below can kill these, null them out so we don't - // have invalid pointer lying around. - newRootView = nullptr; - newVM = nullptr; - // If the IsUnderHiddenEmbedderElement() state has been changed, we need to // update it. if (oldPresShell && presShell && diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp @@ -7514,8 +7514,7 @@ static inline void AssertNoStaleServoDataIn(nsINode& aSubtreeRoot) { } already_AddRefed<PresShell> Document::CreatePresShell( - nsPresContext* aContext, nsViewManager* aViewManager, - nsSubDocumentFrame* aEmbedderFrame) { + nsPresContext* aContext, nsSubDocumentFrame* aEmbedderFrame) { MOZ_DIAGNOSTIC_ASSERT(!mPresShell, "We have a presshell already!"); NS_ENSURE_FALSE(GetBFCacheEntry(), nullptr); @@ -7536,7 +7535,7 @@ already_AddRefed<PresShell> Document::CreatePresShell( FillStyleSet(); } - presShell->Init(aContext, aViewManager); + presShell->Init(aContext); if (RefPtr<class HighlightRegistry> highlightRegistry = mHighlightRegistry) { highlightRegistry->AddHighlightSelectionsToFrameSelection(); } diff --git a/dom/base/Document.h b/dom/base/Document.h @@ -1211,8 +1211,7 @@ class Document : public nsINode, * presshell if the presshell should observe document mutations. */ MOZ_CAN_RUN_SCRIPT already_AddRefed<PresShell> CreatePresShell( - nsPresContext* aContext, nsViewManager* aViewManager, - nsSubDocumentFrame* aEmbedderFrame); + nsPresContext* aContext, nsSubDocumentFrame* aEmbedderFrame); void DeletePresShell(); PresShell* GetPresShell() const { diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp @@ -201,7 +201,6 @@ #include "nsTArray.h" #include "nsTextNode.h" #include "nsThreadUtils.h" -#include "nsViewManager.h" #include "nsWindowSizes.h" #include "nsXULElement.h" diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp @@ -79,7 +79,6 @@ #include "nsTableWrapperFrame.h" #include "nsTextFrame.h" #include "nsThreadUtils.h" -#include "nsViewManager.h" #ifdef ACCESSIBILITY # include "nsAccessibilityService.h" diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp @@ -66,7 +66,7 @@ #include "nsSandboxFlags.h" #include "nsString.h" #include "nsStringFwd.h" -#include "nsViewManager.h" +#include "nsView.h" #include "nsWidgetsCID.h" using namespace mozilla; using namespace mozilla::css; @@ -914,7 +914,7 @@ nsresult nsContentSink::WillParseImpl(void) { uint32_t currentTime = PR_IntervalToMicroseconds(PR_IntervalNow()); if (StaticPrefs::content_sink_enable_perf_mode() == 0) { - uint32_t lastEventTime = nsViewManager::GetLastUserEventTime(); + uint32_t lastEventTime = nsView::GetLastUserEventTime(); bool newDynLower = mDocument->IsInBackgroundWindow() || ((currentTime - mBeginLoadTime) > StaticPrefs::content_sink_initial_perf_time() && diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp @@ -74,7 +74,6 @@ #include "nsQueryObject.h" #include "nsRefreshDriver.h" #include "nsStyleUtil.h" -#include "nsViewManager.h" #if defined(MOZ_WIDGET_GTK) # include <gdk/gdk.h> @@ -423,15 +422,12 @@ nsDOMWindowUtils::GetDocumentMetadata(const nsAString& aName, NS_IMETHODIMP nsDOMWindowUtils::UpdateLayerTree() { FlushLayoutWithoutThrottledAnimations(); - if (RefPtr<PresShell> presShell = GetPresShell()) { - RefPtr<nsViewManager> vm = presShell->GetViewManager(); - if (nsView* view = vm->GetRootView()) { - nsAutoScriptBlocker scriptBlocker; - presShell->PaintAndRequestComposite( - presShell->GetRootFrame(), view->GetWidget()->GetWindowRenderer(), - PaintFlags::PaintSyncDecodeImages); - presShell->GetWindowRenderer()->WaitOnTransactionProcessed(); - } + if (RefPtr<PresShell> ps = GetPresShell()) { + nsAutoScriptBlocker scriptBlocker; + RefPtr renderer = ps->GetWindowRenderer(); + ps->PaintAndRequestComposite(ps->GetRootFrame(), renderer, + PaintFlags::PaintSyncDecodeImages); + renderer->WaitOnTransactionProcessed(); } return NS_OK; } diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp @@ -118,7 +118,6 @@ #include "nsSubDocumentFrame.h" #include "nsThreadUtils.h" #include "nsUnicharUtils.h" -#include "nsViewManager.h" #include "nsXPCOMPrivate.h" // for XUL_DLL #include "nsXULPopupManager.h" #include "prenv.h" @@ -984,7 +983,7 @@ bool nsFrameLoader::Show(nsSubDocumentFrame* aFrame) { } } aFrame->EnsureEmbeddingPresShell(presShell); - MOZ_DIAGNOSTIC_ASSERT(presShell->GetViewManager()->GetRootView()); + MOZ_DIAGNOSTIC_ASSERT(presShell->GetRootView()); } RefPtr<nsDocShell> baseWindow = GetDocShell(); diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp @@ -172,8 +172,6 @@ #include "nsQueryObject.h" #include "nsServiceManagerUtils.h" #include "nsThreadUtils.h" -#include "nsView.h" -#include "nsViewManager.h" #include "xpcprivate.h" #ifdef NS_PRINTING diff --git a/dom/view-transitions/ViewTransition.cpp b/dom/view-transitions/ViewTransition.cpp @@ -31,7 +31,6 @@ #include "nsLayoutUtils.h" #include "nsPresContext.h" #include "nsString.h" -#include "nsViewManager.h" namespace mozilla::dom { diff --git a/layout/base/MobileViewportManager.cpp b/layout/base/MobileViewportManager.cpp @@ -16,7 +16,6 @@ #include "mozilla/dom/InteractiveWidget.h" #include "nsIFrame.h" #include "nsLayoutUtils.h" -#include "nsViewManager.h" #include "nsViewportInfo.h" mozilla::LazyLogModule MobileViewportManager::gLog("apz.mobileviewport"); diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp @@ -198,7 +198,6 @@ #include "nsTreeBodyFrame.h" #include "nsTreeColumns.h" #include "nsView.h" -#include "nsViewManager.h" #include "nsViewportInfo.h" #include "nsWindowSizes.h" #include "nsXPCOM.h" @@ -670,7 +669,6 @@ bool PresShell::AccessibleCaretEnabled(nsIDocShell* aDocShell) { PresShell::PresShell(Document* aDocument) : mDocument(aDocument), - mViewManager(nullptr), mLastSelectionForToString(nullptr), #ifdef ACCESSIBILITY mDocAccessible(nullptr), @@ -791,13 +789,12 @@ PresShell::~PresShell() { * Note this can't be merged into our constructor because caret initialization * calls AddRef() on us. */ -void PresShell::Init(nsPresContext* aPresContext, nsViewManager* aViewManager) { +void PresShell::Init(nsPresContext* aPresContext) { MOZ_ASSERT(mDocument); MOZ_ASSERT(aPresContext); - MOZ_ASSERT(aViewManager); - MOZ_ASSERT(!mViewManager, "already initialized"); + MOZ_ASSERT(!mRootView, "Already initialized"); - mViewManager = aViewManager; + mRootView = MakeUnique<nsView>(this); // mDocument is now set. It might have a display document whose "need layout/ // style" flush flags are not set, but ours will be set. To keep these @@ -809,9 +806,6 @@ void PresShell::Init(nsPresContext* aPresContext, nsViewManager* aViewManager) { // Create our frame constructor. mFrameConstructor = MakeUnique<nsCSSFrameConstructor>(mDocument, this); - // The document viewer owns both view manager and pres shell. - mViewManager->SetPresShell(this); - // Bind the context to the presentation shell. // FYI: We cannot initialize mPresContext in the constructor because we // cannot call AttachPresShell() in it and once we initialize @@ -1260,15 +1254,7 @@ void PresShell::Destroy() { mAccessibleCaretEventHub = nullptr; } - if (mViewManager) { - if (auto* root = mViewManager->GetRootView()) { - root->Destroy(); - } - // Clear the view manager's weak pointer back to |this| in case it - // was leaked. - mViewManager->SetPresShell(nullptr); - mViewManager = nullptr; - } + mRootView = nullptr; if (mPresContext) { // We hold a reference to the pres context, and it holds a weak link back @@ -4406,7 +4392,7 @@ void PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush aFlush) { } MOZ_DIAGNOSTIC_ASSERT(!mIsDestroying || !isSafeToFlush); - MOZ_DIAGNOSTIC_ASSERT(mIsDestroying || mViewManager); + MOZ_DIAGNOSTIC_ASSERT(mIsDestroying || mRootView); MOZ_DIAGNOSTIC_ASSERT(mIsDestroying || mDocument->HasShellOrBFCacheEntry()); if (!isSafeToFlush) { @@ -5632,7 +5618,6 @@ struct PaintParams { }; WindowRenderer* PresShell::GetWindowRenderer() { - NS_ASSERTION(mViewManager, "Should have view manager"); if (nsIWidget* widget = GetOwnWidget()) { return widget->GetWindowRenderer(); } @@ -5650,11 +5635,8 @@ nsIWidget* PresShell::GetNearestWidget() const { } nsIWidget* PresShell::GetOwnWidget() const { - if (!mViewManager) { - return nullptr; - } - if (auto* root = mViewManager->GetRootView()) { - return root->GetWidget(); + if (mRootView) { + return mRootView->GetWidget(); } return nullptr; } diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h @@ -78,7 +78,6 @@ class nsRegion; class nsTextFrame; class nsSubDocumentFrame; class nsView; -class nsViewManager; class nsWindowSizes; class WeakFrame; class ZoomConstraintsClient; @@ -243,7 +242,7 @@ class PresShell final : public nsStubDocumentObserver, return mLastOverWindowPointerLocation; } - MOZ_CAN_RUN_SCRIPT void Init(nsPresContext*, nsViewManager*); + MOZ_CAN_RUN_SCRIPT void Init(nsPresContext*); /** * All callers are responsible for calling |Destroy| after calling @@ -312,7 +311,7 @@ class PresShell final : public nsStubDocumentObserver, */ PresShell* GetRootPresShell() const; - nsViewManager* GetViewManager() const { return mViewManager; } + nsView* GetRootView() const { return mRootView.get(); } nsRefreshDriver* GetRefreshDriver() const; @@ -3204,7 +3203,9 @@ class PresShell final : public nsStubDocumentObserver, MOZ_KNOWN_LIVE RefPtr<Document> const mDocument; MOZ_KNOWN_LIVE RefPtr<nsPresContext> const mPresContext; UniquePtr<nsCSSFrameConstructor> mFrameConstructor; - nsViewManager* mViewManager; // [WEAK] docViewer owns it so I don't have to + // The object responsible for listening to widget events. + // TODO(emilio): Find a better name or remove altogether. + UniquePtr<nsView> mRootView; RefPtr<nsFrameSelection> mSelection; // The frame selection that last took focus on this shell, which we need to // hide if we focus another selection. May or may not be the same as diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp @@ -106,7 +106,6 @@ #include "nsTextNode.h" #include "nsTransitionManager.h" #include "nsUnicharUtils.h" -#include "nsViewManager.h" #include "nsXULElement.h" #ifdef XP_MACOSX diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp @@ -90,7 +90,6 @@ #include "nsSandboxFlags.h" #include "nsStyleSheetService.h" #include "nsView.h" -#include "nsViewManager.h" #include "nsXULPopupManager.h" //-------------------------- @@ -334,10 +333,6 @@ class nsDocumentViewer final : public nsIDocumentViewer, virtual ~nsDocumentViewer(); private: - /** - * Creates a view manager, root view, and widget for the root view, setting - * mViewManager and mWindow. - */ void MakeWindow(); nsresult CreateDeviceContext(nsSubDocumentFrame* aContainerFrame); @@ -381,9 +376,12 @@ class nsDocumentViewer final : public nsIDocumentViewer, std::tuple<const nsIFrame*, int32_t> GetCurrentSheetFrameAndNumber() const; protected: - // Returns the current viewmanager. Might be null. - nsViewManager* GetViewManager(); - + // This will make mPresShell stop listener to any widget it's currently + // listening to, and start listening to mWindow for events. Note that + // the previous mWindow listener might be kept around as the + // PreviouslyAttachedWidgetListener so that we are able to paint the old page + // while the new one loads. + void AttachToTopLevelWidget(); void DetachFromTopLevelWidget(); // IMPORTANT: The ownership implicit in the following member @@ -399,7 +397,6 @@ class nsDocumentViewer final : public nsIDocumentViewer, // so they will be destroyed in the reverse order (pinkerton, scc) nsCOMPtr<Document> mDocument; nsCOMPtr<nsIWidget> mWindow; // may be null - RefPtr<nsViewManager> mViewManager; RefPtr<nsPresContext> mPresContext; RefPtr<PresShell> mPresShell; @@ -413,7 +410,6 @@ class nsDocumentViewer final : public nsIDocumentViewer, RefPtr<BFCachePreventionObserver> mBFCachePreventionObserver; nsIWidget* mParentWidget; // purposely won't be ref counted. May be null - bool mAttachedToParent; // view is attached to the parent widget LayoutDeviceIntRect mBounds; @@ -475,7 +471,6 @@ void nsDocumentViewer::PrepareToStartLoad() { mStopped = false; mLoaded = false; - mAttachedToParent = false; mDeferredWindowClose = false; #ifdef NS_PRINTING @@ -492,7 +487,6 @@ void nsDocumentViewer::PrepareToStartLoad() { nsDocumentViewer::nsDocumentViewer() : mParentWidget(nullptr), - mAttachedToParent(false), mNumURLStarts(0), mDestroyBlockedCount(0), mStopped(false), @@ -683,13 +677,13 @@ nsresult nsDocumentViewer::InitPresentationStuff(bool aDoInitialReflow) { // Now make the shell for the document nsCOMPtr<Document> doc = mDocument; RefPtr<nsPresContext> presContext = mPresContext; - RefPtr<nsViewManager> viewManager = mViewManager; - mPresShell = - doc->CreatePresShell(presContext, viewManager, FindContainerFrame()); + mPresShell = doc->CreatePresShell(presContext, FindContainerFrame()); if (!mPresShell) { return NS_ERROR_FAILURE; } + AttachToTopLevelWidget(); + if (aDoInitialReflow) { // Since Initialize() will create frames for *all* items // that are currently in the document tree, we need to flush @@ -835,7 +829,6 @@ nsresult nsDocumentViewer::InitInternal( // this new document since doing that will cause us to re-enter // into nsSubDocumentFrame code through reflows caused by // FlushPendingNotifications() calls down the road... - MakeWindow(); Hide(); #ifdef NS_PRINT_PREVIEW @@ -882,8 +875,6 @@ nsresult nsDocumentViewer::InitInternal( } if (aDoCreation && mPresContext) { - // The ViewManager and Root View was created above (in - // MakeWindow())... rv = InitPresentationStuff(!makeCX); } @@ -1467,19 +1458,7 @@ nsDocumentViewer::Open(nsISupports* aState, nsISHEntry* aSHEntry) { // page B, we detach. So page A's view has no widget. If we then go // back to it, and it is in the bfcache, we will use that view, which // doesn't have a widget. The attach call here will properly attach us. - if (mParentWidget && mPresContext) { - // If the old view is already attached to our parent, detach - DetachFromTopLevelWidget(); - - nsViewManager* vm = GetViewManager(); - MOZ_ASSERT(vm, "no view manager"); - nsView* v = vm->GetRootView(); - MOZ_ASSERT(v, "no root view"); - MOZ_ASSERT(mParentWidget, "no mParentWidget to set"); - v->AttachToTopLevelWidget(mParentWidget); - - mAttachedToParent = true; - } + AttachToTopLevelWidget(); return NS_OK; } @@ -1725,7 +1704,6 @@ nsDocumentViewer::Destroy() { } mWindow = nullptr; - mViewManager = nullptr; mContainer = WeakPtr<nsDocShell>(); return NS_OK; @@ -1861,8 +1839,6 @@ PresShell* nsDocumentViewer::GetPresShell() { return mPresShell; } nsPresContext* nsDocumentViewer::GetPresContext() { return mPresContext; } -nsViewManager* nsDocumentViewer::GetViewManager() { return mViewManager; } - NS_IMETHODIMP nsDocumentViewer::GetBounds(LayoutDeviceIntRect& aResult) { NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); @@ -1914,11 +1890,7 @@ nsDocumentViewer::SetBoundsWithFlags(const LayoutDeviceIntRect& aBounds, bool boundsChanged = !mBounds.IsEqualEdges(aBounds); mBounds = aBounds; - if (mWindow && !mAttachedToParent) { - // Resize the widget, but don't trigger repaint. Layout will generate - // repaint requests during reflow. - mWindow->Resize(aBounds / mWindow->GetDesktopToDeviceScale(), false); - } else if (mPresContext && mViewManager) { + if (mPresContext) { // Ensure presContext's deviceContext is up to date, as we sometimes get // here before a resolution-change notification has been fully handled // during display configuration changes, especially when there are lots @@ -2021,15 +1993,6 @@ nsDocumentViewer::Show() { } } - if (mWindow) { - // When attached to a top level xul window, we do not need to call - // Show on the widget. Underlying window management code handles - // this when the window is initialized. - if (!mAttachedToParent) { - mWindow->Show(true); - } - } - // Hold on to the document so we can use it after the script blocker below // has been released (which might re-entrantly call into other // nsDocumentViewer methods). @@ -2070,8 +2033,6 @@ nsDocumentViewer::Show() { return rv; } - MakeWindow(); - if (mPresContext) { Hide(); @@ -2098,10 +2059,6 @@ nsDocumentViewer::Show() { NS_IMETHODIMP nsDocumentViewer::Hide() { - if (!mAttachedToParent && mWindow) { - mWindow->Show(false); - } - if (!mPresShell) { return NS_OK; } @@ -2142,17 +2099,9 @@ nsDocumentViewer::Hide() { DestroyPresContext(); - mViewManager = nullptr; mWindow = nullptr; mDeviceContext = nullptr; mParentWidget = nullptr; - - nsCOMPtr<nsIBaseWindow> base_win(mContainer); - - if (base_win && !mAttachedToParent) { - base_win->SetParentWidget(nullptr); - } - return NS_OK; } @@ -2185,49 +2134,22 @@ nsDocumentViewer::ClearHistoryEntry() { //------------------------------------------------------- -void nsDocumentViewer::MakeWindow() { - if (GetIsPrintPreview()) { - return; - } - - mViewManager = new nsViewManager(); - - // Create a view - nsView* view = mViewManager->CreateView(); - - // Create a widget if we were given a parent widget or don't have a - // container view that we can hook up to without a widget. - // Don't create widgets for ResourceDocs (external resources & svg images), - // because when they're displayed, they're painted into *another* document's - // widget. - if (!mDocument->IsResourceDoc()) { - MOZ_ASSERT_IF(!FindContainerFrame(), mParentWidget); - if (mParentWidget) { - // Reuse the top level parent widget. - view->AttachToTopLevelWidget(mParentWidget); - mAttachedToParent = true; - } - } - - // Setup hierarchical relationship in view manager - mViewManager->SetRootView(view); - - mWindow = view->GetWidget(); - - // This SetFocus is necessary so the Arrow Key and Page Key events - // go to the scrolled view as soon as the Window is created instead of going - // to the browser window (this enables keyboard scrolling of the document) - // mWindow->SetFocus(); -} - void nsDocumentViewer::DetachFromTopLevelWidget() { - if (mViewManager) { - nsView* oldView = mViewManager->GetRootView(); + if (mPresShell) { + nsView* oldView = mPresShell->GetRootView(); if (oldView && oldView->HasWidget()) { oldView->DetachFromTopLevelWidget(); } } - mAttachedToParent = false; +} + +void nsDocumentViewer::AttachToTopLevelWidget() { + DetachFromTopLevelWidget(); + if (mPresShell && mParentWidget) { + nsView* view = mPresShell->GetRootView(); + view->AttachToTopLevelWidget(mParentWidget); + mWindow = mParentWidget; + } } nsSubDocumentFrame* nsDocumentViewer::FindContainerFrame() { @@ -3207,7 +3129,6 @@ void nsDocumentViewer::SetIsPrintPreview(bool aIsPrintPreview) { DestroyPresShell(); } mWindow = nullptr; - mViewManager = nullptr; mPresContext = nullptr; mPresShell = nullptr; } @@ -3318,11 +3239,7 @@ NS_IMETHODIMP nsDocumentViewer::SetPrintSettingsForSubdocument( mPresContext = CreatePresContext( mDocument, nsPresContext::eContext_PrintPreview, FindContainerFrame()); mPresContext->SetPrintSettings(aPrintSettings); - rv = mPresContext->Init(mDeviceContext); - NS_ENSURE_SUCCESS(rv, rv); - - MakeWindow(); - + MOZ_TRY(mPresContext->Init(mDeviceContext)); MOZ_TRY(InitPresentationStuff(true)); } @@ -3351,7 +3268,6 @@ NS_IMETHODIMP nsDocumentViewer::SetPageModeForTesting( DestroyPresContext(); } - mViewManager = nullptr; mWindow = nullptr; NS_ENSURE_STATE(mDocument); @@ -3427,8 +3343,7 @@ void nsDocumentViewer::DestroyPresContext() { mPresContext = nullptr; } -void nsDocumentViewer::SetPrintPreviewPresentation(nsViewManager* aViewManager, - nsPresContext* aPresContext, +void nsDocumentViewer::SetPrintPreviewPresentation(nsPresContext* aPresContext, PresShell* aPresShell) { // Protect against pres shell destruction running scripts and re-entrantly // creating a new presentation. @@ -3439,16 +3354,10 @@ void nsDocumentViewer::SetPrintPreviewPresentation(nsViewManager* aViewManager, } mWindow = nullptr; - mViewManager = aViewManager; mPresContext = aPresContext; mPresShell = aPresShell; - if (mParentWidget) { - DetachFromTopLevelWidget(); - nsView* rootView = mViewManager->GetRootView(); - rootView->AttachToTopLevelWidget(mParentWidget); - mAttachedToParent = true; - } + AttachToTopLevelWidget(); } // Fires the "document-shown" event so that interested parties are aware of it. diff --git a/layout/base/nsIDocumentViewerPrint.h b/layout/base/nsIDocumentViewerPrint.h @@ -46,8 +46,7 @@ class nsIDocumentViewerPrint : public nsISupports { /** * Replaces the current presentation with print preview presentation. */ - virtual void SetPrintPreviewPresentation(nsViewManager* aViewManager, - nsPresContext* aPresContext, + virtual void SetPrintPreviewPresentation(nsPresContext* aPresContext, mozilla::PresShell* aPresShell) = 0; }; @@ -59,8 +58,7 @@ class nsIDocumentViewerPrint : public nsISupports { void IncrementDestroyBlockedCount() override; \ void DecrementDestroyBlockedCount() override; \ void OnDonePrinting() override; \ - void SetPrintPreviewPresentation(nsViewManager* aViewManager, \ - nsPresContext* aPresContext, \ + void SetPrintPreviewPresentation(nsPresContext* aPresContext, \ mozilla::PresShell* aPresShell) override; #endif /* nsIDocumentViewerPrint_h___ */ diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp @@ -95,7 +95,6 @@ #include "nsSubDocumentFrame.h" #include "nsThreadUtils.h" #include "nsTransitionManager.h" -#include "nsViewManager.h" #include "prenv.h" #ifdef ACCESSIBILITY # include "mozilla/a11y/DocAccessible.h" diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp @@ -94,7 +94,6 @@ #include "nsPresContext.h" #include "nsTextFrame.h" #include "nsTransitionManager.h" -#include "nsViewManager.h" #if defined(MOZ_WIDGET_ANDROID) # include "VRManagerChild.h" diff --git a/layout/generic/ViewportFrame.cpp b/layout/generic/ViewportFrame.cpp @@ -24,8 +24,6 @@ #include "nsLayoutUtils.h" #include "nsPlaceholderFrame.h" #include "nsSubDocumentFrame.h" -#include "nsView.h" -#include "nsViewManager.h" using namespace mozilla; diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp @@ -103,8 +103,6 @@ #include "nsStyleStructInlines.h" #include "nsTableWrapperFrame.h" #include "nsTextControlFrame.h" -#include "nsView.h" -#include "nsViewManager.h" // For triple-click pref #include "RetainedDisplayListBuilder.h" diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp @@ -108,7 +108,6 @@ #include "nsTextFrame.h" #include "nsTextPaintStyle.h" #include "nsTransitionManager.h" -#include "nsViewManager.h" namespace mozilla { diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp @@ -41,7 +41,6 @@ #include "nsQueryObject.h" #include "nsReadableUtils.h" #include "nsSubDocumentFrame.h" -#include "nsView.h" // Print Options #include "nsGkAtoms.h" @@ -84,7 +83,6 @@ static const char sPrintSettingsServiceContractID[] = #include "nsIWebBrowserChrome.h" #include "nsPageSequenceFrame.h" #include "nsRange.h" -#include "nsViewManager.h" using namespace mozilla; using namespace mozilla::dom; @@ -310,7 +308,6 @@ static void DumpPrintObjectsTree(nsPrintObject* aPO, int aLevel, FILE* aFD); static void DumpPrintObjectsList(const nsTArray<nsPrintObject*>& aDocList); static void RootFrameList(nsPresContext* aPresContext, FILE* out, const char* aPrefix); -static void DumpViews(nsIDocShell* aDocShell, FILE* out); static void DumpLayoutData(const char* aTitleStr, const char* aURLStr, nsPresContext* aPresContext, nsDeviceContext* aDC, nsIFrame* aRootFrame, nsIDocShell* aDocShell, @@ -1209,12 +1206,6 @@ nsresult nsPrintJob::SetRootView(nsPrintObject* aPO, bool aDocumentIsTopLevel, adjSize = mPrt->mPrintDC->GetDeviceSurfaceDimensions(); } - if (!aPO->mViewManager->GetRootView()) { - // Create a child window of the parent that is our "root view/window" - nsView* rootView = aPO->mViewManager->CreateView(); - aPO->mViewManager->SetRootView(rootView); - } - if (mIsCreatingPrintPreview && aDocumentIsTopLevel) { aPO->mPresContext->SetPaginatedScrolling(canCreateScrollbars); } @@ -1263,8 +1254,6 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO) { // init it with the DC MOZ_TRY(aPO->mPresContext->Init(printData->mPrintDC)); - aPO->mViewManager = new nsViewManager(); - bool doReturn = false; nsSize adjSize; nsresult rv = SetRootView(aPO.get(), documentIsTopLevel, doReturn, adjSize); @@ -1311,10 +1300,8 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO) { // in media_queries.rs for more details. RefPtr<Document> doc = aPO->mDocument; RefPtr<nsPresContext> presContext = aPO->mPresContext; - RefPtr<nsViewManager> viewManager = aPO->mViewManager; - aPO->mPresShell = - doc->CreatePresShell(presContext, viewManager, embedderFrame); + aPO->mPresShell = doc->CreatePresShell(presContext, embedderFrame); if (!aPO->mPresShell) { return NS_ERROR_FAILURE; } @@ -1337,8 +1324,8 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO) { pageSize.width, pageSize.height)); if (mIsCreatingPrintPreview && documentIsTopLevel) { - mDocViewerPrint->SetPrintPreviewPresentation( - aPO->mViewManager, aPO->mPresContext, aPO->mPresShell.get()); + mDocViewerPrint->SetPrintPreviewPresentation(aPO->mPresContext, + aPO->mPresShell.get()); } MOZ_TRY(aPO->mPresShell->Initialize()); @@ -1415,18 +1402,6 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO) { RootFrameList(aPO->mPresContext, fd, 0); // DumpFrames(fd, aPO->mPresContext, renderingContext, theRootFrame, 0); fprintf(fd, "---------------------------------------\n\n"); - fprintf(fd, "--------------- Views From Root Frame----------------\n"); - nsView* v = theRootFrame->GetView(); - if (v) { - v->List(fd); - } else { - printf("View is null!\n"); - } - if (aPO->mDocShell) { - fprintf(fd, "--------------- All Views ----------------\n"); - DumpViews(aPO->mDocShell, fd); - fprintf(fd, "---------------------------------------\n\n"); - } fclose(fd); } } @@ -2183,38 +2158,6 @@ static void DumpFrames(FILE* out, nsPresContext* aPresContext, } /** --------------------------------------------------- - * Dumps the Views from the DocShell - */ -static void DumpViews(nsIDocShell* aDocShell, FILE* out) { - NS_ASSERTION(aDocShell, "Pointer is null!"); - NS_ASSERTION(out, "Pointer is null!"); - - if (nullptr != aDocShell) { - fprintf(out, "docshell=%p \n", aDocShell); - if (PresShell* presShell = aDocShell->GetPresShell()) { - nsViewManager* vm = presShell->GetViewManager(); - if (vm) { - nsView* root = vm->GetRootView(); - if (root) { - root->List(out); - } - } - } else { - fputs("null pres shell\n", out); - } - - // dump the views of the sub documents - int32_t i, n; - BrowsingContext* bc = nsDocShell::Cast(aDocShell)->GetBrowsingContext(); - for (auto& child : bc->Children()) { - if (auto childDS = child->GetDocShell()) { - DumpViews(childAsShell, out); - } - } - } -} - -/** --------------------------------------------------- * Dumps the Views and Frames */ void DumpLayoutData(const char* aTitleStr, const char* aURLStr, @@ -2259,11 +2202,6 @@ void DumpLayoutData(const char* aTitleStr, const char* aURLStr, } else { printf("View is null!\n"); } - if (aDocShell) { - fprintf(fd, "--------------- All Views ----------------\n"); - DumpViews(aDocShell, fd); - fprintf(fd, "---------------------------------------\n\n"); - } if (aFD == nullptr) { fclose(fd); } diff --git a/layout/printing/nsPrintObject.cpp b/layout/printing/nsPrintObject.cpp @@ -68,7 +68,6 @@ void nsPrintObject::DestroyPresentation() { } mPresShell = nullptr; mPresContext = nullptr; - mViewManager = nullptr; } void nsPrintObject::EnablePrinting(bool aEnable) { diff --git a/layout/printing/nsPrintObject.h b/layout/printing/nsPrintObject.h @@ -12,7 +12,6 @@ #include "nsCOMPtr.h" #include "nsIDocShell.h" #include "nsIDocShellTreeOwner.h" -#include "nsViewManager.h" class nsIContent; class nsPresContext; @@ -58,7 +57,6 @@ class nsPrintObject final { RefPtr<nsPresContext> mPresContext; RefPtr<mozilla::PresShell> mPresShell; - RefPtr<nsViewManager> mViewManager; nsCOMPtr<nsIContent> mContent; diff --git a/layout/tools/layout-debug/src/nsILayoutDebuggingTools.idl b/layout/tools/layout-debug/src/nsILayoutDebuggingTools.idl @@ -36,7 +36,6 @@ interface nsILayoutDebuggingTools : nsISupports void dumpContent(in boolean anonymousSubtrees); void dumpFrames(in uint8_t flags); void dumpTextRuns(); - void dumpViews(); void dumpCounterManager(); void dumpRetainedDisplayList(); diff --git a/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp b/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp @@ -26,7 +26,6 @@ #include "nsIPrintSettingsService.h" #include "nsLayoutUtils.h" #include "nsPIDOMWindow.h" -#include "nsViewManager.h" using namespace mozilla; using mozilla::dom::Document; @@ -48,14 +47,6 @@ static PresShell* GetPresShell(nsIDocShell* aDocShell) { return viewer->GetPresShell(); } -static nsViewManager* view_manager(nsIDocShell* aDocShell) { - PresShell* presShell = GetPresShell(aDocShell); - if (!presShell) { - return nullptr; - } - return presShell->GetViewManager(); -} - #ifdef DEBUG static already_AddRefed<Document> document(nsIDocShell* aDocShell) { nsCOMPtr<nsIDocumentViewer> viewer(doc_viewer(aDocShell)); @@ -250,28 +241,6 @@ nsLayoutDebuggingTools::DumpTextRuns() { return NS_OK; } -static void DumpViewsRecur(nsIDocShell* aDocShell, FILE* out) { -#ifdef DEBUG - fprintf(out, "docshell=%p \n", static_cast<void*>(aDocShell)); - RefPtr<nsViewManager> vm(view_manager(aDocShell)); - if (vm) { - nsView* root = vm->GetRootView(); - if (root) { - root->List(out); - } - } else { - fputs("null view manager\n", out); - } -#endif // DEBUG -} - -NS_IMETHODIMP -nsLayoutDebuggingTools::DumpViews() { - NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); - DumpViewsRecur(mDocShell, stdout); - return NS_OK; -} - NS_IMETHODIMP nsLayoutDebuggingTools::DumpCounterManager() { NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); diff --git a/layout/tools/layout-debug/ui/content/layoutdebug.ftl b/layout/tools/layout-debug/ui/content/layoutdebug.ftl @@ -67,9 +67,6 @@ layoutdebug-dump-frames-in-css-pixels = layoutdebug-dump-text-runs = .label = Text Runs .accesskey = T -layoutdebug-dump-views = - .label = Views and Widgets - .accesskey = V layoutdebug-dump-counter-manager = .label = CSS Counters .accesskey = n diff --git a/layout/tools/layout-debug/ui/content/layoutdebug.js b/layout/tools/layout-debug/ui/content/layoutdebug.js @@ -35,7 +35,6 @@ const FEATURES = { const SIMPLE_COMMANDS = [ "dumpTextRuns", - "dumpViews", "dumpCounterManager", "dumpRetainedDisplayList", "dumpStyleSheets", @@ -425,9 +424,6 @@ function OnLDBLoad() { case "menu_dumpTextRuns": gDebugger.dumpTextRuns(); break; - case "menu_dumpViews": - gDebugger.dumpViews(); - break; case "menu_dumpCounterManager": gDebugger.dumpCounterManager(); break; diff --git a/layout/tools/layout-debug/ui/content/layoutdebug.xhtml b/layout/tools/layout-debug/ui/content/layoutdebug.xhtml @@ -198,10 +198,6 @@ data-l10n-id="layoutdebug-dump-text-runs" /> <menuitem - id="menu_dumpViews" - data-l10n-id="layoutdebug-dump-views" - /> - <menuitem id="menu_dumpCounterManager" data-l10n-id="layoutdebug-dump-counter-manager" /> diff --git a/layout/xul/nsMenuPopupFrame.cpp b/layout/xul/nsMenuPopupFrame.cpp @@ -63,7 +63,7 @@ #include "nsStyleStructInlines.h" #include "nsTransitionManager.h" #include "nsUnicharUtils.h" -#include "nsViewManager.h" +#include "nsView.h" #include "nsWidgetsCID.h" #include "nsXULPopupManager.h" diff --git a/layout/xul/nsXULPopupManager.cpp b/layout/xul/nsXULPopupManager.cpp @@ -62,7 +62,6 @@ #include "nsPIDOMWindow.h" #include "nsPIWindowRoot.h" #include "nsPresContextInlines.h" -#include "nsViewManager.h" #include "nsXULElement.h" using namespace mozilla; @@ -3067,17 +3066,9 @@ nsXULMenuCommandEvent::Run() { } } - // The order of the nsViewManager and PresShell COM pointers is - // important below. We want the pres shell to get released before the - // associated view manager on exit from this function. - // See bug 54233. - // XXXndeakin is this still needed? RefPtr<nsPresContext> presContext = menu->OwnerDoc()->GetPresContext(); RefPtr<PresShell> presShell = presContext ? presContext->PresShell() : nullptr; - RefPtr<nsViewManager> kungFuDeathGrip = - presShell ? presShell->GetViewManager() : nullptr; - (void)kungFuDeathGrip; // Not referred to directly within this function // Deselect ourselves. if (mCloseMenuMode != CloseMenuMode_None) { diff --git a/view/moz.build b/view/moz.build @@ -9,18 +9,12 @@ with Files("**"): EXPORTS += [ "nsView.h", - "nsViewManager.h", ] UNIFIED_SOURCES += [ "nsView.cpp", - "nsViewManager.cpp", ] include("/ipc/chromium/chromium-config.mozbuild") FINAL_LIBRARY = "xul" - -LOCAL_INCLUDES += [ - "/gfx/cairo/cairo/src", -] diff --git a/view/nsView.cpp b/view/nsView.cpp @@ -15,7 +15,6 @@ #include "mozilla/dom/BrowserParent.h" #include "mozilla/widget/Screen.h" #include "nsIWidget.h" -#include "nsViewManager.h" #include "nsIFrame.h" #include "nsXULPopupManager.h" #include "nsIWidgetListener.h" @@ -28,22 +27,29 @@ using namespace mozilla; using namespace mozilla::widget; -nsView::nsView(nsViewManager* aViewManager) : mViewManager(aViewManager) { - MOZ_COUNT_CTOR(nsView); +static uint32_t gLastUserEventTime = 0; +static void MaybeUpdateLastUserEventTime(WidgetGUIEvent* aEvent) { + WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); + if ((mouseEvent && + // Ignore mouse events that we synthesize. + mouseEvent->mReason == WidgetMouseEvent::eReal && + // Ignore mouse exit and enter (we'll get moves if the user + // is really moving the mouse) since we get them when we + // create and destroy widgets. + mouseEvent->mMessage != eMouseExitFromWidget && + mouseEvent->mMessage != eMouseEnterIntoWidget) || + aEvent->HasKeyEventMessage() || aEvent->HasIMEEventMessage()) { + gLastUserEventTime = PR_IntervalToMicroseconds(PR_IntervalNow()); + } } +uint32_t nsView::GetLastUserEventTime() { return gLastUserEventTime; } + +nsView::nsView(PresShell* aPs) : mPresShell(aPs) { MOZ_COUNT_CTOR(nsView); } + nsView::~nsView() { MOZ_COUNT_DTOR(nsView); - if (mViewManager) { - nsView* rootView = mViewManager->GetRootView(); - if (rootView == this) { - // Inform the view manager that the root view has gone away... - mViewManager->SetRootView(nullptr); - } - mViewManager = nullptr; - } - if (mPreviousWindow) { mPreviousWindow->SetPreviouslyAttachedWidgetListener(nullptr); } @@ -133,7 +139,7 @@ void nsView::List(FILE* out, int32_t aIndent) const { } #endif // DEBUG -PresShell* nsView::GetPresShell() { return GetViewManager()->GetPresShell(); } +PresShell* nsView::GetPresShell() { return mPresShell; } bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight) { @@ -172,9 +178,6 @@ bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth, void nsView::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) { MOZ_ASSERT(XRE_IsParentProcess(), "Should be only called for the browser parent process"); - MOZ_ASSERT(this == mViewManager->GetRootView(), - "Should be called for the root view"); - CallOnAllRemoteChildren( [aHeight](dom::BrowserParent* aBrowserParent) -> CallState { aBrowserParent->DynamicToolbarMaxHeightChanged(aHeight); @@ -185,8 +188,6 @@ void nsView::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) { void nsView::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) { MOZ_ASSERT(XRE_IsParentProcess(), "Should be only called for the browser parent process"); - MOZ_ASSERT(this == mViewManager->GetRootView(), - "Should be called for the root view"); CallOnAllRemoteChildren( [aOffset](dom::BrowserParent* aBrowserParent) -> CallState { // Skip background tabs. @@ -202,8 +203,6 @@ void nsView::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) { void nsView::KeyboardHeightChanged(ScreenIntCoord aHeight) { MOZ_ASSERT(XRE_IsParentProcess(), "Should be only called for the browser parent process"); - MOZ_ASSERT(this == mViewManager->GetRootView(), - "Should be called for the root view"); CallOnAllRemoteChildren( [aHeight](dom::BrowserParent* aBrowserParent) -> CallState { // Skip background tabs. @@ -219,8 +218,6 @@ void nsView::KeyboardHeightChanged(ScreenIntCoord aHeight) { void nsView::AndroidPipModeChanged(bool aPipMode) { MOZ_ASSERT(XRE_IsParentProcess(), "Should be only called for the browser parent process"); - MOZ_ASSERT(this == mViewManager->GetRootView(), - "Should be called for the root view"); CallOnAllRemoteChildren( [aPipMode](dom::BrowserParent* aBrowserParent) -> CallState { aBrowserParent->AndroidPipModeChanged(aPipMode); @@ -269,7 +266,7 @@ nsEventStatus nsView::HandleEvent(WidgetGUIEvent* aEvent) { MOZ_ASSERT(aEvent->mWidget, "null widget ptr"); nsEventStatus result = nsEventStatus_eIgnore; - nsViewManager::MaybeUpdateLastUserEventTime(aEvent); + MaybeUpdateLastUserEventTime(aEvent); if (RefPtr<PresShell> ps = GetPresShell()) { if (nsIFrame* root = ps->GetRootFrame()) { ps->HandleEvent(root, aEvent, false, &result); @@ -305,9 +302,8 @@ void nsView::SafeAreaInsetsChanged( } bool nsView::IsPrimaryFramePaintSuppressed() const { - return StaticPrefs::layout_show_previous_page() && - mViewManager->GetPresShell() && - mViewManager->GetPresShell()->IsPaintingSuppressed(); + return StaticPrefs::layout_show_previous_page() && mPresShell && + mPresShell->IsPaintingSuppressed(); } void nsView::CallOnAllRemoteChildren( diff --git a/view/nsView.h b/view/nsView.h @@ -6,11 +6,7 @@ #ifndef nsView_h__ #define nsView_h__ -#include "nsCoord.h" #include "nsRect.h" -#include "nsPoint.h" -#include "nsRegion.h" -#include "nsCRT.h" #include "nsCOMPtr.h" #include "nsIWidgetListener.h" #include "Units.h" @@ -118,14 +114,6 @@ class nsView final : public nsIWidgetListener { void operator delete(void* ptr) { ::operator delete(ptr); } /** - * Get the view manager which "owns" the view. - * This method might require some expensive traversal work in the future. If - * you can get the view manager from somewhere else, do that instead. - * @result the view manager - */ - nsViewManager* GetViewManager() const { return mViewManager; } - - /** * Destroy the view. * * The view destroys its child views, and destroys and releases its @@ -154,6 +142,8 @@ class nsView final : public nsIWidgetListener { void AttachToTopLevelWidget(nsIWidget* aWidget); void DetachFromTopLevelWidget(); + static uint32_t GetLastUserEventTime(); + /** * In 4.0, the "cutout" nature of a view is queryable. * If we believe that all cutout view have a native widget, this @@ -202,18 +192,17 @@ class nsView final : public nsIWidgetListener { nsEventStatus HandleEvent(mozilla::WidgetGUIEvent*) override; void SafeAreaInsetsChanged(const mozilla::LayoutDeviceIntMargin&) override; + explicit nsView(mozilla::PresShell*); virtual ~nsView(); bool IsPrimaryFramePaintSuppressed() const; private: - explicit nsView(nsViewManager* = nullptr); - void CallOnAllRemoteChildren( const std::function<mozilla::CallState(mozilla::dom::BrowserParent*)>& aCallback); - nsViewManager* mViewManager; + mozilla::PresShell* mPresShell = nullptr; nsCOMPtr<nsIWidget> mWindow; nsCOMPtr<nsIWidget> mPreviousWindow; }; diff --git a/view/nsViewManager.cpp b/view/nsViewManager.cpp @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsViewManager.h" - -#include "mozilla/MouseEvents.h" -#include "mozilla/PresShell.h" -#include "mozilla/PresShellInlines.h" -#include "mozilla/Preferences.h" -#include "mozilla/ProfilerLabels.h" -#include "mozilla/StartupTimeline.h" -#include "mozilla/dom/Document.h" -#include "nsGfxCIID.h" -#include "nsView.h" -#include "nsCOMPtr.h" -#include "nsRegion.h" -#include "nsCOMArray.h" -#include "nsXULPopupManager.h" -#include "nsPresContext.h" -#include "nsRefreshDriver.h" -#include "nsContentUtils.h" // for nsAutoScriptBlocker -#include "nsLayoutUtils.h" -#include "gfxPlatform.h" -#include "WindowRenderer.h" - -/** - XXX TODO XXX - - DeCOMify newly private methods - Optimize view storage -*/ - -/** - A note about platform assumptions: - - We assume that a widget is z-ordered on top of its parent. - - We do NOT assume anything about the relative z-ordering of sibling widgets. - Even though we ask for a specific z-order, we don't assume that widget - z-ordering actually works. -*/ - -using namespace mozilla; -using namespace mozilla::layers; - -#define NSCOORD_NONE INT32_MIN - -#undef DEBUG_MOUSE_LOCATION - -uint32_t nsViewManager::gLastUserEventTime = 0; - -nsViewManager::nsViewManager() : mPresShell(nullptr), mRootView(nullptr) {} - -nsViewManager::~nsViewManager() { - if (mRootView) { - // Destroy any remaining views - mRootView->Destroy(); - mRootView = nullptr; - } - - MOZ_RELEASE_ASSERT(!mPresShell, - "Releasing nsViewManager without having called Destroy on " - "the PresShell!"); -} - -nsView* nsViewManager::CreateView() { return new nsView(this); } - -void nsViewManager::SetRootView(nsView* aView) { - MOZ_ASSERT(!aView || aView->GetViewManager() == this, - "Unexpected viewmanager on root view"); - - // Do NOT destroy the current root view. It's the caller's responsibility - // to destroy it - mRootView = aView; -} - -void nsViewManager::MaybeUpdateLastUserEventTime(WidgetGUIEvent* aEvent) { - WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); - if ((mouseEvent && - // Ignore mouse events that we synthesize. - mouseEvent->mReason == WidgetMouseEvent::eReal && - // Ignore mouse exit and enter (we'll get moves if the user - // is really moving the mouse) since we get them when we - // create and destroy widgets. - mouseEvent->mMessage != eMouseExitFromWidget && - mouseEvent->mMessage != eMouseEnterIntoWidget) || - aEvent->HasKeyEventMessage() || aEvent->HasIMEEventMessage()) { - gLastUserEventTime = PR_IntervalToMicroseconds(PR_IntervalNow()); - } -} diff --git a/view/nsViewManager.h b/view/nsViewManager.h @@ -1,111 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef nsViewManager_h___ -#define nsViewManager_h___ - -#include "nscore.h" -#include "nsView.h" -#include "nsCOMPtr.h" -#include "nsCRT.h" -#include "nsTArray.h" -#include "nsTArray.h" -#include "mozilla/EventForwards.h" - -class nsIWidget; -struct nsRect; -class nsRegion; - -namespace mozilla { -class PresShell; -} // namespace mozilla - -class nsViewManager final { - ~nsViewManager(); - - public: - friend class nsView; - - typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect; - typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion; - - NS_INLINE_DECL_REFCOUNTING(nsViewManager) - - nsViewManager(); - - /** - * Create an ordinary view - * @result The new view. Never null. - */ - nsView* CreateView(); - - /** - * Get the root of the view tree. - * @result the root view - */ - nsView* GetRootView() { return mRootView; } - - /** - * Set the root of the view tree. Does not destroy the current root view. - * aView may have a parent view managed by a different view manager. - * aView may have a widget (anything but printing) or may not (printing). - * @param aView view to set as root - */ - void SetRootView(nsView* aView); - - /** - * Set the presshell associated with this manager - * @param aPresShell - new presshell - */ - void SetPresShell(mozilla::PresShell* aPresShell) { mPresShell = aPresShell; } - - /** - * Get the pres shell associated with this manager - */ - mozilla::PresShell* GetPresShell() const { return mPresShell; } - - public: - /** - * Retrieve the time of the last user event. User events - * include mouse and keyboard events. The viewmanager - * saves the time of the last user event. - */ - static uint32_t GetLastUserEventTime() { return gLastUserEventTime; } - static void MaybeUpdateLastUserEventTime(mozilla::WidgetGUIEvent*); - - private: - static uint32_t gLastUserEventTime; - - mozilla::PresShell* mPresShell; - - nsView* mRootView; - // from here to public should be static and locked... MMP -}; - -/** - Invalidation model: - - 1) Callers call into the view manager and ask it to invalidate a view. - - 2) The view manager finds the "right" widget for the view, henceforth called - the root widget. - - 3) The view manager traverses descendants of the root widget and for each - one that needs invalidation stores the rect to invalidate on the widget's - view (batching). - - 4) The dirty region is flushed to the right widget when - ProcessPendingUpdates is called from the RefreshDriver. - - It's important to note that widgets associated to views outside this view - manager can end up being invalidated during step 3. Therefore, the end of a - view update batch really needs to traverse the entire view tree, to ensure - that those invalidates happen. - - To cope with this, invalidation processing and should only happen on the - root viewmanager. -*/ - -#endif // nsViewManager_h___ diff --git a/widget/nsIWidget.cpp b/widget/nsIWidget.cpp @@ -87,8 +87,6 @@ #include "mozilla/layers/CompositorSession.h" #include "VRManagerChild.h" #include "gfxConfig.h" -#include "nsView.h" -#include "nsViewManager.h" static mozilla::LazyLogModule sBaseWidgetLog("BaseWidget");