[Editor] Dispatch an event when some global states are changing

- this way the context menu in Firefox can take into account what we
  have in the clipboard, if an editor is selected, ...
- when the user will click on a context menu item, an action will be
  triggered, hence this patch adds what is required to handle it;
- some tests will be added in the Firefox' patch.
This commit is contained in:
Calixte Denizet 2022-07-04 18:04:32 +02:00
parent a1ac1a61b7
commit ec0f9f6dcf
8 changed files with 278 additions and 28 deletions

View file

@ -271,6 +271,20 @@ class MozL10n {
window.addEventListener("save", handleEvent);
})();
(function listenEditingEvent() {
const handleEvent = function ({ detail }) {
if (!PDFViewerApplication.initialized) {
return;
}
PDFViewerApplication.eventBus.dispatch("editingaction", {
source: window,
name: detail.name,
});
};
window.addEventListener("editingaction", handleEvent);
})();
class FirefoxComDataRangeTransport extends PDFDataRangeTransport {
requestDataRange(begin, end) {
FirefoxCom.request("requestDataRange", { begin, end });
@ -384,6 +398,10 @@ class FirefoxExternalServices extends DefaultExternalServices {
return new FirefoxPreferences();
}
static updateEditorStates(data) {
FirefoxCom.request("updateEditorStates", data);
}
static createL10n(options) {
const mozL10n = document.mozL10n;
// TODO refactor mozL10n.setExternalLocalizerServices