Bug 1869092 - Fix timeouts in browser_PanelMultiView.js. r=twisniewski,test-only
[gecko.git] / toolkit / actors / AutoScrollParent.sys.mjs
blob1f9f780902b88d2e5908bfb1e947fd466a195be9
1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 export class AutoScrollParent extends JSWindowActorParent {
7   receiveMessage(msg) {
8     let browser = this.manager.browsingContext.top.embedderElement;
9     if (!browser) {
10       return null;
11     }
13     // If another tab is activated, we shouldn't start autoscroll requested
14     // for the previous active window if and only if the browser is a remote
15     // browser.  This is required for web apps which don't prevent default of
16     // middle click after opening a new window.  If the active tab is our
17     // documents like about:*, we don't need this check since our documents
18     // should do it correctly.
19     const requestedInForegroundTab = browser.isRemoteBrowser
20       ? Services.focus.focusedElement == browser
21       : true;
23     let data = msg.data;
24     switch (msg.name) {
25       case "Autoscroll:Start":
26         // Don't start autoscroll if the tab has already been a background tab.
27         if (!requestedInForegroundTab) {
28           return Promise.resolve({ autoscrollEnabled: false, usingAPZ: false });
29         }
30         return Promise.resolve(browser.startScroll(data));
31       case "Autoscroll:MaybeStartInParent":
32         // Don't start autoscroll if the tab has already been a background tab.
33         if (!requestedInForegroundTab) {
34           return Promise.resolve({ autoscrollEnabled: false, usingAPZ: false });
35         }
36         let parent = this.browsingContext.parent;
37         if (parent) {
38           let actor = parent.currentWindowGlobal.getActor("AutoScroll");
39           actor.sendAsyncMessage("Autoscroll:MaybeStart", data);
40         }
41         break;
42       case "Autoscroll:Cancel":
43         browser.cancelScroll();
44         break;
45     }
46     return null;
47   }