From 22aefa1b9daa4ae0b8e8d161d9d0173bb2117c9b Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 17 Nov 2016 13:24:33 +0000 Subject: [PATCH 1/6] Resolve imports conflict. --- webrender/src/frame.rs | 36 +++++++++++++++++++++++++++++++++-- webrender_traits/src/types.rs | 8 +++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/webrender/src/frame.rs b/webrender/src/frame.rs index d605f87a29..5ee99cf094 100644 --- a/webrender/src/frame.rs +++ b/webrender/src/frame.rs @@ -19,7 +19,7 @@ use tiling::{AuxiliaryListsMap, FrameBuilder, FrameBuilderConfig, PrimitiveFlags use util::MatrixHelpers; use webrender_traits::{AuxiliaryLists, PipelineId, Epoch, ScrollPolicy, ScrollLayerId}; use webrender_traits::{ClipRegion, ColorF, DisplayItem, StackingContext, FilterOp, MixBlendMode}; -use webrender_traits::{ScrollEventPhase, ScrollLayerInfo, SpecificDisplayItem, ScrollLayerState}; +use webrender_traits::{ScrollEventPhase, ScrollLayerInfo, ScrollLocation, SpecificDisplayItem, ScrollLayerState}; use webrender_traits::{LayerRect, LayerPoint, LayerSize}; use webrender_traits::{ServoScrollRootId, ScrollLayerRect, as_scroll_parent_rect, ScrollLayerPixel}; use webrender_traits::WorldPoint4D; @@ -331,10 +331,11 @@ impl Frame { /// Returns true if any layers actually changed position or false otherwise. pub fn scroll(&mut self, - mut delta: Point2D, + scroll_location: ScrollLocation, cursor: Point2D, phase: ScrollEventPhase) -> bool { + let root_scroll_layer_id = match self.root_scroll_layer_id { Some(root_scroll_layer_id) => root_scroll_layer_id, None => return false, @@ -350,6 +351,37 @@ impl Frame { ScrollLayerInfo::Fixed => unreachable!("Tried to scroll a fixed position layer."), }; + let mut delta:Point2D = match scroll_location { + ScrollLocation::Delta(delta) => delta, + ScrollLocation::Start => { + if layer.scrolling.offset.y.round() == 0.0 { + // Nothing to do. + return false; + } + + layer.scrolling.offset.y = 0.0; + return true; + }, + ScrollLocation::End => { + let end_pos = -layer.content_size.height + + (layer.local_viewport_rect.size.height); + + if layer.scrolling.offset.y.round() == end_pos { + // Nothing to do. + return false; + } + + layer.scrolling.offset.y = end_pos; + return true; + }, + }; + + let overscroll_amount = layer.overscroll_amount(); + let overscrolling = CAN_OVERSCROLL && (overscroll_amount.width != 0.0 || + overscroll_amount.height != 0.0); + if overscrolling { + if overscroll_amount.width != 0.0 { + delta.x /= overscroll_amount.width.abs() let mut scrolled_a_layer = false; for (layer_id, layer) in self.layers.iter_mut() { if layer_id.pipeline_id != scroll_layer_id.pipeline_id { diff --git a/webrender_traits/src/types.rs b/webrender_traits/src/types.rs index 7db1883e74..320dce9f11 100644 --- a/webrender_traits/src/types.rs +++ b/webrender_traits/src/types.rs @@ -48,7 +48,6 @@ pub enum ApiMsg { BuiltDisplayListDescriptor, AuxiliaryListsDescriptor), SetRootPipeline(PipelineId), - Scroll(Point2D, Point2D, ScrollEventPhase), ScrollLayersWithScrollId(Point2D, PipelineId, ServoScrollRootId), TickScrollingBounce, TranslatePointToLayerSpace(Point2D, MsgSender<(Point2D, PipelineId)>), @@ -492,6 +491,13 @@ pub enum ScrollPolicy { Fixed, } +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum ScrollLocation { + Delta(Point2D), // Scroll by a certain amount. + Start, // Scroll to very top of element. + End // Scroll to very bottom of element. +} + #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] pub struct ServoScrollRootId(pub usize); From efdaeb1c18aea2be3172aea2af309298b2f54402 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 8 Nov 2016 18:01:33 +0000 Subject: [PATCH 2/6] Implement home end key scrolling support. --- webrender/src/frame.rs | 61 ++++++++++++++++++------------------- webrender_traits/src/api.rs | 6 ++-- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/webrender/src/frame.rs b/webrender/src/frame.rs index 5ee99cf094..5b77e180c6 100644 --- a/webrender/src/frame.rs +++ b/webrender/src/frame.rs @@ -19,11 +19,15 @@ use tiling::{AuxiliaryListsMap, FrameBuilder, FrameBuilderConfig, PrimitiveFlags use util::MatrixHelpers; use webrender_traits::{AuxiliaryLists, PipelineId, Epoch, ScrollPolicy, ScrollLayerId}; use webrender_traits::{ClipRegion, ColorF, DisplayItem, StackingContext, FilterOp, MixBlendMode}; +<<<<<<< 22aefa1b9daa4ae0b8e8d161d9d0173bb2117c9b use webrender_traits::{ScrollEventPhase, ScrollLayerInfo, ScrollLocation, SpecificDisplayItem, ScrollLayerState}; use webrender_traits::{LayerRect, LayerPoint, LayerSize}; use webrender_traits::{ServoScrollRootId, ScrollLayerRect, as_scroll_parent_rect, ScrollLayerPixel}; use webrender_traits::WorldPoint4D; use webrender_traits::{LayerTransform, LayerToScrollTransform, ScrollToWorldTransform}; +======= +use webrender_traits::{ScrollEventPhase, ScrollLayerInfo, SpecificDisplayItem, ScrollLayerState, ScrollLocation}; +>>>>>>> Implement home end key scrolling support. #[cfg(target_os = "macos")] const CAN_OVERSCROLL: bool = true; @@ -335,7 +339,6 @@ impl Frame { cursor: Point2D, phase: ScrollEventPhase) -> bool { - let root_scroll_layer_id = match self.root_scroll_layer_id { Some(root_scroll_layer_id) => root_scroll_layer_id, None => return false, @@ -351,37 +354,6 @@ impl Frame { ScrollLayerInfo::Fixed => unreachable!("Tried to scroll a fixed position layer."), }; - let mut delta:Point2D = match scroll_location { - ScrollLocation::Delta(delta) => delta, - ScrollLocation::Start => { - if layer.scrolling.offset.y.round() == 0.0 { - // Nothing to do. - return false; - } - - layer.scrolling.offset.y = 0.0; - return true; - }, - ScrollLocation::End => { - let end_pos = -layer.content_size.height + - (layer.local_viewport_rect.size.height); - - if layer.scrolling.offset.y.round() == end_pos { - // Nothing to do. - return false; - } - - layer.scrolling.offset.y = end_pos; - return true; - }, - }; - - let overscroll_amount = layer.overscroll_amount(); - let overscrolling = CAN_OVERSCROLL && (overscroll_amount.width != 0.0 || - overscroll_amount.height != 0.0); - if overscrolling { - if overscroll_amount.width != 0.0 { - delta.x /= overscroll_amount.width.abs() let mut scrolled_a_layer = false; for (layer_id, layer) in self.layers.iter_mut() { if layer_id.pipeline_id != scroll_layer_id.pipeline_id { @@ -398,6 +370,31 @@ impl Frame { continue; } + let mut delta:Point2D = match scroll_location { + ScrollLocation::Delta(delta) => delta, + ScrollLocation::Start => { + if layer.scrolling.offset.y.round() == 0.0 { + // Nothing to do. + return false; + } + + layer.scrolling.offset.y = 0.0; + return true; + }, + ScrollLocation::End => { + let end_pos = -layer.content_size.height + + layer.local_viewport_rect.size.height; + + if layer.scrolling.offset.y.round() == end_pos { + // Nothing to do. + return false; + } + + layer.scrolling.offset.y = end_pos; + return true; + }, + }; + let overscroll_amount = layer.overscroll_amount(); let overscrolling = CAN_OVERSCROLL && (overscroll_amount.width != 0.0 || overscroll_amount.height != 0.0); diff --git a/webrender_traits/src/api.rs b/webrender_traits/src/api.rs index 79f89ae75b..0168c94b5f 100644 --- a/webrender_traits/src/api.rs +++ b/webrender_traits/src/api.rs @@ -9,7 +9,7 @@ use offscreen_gl_context::{GLContextAttributes, GLLimits}; use std::cell::Cell; use {ApiMsg, ColorF, DisplayListBuilder, Epoch}; use {FontKey, IdNamespace, ImageFormat, ImageKey, NativeFontHandle, PipelineId}; -use {RenderApiSender, ResourceId, ScrollEventPhase, ScrollLayerState, ServoScrollRootId}; +use {RenderApiSender, ResourceId, ScrollEventPhase, ScrollLayerState, ScrollLocation, ServoScrollRootId}; use {GlyphKey, GlyphDimensions, ImageData, WebGLContextId, WebGLCommand}; impl RenderApiSender { @@ -188,8 +188,8 @@ impl RenderApi { /// /// Webrender looks for the layer closest to the user /// which has `ScrollPolicy::Scrollable` set. - pub fn scroll(&self, delta: Point2D, cursor: Point2D, phase: ScrollEventPhase) { - let msg = ApiMsg::Scroll(delta, cursor, phase); + pub fn scroll(&self, scroll_location: ScrollLocation, cursor: Point2D, phase: ScrollEventPhase) { + let msg = ApiMsg::Scroll(scroll_location, cursor, phase); self.api_sender.send(msg).unwrap(); } From 2d0c213be58a21813774393af3f11e3504a5abc0 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 11 Nov 2016 18:43:52 +0000 Subject: [PATCH 3/6] Fix indentation. --- webrender/src/frame.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/webrender/src/frame.rs b/webrender/src/frame.rs index 5b77e180c6..9a84182062 100644 --- a/webrender/src/frame.rs +++ b/webrender/src/frame.rs @@ -19,15 +19,11 @@ use tiling::{AuxiliaryListsMap, FrameBuilder, FrameBuilderConfig, PrimitiveFlags use util::MatrixHelpers; use webrender_traits::{AuxiliaryLists, PipelineId, Epoch, ScrollPolicy, ScrollLayerId}; use webrender_traits::{ClipRegion, ColorF, DisplayItem, StackingContext, FilterOp, MixBlendMode}; -<<<<<<< 22aefa1b9daa4ae0b8e8d161d9d0173bb2117c9b use webrender_traits::{ScrollEventPhase, ScrollLayerInfo, ScrollLocation, SpecificDisplayItem, ScrollLayerState}; use webrender_traits::{LayerRect, LayerPoint, LayerSize}; use webrender_traits::{ServoScrollRootId, ScrollLayerRect, as_scroll_parent_rect, ScrollLayerPixel}; use webrender_traits::WorldPoint4D; use webrender_traits::{LayerTransform, LayerToScrollTransform, ScrollToWorldTransform}; -======= -use webrender_traits::{ScrollEventPhase, ScrollLayerInfo, SpecificDisplayItem, ScrollLayerState, ScrollLocation}; ->>>>>>> Implement home end key scrolling support. #[cfg(target_os = "macos")] const CAN_OVERSCROLL: bool = true; @@ -302,6 +298,7 @@ impl Frame { } /// Returns true if any layers actually changed position or false otherwise. +<<<<<<< efdaeb1c18aea2be3172aea2af309298b2f54402 pub fn scroll_layers(&mut self, origin: Point2D, pipeline_id: PipelineId, From 651315134e6cd650f1eb88839252ea0d09db9362 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 17 Nov 2016 13:57:32 +0000 Subject: [PATCH 4/6] Add types ScrollLocation documentation. Insert continue in layers loop instead of early return. --- webrender/src/frame.rs | 20 +++++++++++--------- webrender_traits/src/types.rs | 9 ++++++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/webrender/src/frame.rs b/webrender/src/frame.rs index 9a84182062..d91a80b750 100644 --- a/webrender/src/frame.rs +++ b/webrender/src/frame.rs @@ -367,28 +367,30 @@ impl Frame { continue; } - let mut delta:Point2D = match scroll_location { + let mut delta = match scroll_location { ScrollLocation::Delta(delta) => delta, ScrollLocation::Start => { - if layer.scrolling.offset.y.round() == 0.0 { - // Nothing to do. - return false; + if layer.scrolling.offset.y.round() <= 0.0 { + // Nothing to do on this layer. + continue; } layer.scrolling.offset.y = 0.0; - return true; + scrolled_a_layer = true; + continue; }, ScrollLocation::End => { let end_pos = -layer.content_size.height + layer.local_viewport_rect.size.height; - if layer.scrolling.offset.y.round() == end_pos { - // Nothing to do. - return false; + if layer.scrolling.offset.y.round() >= end_pos { + // Nothing to do on this layer. + continue; } layer.scrolling.offset.y = end_pos; - return true; + scrolled_a_layer = true; + continue; }, }; diff --git a/webrender_traits/src/types.rs b/webrender_traits/src/types.rs index 320dce9f11..2a5551511a 100644 --- a/webrender_traits/src/types.rs +++ b/webrender_traits/src/types.rs @@ -493,9 +493,12 @@ pub enum ScrollPolicy { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum ScrollLocation { - Delta(Point2D), // Scroll by a certain amount. - Start, // Scroll to very top of element. - End // Scroll to very bottom of element. + /// Scroll by a certain amount. + Delta(Point2D), + /// Scroll to very top of element. + Start, + /// Scroll to very bottom of element. + End } #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] From 0ee01f37ef4aec747ccf1fd0907620adefc9f4e9 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Nov 2016 09:11:13 +0000 Subject: [PATCH 5/6] Fix nits, reordered calc, fixed indentation --- webrender/src/frame.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webrender/src/frame.rs b/webrender/src/frame.rs index d91a80b750..37caed162c 100644 --- a/webrender/src/frame.rs +++ b/webrender/src/frame.rs @@ -380,8 +380,8 @@ impl Frame { continue; }, ScrollLocation::End => { - let end_pos = -layer.content_size.height + - layer.local_viewport_rect.size.height; + let end_pos = layer.local_viewport_rect.size.height + - layer.content_size.height; if layer.scrolling.offset.y.round() >= end_pos { // Nothing to do on this layer. @@ -391,7 +391,7 @@ impl Frame { layer.scrolling.offset.y = end_pos; scrolled_a_layer = true; continue; - }, + } }; let overscroll_amount = layer.overscroll_amount(); From fa805afdb9735b5815eb0633555ba1f1c14105c0 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Nov 2016 09:41:46 +0000 Subject: [PATCH 6/6] Add Scroll ApiMsg --- webrender/src/frame.rs | 1 - webrender_traits/src/types.rs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/webrender/src/frame.rs b/webrender/src/frame.rs index 37caed162c..18f62a70db 100644 --- a/webrender/src/frame.rs +++ b/webrender/src/frame.rs @@ -298,7 +298,6 @@ impl Frame { } /// Returns true if any layers actually changed position or false otherwise. -<<<<<<< efdaeb1c18aea2be3172aea2af309298b2f54402 pub fn scroll_layers(&mut self, origin: Point2D, pipeline_id: PipelineId, diff --git a/webrender_traits/src/types.rs b/webrender_traits/src/types.rs index 2a5551511a..79fda1cfb2 100644 --- a/webrender_traits/src/types.rs +++ b/webrender_traits/src/types.rs @@ -48,6 +48,7 @@ pub enum ApiMsg { BuiltDisplayListDescriptor, AuxiliaryListsDescriptor), SetRootPipeline(PipelineId), + Scroll(ScrollLocation, Point2D, ScrollEventPhase), ScrollLayersWithScrollId(Point2D, PipelineId, ServoScrollRootId), TickScrollingBounce, TranslatePointToLayerSpace(Point2D, MsgSender<(Point2D, PipelineId)>),