commit 8bd614f7628813887031d3ed689bdefcc35d0f5c
parent 857fc08db7a3765b98e034d011509be6e9bcaada
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Wed, 12 Nov 2025 18:22:35 +0000
Bug 1999627 - Remove nsViewManager's device context. r=tnikkel,layout-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D272211
Diffstat:
9 files changed, 31 insertions(+), 42 deletions(-)
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
@@ -16,6 +16,7 @@
# include <unistd.h> // for getpid()
#endif
+#include "nsDeviceContext.h"
#include "mozilla/Attributes.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/BasePrincipal.h"
diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp
@@ -56,6 +56,7 @@
#include "nsComputedDOMStyle.h"
#include "nsContentList.h"
#include "nsContentUtils.h"
+#include "nsDeviceContext.h"
#include "nsError.h"
#include "nsFocusManager.h"
#include "nsFrameManager.h"
diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp
@@ -11,6 +11,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/ScopeExit.h"
#include "nsGlobalWindowInner.h"
+#include "nsDeviceContext.h"
// Local Includes
#include "Navigator.h"
diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp
@@ -25,6 +25,7 @@
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsContentUtils.h"
+#include "nsDeviceContext.h"
#include "nsFrameSelection.h"
#include "nsGenericHTMLElement.h"
#include "nsIContent.h"
@@ -2180,7 +2181,7 @@ void nsDocumentViewer::MakeWindow(const nsSize& aSize) {
return;
}
- mViewManager = new nsViewManager(mPresContext->DeviceContext());
+ mViewManager = new nsViewManager();
// Create a view
nsView* view = mViewManager->CreateView(aSize);
diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp
@@ -72,6 +72,7 @@
#include "nsCRT.h"
#include "nsCSSFrameConstructor.h"
#include "nsContentUtils.h"
+#include "nsDeviceContext.h"
#include "nsDocShell.h"
#include "nsFontCache.h"
#include "nsFontFaceLoader.h"
diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp
@@ -1263,7 +1263,7 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO) {
// init it with the DC
MOZ_TRY(aPO->mPresContext->Init(printData->mPrintDC));
- aPO->mViewManager = new nsViewManager(printData->mPrintDC);
+ aPO->mViewManager = new nsViewManager();
bool doReturn = false;
nsSize adjSize;
diff --git a/view/nsView.cpp b/view/nsView.cpp
@@ -5,6 +5,7 @@
#include "nsView.h"
+#include "nsDeviceContext.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/IntegerPrintfMacros.h"
@@ -190,9 +191,7 @@ LayoutDeviceIntRect nsView::CalcWidgetBounds(
aTransparency);
}
-void nsView::SetDimensions(const nsRect& aRect) {
- mDimBounds = aRect;
-}
+void nsView::SetDimensions(const nsRect& aRect) { mDimBounds = aRect; }
void nsView::SetNeedsWindowPropertiesSync() {
mNeedsWindowPropertiesSync = true;
@@ -290,17 +289,11 @@ void nsView::List(FILE* out, int32_t aIndent) const {
int32_t i;
for (i = aIndent; --i >= 0;) fputs(" ", out);
fprintf(out, "%p ", (void*)this);
- if (nullptr != mWindow) {
- nscoord p2a = mViewManager->AppUnitsPerDevPixel();
- LayoutDeviceIntRect rect = mWindow->GetClientBounds();
- nsRect windowBounds = LayoutDeviceIntRect::ToAppUnits(rect, p2a);
- rect = mWindow->GetBounds();
- nsRect nonclientBounds = LayoutDeviceIntRect::ToAppUnits(rect, p2a);
+ if (mWindow) {
nsrefcnt widgetRefCnt = mWindow.get()->AddRef() - 1;
mWindow.get()->Release();
- fprintf(out, "(widget=%p[%" PRIuPTR "] pos={%d,%d,%d,%d}) ", (void*)mWindow,
- widgetRefCnt, nonclientBounds.X(), nonclientBounds.Y(),
- windowBounds.Width(), windowBounds.Height());
+ fprintf(out, "(widget=%p[%" PRIuPTR "] pos=%s) ", (void*)mWindow,
+ widgetRefCnt, ToString(mWindow->GetBounds()).c_str());
}
nsRect brect = GetBounds();
fprintf(out, "{%d,%d,%d,%d}", brect.X(), brect.Y(), brect.Width(),
@@ -328,11 +321,20 @@ bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth,
return false;
}
- RefPtr<nsDeviceContext> devContext = mViewManager->GetDeviceContext();
+ PresShell* ps = mViewManager->GetPresShell();
+ if (!ps) {
+ return false;
+ }
+
+ nsPresContext* pc = ps->GetPresContext();
+ if (!pc) {
+ return false;
+ }
+
// ensure DPI is up-to-date, in case of window being opened and sized
// on a non-default-dpi display (bug 829963)
- devContext->CheckDPIChange();
- int32_t p2a = devContext->AppUnitsPerDevPixel();
+ pc->DeviceContext()->CheckDPIChange();
+ int32_t p2a = pc->AppUnitsPerDevPixel();
if (auto* frame = GetFrame()) {
// Usually the resize would deal with this, but there are some cases (like
// web-extension popups) where frames might already be correctly sized etc
@@ -344,10 +346,7 @@ bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth,
NSIntPixelsToAppUnits(aHeight, p2a));
if (nsXULPopupManager* pm = nsXULPopupManager::GetInstance()) {
- PresShell* presShell = mViewManager->GetPresShell();
- if (presShell && presShell->GetDocument()) {
- pm->AdjustPopupsOnWindowChange(presShell);
- }
+ pm->AdjustPopupsOnWindowChange(ps);
}
return true;
@@ -460,7 +459,7 @@ void nsView::RequestRepaint() {
nsEventStatus nsView::HandleEvent(WidgetGUIEvent* aEvent,
bool aUseAttachedEvents) {
- MOZ_ASSERT(nullptr != aEvent->mWidget, "null widget ptr");
+ MOZ_ASSERT(aEvent->mWidget, "null widget ptr");
nsEventStatus result = nsEventStatus_eIgnore;
nsView* view;
diff --git a/view/nsViewManager.cpp b/view/nsViewManager.cpp
@@ -51,15 +51,12 @@ using namespace mozilla::layers;
uint32_t nsViewManager::gLastUserEventTime = 0;
-nsViewManager::nsViewManager(nsDeviceContext* aContext)
- : mContext(aContext),
- mPresShell(nullptr),
+nsViewManager::nsViewManager()
+ : mPresShell(nullptr),
mDelayedResize(NSCOORD_NONE, NSCOORD_NONE),
mRootView(nullptr),
mPainting(false),
- mHasPendingWidgetGeometryChanges(false) {
- MOZ_ASSERT(aContext);
-}
+ mHasPendingWidgetGeometryChanges(false) {}
nsViewManager::~nsViewManager() {
if (mRootView) {
diff --git a/view/nsViewManager.h b/view/nsViewManager.h
@@ -11,7 +11,6 @@
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsTArray.h"
-#include "nsDeviceContext.h"
#include "nsTArray.h"
#include "mozilla/Attributes.h"
#include "mozilla/EventForwards.h"
@@ -19,7 +18,6 @@
class nsIWidget;
struct nsRect;
class nsRegion;
-class nsDeviceContext;
namespace mozilla {
class PresShell;
@@ -36,7 +34,7 @@ class nsViewManager final {
NS_INLINE_DECL_REFCOUNTING(nsViewManager)
- explicit nsViewManager(nsDeviceContext* aContext);
+ nsViewManager();
/**
* Initialize the ViewManager
@@ -44,7 +42,7 @@ class nsViewManager final {
* because it holds a reference to this instance.
* @result The result of the initialization, NS_OK if no errors
*/
- nsresult Init(nsDeviceContext* aContext);
+ nsresult Init();
/**
* Create an ordinary view
@@ -126,11 +124,6 @@ class nsViewManager final {
*/
mozilla::PresShell* GetPresShell() const { return mPresShell; }
- /**
- * Get the device context associated with this manager
- */
- nsDeviceContext* GetDeviceContext() const { return mContext; }
-
public:
/**
* Indicate whether the viewmanager is currently painting
@@ -158,10 +151,6 @@ class nsViewManager final {
*/
MOZ_CAN_RUN_SCRIPT void UpdateWidgetGeometry();
- int32_t AppUnitsPerDevPixel() const {
- return mContext->AppUnitsPerDevPixel();
- }
-
private:
static uint32_t gLastUserEventTime;
@@ -207,7 +196,6 @@ class nsViewManager final {
// pending updates.
void PostPendingUpdate();
- RefPtr<nsDeviceContext> mContext;
mozilla::PresShell* mPresShell;
// The size for a resize that we delayed until the root view becomes