Index: src/macosx/classes/sun/lwawt/macosx/CPlatformView.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/macosx/classes/sun/lwawt/macosx/CPlatformView.java	(date 1475168420000)
+++ src/macosx/classes/sun/lwawt/macosx/CPlatformView.java	(revision )
@@ -192,7 +192,8 @@
 
         if (event.getType() == CocoaConstants.NSScrollWheel) {
             responder.handleScrollEvent(x, y, event.getModifierFlags(),
-                                        event.getScrollDeltaX(), event.getScrollDeltaY());
+                                        event.getScrollDeltaX(), event.getScrollDeltaY(),
+                                        event.getScrollMask());
         } else {
             responder.handleMouseEvent(event.getType(), event.getModifierFlags(), event.getButtonNumber(),
                                        event.getClickCount(), x, y, event.getAbsX(), event.getAbsY());
Index: src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java	(date 1475168420000)
+++ src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java	(revision )
@@ -91,7 +91,7 @@
         int x = (int)pluginX;
         int y = (int)pluginY;
 
-        responder.handleScrollEvent(x, y, modifierFlags, deltaX, deltaY);
+        responder.handleScrollEvent(x, y, modifierFlags, deltaX, deltaY, NSEvent.SCROLL_MASK_WHEEL);
     }
 
     public void handleKeyEvent(int eventType, int modifierFlags, String characters,
Index: src/macosx/native/sun/awt/LWCToolkit.m
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/macosx/native/sun/awt/LWCToolkit.m	(date 1475168420000)
+++ src/macosx/native/sun/awt/LWCToolkit.m	(revision )
@@ -39,6 +39,13 @@
 
 #import "sizecalc.h"
 
+// SCROLL EVENT MASK
+#define SCROLL_MASK_WHEEL 1
+#define SCROLL_MASK_TRACKPAD (1 << 1)
+#define SCROLL_MASK_PHASE_BEGAN (1 << 2)
+#define SCROLL_MASK_PHASE_CANCELLED (1 << 3)
+#define SCROLL_MASK_PHASE_ENDED (1 << 4)
+
 int gNumberOfButtons;
 jint* gButtonDownMasks;
 
@@ -54,6 +61,25 @@
     eventCount++;
 }
 
++ (jint) scrollTypeToMask: (NSEventPhase) phase {
+    if (phase) {
+        jint scrollMask = SCROLL_MASK_TRACKPAD;
+        switch (phase) {
+            case NSEventPhaseBegan:
+                scrollMask |= SCROLL_MASK_PHASE_BEGAN;
+                break;
+            case NSEventPhaseCancelled:
+                scrollMask |= SCROLL_MASK_PHASE_CANCELLED;
+                break;
+            case NSEventPhaseEnded:
+                scrollMask |= SCROLL_MASK_PHASE_ENDED;
+                break;
+        }
+        return scrollMask;
+    } else {
+        return SCROLL_MASK_WHEEL;
+    }
+}
 @end
 
 
Index: src/macosx/native/sun/awt/CTrayIcon.m
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/macosx/native/sun/awt/CTrayIcon.m	(date 1475168420000)
+++ src/macosx/native/sun/awt/CTrayIcon.m	(revision )
@@ -135,8 +135,13 @@
 
     clickCount = [event clickCount];
 
+    jint scrollMask = 0;
+    if (type == NSScrollWheel) {
+        scrollMask = [AWTToolkit scrollTypeToMask: [event phase]];
+    }
+
     static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
