2016-02-22 01:54:23 +09:00
|
|
|
/* Copyright 2016 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.
|
|
|
|
*/
|
|
|
|
|
2017-05-04 10:05:53 +09:00
|
|
|
import { NullL10n } from './ui_utils';
|
2017-04-15 00:32:36 +09:00
|
|
|
import { RenderingStates } from './pdf_rendering_queue';
|
2017-01-15 20:37:06 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
const UI_NOTIFICATION_CLASS = 'pdfSidebarNotification';
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
const SidebarView = {
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
UNKNOWN: -1,
|
2016-02-22 01:54:23 +09:00
|
|
|
NONE: 0,
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
THUMBS: 1, // Default value.
|
2016-02-22 01:54:23 +09:00
|
|
|
OUTLINE: 2,
|
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
|
|
|
ATTACHMENTS: 3,
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
LAYERS: 4,
|
2016-02-22 01:54:23 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {Object} PDFSidebarOptions
|
2019-02-24 21:12:23 +09:00
|
|
|
* @property {PDFSidebarElements} elements - The DOM elements.
|
2016-03-12 21:07:43 +09:00
|
|
|
* @property {PDFViewer} pdfViewer - The document viewer.
|
|
|
|
* @property {PDFThumbnailViewer} pdfThumbnailViewer - The thumbnail viewer.
|
2019-02-24 21:12:23 +09:00
|
|
|
* @property {EventBus} eventBus - The application event bus.
|
|
|
|
* @property {IL10n} l10n - The localization service.
|
|
|
|
* @property {boolean} disableNotification - (optional) Disable the notification
|
|
|
|
* for documents containing outline/attachments. The default value is `false`.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {Object} PDFSidebarElements
|
2016-02-22 01:54:23 +09:00
|
|
|
* @property {HTMLDivElement} outerContainer - The outer container
|
|
|
|
* (encasing both the viewer and sidebar elements).
|
2017-09-30 23:41:46 +09:00
|
|
|
* @property {HTMLDivElement} viewerContainer - The viewer container
|
|
|
|
* (in which the viewer element is placed).
|
2016-02-22 01:54:23 +09:00
|
|
|
* @property {HTMLButtonElement} toggleButton - The button used for
|
|
|
|
* opening/closing the sidebar.
|
|
|
|
* @property {HTMLButtonElement} thumbnailButton - The button used to show
|
|
|
|
* the thumbnail view.
|
|
|
|
* @property {HTMLButtonElement} outlineButton - The button used to show
|
|
|
|
* the outline view.
|
|
|
|
* @property {HTMLButtonElement} attachmentsButton - The button used to show
|
|
|
|
* the attachments view.
|
|
|
|
* @property {HTMLDivElement} thumbnailView - The container in which
|
|
|
|
* the thumbnails are placed.
|
|
|
|
* @property {HTMLDivElement} outlineView - The container in which
|
|
|
|
* the outline is placed.
|
|
|
|
* @property {HTMLDivElement} attachmentsView - The container in which
|
|
|
|
* the attachments are placed.
|
|
|
|
*/
|
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
class PDFSidebar {
|
2016-02-22 01:54:23 +09:00
|
|
|
/**
|
|
|
|
* @param {PDFSidebarOptions} options
|
|
|
|
*/
|
2019-02-24 21:12:23 +09:00
|
|
|
constructor({ elements, pdfViewer, pdfThumbnailViewer, eventBus,
|
|
|
|
l10n = NullL10n, disableNotification = false, }) {
|
2016-02-22 01:54:23 +09:00
|
|
|
this.isOpen = false;
|
|
|
|
this.active = SidebarView.THUMBS;
|
|
|
|
this.isInitialViewSet = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback used when the sidebar has been opened/closed, to ensure that
|
|
|
|
* the viewers (PDFViewer/PDFThumbnailViewer) are updated correctly.
|
|
|
|
*/
|
|
|
|
this.onToggled = null;
|
|
|
|
|
2019-02-24 21:12:23 +09:00
|
|
|
this.pdfViewer = pdfViewer;
|
|
|
|
this.pdfThumbnailViewer = pdfThumbnailViewer;
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2019-02-24 21:12:23 +09:00
|
|
|
this.outerContainer = elements.outerContainer;
|
|
|
|
this.viewerContainer = elements.viewerContainer;
|
|
|
|
this.toggleButton = elements.toggleButton;
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2019-02-24 21:12:23 +09:00
|
|
|
this.thumbnailButton = elements.thumbnailButton;
|
|
|
|
this.outlineButton = elements.outlineButton;
|
|
|
|
this.attachmentsButton = elements.attachmentsButton;
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2019-02-24 21:12:23 +09:00
|
|
|
this.thumbnailView = elements.thumbnailView;
|
|
|
|
this.outlineView = elements.outlineView;
|
|
|
|
this.attachmentsView = elements.attachmentsView;
|
2017-01-15 20:37:06 +09:00
|
|
|
|
2018-10-02 20:08:24 +09:00
|
|
|
this.eventBus = eventBus;
|
2017-05-04 10:05:53 +09:00
|
|
|
this.l10n = l10n;
|
2019-02-24 21:12:23 +09:00
|
|
|
this._disableNotification = disableNotification;
|
2017-05-04 10:05:53 +09:00
|
|
|
|
2016-02-22 01:54:23 +09:00
|
|
|
this._addEventListeners();
|
|
|
|
}
|
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
reset() {
|
|
|
|
this.isInitialViewSet = false;
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
this._hideUINotification(null);
|
|
|
|
this.switchView(SidebarView.THUMBS);
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
this.outlineButton.disabled = false;
|
|
|
|
this.attachmentsButton.disabled = false;
|
|
|
|
}
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
/**
|
|
|
|
* @returns {number} One of the values in {SidebarView}.
|
|
|
|
*/
|
|
|
|
get visibleView() {
|
|
|
|
return (this.isOpen ? this.active : SidebarView.NONE);
|
|
|
|
}
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
get isThumbnailViewVisible() {
|
|
|
|
return (this.isOpen && this.active === SidebarView.THUMBS);
|
|
|
|
}
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
get isOutlineViewVisible() {
|
|
|
|
return (this.isOpen && this.active === SidebarView.OUTLINE);
|
|
|
|
}
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
get isAttachmentsViewVisible() {
|
|
|
|
return (this.isOpen && this.active === SidebarView.ATTACHMENTS);
|
|
|
|
}
|
2016-03-12 21:07:43 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
/**
|
|
|
|
* @param {number} view - The sidebar view that should become visible,
|
|
|
|
* must be one of the values in {SidebarView}.
|
|
|
|
*/
|
Remove the ability to pass a `scale` parameter in the (optional) `args` object parameter of `PDFViewerApplication.open(file, args)`
Since the very early days of the viewer, it's been possible to pass in a `scale` when opening a PDF file. However, most of the time it was/is actually being ignored, which limits its usefulness considerably.
In older versions of the viewer, if a document hash was present (i.e. `PDFViewerApplication.initialBookmark` being set) or if the document existed in the `ViewHistory`, the `scale` passed to `PDFViewerApplication.open` would thus always be ignored.
In addition to the above, in the current viewer there's even more cases where the `scale` parameter will be ignored: if a (valid) browser history entry exists on document load, or if the `defaultZoomValue` preference is set to a non-default value.
Hence the result is that in most situation, a `scale` passed to `PDFViewerApplication.open` will be completely ignored.
A much better, not to mention supported, way of setting the initial scale is by using the `defaultZoomLevel` preference. In comparision, this also has the advantage of being used in situations where the `scale` would be ignored.
All in all this leads to the current situation where we have code which is essentially dead, since no part of the viewer (by default) relies on it.
To clean up this code, and to avoid having to pass (basically) unused parameters around, I'd thus like to remove the ability to pass a `scale` to `PDFViewerApplication.open`.
2017-08-24 16:24:32 +09:00
|
|
|
setInitialView(view = SidebarView.NONE) {
|
2017-04-18 03:32:21 +09:00
|
|
|
if (this.isInitialViewSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.isInitialViewSet = true;
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2019-02-02 18:03:30 +09:00
|
|
|
// If the user has already manually opened the sidebar, immediately closing
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
// it would be bad UX; also ignore the "unknown" sidebar view value.
|
|
|
|
if (view === SidebarView.NONE || view === SidebarView.UNKNOWN) {
|
2017-04-18 03:32:21 +09:00
|
|
|
this._dispatchEvent();
|
|
|
|
return;
|
|
|
|
}
|
2019-02-02 18:03:30 +09:00
|
|
|
// Prevent dispatching two back-to-back `sidebarviewchanged` events,
|
|
|
|
// since `this._switchView` dispatched the event if the view changed.
|
|
|
|
if (!this._switchView(view, /* forceOpen */ true)) {
|
2017-04-18 03:32:21 +09:00
|
|
|
this._dispatchEvent();
|
|
|
|
}
|
|
|
|
}
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
/**
|
|
|
|
* @param {number} view - The sidebar view that should be switched to,
|
|
|
|
* must be one of the values in {SidebarView}.
|
|
|
|
* @param {boolean} forceOpen - (optional) Ensure that the sidebar is open.
|
|
|
|
* The default value is `false`.
|
|
|
|
*/
|
|
|
|
switchView(view, forceOpen = false) {
|
2019-02-02 18:03:30 +09:00
|
|
|
this._switchView(view, forceOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean} Indicating if `this._dispatchEvent` was called.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_switchView(view, forceOpen = false) {
|
|
|
|
const isViewChanged = (view !== this.active);
|
2017-06-30 19:55:22 +09:00
|
|
|
let shouldForceRendering = false;
|
2017-04-18 03:32:21 +09:00
|
|
|
|
|
|
|
switch (view) {
|
2019-02-02 18:03:30 +09:00
|
|
|
case SidebarView.NONE:
|
|
|
|
if (this.isOpen) {
|
|
|
|
this.close();
|
|
|
|
return true; // Closing will trigger rendering and dispatch the event.
|
|
|
|
}
|
|
|
|
return false;
|
2017-04-18 03:32:21 +09:00
|
|
|
case SidebarView.THUMBS:
|
|
|
|
if (this.isOpen && isViewChanged) {
|
|
|
|
shouldForceRendering = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SidebarView.OUTLINE:
|
|
|
|
if (this.outlineButton.disabled) {
|
2019-02-02 18:03:30 +09:00
|
|
|
return false;
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SidebarView.ATTACHMENTS:
|
|
|
|
if (this.attachmentsButton.disabled) {
|
2019-02-02 18:03:30 +09:00
|
|
|
return false;
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2019-02-02 18:03:30 +09:00
|
|
|
console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
|
|
|
|
return false;
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
|
|
|
// Update the active view *after* it has been validated above,
|
|
|
|
// in order to prevent setting it to an invalid state.
|
2019-02-07 01:18:45 +09:00
|
|
|
this.active = view;
|
|
|
|
|
|
|
|
// Update the CSS classes, for all buttons...
|
|
|
|
this.thumbnailButton.classList.toggle('toggled',
|
|
|
|
view === SidebarView.THUMBS);
|
|
|
|
this.outlineButton.classList.toggle('toggled',
|
|
|
|
view === SidebarView.OUTLINE);
|
|
|
|
this.attachmentsButton.classList.toggle('toggled',
|
|
|
|
view === SidebarView.ATTACHMENTS);
|
|
|
|
// ... and for all views.
|
|
|
|
this.thumbnailView.classList.toggle('hidden', view !== SidebarView.THUMBS);
|
|
|
|
this.outlineView.classList.toggle('hidden', view !== SidebarView.OUTLINE);
|
|
|
|
this.attachmentsView.classList.toggle('hidden',
|
|
|
|
view !== SidebarView.ATTACHMENTS);
|
2017-04-18 03:32:21 +09:00
|
|
|
|
|
|
|
if (forceOpen && !this.isOpen) {
|
|
|
|
this.open();
|
2019-02-02 18:03:30 +09:00
|
|
|
return true; // Opening will trigger rendering and dispatch the event.
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
|
|
|
if (shouldForceRendering) {
|
2019-02-07 01:18:45 +09:00
|
|
|
this._updateThumbnailViewer();
|
2016-02-22 01:54:23 +09:00
|
|
|
this._forceRendering();
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
|
|
|
if (isViewChanged) {
|
2016-03-12 21:07:43 +09:00
|
|
|
this._dispatchEvent();
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
|
|
|
this._hideUINotification(this.active);
|
2019-02-02 18:03:30 +09:00
|
|
|
return isViewChanged;
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
2017-01-15 20:37:06 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
open() {
|
|
|
|
if (this.isOpen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.isOpen = true;
|
|
|
|
this.toggleButton.classList.add('toggled');
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2019-02-07 01:18:45 +09:00
|
|
|
this.outerContainer.classList.add('sidebarMoving', 'sidebarOpen');
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
if (this.active === SidebarView.THUMBS) {
|
|
|
|
this._updateThumbnailViewer();
|
|
|
|
}
|
|
|
|
this._forceRendering();
|
|
|
|
this._dispatchEvent();
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
this._hideUINotification(this.active);
|
|
|
|
}
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
close() {
|
|
|
|
if (!this.isOpen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.isOpen = false;
|
|
|
|
this.toggleButton.classList.remove('toggled');
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
this.outerContainer.classList.add('sidebarMoving');
|
|
|
|
this.outerContainer.classList.remove('sidebarOpen');
|
2016-03-12 21:07:43 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
this._forceRendering();
|
|
|
|
this._dispatchEvent();
|
|
|
|
}
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
toggle() {
|
|
|
|
if (this.isOpen) {
|
|
|
|
this.close();
|
|
|
|
} else {
|
|
|
|
this.open();
|
|
|
|
}
|
|
|
|
}
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_dispatchEvent() {
|
|
|
|
this.eventBus.dispatch('sidebarviewchanged', {
|
|
|
|
source: this,
|
|
|
|
view: this.visibleView,
|
|
|
|
});
|
|
|
|
}
|
2017-01-15 20:37:06 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_forceRendering() {
|
|
|
|
if (this.onToggled) {
|
|
|
|
this.onToggled();
|
|
|
|
} else { // Fallback
|
|
|
|
this.pdfViewer.forceRendering();
|
|
|
|
this.pdfThumbnailViewer.forceRendering();
|
|
|
|
}
|
|
|
|
}
|
2017-01-15 20:37:06 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_updateThumbnailViewer() {
|
2017-06-30 19:55:22 +09:00
|
|
|
let { pdfViewer, pdfThumbnailViewer, } = this;
|
2017-04-18 03:32:21 +09:00
|
|
|
|
|
|
|
// Use the rendered pages to set the corresponding thumbnail images.
|
2017-06-30 19:55:22 +09:00
|
|
|
let pagesCount = pdfViewer.pagesCount;
|
|
|
|
for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
|
|
|
|
let pageView = pdfViewer.getPageView(pageIndex);
|
2017-04-18 03:32:21 +09:00
|
|
|
if (pageView && pageView.renderingState === RenderingStates.FINISHED) {
|
2017-06-30 19:55:22 +09:00
|
|
|
let thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
|
2017-04-18 03:32:21 +09:00
|
|
|
thumbnailView.setImage(pageView);
|
2017-01-15 20:37:06 +09:00
|
|
|
}
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
2017-06-30 19:55:22 +09:00
|
|
|
pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
2017-01-15 20:37:06 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_showUINotification(view) {
|
2019-02-24 21:12:23 +09:00
|
|
|
if (this._disableNotification) {
|
2017-04-18 03:32:21 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-04 10:05:53 +09:00
|
|
|
this.l10n.get('toggle_sidebar_notification.title', null,
|
|
|
|
'Toggle Sidebar (document contains outline/attachments)').
|
|
|
|
then((msg) => {
|
|
|
|
this.toggleButton.title = msg;
|
|
|
|
});
|
2017-04-18 03:32:21 +09:00
|
|
|
|
|
|
|
if (!this.isOpen) {
|
|
|
|
// Only show the notification on the `toggleButton` if the sidebar is
|
|
|
|
// currently closed, to avoid unnecessarily bothering the user.
|
|
|
|
this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
|
|
|
|
} else if (view === this.active) {
|
|
|
|
// If the sidebar is currently open *and* the `view` is visible, do not
|
|
|
|
// bother the user with a notification on the corresponding button.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (view) {
|
|
|
|
case SidebarView.OUTLINE:
|
|
|
|
this.outlineButton.classList.add(UI_NOTIFICATION_CLASS);
|
|
|
|
break;
|
|
|
|
case SidebarView.ATTACHMENTS:
|
|
|
|
this.attachmentsButton.classList.add(UI_NOTIFICATION_CLASS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_hideUINotification(view) {
|
2019-02-24 21:12:23 +09:00
|
|
|
if (this._disableNotification) {
|
2017-04-18 03:32:21 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-30 19:55:22 +09:00
|
|
|
let removeNotification = (view) => {
|
2017-01-15 20:37:06 +09:00
|
|
|
switch (view) {
|
|
|
|
case SidebarView.OUTLINE:
|
2017-04-18 03:32:21 +09:00
|
|
|
this.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
|
2017-01-15 20:37:06 +09:00
|
|
|
break;
|
|
|
|
case SidebarView.ATTACHMENTS:
|
2017-04-18 03:32:21 +09:00
|
|
|
this.attachmentsButton.classList.remove(UI_NOTIFICATION_CLASS);
|
2017-01-15 20:37:06 +09:00
|
|
|
break;
|
|
|
|
}
|
2017-04-18 03:32:21 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!this.isOpen && view !== null) {
|
|
|
|
// Only hide the notifications when the sidebar is currently open,
|
|
|
|
// or when it is being reset (i.e. `view === null`).
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
|
|
|
|
|
|
|
|
if (view !== null) {
|
|
|
|
removeNotification(view);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (view in SidebarView) { // Remove all sidebar notifications on reset.
|
|
|
|
removeNotification(SidebarView[view]);
|
|
|
|
}
|
|
|
|
|
2017-05-04 10:05:53 +09:00
|
|
|
this.l10n.get('toggle_sidebar.title', null, 'Toggle Sidebar').
|
|
|
|
then((msg) => {
|
|
|
|
this.toggleButton.title = msg;
|
|
|
|
});
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
2017-01-15 20:37:06 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_addEventListeners() {
|
2017-09-30 23:41:46 +09:00
|
|
|
this.viewerContainer.addEventListener('transitionend', (evt) => {
|
|
|
|
if (evt.target === this.viewerContainer) {
|
2017-04-18 03:32:21 +09:00
|
|
|
this.outerContainer.classList.remove('sidebarMoving');
|
2017-01-15 20:37:06 +09:00
|
|
|
}
|
2017-04-18 03:32:21 +09:00
|
|
|
});
|
2017-01-15 20:37:06 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
// Buttons for switching views.
|
|
|
|
this.thumbnailButton.addEventListener('click', () => {
|
|
|
|
this.switchView(SidebarView.THUMBS);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.outlineButton.addEventListener('click', () => {
|
|
|
|
this.switchView(SidebarView.OUTLINE);
|
|
|
|
});
|
|
|
|
this.outlineButton.addEventListener('dblclick', () => {
|
2018-10-02 20:08:24 +09:00
|
|
|
this.eventBus.dispatch('toggleoutlinetree', { source: this, });
|
2017-04-18 03:32:21 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
this.attachmentsButton.addEventListener('click', () => {
|
|
|
|
this.switchView(SidebarView.ATTACHMENTS);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Disable/enable views.
|
|
|
|
this.eventBus.on('outlineloaded', (evt) => {
|
2017-06-30 19:55:22 +09:00
|
|
|
let outlineCount = evt.outlineCount;
|
2017-04-18 03:32:21 +09:00
|
|
|
|
|
|
|
this.outlineButton.disabled = !outlineCount;
|
|
|
|
|
|
|
|
if (outlineCount) {
|
|
|
|
this._showUINotification(SidebarView.OUTLINE);
|
|
|
|
} else if (this.active === SidebarView.OUTLINE) {
|
|
|
|
// If the outline view was opened during document load, switch away
|
|
|
|
// from it if it turns out that the document has no outline.
|
|
|
|
this.switchView(SidebarView.THUMBS);
|
2017-01-15 20:37:06 +09:00
|
|
|
}
|
2017-04-18 03:32:21 +09:00
|
|
|
});
|
2017-01-15 20:37:06 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
this.eventBus.on('attachmentsloaded', (evt) => {
|
2017-08-17 21:12:42 +09:00
|
|
|
if (evt.attachmentsCount) {
|
|
|
|
this.attachmentsButton.disabled = false;
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
this._showUINotification(SidebarView.ATTACHMENTS);
|
2017-08-17 21:12:42 +09:00
|
|
|
return;
|
2017-04-18 03:32:21 +09:00
|
|
|
}
|
2017-08-17 21:12:42 +09:00
|
|
|
|
|
|
|
// Attempt to avoid temporarily disabling, and switching away from, the
|
|
|
|
// attachment view for documents that do not contain proper attachments
|
|
|
|
// but *only* FileAttachment annotations. Hence we defer those operations
|
|
|
|
// slightly to allow time for parsing any FileAttachment annotations that
|
|
|
|
// may be present on the *initially* rendered page of the document.
|
|
|
|
Promise.resolve().then(() => {
|
|
|
|
if (this.attachmentsView.hasChildNodes()) {
|
|
|
|
// FileAttachment annotations were appended to the attachment view.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.attachmentsButton.disabled = true;
|
|
|
|
|
|
|
|
if (this.active === SidebarView.ATTACHMENTS) {
|
|
|
|
// If the attachment view was opened during document load, switch away
|
|
|
|
// from it if it turns out that the document has no attachments.
|
|
|
|
this.switchView(SidebarView.THUMBS);
|
|
|
|
}
|
|
|
|
});
|
2017-04-18 03:32:21 +09:00
|
|
|
});
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-04-18 03:32:21 +09:00
|
|
|
// Update the thumbnailViewer, if visible, when exiting presentation mode.
|
|
|
|
this.eventBus.on('presentationmodechanged', (evt) => {
|
|
|
|
if (!evt.active && !evt.switchInProgress && this.isThumbnailViewVisible) {
|
|
|
|
this._updateThumbnailViewer();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
export {
|
|
|
|
SidebarView,
|
|
|
|
PDFSidebar,
|
|
|
|
};
|