-
Notifications
You must be signed in to change notification settings - Fork 299
Add API for scrolling individual layers #590
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
Conversation
@glennw r? |
} | ||
|
||
found_layer = true; | ||
scrolled_a_layer = layer.set_scroll_origin(&origin); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
979f65d
to
bf9ad79
Compare
There was a problem hiding this 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>>, |
There was a problem hiding this comment.
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>
?
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space missing before {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Will fix.
Looks good once @kvark's comments are addressed. |
This will allow Servo to reimplement scroll_to_fragment.
bf9ad79
to
c33d8e4
Compare
@bors-servo r=glennw Thanks everyone for the reviews! |
📌 Commit c33d8e4 has been approved by |
⚡ Test exempted - status |
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 -->
This will allow Servo to reimplement scroll_to_fragment.
This change is