-    static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
+    static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
     jobject jEvent = JNFNewObject(env, jctor_NSEvent,
                                   [event type],
                                   [event modifierFlags],
@@ -145,7 +150,8 @@
                                   (jint)localPoint.x, (jint)localPoint.y,
                                   (jint)absP.x, (jint)absP.y,
                                   [event deltaY],
-                                  [event deltaX]);
+                                  [event deltaX],
+                                  scrollMask);
     if (jEvent == nil) {
         // Unable to create event by some reason.
         return;
Index: src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java	(date 1475168420000)
+++ src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java	(revision )
@@ -47,6 +47,9 @@
     private final PlatformEventNotifier eventNotifier;
     private final boolean isNpapiCallback;
     private int lastKeyPressCode = KeyEvent.VK_UNDEFINED;
+    private static final double DELTA_THRESHOLD = 0.8;
+    private double accumulatedDeltaX;
+    private double accumulatedDeltaY;
 
     CPlatformResponder(final PlatformEventNotifier eventNotifier,
                        final boolean isNpapiCallback) {
@@ -93,37 +96,66 @@
      * Handles scroll events.
      */
     void handleScrollEvent(final int x, final int y, final int modifierFlags,
-                           final double deltaX, final double deltaY) {
+                           final double deltaX, final double deltaY,
+                           final int scrollMask) {
         final int buttonNumber = CocoaConstants.kCGMouseButtonCenter;
         int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                         modifierFlags);
         final boolean isShift = (jmodifiers & InputEvent.SHIFT_DOWN_MASK) != 0;
 
+        int roundDeltaX = (int) Math.round(deltaX);
+        int roundDeltaY = (int) Math.round(deltaY);
+
+        if ((scrollMask & NSEvent.SCROLL_MASK_TRACKPAD) != 0) {
+            if ((scrollMask & NSEvent.SCROLL_MASK_PHASE_BEGAN) != 0) {
+                accumulatedDeltaX = deltaX;
+                accumulatedDeltaY = deltaY;
+            } else {
+                accumulatedDeltaX += deltaX;
+                accumulatedDeltaY += deltaY;
+            }
+
+            if (Math.abs(accumulatedDeltaX) > DELTA_THRESHOLD) {
+                roundDeltaX = (int) Math.round(accumulatedDeltaX);
+                accumulatedDeltaX -= roundDeltaX;
+            }
+
+            if (Math.abs(accumulatedDeltaY) > DELTA_THRESHOLD) {
+                roundDeltaY = (int) Math.round(accumulatedDeltaY);
+                accumulatedDeltaY -= roundDeltaY;
+            }
+        } else {
+            if (roundDeltaX == 0 && deltaX != 0) {
+                roundDeltaX = deltaX > 0 ? 1 : -1;
+            }
+
+            if (roundDeltaY == 0 && deltaY != 0) {
+                roundDeltaY = deltaY > 0 ? 1 : -1;
+            }
+        }
+
         // Vertical scroll.
         if (!isShift && deltaY != 0.0) {
-            dispatchScrollEvent(x, y, jmodifiers, deltaY);
+            dispatchScrollEvent(x, y, jmodifiers, roundDeltaY, deltaY);
         }
         // Horizontal scroll or shirt+vertical scroll.
         final double delta = isShift && deltaY != 0.0 ? deltaY : deltaX;
+        final int roundDelta = isShift && roundDeltaY != 0.0 ? roundDeltaY : roundDeltaX;
         if (delta != 0.0) {
             jmodifiers |= InputEvent.SHIFT_DOWN_MASK;
-            dispatchScrollEvent(x, y, jmodifiers, delta);
+            dispatchScrollEvent(x, y, jmodifiers, roundDelta, delta);
         }
     }
 
     private void dispatchScrollEvent(final int x, final int y,
-                                     final int modifiers, final double delta) {
+                                     final int modifiers,
+                                     final int roundDelta, final double delta) {
         final long when = System.currentTimeMillis();
         final int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL;
         final int scrollAmount = 1;
-        int wheelRotation = (int) delta;
-        int signum = (int) Math.signum(delta);
-        if (signum * delta < 1) {
-            wheelRotation = signum;
-        }
         // invert the wheelRotation for the peer
         eventNotifier.notifyMouseWheelEvent(when, x, y, modifiers, scrollType,
-                scrollAmount, -wheelRotation, -delta, null);
+                scrollAmount, -roundDelta, -delta, null);
     }
 
     /**
Index: src/macosx/native/sun/awt/LWCToolkit.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/macosx/native/sun/awt/LWCToolkit.h	(date 1475168420000)
+++ src/macosx/native/sun/awt/LWCToolkit.h	(revision )
@@ -40,6 +40,7 @@
 @interface AWTToolkit : NSObject { }
 + (long) getEventCount;
 + (void) eventCountPlusPlus;
++ (jint) scrollTypeToMask: (NSEventPhase) phase;
 @end
 
 /*
Index: src/macosx/classes/sun/lwawt/macosx/NSEvent.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/macosx/classes/sun/lwawt/macosx/NSEvent.java	(date 1475168420000)
+++ src/macosx/classes/sun/lwawt/macosx/NSEvent.java	(revision )
@@ -32,6 +32,13 @@
  * JDK functionality.
  */
 final class NSEvent {
+
+    static final int SCROLL_MASK_WHEEL = 1;
+    static final int SCROLL_MASK_TRACKPAD = 1 << 1;
+    static final int SCROLL_MASK_PHASE_BEGAN = 1 << 2;
+    static final int SCROLL_MASK_PHASE_CANCELLED = 1 << 3;
+    static final int SCROLL_MASK_PHASE_ENDED = 1 << 4;
+
     private int type;
     private int modifierFlags;
 
@@ -42,6 +49,7 @@
     private int y;
     private double scrollDeltaY;
     private double scrollDeltaX;
+    private int scrollMask;
     private int absX;
     private int absY;
 
@@ -62,7 +70,7 @@
     // Called from native
     NSEvent(int type, int modifierFlags, int clickCount, int buttonNumber,
                    int x, int y, int absX, int absY,
-                   double scrollDeltaY, double scrollDeltaX) {
+                   double scrollDeltaY, double scrollDeltaX, int scrollMask) {
         this.type = type;
         this.modifierFlags = modifierFlags;
         this.clickCount = clickCount;
@@ -73,6 +81,7 @@
         this.absY = absY;
         this.scrollDeltaY = scrollDeltaY;
         this.scrollDeltaX = scrollDeltaX;
+        this.scrollMask = scrollMask;
     }
 
     int getType() {
@@ -107,6 +116,10 @@
         return scrollDeltaX;
     }
 
+    int getScrollMask() {
+        return scrollMask;
+    }
+
     int getAbsX() {
         return absX;
     }
Index: src/macosx/native/sun/awt/AWTView.m
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/macosx/native/sun/awt/AWTView.m	(date 1475168420000)
+++ src/macosx/native/sun/awt/AWTView.m	(revision )
@@ -54,6 +54,10 @@
 //#define IM_DEBUG TRUE
 //#define EXTRA_DEBUG
 
+#define SCROLL_MASK_WHEEL 1
+#define SCROLL_MASK_TRACKPAD (1 << 1)
+#define SCROLL_MASK_PHASE_BEGAN (1 << 2)
+
 static BOOL shouldUsePressAndHold() {
     static int shouldUsePressAndHold = -1;
     if (shouldUsePressAndHold != -1) return shouldUsePressAndHold;
@@ -430,8 +434,13 @@
         clickCount = [event clickCount];
     }
 
+    jint scrollMask = 0;
+    if (type == NSScrollWheel) {
+        scrollMask = [AWTToolkit scrollTypeToMask: [event phase]];
+    }
+    
     static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
-    static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
+    static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
     jobject jEvent = JNFNewObject(env, jctor_NSEvent,
                                   [event type],
                                   [event modifierFlags],
@@ -440,7 +449,8 @@
                                   (jint)localPoint.x, (jint)localPoint.y,
                                   (jint)absP.x, (jint)absP.y,
                                   [event deltaY],
-                                  [event deltaX]);
+                                  [event deltaX],
+                                  scrollMask);
     if (jEvent == nil) {
         // Unable to create event by some reason.
         return;
