diff options
author | Martin Robinson <mrobinson@igalia.com> | 2014-09-23 16:38:52 -0700 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2014-09-25 07:57:46 -0700 |
commit | e01c5cd8637c32b1bdf9c80f776278eab3feae0b (patch) | |
tree | 01907d10f9b660531d80c0ef5b6741113a43b0c7 | |
parent | 80433f7ea0bfb3fe0963de87bea5ad60a5c3ea75 (diff) | |
download | servo-e01c5cd8637c32b1bdf9c80f776278eab3feae0b.tar.gz servo-e01c5cd8637c32b1bdf9c80f776278eab3feae0b.zip |
Differentiate clearly how child layers handle scroll events
This allows the scroll handler to know if a child layer didn't handle
an event or the scroll position of the child layer was simply unchanged.
-rw-r--r-- | components/compositing/compositor.rs | 3 | ||||
-rw-r--r-- | components/compositing/events.rs | 38 |
2 files changed, 28 insertions, 13 deletions
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index e752bc37a84..cd8830f1c9d 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -9,6 +9,7 @@ use compositor_task::{SetLayerOrigin, Paint, ScrollFragmentPoint, LoadComplete}; use compositor_task::{ShutdownComplete, ChangeRenderState, RenderMsgDiscarded}; use constellation::SendableFrameTree; use events; +use events::ScrollPositionChanged; use pipeline::CompositionPipeline; use platform::{Application, Window}; use windowing; @@ -766,7 +767,7 @@ impl IOCompositor { delta, cursor.as_f32(), window_size, - scene_scale) || scroll; + scene_scale) == ScrollPositionChanged; } None => { } } diff --git a/components/compositing/events.rs b/components/compositing/events.rs index 0c9136d9936..ee1ba2231d4 100644 --- a/components/compositing/events.rs +++ b/components/compositing/events.rs @@ -39,6 +39,13 @@ impl Clampable for f32 { } } +#[deriving(PartialEq)] +pub enum ScrollEventResult { + ScrollEventUnhandled, + ScrollPositionChanged, + ScrollPositionUnchanged, +} + /// Move the layer's descendants that don't want scroll events and scroll by a relative /// specified amount in page coordinates. This also takes in a cursor position to see if the /// mouse is over child layers first. If a layer successfully scrolled, returns true; otherwise @@ -48,11 +55,11 @@ pub fn handle_scroll_event(layer: Rc<Layer<CompositorData>>, cursor: TypedPoint2D<DevicePixel, f32>, window_size: TypedSize2D<DevicePixel, f32>, scale: ScaleFactor<PagePx, DevicePixel, f32>) - -> bool { + -> ScrollEventResult { // If this layer doesn't want scroll events, neither it nor its children can handle scroll // events. if layer.extra_data.borrow().wants_scroll_events != WantsScrollEvents { - return false + return ScrollEventUnhandled; } // Allow children to scroll. @@ -61,13 +68,15 @@ pub fn handle_scroll_event(layer: Rc<Layer<CompositorData>>, let new_cursor = cursor - scroll_offset_in_device_pixels; for child in layer.children().iter() { let child_bounds = child.bounds.borrow(); - if child_bounds.contains(&new_cursor) && - handle_scroll_event(child.clone(), - delta, - new_cursor - child_bounds.origin, - child_bounds.size, - scale) { - return true + if child_bounds.contains(&new_cursor) { + let result = handle_scroll_event(child.clone(), + delta, + new_cursor - child_bounds.origin, + child_bounds.size, + scale); + if result != ScrollEventUnhandled { + return result; + } } } @@ -81,7 +90,7 @@ pub fn clamp_scroll_offset_and_scroll_layer(layer: Rc<Layer<CompositorData>>, new_offset: TypedPoint2D<DevicePixel, f32>, window_size: TypedSize2D<DevicePixel, f32>, scale: ScaleFactor<PagePx, DevicePixel, f32>) - -> bool { + -> ScrollEventResult { let layer_size = layer.bounds.borrow().size; let min_x = (window_size.width - layer_size.width).get().min(0.0); let min_y = (window_size.height - layer_size.height).get().min(0.0); @@ -91,7 +100,7 @@ pub fn clamp_scroll_offset_and_scroll_layer(layer: Rc<Layer<CompositorData>>, let new_offset_in_page_px = new_offset / scale; if layer.extra_data.borrow().scroll_offset == new_offset_in_page_px { - return false + return ScrollPositionUnchanged; } // The scroll offset is just a record of the scroll position of this scrolling root, @@ -102,7 +111,12 @@ pub fn clamp_scroll_offset_and_scroll_layer(layer: Rc<Layer<CompositorData>>, for child in layer.children().iter() { result |= scroll_layer_and_all_child_layers(child.clone(), new_offset_in_page_px); } - return result; + + if result { + return ScrollPositionChanged; + } else { + return ScrollPositionUnchanged; + } } fn scroll_layer_and_all_child_layers(layer: Rc<Layer<CompositorData>>, |