auto merge of #1112 : SimonSapin/servo/newnewcss, r=metajack

Following up on #1109. These three commits are independent.
This commit is contained in:
bors-servo 2013-10-23 06:19:03 -07:00
commit 1ed87f94b4
17 changed files with 30 additions and 297 deletions

15
.gitmodules vendored
View file

@ -46,18 +46,6 @@
[submodule "src/support/sharegl/sharegl"] [submodule "src/support/sharegl/sharegl"]
path = src/support/sharegl/sharegl path = src/support/sharegl/sharegl
url = https://github.com/mozilla-servo/sharegl.git url = https://github.com/mozilla-servo/sharegl.git
[submodule "src/support/wapcaplet/libwapcaplet"]
path = src/support/wapcaplet/libwapcaplet
url = https://github.com/mozilla-servo/libwapcaplet.git
[submodule "src/support/netsurfcss/libcss"]
path = src/support/netsurfcss/libcss
url = https://github.com/mozilla-servo/libcss.git
[submodule "src/support/netsurfcss/rust-netsurfcss"]
path = src/support/netsurfcss/rust-netsurfcss
url = https://github.com/mozilla-servo/rust-netsurfcss.git
[submodule "src/support/wapcaplet/rust-wapcaplet"]
path = src/support/wapcaplet/rust-wapcaplet
url = https://github.com/mozilla-servo/rust-wapcaplet.git
[submodule "src/platform/macos/rust-core-graphics"] [submodule "src/platform/macos/rust-core-graphics"]
path = src/platform/macos/rust-core-graphics path = src/platform/macos/rust-core-graphics
url = https://github.com/mozilla-servo/rust-core-graphics.git url = https://github.com/mozilla-servo/rust-core-graphics.git
@ -73,9 +61,6 @@
[submodule "src/platform/linux/rust-xlib"] [submodule "src/platform/linux/rust-xlib"]
path = src/platform/linux/rust-xlib path = src/platform/linux/rust-xlib
url = https://github.com/mozilla-servo/rust-xlib.git url = https://github.com/mozilla-servo/rust-xlib.git
[submodule "src/support/css/rust-css"]
path = src/support/css/rust-css
url = https://github.com/mozilla-servo/rust-css.git
[submodule "src/support/skia/skia"] [submodule "src/support/skia/skia"]
path = src/support/skia/skia path = src/support/skia/skia
url = https://github.com/mozilla-servo/skia.git url = https://github.com/mozilla-servo/skia.git

7
configure vendored
View file

@ -480,7 +480,6 @@ fi
CFG_SUBMODULES="\ CFG_SUBMODULES="\
support/alert/rust-alert \ support/alert/rust-alert \
support/azure/rust-azure \ support/azure/rust-azure \
support/css/rust-css \
support/css/rust-cssparser \ support/css/rust-cssparser \
support/geom/rust-geom \ support/geom/rust-geom \
support/harfbuzz/rust-harfbuzz \ support/harfbuzz/rust-harfbuzz \
@ -489,8 +488,6 @@ CFG_SUBMODULES="\
support/hubbub/rust-hubbub \ support/hubbub/rust-hubbub \
support/layers/rust-layers \ support/layers/rust-layers \
support/libparserutils/libparserutils \ support/libparserutils/libparserutils \
support/netsurfcss/libcss \
support/netsurfcss/rust-netsurfcss \
support/nss/nspr \ support/nss/nspr \
support/nss/nss \ support/nss/nss \
support/opengles/rust-opengles \ support/opengles/rust-opengles \
@ -500,9 +497,7 @@ CFG_SUBMODULES="\
support/spidermonkey/rust-mozjs \ support/spidermonkey/rust-mozjs \
support/stb-image/rust-stb-image \ support/stb-image/rust-stb-image \
support/png/libpng \ support/png/libpng \
support/png/rust-png \ support/png/rust-png"
support/wapcaplet/libwapcaplet \
support/wapcaplet/rust-wapcaplet"
if [ $CFG_OSTYPE = "apple-darwin" ] if [ $CFG_OSTYPE = "apple-darwin" ]
then then

View file

