Skip to content

Commit

Permalink
Auto merge of #2629 - glennw:remove-overscroll, r=mrobinson
Browse files Browse the repository at this point in the history
Remove overscroll code and api.

Fixes #2545.
Fixes #1762.
Fixes #1314.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/2629)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Apr 6, 2018
2 parents fe24137 + c262d18 commit a05186d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 365 deletions.
2 changes: 0 additions & 2 deletions webrender/examples/scrolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ impl Example for App {
txn.scroll(
ScrollLocation::Delta(LayoutVector2D::new(offset.0, offset.1)),
self.cursor_position,
ScrollEventPhase::Start,
);
}
glutin::WindowEvent::CursorMoved { position: (x, y), .. } => {
Expand All @@ -181,7 +180,6 @@ impl Example for App {
txn.scroll(
ScrollLocation::Delta(LayoutVector2D::new(dx, dy)),
self.cursor_position,
ScrollEventPhase::Start,
);
}
glutin::WindowEvent::MouseInput { .. } => {
Expand Down
119 changes: 13 additions & 106 deletions webrender/src/clip_scroll_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use api::{DevicePixelScale, ExternalScrollId, LayerPixel, LayerPoint, LayerRect, LayerSize};
use api::{LayerVector2D, LayoutTransform, LayoutVector2D, PipelineId, PropertyBinding};
use api::{ScrollClamping, ScrollEventPhase, ScrollLocation, ScrollSensitivity, StickyOffsetBounds};
use api::{ScrollClamping, ScrollLocation, ScrollSensitivity, StickyOffsetBounds};
use api::WorldPoint;
use clip::{ClipChain, ClipChainNode, ClipSourcesHandle, ClipStore, ClipWorkItem};
use clip_scroll_tree::{ClipChainIndex, ClipScrollNodeIndex, CoordinateSystemId};
Expand All @@ -15,16 +15,9 @@ use gpu_cache::GpuCache;
use gpu_types::{ClipScrollNodeIndex as GPUClipScrollNodeIndex, ClipScrollNodeData};
use resource_cache::ResourceCache;
use scene::SceneProperties;
use spring::{DAMPING, STIFFNESS, Spring};
use util::{LayerToWorldFastTransform, LayerFastTransform, LayoutFastTransform};
use util::{TransformedRectKind};

#[cfg(target_os = "macos")]
const CAN_OVERSCROLL: bool = true;

#[cfg(not(target_os = "macos"))]
const CAN_OVERSCROLL: bool = false;

#[derive(Debug)]
pub struct StickyFrameInfo {
pub margins: SideOffsets2D<Option<f32>>,
Expand Down Expand Up @@ -269,8 +262,6 @@ impl ClipScrollNode {
}

scrolling.offset = new_offset;
scrolling.bouncing_back = false;
scrolling.started_bouncing_back = false;
true
}

Expand Down Expand Up @@ -666,17 +657,13 @@ impl ClipScrollNode {
}


pub fn scroll(&mut self, scroll_location: ScrollLocation, phase: ScrollEventPhase) -> bool {
pub fn scroll(&mut self, scroll_location: ScrollLocation) -> bool {
let scrolling = match self.node_type {
NodeType::ScrollFrame(ref mut scrolling) => scrolling,
_ => return false,
};

if scrolling.started_bouncing_back && phase == ScrollEventPhase::Move(false) {
return false;
}

let mut delta = match scroll_location {
let delta = match scroll_location {
ScrollLocation::Delta(delta) => delta,
ScrollLocation::Start => {
if scrolling.offset.y.round() >= 0.0 {
Expand All @@ -699,56 +686,25 @@ impl ClipScrollNode {
}
};

let overscroll_amount = scrolling.overscroll_amount();
let overscrolling = CAN_OVERSCROLL && (overscroll_amount != LayerVector2D::zero());
if overscrolling {
if overscroll_amount.x != 0.0 {
delta.x /= overscroll_amount.x.abs()
}
if overscroll_amount.y != 0.0 {
delta.y /= overscroll_amount.y.abs()
}
}

let scrollable_width = scrolling.scrollable_size.width;
let scrollable_height = scrolling.scrollable_size.height;
let is_unscrollable = scrollable_width <= 0. && scrollable_height <= 0.;
let original_layer_scroll_offset = scrolling.offset;

if scrollable_width > 0. {
scrolling.offset.x = scrolling.offset.x + delta.x;
if is_unscrollable || !CAN_OVERSCROLL {
scrolling.offset.x = scrolling.offset.x.min(0.0).max(-scrollable_width).round();
}
scrolling.offset.x = (scrolling.offset.x + delta.x)
.min(0.0)
.max(-scrollable_width)
.round();
}

if scrollable_height > 0. {
scrolling.offset.y = scrolling.offset.y + delta.y;
if is_unscrollable || !CAN_OVERSCROLL {
scrolling.offset.y = scrolling.offset.y.min(0.0).max(-scrollable_height).round();
}
scrolling.offset.y = (scrolling.offset.y + delta.y)
.min(0.0)
.max(-scrollable_height)
.round();
}

if phase == ScrollEventPhase::Start || phase == ScrollEventPhase::Move(true) {
scrolling.started_bouncing_back = false
} else if overscrolling &&
((delta.x < 1.0 && delta.y < 1.0) || phase == ScrollEventPhase::End)
{
scrolling.started_bouncing_back = true;
scrolling.bouncing_back = true
}

if CAN_OVERSCROLL {
scrolling.stretch_overscroll_spring(overscroll_amount);
}

scrolling.offset != original_layer_scroll_offset || scrolling.started_bouncing_back
}

pub fn tick_scrolling_bounce_animation(&mut self) {
if let NodeType::ScrollFrame(ref mut scrolling) = self.node_type {
scrolling.tick_scrolling_bounce_animation();
}
scrolling.offset != original_layer_scroll_offset
}

pub fn ray_intersects_node(&self, cursor: &WorldPoint) -> bool {
Expand Down Expand Up @@ -781,13 +737,6 @@ impl ClipScrollNode {
}
}

pub fn is_overscrolling(&self) -> bool {
match self.node_type {
NodeType::ScrollFrame(ref state) => state.overscroll_amount() != LayerVector2D::zero(),
_ => false,
}
}

pub fn matches_external_id(&self, external_id: ExternalScrollId) -> bool {
match self.node_type {
NodeType::ScrollFrame(info) if info.external_id == Some(external_id) => true,
Expand All @@ -799,10 +748,6 @@ impl ClipScrollNode {
#[derive(Copy, Clone, Debug)]
pub struct ScrollFrameInfo {
pub offset: LayerVector2D,
pub spring: Spring,
pub started_bouncing_back: bool,
pub bouncing_back: bool,
pub should_handoff_scroll: bool,
pub scroll_sensitivity: ScrollSensitivity,

/// Amount that this ScrollFrame can scroll in both directions.
Expand All @@ -815,7 +760,7 @@ pub struct ScrollFrameInfo {

}

/// Manages scrolling offset, overscroll state, etc.
/// Manages scrolling offset.
impl ScrollFrameInfo {
pub fn new(
scroll_sensitivity: ScrollSensitivity,
Expand All @@ -824,10 +769,6 @@ impl ScrollFrameInfo {
) -> ScrollFrameInfo {
ScrollFrameInfo {
offset: LayerVector2D::zero(),
spring: Spring::at(LayerPoint::zero(), STIFFNESS, DAMPING),
started_bouncing_back: false,
bouncing_back: false,
should_handoff_scroll: false,
scroll_sensitivity,
scrollable_size,
external_id,
Expand All @@ -840,40 +781,6 @@ impl ScrollFrameInfo {
ScrollSensitivity::Script => false,
}
}

pub fn stretch_overscroll_spring(&mut self, overscroll_amount: LayerVector2D) {
let offset = self.offset.to_point();
self.spring
.coords(offset, offset, offset + overscroll_amount);
}

pub fn tick_scrolling_bounce_animation(&mut self) {
let finished = self.spring.animate();
self.offset = self.spring.current().to_vector();
if finished {
self.bouncing_back = false
}
}

pub fn overscroll_amount(&self) -> LayerVector2D {
let overscroll_x = if self.offset.x > 0.0 {
-self.offset.x
} else if self.offset.x < -self.scrollable_size.width {
-self.scrollable_size.width - self.offset.x
} else {
0.0
};

let overscroll_y = if self.offset.y > 0.0 {
-self.offset.y
} else if self.offset.y < -self.scrollable_size.height {
-self.scrollable_size.height - self.offset.y
} else {
0.0
};

LayerVector2D::new(overscroll_x, overscroll_y)
}
}

/// Contains information about reference frames.
Expand Down
93 changes: 3 additions & 90 deletions webrender/src/clip_scroll_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{DeviceIntRect, DevicePixelScale, ExternalScrollId, LayerPoint, LayerRect, LayerVector2D};
use api::{PipelineId, ScrollClamping, ScrollEventPhase, ScrollLocation, ScrollNodeState};
use api::{PipelineId, ScrollClamping, ScrollLocation, ScrollNodeState};
use api::WorldPoint;
use clip::{ClipChain, ClipSourcesHandle, ClipStore};
use clip_scroll_node::{ClipScrollNode, NodeType, ScrollFrameInfo, StickyFrameInfo};
Expand Down Expand Up @@ -70,10 +70,6 @@ pub struct ClipScrollTree {

pub pending_scroll_offsets: FastHashMap<ExternalScrollId, (LayerPoint, ScrollClamping)>,

/// The ClipId of the currently scrolling node. Used to allow the same
/// node to scroll even if a touch operation leaves the boundaries of that node.
pub currently_scrolling_node_index: Option<ClipScrollNodeIndex>,

/// The current frame id, used for giving a unique id to all new dynamically
/// added frames and clips. The ClipScrollTree increments this by one every
/// time a new dynamic frame is created.
Expand Down Expand Up @@ -116,7 +112,6 @@ impl ClipScrollTree {
clip_chains_descriptors: Vec::new(),
clip_chains: vec![ClipChain::empty(&DeviceIntRect::zero())],
pending_scroll_offsets: FastHashMap::default(),
currently_scrolling_node_index: None,
current_new_node_item: 1,
pipelines_to_discard: FastHashSet::default(),
}
Expand All @@ -138,18 +133,6 @@ impl ClipScrollTree {
TOPMOST_SCROLL_NODE_INDEX
}

pub fn collect_nodes_bouncing_back(&self) -> FastHashSet<ClipScrollNodeIndex> {
let mut nodes_bouncing_back = FastHashSet::default();
for (index, node) in self.nodes.iter().enumerate() {
if let NodeType::ScrollFrame(ref scrolling) = node.node_type {
if scrolling.bouncing_back {
nodes_bouncing_back.insert(ClipScrollNodeIndex(index));
}
}
}
nodes_bouncing_back
}

fn find_scrolling_node_at_point_in_node(
&self,
cursor: &WorldPoint,
Expand Down Expand Up @@ -235,71 +218,13 @@ impl ClipScrollTree {
&mut self,
scroll_location: ScrollLocation,
cursor: WorldPoint,
phase: ScrollEventPhase,
) -> bool {
if self.nodes.is_empty() {
return false;
}

let node_index = match (
phase,
self.find_scrolling_node_at_point(&cursor),
self.currently_scrolling_node_index,
) {
(ScrollEventPhase::Start, scroll_node_at_point_index, _) => {
self.currently_scrolling_node_index = Some(scroll_node_at_point_index);
scroll_node_at_point_index
}
(_, scroll_node_at_point_index, Some(cached_node_index)) => {
match self.nodes.get(cached_node_index.0) {
Some(_) => cached_node_index,
None => {
self.currently_scrolling_node_index = Some(scroll_node_at_point_index);
scroll_node_at_point_index
}
}
}
(_, _, None) => return false,
};

let topmost_scroll_node_index = self.topmost_scroll_node_index();
let non_root_overscroll = if node_index != topmost_scroll_node_index {
self.nodes[node_index.0].is_overscrolling()
} else {
false
};

let mut switch_node = false;
{
let node = &mut self.nodes[node_index.0];
if let NodeType::ScrollFrame(ref mut scrolling) = node.node_type {
match phase {
ScrollEventPhase::Start => {
// if this is a new gesture, we do not switch node,
// however we do save the state of non_root_overscroll,
// for use in the subsequent Move phase.
scrolling.should_handoff_scroll = non_root_overscroll;
}
ScrollEventPhase::Move(_) => {
// Switch node if movement originated in a new gesture,
// from a non root node in overscroll.
switch_node = scrolling.should_handoff_scroll && non_root_overscroll
}
ScrollEventPhase::End => {
// clean-up when gesture ends.
scrolling.should_handoff_scroll = false;
}
}
}
}

let node_index = if switch_node {
topmost_scroll_node_index
} else {
node_index
};

self.nodes[node_index.0].scroll(scroll_location, phase)
let node_index = self.find_scrolling_node_at_point(&cursor);
self.nodes[node_index.0].scroll(scroll_location)
}

pub fn update_tree(
Expand Down Expand Up @@ -433,12 +358,6 @@ impl ClipScrollTree {
}
}

pub fn tick_scrolling_bounce_animations(&mut self) {
for node in &mut self.nodes {
node.tick_scrolling_bounce_animation()
}
}

pub fn finalize_and_apply_pending_scroll_offsets(&mut self, old_states: ScrollStates) {
for node in &mut self.nodes {
let external_id = match node.node_type {
Expand Down Expand Up @@ -529,12 +448,6 @@ impl ClipScrollTree {

pub fn discard_frame_state_for_pipeline(&mut self, pipeline_id: PipelineId) {
self.pipelines_to_discard.insert(pipeline_id);

if let Some(index) = self.currently_scrolling_node_index {
if self.nodes[index.0].pipeline_id == pipeline_id {
self.currently_scrolling_node_index = None;
}
}
}

fn print_node<T: PrintTreePrinter>(
Expand Down
5 changes: 0 additions & 5 deletions webrender/src/internal_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use api::{DebugCommand, DeviceUintRect, DocumentId, ExternalImageData, ExternalImageId};
use api::ImageFormat;
use clip_scroll_tree::ClipScrollNodeIndex;
use device::TextureFilter;
use renderer::PipelineInfo;
use gpu_cache::GpuCacheUpdateList;
Expand Down Expand Up @@ -138,21 +137,17 @@ pub struct RenderedDocument {
/// been rendered, which is necessary for reftests.
/// - Pipelines that were removed from the scene.
pub pipeline_info: PipelineInfo,
/// The layers that are currently affected by the over-scrolling animation.
pub layers_bouncing_back: FastHashSet<ClipScrollNodeIndex>,

pub frame: tiling::Frame,
}

impl RenderedDocument {
pub fn new(
pipeline_info: PipelineInfo,
layers_bouncing_back: FastHashSet<ClipScrollNodeIndex>,
frame: tiling::Frame,
) -> Self {
RenderedDocument {
pipeline_info,
layers_bouncing_back,
frame,
}
}
Expand Down
Loading

0 comments on commit a05186d

Please sign in to comment.