From 3b91e137b6974693b14420726dd3c10fa27f3f23 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Thu, 2 Jun 2016 21:23:42 +0300 Subject: [PATCH] IDEA-156745 move utility method from UIUtil to JBScrollPane --- .../intellij/ui/components/JBScrollPane.java | 17 ++++++++++++++++- .../keymap/impl/IdeMouseEventDispatcher.java | 3 ++- .../util/resources/misc/registry.properties | 1 - .../util/src/com/intellij/util/ui/UIUtil.java | 14 -------------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java index 6155131c4b77..1008872404d5 100644 --- a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java +++ b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java @@ -40,7 +40,9 @@ import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicScrollBarUI; import javax.swing.plaf.basic.BasicScrollPaneUI; import java.awt.*; +import java.awt.event.InputEvent; import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.image.*; import java.lang.reflect.Field; @@ -182,7 +184,7 @@ public class JBScrollPane extends JScrollPane { if (value instanceof MouseWheelListener) { MouseWheelListener oldListener = (MouseWheelListener)value; MouseWheelListener newListener = event -> { - if (UIUtil.isScrollEvent(event)) { + if (isScrollEvent(event)) { Object source = event.getSource(); if (source instanceof JScrollPane) { JScrollPane pane = (JScrollPane)source; @@ -988,4 +990,17 @@ public class JBScrollPane extends JScrollPane { public void dispose() { } } + + /** + * Indicates whether the specified event is not consumed and does not have unexpected modifiers. + * + * @param event a mouse wheel event to check for validity + * @return {@code true} if the specified event is valid, {@code false} otherwise + */ + public static boolean isScrollEvent(@NotNull MouseWheelEvent event) { + if (event.isConsumed()) return false; // event should not be consumed already + if (event.getWheelRotation() == 0) return false; // any rotation expected (forward or backward) + int modifiers = ~InputEvent.SHIFT_MASK & ~InputEvent.SHIFT_DOWN_MASK & event.getModifiers(); + return modifiers == 0; // no modifiers expected except SHIFT for horizontal scrolling + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java index e576fdd8da83..2597914c08fc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java @@ -46,6 +46,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import static com.intellij.ui.components.JBScrollPane.isScrollEvent; import static java.awt.event.MouseEvent.*; /** @@ -325,7 +326,7 @@ public final class IdeMouseEventDispatcher { final MouseWheelEvent mwe = (MouseWheelEvent)e; return mwe.isShiftDown() && mwe.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL - && UIUtil.isScrollEvent(mwe) + && isScrollEvent(mwe) && findHorizontalScrollBar(c) != null; } return false; diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 5291008d75c5..d287400e4eb4 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -109,7 +109,6 @@ ide.tree.deferred.icon.invalidates.cache=true ide.splitter.mouseZone=6 ide.smart.horizontal.scrolling=true -ide.scroll.event.old.behavior=false ide.scroll.new.layout=true ide.scroll.align.component=true ide.scroll.background.auto=true diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index 45cdc29d29f6..e2e82af88d37 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -3710,18 +3710,4 @@ public class UIUtil { } }); } - - /** - * Indicates whether the specified event is not consumed and does not have unexpected modifiers. - * - * @param event a mouse wheel event to check for validity - * @return {@code true} if the specified event is valid, {@code false} otherwise - */ - public static boolean isScrollEvent(@NotNull MouseWheelEvent event) { - if (Registry.is("ide.scroll.event.old.behavior")) return true; - if (event.isConsumed()) return false; // event should not be consumed already - if (event.getWheelRotation() == 0) return false; // any rotation expected (forward or backward) - int modifiers = ~InputEvent.SHIFT_MASK & ~InputEvent.SHIFT_DOWN_MASK & event.getModifiers(); - return modifiers == 0; // no modifiers expected except SHIFT for horizontal scrolling - } }