Removes PresentationMode dependency from PDFViewer
This commit is contained in:
parent
a06a974f78
commit
fbd7eedce8
@ -15,9 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals RenderingStates, PDFView, PDFJS, mozL10n, CustomStyle,
|
||||
PresentationMode, scrollIntoView, SCROLLBAR_PADDING, CSS_UNITS,
|
||||
UNKNOWN_SCALE, DEFAULT_SCALE, getOutputScale, TextLayerBuilder,
|
||||
Stats */
|
||||
SCROLLBAR_PADDING, CSS_UNITS, UNKNOWN_SCALE, DEFAULT_SCALE,
|
||||
getOutputScale, TextLayerBuilder, scrollIntoView, Stats,
|
||||
PresentationModeState */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -346,7 +346,8 @@ var PageView = function pageView(container, id, scale, defaultViewport,
|
||||
};
|
||||
|
||||
this.scrollIntoView = function pageViewScrollIntoView(dest) {
|
||||
if (PresentationMode.active) {
|
||||
if (this.viewer.presentationModeState ===
|
||||
PresentationModeState.FULLSCREEN) {
|
||||
if (this.linkService.page !== this.id) {
|
||||
// Avoid breaking getVisiblePages in presentation mode.
|
||||
this.linkService.page = this.id;
|
||||
@ -520,13 +521,15 @@ var PageView = function pageView(container, id, scale, defaultViewport,
|
||||
div.appendChild(textLayerDiv);
|
||||
}
|
||||
}
|
||||
var isViewerInPresentationMode =
|
||||
this.viewer.presentationModeState === PresentationModeState.FULLSCREEN;
|
||||
var textLayer = this.textLayer =
|
||||
textLayerDiv ? new TextLayerBuilder({
|
||||
textLayerDiv: textLayerDiv,
|
||||
pageIndex: this.id - 1,
|
||||
lastScrollSource: this.linkService,
|
||||
viewport: this.viewport,
|
||||
isViewerInPresentationMode: PresentationMode.active,
|
||||
isViewerInPresentationMode: isViewerInPresentationMode,
|
||||
findController: PDFView.findController
|
||||
}) : null;
|
||||
// TODO(mack): use data attributes to store these
|
||||
|
@ -16,11 +16,18 @@
|
||||
*/
|
||||
/*globals watchScroll, Cache, DEFAULT_CACHE_SIZE, PageView, UNKNOWN_SCALE,
|
||||
IGNORE_CURRENT_POSITION_ON_ZOOM, SCROLLBAR_PADDING, VERTICAL_PADDING,
|
||||
MAX_AUTO_SCALE, getVisibleElements, PresentationMode,
|
||||
RenderingStates, Promise, CSS_UNITS, PDFJS */
|
||||
MAX_AUTO_SCALE, getVisibleElements, RenderingStates, Promise,
|
||||
CSS_UNITS, PDFJS */
|
||||
|
||||
'use strict';
|
||||
|
||||
var PresentationModeState = {
|
||||
UNKNOWN: 0,
|
||||
NORMAL: 1,
|
||||
CHANGING: 2,
|
||||
FULLSCREEN: 3,
|
||||
};
|
||||
|
||||
var PDFViewer = (function pdfViewer() {
|
||||
function PDFViewer(options) {
|
||||
this.container = options.container;
|
||||
@ -30,6 +37,7 @@ var PDFViewer = (function pdfViewer() {
|
||||
|
||||
this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this));
|
||||
this.updateInProgress = false;
|
||||
this.presentationModeState = PresentationModeState.UNKNOWN;
|
||||
this.resetView();
|
||||
}
|
||||
|
||||
@ -191,7 +199,10 @@ var PDFViewer = (function pdfViewer() {
|
||||
|
||||
if (!noScroll) {
|
||||
var page = this.currentPageNumber, dest;
|
||||
if (this.location && !this.inPresentationMode &&
|
||||
var inPresentationMode =
|
||||
this.presentationModeState === PresentationModeState.CHANGING ||
|
||||
this.presentationModeState === PresentationModeState.FULLSCREEN;
|
||||
if (this.location && !inPresentationMode &&
|
||||
!IGNORE_CURRENT_POSITION_ON_ZOOM) {
|
||||
page = this.location.pageNumber;
|
||||
dest = [null, { name: 'XYZ' }, this.location.left,
|
||||
@ -223,8 +234,10 @@ var PDFViewer = (function pdfViewer() {
|
||||
if (!currentPage) {
|
||||
return;
|
||||
}
|
||||
var hPadding = PresentationMode.active ? 0 : SCROLLBAR_PADDING;
|
||||
var vPadding = PresentationMode.active ? 0 : VERTICAL_PADDING;
|
||||
var inPresentationMode =
|
||||
this.presentationModeState === PresentationModeState.FULLSCREEN;
|
||||
var hPadding = inPresentationMode ? 0 : SCROLLBAR_PADDING;
|
||||
var vPadding = inPresentationMode ? 0 : VERTICAL_PADDING;
|
||||
var pageWidthScale = (this.container.clientWidth - hPadding) /
|
||||
currentPage.width * currentPage.scale;
|
||||
var pageHeightScale = (this.container.clientHeight - vPadding) /
|
||||
@ -295,10 +308,6 @@ var PDFViewer = (function pdfViewer() {
|
||||
};
|
||||
},
|
||||
|
||||
get inPresentationMode() {
|
||||
return PresentationMode.active || PresentationMode.switchInProgress;
|
||||
},
|
||||
|
||||
update: function () {
|
||||
var visible = this.getVisiblePages();
|
||||
var visiblePages = visible.views;
|
||||
@ -334,7 +343,7 @@ var PDFViewer = (function pdfViewer() {
|
||||
currentId = visiblePages[0].id;
|
||||
}
|
||||
|
||||
if (!PresentationMode.active) {
|
||||
if (this.presentationModeState !== PresentationModeState.FULLSCREEN) {
|
||||
this.setCurrentPageNumber(currentId);
|
||||
}
|
||||
|
||||
@ -360,12 +369,12 @@ var PDFViewer = (function pdfViewer() {
|
||||
},
|
||||
|
||||
get isHorizontalScrollbarEnabled() {
|
||||
return (PresentationMode.active ? false :
|
||||
(this.container.scrollWidth > this.container.clientWidth));
|
||||
return (this.presentationModeState === PresentationModeState.FULLSCREEN ?
|
||||
false : (this.container.scrollWidth > this.container.clientWidth));
|
||||
},
|
||||
|
||||
getVisiblePages: function () {
|
||||
if (!PresentationMode.active) {
|
||||
if (this.presentationModeState !== PresentationModeState.FULLSCREEN) {
|
||||
return getVisibleElements(this.container, this.pages, true);
|
||||
} else {
|
||||
// The algorithm in getVisibleElements doesn't work in all browsers and
|
||||
|
@ -81,6 +81,7 @@ var PresentationMode = {
|
||||
}
|
||||
this.switchInProgress = setTimeout(function switchInProgressTimeout() {
|
||||
delete this.switchInProgress;
|
||||
this._notifyStateChange();
|
||||
}.bind(this), DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
|
||||
},
|
||||
|
||||
@ -97,6 +98,7 @@ var PresentationMode = {
|
||||
return false;
|
||||
}
|
||||
this._setSwitchInProgress();
|
||||
this._notifyStateChange();
|
||||
|
||||
if (this.container.requestFullscreen) {
|
||||
this.container.requestFullscreen();
|
||||
@ -118,9 +120,19 @@ var PresentationMode = {
|
||||
return true;
|
||||
},
|
||||
|
||||
_notifyStateChange: function presentationModeNotifyStateChange() {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent('presentationmodechanged', true, true, {
|
||||
active: PresentationMode.active,
|
||||
switchInProgress: !!PresentationMode.switchInProgress
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
},
|
||||
|
||||
enter: function presentationModeEnter() {
|
||||
this.active = true;
|
||||
this._resetSwitchInProgress();
|
||||
this._notifyStateChange();
|
||||
|
||||
// Ensure that the correct page is scrolled into view when entering
|
||||
// Presentation Mode, by waiting until fullscreen mode in enabled.
|
||||
@ -148,6 +160,8 @@ var PresentationMode = {
|
||||
// Note: This is only necessary in non-Mozilla browsers.
|
||||
setTimeout(function exitPresentationModeTimeout() {
|
||||
this.active = false;
|
||||
this._notifyStateChange();
|
||||
|
||||
PDFView.setScale(this.args.previousScale, true);
|
||||
PDFView.page = page;
|
||||
this.args = null;
|
||||
|
@ -21,7 +21,7 @@
|
||||
PasswordPrompt, PresentationMode, HandTool, Promise,
|
||||
DocumentProperties, DocumentOutlineView, DocumentAttachmentsView,
|
||||
OverlayManager, PDFFindController, PDFFindBar, getVisibleElements,
|
||||
watchScroll, PDFViewer, PDFRenderingQueue */
|
||||
watchScroll, PDFViewer, PDFRenderingQueue, PresentationModeState */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -1668,6 +1668,14 @@ document.addEventListener('pagerendered', function (e) {
|
||||
thumbnailView.setImage(pageView.canvas);
|
||||
}, true);
|
||||
|
||||
window.addEventListener('presentationmodechanged', function (e) {
|
||||
var active = e.detail.active;
|
||||
var switchInProgress = e.detail.switchInProgress;
|
||||
PDFView.pdfViewer.presentationModeState =
|
||||
switchInProgress ? PresentationModeState.CHANGING :
|
||||
active ? PresentationModeState.FULLSCREEN : PresentationModeState.NORMAL;
|
||||
});
|
||||
|
||||
function updateViewarea() {
|
||||
if (!PDFView.initialized) {
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user