Skip to content

Implement Home end key scroll #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions webrender/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -331,7 +331,7 @@ impl Frame {

/// Returns true if any layers actually changed position or false otherwise.
pub fn scroll(&mut self,
mut delta: Point2D<f32>,
scroll_location: ScrollLocation,
cursor: Point2D<f32>,
phase: ScrollEventPhase)
-> bool {
Expand Down Expand Up @@ -366,6 +366,33 @@ impl Frame {
continue;
}

let mut delta = match scroll_location {
ScrollLocation::Delta(delta) => delta,
ScrollLocation::Start => {
if layer.scrolling.offset.y.round() <= 0.0 {
// Nothing to do on this layer.
continue;
}

layer.scrolling.offset.y = 0.0;
scrolled_a_layer = true;
continue;
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comma here and in the section below aren't necessary.

ScrollLocation::End => {
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.
continue;
}

layer.scrolling.offset.y = end_pos;
scrolled_a_layer = true;
continue;
}
};

let overscroll_amount = layer.overscroll_amount();
let overscrolling = CAN_OVERSCROLL && (overscroll_amount.width != 0.0 ||
overscroll_amount.height != 0.0);
Expand Down
6 changes: 3 additions & 3 deletions webrender_traits/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<f32>, cursor: Point2D<f32>, phase: ScrollEventPhase) {
let msg = ApiMsg::Scroll(delta, cursor, phase);
pub fn scroll(&self, scroll_location: ScrollLocation, cursor: Point2D<f32>, phase: ScrollEventPhase) {
let msg = ApiMsg::Scroll(scroll_location, cursor, phase);
self.api_sender.send(msg).unwrap();
}

Expand Down
12 changes: 11 additions & 1 deletion webrender_traits/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum ApiMsg {
BuiltDisplayListDescriptor,
AuxiliaryListsDescriptor),
SetRootPipeline(PipelineId),
Scroll(Point2D<f32>, Point2D<f32>, ScrollEventPhase),
Scroll(ScrollLocation, Point2D<f32>, ScrollEventPhase),
ScrollLayersWithScrollId(Point2D<f32>, PipelineId, ServoScrollRootId),
TickScrollingBounce,
TranslatePointToLayerSpace(Point2D<f32>, MsgSender<(Point2D<f32>, PipelineId)>),
Expand Down Expand Up @@ -492,6 +492,16 @@ pub enum ScrollPolicy {
Fixed,
}

#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum ScrollLocation {
/// Scroll by a certain amount.
Delta(Point2D<f32>),
/// Scroll to very top of element.
Start,
/// Scroll to very bottom of element.
End
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct ServoScrollRootId(pub usize);

Expand Down