Skip to content

Commit baaa654

Browse files
authored
browser(firefox): resize window when changing viewport (#2861)
1 parent 64f5721 commit baaa654

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

browser_patches/firefox/BUILD_NUMBER

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1124
2-
Changed: [email protected] Mon Jul 6 17:16:56 PDT 2020
1+
1125
2+
Changed: [email protected] Tue Jul 7 10:43:01 PDT 2020

browser_patches/firefox/juggler/TargetRegistry.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ class TargetRegistry {
146146
let tab;
147147
let gBrowser;
148148
const windowsIt = Services.wm.getEnumerator('navigator:browser');
149+
let window;
149150
while (windowsIt.hasMoreElements()) {
150-
const window = windowsIt.getNext();
151+
window = windowsIt.getNext();
151152
// gBrowser is always created before tabs. If gBrowser is not
152153
// initialized yet the browser belongs to another window.
153154
if (!window.gBrowser)
@@ -172,7 +173,7 @@ class TargetRegistry {
172173
openerTarget = this._browserToTarget.get(tab.openerTab.linkedBrowser);
173174
}
174175
const browserContext = this._userContextIdToBrowserContext.get(userContextId);
175-
const target = new PageTarget(this, gBrowser, tab, linkedBrowser, browserContext, openerTarget);
176+
const target = new PageTarget(this, window, gBrowser, tab, linkedBrowser, browserContext, openerTarget);
176177

177178
const sessions = [];
178179
const readyData = { sessions, target };
@@ -187,12 +188,12 @@ class TargetRegistry {
187188
},
188189
});
189190

190-
const onTabOpenListener = event => {
191+
const onTabOpenListener = (window, event) => {
191192
const tab = event.target;
192193
const userContextId = tab.userContextId;
193194
const browserContext = this._userContextIdToBrowserContext.get(userContextId);
194195
if (browserContext && browserContext.defaultViewportSize)
195-
setViewportSizeForBrowser(browserContext.defaultViewportSize, tab.linkedBrowser);
196+
setViewportSizeForBrowser(browserContext.defaultViewportSize, tab.linkedBrowser, window);
196197
};
197198

198199
const onTabCloseListener = event => {
@@ -220,7 +221,7 @@ class TargetRegistry {
220221
});
221222
if (!domWindow.gBrowser)
222223
return;
223-
domWindow.gBrowser.tabContainer.addEventListener('TabOpen', onTabOpenListener);
224+
domWindow.gBrowser.tabContainer.addEventListener('TabOpen', event => onTabOpenListener(domWindow, event));
224225
domWindow.gBrowser.tabContainer.addEventListener('TabClose', onTabCloseListener);
225226
},
226227
onCloseWindow: window => {
@@ -304,7 +305,7 @@ class TargetRegistry {
304305
});
305306
});
306307
if (browserContext && browserContext.defaultViewportSize)
307-
setViewportSizeForBrowser(browserContext.defaultViewportSize, browser);
308+
setViewportSizeForBrowser(browserContext.defaultViewportSize, browser, window);
308309
browser.focus();
309310
if (browserContext.settings.timezoneId) {
310311
if (await target.hasFailedToOverrideTimezone())
@@ -332,11 +333,12 @@ class TargetRegistry {
332333
}
333334

334335
class PageTarget {
335-
constructor(registry, gBrowser, tab, linkedBrowser, browserContext, opener) {
336+
constructor(registry, win, gBrowser, tab, linkedBrowser, browserContext, opener) {
336337
EventEmitter.decorate(this);
337338

338339
this._targetId = helper.generateId();
339340
this._registry = registry;
341+
this._window = win;
340342
this._gBrowser = gBrowser;
341343
this._tab = tab;
342344
this._linkedBrowser = linkedBrowser;
@@ -374,7 +376,7 @@ class PageTarget {
374376

375377
async setViewportSize(viewportSize) {
376378
this._viewportSize = viewportSize;
377-
const actualSize = setViewportSizeForBrowser(viewportSize, this._linkedBrowser);
379+
const actualSize = setViewportSizeForBrowser(viewportSize, this._linkedBrowser, this._window);
378380
await this._channel.connect('').send('awaitViewportDimensions', {
379381
width: actualSize.width,
380382
height: actualSize.height
@@ -690,9 +692,11 @@ async function waitForWindowReady(window) {
690692
}
691693
}
692694

693-
function setViewportSizeForBrowser(viewportSize, browser) {
695+
function setViewportSizeForBrowser(viewportSize, browser, window) {
694696
if (viewportSize) {
695697
const {width, height} = viewportSize;
698+
const rect = browser.getBoundingClientRect();
699+
window.resizeBy(width - rect.width, height - rect.height);
696700
browser.style.setProperty('min-width', width + 'px');
697701
browser.style.setProperty('min-height', height + 'px');
698702
browser.style.setProperty('max-width', width + 'px');

0 commit comments

Comments
 (0)