2013-09-05 06:48:31 +09:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-04-13 19:36:39 +09:00
|
|
|
import {
|
|
|
|
CursorTool,
|
|
|
|
ScrollMode,
|
|
|
|
SpreadMode,
|
|
|
|
toggleCheckedBtn,
|
2023-05-11 18:48:51 +09:00
|
|
|
toggleExpandedBtn,
|
2023-04-13 19:36:39 +09:00
|
|
|
} from "./ui_utils.js";
|
2022-09-08 18:53:56 +09:00
|
|
|
import { PagesCountLimit } from "./pdf_viewer.js";
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2016-05-11 08:31:03 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} SecondaryToolbarOptions
|
|
|
|
* @property {HTMLDivElement} toolbar - Container for the secondary toolbar.
|
|
|
|
* @property {HTMLButtonElement} toggleButton - Button to toggle the visibility
|
|
|
|
* of the secondary toolbar.
|
|
|
|
* @property {HTMLButtonElement} presentationModeButton - Button for entering
|
|
|
|
* presentation mode.
|
|
|
|
* @property {HTMLButtonElement} openFileButton - Button to open a file.
|
|
|
|
* @property {HTMLButtonElement} printButton - Button to print the document.
|
|
|
|
* @property {HTMLButtonElement} downloadButton - Button to download the
|
|
|
|
* document.
|
2021-09-30 20:30:55 +09:00
|
|
|
* @property {HTMLAnchorElement} viewBookmarkButton - Button to obtain a
|
|
|
|
* bookmark link to the current location in the document.
|
2016-05-11 08:31:03 +09:00
|
|
|
* @property {HTMLButtonElement} firstPageButton - Button to go to the first
|
|
|
|
* page in the document.
|
|
|
|
* @property {HTMLButtonElement} lastPageButton - Button to go to the last page
|
|
|
|
* in the document.
|
|
|
|
* @property {HTMLButtonElement} pageRotateCwButton - Button to rotate the pages
|
|
|
|
* clockwise.
|
|
|
|
* @property {HTMLButtonElement} pageRotateCcwButton - Button to rotate the
|
|
|
|
* pages counterclockwise.
|
2016-09-07 20:30:26 +09:00
|
|
|
* @property {HTMLButtonElement} cursorSelectToolButton - Button to enable the
|
|
|
|
* select tool.
|
|
|
|
* @property {HTMLButtonElement} cursorHandToolButton - Button to enable the
|
2016-05-11 08:31:03 +09:00
|
|
|
* hand tool.
|
|
|
|
* @property {HTMLButtonElement} documentPropertiesButton - Button for opening
|
|
|
|
* the document properties dialog.
|
|
|
|
*/
|
2013-09-05 06:48:31 +09:00
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
class SecondaryToolbar {
|
2023-12-26 18:56:48 +09:00
|
|
|
#opts;
|
|
|
|
|
2016-05-11 08:31:03 +09:00
|
|
|
/**
|
|
|
|
* @param {SecondaryToolbarOptions} options
|
|
|
|
* @param {EventBus} eventBus
|
|
|
|
*/
|
2023-09-20 21:08:28 +09:00
|
|
|
constructor(options, eventBus) {
|
2023-12-26 18:56:48 +09:00
|
|
|
this.#opts = options;
|
|
|
|
const buttons = [
|
2016-05-11 08:31:03 +09:00
|
|
|
{
|
|
|
|
element: options.presentationModeButton,
|
|
|
|
eventName: "presentationmode",
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
close: true,
|
|
|
|
},
|
|
|
|
{ element: options.printButton, eventName: "print", close: true },
|
|
|
|
{ element: options.downloadButton, eventName: "download", close: true },
|
|
|
|
{ element: options.viewBookmarkButton, eventName: null, close: true },
|
|
|
|
{ element: options.firstPageButton, eventName: "firstpage", close: true },
|
|
|
|
{ element: options.lastPageButton, eventName: "lastpage", close: true },
|
2016-05-11 08:31:03 +09:00
|
|
|
{
|
|
|
|
element: options.pageRotateCwButton,
|
|
|
|
eventName: "rotatecw",
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
close: false,
|
|
|
|
},
|
2016-05-11 08:31:03 +09:00
|
|
|
{
|
|
|
|
element: options.pageRotateCcwButton,
|
|
|
|
eventName: "rotateccw",
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
close: false,
|
|
|
|
},
|
2016-09-07 20:30:26 +09:00
|
|
|
{
|
|
|
|
element: options.cursorSelectToolButton,
|
|
|
|
eventName: "switchcursortool",
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
eventDetails: { tool: CursorTool.SELECT },
|
|
|
|
close: true,
|
|
|
|
},
|
2016-09-07 20:30:26 +09:00
|
|
|
{
|
|
|
|
element: options.cursorHandToolButton,
|
|
|
|
eventName: "switchcursortool",
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
eventDetails: { tool: CursorTool.HAND },
|
|
|
|
close: true,
|
|
|
|
},
|
2021-10-07 21:04:41 +09:00
|
|
|
{
|
|
|
|
element: options.scrollPageButton,
|
|
|
|
eventName: "switchscrollmode",
|
|
|
|
eventDetails: { mode: ScrollMode.PAGE },
|
|
|
|
close: true,
|
|
|
|
},
|
2018-05-15 12:10:32 +09:00
|
|
|
{
|
|
|
|
element: options.scrollVerticalButton,
|
|
|
|
eventName: "switchscrollmode",
|
|
|
|
eventDetails: { mode: ScrollMode.VERTICAL },
|
|
|
|
close: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: options.scrollHorizontalButton,
|
|
|
|
eventName: "switchscrollmode",
|
|
|
|
eventDetails: { mode: ScrollMode.HORIZONTAL },
|
|
|
|
close: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: options.scrollWrappedButton,
|
|
|
|
eventName: "switchscrollmode",
|
|
|
|
eventDetails: { mode: ScrollMode.WRAPPED },
|
|
|
|
close: true,
|
|
|
|
},
|
2018-05-15 12:10:32 +09:00
|
|
|
{
|
|
|
|
element: options.spreadNoneButton,
|
|
|
|
eventName: "switchspreadmode",
|
|
|
|
eventDetails: { mode: SpreadMode.NONE },
|
|
|
|
close: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: options.spreadOddButton,
|
|
|
|
eventName: "switchspreadmode",
|
|
|
|
eventDetails: { mode: SpreadMode.ODD },
|
|
|
|
close: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: options.spreadEvenButton,
|
|
|
|
eventName: "switchspreadmode",
|
|
|
|
eventDetails: { mode: SpreadMode.EVEN },
|
|
|
|
close: true,
|
|
|
|
},
|
2016-05-11 08:31:03 +09:00
|
|
|
{
|
|
|
|
element: options.documentPropertiesButton,
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
eventName: "documentproperties",
|
|
|
|
close: true,
|
|
|
|
},
|
2013-10-18 06:49:30 +09:00
|
|
|
];
|
2022-05-08 05:05:39 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2023-12-26 18:56:48 +09:00
|
|
|
buttons.push({
|
2022-04-25 17:06:47 +09:00
|
|
|
element: options.openFileButton,
|
|
|
|
eventName: "openfile",
|
|
|
|
close: true,
|
|
|
|
});
|
|
|
|
}
|
2013-10-18 06:49:30 +09:00
|
|
|
|
2016-05-11 08:31:03 +09:00
|
|
|
this.eventBus = eventBus;
|
|
|
|
this.opened = false;
|
|
|
|
|
2018-05-15 12:10:32 +09:00
|
|
|
// Bind the event listeners for click, cursor tool, and scroll/spread mode
|
|
|
|
// actions.
|
2023-12-26 18:56:48 +09:00
|
|
|
this.#bindListeners(buttons);
|
2022-08-10 04:33:18 +09:00
|
|
|
|
|
|
|
this.reset();
|
2016-05-11 08:31:03 +09:00
|
|
|
}
|
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {boolean}
|
2017-05-08 04:43:50 +09:00
|
|
|
*/
|
|
|
|
get isOpen() {
|
|
|
|
return this.opened;
|
|
|
|
}
|
|
|
|
|
|
|
|
setPageNumber(pageNumber) {
|
|
|
|
this.pageNumber = pageNumber;
|
2022-03-06 23:44:53 +09:00
|
|
|
this.#updateUIState();
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
setPagesCount(pagesCount) {
|
|
|
|
this.pagesCount = pagesCount;
|
2022-03-06 23:44:53 +09:00
|
|
|
this.#updateUIState();
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
this.pageNumber = 0;
|
|
|
|
this.pagesCount = 0;
|
2022-03-06 23:44:53 +09:00
|
|
|
this.#updateUIState();
|
2018-06-30 21:54:33 +09:00
|
|
|
|
|
|
|
// Reset the Scroll/Spread buttons too, since they're document specific.
|
2023-12-26 18:56:48 +09:00
|
|
|
this.#scrollModeChanged({ mode: ScrollMode.VERTICAL });
|
|
|
|
this.#spreadModeChanged({ mode: SpreadMode.NONE });
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
|
|
|
|
2022-03-06 23:44:53 +09:00
|
|
|
#updateUIState() {
|
2023-12-26 18:56:48 +09:00
|
|
|
const {
|
|
|
|
firstPageButton,
|
|
|
|
lastPageButton,
|
|
|
|
pageRotateCwButton,
|
|
|
|
pageRotateCcwButton,
|
|
|
|
} = this.#opts;
|
|
|
|
|
|
|
|
firstPageButton.disabled = this.pageNumber <= 1;
|
|
|
|
lastPageButton.disabled = this.pageNumber >= this.pagesCount;
|
|
|
|
pageRotateCwButton.disabled = this.pagesCount === 0;
|
|
|
|
pageRotateCcwButton.disabled = this.pagesCount === 0;
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
|
|
|
|
2023-12-26 18:56:48 +09:00
|
|
|
#bindListeners(buttons) {
|
|
|
|
const { eventBus } = this;
|
|
|
|
const { toggleButton } = this.#opts;
|
2017-05-08 04:43:50 +09:00
|
|
|
// Button to toggle the visibility of the secondary toolbar.
|
2023-12-26 18:56:48 +09:00
|
|
|
toggleButton.addEventListener("click", this.toggle.bind(this));
|
2017-05-08 04:43:50 +09:00
|
|
|
|
|
|
|
// All items within the secondary toolbar.
|
2023-12-26 18:56:48 +09:00
|
|
|
for (const { element, eventName, close, eventDetails } of buttons) {
|
2017-05-08 04:43:50 +09:00
|
|
|
element.addEventListener("click", evt => {
|
|
|
|
if (eventName !== null) {
|
2023-12-26 18:56:48 +09:00
|
|
|
eventBus.dispatch(eventName, { source: this, ...eventDetails });
|
2016-05-11 08:31:03 +09:00
|
|
|
}
|
2017-05-08 04:43:50 +09:00
|
|
|
if (close) {
|
|
|
|
this.close();
|
2016-05-11 08:31:03 +09:00
|
|
|
}
|
2023-12-26 18:56:48 +09:00
|
|
|
eventBus.dispatch("reporttelemetry", {
|
2023-09-20 21:08:28 +09:00
|
|
|
source: this,
|
|
|
|
details: {
|
|
|
|
type: "buttons",
|
|
|
|
data: { id: element.id },
|
|
|
|
},
|
2022-09-09 02:23:41 +09:00
|
|
|
});
|
2016-12-10 21:58:06 +09:00
|
|
|
});
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
2023-12-26 18:56:48 +09:00
|
|
|
|
|
|
|
eventBus._on("cursortoolchanged", this.#cursorToolChanged.bind(this));
|
|
|
|
eventBus._on("scrollmodechanged", this.#scrollModeChanged.bind(this));
|
|
|
|
eventBus._on("spreadmodechanged", this.#spreadModeChanged.bind(this));
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
2016-09-08 19:35:49 +09:00
|
|
|
|
2023-12-26 18:56:48 +09:00
|
|
|
#cursorToolChanged({ tool }) {
|
|
|
|
const { cursorSelectToolButton, cursorHandToolButton } = this.#opts;
|
|
|
|
|
|
|
|
toggleCheckedBtn(cursorSelectToolButton, tool === CursorTool.SELECT);
|
|
|
|
toggleCheckedBtn(cursorHandToolButton, tool === CursorTool.HAND);
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
2016-09-08 19:35:49 +09:00
|
|
|
|
2023-12-26 18:56:48 +09:00
|
|
|
#scrollModeChanged({ mode }) {
|
|
|
|
const {
|
|
|
|
scrollPageButton,
|
|
|
|
scrollVerticalButton,
|
|
|
|
scrollHorizontalButton,
|
|
|
|
scrollWrappedButton,
|
|
|
|
spreadNoneButton,
|
|
|
|
spreadOddButton,
|
|
|
|
spreadEvenButton,
|
|
|
|
} = this.#opts;
|
2018-07-08 17:56:06 +09:00
|
|
|
|
2023-12-26 18:56:48 +09:00
|
|
|
toggleCheckedBtn(scrollPageButton, mode === ScrollMode.PAGE);
|
|
|
|
toggleCheckedBtn(scrollVerticalButton, mode === ScrollMode.VERTICAL);
|
|
|
|
toggleCheckedBtn(scrollHorizontalButton, mode === ScrollMode.HORIZONTAL);
|
|
|
|
toggleCheckedBtn(scrollWrappedButton, mode === ScrollMode.WRAPPED);
|
Enforce PAGE-scrolling for *very* large/long documents (bug 1588435, PR 11263 follow-up)
This patch is essentially a continuation of PR 11263, which tried to improve loading/initialization performance of *very* large/long documents.
Note that browsers, in general, don't handle a huge amount of DOM-elements very well, with really poor (e.g. sluggish scrolling) performance once the number gets "large". Furthermore, at least in Firefox, it seems that DOM-elements towards the bottom of a HTML-page can effectively be ignored; for the PDF.js viewer that means that pages at the end of the document can become impossible to access.
Hence, in order to improve things for these *very* large/long documents, this patch will now enforce usage of the (recently added) PAGE-scrolling mode for these documents. As implemented, this will only happen once the number of pages *exceed* 15000 (which is hopefully rare in practice).
While this might feel a bit jarring to users being *forced* to use PAGE-scrolling, it seems all things considered like a better idea to ensure that the entire document actually remains accessible and with (hopefully) more acceptable performance.
Fixes [bug 1588435](https://bugzilla.mozilla.org/show_bug.cgi?id=1588435), to the extent that doing so is possible since the document contains 25560 pages (and is 197 MB large).
2021-11-29 02:43:30 +09:00
|
|
|
|
2023-12-26 18:56:48 +09:00
|
|
|
// Permanently *disable* the Scroll buttons when PAGE-scrolling is being
|
|
|
|
// enforced for *very* long/large documents; please see the `BaseViewer`.
|
|
|
|
const forceScrollModePage =
|
|
|
|
this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
|
|
|
|
scrollPageButton.disabled = forceScrollModePage;
|
|
|
|
scrollVerticalButton.disabled = forceScrollModePage;
|
|
|
|
scrollHorizontalButton.disabled = forceScrollModePage;
|
|
|
|
scrollWrappedButton.disabled = forceScrollModePage;
|
2018-06-30 21:54:33 +09:00
|
|
|
|
2023-12-26 18:56:48 +09:00
|
|
|
// Temporarily *disable* the Spread buttons when horizontal scrolling is
|
|
|
|
// enabled, since the non-default Spread modes doesn't affect the layout.
|
|
|
|
const isHorizontal = mode === ScrollMode.HORIZONTAL;
|
|
|
|
spreadNoneButton.disabled = isHorizontal;
|
|
|
|
spreadOddButton.disabled = isHorizontal;
|
|
|
|
spreadEvenButton.disabled = isHorizontal;
|
2018-05-15 12:10:32 +09:00
|
|
|
}
|
|
|
|
|
2023-12-26 18:56:48 +09:00
|
|
|
#spreadModeChanged({ mode }) {
|
|
|
|
const { spreadNoneButton, spreadOddButton, spreadEvenButton } = this.#opts;
|
2018-06-30 21:54:33 +09:00
|
|
|
|
2023-12-26 18:56:48 +09:00
|
|
|
toggleCheckedBtn(spreadNoneButton, mode === SpreadMode.NONE);
|
|
|
|
toggleCheckedBtn(spreadOddButton, mode === SpreadMode.ODD);
|
|
|
|
toggleCheckedBtn(spreadEvenButton, mode === SpreadMode.EVEN);
|
2018-05-15 12:10:32 +09:00
|
|
|
}
|
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
open() {
|
|
|
|
if (this.opened) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.opened = true;
|
2023-12-26 18:56:48 +09:00
|
|
|
|
|
|
|
const { toggleButton, toolbar } = this.#opts;
|
|
|
|
toggleExpandedBtn(toggleButton, true, toolbar);
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
2016-09-08 19:35:49 +09:00
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
close() {
|
|
|
|
if (!this.opened) {
|
|
|
|
return;
|
2013-09-05 06:48:31 +09:00
|
|
|
}
|
2017-05-08 04:43:50 +09:00
|
|
|
this.opened = false;
|
2023-12-26 18:56:48 +09:00
|
|
|
|
|
|
|
const { toggleButton, toolbar } = this.#opts;
|
|
|
|
toggleExpandedBtn(toggleButton, false, toolbar);
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
2016-05-11 08:31:03 +09:00
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
toggle() {
|
|
|
|
if (this.opened) {
|
|
|
|
this.close();
|
|
|
|
} else {
|
|
|
|
this.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
export { SecondaryToolbar };
|