browser(firefox): properly hide scrollbars in all frames (#2505)

This commit is contained in:
Dmitry Gozman 2020-06-08 15:54:47 -07:00 коммит произвёл GitHub
Родитель 4ec215a88b
Коммит ac88f98999
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 11 добавлений и 157 удалений

Просмотреть файл

@ -1,2 +1 @@
1103
1104
1105

Просмотреть файл

@ -67,6 +67,12 @@ CommandLineHandler.prototype = {
});
Services.mm.loadFrameScript(FRAME_SCRIPT, true /* aAllowDelayedLoad */);
if (Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo).isHeadless) {
const styleSheetService = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Components.interfaces.nsIStyleSheetService);
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
const uri = ioService.newURI('chrome://juggler/content/content/hidden-scrollbars.css', null, null);
styleSheetService.loadAndRegisterSheet(uri, styleSheetService.AGENT_SHEET);
}
dump(`Juggler listening on ws://127.0.0.1:${this._server.port}/${token}\n`);
},

Просмотреть файл

@ -70,6 +70,8 @@ class FrameTree {
_frameForWorker(workerDebugger) {
if (workerDebugger.type !== Ci.nsIWorkerDebugger.TYPE_DEDICATED)
return null;
if (!workerDebugger.window)
return null;
const docShell = workerDebugger.window.docShell;
return this._docShellToFrame.get(docShell) || null;
}

Просмотреть файл

@ -1,89 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;
const Cc = Components.classes;
const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const HIDDEN_SCROLLBARS = Services.io.newURI('chrome://juggler/content/content/hidden-scrollbars.css');
const FLOATING_SCROLLBARS = Services.io.newURI('chrome://juggler/content/content/floating-scrollbars.css');
const isHeadless = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo).isHeadless;
const helper = new Helper();
class ScrollbarManager {
constructor(docShell) {
this._docShell = docShell;
this._customScrollbars = null;
this._contentViewerScrollBars = new Map();
if (isHeadless)
this._setCustomScrollbars(HIDDEN_SCROLLBARS);
const webProgress = this._docShell.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress);
this.QueryInterface = ChromeUtils.generateQI(['nsIWebProgressListener', 'nsISupportsWeakReference']);
this._eventListeners = [
helper.addProgressListener(webProgress, this, Ci.nsIWebProgress.NOTIFY_ALL),
];
}
onLocationChange(webProgress, request, URI, flags) {
if (flags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT)
return;
this._updateAllDocShells();
}
setFloatingScrollbars(enabled) {
if (this._customScrollbars === HIDDEN_SCROLLBARS)
return;
this._setCustomScrollbars(enabled ? FLOATING_SCROLLBARS : null);
}
_setCustomScrollbars(customScrollbars) {
if (this._customScrollbars === customScrollbars)
return;
this._customScrollbars = customScrollbars;
this._updateAllDocShells();
}
_updateAllDocShells() {
const allDocShells = [this._docShell];
for (let i = 0; i < this._docShell.childCount; i++)
allDocShells.push(this._docShell.getChildAt(i).QueryInterface(Ci.nsIDocShell));
// At this point, a content viewer might not be loaded for certain docShells.
// Scrollbars will be updated in onLocationChange.
const contentViewers = allDocShells.map(docShell => docShell.contentViewer).filter(contentViewer => !!contentViewer);
// Update scrollbar stylesheets.
for (const contentViewer of contentViewers) {
const oldScrollbars = this._contentViewerScrollBars.get(contentViewer);
if (oldScrollbars === this._customScrollbars)
continue;
const winUtils = contentViewer.DOMDocument.defaultView.windowUtils;
if (oldScrollbars)
winUtils.removeSheet(oldScrollbars, winUtils.AGENT_SHEET);
if (this._customScrollbars)
winUtils.loadSheet(this._customScrollbars, winUtils.AGENT_SHEET);
}
// Update state for all *existing* docShells.
this._contentViewerScrollBars.clear();
for (const contentViewer of contentViewers)
this._contentViewerScrollBars.set(contentViewer, this._customScrollbars);
}
dispose() {
this._setCustomScrollbars(null);
helper.removeListeners(this._eventListeners);
}
}
var EXPORTED_SYMBOLS = ['ScrollbarManager'];
this.ScrollbarManager = ScrollbarManager;

Просмотреть файл

@ -1,51 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
@namespace html url("http://www.w3.org/1999/xhtml");
/* Restrict all styles to `*|*:not(html|select) > scrollbar` so that scrollbars
inside a <select> are excluded (including them hides the select arrow on
Windows). We want to include both the root scrollbars for the document as
well as any overflow: scroll elements within the page, while excluding
<select>. */
*|*:not(html|select) > scrollbar {
-moz-appearance: none !important;
position: relative;
background-color: transparent;
background-image: none;
z-index: 2147483647;
padding: 2px;
border: none;
}
/* Scrollbar code will reset the margin to the correct side depending on
where layout actually puts the scrollbar */
*|*:not(html|select) > scrollbar[orient="vertical"] {
margin-left: -10px;
min-width: 10px;
max-width: 10px;
}
*|*:not(html|select) > scrollbar[orient="horizontal"] {
margin-top: -10px;
min-height: 10px;
max-height: 10px;
}
*|*:not(html|select) > scrollbar slider {
-moz-appearance: none !important;
}
*|*:not(html|select) > scrollbar thumb {
-moz-appearance: none !important;
background-color: rgba(0,0,0,0.2);
border-width: 0px !important;
border-radius: 3px !important;
}
*|*:not(html|select) > scrollbar scrollbarbutton,
*|*:not(html|select) > scrollbar gripper {
display: none;
}

Просмотреть файл

@ -2,16 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
@namespace html url("http://www.w3.org/1999/xhtml");
/* Restrict all styles to `*|*:not(html|select) > scrollbar` so that scrollbars
inside a <select> are excluded (including them hides the select arrow on
Windows). We want to include both the root scrollbars for the document as
well as any overflow: scroll elements within the page, while excluding
<select>. */
*|*:not(html|select) > scrollbar {
-moz-appearance: none !important;
display: none;
* {
scrollbar-width: none !important;
}

Просмотреть файл

@ -6,11 +6,9 @@ const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
const {FrameTree} = ChromeUtils.import('chrome://juggler/content/content/FrameTree.js');
const {NetworkMonitor} = ChromeUtils.import('chrome://juggler/content/content/NetworkMonitor.js');
const {ScrollbarManager} = ChromeUtils.import('chrome://juggler/content/content/ScrollbarManager.js');
const {SimpleChannel} = ChromeUtils.import('chrome://juggler/content/SimpleChannel.js');
const {PageAgent} = ChromeUtils.import('chrome://juggler/content/content/PageAgent.js');
const scrollbarManager = new ScrollbarManager(docShell);
let frameTree;
let networkMonitor;
const helper = new Helper();
@ -182,7 +180,6 @@ function initialize() {
for (const sessionId of sessions.keys())
disposeContentSession(sessionId);
scrollbarManager.dispose();
networkMonitor.dispose();
frameTree.dispose();
}),