diff --git a/web/presentation_mode.js b/web/presentation_mode.js index 6fc223ba6..4ef1a0e7b 100644 --- a/web/presentation_mode.js +++ b/web/presentation_mode.js @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* globals scrollIntoView, PDFViewerApplication */ +/* globals PDFViewerApplication */ 'use strict'; @@ -27,41 +27,26 @@ var PresentationMode = { active: false, args: null, contextMenuOpen: false, -//#if (GENERIC || CHROME) - prevCoords: { x: null, y: null }, -//#endif mouseScrollTimeStamp: 0, mouseScrollDelta: 0, initialize: function presentationModeInitialize(options) { this.initialized = true; this.container = options.container; - this.secondaryToolbar = options.secondaryToolbar; + this.pdfThumbnailViewer = options.pdfThumbnailViewer || null; + var contextMenuItems = options.contextMenuItems || null; this.viewer = this.container.firstElementChild; - this.firstPage = options.firstPage; - this.lastPage = options.lastPage; - this.pageRotateCw = options.pageRotateCw; - this.pageRotateCcw = options.pageRotateCcw; - - this.firstPage.addEventListener('click', function() { - this.contextMenuOpen = false; - this.secondaryToolbar.firstPageClick(); - }.bind(this)); - this.lastPage.addEventListener('click', function() { - this.contextMenuOpen = false; - this.secondaryToolbar.lastPageClick(); - }.bind(this)); - - this.pageRotateCw.addEventListener('click', function() { - this.contextMenuOpen = false; - this.secondaryToolbar.pageRotateCwClick(); - }.bind(this)); - this.pageRotateCcw.addEventListener('click', function() { - this.contextMenuOpen = false; - this.secondaryToolbar.pageRotateCcwClick(); - }.bind(this)); + if (contextMenuItems) { + for (var i = 0, ii = contextMenuItems.length; i < ii; i++) { + var item = contextMenuItems[i]; + item.element.addEventListener('click', function (handler) { + this.contextMenuOpen = false; + handler(); + }.bind(this, item.handler)); + } + } }, get isFullscreen() { @@ -186,9 +171,11 @@ var PresentationMode = { this.container.removeAttribute('contextmenu'); this.contextMenuOpen = false; - // Ensure that the thumbnail of the current page is visible - // when exiting presentation mode. - scrollIntoView(document.getElementById('thumbnailContainer' + page)); + if (this.pdfThumbnailViewer) { + // Ensure that the thumbnail of the current page is visible + // when exiting presentation mode. + this.pdfThumbnailViewer.ensureThumbnailVisible(page); + } }, showControls: function presentationModeShowControls() { @@ -213,19 +200,6 @@ var PresentationMode = { }, mouseMove: function presentationModeMouseMove(evt) { -//#if (GENERIC || CHROME) - // Workaround for a bug in WebKit browsers that causes the 'mousemove' event - // to be fired when the cursor is changed. For details, see: - // http://code.google.com/p/chromium/issues/detail?id=103041. - - var currCoords = { x: evt.clientX, y: evt.clientY }; - var prevCoords = PresentationMode.prevCoords; - PresentationMode.prevCoords = currCoords; - - if (currCoords.x === prevCoords.x && currCoords.y === prevCoords.y) { - return; - } -//#endif PresentationMode.showControls(); }, diff --git a/web/viewer.js b/web/viewer.js index 994835dce..819be1a84 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -15,7 +15,7 @@ * limitations under the License. */ /* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, ProgressBar, - DownloadManager, getFileName, scrollIntoView, getPDFFileNameFromURL, + DownloadManager, getFileName, getPDFFileNameFromURL, PDFHistory, Preferences, SidebarView, ViewHistory, Stats, PDFThumbnailViewer, URL, noContextMenuHandler, SecondaryToolbar, PasswordPrompt, PresentationMode, HandTool, Promise, @@ -188,13 +188,20 @@ var PDFViewerApplication = { }); if (this.supportsFullscreen) { + var toolbar = SecondaryToolbar; PresentationMode.initialize({ container: container, - secondaryToolbar: SecondaryToolbar, - firstPage: document.getElementById('contextFirstPage'), - lastPage: document.getElementById('contextLastPage'), - pageRotateCw: document.getElementById('contextPageRotateCw'), - pageRotateCcw: document.getElementById('contextPageRotateCcw') + pdfThumbnailViewer: this.pdfThumbnailViewer, + contextMenuItems: [ + { element: document.getElementById('contextFirstPage'), + handler: toolbar.firstPageClick.bind(toolbar) }, + { element: document.getElementById('contextLastPage'), + handler: toolbar.lastPageClick.bind(toolbar) }, + { element: document.getElementById('contextPageRotateCw'), + handler: toolbar.pageRotateCwClick.bind(toolbar) }, + { element: document.getElementById('contextPageRotateCcw'), + handler: toolbar.pageRotateCcwClick.bind(toolbar) } + ] }); } @@ -317,8 +324,8 @@ var PDFViewerApplication = { get supportsFullscreen() { var doc = document.documentElement; - var support = doc.requestFullscreen || doc.mozRequestFullScreen || - doc.webkitRequestFullScreen || doc.msRequestFullscreen; + var support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || + doc.webkitRequestFullScreen || doc.msRequestFullscreen); if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || @@ -1936,15 +1943,9 @@ window.addEventListener('DOMMouseScroll', handleMouseWheel); window.addEventListener('mousewheel', handleMouseWheel); window.addEventListener('click', function click(evt) { - if (!PDFViewerApplication.pdfViewer.isInPresentationMode) { - if (SecondaryToolbar.opened && - PDFViewerApplication.pdfViewer.containsElement(evt.target)) { - SecondaryToolbar.close(); - } - } else if (evt.button === 0) { - // Necessary since preventDefault() in 'mousedown' won't stop - // the event propagation in all circumstances in presentation mode. - evt.preventDefault(); + if (SecondaryToolbar.opened && + PDFViewerApplication.pdfViewer.containsElement(evt.target)) { + SecondaryToolbar.close(); } }, false);