Merge pull request #11655 from Snuffleupagus/rm-getGlobalEventBus
[api-minor] Remove the `getGlobalEventBus` viewer functionality, and the `eventBusDispatchToDOM` option/preference (PR 11631 follow-up)
This commit is contained in:
commit
ce1727626c
@ -58,10 +58,6 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"eventBusDispatchToDOM": {
|
|
||||||
"type": "boolean",
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"pdfBugEnabled": {
|
"pdfBugEnabled": {
|
||||||
"title": "Enable debugging tools",
|
"title": "Enable debugging tools",
|
||||||
"description": "Whether to enable debugging tools.",
|
"description": "Whether to enable debugging tools.",
|
||||||
|
@ -312,7 +312,7 @@ describe("ui_utils", function() {
|
|||||||
expect(count).toEqual(2);
|
expect(count).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not, by default, re-dispatch to DOM", function(done) {
|
it("should not re-dispatch to DOM", function(done) {
|
||||||
if (isNodeJS) {
|
if (isNodeJS) {
|
||||||
pending("Document in not supported in Node.js.");
|
pending("Document in not supported in Node.js.");
|
||||||
}
|
}
|
||||||
@ -329,54 +329,6 @@ describe("ui_utils", function() {
|
|||||||
|
|
||||||
eventBus.dispatch("test");
|
eventBus.dispatch("test");
|
||||||
|
|
||||||
Promise.resolve().then(() => {
|
|
||||||
expect(count).toEqual(1);
|
|
||||||
|
|
||||||
document.removeEventListener("test", domEventListener);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it("should re-dispatch to DOM", function(done) {
|
|
||||||
if (isNodeJS) {
|
|
||||||
pending("Document in not supported in Node.js.");
|
|
||||||
}
|
|
||||||
const eventBus = new EventBus({ dispatchToDOM: true });
|
|
||||||
let count = 0;
|
|
||||||
eventBus.on("test", function(evt) {
|
|
||||||
expect(evt).toEqual(undefined);
|
|
||||||
count++;
|
|
||||||
});
|
|
||||||
function domEventListener(evt) {
|
|
||||||
expect(evt.detail).toEqual({});
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
document.addEventListener("test", domEventListener);
|
|
||||||
|
|
||||||
eventBus.dispatch("test");
|
|
||||||
|
|
||||||
Promise.resolve().then(() => {
|
|
||||||
expect(count).toEqual(2);
|
|
||||||
|
|
||||||
document.removeEventListener("test", domEventListener);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it("should re-dispatch to DOM, with arguments (without internal listeners)", function(done) {
|
|
||||||
if (isNodeJS) {
|
|
||||||
pending("Document in not supported in Node.js.");
|
|
||||||
}
|
|
||||||
const eventBus = new EventBus({ dispatchToDOM: true });
|
|
||||||
let count = 0;
|
|
||||||
function domEventListener(evt) {
|
|
||||||
expect(evt.detail).toEqual({ abc: 123 });
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
document.addEventListener("test", domEventListener);
|
|
||||||
|
|
||||||
eventBus.dispatch("test", {
|
|
||||||
abc: 123,
|
|
||||||
});
|
|
||||||
|
|
||||||
Promise.resolve().then(() => {
|
Promise.resolve().then(() => {
|
||||||
expect(count).toEqual(1);
|
expect(count).toEqual(1);
|
||||||
|
|
||||||
|
10
web/app.js
10
web/app.js
@ -125,6 +125,10 @@ class DefaultExternalServices {
|
|||||||
metaKey: true,
|
metaKey: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get isInAutomation() {
|
||||||
|
return shadow(this, "isInAutomation", false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const PDFViewerApplication = {
|
const PDFViewerApplication = {
|
||||||
@ -339,13 +343,13 @@ const PDFViewerApplication = {
|
|||||||
async _initializeViewerComponents() {
|
async _initializeViewerComponents() {
|
||||||
const appConfig = this.appConfig;
|
const appConfig = this.appConfig;
|
||||||
|
|
||||||
this.overlayManager = new OverlayManager();
|
|
||||||
|
|
||||||
const eventBus =
|
const eventBus =
|
||||||
appConfig.eventBus ||
|
appConfig.eventBus ||
|
||||||
new EventBus({ dispatchToDOM: AppOptions.get("eventBusDispatchToDOM") });
|
new EventBus({ isInAutomation: this.externalServices.isInAutomation });
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
|
this.overlayManager = new OverlayManager();
|
||||||
|
|
||||||
const pdfRenderingQueue = new PDFRenderingQueue();
|
const pdfRenderingQueue = new PDFRenderingQueue();
|
||||||
pdfRenderingQueue.onIdle = this.cleanup.bind(this);
|
pdfRenderingQueue.onIdle = this.cleanup.bind(this);
|
||||||
this.pdfRenderingQueue = pdfRenderingQueue;
|
this.pdfRenderingQueue = pdfRenderingQueue;
|
||||||
|
@ -66,11 +66,6 @@ const defaultOptions = {
|
|||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
eventBusDispatchToDOM: {
|
|
||||||
/** @type {boolean} */
|
|
||||||
value: false,
|
|
||||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
||||||
},
|
|
||||||
externalLinkRel: {
|
externalLinkRel: {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
value: "noopener noreferrer nofollow",
|
value: "noopener noreferrer nofollow",
|
||||||
|
@ -17,7 +17,6 @@ import {
|
|||||||
CSS_UNITS,
|
CSS_UNITS,
|
||||||
DEFAULT_SCALE,
|
DEFAULT_SCALE,
|
||||||
DEFAULT_SCALE_VALUE,
|
DEFAULT_SCALE_VALUE,
|
||||||
getGlobalEventBus,
|
|
||||||
getVisibleElements,
|
getVisibleElements,
|
||||||
isPortraitOrientation,
|
isPortraitOrientation,
|
||||||
isValidRotation,
|
isValidRotation,
|
||||||
@ -145,7 +144,7 @@ class BaseViewer {
|
|||||||
|
|
||||||
this.container = options.container;
|
this.container = options.container;
|
||||||
this.viewer = options.viewer || options.container.firstElementChild;
|
this.viewer = options.viewer || options.container.firstElementChild;
|
||||||
this.eventBus = options.eventBus || getGlobalEventBus();
|
this.eventBus = options.eventBus;
|
||||||
this.linkService = options.linkService || new SimpleLinkService();
|
this.linkService = options.linkService || new SimpleLinkService();
|
||||||
this.downloadManager = options.downloadManager || null;
|
this.downloadManager = options.downloadManager || null;
|
||||||
this.findController = options.findController || null;
|
this.findController = options.findController || null;
|
||||||
|
@ -345,6 +345,13 @@ class FirefoxExternalServices extends DefaultExternalServices {
|
|||||||
);
|
);
|
||||||
return shadow(this, "supportedMouseWheelZoomModifierKeys", support);
|
return shadow(this, "supportedMouseWheelZoomModifierKeys", support);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get isInAutomation() {
|
||||||
|
// Returns the value of `Cu.isInAutomation`, which is only `true` when e.g.
|
||||||
|
// various test-suites are running in mozilla-central.
|
||||||
|
const isInAutomation = FirefoxCom.requestSync("isInAutomation");
|
||||||
|
return shadow(this, "isInAutomation", isInAutomation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PDFViewerApplication.externalServices = FirefoxExternalServices;
|
PDFViewerApplication.externalServices = FirefoxExternalServices;
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getGlobalEventBus, NullL10n } from "./ui_utils.js";
|
|
||||||
import { FindState } from "./pdf_find_controller.js";
|
import { FindState } from "./pdf_find_controller.js";
|
||||||
|
import { NullL10n } from "./ui_utils.js";
|
||||||
|
|
||||||
const MATCHES_COUNT_LIMIT = 1000;
|
const MATCHES_COUNT_LIMIT = 1000;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ class PDFFindBar {
|
|||||||
this.findResultsCount = options.findResultsCount || null;
|
this.findResultsCount = options.findResultsCount || null;
|
||||||
this.findPreviousButton = options.findPreviousButton || null;
|
this.findPreviousButton = options.findPreviousButton || null;
|
||||||
this.findNextButton = options.findNextButton || null;
|
this.findNextButton = options.findNextButton || null;
|
||||||
this.eventBus = eventBus || getGlobalEventBus();
|
this.eventBus = eventBus;
|
||||||
this.l10n = l10n;
|
this.l10n = l10n;
|
||||||
|
|
||||||
// Add event listeners to the DOM elements.
|
// Add event listeners to the DOM elements.
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getGlobalEventBus, scrollIntoView } from "./ui_utils.js";
|
|
||||||
import { createPromiseCapability } from "pdfjs-lib";
|
import { createPromiseCapability } from "pdfjs-lib";
|
||||||
import { getCharacterType } from "./pdf_find_utils.js";
|
import { getCharacterType } from "./pdf_find_utils.js";
|
||||||
|
import { scrollIntoView } from "./ui_utils.js";
|
||||||
|
|
||||||
const FindState = {
|
const FindState = {
|
||||||
FOUND: 0,
|
FOUND: 0,
|
||||||
@ -69,7 +69,7 @@ class PDFFindController {
|
|||||||
*/
|
*/
|
||||||
constructor({ linkService, eventBus }) {
|
constructor({ linkService, eventBus }) {
|
||||||
this._linkService = linkService;
|
this._linkService = linkService;
|
||||||
this._eventBus = eventBus || getGlobalEventBus();
|
this._eventBus = eventBus;
|
||||||
|
|
||||||
this._reset();
|
this._reset();
|
||||||
eventBus._on("findbarclose", this._onFindBarClose.bind(this));
|
eventBus._on("findbarclose", this._onFindBarClose.bind(this));
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getGlobalEventBus,
|
|
||||||
isValidRotation,
|
isValidRotation,
|
||||||
parseQueryString,
|
parseQueryString,
|
||||||
waitOnEventOrTimeout,
|
waitOnEventOrTimeout,
|
||||||
@ -59,7 +58,7 @@ class PDFHistory {
|
|||||||
*/
|
*/
|
||||||
constructor({ linkService, eventBus }) {
|
constructor({ linkService, eventBus }) {
|
||||||
this.linkService = linkService;
|
this.linkService = linkService;
|
||||||
this.eventBus = eventBus || getGlobalEventBus();
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
this._initialized = false;
|
this._initialized = false;
|
||||||
this._fingerprint = "";
|
this._fingerprint = "";
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getGlobalEventBus, parseQueryString } from "./ui_utils.js";
|
import { parseQueryString } from "./ui_utils.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} PDFLinkServiceOptions
|
* @typedef {Object} PDFLinkServiceOptions
|
||||||
@ -44,7 +44,7 @@ class PDFLinkService {
|
|||||||
externalLinkEnabled = true,
|
externalLinkEnabled = true,
|
||||||
ignoreDestinationZoom = false,
|
ignoreDestinationZoom = false,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
this.eventBus = eventBus || getGlobalEventBus();
|
this.eventBus = eventBus;
|
||||||
this.externalLinkTarget = externalLinkTarget;
|
this.externalLinkTarget = externalLinkTarget;
|
||||||
this.externalLinkRel = externalLinkRel;
|
this.externalLinkRel = externalLinkRel;
|
||||||
this.externalLinkEnabled = externalLinkEnabled;
|
this.externalLinkEnabled = externalLinkEnabled;
|
||||||
|
@ -17,7 +17,6 @@ import {
|
|||||||
approximateFraction,
|
approximateFraction,
|
||||||
CSS_UNITS,
|
CSS_UNITS,
|
||||||
DEFAULT_SCALE,
|
DEFAULT_SCALE,
|
||||||
getGlobalEventBus,
|
|
||||||
getOutputScale,
|
getOutputScale,
|
||||||
NullL10n,
|
NullL10n,
|
||||||
RendererType,
|
RendererType,
|
||||||
@ -92,7 +91,7 @@ class PDFPageView {
|
|||||||
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
||||||
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
|
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
|
||||||
|
|
||||||
this.eventBus = options.eventBus || getGlobalEventBus();
|
this.eventBus = options.eventBus;
|
||||||
this.renderingQueue = options.renderingQueue;
|
this.renderingQueue = options.renderingQueue;
|
||||||
this.textLayerFactory = options.textLayerFactory;
|
this.textLayerFactory = options.textLayerFactory;
|
||||||
this.annotationLayerFactory = options.annotationLayerFactory;
|
this.annotationLayerFactory = options.annotationLayerFactory;
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getGlobalEventBus } from "./ui_utils.js";
|
|
||||||
import { renderTextLayer } from "pdfjs-lib";
|
import { renderTextLayer } from "pdfjs-lib";
|
||||||
|
|
||||||
const EXPAND_DIVS_TIMEOUT = 300; // ms
|
const EXPAND_DIVS_TIMEOUT = 300; // ms
|
||||||
@ -45,7 +44,7 @@ class TextLayerBuilder {
|
|||||||
enhanceTextSelection = false,
|
enhanceTextSelection = false,
|
||||||
}) {
|
}) {
|
||||||
this.textLayerDiv = textLayerDiv;
|
this.textLayerDiv = textLayerDiv;
|
||||||
this.eventBus = eventBus || getGlobalEventBus();
|
this.eventBus = eventBus;
|
||||||
this.textContent = null;
|
this.textContent = null;
|
||||||
this.textContentItemsStr = [];
|
this.textContentItemsStr = [];
|
||||||
this.textContentStream = null;
|
this.textContentStream = null;
|
||||||
|
@ -760,6 +760,9 @@ const animationStarted = new Promise(function(resolve) {
|
|||||||
* NOTE: Only used to support various PDF viewer tests in `mozilla-central`.
|
* NOTE: Only used to support various PDF viewer tests in `mozilla-central`.
|
||||||
*/
|
*/
|
||||||
function dispatchDOMEvent(eventName, args = null) {
|
function dispatchDOMEvent(eventName, args = null) {
|
||||||
|
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("MOZCENTRAL")) {
|
||||||
|
throw new Error("Not implemented: dispatchDOMEvent");
|
||||||
|
}
|
||||||
const details = Object.create(null);
|
const details = Object.create(null);
|
||||||
if (args && args.length > 0) {
|
if (args && args.length > 0) {
|
||||||
const obj = args[0];
|
const obj = args[0];
|
||||||
@ -784,19 +787,11 @@ function dispatchDOMEvent(eventName, args = null) {
|
|||||||
* and `off` methods. To raise an event, the `dispatch` method shall be used.
|
* and `off` methods. To raise an event, the `dispatch` method shall be used.
|
||||||
*/
|
*/
|
||||||
class EventBus {
|
class EventBus {
|
||||||
constructor({ dispatchToDOM = false } = {}) {
|
constructor(options) {
|
||||||
this._listeners = Object.create(null);
|
this._listeners = Object.create(null);
|
||||||
this._dispatchToDOM = dispatchToDOM === true;
|
|
||||||
|
|
||||||
if (
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("MOZCENTRAL")) {
|
||||||
typeof PDFJSDev !== "undefined" &&
|
this._isInAutomation = (options && options.isInAutomation) === true;
|
||||||
!PDFJSDev.test("MOZCENTRAL || TESTING") &&
|
|
||||||
dispatchToDOM
|
|
||||||
) {
|
|
||||||
console.error(
|
|
||||||
"The `eventBusDispatchToDOM` option/preference is deprecated, " +
|
|
||||||
"add event listeners to the EventBus instance rather than the DOM."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -819,7 +814,10 @@ class EventBus {
|
|||||||
dispatch(eventName) {
|
dispatch(eventName) {
|
||||||
const eventListeners = this._listeners[eventName];
|
const eventListeners = this._listeners[eventName];
|
||||||
if (!eventListeners || eventListeners.length === 0) {
|
if (!eventListeners || eventListeners.length === 0) {
|
||||||
if (this._dispatchToDOM) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("MOZCENTRAL")) &&
|
||||||
|
this._isInAutomation
|
||||||
|
) {
|
||||||
const args = Array.prototype.slice.call(arguments, 1);
|
const args = Array.prototype.slice.call(arguments, 1);
|
||||||
dispatchDOMEvent(eventName, args);
|
dispatchDOMEvent(eventName, args);
|
||||||
}
|
}
|
||||||
@ -848,7 +846,10 @@ class EventBus {
|
|||||||
});
|
});
|
||||||
externalListeners = null;
|
externalListeners = null;
|
||||||
}
|
}
|
||||||
if (this._dispatchToDOM) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("MOZCENTRAL")) &&
|
||||||
|
this._isInAutomation
|
||||||
|
) {
|
||||||
dispatchDOMEvent(eventName, args);
|
dispatchDOMEvent(eventName, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -884,17 +885,6 @@ class EventBus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let globalEventBus = null;
|
|
||||||
function getGlobalEventBus(dispatchToDOM = false) {
|
|
||||||
console.error(
|
|
||||||
"getGlobalEventBus is deprecated, use a manually created EventBus instance instead."
|
|
||||||
);
|
|
||||||
if (!globalEventBus) {
|
|
||||||
globalEventBus = new EventBus({ dispatchToDOM });
|
|
||||||
}
|
|
||||||
return globalEventBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
function clamp(v, min, max) {
|
function clamp(v, min, max) {
|
||||||
return Math.min(Math.max(v, min), max);
|
return Math.min(Math.max(v, min), max);
|
||||||
}
|
}
|
||||||
@ -1013,7 +1003,6 @@ export {
|
|||||||
SpreadMode,
|
SpreadMode,
|
||||||
NullL10n,
|
NullL10n,
|
||||||
EventBus,
|
EventBus,
|
||||||
getGlobalEventBus,
|
|
||||||
clamp,
|
clamp,
|
||||||
ProgressBar,
|
ProgressBar,
|
||||||
getPDFFileNameFromURL,
|
getPDFFileNameFromURL,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user