зеркало из https://github.com/mozilla/gecko-dev.git
servo: Stub CSS computed style construction
Source-Repo: https://github.com/servo/servo Source-Revision: 48034368b5058897068e1e29bd6613de28a8feeb
This commit is contained in:
Родитель
26936cecb5
Коммит
d16b2a8b0f
|
@ -1,6 +1,6 @@
|
||||||
import dom::rcu::{writer_methods};
|
import dom::rcu::{writer_methods};
|
||||||
import gfx::geom::{au, size};
|
import gfx::geom::{au, size};
|
||||||
import layout::base::box;
|
import layout::base::layout_data;
|
||||||
import util::tree;
|
import util::tree;
|
||||||
|
|
||||||
enum node_data = {
|
enum node_data = {
|
||||||
|
@ -13,10 +13,12 @@ enum node_kind {
|
||||||
nk_img(size<au>)
|
nk_img(size<au>)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The rd_aux data is a (weak) pointer to the primary box. Note that
|
#[doc="The rd_aux data is a (weak) pointer to the layout data, which contains
|
||||||
// there may be multiple boxes per DOM node.
|
the CSS info as well as the primary box. Note that there may be multiple
|
||||||
type node = rcu::handle<node_data, box>;
|
boxes per DOM node."]
|
||||||
type node_scope = rcu::scope<node_data, box>;
|
type node = rcu::handle<node_data, layout_data>;
|
||||||
|
|
||||||
|
type node_scope = rcu::scope<node_data, layout_data>;
|
||||||
|
|
||||||
fn node_scope() -> node_scope { rcu::scope() }
|
fn node_scope() -> node_scope { rcu::scope() }
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ fn draw_display_list(
|
||||||
clear(draw_target);
|
clear(draw_target);
|
||||||
|
|
||||||
for display_list.each {|item|
|
for display_list.each {|item|
|
||||||
|
#debug["drawing %?", item];
|
||||||
let (r, g, b) = alt check item.item_type {
|
let (r, g, b) = alt check item.item_type {
|
||||||
dl::solid_color(r, g, b) { (r, g, b) }
|
dl::solid_color(r, g, b) { (r, g, b) }
|
||||||
};
|
};
|
||||||
|
@ -109,4 +110,4 @@ fn clear(draw_target: AzDrawTargetRef) {
|
||||||
);
|
);
|
||||||
|
|
||||||
AzReleaseColorPattern(black_pattern);
|
AzReleaseColorPattern(black_pattern);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
import dom::base::{nk_div, nk_img, node_data, node_kind, node};
|
import dom::base::{nk_div, nk_img, node_data, node_kind, node};
|
||||||
import dom::rcu;
|
import dom::rcu;
|
||||||
import dom::rcu::reader_methods;
|
import dom::rcu::reader_methods;
|
||||||
import inline::inline_layout_methods;
|
|
||||||
import gfx::geom;
|
import gfx::geom;
|
||||||
import gfx::geom::{size, rect, point, au};
|
import gfx::geom::{size, rect, point, au};
|
||||||
|
import /*layout::*/inline::inline_layout_methods;
|
||||||
|
import /*layout::*/style::style::{computed_style, di_block, di_inline};
|
||||||
|
import /*layout::*/style::style::style_methods;
|
||||||
import util::{tree};
|
import util::{tree};
|
||||||
|
|
||||||
enum display {
|
|
||||||
di_block,
|
|
||||||
di_inline
|
|
||||||
}
|
|
||||||
|
|
||||||
enum box = {
|
enum box = {
|
||||||
tree: tree::fields<@box>,
|
tree: tree::fields<@box>,
|
||||||
node: node,
|
node: node,
|
||||||
mut display: display,
|
|
||||||
mut bounds: geom::rect<au>
|
mut bounds: geom::rect<au>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum layout_data = {
|
||||||
|
mut computed_style: computed_style,
|
||||||
|
mut box: option<@box>
|
||||||
|
};
|
||||||
|
|
||||||
enum ntree { ntree }
|
enum ntree { ntree }
|
||||||
impl of tree::rd_tree_ops<node> for ntree {
|
impl of tree::rd_tree_ops<node> for ntree {
|
||||||
fn each_child(node: node, f: fn(node) -> bool) {
|
fn each_child(node: node, f: fn(node) -> bool) {
|
||||||
|
@ -53,7 +54,7 @@ impl of tree::wr_tree_ops<@box> for btree {
|
||||||
impl block_layout_methods for @box {
|
impl block_layout_methods for @box {
|
||||||
#[doc="The main reflow routine."]
|
#[doc="The main reflow routine."]
|
||||||
fn reflow(available_width: au) {
|
fn reflow(available_width: au) {
|
||||||
alt self.display {
|
alt self.node.get_computed_style().display {
|
||||||
di_block { self.reflow_block(available_width) }
|
di_block { self.reflow_block(available_width) }
|
||||||
di_inline { self.reflow_inline(available_width) }
|
di_inline { self.reflow_inline(available_width) }
|
||||||
}
|
}
|
||||||
|
@ -61,7 +62,7 @@ impl block_layout_methods for @box {
|
||||||
|
|
||||||
#[doc="The main reflow routine for block layout."]
|
#[doc="The main reflow routine for block layout."]
|
||||||
fn reflow_block(available_width: au) {
|
fn reflow_block(available_width: au) {
|
||||||
assert self.display == di_block;
|
assert self.node.get_computed_style().display == di_block;
|
||||||
|
|
||||||
// Root here is the root of the reflow, not necessarily the doc as
|
// Root here is the root of the reflow, not necessarily the doc as
|
||||||
// a whole.
|
// a whole.
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
import dom::base::node;
|
import dom::base::node;
|
||||||
import dom::rcu::reader_methods;
|
import dom::rcu::reader_methods;
|
||||||
import gfx::geom;
|
import gfx::geom;
|
||||||
import /*layout::*/base::{box, btree, di_block, di_inline, ntree, rd_tree_ops};
|
import /*layout::*/base::{box, btree, ntree, rd_tree_ops, wr_tree_ops};
|
||||||
import /*layout::*/base::wr_tree_ops;
|
import /*layout::*/style::style::{di_block, di_inline};
|
||||||
import util::tree;
|
import util::tree;
|
||||||
|
|
||||||
export box_builder_methods;
|
export box_builder_methods;
|
||||||
|
@ -12,14 +12,13 @@ export box_builder_methods;
|
||||||
fn new_box(n: node) -> @box {
|
fn new_box(n: node) -> @box {
|
||||||
@box({tree: tree::empty(),
|
@box({tree: tree::empty(),
|
||||||
node: n,
|
node: n,
|
||||||
mut display: di_block,
|
|
||||||
mut bounds: geom::zero_rect_au()})
|
mut bounds: geom::zero_rect_au()})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl box_builder_priv_methods for node {
|
impl box_builder_priv_methods for node {
|
||||||
fn construct_boxes() -> @box {
|
fn construct_boxes() -> @box {
|
||||||
let b = new_box(self);
|
let b = new_box(self);
|
||||||
self.set_aux(b);
|
self.aux::<()>({ |a| a.box = some(b); });
|
||||||
ret b;
|
ret b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
// Inline layout.
|
// Inline layout.
|
||||||
|
|
||||||
import base::*; // FIXME: Can't get around import * due to resolve bug.
|
|
||||||
import dom::rcu;
|
import dom::rcu;
|
||||||
import dom::rcu::reader_methods;
|
import dom::rcu::reader_methods;
|
||||||
import gfx::geom::au;
|
import gfx::geom::au;
|
||||||
|
import /*layout::*/base::*; // FIXME: Can't get around import *; resolve bug.
|
||||||
|
import /*layout::*/style::style::{di_inline, style_methods};
|
||||||
import util::tree;
|
import util::tree;
|
||||||
|
|
||||||
#[doc="The main reflow routine for inline layout."]
|
#[doc="The main reflow routine for inline layout."]
|
||||||
impl inline_layout_methods for @box {
|
impl inline_layout_methods for @box {
|
||||||
fn reflow_inline(available_width: au) {
|
fn reflow_inline(available_width: au) {
|
||||||
assert self.display == di_inline;
|
assert self.node.get_computed_style().display == di_inline;
|
||||||
|
|
||||||
// FIXME: This is clownshoes inline layout and is not even close to
|
// FIXME: This is clownshoes inline layout and is not even close to
|
||||||
// correct.
|
// correct.
|
||||||
|
|
|
@ -11,6 +11,7 @@ import gfx::geom;
|
||||||
import gfx::renderer;
|
import gfx::renderer;
|
||||||
import dom::base::node;
|
import dom::base::node;
|
||||||
import dom::rcu::scope;
|
import dom::rcu::scope;
|
||||||
|
import /*layout::*/style::style::style_methods;
|
||||||
import base::*;
|
import base::*;
|
||||||
import box_builder::box_builder_methods;
|
import box_builder::box_builder_methods;
|
||||||
import dl = display_list;
|
import dl = display_list;
|
||||||
|
@ -29,6 +30,7 @@ fn layout(to_renderer: chan<renderer::msg>) -> chan<msg> {
|
||||||
exit { break; }
|
exit { break; }
|
||||||
build(node) {
|
build(node) {
|
||||||
#debug("layout: received layout request");
|
#debug("layout: received layout request");
|
||||||
|
node.recompute_style_for_subtree();
|
||||||
let this_box = node.construct_boxes_for_subtree();
|
let this_box = node.construct_boxes_for_subtree();
|
||||||
this_box.reflow(geom::px_to_au(800));
|
this_box.reflow(geom::px_to_au(800));
|
||||||
let dlist = build_display_list(this_box);
|
let dlist = build_display_list(this_box);
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
#[doc="High-level interface to CSS selector matching."]
|
||||||
|
|
||||||
|
import dom::base::{nk_div, nk_img, node, node_kind};
|
||||||
|
import dom::rcu::reader_methods;
|
||||||
|
import /*layout::*/base::*; // FIXME: resolve bug requires *
|
||||||
|
|
||||||
|
enum computed_style = {
|
||||||
|
mut display: display
|
||||||
|
};
|
||||||
|
|
||||||
|
enum display {
|
||||||
|
di_block,
|
||||||
|
di_inline
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc="Returns the default style for the given node kind."]
|
||||||
|
fn default_style_for_node_kind(kind : node_kind) -> computed_style {
|
||||||
|
alt kind {
|
||||||
|
nk_div { computed_style({ mut display: di_block }) }
|
||||||
|
nk_img(*) { computed_style({ mut display: di_block }) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl style_priv for node {
|
||||||
|
#[doc="
|
||||||
|
Performs CSS selector matching on a node.
|
||||||
|
|
||||||
|
This is, importantly, the function that creates the layout data for
|
||||||
|
the node (the reader-auxiliary box in the RCU model) and populates it
|
||||||
|
with the computed style.
|
||||||
|
"]
|
||||||
|
fn recompute_style() {
|
||||||
|
let default_style: computed_style =
|
||||||
|
default_style_for_node_kind(self.rd { |n| n.kind });
|
||||||
|
let the_layout_data = @layout_data({
|
||||||
|
mut computed_style: default_style,
|
||||||
|
mut box: none
|
||||||
|
});
|
||||||
|
self.set_aux(the_layout_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl style_methods for node {
|
||||||
|
#[doc="
|
||||||
|
Returns the computed style for the given node. If CSS selector matching
|
||||||
|
has not yet been performed, fails.
|
||||||
|
|
||||||
|
TODO: Return a safe reference; don't copy.
|
||||||
|
"]
|
||||||
|
fn get_computed_style() -> computed_style {
|
||||||
|
if !self.has_aux() {
|
||||||
|
fail "get_computed_style() called on a node without a style!";
|
||||||
|
}
|
||||||
|
ret self.aux({ |x| x }).computed_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc="
|
||||||
|
Performs CSS selector matching on a subtree.
|
||||||
|
|
||||||
|
This is, importantly, the function that creates the layout data for
|
||||||
|
the node (the reader-auxiliary box in the RCU model) and populates it
|
||||||
|
with the computed style.
|
||||||
|
"]
|
||||||
|
fn recompute_style_for_subtree() {
|
||||||
|
self.recompute_style();
|
||||||
|
for ntree.each_child(self) {
|
||||||
|
|kid|
|
||||||
|
kid.recompute_style_for_subtree();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,10 @@ mod image {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod layout {
|
mod layout {
|
||||||
|
mod style {
|
||||||
|
mod style;
|
||||||
|
}
|
||||||
|
|
||||||
mod base;
|
mod base;
|
||||||
mod box_builder;
|
mod box_builder;
|
||||||
mod display_list;
|
mod display_list;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче