Simplified wheel processing.
This commit is contained in:
parent
6c263c1994
commit
223a18ccc8
37
web/app.js
37
web/app.js
@ -93,6 +93,7 @@ var PDFAttachmentViewer = pdfAttachmentViewerLib.PDFAttachmentViewer;
|
|||||||
var PDFFindController = pdfFindControllerLib.PDFFindController;
|
var PDFFindController = pdfFindControllerLib.PDFFindController;
|
||||||
var PDFFindBar = pdfFindBarLib.PDFFindBar;
|
var PDFFindBar = pdfFindBarLib.PDFFindBar;
|
||||||
var getGlobalEventBus = domEventsLib.getGlobalEventBus;
|
var getGlobalEventBus = domEventsLib.getGlobalEventBus;
|
||||||
|
var normalizeWheelEventDelta = uiUtilsLib.normalizeWheelEventDelta;
|
||||||
|
|
||||||
var DEFAULT_SCALE_DELTA = 1.1;
|
var DEFAULT_SCALE_DELTA = 1.1;
|
||||||
var MIN_SCALE = 0.25;
|
var MIN_SCALE = 0.25;
|
||||||
@ -1217,16 +1218,6 @@ var PDFViewerApplication = {
|
|||||||
this.pdfPresentationMode.request();
|
this.pdfPresentationMode.request();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {number} delta - The delta value from the mouse event.
|
|
||||||
*/
|
|
||||||
scrollPresentationMode: function pdfViewScrollPresentationMode(delta) {
|
|
||||||
if (!this.pdfPresentationMode) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.pdfPresentationMode.mouseScroll(delta);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef UpdateUIToolbarParameters
|
* @typedef UpdateUIToolbarParameters
|
||||||
* @property {number} pageNumber
|
* @property {number} pageNumber
|
||||||
@ -1998,17 +1989,12 @@ function webViewerPageChanging(e) {
|
|||||||
|
|
||||||
var zoomDisabled = false, zoomDisabledTimeout;
|
var zoomDisabled = false, zoomDisabledTimeout;
|
||||||
function handleMouseWheel(evt) {
|
function handleMouseWheel(evt) {
|
||||||
var MOUSE_WHEEL_DELTA_FACTOR = 40;
|
|
||||||
var ticks = (evt.type === 'DOMMouseScroll') ? -evt.detail :
|
|
||||||
evt.wheelDelta / MOUSE_WHEEL_DELTA_FACTOR;
|
|
||||||
var direction = (ticks < 0) ? 'zoomOut' : 'zoomIn';
|
|
||||||
|
|
||||||
var pdfViewer = PDFViewerApplication.pdfViewer;
|
var pdfViewer = PDFViewerApplication.pdfViewer;
|
||||||
if (pdfViewer.isInPresentationMode) {
|
if (pdfViewer.isInPresentationMode) {
|
||||||
evt.preventDefault();
|
return;
|
||||||
PDFViewerApplication.scrollPresentationMode(ticks *
|
}
|
||||||
MOUSE_WHEEL_DELTA_FACTOR);
|
|
||||||
} else if (evt.ctrlKey || evt.metaKey) {
|
if (evt.ctrlKey || evt.metaKey) {
|
||||||
var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
|
var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
|
||||||
if ((evt.ctrlKey && !support.ctrlKey) ||
|
if ((evt.ctrlKey && !support.ctrlKey) ||
|
||||||
(evt.metaKey && !support.metaKey)) {
|
(evt.metaKey && !support.metaKey)) {
|
||||||
@ -2023,7 +2009,15 @@ function handleMouseWheel(evt) {
|
|||||||
|
|
||||||
var previousScale = pdfViewer.currentScale;
|
var previousScale = pdfViewer.currentScale;
|
||||||
|
|
||||||
PDFViewerApplication[direction](Math.abs(ticks));
|
var delta = normalizeWheelEventDelta(evt);
|
||||||
|
|
||||||
|
var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
|
||||||
|
var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
|
||||||
|
if (ticks < 0) {
|
||||||
|
PDFViewerApplication.zoomOut(-ticks);
|
||||||
|
} else {
|
||||||
|
PDFViewerApplication.zoomIn(ticks);
|
||||||
|
}
|
||||||
|
|
||||||
var currentScale = pdfViewer.currentScale;
|
var currentScale = pdfViewer.currentScale;
|
||||||
if (previousScale !== currentScale) {
|
if (previousScale !== currentScale) {
|
||||||
@ -2046,8 +2040,7 @@ function handleMouseWheel(evt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('DOMMouseScroll', handleMouseWheel);
|
window.addEventListener('wheel', handleMouseWheel);
|
||||||
window.addEventListener('mousewheel', handleMouseWheel);
|
|
||||||
|
|
||||||
window.addEventListener('click', function click(evt) {
|
window.addEventListener('click', function click(evt) {
|
||||||
if (!PDFViewerApplication.secondaryToolbar.isOpen) {
|
if (!PDFViewerApplication.secondaryToolbar.isOpen) {
|
||||||
|
@ -17,13 +17,15 @@
|
|||||||
|
|
||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
define('pdfjs-web/pdf_presentation_mode', ['exports'], factory);
|
define('pdfjs-web/pdf_presentation_mode', ['exports', 'pdfjs-web/ui_utils'],
|
||||||
|
factory);
|
||||||
} else if (typeof exports !== 'undefined') {
|
} else if (typeof exports !== 'undefined') {
|
||||||
factory(exports);
|
factory(exports, require('./ui_utils.js'));
|
||||||
} else {
|
} else {
|
||||||
factory((root.pdfjsWebPDFPresentationMode = {}));
|
factory((root.pdfjsWebPDFPresentationMode = {}), root.pdfjsWebUIUtils);
|
||||||
}
|
}
|
||||||
}(this, function (exports) {
|
}(this, function (exports, uiUtils) {
|
||||||
|
var normalizeWheelEventDelta = uiUtils.normalizeWheelEventDelta;
|
||||||
|
|
||||||
var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500; // in ms
|
var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500; // in ms
|
||||||
var DELAY_BEFORE_HIDING_CONTROLS = 3000; // in ms
|
var DELAY_BEFORE_HIDING_CONTROLS = 3000; // in ms
|
||||||
@ -120,16 +122,19 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switches page when the user scrolls (using a scroll wheel or a touchpad)
|
* @private
|
||||||
* with large enough motion, to prevent accidental page switches.
|
|
||||||
* @param {number} delta - The delta value from the mouse event.
|
|
||||||
*/
|
*/
|
||||||
mouseScroll: function PDFPresentationMode_mouseScroll(delta) {
|
_mouseWheel: function PDFPresentationMode_mouseWheel(evt) {
|
||||||
if (!this.active) {
|
if (!this.active) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
var delta = normalizeWheelEventDelta(evt);
|
||||||
|
|
||||||
var MOUSE_SCROLL_COOLDOWN_TIME = 50;
|
var MOUSE_SCROLL_COOLDOWN_TIME = 50;
|
||||||
var PAGE_SWITCH_THRESHOLD = 120;
|
var PAGE_SWITCH_THRESHOLD = 0.1;
|
||||||
var PageSwitchDirection = {
|
var PageSwitchDirection = {
|
||||||
UP: -1,
|
UP: -1,
|
||||||
DOWN: 1
|
DOWN: 1
|
||||||
@ -340,11 +345,13 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
|
|||||||
_addWindowListeners: function PDFPresentationMode_addWindowListeners() {
|
_addWindowListeners: function PDFPresentationMode_addWindowListeners() {
|
||||||
this.showControlsBind = this._showControls.bind(this);
|
this.showControlsBind = this._showControls.bind(this);
|
||||||
this.mouseDownBind = this._mouseDown.bind(this);
|
this.mouseDownBind = this._mouseDown.bind(this);
|
||||||
|
this.mouseWheelBind = this._mouseWheel.bind(this);
|
||||||
this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
|
this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
|
||||||
this.contextMenuBind = this._contextMenu.bind(this);
|
this.contextMenuBind = this._contextMenu.bind(this);
|
||||||
|
|
||||||
window.addEventListener('mousemove', this.showControlsBind);
|
window.addEventListener('mousemove', this.showControlsBind);
|
||||||
window.addEventListener('mousedown', this.mouseDownBind);
|
window.addEventListener('mousedown', this.mouseDownBind);
|
||||||
|
window.addEventListener('wheel', this.mouseWheelBind);
|
||||||
window.addEventListener('keydown', this.resetMouseScrollStateBind);
|
window.addEventListener('keydown', this.resetMouseScrollStateBind);
|
||||||
window.addEventListener('contextmenu', this.contextMenuBind);
|
window.addEventListener('contextmenu', this.contextMenuBind);
|
||||||
},
|
},
|
||||||
@ -356,11 +363,13 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
|
|||||||
function PDFPresentationMode_removeWindowListeners() {
|
function PDFPresentationMode_removeWindowListeners() {
|
||||||
window.removeEventListener('mousemove', this.showControlsBind);
|
window.removeEventListener('mousemove', this.showControlsBind);
|
||||||
window.removeEventListener('mousedown', this.mouseDownBind);
|
window.removeEventListener('mousedown', this.mouseDownBind);
|
||||||
|
window.removeEventListener('wheel', this.mouseWheelBind);
|
||||||
window.removeEventListener('keydown', this.resetMouseScrollStateBind);
|
window.removeEventListener('keydown', this.resetMouseScrollStateBind);
|
||||||
window.removeEventListener('contextmenu', this.contextMenuBind);
|
window.removeEventListener('contextmenu', this.contextMenuBind);
|
||||||
|
|
||||||
delete this.showControlsBind;
|
delete this.showControlsBind;
|
||||||
delete this.mouseDownBind;
|
delete this.mouseDownBind;
|
||||||
|
delete this.mouseWheelBind;
|
||||||
delete this.resetMouseScrollStateBind;
|
delete this.resetMouseScrollStateBind;
|
||||||
delete this.contextMenuBind;
|
delete this.contextMenuBind;
|
||||||
},
|
},
|
||||||
|
@ -384,6 +384,28 @@ function getPDFFileNameFromURL(url) {
|
|||||||
return suggestedFilename || 'document.pdf';
|
return suggestedFilename || 'document.pdf';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeWheelEventDelta(evt) {
|
||||||
|
var delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
|
||||||
|
var angle = Math.atan2(evt.deltaY, evt.deltaX);
|
||||||
|
if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
|
||||||
|
// All that is left-up oriented has to change the sign.
|
||||||
|
delta = -delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
var MOUSE_DOM_DELTA_PIXEL_MODE = 0;
|
||||||
|
var MOUSE_DOM_DELTA_LINE_MODE = 1;
|
||||||
|
var MOUSE_PIXELS_PER_LINE = 30;
|
||||||
|
var MOUSE_LINES_PER_PAGE = 30;
|
||||||
|
|
||||||
|
// Converts delta to per-page units
|
||||||
|
if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
|
||||||
|
delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
|
||||||
|
} else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
|
||||||
|
delta /= MOUSE_LINES_PER_PAGE;
|
||||||
|
}
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple event bus for an application. Listeners are attached using the
|
* Simple event bus for an application. Listeners are attached using the
|
||||||
* `on` and `off` methods. To raise an event, the `dispatch` method shall be
|
* `on` and `off` methods. To raise an event, the `dispatch` method shall be
|
||||||
@ -529,4 +551,5 @@ exports.getOutputScale = getOutputScale;
|
|||||||
exports.scrollIntoView = scrollIntoView;
|
exports.scrollIntoView = scrollIntoView;
|
||||||
exports.watchScroll = watchScroll;
|
exports.watchScroll = watchScroll;
|
||||||
exports.binarySearchFirstItem = binarySearchFirstItem;
|
exports.binarySearchFirstItem = binarySearchFirstItem;
|
||||||
|
exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user