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