diff --git a/.gitmodules b/.gitmodules index 67c3e57ce16..a3521ebae7d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -46,18 +46,6 @@ [submodule "src/support/sharegl/sharegl"] path = src/support/sharegl/sharegl 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"] path = src/platform/macos/rust-core-graphics url = https://github.com/mozilla-servo/rust-core-graphics.git @@ -73,9 +61,6 @@ [submodule "src/platform/linux/rust-xlib"] path = src/platform/linux/rust-xlib 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"] path = src/support/skia/skia url = https://github.com/mozilla-servo/skia.git diff --git a/configure b/configure index 319ec852ee1..606bb5a1a8d 100755 --- a/configure +++ b/configure @@ -480,7 +480,6 @@ fi CFG_SUBMODULES="\ support/alert/rust-alert \ support/azure/rust-azure \ - support/css/rust-css \ support/css/rust-cssparser \ support/geom/rust-geom \ support/harfbuzz/rust-harfbuzz \ @@ -489,8 +488,6 @@ CFG_SUBMODULES="\ support/hubbub/rust-hubbub \ support/layers/rust-layers \ support/libparserutils/libparserutils \ - support/netsurfcss/libcss \ - support/netsurfcss/rust-netsurfcss \ support/nss/nspr \ support/nss/nss \ support/opengles/rust-opengles \ @@ -500,9 +497,7 @@ CFG_SUBMODULES="\ support/spidermonkey/rust-mozjs \ support/stb-image/rust-stb-image \ support/png/libpng \ - support/png/rust-png \ - support/wapcaplet/libwapcaplet \ - support/wapcaplet/rust-wapcaplet" + support/png/rust-png" if [ $CFG_OSTYPE = "apple-darwin" ] then diff --git a/mk/sub.mk b/mk/sub.mk index 47d4edad95a..5ff6c41deef 100644 --- a/mk/sub.mk +++ b/mk/sub.mk @@ -15,7 +15,6 @@ NO_TESTS += \ SLOW_BUILDS += \ libcss \ libparserutils \ - libwapcaplet \ mozjs \ sharegl \ skia \ @@ -26,7 +25,6 @@ NATIVE_BUILDS += \ libcss \ libhubbub \ libparserutils \ - libwapcaplet \ mozjs \ skia \ nss \ @@ -72,27 +70,6 @@ DEPS_rust-hubbub += \ rust \ $(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 += \ mozjs \ rust \ @@ -102,11 +79,6 @@ CFLAGS_rust-mozjs += \ "-I../mozjs/dist/include" \ $(NULL) -DEPS_libcss += \ - libwapcaplet \ - libparserutils \ - $(NULL) - DEPS_rust-png += \ libpng \ $(NULL) diff --git a/src/README.md b/src/README.md index 197ad80fb70..fdb72b189e9 100644 --- a/src/README.md +++ b/src/README.md @@ -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 with Direct2D, Core Graphics (Quartz), Skia, and Cairo. -* `support/css`: A general CSS parsing and selector matching library. This abstraction layer - exists to prevent `libcss` internals from leaking into Servo. +* `support/css`: A low-level CSS parsing library for Rust. * `support/geom`: A simple Euclidean geometry and linear algebra library. * `support/glut`: Bindings to the GLUT windowing framework. This bare-bones windowing framework is 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 like Clutter. * `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/png`: Bindings to libpng. * `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/stb-image`: A minimalist image decoding library. This is a temporary stopgap for image decoding until a higher-performance solution is available. -* `support/wapcaplet`: A string storage library used by `hubbub` and `netsurfcss`. ## Platform-specfic bindings diff --git a/src/components/gfx/gfx.rc b/src/components/gfx/gfx.rc index f21b70d5cea..c6c8b9c2d4b 100644 --- a/src/components/gfx/gfx.rc +++ b/src/components/gfx/gfx.rc @@ -12,7 +12,6 @@ extern mod azure; extern mod geom; -extern mod newcss (name = "css"); extern mod stb_image; extern mod extra; extern mod servo_net (name = "net"); diff --git a/src/components/main/css/matching.rs b/src/components/main/css/matching.rs index 099b2bc600e..c777a676505 100644 --- a/src/components/main/css/matching.rs +++ b/src/components/main/css/matching.rs @@ -6,6 +6,8 @@ use std::cell::Cell; use css::node_style::StyledNode; +use css::node_util::NodeUtil; +use layout::incremental; use script::dom::node::{AbstractNode, LayoutView}; use style::Stylist; @@ -39,7 +41,7 @@ impl MatchMethods for AbstractNode { for kid in self.children() { if kid.is_element() { - kid.match_subtree(stylist); + kid.match_subtree(stylist); } } } @@ -54,7 +56,15 @@ impl MatchMethods for AbstractNode { }; let cell = Cell::new(computed_values); 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>) { diff --git a/src/components/main/css/select.rs b/src/components/main/css/select.rs index b63a8a8ac6f..a3e055a8e91 100644 --- a/src/components/main/css/select.rs +++ b/src/components/main/css/select.rs @@ -2,63 +2,13 @@ * 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 extra::url::Url; -use std::cell::Cell; use style::Stylesheet; use style::Stylist; use style::selector_matching::UserAgentOrigin; -use newcss::util::DataStream; pub fn new_stylist() -> Stylist { let mut stylist = Stylist::new(); - stylist.add_stylesheet(html4_default_style(), UserAgentOrigin); - stylist.add_stylesheet(servo_default_style(), UserAgentOrigin); + let ua_stylesheet = Stylesheet::from_str(include_str!("user-agent.css")); + stylist.add_stylesheet(ua_stylesheet, UserAgentOrigin); 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 shouldn’t be needed. -// The initial value of border-*-width is 'medium' (for which 2px is ok.) -// It’s 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; }" -} diff --git a/src/components/main/css/select_handler.rs b/src/components/main/css/select_handler.rs deleted file mode 100644 index aea2925b3d3..00000000000 --- a/src/components/main/css/select_handler.rs +++ /dev/null @@ -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, -} - -fn with_node_name(node: AbstractNode, 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> for NodeSelectHandler { - fn with_node_name(&self, node: &AbstractNode, f: &fn(&str) -> R) -> R { - with_node_name(*node, f) - } - - fn named_parent_node(&self, node: &AbstractNode, name: &str) - -> Option> { - 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) -> Option> { - node.parent_node() - } - - // TODO: Use a Bloom filter. - fn named_ancestor_node(&self, node: &AbstractNode, name: &str) - -> Option> { - 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) -> bool { - self.parent_node(node).is_none() - } - - fn node_is_link(&self, node: &AbstractNode) -> bool { - if node.is_element() { - do node.with_imm_element |element| { - "a" == element.tag_name - } - } else { - false - } - } - - fn with_node_classes(&self, node: &AbstractNode, 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, 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(&self, node: &AbstractNode, 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, 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 - } - } - } -} diff --git a/src/components/main/layout/incremental.rs b/src/components/main/layout/incremental.rs index 85f565c04bc..da45839188c 100644 --- a/src/components/main/layout/incremental.rs +++ b/src/components/main/layout/incremental.rs @@ -2,9 +2,7 @@ * 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 newcss::complete::CompleteSelectResults; - -use script::dom::node::{AbstractNode, LayoutView}; +use style::ComputedValues; /// Individual layout actions that may be necessary after restyling. /// @@ -113,18 +111,14 @@ impl RestyleDamage { // breakage on modifications. macro_rules! add_if_not_equal( ($old:ident, $new:ident, $damage:ident, - [ $($effect:ident),* ], [ $($getter:ident),* ]) => ({ - if $( ($old.$getter() != $new.$getter()) )||* { + [ $($effect:ident),* ], [ $($style_struct:ident.$name:ident),* ]) => ({ + if $( ($old.$style_struct.$name != $new.$style_struct.$name) )||* { $damage.union_in_place( restyle_damage!( $($effect),* ) ); } }) ) -pub fn compute_damage(node: &AbstractNode, - old_results: &CompleteSelectResults, new_results: &CompleteSelectResults) - -> RestyleDamage { - let old = old_results.computed_style(); - let new = new_results.computed_style(); +pub fn compute_damage(old: &ComputedValues, new: &ComputedValues) -> RestyleDamage { let mut damage = RestyleDamage::none(); // This checks every CSS property, as enumerated in @@ -134,21 +128,18 @@ pub fn compute_damage(node: &AbstractNode, // FIXME: We can short-circuit more of this. add_if_not_equal!(old, new, damage, [ Repaint ], - [ color, background_color, border_top_color, border_right_color, - border_bottom_color, border_left_color ]); + [ Color.color, Background.background_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 ], - [ border_top_width, border_right_width, border_bottom_width, - border_left_width, margin_top, margin_right, margin_bottom, margin_left, - padding_top, padding_right, padding_bottom, padding_left, position, - width, height, float, font_family, font_size, font_style, font_weight, - text_align, text_decoration, line_height ]); - - // Handle 'display' specially because it has this 'is_root' parameter. - let is_root = node.is_root(); - if old.display(is_root) != new.display(is_root) { - damage.union_in_place(restyle_damage!(Repaint, BubbleWidths, Reflow)); - } + [ Border.border_top_width, Border.border_right_width, + Border.border_bottom_width, Border.border_left_width, + Margin.margin_top, Margin.margin_right, Margin.margin_bottom, Margin.margin_left, + Padding.padding_top, Padding.padding_right, Padding.padding_bottom, Padding.padding_left, + Box.position, Box.width, Box.height, Box.float, Box.display, + Font.font_family, Font.font_size, Font.font_style, Font.font_weight, + Text.text_align, Text.text_decoration, Box.line_height ]); // FIXME: test somehow that we checked every CSS property diff --git a/src/components/main/servo.rc b/src/components/main/servo.rc index 2d08f88567e..e770e6c3972 100755 --- a/src/components/main/servo.rc +++ b/src/components/main/servo.rc @@ -24,7 +24,6 @@ extern mod glfw; extern mod glut; extern mod js; extern mod layers; -extern mod newcss (name = "css"); extern mod opengles; extern mod png; extern mod script; @@ -66,7 +65,6 @@ pub mod compositing; pub mod macros; pub mod css { - mod select_handler; mod node_util; pub mod select; diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 6ebff7e1fda..a3344586ce5 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -20,11 +20,9 @@ use dom::text::Text; use std::cast; use std::cast::transmute; -use std::libc::c_void; use std::unstable::raw::Box; use extra::arc::Arc; use js::jsapi::{JSObject, JSContext}; -use netsurfcss::util::VoidPtrLike; use style::ComputedValues; use style::properties::PropertyDeclaration; use servo_util::tree::{TreeNode, TreeNodeRef, TreeNodeRefAsElement}; @@ -857,23 +855,6 @@ impl Node { } } -/// The CSS library requires that DOM nodes be convertible to `*c_void` via the `VoidPtrLike` -/// trait. -impl VoidPtrLike for AbstractNode { - fn from_void_ptr(node: *c_void) -> AbstractNode { - assert!(node.is_not_null()); - unsafe { - cast::transmute(node) - } - } - - fn to_void_ptr(&self) -> *c_void { - unsafe { - cast::transmute(*self) - } - } -} - impl Reflectable for Node { fn reflector<'a>(&'a self) -> &'a Reflector { &self.reflector_ diff --git a/src/components/script/script.rc b/src/components/script/script.rc index 13f98daf71a..acd023c6175 100644 --- a/src/components/script/script.rc +++ b/src/components/script/script.rc @@ -17,8 +17,6 @@ extern mod geom; extern mod gfx (name = "gfx"); extern mod hubbub; extern mod js; -extern mod netsurfcss; -extern mod newcss (name = "css"); extern mod servo_net (name = "net"); extern mod servo_util (name = "util"); extern mod style; diff --git a/src/support/css/rust-css b/src/support/css/rust-css deleted file mode 160000 index f385f19b847..00000000000 --- a/src/support/css/rust-css +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f385f19b847a394abffb76875d84f960496f01dd diff --git a/src/support/netsurfcss/libcss b/src/support/netsurfcss/libcss deleted file mode 160000 index 720128629f3..00000000000 --- a/src/support/netsurfcss/libcss +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 720128629f3395e8836e64887d2c105d94603746 diff --git a/src/support/netsurfcss/rust-netsurfcss b/src/support/netsurfcss/rust-netsurfcss deleted file mode 160000 index d94c0ab178f..00000000000 --- a/src/support/netsurfcss/rust-netsurfcss +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d94c0ab178fa06e7f270ea8c3a1d1202f4e23e14 diff --git a/src/support/wapcaplet/libwapcaplet b/src/support/wapcaplet/libwapcaplet deleted file mode 160000 index 1c334363957..00000000000 --- a/src/support/wapcaplet/libwapcaplet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1c3343639571d65bc0c45cab8253dabe33aace9e diff --git a/src/support/wapcaplet/rust-wapcaplet b/src/support/wapcaplet/rust-wapcaplet deleted file mode 160000 index fa32f481ead..00000000000 --- a/src/support/wapcaplet/rust-wapcaplet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fa32f481eade263241c54bd3212f50466c802eac