Scrol workspace on mouse wheel and pinch-zoom

Distinguish pinch-zoom in Chrome using e.ctrlKey.

If a mouse wheel event is not a zoom event, scroll the workspace.

#51
This commit is contained in:
Tim Mickel 2016-03-29 12:53:47 -04:00
parent 4c52b30a15
commit 473cb0abce

View file

@ -668,10 +668,27 @@ Blockly.WorkspaceSvg.prototype.moveDrag = function(e) {
*/
Blockly.WorkspaceSvg.prototype.onMouseWheel_ = function(e) {
// TODO: Remove terminateDrag and compensate for coordinate skew during zoom.
Blockly.terminateDrag_();
var delta = e.deltaY > 0 ? -1 : 1;
var position = Blockly.mouseToSvg(e, this.getParentSvg());
this.zoom(position.x, position.y, delta);
if (e.ctrlKey) {
// Pinch-to-zoom in Chrome only
Blockly.terminateDrag_();
var delta = e.deltaY > 0 ? -1 : 1;
var position = Blockly.mouseToSvg(e, this.getParentSvg());
this.zoom(position.x, position.y, delta);
} else {
// This is a regular mouse wheel event - scroll the workspace
var metrics = this.getMetrics();
var x = this.scrollX - e.deltaX;
var y = this.scrollY - e.deltaY;
x = Math.min(x, -metrics.contentLeft);
y = Math.min(y, -metrics.contentTop);
x = Math.max(x, metrics.viewWidth - metrics.contentLeft -
metrics.contentWidth);
y = Math.max(y, metrics.viewHeight - metrics.contentTop -
metrics.contentHeight);
// Move the scrollbars and the page will scroll automatically.
this.scrollbar.set(-x - metrics.contentLeft,
-y - metrics.contentTop);
}
e.preventDefault();
};