diff options
Diffstat (limited to 'components/compositing')
-rw-r--r-- | components/compositing/Cargo.toml | 2 | ||||
-rw-r--r-- | components/compositing/compositor.rs | 139 | ||||
-rw-r--r-- | components/compositing/compositor_layer.rs | 59 | ||||
-rw-r--r-- | components/compositing/lib.rs | 2 | ||||
-rw-r--r-- | components/compositing/touch.rs | 28 | ||||
-rw-r--r-- | components/compositing/windowing.rs | 24 |
6 files changed, 121 insertions, 133 deletions
diff --git a/components/compositing/Cargo.toml b/components/compositing/Cargo.toml index ff5440b54d5..f928ef72793 100644 --- a/components/compositing/Cargo.toml +++ b/components/compositing/Cargo.toml @@ -12,7 +12,7 @@ path = "lib.rs" [dependencies] app_units = "0.2.5" azure = {git = "https://github.com/servo/rust-azure", features = ["plugins"]} -euclid = "0.7.1" +euclid = "0.8.2" gfx_traits = {path = "../gfx_traits"} gleam = "0.2.8" image = "0.10" diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 653fb219447..8c0c3c26018 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -153,24 +153,24 @@ pub struct IOCompositor<Window: WindowMethods> { scene: Scene<CompositorData>, /// The application window size. - window_size: TypedSize2D<DevicePixel, u32>, + window_size: TypedSize2D<u32, DevicePixel>, /// The overridden viewport. - viewport: Option<(TypedPoint2D<DevicePixel, u32>, TypedSize2D<DevicePixel, u32>)>, + viewport: Option<(TypedPoint2D<u32, DevicePixel>, TypedSize2D<u32, DevicePixel>)>, /// "Mobile-style" zoom that does not reflow the page. - viewport_zoom: ScaleFactor<PagePx, ViewportPx, f32>, + viewport_zoom: ScaleFactor<f32, PagePx, ViewportPx>, /// Viewport zoom constraints provided by @viewport. - min_viewport_zoom: Option<ScaleFactor<PagePx, ViewportPx, f32>>, - max_viewport_zoom: Option<ScaleFactor<PagePx, ViewportPx, f32>>, + min_viewport_zoom: Option<ScaleFactor<f32, PagePx, ViewportPx>>, + max_viewport_zoom: Option<ScaleFactor<f32, PagePx, ViewportPx>>, /// "Desktop-style" zoom that resizes the viewport to fit the window. /// See `ViewportPx` docs in util/geom.rs for details. - page_zoom: ScaleFactor<ViewportPx, ScreenPx, f32>, + page_zoom: ScaleFactor<f32, ViewportPx, ScreenPx>, /// The device pixel ratio for this window. - scale_factor: ScaleFactor<ScreenPx, DevicePixel, f32>, + scale_factor: ScaleFactor<f32, ScreenPx, DevicePixel>, channel_to_self: Box<CompositorProxy + Send>, @@ -254,9 +254,9 @@ struct ScrollZoomEvent { /// Change the pinch zoom level by this factor magnification: f32, /// Scroll by this offset - delta: TypedPoint2D<DevicePixel, f32>, + delta: TypedPoint2D<f32, DevicePixel>, /// Apply changes to the frame at this location - cursor: TypedPoint2D<DevicePixel, i32>, + cursor: TypedPoint2D<i32, DevicePixel>, /// The scroll event phase. phase: ScrollEventPhase, /// The number of OS events that have been coalesced together into this one event. @@ -281,7 +281,7 @@ struct HitTestResult { /// The topmost layer containing the requested point layer: Rc<Layer<CompositorData>>, /// The point in client coordinates of the innermost window or frame containing `layer` - point: TypedPoint2D<LayerPixel, f32>, + point: TypedPoint2D<f32, LayerPixel>, } struct PipelineDetails { @@ -467,10 +467,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { context: None, root_pipeline: None, pipeline_details: HashMap::new(), - scene: Scene::new(Rect { - origin: Point2D::zero(), - size: window_size.as_f32(), - }), + scene: Scene::new(TypedRect::new(TypedPoint2D::zero(), window_size.as_f32())), window_size: window_size, viewport: None, scale_factor: scale_factor, @@ -792,7 +789,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { match self.find_layer_with_pipeline_and_layer_id(pipeline_id, layer_id) { Some(ref layer) => { let typed = layer.extra_data.borrow().scroll_offset; - let _ = sender.send(Point2D::new(typed.x.get(), typed.y.get())); + let _ = sender.send(Point2D::new(typed.x, typed.y)); }, None => { warn!("Can't find requested layer in handling Msg::GetScrollOffset"); @@ -913,7 +910,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { fn create_root_layer_for_pipeline_and_size(&mut self, pipeline: &CompositionPipeline, - frame_size: Option<TypedSize2D<PagePx, f32>>) + frame_size: Option<TypedSize2D<f32, PagePx>>) -> Rc<Layer<CompositorData>> { let layer_properties = LayerProperties { id: LayerId::null(), @@ -939,8 +936,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { *root_layer.masks_to_bounds.borrow_mut() = true; if let Some(ref frame_size) = frame_size { - let frame_size = frame_size.to_untyped(); - root_layer.bounds.borrow_mut().size = Size2D::from_untyped(&frame_size); + root_layer.bounds.borrow_mut().size = + TypedSize2D::new(frame_size.width, frame_size.height); } root_layer @@ -998,8 +995,9 @@ impl<Window: WindowMethods> IOCompositor<Window> { if let Some(subpage_id) = properties.subpage_pipeline_id { match self.find_layer_with_pipeline_and_layer_id(subpage_id, LayerId::null()) { Some(layer) => { - *layer.bounds.borrow_mut() = Rect::from_untyped( - &Rect::new(Point2D::zero(), properties.rect.size)); + *layer.bounds.borrow_mut() = + TypedRect::new(TypedPoint2D::zero(), + TypedSize2D::from_untyped(&properties.rect.size)); } None => warn!("Tried to update non-existent subpage root layer: {:?}", subpage_id), } @@ -1178,12 +1176,12 @@ impl<Window: WindowMethods> IOCompositor<Window> { fn move_layer(&self, pipeline_id: PipelineId, layer_id: LayerId, - origin: TypedPoint2D<LayerPixel, f32>) + origin: TypedPoint2D<f32, LayerPixel>) -> bool { match self.find_layer_with_pipeline_and_layer_id(pipeline_id, layer_id) { Some(ref layer) => { if layer.wants_scroll_events() == WantsScrollEventsFlag::WantsScrollEvents { - layer.clamp_scroll_offset_and_scroll_layer(Point2D::typed(0f32, 0f32) - origin); + layer.clamp_scroll_offset_and_scroll_layer(TypedPoint2D::zero() - origin); } true } @@ -1195,7 +1193,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { pipeline_id: PipelineId, layer_id: LayerId) { if let Some(point) = self.fragment_point.take() { - if !self.move_layer(pipeline_id, layer_id, Point2D::from_untyped(&point)) { + if !self.move_layer(pipeline_id, layer_id, TypedPoint2D::from_untyped(&point)) { return warn!("Compositor: Tried to scroll to fragment with unknown layer."); } @@ -1251,8 +1249,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { new_layer_buffer_set: Box<LayerBufferSet>, epoch: Epoch) { debug!("compositor received new frame at size {:?}x{:?}", - self.window_size.width.get(), - self.window_size.height.get()); + self.window_size.width, + self.window_size.height); // From now on, if we destroy the buffers, they will leak. let mut new_layer_buffer_set = new_layer_buffer_set; @@ -1268,7 +1266,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { pipeline_id: PipelineId, layer_id: LayerId, point: Point2D<f32>) { - if self.move_layer(pipeline_id, layer_id, Point2D::from_untyped(&point)) { + if self.move_layer(pipeline_id, layer_id, TypedPoint2D::from_untyped(&point)) { self.perform_updates_after_scroll(); self.send_viewport_rects_for_all_layers() } else { @@ -1369,7 +1367,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn on_resize_window_event(&mut self, new_size: TypedSize2D<DevicePixel, u32>) { + fn on_resize_window_event(&mut self, new_size: TypedSize2D<u32, DevicePixel>) { debug!("compositor resizing to {:?}", new_size.to_untyped()); // A size change could also mean a resolution change. @@ -1457,7 +1455,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn on_mouse_window_move_event_class(&mut self, cursor: TypedPoint2D<DevicePixel, f32>) { + fn on_mouse_window_move_event_class(&mut self, cursor: TypedPoint2D<f32, DevicePixel>) { if opts::get().convert_mouse_to_touch { self.on_touch_move(TouchId(0), cursor); return @@ -1505,7 +1503,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn on_touch_down(&mut self, identifier: TouchId, point: TypedPoint2D<DevicePixel, f32>) { + fn on_touch_down(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) { self.touch_handler.on_touch_down(identifier, point); if let Some(result) = self.find_topmost_layer_at_point(point / self.scene.scale) { result.layer.send_event(self, TouchEvent(TouchEventType::Down, identifier, @@ -1513,7 +1511,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn on_touch_move(&mut self, identifier: TouchId, point: TypedPoint2D<DevicePixel, f32>) { + fn on_touch_move(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) { match self.touch_handler.on_touch_move(identifier, point) { TouchAction::Scroll(delta) => { match point.cast() { @@ -1522,7 +1520,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } TouchAction::Zoom(magnification, scroll_delta) => { - let cursor = Point2D::typed(-1, -1); // Make sure this hits the base layer. + let cursor = TypedPoint2D::new(-1, -1); // Make sure this hits the base layer. self.pending_scroll_zoom_events.push(ScrollZoomEvent { magnification: magnification, delta: scroll_delta, @@ -1542,7 +1540,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn on_touch_up(&mut self, identifier: TouchId, point: TypedPoint2D<DevicePixel, f32>) { + fn on_touch_up(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) { if let Some(result) = self.find_topmost_layer_at_point(point / self.scene.scale) { result.layer.send_event(self, TouchEvent(TouchEventType::Up, identifier, result.point.to_untyped())); @@ -1552,7 +1550,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn on_touch_cancel(&mut self, identifier: TouchId, point: TypedPoint2D<DevicePixel, f32>) { + fn on_touch_cancel(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) { // Send the event to script. self.touch_handler.on_touch_cancel(identifier, point); if let Some(result) = self.find_topmost_layer_at_point(point / self.scene.scale) { @@ -1562,7 +1560,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } /// http://w3c.github.io/touch-events/#mouse-events - fn simulate_mouse_click(&self, p: TypedPoint2D<DevicePixel, f32>) { + fn simulate_mouse_click(&self, p: TypedPoint2D<f32, DevicePixel>) { match self.find_topmost_layer_at_point(p / self.scene.scale) { Some(HitTestResult { layer, point }) => { let button = MouseButton::Left; @@ -1576,8 +1574,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { } fn on_scroll_window_event(&mut self, - delta: TypedPoint2D<DevicePixel, f32>, - cursor: TypedPoint2D<DevicePixel, i32>) { + delta: TypedPoint2D<f32, DevicePixel>, + cursor: TypedPoint2D<i32, DevicePixel>) { self.pending_scroll_zoom_events.push(ScrollZoomEvent { magnification: 1.0, delta: delta, @@ -1589,8 +1587,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { } fn on_scroll_start_window_event(&mut self, - delta: TypedPoint2D<DevicePixel, f32>, - cursor: TypedPoint2D<DevicePixel, i32>) { + delta: TypedPoint2D<f32, DevicePixel>, + cursor: TypedPoint2D<i32, DevicePixel>) { self.scroll_in_progress = true; self.pending_scroll_zoom_events.push(ScrollZoomEvent { magnification: 1.0, @@ -1603,8 +1601,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { } fn on_scroll_end_window_event(&mut self, - delta: TypedPoint2D<DevicePixel, f32>, - cursor: TypedPoint2D<DevicePixel, i32>) { + delta: TypedPoint2D<f32, DevicePixel>, + cursor: TypedPoint2D<i32, DevicePixel>) { self.scroll_in_progress = false; self.pending_scroll_zoom_events.push(ScrollZoomEvent { magnification: 1.0, @@ -1710,17 +1708,19 @@ impl<Window: WindowMethods> IOCompositor<Window> { /// sends them to layout as necessary. This ultimately triggers a rerender of the content. fn send_updated_display_ports_to_layout(&mut self) { fn process_layer(layer: &Layer<CompositorData>, - window_size: &TypedSize2D<LayerPixel, f32>, + window_size: &TypedSize2D<f32, LayerPixel>, new_display_ports: &mut HashMap<PipelineId, Vec<(LayerId, Rect<Au>)>>) { let visible_rect = - Rect::new(Point2D::zero(), *window_size).translate(&-*layer.content_offset.borrow()) - .intersection(&*layer.bounds.borrow()) - .unwrap_or(Rect::zero()) - .to_untyped(); - let visible_rect = Rect::new(Point2D::new(Au::from_f32_px(visible_rect.origin.x), - Au::from_f32_px(visible_rect.origin.y)), - Size2D::new(Au::from_f32_px(visible_rect.size.width), - Au::from_f32_px(visible_rect.size.height))); + TypedRect::new(TypedPoint2D::zero(), *window_size) + .translate(&-*layer.content_offset.borrow()) + .intersection(&*layer.bounds.borrow()) + .unwrap_or(TypedRect::zero()) + .to_untyped(); + let visible_rect = TypedRect::new( + TypedPoint2D::new(Au::from_f32_px(visible_rect.origin.x), + Au::from_f32_px(visible_rect.origin.y)), + TypedSize2D::new(Au::from_f32_px(visible_rect.size.width), + Au::from_f32_px(visible_rect.size.height))); let extra_layer_data = layer.extra_data.borrow(); if !new_display_ports.contains_key(&extra_layer_data.pipeline_id) { @@ -1815,7 +1815,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn device_pixels_per_screen_px(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32> { + fn device_pixels_per_screen_px(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel> { match opts::get().device_pixels_per_px { Some(device_pixels_per_px) => ScaleFactor::new(device_pixels_per_px), None => match opts::get().output_file { @@ -1825,7 +1825,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn device_pixels_per_page_px(&self) -> ScaleFactor<PagePx, DevicePixel, f32> { + fn device_pixels_per_page_px(&self) -> ScaleFactor<f32, PagePx, DevicePixel> { self.viewport_zoom * self.page_zoom * self.device_pixels_per_screen_px() } @@ -1855,8 +1855,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { fn on_pinch_zoom_window_event(&mut self, magnification: f32) { self.pending_scroll_zoom_events.push(ScrollZoomEvent { magnification: magnification, - delta: Point2D::typed(0.0, 0.0), // TODO: Scroll to keep the center in view? - cursor: Point2D::typed(-1, -1), // Make sure this hits the base layer. + delta: TypedPoint2D::zero(), // TODO: Scroll to keep the center in view? + cursor: TypedPoint2D::new(-1, -1), // Make sure this hits the base layer. phase: ScrollEventPhase::Move(true), event_count: 1, }); @@ -1874,7 +1874,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn on_touchpad_pressure_event(&self, cursor: TypedPoint2D<DevicePixel, f32>, pressure: f32, + fn on_touchpad_pressure_event(&self, cursor: TypedPoint2D<f32, DevicePixel>, pressure: f32, phase: TouchpadPressurePhase) { if let Some(true) = PREFS.get("dom.forcetouch.enabled").as_boolean() { match self.find_topmost_layer_at_point(cursor / self.scene.scale) { @@ -2194,7 +2194,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { return Err(UnableToComposite::NoContext) } let (width, height) = - (self.window_size.width.get() as usize, self.window_size.height.get() as usize); + (self.window_size.width as usize, self.window_size.height as usize); if !self.window.prepare_for_composite(width, height) { return Err(UnableToComposite::WindowUnprepared) } @@ -2236,15 +2236,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { self.dump_layer_tree(); // Adjust the layer dimensions as necessary to correspond to the size of the window. self.scene.viewport = match self.viewport { - Some((point, size)) => Rect { - origin: point.as_f32(), - size: size.as_f32(), - }, - - None => Rect { - origin: Point2D::zero(), - size: self.window_size.as_f32(), - } + Some((point, size)) => TypedRect::new(point.as_f32(), size.as_f32()), + None => TypedRect::new(TypedPoint2D::zero(), self.window_size.as_f32()), }; // Paint the scene. @@ -2255,15 +2248,13 @@ impl<Window: WindowMethods> IOCompositor<Window> { match self.context { Some(context) => { if let Some((point, size)) = self.viewport { - let point = point.to_untyped(); - let size = size.to_untyped(); + let point = point.to_untyped(); let size = size.to_untyped(); - gl::scissor(point.x as GLint, point.y as GLint, - size.width as GLsizei, size.height as GLsizei); + gl::scissor(point.x as GLint, point.y as GLint, size.width as GLsizei, + size.height as GLsizei); - gl::enable(gl::SCISSOR_TEST); - rendergl::render_scene(layer.clone(), context, &self.scene); - gl::disable(gl::SCISSOR_TEST); + gl::enable(gl::SCISSOR_TEST); rendergl::render_scene(layer.clone(), + context, &self.scene); gl::disable(gl::SCISSOR_TEST); } else { rendergl::render_scene(layer.clone(), context, &self.scene); @@ -2389,8 +2380,8 @@ impl<Window: WindowMethods> IOCompositor<Window> { fn find_topmost_layer_at_point_for_layer(&self, layer: Rc<Layer<CompositorData>>, - point_in_parent_layer: TypedPoint2D<LayerPixel, f32>, - clip_rect_in_parent_layer: &TypedRect<LayerPixel, f32>) + point_in_parent_layer: TypedPoint2D<f32, LayerPixel>, + clip_rect_in_parent_layer: &TypedRect<f32, LayerPixel>) -> Option<HitTestResult> { let layer_bounds = *layer.bounds.borrow(); let masks_to_bounds = *layer.masks_to_bounds.borrow(); @@ -2439,7 +2430,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } fn find_topmost_layer_at_point(&self, - point: TypedPoint2D<LayerPixel, f32>) + point: TypedPoint2D<f32, LayerPixel>) -> Option<HitTestResult> { match self.scene.root { Some(ref layer) => { diff --git a/components/compositing/compositor_layer.rs b/components/compositing/compositor_layer.rs index 9f5e0480e1b..745da90f2d3 100644 --- a/components/compositing/compositor_layer.rs +++ b/components/compositing/compositor_layer.rs @@ -4,9 +4,8 @@ use azure::azure_hl; use compositor::IOCompositor; -use euclid::length::Length; -use euclid::point::{Point2D, TypedPoint2D}; -use euclid::rect::Rect; +use euclid::point::TypedPoint2D; +use euclid::rect::TypedRect; use euclid::size::TypedSize2D; use gfx_traits::{Epoch, LayerId, LayerProperties, ScrollPolicy}; use layers::color::Color; @@ -44,7 +43,7 @@ pub struct CompositorData { /// The scroll offset originating from this scrolling root. This allows scrolling roots /// to track their current scroll position even while their content_offset does not change. - pub scroll_offset: TypedPoint2D<LayerPixel, f32>, + pub scroll_offset: TypedPoint2D<f32, LayerPixel>, /// The pipeline ID of this layer, if it represents a subpage. pub subpage_info: Option<PipelineId>, @@ -63,11 +62,11 @@ impl CompositorData { scroll_policy: layer_properties.scroll_policy, requested_epoch: Epoch(0), painted_epoch: Epoch(0), - scroll_offset: Point2D::typed(0., 0.), + scroll_offset: TypedPoint2D::zero(), subpage_info: layer_properties.subpage_pipeline_id, }; - Rc::new(Layer::new(Rect::from_untyped(&layer_properties.rect), + Rc::new(Layer::new(TypedRect::from_untyped(&layer_properties.rect), tile_size, to_layers_color(&layer_properties.background_color), 1.0, @@ -117,8 +116,8 @@ pub trait CompositorLayer { /// ScrollPositionUnchanged or ScrollPositionChanged. If no layer was targeted by the event /// returns ScrollEventUnhandled. fn handle_scroll_event(&self, - delta: TypedPoint2D<LayerPixel, f32>, - cursor: TypedPoint2D<LayerPixel, f32>) + delta: TypedPoint2D<f32, LayerPixel>, + cursor: TypedPoint2D<f32, LayerPixel>) -> ScrollEventResult; // Takes in a MouseWindowEvent, determines if it should be passed to children, and @@ -127,12 +126,12 @@ pub trait CompositorLayer { fn send_mouse_event<Window>(&self, compositor: &IOCompositor<Window>, event: MouseWindowEvent, - cursor: TypedPoint2D<LayerPixel, f32>) + cursor: TypedPoint2D<f32, LayerPixel>) where Window: WindowMethods; fn send_mouse_move_event<Window>(&self, compositor: &IOCompositor<Window>, - cursor: TypedPoint2D<LayerPixel, f32>) + cursor: TypedPoint2D<f32, LayerPixel>) where Window: WindowMethods; fn send_event<Window>(&self, @@ -142,17 +141,17 @@ pub trait CompositorLayer { fn send_touchpad_pressure_event<Window>(&self, compositor: &IOCompositor<Window>, - cursor: TypedPoint2D<LayerPixel, f32>, + cursor: TypedPoint2D<f32, LayerPixel>, pressure: f32, phase: TouchpadPressurePhase) where Window: WindowMethods; fn clamp_scroll_offset_and_scroll_layer(&self, - new_offset: TypedPoint2D<LayerPixel, f32>) + new_offset: TypedPoint2D<f32, LayerPixel>) -> ScrollEventResult; fn scroll_layer_and_all_child_layers(&self, - new_offset: TypedPoint2D<LayerPixel, f32>) + new_offset: TypedPoint2D<f32, LayerPixel>) -> bool; /// Return a flag describing how this layer deals with scroll events. @@ -202,8 +201,8 @@ impl Clampable for f32 { } fn calculate_content_size_for_layer(layer: &Layer<CompositorData>) - -> TypedSize2D<LayerPixel, f32> { - layer.children().iter().fold(Rect::zero(), + -> TypedSize2D<f32, LayerPixel> { + layer.children().iter().fold(TypedRect::zero(), |unioned_rect, child_rect| { unioned_rect.union(&*child_rect.bounds.borrow()) }).size @@ -229,11 +228,11 @@ impl CompositorLayer for Layer<CompositorData> { } fn update_layer(&self, layer_properties: LayerProperties) { - *self.bounds.borrow_mut() = Rect::from_untyped(&layer_properties.rect); + *self.bounds.borrow_mut() = TypedRect::from_untyped(&layer_properties.rect); // Call scroll for bounds checking if the page shrunk. Use (-1, -1) as the // cursor position to make sure the scroll isn't propagated downwards. - self.handle_scroll_event(Point2D::typed(0f32, 0f32), Point2D::typed(-1f32, -1f32)); + self.handle_scroll_event(TypedPoint2D::zero(), TypedPoint2D::new(-1f32, -1f32)); self.update_layer_except_bounds(layer_properties); } @@ -320,8 +319,8 @@ impl CompositorLayer for Layer<CompositorData> { } fn handle_scroll_event(&self, - delta: TypedPoint2D<LayerPixel, f32>, - cursor: TypedPoint2D<LayerPixel, f32>) + delta: TypedPoint2D<f32, LayerPixel>, + cursor: TypedPoint2D<f32, LayerPixel>) -> ScrollEventResult { // Allow children to scroll. let scroll_offset = self.extra_data.borrow().scroll_offset; @@ -344,15 +343,15 @@ impl CompositorLayer for Layer<CompositorData> { self.clamp_scroll_offset_and_scroll_layer(scroll_offset + delta) } - fn clamp_scroll_offset_and_scroll_layer(&self, new_offset: TypedPoint2D<LayerPixel, f32>) + fn clamp_scroll_offset_and_scroll_layer(&self, new_offset: TypedPoint2D<f32, LayerPixel>) -> ScrollEventResult { let layer_size = self.bounds.borrow().size; let content_size = calculate_content_size_for_layer(self); - let min_x = (layer_size.width - content_size.width).get().min(0.0); - let min_y = (layer_size.height - content_size.height).get().min(0.0); - let new_offset: TypedPoint2D<LayerPixel, f32> = - Point2D::new(Length::new(new_offset.x.get().clamp(&min_x, &0.0)), - Length::new(new_offset.y.get().clamp(&min_y, &0.0))); + let min_x = (layer_size.width - content_size.width).min(0.0); + let min_y = (layer_size.height - content_size.height).min(0.0); + let new_offset: TypedPoint2D<f32, LayerPixel> = + TypedPoint2D::new(new_offset.x.clamp(&min_x, &0.0), + new_offset.y.clamp(&min_y, &0.0)); if self.extra_data.borrow().scroll_offset == new_offset { return ScrollEventResult::ScrollPositionUnchanged; @@ -377,7 +376,7 @@ impl CompositorLayer for Layer<CompositorData> { fn send_mouse_event<Window>(&self, compositor: &IOCompositor<Window>, event: MouseWindowEvent, - cursor: TypedPoint2D<LayerPixel, f32>) + cursor: TypedPoint2D<f32, LayerPixel>) where Window: WindowMethods { let event_point = cursor.to_untyped(); let message = match event { @@ -393,7 +392,7 @@ impl CompositorLayer for Layer<CompositorData> { fn send_mouse_move_event<Window>(&self, compositor: &IOCompositor<Window>, - cursor: TypedPoint2D<LayerPixel, f32>) + cursor: TypedPoint2D<f32, LayerPixel>) where Window: WindowMethods { self.send_event(compositor, MouseMoveEvent(Some(cursor.to_untyped()))); } @@ -409,7 +408,7 @@ impl CompositorLayer for Layer<CompositorData> { fn send_touchpad_pressure_event<Window>(&self, compositor: &IOCompositor<Window>, - cursor: TypedPoint2D<LayerPixel, f32>, + cursor: TypedPoint2D<f32, LayerPixel>, pressure: f32, phase: TouchpadPressurePhase) where Window: WindowMethods { @@ -419,14 +418,14 @@ impl CompositorLayer for Layer<CompositorData> { } } - fn scroll_layer_and_all_child_layers(&self, new_offset: TypedPoint2D<LayerPixel, f32>) + fn scroll_layer_and_all_child_layers(&self, new_offset: TypedPoint2D<f32, LayerPixel>) -> bool { let mut result = false; // Only scroll this layer if it's not fixed-positioned. if self.extra_data.borrow().scroll_policy != ScrollPolicy::FixedPosition { let new_offset = new_offset.to_untyped(); - *self.content_offset.borrow_mut() = Point2D::from_untyped(&new_offset); + *self.content_offset.borrow_mut() = TypedPoint2D::from_untyped(&new_offset); result = true } diff --git a/components/compositing/lib.rs b/components/compositing/lib.rs index 1f510d39e8d..3888b03e6d3 100644 --- a/components/compositing/lib.rs +++ b/components/compositing/lib.rs @@ -55,7 +55,7 @@ pub mod windowing; pub struct SendableFrameTree { pub pipeline: CompositionPipeline, - pub size: Option<TypedSize2D<PagePx, f32>>, + pub size: Option<TypedSize2D<f32, PagePx>>, pub children: Vec<SendableFrameTree>, } diff --git a/components/compositing/touch.rs b/components/compositing/touch.rs index 4f20afedd63..3bc22440994 100644 --- a/components/compositing/touch.rs +++ b/components/compositing/touch.rs @@ -19,11 +19,11 @@ pub struct TouchHandler { #[derive(Clone, Copy, Debug)] pub struct TouchPoint { pub id: TouchId, - pub point: TypedPoint2D<DevicePixel, f32> + pub point: TypedPoint2D<f32, DevicePixel> } impl TouchPoint { - pub fn new(id: TouchId, point: TypedPoint2D<DevicePixel, f32>) -> Self { + pub fn new(id: TouchId, point: TypedPoint2D<f32, DevicePixel>) -> Self { TouchPoint { id: id, point: point } } } @@ -57,9 +57,9 @@ pub enum TouchAction { /// Simulate a mouse click. Click, /// Scroll by the provided offset. - Scroll(TypedPoint2D<DevicePixel, f32>), + Scroll(TypedPoint2D<f32, DevicePixel>), /// Zoom by a magnification factor and scroll by the provided offset. - Zoom(f32, TypedPoint2D<DevicePixel, f32>), + Zoom(f32, TypedPoint2D<f32, DevicePixel>), /// Send a JavaScript event to content. DispatchEvent, /// Don't do anything. @@ -74,7 +74,7 @@ impl TouchHandler { } } - pub fn on_touch_down(&mut self, id: TouchId, point: TypedPoint2D<DevicePixel, f32>) { + pub fn on_touch_down(&mut self, id: TouchId, point: TypedPoint2D<f32, DevicePixel>) { let point = TouchPoint::new(id, point); self.active_touch_points.push(point); @@ -87,7 +87,7 @@ impl TouchHandler { }; } - pub fn on_touch_move(&mut self, id: TouchId, point: TypedPoint2D<DevicePixel, f32>) + pub fn on_touch_move(&mut self, id: TouchId, point: TypedPoint2D<f32, DevicePixel>) -> TouchAction { let idx = match self.active_touch_points.iter_mut().position(|t| t.id == id) { Some(i) => i, @@ -101,10 +101,10 @@ impl TouchHandler { let action = match self.state { Touching => { let delta = point - old_point; - // TODO let delta: TypedPoint2D<ScreenPx, _> = delta / self.device_pixels_per_screen_px(); + // TODO let delta: TypedPoint2D<_, ScreenPx> = delta / self.device_pixels_per_screen_px(); - if delta.x.get().abs() > TOUCH_PAN_MIN_SCREEN_PX || - delta.y.get().abs() > TOUCH_PAN_MIN_SCREEN_PX + if delta.x.abs() > TOUCH_PAN_MIN_SCREEN_PX || + delta.y.abs() > TOUCH_PAN_MIN_SCREEN_PX { self.state = Panning; TouchAction::Scroll(delta) @@ -142,7 +142,7 @@ impl TouchHandler { action } - pub fn on_touch_up(&mut self, id: TouchId, _point: TypedPoint2D<DevicePixel, f32>) + pub fn on_touch_up(&mut self, id: TouchId, _point: TypedPoint2D<f32, DevicePixel>) -> TouchAction { match self.active_touch_points.iter().position(|t| t.id == id) { Some(i) => { @@ -176,7 +176,7 @@ impl TouchHandler { } } - pub fn on_touch_cancel(&mut self, id: TouchId, _point: TypedPoint2D<DevicePixel, f32>) { + pub fn on_touch_cancel(&mut self, id: TouchId, _point: TypedPoint2D<f32, DevicePixel>) { match self.active_touch_points.iter().position(|t| t.id == id) { Some(i) => { self.active_touch_points.swap_remove(i); @@ -219,16 +219,14 @@ impl TouchHandler { self.active_touch_points.len() } - fn pinch_distance_and_center(&self) -> (f32, TypedPoint2D<DevicePixel, f32>) { + fn pinch_distance_and_center(&self) -> (f32, TypedPoint2D<f32, DevicePixel>) { debug_assert!(self.touch_count() == 2); let p0 = self.active_touch_points[0].point; let p1 = self.active_touch_points[1].point; let center = (p0 + p1) / ScaleFactor::new(2.0); let d = p0 - p1; - let dx = d.x.get(); - let dy = d.y.get(); - let distance = f32::sqrt(dx * dx + dy * dy); + let distance = f32::sqrt(d.x * d.x + d.y * d.y); (distance, center) } diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 2da658a9661..dc0465962ce 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -21,9 +21,9 @@ use util::geometry::ScreenPx; #[derive(Clone)] pub enum MouseWindowEvent { - Click(MouseButton, TypedPoint2D<DevicePixel, f32>), - MouseDown(MouseButton, TypedPoint2D<DevicePixel, f32>), - MouseUp(MouseButton, TypedPoint2D<DevicePixel, f32>), + Click(MouseButton, TypedPoint2D<f32, DevicePixel>), + MouseDown(MouseButton, TypedPoint2D<f32, DevicePixel>), + MouseUp(MouseButton, TypedPoint2D<f32, DevicePixel>), } #[derive(Clone)] @@ -49,22 +49,22 @@ pub enum WindowEvent { /// context when this message is sent. InitializeCompositing, /// Sent when the window is resized. - Resize(TypedSize2D<DevicePixel, u32>), + Resize(TypedSize2D<u32, DevicePixel>), /// Touchpad Pressure - TouchpadPressure(TypedPoint2D<DevicePixel, f32>, f32, TouchpadPressurePhase), + TouchpadPressure(TypedPoint2D<f32, DevicePixel>, f32, TouchpadPressurePhase), /// Sent when you want to override the viewport. - Viewport(TypedPoint2D<DevicePixel, u32>, TypedSize2D<DevicePixel, u32>), + Viewport(TypedPoint2D<u32, DevicePixel>, TypedSize2D<u32, DevicePixel>), /// Sent when a new URL is to be loaded. LoadUrl(String), /// Sent when a mouse hit test is to be performed. MouseWindowEventClass(MouseWindowEvent), /// Sent when a mouse move. - MouseWindowMoveEventClass(TypedPoint2D<DevicePixel, f32>), + MouseWindowMoveEventClass(TypedPoint2D<f32, DevicePixel>), /// Touch event: type, identifier, point - Touch(TouchEventType, TouchId, TypedPoint2D<DevicePixel, f32>), + Touch(TouchEventType, TouchId, TypedPoint2D<f32, DevicePixel>), /// Sent when the user scrolls. The first point is the delta and the second point is the /// origin. - Scroll(TypedPoint2D<DevicePixel, f32>, TypedPoint2D<DevicePixel, i32>, TouchEventType), + Scroll(TypedPoint2D<f32, DevicePixel>, TypedPoint2D<i32, DevicePixel>, TouchEventType), /// Sent when the user zooms. Zoom(f32), /// Simulated "pinch zoom" gesture for non-touch platforms (e.g. ctrl-scrollwheel). @@ -108,9 +108,9 @@ impl Debug for WindowEvent { pub trait WindowMethods { /// Returns the size of the window in hardware pixels. - fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, u32>; + fn framebuffer_size(&self) -> TypedSize2D<u32, DevicePixel>; /// Returns the size of the window in density-independent "px" units. - fn size(&self) -> TypedSize2D<ScreenPx, f32>; + fn size(&self) -> TypedSize2D<f32, ScreenPx>; /// Presents the window to the screen (perhaps by page flipping). fn present(&self); @@ -137,7 +137,7 @@ pub trait WindowMethods { fn head_parsed(&self); /// Returns the scale factor of the system (device pixels / screen pixels). - fn scale_factor(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32>; + fn scale_factor(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel>; /// Gets the OS native graphics display for this window. fn native_display(&self) -> NativeDisplay; |