Auto merge of #9968 - izgzhen:scroll, r=asajeffrey

Implement scroll, scrollLeft, scrollTop and friends, addressing issue #9650

This is a work in progress to solve https://github.com/servo/servo/issues/9650. Thanks a lot for helping the review.

- [x] scroll
- [x] scrollTo
- [x] scrollBy
- [x] scrollTop (setter and getter)
- [x] scrollLeft (setter and getter)

The setters will be implemented in another PR after this is merged.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9968)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-20 18:40:26 +05:30
commit 8d988f20c1
15 changed files with 569 additions and 12 deletions

View file

@ -714,6 +714,18 @@ impl<Window: WindowMethods> IOCompositor<Window> {
let _ = sender.send(());
}
(Msg::GetScrollOffset(pipeline_id, layer_id, sender), ShutdownState::NotShuttingDown) => {
match self.find_layer_with_pipeline_and_layer_id(pipeline_id, layer_id) {
Some(ref layer) => {
let typed = layer.extra_data.borrow().scroll_offset;
let _ = sender.send(Point2D::new(typed.x.get(), typed.y.get()));
},
None => {
warn!("Can't find requested layer in handling Msg::GetScrollOffset");
},
}
}
// When we are shutting_down, we need to avoid performing operations
// such as Paint that may crash because we have begun tearing down
// the rest of our resources.

View file

@ -98,6 +98,10 @@ pub fn run_script_listener_thread(compositor_proxy: Box<CompositorProxy + 'stati
compositor_proxy.send(Msg::TouchEventProcessed(result))
}
ScriptToCompositorMsg::GetScrollOffset(pid, lid, send) => {
compositor_proxy.send(Msg::GetScrollOffset(pid, lid, send));
}
ScriptToCompositorMsg::Exited => break,
}
}
@ -231,6 +235,8 @@ pub enum Msg {
MoveTo(Point2D<i32>),
/// Resize the window to size
ResizeTo(Size2D<u32>),
/// Get scroll offset of a layer
GetScrollOffset(PipelineId, LayerId, IpcSender<Point2D<f32>>),
/// A pipeline was shut down.
// This message acts as a synchronization point between the constellation,
// when it shuts down a pipeline, to the compositor; when the compositor
@ -272,6 +278,7 @@ impl Debug for Msg {
Msg::MoveTo(..) => write!(f, "MoveTo"),
Msg::ResizeTo(..) => write!(f, "ResizeTo"),
Msg::PipelineExited(..) => write!(f, "PipelineExited"),
Msg::GetScrollOffset(..) => write!(f, "GetScrollOffset"),
}
}
}