(cm, e)
| 3838 | }; |
| 3839 | |
| 3840 | function onScrollWheel(cm, e) { |
| 3841 | var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y; |
| 3842 | |
| 3843 | var display = cm.display, scroll = display.scroller; |
| 3844 | // Quit if there's nothing to scroll here |
| 3845 | if (!(dx && scroll.scrollWidth > scroll.clientWidth || |
| 3846 | dy && scroll.scrollHeight > scroll.clientHeight)) return; |
| 3847 | |
| 3848 | // Webkit browsers on OS X abort momentum scrolls when the target |
| 3849 | // of the scroll event is removed from the scrollable element. |
| 3850 | // This hack (see related code in patchDisplay) makes sure the |
| 3851 | // element is kept around. |
| 3852 | if (dy && mac && webkit) { |
| 3853 | outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) { |
| 3854 | for (var i = 0; i < view.length; i++) { |
| 3855 | if (view[i].node == cur) { |
| 3856 | cm.display.currentWheelTarget = cur; |
| 3857 | break outer; |
| 3858 | } |
| 3859 | } |
| 3860 | } |
| 3861 | } |
| 3862 | |
| 3863 | // On some browsers, horizontal scrolling will cause redraws to |
| 3864 | // happen before the gutter has been realigned, causing it to |
| 3865 | // wriggle around in a most unseemly way. When we have an |
| 3866 | // estimated pixels/delta value, we just handle horizontal |
| 3867 | // scrolling entirely here. It'll be slightly off from native, but |
| 3868 | // better than glitching out. |
| 3869 | if (dx && !gecko && !presto && wheelPixelsPerUnit != null) { |
| 3870 | if (dy) |
| 3871 | setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight))); |
| 3872 | setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth))); |
| 3873 | e_preventDefault(e); |
| 3874 | display.wheelStartX = null; // Abort measurement, if in progress |
| 3875 | return; |
| 3876 | } |
| 3877 | |
| 3878 | // 'Project' the visible viewport to cover the area that is being |
| 3879 | // scrolled into view (if we know enough to estimate it). |
| 3880 | if (dy && wheelPixelsPerUnit != null) { |
| 3881 | var pixels = dy * wheelPixelsPerUnit; |
| 3882 | var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight; |
| 3883 | if (pixels < 0) top = Math.max(0, top + pixels - 50); |
| 3884 | else bot = Math.min(cm.doc.height, bot + pixels + 50); |
| 3885 | updateDisplaySimple(cm, {top: top, bottom: bot}); |
| 3886 | } |
| 3887 | |
| 3888 | if (wheelSamples < 20) { |
| 3889 | if (display.wheelStartX == null) { |
| 3890 | display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop; |
| 3891 | display.wheelDX = dx; display.wheelDY = dy; |
| 3892 | setTimeout(function() { |
| 3893 | if (display.wheelStartX == null) return; |
| 3894 | var movedX = scroll.scrollLeft - display.wheelStartX; |
| 3895 | var movedY = scroll.scrollTop - display.wheelStartY; |
| 3896 | var sample = (movedY && display.wheelDY && movedY / display.wheelDY) || |
| 3897 | (movedX && display.wheelDX && movedX / display.wheelDX); |
no test coverage detected