@@ -117,6 +117,14 @@ void ScreenManager::CopyScreensToAllRemotesIfIsParent() {
117
117
NS_IMETHODIMP
118
118
ScreenManager::ScreenForRect (int32_t aX, int32_t aY, int32_t aWidth,
119
119
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) {
120
128
#if defined(MOZ_WAYLAND) && defined(MOZ_LOGGING)
121
129
static bool inWayland = GdkIsWaylandDisplay ();
122
130
if (inWayland) {
@@ -132,14 +140,13 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
132
140
LayoutDeviceIntRect (), LayoutDeviceIntRect (), 0 , 0 , 0 ,
133
141
DesktopToLayoutDeviceScale (), CSSToLayoutDeviceScale (), 96 /* dpi */ ,
134
142
Screen::IsPseudoDisplay::No, hal::ScreenOrientation::None, 0 );
135
- screen.forget (aOutScreen);
136
- return NS_OK;
143
+ return screen.forget ();
137
144
}
138
145
139
146
// Optimize for the common case. If the number of screens is only
140
147
// one then just return the primary screen.
141
148
if (mScreenList .Length () == 1 ) {
142
- return GetPrimaryScreen (aOutScreen );
149
+ return GetPrimaryScreen ();
143
150
}
144
151
145
152
// which screen should we return?
@@ -148,14 +155,13 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
148
155
// walk the list of screens and find the one that has the most
149
156
// surface area.
150
157
uint32_t area = 0 ;
151
- DesktopIntRect windowRect (aX, aY, aWidth, aHeight);
152
158
for (auto & screen : mScreenList ) {
153
159
int32_t x, y, width, height;
154
160
x = y = width = height = 0 ;
155
161
screen->GetRectDisplayPix (&x, &y, &width, &height);
156
162
// calculate the surface area
157
163
DesktopIntRect screenRect (x, y, width, height);
158
- screenRect.IntersectRect (screenRect, windowRect );
164
+ screenRect.IntersectRect (screenRect, aRect );
159
165
uint32_t tempArea = screenRect.Area ();
160
166
if (tempArea > area) {
161
167
which = screen.get ();
@@ -167,8 +173,7 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
167
173
// return the screen that has the largest intersection.
168
174
if (area > 0 ) {
169
175
RefPtr<Screen> ret = which;
170
- ret.forget (aOutScreen);
171
- return NS_OK;
176
+ return ret.forget ();
172
177
}
173
178
174
179
// If the rect does not intersect a screen, find
@@ -180,17 +185,17 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
180
185
screen->GetRectDisplayPix (&x, &y, &width, &height);
181
186
182
187
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 ( );
187
192
}
188
193
189
194
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 ( );
194
199
}
195
200
196
201
uint32_t tempDistance = distanceX * distanceX + distanceY * distanceY;
@@ -204,8 +209,7 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
204
209
}
205
210
206
211
RefPtr<Screen> ret = which;
207
- ret.forget (aOutScreen);
208
- return NS_OK;
212
+ return ret.forget ();
209
213
}
210
214
211
215
// The screen with the menubar/taskbar. This shouldn't be needed very
0 commit comments