@ -15,7 +15,6 @@ NO_TESTS += \
SLOW_BUILDS += \ SLOW_BUILDS += \
libcss \ libcss \
libparserutils \ libparserutils \
libwapcaplet \
mozjs \ mozjs \
sharegl \ sharegl \
skia \ skia \
@ -26,7 +25,6 @@ NATIVE_BUILDS += \
libcss \ libcss \
libhubbub \ libhubbub \
libparserutils \ libparserutils \
libwapcaplet \
mozjs \ mozjs \
skia \ skia \
nss \ nss \
@ -72,27 +70,6 @@ DEPS_rust-hubbub += \
rust \ rust \
$(NULL) $(NULL)
DEPS_rust-netsurfcss += \
libcss \
rust-wapcaplet \
rust \
$(NULL)
DEPS_rust-wapcaplet += \
libwapcaplet \
rust \
$(NULL)
CFLAGS_rust-wapcaplet += \
"-I$(S)src/libwapcaplet/include" \
$(NULL)
DEPS_rust-css += \
rust-netsurfcss \
rust-wapcaplet \
rust \
$(NULL)
DEPS_rust-mozjs += \ DEPS_rust-mozjs += \
mozjs \ mozjs \
rust \ rust \
@ -102,11 +79,6 @@ CFLAGS_rust-mozjs += \
"-I../mozjs/dist/include" \ "-I../mozjs/dist/include" \
$(NULL) $(NULL)
DEPS_libcss += \
libwapcaplet \
libparserutils \
$(NULL)
DEPS_rust-png += \ DEPS_rust-png += \
libpng \ libpng \
$(NULL) $(NULL)

View file

@ -19,8 +19,7 @@ they are designed to be useful in other Rust projects.
* `support/azure`: A cross-platform 2D drawing library from the Mozilla project. Azure can render * `support/azure`: A cross-platform 2D drawing library from the Mozilla project. Azure can render
with Direct2D, Core Graphics (Quartz), Skia, and Cairo. with Direct2D, Core Graphics (Quartz), Skia, and Cairo.
* `support/css`: A general CSS parsing and selector matching library. This abstraction layer * `support/css`: A low-level CSS parsing library for Rust.
exists to prevent `libcss` internals from leaking into Servo.
* `support/geom`: A simple Euclidean geometry and linear algebra library. * `support/geom`: A simple Euclidean geometry and linear algebra library.
* `support/glut`: Bindings to the GLUT windowing framework. This bare-bones windowing framework is * `support/glut`: Bindings to the GLUT windowing framework. This bare-bones windowing framework is
useful for testing the engine without browser chrome. useful for testing the engine without browser chrome.
@ -32,8 +31,6 @@ they are designed to be useful in other Rust projects.
* `support/layers`: A simple GPU-accelerated 2D scene graph library, somewhat similar to libraries * `support/layers`: A simple GPU-accelerated 2D scene graph library, somewhat similar to libraries
like Clutter. like Clutter.
* `support/libparserutils`: A parsing library used by `hubbub` and `netsurfcss`. * `support/libparserutils`: A parsing library used by `hubbub` and `netsurfcss`.
* `support/netsurfcss`: The CSS library from the NetSurf project. This is a temporary stopgap for
CSS parsing until a pure-Rust solution is available.
* `support/opengles`: Bindings to OpenGL ES 2.0. * `support/opengles`: Bindings to OpenGL ES 2.0.
* `support/png`: Bindings to libpng. * `support/png`: Bindings to libpng.
* `support/sharegl`: A library for sharing OpenGL or Direct3D textures between processes. * `support/sharegl`: A library for sharing OpenGL or Direct3D textures between processes.
@ -41,7 +38,6 @@ they are designed to be useful in other Rust projects.
* `support/spidermonkey`: Mozilla's JavaScript engine. * `support/spidermonkey`: Mozilla's JavaScript engine.
* `support/stb-image`: A minimalist image decoding library. This is a temporary stopgap for image * `support/stb-image`: A minimalist image decoding library. This is a temporary stopgap for image
decoding until a higher-performance solution is available. decoding until a higher-performance solution is available.
* `support/wapcaplet`: A string storage library used by `hubbub` and `netsurfcss`.
## Platform-specfic bindings ## Platform-specfic bindings

View file

@ -12,7 +12,6 @@
extern mod azure; extern mod azure;
extern mod geom; extern mod geom;
extern mod newcss (name = "css");
extern mod stb_image; extern mod stb_image;
extern mod extra; extern mod extra;
extern mod servo_net (name = "net"); extern mod servo_net (name = "net");

View file

