Repository: napari/napari

Issue:
Use new mouse function bindings and test mouse functions on layers
We need to refactor the current mouse functions on the layers to use the new mouse bindings framework in #544 and add tests for all of them, as was done for one in #684



Discussion:

Resolving patch:
diff --git a/napari/_qt/qt_viewer.py b/napari/_qt/qt_viewer.py
--- a/napari/_qt/qt_viewer.py
+++ b/napari/_qt/qt_viewer.py
@@ -459,8 +459,10 @@ def on_mouse_press(self, event):
 
         layer = self.viewer.active_layer
         if layer is not None:
-            # Line bellow needed until layer mouse callbacks are refactored
-            self.layer_to_visual[layer].on_mouse_press(event)
+            # update cursor position in visual and layer
+            visual = self.layer_to_visual[layer]
+            visual._position = list(event.pos)
+            layer.position = visual._transform_position(visual._position)
             mouse_press_callbacks(layer, event)
 
     def on_mouse_move(self, event):
@@ -478,8 +480,10 @@ def on_mouse_move(self, event):
 
         layer = self.viewer.active_layer
         if layer is not None:
-            # Line bellow needed until layer mouse callbacks are refactored
-            self.layer_to_visual[layer].on_mouse_move(event)
+            # update cursor position in visual and layer
+            visual = self.layer_to_visual[layer]
+            visual._position = list(event.pos)
+            layer.position = visual._transform_position(visual._position)
             mouse_move_callbacks(layer, event)
 
     def on_mouse_release(self, event):
@@ -490,12 +494,17 @@ def on_mouse_release(self, event):
         event : qtpy.QtCore.QEvent
             Event from the Qt context.
         """
+        if event.pos is None:
+            return
+
         mouse_release_callbacks(self.viewer, event)
 
         layer = self.viewer.active_layer
         if layer is not None:
-            # Line bellow needed until layer mouse callbacks are refactored
-            self.layer_to_visual[layer].on_mouse_release(event)
+            # update cursor position in visual and layer
+            visual = self.layer_to_visual[layer]
+            visual._position = list(event.pos)
+            layer.position = visual._transform_position(visual._position)
             mouse_release_callbacks(layer, event)
 
     def on_key_press(self, event):
diff --git a/napari/_vispy/vispy_base_layer.py b/napari/_vispy/vispy_base_layer.py
--- a/napari/_vispy/vispy_base_layer.py
+++ b/napari/_vispy/vispy_base_layer.py
@@ -177,32 +177,6 @@ def _reset_base(self):
         self._on_scale_change()
         self._on_translate_change()
 
-    def on_mouse_move(self, event):
-        """Called whenever mouse moves over canvas."""
-        if event.pos is None:
-            return
-        self._position = list(event.pos)
-        self.layer.position = self._transform_position(self._position)
-        self.layer.on_mouse_move(event)
-
-    def on_mouse_press(self, event):
-        """Called whenever mouse pressed in canvas.
-        """
-        if event.pos is None:
-            return
-        self._position = list(event.pos)
-        self.layer.position = self._transform_position(self._position)
-        self.layer.on_mouse_press(event)
-
-    def on_mouse_release(self, event):
-        """Called whenever mouse released in canvas.
-        """
-        if event.pos is None:
-            return
-        self._position = list(event.pos)
-        self.layer.position = self._transform_position(self._position)
-        self.layer.on_mouse_release(event)
-
     def on_draw(self, event):
         """Called whenever the canvas is drawn.
         """
diff --git a/napari/layers/base/base.py b/napari/layers/base/base.py
--- a/napari/layers/base/base.py
+++ b/napari/layers/base/base.py
@@ -723,17 +723,3 @@ def to_svg(self, file=None, canvas_shape=None):
                 f.write(svg)
 
         return svg
-
-    def on_mouse_move(self, event):
-        """Called whenever mouse moves over canvas."""
-        return
-
-    def on_mouse_press(self, event):
-        """Called whenever mouse pressed in canvas.
-        """
-        return
-
-    def on_mouse_release(self, event):
-        """Called whenever mouse released in canvas.
-        """
-        return


Test patch: