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:
parent
95b2ec124b
commit
e7fd5b4d4d
@ -14,7 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals scrollIntoView, PDFViewerApplication */
|
/* globals PDFViewerApplication */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -27,41 +27,26 @@ var PresentationMode = {
|
|||||||
active: false,
|
active: false,
|
||||||
args: null,
|
args: null,
|
||||||
contextMenuOpen: false,
|
contextMenuOpen: false,
|
||||||
//#if (GENERIC || CHROME)
|
|
||||||
prevCoords: { x: null, y: null },
|
|
||||||
//#endif
|
|
||||||
mouseScrollTimeStamp: 0,
|
mouseScrollTimeStamp: 0,
|
||||||
mouseScrollDelta: 0,
|
mouseScrollDelta: 0,
|
||||||
|
|
||||||
initialize: function presentationModeInitialize(options) {
|
initialize: function presentationModeInitialize(options) {
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
this.container = options.container;
|
this.container = options.container;
|
||||||
this.secondaryToolbar = options.secondaryToolbar;
|
this.pdfThumbnailViewer = options.pdfThumbnailViewer || null;
|
||||||
|
var contextMenuItems = options.contextMenuItems || null;
|
||||||
|
|
||||||
this.viewer = this.container.firstElementChild;
|
this.viewer = this.container.firstElementChild;
|
||||||
|
|
||||||
this.firstPage = options.firstPage;
|
if (contextMenuItems) {
|
||||||
this.lastPage = options.lastPage;
|
for (var i = 0, ii = contextMenuItems.length; i < ii; i++) {
|
||||||
this.pageRotateCw = options.pageRotateCw;
|
var item = contextMenuItems[i];
|
||||||
this.pageRotateCcw = options.pageRotateCcw;
|
item.element.addEventListener('click', function (handler) {
|
||||||
|
this.contextMenuOpen = false;
|
||||||
this.firstPage.addEventListener('click', function() {
|
handler();
|
||||||
this.contextMenuOpen = false;
|
}.bind(this, item.handler));
|
||||||
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));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get isFullscreen() {
|
get isFullscreen() {
|
||||||
@ -186,9 +171,11 @@ var PresentationMode = {
|
|||||||
this.container.removeAttribute('contextmenu');
|
this.container.removeAttribute('contextmenu');
|
||||||
this.contextMenuOpen = false;
|
this.contextMenuOpen = false;
|
||||||
|
|
||||||
// Ensure that the thumbnail of the current page is visible
|
if (this.pdfThumbnailViewer) {
|
||||||
// when exiting presentation mode.
|
// Ensure that the thumbnail of the current page is visible
|
||||||
scrollIntoView(document.getElementById('thumbnailContainer' + page));
|
// when exiting presentation mode.
|
||||||
|
this.pdfThumbnailViewer.ensureThumbnailVisible(page);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
showControls: function presentationModeShowControls() {
|
showControls: function presentationModeShowControls() {
|
||||||
@ -213,19 +200,6 @@ var PresentationMode = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
mouseMove: function presentationModeMouseMove(evt) {
|
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();
|
PresentationMode.showControls();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, ProgressBar,
|
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, ProgressBar,
|
||||||
DownloadManager, getFileName, scrollIntoView, getPDFFileNameFromURL,
|
DownloadManager, getFileName, getPDFFileNameFromURL,
|
||||||
PDFHistory, Preferences, SidebarView, ViewHistory, Stats,
|
PDFHistory, Preferences, SidebarView, ViewHistory, Stats,
|
||||||
PDFThumbnailViewer, URL, noContextMenuHandler, SecondaryToolbar,
|
PDFThumbnailViewer, URL, noContextMenuHandler, SecondaryToolbar,
|
||||||
PasswordPrompt, PresentationMode, HandTool, Promise,
|
PasswordPrompt, PresentationMode, HandTool, Promise,
|
||||||
@ -188,13 +188,20 @@ var PDFViewerApplication = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (this.supportsFullscreen) {
|
if (this.supportsFullscreen) {
|
||||||
|
var toolbar = SecondaryToolbar;
|
||||||
PresentationMode.initialize({
|
PresentationMode.initialize({
|
||||||
container: container,
|
container: container,
|
||||||
secondaryToolbar: SecondaryToolbar,
|
pdfThumbnailViewer: this.pdfThumbnailViewer,
|
||||||
firstPage: document.getElementById('contextFirstPage'),
|
contextMenuItems: [
|
||||||
lastPage: document.getElementById('contextLastPage'),
|
{ element: document.getElementById('contextFirstPage'),
|
||||||
pageRotateCw: document.getElementById('contextPageRotateCw'),
|
handler: toolbar.firstPageClick.bind(toolbar) },
|
||||||
pageRotateCcw: document.getElementById('contextPageRotateCcw')
|
{ 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() {
|
get supportsFullscreen() {
|
||||||
var doc = document.documentElement;
|
var doc = document.documentElement;
|
||||||
var support = doc.requestFullscreen || doc.mozRequestFullScreen ||
|
var support = !!(doc.requestFullscreen || doc.mozRequestFullScreen ||
|
||||||
doc.webkitRequestFullScreen || doc.msRequestFullscreen;
|
doc.webkitRequestFullScreen || doc.msRequestFullscreen);
|
||||||
|
|
||||||
if (document.fullscreenEnabled === false ||
|
if (document.fullscreenEnabled === false ||
|
||||||
document.mozFullScreenEnabled === false ||
|
document.mozFullScreenEnabled === false ||
|
||||||
@ -1936,15 +1943,9 @@ window.addEventListener('DOMMouseScroll', handleMouseWheel);
|
|||||||
window.addEventListener('mousewheel', handleMouseWheel);
|
window.addEventListener('mousewheel', handleMouseWheel);
|
||||||
|
|
||||||
window.addEventListener('click', function click(evt) {
|
window.addEventListener('click', function click(evt) {
|
||||||
if (!PDFViewerApplication.pdfViewer.isInPresentationMode) {
|
if (SecondaryToolbar.opened &&
|
||||||
if (SecondaryToolbar.opened &&
|
PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
|
||||||
PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
|
SecondaryToolbar.close();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user