@ -6,6 +6,8 @@
use std::cell::Cell; use std::cell::Cell;
use css::node_style::StyledNode; use css::node_style::StyledNode;
use css::node_util::NodeUtil;
use layout::incremental;
use script::dom::node::{AbstractNode, LayoutView}; use script::dom::node::{AbstractNode, LayoutView};
use style::Stylist; use style::Stylist;
@ -39,7 +41,7 @@ impl MatchMethods for AbstractNode<LayoutView> {
for kid in self.children() { for kid in self.children() {
if kid.is_element() { if kid.is_element() {
kid.match_subtree(stylist); kid.match_subtree(stylist);
} }
} }
} }
@ -54,7 +56,15 @@ impl MatchMethods for AbstractNode<LayoutView> {
}; };
let cell = Cell::new(computed_values); let cell = Cell::new(computed_values);
do self.write_layout_data |data| { do self.write_layout_data |data| {
data.style = Some(cell.take()); let style = cell.take();
// If there was an existing style, compute the damage that
// incremental layout will need to fix.
match data.style {
None => (),
Some(ref previous_style) => self.set_restyle_damage(
incremental::compute_damage(previous_style, &style))
}
data.style = Some(style);
} }
} }
fn cascade_subtree(&self, parent: Option<AbstractNode<LayoutView>>) { fn cascade_subtree(&self, parent: Option<AbstractNode<LayoutView>>) {

View file

@ -2,63 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use extra::url::Url;
use std::cell::Cell;
use style::Stylesheet; use style::Stylesheet;
use style::Stylist; use style::Stylist;
use style::selector_matching::UserAgentOrigin; use style::selector_matching::UserAgentOrigin;
use newcss::util::DataStream;
pub fn new_stylist() -> Stylist { pub fn new_stylist() -> Stylist {
let mut stylist = Stylist::new(); let mut stylist = Stylist::new();
stylist.add_stylesheet(html4_default_style(), UserAgentOrigin); let ua_stylesheet = Stylesheet::from_str(include_str!("user-agent.css"));
stylist.add_stylesheet(servo_default_style(), UserAgentOrigin); stylist.add_stylesheet(ua_stylesheet, UserAgentOrigin);
stylist stylist
} }
fn html4_default_style() -> Stylesheet {
Stylesheet::from_str(html4_default_style_str())
}
fn servo_default_style() -> Stylesheet {
Stylesheet::from_str(servo_default_style_str())
}
fn default_url(name: &str) -> Url {
FromStr::from_str(fmt!("http://%s", name)).unwrap()
}
fn style_stream(style: &str) -> @mut DataStream {
let style = Cell::new(style.as_bytes().to_owned());
struct StyleDataStream {
style: Cell<~[u8]>,
}
impl DataStream for StyleDataStream {
fn read(&mut self) -> Option<~[u8]> {
if !self.style.is_empty() {
Some(self.style.take())
} else {
None
}
}
}
let stream = @mut StyleDataStream {
style: style,
};
stream as @mut DataStream
}
fn html4_default_style_str() -> &'static str {
include_str!("user-agent.css")
}
// FIXME: this shouldnt be needed.
// The initial value of border-*-width is 'medium' (for which 2px is ok.)
// Its the *computed values* that is set to 0 when the corresponding
// border-*-style is 'none' (the initial value) or 'hidden'.
// This should be taken care of when removing libcss.
fn servo_default_style_str() -> &'static str {
// libcss want's this to default to 2px..
"* { border-width: 0px; }"
}

View file

