Skip to content

Conversation

mrobinson
Copy link
Member

@mrobinson mrobinson commented Nov 23, 2016

This will allow Servo to reimplement scroll_to_fragment.


This change is Reviewable

@mrobinson
Copy link
Member Author

@glennw r?

}

found_layer = true;
scrolled_a_layer = layer.set_scroll_origin(&origin);
Copy link
Member

@emilio emilio Nov 23, 2016

Choose a reason for hiding this comment

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

probably you want this to be scrolled_a_layer |= layer.set_scroll_origin(&origin), right?

Otherwise (if we can just scroll one layer) we might as well break from the loop when that happens.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! I will fix this.

In practice this doesn't cause a problem because all layers with the same ScrollRootId should be be in sync. On the other hand, it is good to write resilient code, which is what I tried to do here, but failed.


if !found_layer {
let scroll_offsets =
self.pending_scroll_offsets.entry(pipeline_id).or_insert(HashMap::new());
Copy link
Member

Choose a reason for hiding this comment

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

nit: or_insert_with(HashMap::new) doesn't call HashMap::new() unconditionally, though I don't know if that allocates so it could be meaningless.

Copy link
Member Author

Choose a reason for hiding this comment

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

or_insert_with is much better here. Thanks!

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -52,6 +52,7 @@ pub struct Frame {
AuxiliaryLists,
BuildHasherDefault<FnvHasher>>,
pub root_scroll_layer_id: Option<ScrollLayerId>,
pending_scroll_offsets: HashMap<PipelineId, HashMap<ServoScrollRootId, LayerPoint>>,
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't it be more efficient to have a single HashMap<(PipelineId, ServoScrollRootId), LayerPoint>?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that is much nicer!

@@ -86,6 +86,26 @@ impl Layer {
LayerSize::new(overscroll_x, overscroll_y)
}

pub fn set_scroll_origin(&mut self, origin: &LayerPoint) -> bool{
Copy link
Member

Choose a reason for hiding this comment

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

nit: space missing before {

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay. Will fix.

@glennw
Copy link
Member

glennw commented Nov 25, 2016

Looks good once @kvark's comments are addressed.

This will allow Servo to reimplement scroll_to_fragment.
@mrobinson
Copy link
Member Author

@bors-servo r=glennw

Thanks everyone for the reviews!

@bors-servo
Copy link
Contributor

📌 Commit c33d8e4 has been approved by glennw

@bors-servo
Copy link
Contributor

⚡ Test exempted - status

@bors-servo bors-servo merged commit c33d8e4 into servo:master Nov 25, 2016
bors-servo pushed a commit that referenced this pull request Nov 25, 2016
Add API for scrolling individual layers

This will allow Servo to reimplement scroll_to_fragment.

<!-- 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/590)
<!-- Reviewable:end -->
@mrobinson mrobinson deleted the scroll-to-fragment branch February 6, 2017 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants