[session] Clarify coordinates across systems, part 4

Input and scenic are just two examples of systems that want to use
different corrdinate units within Fuchsia. This CL creates a struct that
allows systems to set and retrieve coordinates in pixels, pips, or
millimeters.

This CL moves the workstation product over to using the default
functions.

Bug: 44272
Change-Id: I0a8a0bf8134dc84f3cd9ae69afa29b880bcd1f03
diff --git a/session_shells/ermine/session/src/mouse_pointer_hack.rs b/session_shells/ermine/session/src/mouse_pointer_hack.rs
index b4c087a..5a20fe5 100644
--- a/session_shells/ermine/session/src/mouse_pointer_hack.rs
+++ b/session_shells/ermine/session/src/mouse_pointer_hack.rs
@@ -3,10 +3,16 @@
 // found in the LICENSE file.
 
 use {
-    async_trait::async_trait, fidl_fuchsia_ui_input as fidl_ui_input,
-    fidl_fuchsia_ui_policy::PointerCaptureListenerHackProxy, futures::lock::Mutex,
-    input::input_device, input::input_handler::InputHandler, input::mouse,
-    std::collections::HashSet, std::sync::Arc, input::{Position, Size},
+    async_trait::async_trait,
+    fidl_fuchsia_ui_input as fidl_ui_input,
+    fidl_fuchsia_ui_policy::PointerCaptureListenerHackProxy,
+    futures::lock::Mutex,
+    input::input_device,
+    input::input_handler::InputHandler,
+    input::mouse,
+    input::{Position, Size},
+    std::collections::HashSet,
+    std::sync::Arc,
 };
 
 /// A [`MousePointerHack`] tracks the mouse position and sends it to observers.
@@ -83,25 +89,12 @@
     /// # Parameters
     /// - `mouse_event`: The mouse event to use to update the cursor location.
     async fn update_cursor_position(&mut self, mouse_event: &mouse::MouseEvent) {
-        if mouse_event.movement().x == 0.0 && mouse_event.movement().y == 0.0 {
+        if mouse_event.movement == Position::zero() {
             return;
         }
 
-        self.current_position += mouse_event.movement();
-
-        if self.current_position.x > self.screen_size.width {
-            self.current_position.x = self.screen_size.width;
-        }
-        if self.current_position.y > self.screen_size.height {
-            self.current_position.y = self.screen_size.height;
-        }
-
-        if self.current_position.x < 0.0 {
-            self.current_position.x = 0.0;
-        }
-        if self.current_position.y < 0.0 {
-            self.current_position.y = 0.0;
-        }
+        self.current_position += mouse_event.movement;
+        Position::clamp_size(&mut self.current_position, Size::zero(), self.screen_size)
     }
 
     /// Sends a pointer event with the given phase and buttons to listeners.
diff --git a/session_shells/ermine/session/src/touch_pointer_hack.rs b/session_shells/ermine/session/src/touch_pointer_hack.rs
index 801e4aa..cb4def3 100644
--- a/session_shells/ermine/session/src/touch_pointer_hack.rs
+++ b/session_shells/ermine/session/src/touch_pointer_hack.rs
@@ -3,9 +3,15 @@
 // found in the LICENSE file.
 
 use {
-    async_trait::async_trait, fidl_fuchsia_ui_input as fidl_ui_input,
-    fidl_fuchsia_ui_policy::PointerCaptureListenerHackProxy, futures::lock::Mutex,
-    input::input_device, input::input_handler::InputHandler, input::touch, std::sync::Arc, input::{Position, Size}
+    async_trait::async_trait,
+    fidl_fuchsia_ui_input as fidl_ui_input,
+    fidl_fuchsia_ui_policy::PointerCaptureListenerHackProxy,
+    futures::lock::Mutex,
+    input::input_device,
+    input::input_handler::InputHandler,
+    input::touch,
+    input::{Position, Size},
+    std::sync::Arc,
 };
 
 /// A [`TouchPointerHack`] observes touch events and sends them to observers.
@@ -99,7 +105,8 @@
         event_time: input_device::EventTime,
         touch_descriptor: &touch::TouchDeviceDescriptor,
     ) -> fidl_ui_input::PointerEvent {
-        let position = self.device_coordinate_from_contact(&contact, &touch_descriptor) * self.event_scale;
+        let position =
+            self.device_coordinate_from_contact(&contact, &touch_descriptor) * self.event_scale;
 
         fidl_ui_input::PointerEvent {
             event_time: event_time,
@@ -130,14 +137,14 @@
                 y: (contact_descriptor.y_range.max - contact_descriptor.y_range.min) as f32,
             };
 
-            if range.x == 0.0 || range.y == 0.0 {
-                return contact.position();
+            if range == Position::zero() {
+                return contact.position;
             }
 
-            let normalized = contact.position() / range;
+            let normalized = contact.position / range;
             normalized * self.display_size
         } else {
-            return contact.position();
+            return contact.position;
         }
     }
 }