@ -1,137 +0,0 @@
/* 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/. */
///
/// Implementation of the callbacks that the CSS selector engine uses to query the DOM.
///
use std::str::eq_slice;
use newcss::select::SelectHandler;
use script::dom::node::{AbstractNode, LayoutView};
use servo_util::tree::{TreeNodeRef, ElementLike};
pub struct NodeSelectHandler {
node: AbstractNode<LayoutView>,
}
fn with_node_name<R>(node: AbstractNode<LayoutView>, f: &fn(&str) -> R) -> R {
if !node.is_element() {
fail!(~"attempting to style non-element node");
}
do node.with_imm_element |element_n| {
f(element_n.tag_name)
}
}
impl SelectHandler<AbstractNode<LayoutView>> for NodeSelectHandler {
fn with_node_name<R>(&self, node: &AbstractNode<LayoutView>, f: &fn(&str) -> R) -> R {
with_node_name(*node, f)
}
fn named_parent_node(&self, node: &AbstractNode<LayoutView>, name: &str)
-> Option<AbstractNode<LayoutView>> {
do node.parent_node().and_then |parent| {
do with_node_name(parent) |node_name| {
if eq_slice(name, node_name) {
Some(parent)
} else {
None
}
}
}
}
fn parent_node(&self, node: &AbstractNode<LayoutView>) -> Option<AbstractNode<LayoutView>> {
node.parent_node()
}
// TODO: Use a Bloom filter.
fn named_ancestor_node(&self, node: &AbstractNode<LayoutView>, name: &str)
-> Option<AbstractNode<LayoutView>> {
let mut node = *node;
loop {
let parent = node.parent_node();
match parent {
Some(parent) => {
let mut found = false;
do with_node_name(parent) |node_name| {
if eq_slice(name, node_name) {
found = true;
}
}
if found {
return Some(parent);
}
node = parent;
}
None => return None
}
}
}
fn node_is_root(&self, node: &AbstractNode<LayoutView>) -> bool {
self.parent_node(node).is_none()
}
fn node_is_link(&self, node: &AbstractNode<LayoutView>) -> bool {
if node.is_element() {
do node.with_imm_element |element| {
"a" == element.tag_name
}
} else {
false
}
}
fn with_node_classes<R>(&self, node: &AbstractNode<LayoutView>, f: &fn(Option<&str>) -> R) -> R {
if !node.is_element() {
fail!(~"attempting to style non-element node");
}
do node.with_imm_element() |element_n| {
f(element_n.get_attr("class"))
}
}
fn node_has_class(&self, node: &AbstractNode<LayoutView>, class: &str) -> bool {
if !node.is_element() {
fail!(~"attempting to style non-element node");
}
do node.with_imm_element |element_n| {
match element_n.get_attr("class") {
None => false,
Some(existing_classes) => {
let mut ret = false;
for s in existing_classes.split_iter(' ') {
if s == class {
ret = true;
break;
}
}
ret
}
}
}
}
fn with_node_id<R>(&self, node: &AbstractNode<LayoutView>, f: &fn(Option<&str>) -> R) -> R {
if !node.is_element() {
fail!(~"attempting to style non-element node");
}
do node.with_imm_element() |element_n| {
f(element_n.get_attr("id"))
}
}
fn node_has_id(&self, node: &AbstractNode<LayoutView>, id: &str) -> bool {
if !node.is_element() {
fail!(~"attempting to style non-element node");
}
do node.with_imm_element |element_n| {
match element_n.get_attr("id") {
None => false,
Some(existing_id) => id == existing_id
}
}
}
}

View file

