Bug 1250398 - Disable APZ for source editors. r=gl
authorJ. Ryan Stinnett <jryans@gmail.com>
Fri, 19 Feb 2016 20:08:10 -0600
changeset 322043 684054d29f9b49e6445d74a9ac83e04f311d0c7f
parent 322042 675f335b6b44b0a85aa8a8d5066cbeaaf3d1bc64
child 322044 1bcb9055be8c62b9f61cab5b9d79f5bfa2b92222
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1250398
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1250398 - Disable APZ for source editors. r=gl MozReview-Commit-ID: JmUuoobDr7y
devtools/client/sourceeditor/editor.js
--- a/devtools/client/sourceeditor/editor.js
+++ b/devtools/client/sourceeditor/editor.js
@@ -297,16 +297,40 @@ Editor.prototype = {
 
       win.CodeMirror.commands.save = () => this.emit("saveRequested");
 
       // Create a CodeMirror instance add support for context menus,
       // overwrite the default controller (otherwise items in the top and
       // context menus won't work).
 
       cm = win.CodeMirror(win.document.body, this.config);
+
+      // Disable APZ for source editors. It currently causes the line numbers to
+      // "tear off" and swim around on top of the content. Bug 1160601 tracks
+      // finding a solution that allows APZ to work with CodeMirror.
+      cm.getScrollerElement().addEventListener("wheel", ev => {
+        // By handling the wheel events ourselves, we force the platform to
+        // scroll synchronously, like it did before APZ. However, we lose smooth
+        // scrolling for users with mouse wheels. This seems acceptible vs.
+        // doing nothing and letting the gutter slide around.
+        ev.preventDefault();
+
+        let { deltaX, deltaY } = ev;
+
+        if (ev.deltaMode == ev.DOM_DELTA_LINE) {
+          deltaX *= cm.defaultCharWidth();
+          deltaY *= cm.defaultTextHeight();
+        } else if (ev.deltaMode == ev.DOM_DELTA_PAGE) {
+          deltaX *= cm.getWrapperElement().clientWidth;
+          deltaY *= cm.getWrapperElement().clientHeight;
+        }
+
+        cm.getScrollerElement().scrollBy(deltaX, deltaY);
+      });
+
       cm.getWrapperElement().addEventListener("contextmenu", ev => {
         ev.preventDefault();
 
         if (!this.config.contextMenu) {
           return;
         }
 
         let popup = this.config.contextMenu;