(cm, e)
| 4019 | }; |
| 4020 | |
| 4021 | function onScrollWheel(cm, e) { |
| 4022 | var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y; |
| 4023 | |
| 4024 | var display = cm.display, scroll = display.scroller; |
| 4025 | // Quit if there's nothing to scroll here |
| 4026 | var canScrollX = scroll.scrollWidth > scroll.clientWidth; |
| 4027 | var canScrollY = scroll.scrollHeight > scroll.clientHeight; |
| 4028 | if (!(dx && canScrollX || dy && canScrollY)) return; |
| 4029 | |
| 4030 | // Webkit browsers on OS X abort momentum scrolls when the target |
| 4031 | // of the scroll event is removed from the scrollable element. |
| 4032 | // This hack (see related code in patchDisplay) makes sure the |
| 4033 | // element is kept around. |
| 4034 | if (dy && mac && webkit) { |
| 4035 | outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) { |
| 4036 | for (var i = 0; i < view.length; i++) { |
| 4037 | if (view[i].node == cur) { |
| 4038 | cm.display.currentWheelTarget = cur; |
| 4039 | break outer; |
| 4040 | } |
| 4041 | } |
| 4042 | } |
| 4043 | } |
| 4044 | |
| 4045 | // On some browsers, horizontal scrolling will cause redraws to |
| 4046 | // happen before the gutter has been realigned, causing it to |
| 4047 | // wriggle around in a most unseemly way. When we have an |
| 4048 | // estimated pixels/delta value, we just handle horizontal |
| 4049 | // scrolling entirely here. It'll be slightly off from native, but |
| 4050 | // better than glitching out. |
| 4051 | if (dx && !gecko && !presto && wheelPixelsPerUnit != null) { |
| 4052 | if (dy && canScrollY) |
| 4053 | setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight))); |
| 4054 | setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth))); |
| 4055 | // Only prevent default scrolling if vertical scrolling is |
| 4056 | // actually possible. Otherwise, it causes vertical scroll |
| 4057 | // jitter on OSX trackpads when deltaX is small and deltaY |
| 4058 | // is large (issue #3579) |
| 4059 | if (!dy || (dy && canScrollY)) |
| 4060 | e_preventDefault(e); |
| 4061 | display.wheelStartX = null; // Abort measurement, if in progress |
| 4062 | return; |
| 4063 | } |
| 4064 | |
| 4065 | // 'Project' the visible viewport to cover the area that is being |
| 4066 | // scrolled into view (if we know enough to estimate it). |
| 4067 | if (dy && wheelPixelsPerUnit != null) { |
| 4068 | var pixels = dy * wheelPixelsPerUnit; |
| 4069 | var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight; |
| 4070 | if (pixels < 0) top = Math.max(0, top + pixels - 50); |
| 4071 | else bot = Math.min(cm.doc.height, bot + pixels + 50); |
| 4072 | updateDisplaySimple(cm, {top: top, bottom: bot}); |
| 4073 | } |
| 4074 | |
| 4075 | if (wheelSamples < 20) { |
| 4076 | if (display.wheelStartX == null) { |
| 4077 | display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop; |
| 4078 | display.wheelDX = dx; display.wheelDY = dy; |
no test coverage detected