@ -2,9 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use newcss::complete::CompleteSelectResults; use style::ComputedValues;
use script::dom::node::{AbstractNode, LayoutView};
/// Individual layout actions that may be necessary after restyling. /// Individual layout actions that may be necessary after restyling.
/// ///
@ -113,18 +111,14 @@ impl RestyleDamage {
// breakage on modifications. // breakage on modifications.
macro_rules! add_if_not_equal( macro_rules! add_if_not_equal(
($old:ident, $new:ident, $damage:ident, ($old:ident, $new:ident, $damage:ident,
[ $($effect:ident),* ], [ $($getter:ident),* ]) => ({ [ $($effect:ident),* ], [ $($style_struct:ident.$name:ident),* ]) => ({
if $( ($old.$getter() != $new.$getter()) )||* { if $( ($old.$style_struct.$name != $new.$style_struct.$name) )||* {
$damage.union_in_place( restyle_damage!( $($effect),* ) ); $damage.union_in_place( restyle_damage!( $($effect),* ) );
} }
}) })
) )
pub fn compute_damage(node: &AbstractNode<LayoutView>, pub fn compute_damage(old: &ComputedValues, new: &ComputedValues) -> RestyleDamage {
old_results: &CompleteSelectResults, new_results: &CompleteSelectResults)
-> RestyleDamage {
let old = old_results.computed_style();
let new = new_results.computed_style();
let mut damage = RestyleDamage::none(); let mut damage = RestyleDamage::none();
// This checks every CSS property, as enumerated in // This checks every CSS property, as enumerated in
@ -134,21 +128,18 @@ pub fn compute_damage(node: &AbstractNode<LayoutView>,
// FIXME: We can short-circuit more of this. // FIXME: We can short-circuit more of this.
add_if_not_equal!(old, new, damage, [ Repaint ], add_if_not_equal!(old, new, damage, [ Repaint ],
[ color, background_color, border_top_color, border_right_color, [ Color.color, Background.background_color,
border_bottom_color, border_left_color ]); Border.border_top_color, Border.border_right_color,
Border.border_bottom_color, Border.border_left_color ]);
add_if_not_equal!(old, new, damage, [ Repaint, BubbleWidths, Reflow ], add_if_not_equal!(old, new, damage, [ Repaint, BubbleWidths, Reflow ],
[ border_top_width, border_right_width, border_bottom_width, [ Border.border_top_width, Border.border_right_width,
border_left_width, margin_top, margin_right, margin_bottom, margin_left, Border.border_bottom_width, Border.border_left_width,
padding_top, padding_right, padding_bottom, padding_left, position, Margin.margin_top, Margin.margin_right, Margin.margin_bottom, Margin.margin_left,
width, height, float, font_family, font_size, font_style, font_weight, Padding.padding_top, Padding.padding_right, Padding.padding_bottom, Padding.padding_left,
text_align, text_decoration, line_height ]); Box.position, Box.width, Box.height, Box.float, Box.display,
Font.font_family, Font.font_size, Font.font_style, Font.font_weight,
// Handle 'display' specially because it has this 'is_root' parameter. Text.text_align, Text.text_decoration, Box.line_height ]);
let is_root = node.is_root();
if old.display(is_root) != new.display(is_root) {
damage.union_in_place(restyle_damage!(Repaint, BubbleWidths, Reflow));
}
// FIXME: test somehow that we checked every CSS property // FIXME: test somehow that we checked every CSS property

View file

@ -24,7 +24,6 @@ extern mod glfw;
extern mod glut; extern mod glut;
extern mod js; extern mod js;
extern mod layers; extern mod layers;
extern mod newcss (name = "css");
extern mod opengles; extern mod opengles;
extern mod png; extern mod png;
extern mod script; extern mod script;
@ -66,7 +65,6 @@ pub mod compositing;
pub mod macros; pub mod macros;
pub mod css { pub mod css {
mod select_handler;
mod node_util; mod node_util;
pub mod select; pub mod select;

View file

@ -20,11 +20,9 @@ use dom::text::Text;
use std::cast; use std::cast;
use std::cast::transmute; use std::cast::transmute;
use std::libc::c_void;
use std::unstable::raw::Box; use std::unstable::raw::Box;
use extra::arc::Arc; use extra::arc::Arc;
use js::jsapi::{JSObject, JSContext}; use js::jsapi::{JSObject, JSContext};
use netsurfcss::util::VoidPtrLike;
use style::ComputedValues; use style::ComputedValues;
use style::properties::PropertyDeclaration; use style::properties::PropertyDeclaration;
use servo_util::tree::{TreeNode, TreeNodeRef, TreeNodeRefAsElement}; use servo_util::tree::{TreeNode, TreeNodeRef, TreeNodeRefAsElement};
@ -857,23 +855,6 @@ impl Node<ScriptView> {
} }
} }
/// The CSS library requires that DOM nodes be convertible to `*c_void` via the `VoidPtrLike`
/// trait.
impl VoidPtrLike for AbstractNode<LayoutView> {
fn from_void_ptr(node: *c_void) -> AbstractNode<LayoutView> {
assert!(node.is_not_null());
unsafe {
cast::transmute(node)
}
}
fn to_void_ptr(&self) -> *c_void {
unsafe {
cast::transmute(*self)
}
}
}
impl Reflectable for Node<ScriptView> { impl Reflectable for Node<ScriptView> {
fn reflector<'a>(&'a self) -> &'a Reflector { fn reflector<'a>(&'a self) -> &'a Reflector {
&self.reflector_ &self.reflector_

View file

@ -17,8 +17,6 @@ extern mod geom;
extern mod gfx (name = "gfx"); extern mod gfx (name = "gfx");
extern mod hubbub; extern mod hubbub;
extern mod js; extern mod js;
extern mod netsurfcss;
extern mod newcss (name = "css");
extern mod servo_net (name = "net"); extern mod servo_net (name = "net");
extern mod servo_util (name = "util"); extern mod servo_util (name = "util");
extern mod style; extern mod style;

@ -1 +0,0 @@
Subproject commit f385f19b847a394abffb76875d84f960496f01dd

@ -1 +0,0 @@
Subproject commit 720128629f3395e8836e64887d2c105d94603746

@ -1 +0,0 @@
Subproject commit d94c0ab178fa06e7f270ea8c3a1d1202f4e23e14

@ -1 +0,0 @@
Subproject commit 1c3343639571d65bc0c45cab8253dabe33aace9e

@ -1 +0,0 @@
Subproject commit fa32f481eade263241c54bd3212f50466c802eac