Skip to content

Commit 3a6725a

Browse files
author
bors-servo
authored
Auto merge of #540 - samuknet:home-end-key-scroll2, r=glennw
Implement Home end key scroll Addressing issue servo/servo#13082. Supporting servo/servo#14141. * Adds `ScrollLocation` type in `webrender_traits`. * Refactor api to use new `ScrollLocation` * Implement home/end scrolling in `webrender/src/frame.rs` `fn scroll(...)` using new `ScrollLocation` struct passed in. <!-- 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/540) <!-- Reviewable:end -->
2 parents 3be3018 + fa805af commit 3a6725a

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

webrender/src/frame.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use tiling::{AuxiliaryListsMap, FrameBuilder, FrameBuilderConfig, LayerMap, Prim
1919
use util::MatrixHelpers;
2020
use webrender_traits::{AuxiliaryLists, PipelineId, Epoch, ScrollPolicy, ScrollLayerId};
2121
use webrender_traits::{ClipRegion, ColorF, DisplayItem, StackingContext, FilterOp, MixBlendMode};
22-
use webrender_traits::{ScrollEventPhase, ScrollLayerInfo, SpecificDisplayItem, ScrollLayerState};
22+
use webrender_traits::{ScrollEventPhase, ScrollLayerInfo, ScrollLocation, SpecificDisplayItem, ScrollLayerState};
2323
use webrender_traits::{LayerRect, LayerPoint, LayerSize};
2424
use webrender_traits::{ServoScrollRootId, ScrollLayerRect, as_scroll_parent_rect, ScrollLayerPixel};
2525
use webrender_traits::WorldPoint4D;
@@ -329,7 +329,7 @@ impl Frame {
329329

330330
/// Returns true if any layers actually changed position or false otherwise.
331331
pub fn scroll(&mut self,
332-
mut delta: Point2D<f32>,
332+
scroll_location: ScrollLocation,
333333
cursor: Point2D<f32>,
334334
phase: ScrollEventPhase)
335335
-> bool {
@@ -364,6 +364,33 @@ impl Frame {
364364
continue;
365365
}
366366

367+
let mut delta = match scroll_location {
368+
ScrollLocation::Delta(delta) => delta,
369+
ScrollLocation::Start => {
370+
if layer.scrolling.offset.y.round() <= 0.0 {
371+
// Nothing to do on this layer.
372+
continue;
373+
}
374+
375+
layer.scrolling.offset.y = 0.0;
376+
scrolled_a_layer = true;
377+
continue;
378+
},
379+
ScrollLocation::End => {
380+
let end_pos = layer.local_viewport_rect.size.height
381+
- layer.content_size.height;
382+
383+
if layer.scrolling.offset.y.round() >= end_pos {
384+
// Nothing to do on this layer.
385+
continue;
386+
}
387+
388+
layer.scrolling.offset.y = end_pos;
389+
scrolled_a_layer = true;
390+
continue;
391+
}
392+
};
393+
367394
let overscroll_amount = layer.overscroll_amount();
368395
let overscrolling = CAN_OVERSCROLL && (overscroll_amount.width != 0.0 ||
369396
overscroll_amount.height != 0.0);

webrender_traits/src/api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use offscreen_gl_context::{GLContextAttributes, GLLimits};
99
use std::cell::Cell;
1010
use {ApiMsg, ColorF, DisplayListBuilder, Epoch};
1111
use {FontKey, IdNamespace, ImageFormat, ImageKey, NativeFontHandle, PipelineId};
12-
use {RenderApiSender, ResourceId, ScrollEventPhase, ScrollLayerState, ServoScrollRootId};
12+
use {RenderApiSender, ResourceId, ScrollEventPhase, ScrollLayerState, ScrollLocation, ServoScrollRootId};
1313
use {GlyphKey, GlyphDimensions, ImageData, WebGLContextId, WebGLCommand};
1414

1515
impl RenderApiSender {
@@ -188,8 +188,8 @@ impl RenderApi {
188188
///
189189
/// Webrender looks for the layer closest to the user
190190
/// which has `ScrollPolicy::Scrollable` set.
191-
pub fn scroll(&self, delta: Point2D<f32>, cursor: Point2D<f32>, phase: ScrollEventPhase) {
192-
let msg = ApiMsg::Scroll(delta, cursor, phase);
191+
pub fn scroll(&self, scroll_location: ScrollLocation, cursor: Point2D<f32>, phase: ScrollEventPhase) {
192+
let msg = ApiMsg::Scroll(scroll_location, cursor, phase);
193193
self.api_sender.send(msg).unwrap();
194194
}
195195

webrender_traits/src/types.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub enum ApiMsg {
4848
BuiltDisplayListDescriptor,
4949
AuxiliaryListsDescriptor),
5050
SetRootPipeline(PipelineId),
51-
Scroll(Point2D<f32>, Point2D<f32>, ScrollEventPhase),
51+
Scroll(ScrollLocation, Point2D<f32>, ScrollEventPhase),
5252
ScrollLayersWithScrollId(Point2D<f32>, PipelineId, ServoScrollRootId),
5353
TickScrollingBounce,
5454
TranslatePointToLayerSpace(Point2D<f32>, MsgSender<(Point2D<f32>, PipelineId)>),
@@ -491,6 +491,16 @@ pub enum ScrollPolicy {
491491
Fixed,
492492
}
493493

494+
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
495+
pub enum ScrollLocation {
496+
/// Scroll by a certain amount.
497+
Delta(Point2D<f32>),
498+
/// Scroll to very top of element.
499+
Start,
500+
/// Scroll to very bottom of element.
501+
End
502+
}
503+
494504
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
495505
pub struct ServoScrollRootId(pub usize);
496506

0 commit comments

Comments
 (0)