Skip to content

Commit b05e6c0

Browse files
committedFeb 6, 2023
Bug 1812938 - Part 1. GetWidgetScreen returns Screen instead of nsIScreen. r=emilio,geckoview-reviewers,owlish
`nsIWidget` isn't scriptable, so it is unnecessary to return `nsIScreen` for `GetWidgetScreen`. Differential Revision: https://phabricator.services.mozilla.com/D168029
1 parent 867e2d1 commit b05e6c0

18 files changed

+55
-53
lines changed
 

‎dom/base/Element.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class nsIFrame;
8989
class nsIHTMLCollection;
9090
class nsIMozBrowserFrame;
9191
class nsIPrincipal;
92+
class nsIScreen;
9293
class nsIScrollableFrame;
9394
class nsIURI;
9495
class nsMappedAttributes;

‎gfx/ipc/CompositorSession.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace mozilla {
1515
namespace layers {
1616

1717
using namespace gfx;
18-
using namespace widget;
1918

2019
CompositorSession::CompositorSession(nsBaseWidget* aWidget,
2120
CompositorWidgetDelegate* aDelegate,

‎hal/HalScreenConfiguration.h

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "mozilla/Observer.h"
1111
#include "mozilla/TypedEnumBits.h"
1212

13+
// Undo X11/X.h's definition of None
14+
#undef None
15+
1316
namespace mozilla::hal {
1417

1518
// Make sure that any change to ScreenOrientation values are also made in

‎layout/base/nsDocumentViewer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "mozilla/dom/Document.h"
3131
#include "mozilla/dom/DocumentInlines.h"
3232
#include "mozilla/dom/DocGroup.h"
33+
#include "mozilla/widget/Screen.h"
3334
#include "nsPresContext.h"
3435
#include "nsIFrame.h"
3536
#include "nsIWritablePropertyBag2.h"
@@ -68,7 +69,6 @@
6869
#include "nsDocShell.h"
6970
#include "nsIBaseWindow.h"
7071
#include "nsILayoutHistoryState.h"
71-
#include "nsIScreen.h"
7272
#include "nsCharsetSource.h"
7373
#include "mozilla/ReflowInput.h"
7474
#include "nsIImageLoadingContent.h"

‎view/nsView.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "mozilla/StaticPrefs_layout.h"
1616
#include "mozilla/dom/Document.h"
1717
#include "mozilla/dom/BrowserParent.h"
18+
#include "mozilla/widget/Screen.h"
1819
#include "nsIWidget.h"
1920
#include "nsViewManager.h"
2021
#include "nsIFrame.h"

‎widget/ScreenManager.cpp

+21-17
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ void ScreenManager::CopyScreensToAllRemotesIfIsParent() {
117117
NS_IMETHODIMP
118118
ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
119119
int32_t aHeight, nsIScreen** aOutScreen) {
120+
DesktopIntRect rect(aX, aY, aWidth, aHeight);
121+
nsCOMPtr<nsIScreen> screen = ScreenForRect(rect);
122+
screen.forget(aOutScreen);
123+
return NS_OK;
124+
}
125+
126+
already_AddRefed<Screen> ScreenManager::ScreenForRect(
127+
const DesktopIntRect& aRect) {
120128
#if defined(MOZ_WAYLAND) && defined(MOZ_LOGGING)
121129
static bool inWayland = GdkIsWaylandDisplay();
122130
if (inWayland) {
@@ -132,14 +140,13 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
132140
LayoutDeviceIntRect(), LayoutDeviceIntRect(), 0, 0, 0,
133141
DesktopToLayoutDeviceScale(), CSSToLayoutDeviceScale(), 96 /* dpi */,
134142
Screen::IsPseudoDisplay::No, hal::ScreenOrientation::None, 0);
135-
screen.forget(aOutScreen);
136-
return NS_OK;
143+
return screen.forget();
137144
}
138145

139146
// Optimize for the common case. If the number of screens is only
140147
// one then just return the primary screen.
141148
if (mScreenList.Length() == 1) {
142-
return GetPrimaryScreen(aOutScreen);
149+
return GetPrimaryScreen();
143150
}
144151

145152
// which screen should we return?
@@ -148,14 +155,13 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
148155
// walk the list of screens and find the one that has the most
149156
// surface area.
150157
uint32_t area = 0;
151-
DesktopIntRect windowRect(aX, aY, aWidth, aHeight);
152158
for (auto& screen : mScreenList) {
153159
int32_t x, y, width, height;
154160
x = y = width = height = 0;
155161
screen->GetRectDisplayPix(&x, &y, &width, &height);
156162
// calculate the surface area
157163
DesktopIntRect screenRect(x, y, width, height);
158-
screenRect.IntersectRect(screenRect, windowRect);
164+
screenRect.IntersectRect(screenRect, aRect);
159165
uint32_t tempArea = screenRect.Area();
160166
if (tempArea > area) {
161167
which = screen.get();
@@ -167,8 +173,7 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
167173
// return the screen that has the largest intersection.
168174
if (area > 0) {
169175
RefPtr<Screen> ret = which;
170-
ret.forget(aOutScreen);
171-
return NS_OK;
176+
return ret.forget();
172177
}
173178

174179
// If the rect does not intersect a screen, find
@@ -180,17 +185,17 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
180185
screen->GetRectDisplayPix(&x, &y, &width, &height);
181186

182187
uint32_t distanceX = 0;
183-
if (aX > (x + width)) {
184-
distanceX = aX - (x + width);
185-
} else if ((aX + aWidth) < x) {
186-
distanceX = x - (aX + aWidth);
188+
if (aRect.x > (x + width)) {
189+
distanceX = aRect.x - (x + width);
190+
} else if (aRect.XMost() < x) {
191+
distanceX = x - aRect.XMost();
187192
}
188193

189194
uint32_t distanceY = 0;
190-
if (aY > (y + height)) {
191-
distanceY = aY - (y + height);
192-
} else if ((aY + aHeight) < y) {
193-
distanceY = y - (aY + aHeight);
195+
if (aRect.y > (y + height)) {
196+
distanceY = aRect.y - (y + height);
197+
} else if (aRect.YMost() < y) {
198+
distanceY = y - aRect.YMost();
194199
}
195200

196201
uint32_t tempDistance = distanceX * distanceX + distanceY * distanceY;
@@ -204,8 +209,7 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
204209
}
205210

206211
RefPtr<Screen> ret = which;
207-
ret.forget(aOutScreen);
208-
return NS_OK;
212+
return ret.forget();
209213
}
210214

211215
// The screen with the menubar/taskbar. This shouldn't be needed very

‎widget/ScreenManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ScreenManager final : public nsIScreenManager {
4343
void Refresh(nsTArray<mozilla::dom::ScreenDetails>&& aScreens);
4444
void CopyScreensToRemote(mozilla::dom::ContentParent* aContentParent);
4545
already_AddRefed<Screen> GetPrimaryScreen();
46+
already_AddRefed<Screen> ScreenForRect(const DesktopIntRect& aRect);
4647

4748
const nsTArray<RefPtr<Screen>>& CurrentScreenList() const {
4849
return mScreenList;

‎widget/android/nsWindow.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#include "mozilla/layers/IAPZCTreeManager.h"
102102
#include "mozilla/ProfilerLabels.h"
103103
#include "mozilla/widget/AndroidVsync.h"
104+
#include "mozilla/widget/Screen.h"
104105

105106
#define GVS_LOG(...) MOZ_LOG(sGVSupportLog, LogLevel::Warning, (__VA_ARGS__))
106107

‎widget/cocoa/nsChildView.mm

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include "mozilla/layers/WebRenderLayerManager.h"
8383
#include "mozilla/webrender/WebRenderAPI.h"
8484
#include "mozilla/widget/CompositorWidget.h"
85+
#include "mozilla/widget/Screen.h"
8586
#include "gfxUtils.h"
8687
#include "mozilla/gfx/2D.h"
8788
#include "mozilla/gfx/BorrowedContext.h"

‎widget/cocoa/nsCocoaWindow.mm

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "mozilla/StaticPrefs_widget.h"
5656
#include "mozilla/WritingModes.h"
5757
#include "mozilla/layers/CompositorBridgeChild.h"
58+
#include "mozilla/widget/Screen.h"
5859
#include <algorithm>
5960

6061
namespace mozilla {

‎widget/gtk/ScreenHelperGTK.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ int ScreenGetterWayland::GetMonitorForWindow(nsWindow* aWindow) {
500500
return -1;
501501
}
502502

503-
RefPtr<nsIScreen> ScreenGetterWayland::GetScreenForWindow(nsWindow* aWindow) {
503+
RefPtr<widget::Screen> ScreenGetterWayland::GetScreenForWindow(
504+
nsWindow* aWindow) {
504505
if (mMonitors.IsEmpty()) {
505506
return nullptr;
506507
}
@@ -522,7 +523,7 @@ RefPtr<nsIScreen> ScreenGetterWayland::GetScreenForWindow(nsWindow* aWindow) {
522523
}
523524
#endif
524525

525-
RefPtr<nsIScreen> ScreenHelperGTK::GetScreenForWindow(nsWindow* aWindow) {
526+
RefPtr<widget::Screen> ScreenHelperGTK::GetScreenForWindow(nsWindow* aWindow) {
526527
return gScreenGetter->GetScreenForWindow(aWindow);
527528
}
528529

‎widget/gtk/ScreenHelperGTK.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ScreenGetter {
2929
virtual void Init(){};
3030

3131
virtual void RefreshScreens(){};
32-
virtual RefPtr<nsIScreen> GetScreenForWindow(nsWindow* aWindow) {
32+
virtual RefPtr<widget::Screen> GetScreenForWindow(nsWindow* aWindow) {
3333
return nullptr;
3434
}
3535
};
@@ -70,7 +70,7 @@ class ScreenGetterWayland : public ScreenGetter {
7070
bool RemoveMonitorConfig(int aId);
7171
already_AddRefed<Screen> MakeScreenWayland(gint aMonitor);
7272

73-
RefPtr<nsIScreen> GetScreenForWindow(nsWindow* aWindow);
73+
RefPtr<widget::Screen> GetScreenForWindow(nsWindow* aWindow);
7474

7575
// For internal use from signal callback functions
7676
void RefreshScreens();
@@ -95,7 +95,7 @@ class ScreenHelperGTK final : public ScreenManager::Helper {
9595
~ScreenHelperGTK();
9696

9797
static gint GetGTKMonitorScaleFactor(gint aMonitorNum = 0);
98-
static RefPtr<nsIScreen> GetScreenForWindow(nsWindow* aWindow);
98+
static RefPtr<widget::Screen> GetScreenForWindow(nsWindow* aWindow);
9999
};
100100

101101
} // namespace widget

‎widget/gtk/nsWindow.cpp

+5-13
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
#include "nsViewManager.h"
9797
#include "nsXPLookAndFeel.h"
9898
#include "prlink.h"
99+
#include "Screen.h"
99100
#include "ScreenHelperGTK.h"
100101
#include "SystemTimeConverter.h"
101102
#include "WidgetUtilsGtk.h"
@@ -7284,29 +7285,20 @@ void nsWindow::PerformFullscreenTransition(FullscreenTransitionStage aStage,
72847285
nullptr);
72857286
}
72867287

7287-
already_AddRefed<nsIScreen> nsWindow::GetWidgetScreen() {
7288+
already_AddRefed<widget::Screen> nsWindow::GetWidgetScreen() {
72887289
// Wayland can read screen directly
72897290
if (GdkIsWaylandDisplay()) {
7290-
RefPtr<nsIScreen> screen = ScreenHelperGTK::GetScreenForWindow(this);
7291-
if (screen) {
7291+
if (RefPtr<Screen> screen = ScreenHelperGTK::GetScreenForWindow(this)) {
72927292
return screen.forget();
72937293
}
72947294
}
72957295

7296-
nsCOMPtr<nsIScreenManager> screenManager;
7297-
screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
7298-
if (!screenManager) {
7299-
return nullptr;
7300-
}
7301-
73027296
// GetScreenBounds() is slow for the GTK port so we override and use
73037297
// mBounds directly.
7298+
ScreenManager& screenManager = ScreenManager::GetSingleton();
73047299
LayoutDeviceIntRect bounds = mBounds;
73057300
DesktopIntRect deskBounds = RoundedToInt(bounds / GetDesktopToDeviceScale());
7306-
nsCOMPtr<nsIScreen> screen;
7307-
screenManager->ScreenForRect(deskBounds.x, deskBounds.y, deskBounds.width,
7308-
deskBounds.height, getter_AddRefs(screen));
7309-
return screen.forget();
7301+
return screenManager.ScreenForRect(deskBounds);
73107302
}
73117303

73127304
RefPtr<VsyncDispatcher> nsWindow::GetVsyncDispatcher() {

‎widget/gtk/nsWindow.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ class TimeStamp;
110110
#ifdef MOZ_X11
111111
class CurrentX11TimeGetter;
112112
#endif
113+
114+
namespace widget {
115+
class Screen;
116+
} // namespace widget
113117
} // namespace mozilla
114118

115119
class nsWindow final : public nsBaseWidget {
@@ -197,7 +201,7 @@ class nsWindow final : public nsBaseWidget {
197201
void PerformFullscreenTransition(FullscreenTransitionStage aStage,
198202
uint16_t aDuration, nsISupports* aData,
199203
nsIRunnable* aCallback) override;
200-
already_AddRefed<nsIScreen> GetWidgetScreen() override;
204+
already_AddRefed<Screen> GetWidgetScreen() override;
201205
nsresult MakeFullScreen(bool aFullScreen) override;
202206
void HideWindowChrome(bool aShouldHide) override;
203207

‎widget/nsBaseWidget.cpp

+3-12
Original file line numberDiff line numberDiff line change
@@ -2000,20 +2000,11 @@ LayersId nsBaseWidget::GetRootLayerTreeId() {
20002000
: LayersId{0};
20012001
}
20022002

2003-
already_AddRefed<nsIScreen> nsBaseWidget::GetWidgetScreen() {
2004-
nsCOMPtr<nsIScreenManager> screenManager;
2005-
screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
2006-
if (!screenManager) {
2007-
return nullptr;
2008-
}
2009-
2003+
already_AddRefed<widget::Screen> nsBaseWidget::GetWidgetScreen() {
2004+
ScreenManager& screenManager = ScreenManager::GetSingleton();
20102005
LayoutDeviceIntRect bounds = GetScreenBounds();
20112006
DesktopIntRect deskBounds = RoundedToInt(bounds / GetDesktopToDeviceScale());
2012-
nsCOMPtr<nsIScreen> screen;
2013-
screenManager->ScreenForRect(deskBounds.X(), deskBounds.Y(),
2014-
deskBounds.Width(), deskBounds.Height(),
2015-
getter_AddRefs(screen));
2016-
return screen.forget();
2007+
return screenManager.ScreenForRect(deskBounds);
20172008
}
20182009

20192010
mozilla::DesktopToLayoutDeviceScale

‎widget/nsBaseWidget.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference {
205205
uint16_t aDuration, nsISupports* aData,
206206
nsIRunnable* aCallback) override;
207207
void CleanupFullscreenTransition() override {}
208-
already_AddRefed<nsIScreen> GetWidgetScreen() override;
208+
already_AddRefed<Screen> GetWidgetScreen() override;
209209
nsresult MakeFullScreen(bool aFullScreen) override;
210210
void InfallibleMakeFullScreen(bool aFullScreen);
211211

‎widget/nsIWidget.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class nsIRollupListener;
4949
class imgIContainer;
5050
class nsIContent;
5151
class ViewWrapper;
52-
class nsIScreen;
5352
class nsIRunnable;
5453

5554
namespace mozilla {
@@ -87,6 +86,7 @@ class TextEventDispatcher;
8786
class TextEventDispatcherListener;
8887
class CompositorWidget;
8988
class CompositorWidgetInitData;
89+
class Screen;
9090
} // namespace widget
9191
namespace wr {
9292
class DisplayListBuilder;
@@ -383,6 +383,7 @@ class nsIWidget : public nsISupports {
383383
using PopupLevel = mozilla::widget::PopupLevel;
384384
using BorderStyle = mozilla::widget::BorderStyle;
385385
using TransparencyMode = mozilla::widget::TransparencyMode;
386+
using Screen = mozilla::widget::Screen;
386387

387388
// Used in UpdateThemeGeometries.
388389
struct ThemeGeometry {
@@ -1160,7 +1161,7 @@ class nsIWidget : public nsISupports {
11601161
/**
11611162
* Return the screen the widget is in, or null if we don't know.
11621163
*/
1163-
virtual already_AddRefed<nsIScreen> GetWidgetScreen() = 0;
1164+
virtual already_AddRefed<Screen> GetWidgetScreen() = 0;
11641165

11651166
/**
11661167
* Put the toplevel window into or out of fullscreen mode.

‎widget/windows/nsWindow.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
#include "mozilla/TextEventDispatcherListener.h"
148148
#include "mozilla/widget/nsAutoRollup.h"
149149
#include "mozilla/widget/PlatformWidgetTypes.h"
150+
#include "mozilla/widget/Screen.h"
150151
#include "nsStyleConsts.h"
151152
#include "nsBidiKeyboard.h"
152153
#include "nsStyleConsts.h"

0 commit comments

Comments
 (0)
Failed to load comments.