Refactor the options passed to |PresentationMode.initialize| and clean-up some code in viewer.js and presentation_mode.js

This patch:
 - Passes in a reference to the current PDFThumbnailViewer, which is used to ensure that the current thumbnail becomes visible when exiting PresentationMode.

 - Changes the way that the event listeners for the contextmenu items are defined, to avoid passing in a reference to the SecondaryToolbar.

 - Ensures that |supportsFullscreen| always returns a boolean.
   Currently `supportsFullscreen` will, when the browser supports the fullscreen API, return e.g. `function mozRequestFullScreen()` instead of `true`.

 - Simplifies the |click| handler code when PresentationMode is active.
   This code has been obsolete ever since PR 2919 landed.

 - Removes hack used to workaround a bug in WebKit browsers, which caused |mousemove| events to be fired when the cursor changed.
   This was fixed close to a year ago, see http://code.google.com/p/chromium/issues/detail?id=103041.
This commit is contained in:
Jonas Jenwald 2015-02-01 11:31:18 +01:00
parent 95b2ec124b
commit e7fd5b4d4d
2 changed files with 35 additions and 60 deletions

View file

@ -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);