Skip to content

Commit e5a1da0

Browse files
committed
Allow to change the toolbar height when changing the pref toolbar.density in Firefox (bug 1171799)
It's a first step to just dispatch the pref change to the toolbar. The second one, to effectively use it, will come after PR #18385 is merged.
1 parent 9065ee4 commit e5a1da0

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

web/app.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ const PDFViewerApplication = {
402402
} else {
403403
eventBus = new EventBus();
404404
}
405-
this.eventBus = eventBus;
405+
this.eventBus = this.preferences.eventBus = eventBus;
406406

407407
this.overlayManager = new OverlayManager();
408408

@@ -569,7 +569,11 @@ const PDFViewerApplication = {
569569
await this._nimbusDataPromise
570570
);
571571
} else {
572-
this.toolbar = new Toolbar(appConfig.toolbar, eventBus);
572+
this.toolbar = new Toolbar(
573+
appConfig.toolbar,
574+
eventBus,
575+
AppOptions.get("toolbarDensity")
576+
);
573577
}
574578
}
575579

web/app_options.js

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ const defaultOptions = {
9595
value: true,
9696
kind: OptionKind.BROWSER,
9797
},
98+
toolbarDensity: {
99+
/** @type {number} */
100+
// 0 = "normal", 1 = "compact", 2 = "touch"
101+
value: 0,
102+
kind: OptionKind.BROWSER,
103+
},
98104

99105
annotationEditorMode: {
100106
/** @type {number} */

web/preferences.js

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class BasePreferences {
3737

3838
#initializedPromise = null;
3939

40+
static #eventToDispatch = new Set(["toolbarDensity"]);
41+
4042
constructor() {
4143
if (this.constructor === BasePreferences) {
4244
throw new Error("Cannot initialize BasePreferences.");
@@ -73,6 +75,10 @@ class BasePreferences {
7375
}
7476
}
7577
);
78+
79+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
80+
this.eventBus = null;
81+
}
7682
}
7783

7884
/**
@@ -113,6 +119,9 @@ class BasePreferences {
113119
return; // Invalid preference.
114120
}
115121
AppOptions.set(name, value);
122+
if (this.eventBus && BasePreferences.#eventToDispatch.has(name)) {
123+
this.eventBus.dispatch(name.toLowerCase(), { source: this, value });
124+
}
116125
}
117126

118127
/**

web/toolbar.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ class Toolbar {
5050
/**
5151
* @param {ToolbarOptions} options
5252
* @param {EventBus} eventBus
53+
* @param {number} toolbarDensity - The toolbar density value.
54+
* The possible values are:
55+
* - 0 (default) - The regular toolbar size.
56+
* - 1 (compact) - The small toolbar size.
57+
* - 2 (touch) - The large toolbar size.
5358
*/
54-
constructor(options, eventBus) {
59+
constructor(options, eventBus, toolbarDensity = 0) {
5560
this.#opts = options;
5661
this.eventBus = eventBus;
5762
const buttons = [
@@ -136,9 +141,14 @@ class Toolbar {
136141
}
137142
});
138143

144+
eventBus._on("toolbardensity", this.#updateToolbarDensity.bind(this));
145+
this.#updateToolbarDensity({ value: toolbarDensity });
146+
139147
this.reset();
140148
}
141149

150+
#updateToolbarDensity() {}
151+
142152
#setAnnotationEditorUIManager(uiManager, parentContainer) {
143153
const colorPicker = new ColorPicker({ uiManager });
144154
uiManager.setMainHighlightColorPicker(colorPicker);

0 commit comments

Comments
 (0)