Skip to content

Commit

Permalink
Allow to change the toolbar height when changing the pref toolbar.den…
Browse files Browse the repository at this point in the history
…sity 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 mozilla#18385 is merged.
  • Loading branch information
calixteman committed Jul 5, 2024
1 parent 9065ee4 commit e5a1da0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
8 changes: 6 additions & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ const PDFViewerApplication = {
} else {
eventBus = new EventBus();
}
this.eventBus = eventBus;
this.eventBus = this.preferences.eventBus = eventBus;

this.overlayManager = new OverlayManager();

Expand Down Expand Up @@ -569,7 +569,11 @@ const PDFViewerApplication = {
await this._nimbusDataPromise
);
} else {
this.toolbar = new Toolbar(appConfig.toolbar, eventBus);
this.toolbar = new Toolbar(
appConfig.toolbar,
eventBus,
AppOptions.get("toolbarDensity")
);
}
}

Expand Down
6 changes: 6 additions & 0 deletions web/app_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ const defaultOptions = {
value: true,
kind: OptionKind.BROWSER,
},
toolbarDensity: {
/** @type {number} */
// 0 = "normal", 1 = "compact", 2 = "touch"
value: 0,
kind: OptionKind.BROWSER,
},

annotationEditorMode: {
/** @type {number} */
Expand Down
9 changes: 9 additions & 0 deletions web/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class BasePreferences {

#initializedPromise = null;

static #eventToDispatch = new Set(["toolbarDensity"]);

constructor() {
if (this.constructor === BasePreferences) {
throw new Error("Cannot initialize BasePreferences.");
Expand Down Expand Up @@ -73,6 +75,10 @@ class BasePreferences {
}
}
);

if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
this.eventBus = null;
}
}

/**
Expand Down Expand Up @@ -113,6 +119,9 @@ class BasePreferences {
return; // Invalid preference.
}
AppOptions.set(name, value);
if (this.eventBus && BasePreferences.#eventToDispatch.has(name)) {
this.eventBus.dispatch(name.toLowerCase(), { source: this, value });
}
}

/**
Expand Down
12 changes: 11 additions & 1 deletion web/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ class Toolbar {
/**
* @param {ToolbarOptions} options
* @param {EventBus} eventBus
* @param {number} toolbarDensity - The toolbar density value.
* The possible values are:
* - 0 (default) - The regular toolbar size.
* - 1 (compact) - The small toolbar size.
* - 2 (touch) - The large toolbar size.
*/
constructor(options, eventBus) {
constructor(options, eventBus, toolbarDensity = 0) {
this.#opts = options;
this.eventBus = eventBus;
const buttons = [
Expand Down Expand Up @@ -136,9 +141,14 @@ class Toolbar {
}
});

eventBus._on("toolbardensity", this.#updateToolbarDensity.bind(this));
this.#updateToolbarDensity({ value: toolbarDensity });

this.reset();
}

#updateToolbarDensity() {}

#setAnnotationEditorUIManager(uiManager, parentContainer) {
const colorPicker = new ColorPicker({ uiManager });
uiManager.setMainHighlightColorPicker(colorPicker);
Expand Down

0 comments on commit e5a1da0

Please sign in to comment.