diff options
author | Ms2ger <Ms2ger@gmail.com> | 2016-06-16 02:07:57 +0100 |
---|---|---|
committer | Ms2ger <Ms2ger@gmail.com> | 2016-06-20 19:08:07 +0200 |
commit | 86bfd2cc9f14b95c3b6376c6b723ddf77af3fc35 (patch) | |
tree | 13078c74486575fb7e86e0bb577f1673cefc5f5c /components/script_layout_interface | |
parent | 68d603a6d0a059965d2fa604d153b531cb16d404 (diff) | |
download | servo-86bfd2cc9f14b95c3b6376c6b723ddf77af3fc35.tar.gz servo-86bfd2cc9f14b95c3b6376c6b723ddf77af3fc35.zip |
Move LayoutRPC to script_layout_interface.
Diffstat (limited to 'components/script_layout_interface')
-rw-r--r-- | components/script_layout_interface/Cargo.toml | 3 | ||||
-rw-r--r-- | components/script_layout_interface/lib.rs | 4 | ||||
-rw-r--r-- | components/script_layout_interface/rpc.rs | 96 |
3 files changed, 103 insertions, 0 deletions
diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml index 79d0c10682c..a4ace11ae26 100644 --- a/components/script_layout_interface/Cargo.toml +++ b/components/script_layout_interface/Cargo.toml @@ -9,8 +9,10 @@ name = "script_layout_interface" path = "lib.rs" [dependencies] +app_units = {version = "0.2.3", features = ["plugins"]} bitflags = "0.7" canvas_traits = {path = "../canvas_traits"} +euclid = {version = "0.6.4", features = ["plugins"]} gfx_traits = {path = "../gfx_traits"} heapsize = "0.3.0" heapsize_plugin = "0.1.2" @@ -19,6 +21,7 @@ libc = "0.2" msg = {path = "../msg"} plugins = {path = "../plugins"} range = {path = "../range"} +script_traits = {path = "../script_traits"} selectors = {version = "0.6", features = ["heap_size"]} string_cache = {version = "0.2.20", features = ["heap_size"]} style = {path = "../style"} diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index d9037311f6a..123792a6c6f 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -14,17 +14,20 @@ #![plugin(heapsize_plugin)] #![plugin(plugins)] +extern crate app_units; #[allow(unused_extern_crates)] #[macro_use] extern crate bitflags; extern crate canvas_traits; extern crate core; +extern crate euclid; extern crate gfx_traits; extern crate heapsize; extern crate ipc_channel; extern crate libc; extern crate msg; extern crate range; +extern crate script_traits; extern crate selectors; #[macro_use(atom, ns)] extern crate string_cache; @@ -32,6 +35,7 @@ extern crate style; extern crate url; pub mod restyle_damage; +pub mod rpc; pub mod wrapper_traits; use canvas_traits::CanvasMsg; diff --git a/components/script_layout_interface/rpc.rs b/components/script_layout_interface/rpc.rs new file mode 100644 index 00000000000..21cac2a19c2 --- /dev/null +++ b/components/script_layout_interface/rpc.rs @@ -0,0 +1,96 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use app_units::Au; +use euclid::point::Point2D; +use euclid::rect::Rect; +use gfx_traits::LayerId; +use script_traits::UntrustedNodeAddress; +use style::properties::longhands::{margin_top, margin_right, margin_bottom, margin_left, overflow_x}; + +/// Synchronous messages that script can send to layout. +/// +/// In general, you should use messages to talk to Layout. Use the RPC interface +/// if and only if the work is +/// +/// 1) read-only with respect to LayoutThreadData, +/// 2) small, +/// 3) and really needs to be fast. +pub trait LayoutRPC { + /// Requests the dimensions of the content box, as in the `getBoundingClientRect()` call. + fn content_box(&self) -> ContentBoxResponse; + /// Requests the dimensions of all the content boxes, as in the `getClientRects()` call. + fn content_boxes(&self) -> ContentBoxesResponse; + /// Requests the geometry of this node. Used by APIs such as `clientTop`. + fn node_geometry(&self) -> NodeGeometryResponse; + /// Requests the overflow-x and overflow-y of this node. Used by `scrollTop` etc. + fn node_overflow(&self) -> NodeOverflowResponse; + /// Requests the scroll geometry of this node. Used by APIs such as `scrollTop`. + fn node_scroll_area(&self) -> NodeGeometryResponse; + /// Requests the layer id of this node. Used by APIs such as `scrollTop` + fn node_layer_id(&self) -> NodeLayerIdResponse; + /// Requests the node containing the point of interest + fn hit_test(&self) -> HitTestResponse; + /// Query layout for the resolved value of a given CSS property + fn resolved_style(&self) -> ResolvedStyleResponse; + fn offset_parent(&self) -> OffsetParentResponse; + /// Query layout for the resolve values of the margin properties for an element. + fn margin_style(&self) -> MarginStyleResponse; + + fn nodes_from_point(&self, point: Point2D<f32>) -> Vec<UntrustedNodeAddress>; +} + +pub struct ContentBoxResponse(pub Rect<Au>); + +pub struct ContentBoxesResponse(pub Vec<Rect<Au>>); + +pub struct NodeGeometryResponse { + pub client_rect: Rect<i32>, +} + +pub struct NodeOverflowResponse(pub Option<Point2D<overflow_x::computed_value::T>>); + +pub struct NodeLayerIdResponse { + pub layer_id: LayerId, +} + +pub struct HitTestResponse { + pub node_address: Option<UntrustedNodeAddress>, +} + +pub struct ResolvedStyleResponse(pub Option<String>); + +#[derive(Clone)] +pub struct OffsetParentResponse { + pub node_address: Option<UntrustedNodeAddress>, + pub rect: Rect<Au>, +} + +impl OffsetParentResponse { + pub fn empty() -> OffsetParentResponse { + OffsetParentResponse { + node_address: None, + rect: Rect::zero(), + } + } +} + +#[derive(Clone)] +pub struct MarginStyleResponse { + pub top: margin_top::computed_value::T, + pub right: margin_right::computed_value::T, + pub bottom: margin_bottom::computed_value::T, + pub left: margin_left::computed_value::T, +} + +impl MarginStyleResponse { + pub fn empty() -> MarginStyleResponse { + MarginStyleResponse { + top: margin_top::computed_value::T::Auto, + right: margin_right::computed_value::T::Auto, + bottom: margin_bottom::computed_value::T::Auto, + left: margin_left::computed_value::T::Auto, + } + } +} |