diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2013-05-28 17:13:40 -0700 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2013-05-28 17:13:40 -0700 |
commit | bf82bc54f349dd0944c37129af28dec6b43041fe (patch) | |
tree | 685e113347e8afd1965793aefc9743cd9f1f8494 /src/components/script/layout_interface.rs | |
parent | 0ea1a94f8e8a07378d23552a620a45d610db31c7 (diff) | |
download | servo-bf82bc54f349dd0944c37129af28dec6b43041fe.tar.gz servo-bf82bc54f349dd0944c37129af28dec6b43041fe.zip |
Separate the DOM and layout into separate crates.
Diffstat (limited to 'src/components/script/layout_interface.rs')
-rw-r--r-- | src/components/script/layout_interface.rs | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/components/script/layout_interface.rs b/src/components/script/layout_interface.rs new file mode 100644 index 00000000000..b442dc440d3 --- /dev/null +++ b/src/components/script/layout_interface.rs @@ -0,0 +1,103 @@ +/* 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/. */ + +//! The high-level interface from script to layout. Using this abstract interface helps reduce +/// coupling between these two components, and enables the DOM to be placed in a separate crate +/// from layout. + +use dom::node::{AbstractNode, ScriptView}; +use script_task::ScriptMsg; + +use core::comm::{Chan, SharedChan}; +use geom::rect::Rect; +use geom::size::Size2D; +use gfx::geometry::Au; +use newcss::stylesheet::Stylesheet; +use std::net::url::Url; + +/// Asynchronous messages that script can send to layout. +/// +/// FIXME(pcwalton): I think this should probably be merged with `LayoutQuery` below. +pub enum Msg { + /// Adds the given stylesheet to the document. + AddStylesheetMsg(Stylesheet), + + /// Requests a reflow. + /// + /// FIXME(pcwalton): Call this `reflow` instead? + BuildMsg(~BuildData), + + /// Performs a synchronous layout request. + /// + /// FIXME(pcwalton): As noted below, this isn't very type safe. + QueryMsg(LayoutQuery, Chan<Result<LayoutResponse,()>>), + + /// Requests that the layout task shut down and exit. + ExitMsg, +} + +/// Synchronous messages that script can send to layout. +pub enum LayoutQuery { + /// Requests the dimensions of the content box, as in the `getBoundingClientRect()` call. + ContentBoxQuery(AbstractNode<ScriptView>), + /// Requests the dimensions of all the content boxes, as in the `getClientRects()` call. + ContentBoxesQuery(AbstractNode<ScriptView>), +} + +/// The reply of a synchronous message from script to layout. +/// +/// FIXME(pcwalton): This isn't very type safe. Maybe `LayoutQuery` objects should include +/// response channels? +pub enum LayoutResponse { + /// A response to the `ContentBoxQuery` message. + ContentBoxResponse(Rect<Au>), + /// A response to the `ContentBoxesQuery` message. + ContentBoxesResponse(~[Rect<Au>]), +} + +/// Dirty bits for layout. +pub enum Damage { + /// The document is clean; nothing needs to be done. + NoDamage, + /// Reflow, but do not perform CSS selector matching. + ReflowDamage, + /// Perform CSS selector matching and reflow. + MatchSelectorsDamage, +} + +impl Damage { + /// Sets this damage to the maximum of this damage and the given damage. + /// + /// FIXME(pcwalton): This could be refactored to use `max` and the `Ord` trait, and this + /// function removed. + fn add(&mut self, new_damage: Damage) { + match (*self, new_damage) { + (NoDamage, _) => *self = new_damage, + (ReflowDamage, NoDamage) => *self = ReflowDamage, + (ReflowDamage, new_damage) => *self = new_damage, + (MatchSelectorsDamage, _) => *self = MatchSelectorsDamage + } + } +} + +/// Information needed for a reflow. +pub struct BuildData { + node: AbstractNode<ScriptView>, + /// What reflow needs to be done. + damage: Damage, + /// The URL of the page. + url: Url, + /// The channel through which messages can be sent back to the script task. + script_chan: SharedChan<ScriptMsg>, + /// The current window size. + window_size: Size2D<uint>, + script_join_chan: Chan<()>, +} + +/// Encapsulates a channel to the layout task. +#[deriving(Clone)] +pub struct LayoutTask { + chan: SharedChan<Msg>, +} + |