(cm, e)
| 4473 | } |
| 4474 | |
| 4475 | function onScrollWheel(cm, e) { |
| 4476 | var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y; |
| 4477 | |
| 4478 | var display = cm.display, scroll = display.scroller; |
| 4479 | // Quit if there's nothing to scroll here |
| 4480 | var canScrollX = scroll.scrollWidth > scroll.clientWidth; |
| 4481 | var canScrollY = scroll.scrollHeight > scroll.clientHeight; |
| 4482 | if (!(dx && canScrollX || dy && canScrollY)) { return } |
| 4483 | |
| 4484 | // Webkit browsers on OS X abort momentum scrolls when the target |
| 4485 | // of the scroll event is removed from the scrollable element. |
| 4486 | // This hack (see related code in patchDisplay) makes sure the |
| 4487 | // element is kept around. |
| 4488 | if (dy && mac && webkit) { |
| 4489 | outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) { |
| 4490 | for (var i = 0; i < view.length; i++) { |
| 4491 | if (view[i].node == cur) { |
| 4492 | cm.display.currentWheelTarget = cur; |
| 4493 | break outer |
| 4494 | } |
| 4495 | } |
| 4496 | } |
| 4497 | } |
| 4498 | |
| 4499 | // On some browsers, horizontal scrolling will cause redraws to |
| 4500 | // happen before the gutter has been realigned, causing it to |
| 4501 | // wriggle around in a most unseemly way. When we have an |
| 4502 | // estimated pixels/delta value, we just handle horizontal |
| 4503 | // scrolling entirely here. It'll be slightly off from native, but |
| 4504 | // better than glitching out. |
| 4505 | if (dx && !gecko && !presto && wheelPixelsPerUnit != null) { |
| 4506 | if (dy && canScrollY) |
| 4507 | { updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)); } |
| 4508 | setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit)); |
| 4509 | // Only prevent default scrolling if vertical scrolling is |
| 4510 | // actually possible. Otherwise, it causes vertical scroll |
| 4511 | // jitter on OSX trackpads when deltaX is small and deltaY |
| 4512 | // is large (issue #3579) |
| 4513 | if (!dy || (dy && canScrollY)) |
| 4514 | { e_preventDefault(e); } |
| 4515 | display.wheelStartX = null; // Abort measurement, if in progress |
| 4516 | return |
| 4517 | } |
| 4518 | |
| 4519 | // 'Project' the visible viewport to cover the area that is being |
| 4520 | // scrolled into view (if we know enough to estimate it). |
| 4521 | if (dy && wheelPixelsPerUnit != null) { |
| 4522 | var pixels = dy * wheelPixelsPerUnit; |
| 4523 | var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight; |
| 4524 | if (pixels < 0) { top = Math.max(0, top + pixels - 50); } |
| 4525 | else { bot = Math.min(cm.doc.height, bot + pixels + 50); } |
| 4526 | updateDisplaySimple(cm, {top: top, bottom: bot}); |
| 4527 | } |
| 4528 | |
| 4529 | if (wheelSamples < 20) { |
| 4530 | if (display.wheelStartX == null) { |
| 4531 | display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop; |
| 4532 | display.wheelDX = dx; display.wheelDY = dy; |
no test coverage detected