diff --git a/session_shells/ermine/session/src/workstation_input_pipeline.rs b/session_shells/ermine/session/src/workstation_input_pipeline.rs
index 8fcd83e..ebc484c 100644
--- a/session_shells/ermine/session/src/workstation_input_pipeline.rs
+++ b/session_shells/ermine/session/src/workstation_input_pipeline.rs
@@ -82,8 +82,8 @@
     scene_manager: &FlatSceneManager,
     handlers: &mut Vec<Box<dyn InputHandler>>,
 ) {
-    let (width_pixels, height_pixels) = scene_manager.display_size().pixels();
-    if let Ok(touch_handler) = TouchHandler::new2(
+    let (width_pixels, height_pixels) = scene_manager.display_size.pixels();
+    if let Ok(touch_handler) = TouchHandler::new(
         scene_manager.session.clone(),
         scene_manager.compositor_id,
         Size { width: width_pixels, height: height_pixels },
@@ -99,8 +99,8 @@
     handlers: &mut Vec<Box<dyn InputHandler>>,
 ) {
     let (sender, mut receiver) = futures::channel::mpsc::channel(0);
-    let (width_pixels, height_pixels) = scene_manager.display_size().pixels();
-    let mouse_handler = MouseHandler::new2(
+    let (width_pixels, height_pixels) = scene_manager.display_size.pixels();
+    let mouse_handler = MouseHandler::new(
         Position { x: width_pixels, y: height_pixels },
         Some(sender),
         scene_manager.session.clone(),
@@ -110,8 +110,9 @@
 
     fasync::spawn(async move {
         while let Some(Position { x, y }) = receiver.next().await {
-            let screen_coordinates = ScreenCoordinates::from_pixels(x, y, scene_manager.display_metrics);
-            scene_manager.set_cursor_location2(screen_coordinates);
+            let screen_coordinates =
+                ScreenCoordinates::from_pixels(x, y, scene_manager.display_metrics);
+            scene_manager.set_cursor_location(screen_coordinates);
         }
     });
 }
@@ -122,7 +123,7 @@
     handlers: &mut Vec<Box<dyn InputHandler>>,
 ) {
     let mouse_hack = MousePointerHack::new(
-        scene_manager.display_size().size(),
+        scene_manager.display_size.size(),
         1.0 / scene_manager.display_metrics.pixels_per_pip(),
         pointer_hack_server.pointer_listeners.clone(),
     );
@@ -135,7 +136,7 @@
     handlers: &mut Vec<Box<dyn InputHandler>>,
 ) {
     let touch_hack = TouchPointerHack::new(
-        scene_manager.display_size().size(),
+        scene_manager.display_size.size(),
         1.0 / scene_manager.display_metrics.pixels_per_pip(),
         pointer_hack_server.pointer_listeners.clone(),
     );