aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/gfx/display_list.rs2
-rw-r--r--src/components/gfx/font.rs2
-rw-r--r--src/components/gfx/gfx.rc3
-rw-r--r--src/components/gfx/platform/android/font.rs4
-rw-r--r--src/components/gfx/platform/linux/font.rs4
-rw-r--r--src/components/gfx/platform/macos/font.rs4
-rw-r--r--src/components/gfx/render_context.rs2
-rw-r--r--src/components/gfx/text/glyph.rs5
-rw-r--r--src/components/gfx/text/shaping/harfbuzz.rs2
-rw-r--r--src/components/gfx/text/text_run.rs2
-rw-r--r--src/components/main/css/node_style.rs2
-rw-r--r--src/components/main/css/node_util.rs2
-rw-r--r--src/components/main/css/select_handler.rs1
-rw-r--r--src/components/main/layout/block.rs4
-rw-r--r--src/components/main/layout/box.rs3
-rw-r--r--src/components/main/layout/context.rs2
-rw-r--r--src/components/main/layout/float.rs4
-rw-r--r--src/components/main/layout/float_context.rs2
-rw-r--r--src/components/main/layout/flow.rs2
-rw-r--r--src/components/main/layout/inline.rs2
-rw-r--r--src/components/main/layout/layout_task.rs2
-rw-r--r--src/components/main/layout/model.rs2
-rw-r--r--src/components/script/dom/document.rs2
-rw-r--r--src/components/script/dom/element.rs25
-rw-r--r--src/components/script/dom/htmldocument.rs2
-rw-r--r--src/components/script/dom/htmlimageelement.rs3
-rw-r--r--src/components/script/dom/node.rs24
-rw-r--r--src/components/script/html/hubbub_html_parser.rs2
-rw-r--r--src/components/script/layout_interface.rs2
-rw-r--r--src/components/script/script_task.rs2
-rw-r--r--src/components/style/common_types.rs55
-rw-r--r--src/components/style/properties.rs.mako24
-rw-r--r--src/components/style/selector_matching.rs63
-rw-r--r--src/components/style/style.rc5
-rw-r--r--src/components/util/geometry.rs (renamed from src/components/gfx/geometry.rs)0
-rw-r--r--src/components/util/tree.rs12
-rw-r--r--src/components/util/util.rc2
37 files changed, 159 insertions, 122 deletions
diff --git a/src/components/gfx/display_list.rs b/src/components/gfx/display_list.rs
index e81bd4a2d1e..caebdc470b8 100644
--- a/src/components/gfx/display_list.rs
+++ b/src/components/gfx/display_list.rs
@@ -15,7 +15,7 @@
/// low-level drawing primitives.
use color::Color;
-use geometry::Au;
+use servo_util::geometry::Au;
use newcss::values::CSSBorderStyle;
use render_context::RenderContext;
use text::SendableTextRun;
diff --git a/src/components/gfx/font.rs b/src/components/gfx/font.rs
index 994ee0d91de..a8ce3985aab 100644
--- a/src/components/gfx/font.rs
+++ b/src/components/gfx/font.rs
@@ -4,7 +4,7 @@
use color::Color;
use font_context::FontContext;
-use geometry::Au;
+use servo_util::geometry::Au;
use platform::font_context::FontContextHandle;
use platform::font::{FontHandle, FontTable};
use render_context::RenderContext;
diff --git a/src/components/gfx/gfx.rc b/src/components/gfx/gfx.rc
index 963f083eebc..a9664d5c2e0 100644
--- a/src/components/gfx/gfx.rc
+++ b/src/components/gfx/gfx.rc
@@ -41,13 +41,12 @@ mod render_context;
// Rendering
pub mod color;
pub mod display_list;
-pub mod geometry;
pub mod render_task;
pub mod surface;
// Fonts
pub mod font;
-pub mod font_context;
+pub mod font_context;
pub mod font_list;
// Misc.
diff --git a/src/components/gfx/platform/android/font.rs b/src/components/gfx/platform/android/font.rs
index b8b08cc9599..7da80b3d9cf 100644
--- a/src/components/gfx/platform/android/font.rs
+++ b/src/components/gfx/platform/android/font.rs
@@ -8,8 +8,8 @@ use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
use font::{FontWeight700, FontWeight800, FontWeight900};
-use geometry::Au;
-use geometry;
+use servo_util::geometry::Au;
+use servo_util::geometry;
use platform::font_context::FontContextHandle;
use text::glyph::GlyphIndex;
use text::util::{float_to_fixed, fixed_to_float};
diff --git a/src/components/gfx/platform/linux/font.rs b/src/components/gfx/platform/linux/font.rs
index b8b08cc9599..7da80b3d9cf 100644
--- a/src/components/gfx/platform/linux/font.rs
+++ b/src/components/gfx/platform/linux/font.rs
@@ -8,8 +8,8 @@ use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
use font::{FontWeight700, FontWeight800, FontWeight900};
-use geometry::Au;
-use geometry;
+use servo_util::geometry::Au;
+use servo_util::geometry;
use platform::font_context::FontContextHandle;
use text::glyph::GlyphIndex;
use text::util::{float_to_fixed, fixed_to_float};
diff --git a/src/components/gfx/platform/macos/font.rs b/src/components/gfx/platform/macos/font.rs
index 08978c5d063..6568593e4c1 100644
--- a/src/components/gfx/platform/macos/font.rs
+++ b/src/components/gfx/platform/macos/font.rs
@@ -12,8 +12,8 @@ use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
use font::{FontTableTag, FontWeight100, FontWeight200, FontWeight300, FontWeight400};
use font::{FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900};
use font::{FractionalPixel, SpecifiedFontStyle};
-use geometry::{Au, px_to_pt};
-use geometry;
+use servo_util::geometry::{Au, px_to_pt};
+use servo_util::geometry;
use platform::macos::font_context::FontContextHandle;
use text::glyph::GlyphIndex;
diff --git a/src/components/gfx/render_context.rs b/src/components/gfx/render_context.rs
index 80f58af5ee8..25031f6b695 100644
--- a/src/components/gfx/render_context.rs
+++ b/src/components/gfx/render_context.rs
@@ -3,8 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use servo_msg::compositor_msg::LayerBuffer;
+use servo_util::geometry::Au;
use font_context::FontContext;
-use geometry::Au;
use newcss::values::CSSBorderStyle;
use newcss::values::{CSSBorderStyleNone, CSSBorderStyleHidden, CSSBorderStyleDotted, CSSBorderStyleDashed, CSSBorderStyleSolid, CSSBorderStyleDouble, CSSBorderStyleGroove, CSSBorderStyleRidge, CSSBorderStyleInset, CSSBorderStyleOutset};
use opts::Opts;
diff --git a/src/components/gfx/text/glyph.rs b/src/components/gfx/text/glyph.rs
index adcafc65f8d..8e2e0bf8015 100644
--- a/src/components/gfx/text/glyph.rs
+++ b/src/components/gfx/text/glyph.rs
@@ -4,9 +4,8 @@
use servo_util::vec::*;
use servo_util::range::Range;
-
-use geometry::Au;
-use geometry;
+use servo_util::geometry::Au;
+use servo_util::geometry;
use std::cmp::{Ord, Eq};
use std::num::NumCast;
diff --git a/src/components/gfx/text/shaping/harfbuzz.rs b/src/components/gfx/text/shaping/harfbuzz.rs
index ab736201424..cebc7360d9e 100644
--- a/src/components/gfx/text/shaping/harfbuzz.rs
+++ b/src/components/gfx/text/shaping/harfbuzz.rs
@@ -5,7 +5,7 @@
extern mod harfbuzz;
use font::{Font, FontHandleMethods, FontTableMethods, FontTableTag};
-use geometry::Au;
+use servo_util::geometry::Au;
use platform::font::FontTable;
use text::glyph::{GlyphStore, GlyphIndex, GlyphData};
use text::shaping::ShaperMethods;
diff --git a/src/components/gfx/text/text_run.rs b/src/components/gfx/text/text_run.rs
index 1406e330423..3ca1960921f 100644
--- a/src/components/gfx/text/text_run.rs
+++ b/src/components/gfx/text/text_run.rs
@@ -5,7 +5,7 @@
use std::vec::VecIterator;
use font_context::FontContext;
-use geometry::Au;
+use servo_util::geometry::Au;
use text::glyph::GlyphStore;
use font::{Font, FontDescriptor, RunMetrics};
use servo_util::range::Range;
diff --git a/src/components/main/css/node_style.rs b/src/components/main/css/node_style.rs
index d64e59134c4..c4f38fb566c 100644
--- a/src/components/main/css/node_style.rs
+++ b/src/components/main/css/node_style.rs
@@ -9,6 +9,8 @@ use layout::incremental::RestyleDamage;
use newcss::complete::CompleteStyle;
use script::dom::node::{AbstractNode, LayoutView};
+use servo_util::tree::TreeNodeRef;
+
/// Node mixin providing `style` method that returns a `NodeStyle`
pub trait StyledNode {
diff --git a/src/components/main/css/node_util.rs b/src/components/main/css/node_util.rs
index e76d2db0607..f76a079464c 100644
--- a/src/components/main/css/node_util.rs
+++ b/src/components/main/css/node_util.rs
@@ -8,6 +8,8 @@ use std::cast;
use std::cell::Cell;
use newcss::complete::CompleteSelectResults;
use script::dom::node::{AbstractNode, LayoutView};
+use servo_util::tree::TreeNodeRef;
+
pub trait NodeUtil<'self> {
fn get_css_select_results(self) -> &'self CompleteSelectResults;
diff --git a/src/components/main/css/select_handler.rs b/src/components/main/css/select_handler.rs
index e031b153b0f..75cce0e0d0c 100644
--- a/src/components/main/css/select_handler.rs
+++ b/src/components/main/css/select_handler.rs
@@ -9,6 +9,7 @@
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>,
diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs
index 2795e16880c..f81fa2e45c9 100644
--- a/src/components/main/layout/block.rs
+++ b/src/components/main/layout/block.rs
@@ -17,8 +17,8 @@ use geom::point::Point2D;
use geom::size::Size2D;
use geom::rect::Rect;
use gfx::display_list::DisplayList;
-use gfx::geometry::{Au, to_frac_px};
-use gfx::geometry;
+use servo_util::geometry::{Au, to_frac_px};
+use servo_util::geometry;
pub struct BlockFlowData {
/// Data common to all flows.
diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs
index 76465870f9d..9d1491c11fe 100644
--- a/src/components/main/layout/box.rs
+++ b/src/components/main/layout/box.rs
@@ -21,7 +21,7 @@ use gfx::display_list::{DisplayList, ImageDisplayItem, ImageDisplayItemClass};
use gfx::display_list::{SolidColorDisplayItem, SolidColorDisplayItemClass, TextDisplayItem};
use gfx::display_list::{TextDisplayItemClass};
use gfx::font::{FontStyle, FontWeight300};
-use gfx::geometry::Au;
+use servo_util::geometry::Au;
use gfx::text::text_run::TextRun;
use newcss::color::rgb;
use newcss::complete::CompleteStyle;
@@ -38,6 +38,7 @@ use script::dom::node::{AbstractNode, LayoutView};
use servo_net::image::holder::ImageHolder;
use servo_net::local_image_cache::LocalImageCache;
use servo_util::range::*;
+use servo_util::tree::{TreeNodeRef, ElementLike};
use extra::url::Url;
/// Render boxes (`struct RenderBox`) are the leaves of the layout tree. They cannot position
diff --git a/src/components/main/layout/context.rs b/src/components/main/layout/context.rs
index 13b6f4e8a83..c9ef334af43 100644
--- a/src/components/main/layout/context.rs
+++ b/src/components/main/layout/context.rs
@@ -6,7 +6,7 @@
use geom::rect::Rect;
use gfx::font_context::FontContext;
-use gfx::geometry::Au;
+use servo_util::geometry::Au;
use servo_net::local_image_cache::LocalImageCache;
/// Data needed by the layout task.
diff --git a/src/components/main/layout/float.rs b/src/components/main/layout/float.rs
index d56f8a8269b..c63d8e8f8a6 100644
--- a/src/components/main/layout/float.rs
+++ b/src/components/main/layout/float.rs
@@ -13,8 +13,8 @@ use std::cell::Cell;
use geom::point::Point2D;
use geom::rect::Rect;
use gfx::display_list::DisplayList;
-use gfx::geometry::Au;
-use gfx::geometry;
+use servo_util::geometry::Au;
+use servo_util::geometry;
pub struct FloatFlowData {
/// Data common to all flows.
diff --git a/src/components/main/layout/float_context.rs b/src/components/main/layout/float_context.rs
index 2a49921bb18..adc083105fe 100644
--- a/src/components/main/layout/float_context.rs
+++ b/src/components/main/layout/float_context.rs
@@ -5,7 +5,7 @@
use geom::point::Point2D;
use geom::size::Size2D;
use geom::rect::Rect;
-use gfx::geometry::{Au, max, min};
+use servo_util::geometry::{Au, max, min};
use std::util::replace;
use std::vec;
use std::i32::max_value;
diff --git a/src/components/main/layout/flow.rs b/src/components/main/layout/flow.rs
index f5aec1d6fb6..a1675c46204 100644
--- a/src/components/main/layout/flow.rs
+++ b/src/components/main/layout/flow.rs
@@ -42,7 +42,7 @@ use std::io::stderr;
use geom::point::Point2D;
use geom::rect::Rect;
use gfx::display_list::DisplayList;
-use gfx::geometry::Au;
+use servo_util::geometry::Au;
use script::dom::node::{AbstractNode, LayoutView};
/// The type of the formatting context and data specific to each context, such as line box
diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs
index 33fe8ca335f..c623077f519 100644
--- a/src/components/main/layout/inline.rs
+++ b/src/components/main/layout/inline.rs
@@ -17,7 +17,7 @@ use std::u16;
use std::util;
use geom::{Point2D, Rect, Size2D};
use gfx::display_list::DisplayList;
-use gfx::geometry::Au;
+use servo_util::geometry::Au;
use newcss::units::{Em, Px};
use newcss::values::{CSSFontSizeLength};
use newcss::values::{CSSTextAlignLeft, CSSTextAlignCenter, CSSTextAlignRight, CSSTextAlignJustify};
diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs
index d6e0b86210b..b91e22369f0 100644
--- a/src/components/main/layout/layout_task.rs
+++ b/src/components/main/layout/layout_task.rs
@@ -23,7 +23,7 @@ use geom::rect::Rect;
use geom::size::Size2D;
use gfx::display_list::DisplayList;
use gfx::font_context::FontContext;
-use gfx::geometry::Au;
+use servo_util::geometry::Au;
use gfx::opts::Opts;
use gfx::render_task::{RenderMsg, RenderChan, RenderLayer};
use gfx::render_task;
diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs
index 84508c470b6..e51095ae086 100644
--- a/src/components/main/layout/model.rs
+++ b/src/components/main/layout/model.rs
@@ -6,7 +6,7 @@
use std::num::Zero;
use geom::side_offsets::SideOffsets2D;
-use gfx::geometry::Au;
+use servo_util::geometry::Au;
use newcss::complete::CompleteStyle;
use newcss::units::{Length, Em, Px};
use newcss::values::{CSSBorderWidth, CSSBorderWidthLength, CSSBorderWidthMedium};
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs
index 4687205066d..62fab67b51c 100644
--- a/src/components/script/dom/document.rs
+++ b/src/components/script/dom/document.rs
@@ -24,7 +24,7 @@ use html::hubbub_html_parser::build_element_from_tag;
use js::jsapi::{JSObject, JSContext, JSVal};
use js::jsapi::{JSTRACE_OBJECT, JSTracer, JS_CallTracer};
use js::glue::RUST_OBJECT_TO_JSVAL;
-use servo_util::tree::TreeNodeRef;
+use servo_util::tree::{TreeNodeRef, ElementLike};
use std::hashmap::HashMap;
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index fd50118a9ec..fb6cb9e8d2a 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -14,6 +14,7 @@ use dom::node::{ElementNodeTypeId, Node, ScriptView, AbstractNode};
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
use layout_interface::{ContentBoxesResponse};
use newcss::stylesheet::Stylesheet;
+use servo_util::tree::{TreeNodeRef, ElementLike};
use js::jsapi::{JSContext, JSObject};
@@ -119,17 +120,12 @@ pub enum ElementTypeId {
// Element methods
//
-impl<'self> Element {
- pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> Element {
- Element {
- node: Node::new(ElementNodeTypeId(type_id), document),
- tag_name: tag_name,
- attrs: ~[],
- style_attribute: None,
- }
+impl ElementLike for Element {
+ fn get_local_name<'a>(&'a self) -> &'a str {
+ self.tag_name.as_slice()
}
- pub fn get_attr(&'self self, name: &str) -> Option<&'self str> {
+ fn get_attr<'a>(&'a self, name: &str) -> Option<&'a str> {
// FIXME: Need an each() that links lifetimes in Rust.
for attr in self.attrs.iter() {
// FIXME: only case-insensitive in the HTML namespace (as opposed to SVG, etc.)
@@ -140,6 +136,17 @@ impl<'self> Element {
}
return None;
}
+}
+
+impl<'self> Element {
+ pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> Element {
+ Element {
+ node: Node::new(ElementNodeTypeId(type_id), document),
+ tag_name: tag_name,
+ attrs: ~[],
+ style_attribute: None,
+ }
+ }
pub fn set_attr(&mut self,
abstract_self: AbstractNode<ScriptView>,
diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs
index fc521220ee3..77151d15d01 100644
--- a/src/components/script/dom/htmldocument.rs
+++ b/src/components/script/dom/htmldocument.rs
@@ -13,7 +13,7 @@ use dom::window::Window;
use js::jsapi::{JSObject, JSContext, JSTracer};
-use servo_util::tree::TreeNodeRef;
+use servo_util::tree::{TreeNodeRef, ElementLike};
use std::libc;
use std::ptr;
diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs
index 673886037e3..67ed8f3797d 100644
--- a/src/components/script/dom/htmlimageelement.rs
+++ b/src/components/script/dom/htmlimageelement.rs
@@ -6,11 +6,12 @@ use dom::bindings::utils::{DOMString, ErrorResult, null_str_as_empty};
use dom::htmlelement::HTMLElement;
use dom::node::{ScriptView, AbstractNode};
use extra::url::Url;
-use gfx::geometry::to_px;
+use servo_util::geometry::to_px;
use layout_interface::{ContentBoxQuery, ContentBoxResponse};
use servo_net::image_cache_task;
use servo_net::image_cache_task::ImageCacheTask;
use servo_util::url::make_url;
+use servo_util::tree::ElementLike;
pub struct HTMLImageElement {
htmlelement: HTMLElement,
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index e8b5eb3fc16..6d841922f97 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -25,7 +25,7 @@ use extra::arc::Arc;
use js::jsapi::{JSObject, JSContext};
use netsurfcss::util::VoidPtrLike;
use newcss::complete::CompleteSelectResults;
-use servo_util::tree::{TreeNode, TreeNodeRef};
+use servo_util::tree::{TreeNode, TreeNodeRef, TreeNodeRefAsElement};
use servo_util::range::Range;
use gfx::display_list::DisplayList;
@@ -154,8 +154,23 @@ impl<View> TreeNodeRef<Node<View>> for AbstractNode<View> {
fn with_mut_base<R>(&self, callback: &fn(&mut Node<View>) -> R) -> R {
self.transmute_mut(callback)
}
+
+ fn is_element(&self) -> bool {
+ match self.type_id() {
+ ElementNodeTypeId(*) => true,
+ _ => false
+ }
+ }
+}
+
+impl<View> TreeNodeRefAsElement<Node<View>, Element> for AbstractNode<View> {
+ #[inline]
+ fn with_imm_element_like<R>(&self, f: &fn(&Element) -> R) -> R {
+ self.with_imm_element(f)
+ }
}
+
impl<View> TreeNode<AbstractNode<View>> for Node<View> { }
impl<'self, View> AbstractNode<View> {
@@ -309,13 +324,6 @@ impl<'self, View> AbstractNode<View> {
self.transmute_mut(f)
}
- pub fn is_element(self) -> bool {
- match self.type_id() {
- ElementNodeTypeId(*) => true,
- _ => false
- }
- }
-
// FIXME: This should be doing dynamic borrow checking for safety.
pub fn with_imm_element<R>(self, f: &fn(&Element) -> R) -> R {
if !self.is_element() {
diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs
index e5ccb6f2e83..9bfdc98fb42 100644
--- a/src/components/script/html/hubbub_html_parser.rs
+++ b/src/components/script/html/hubbub_html_parser.rs
@@ -26,7 +26,7 @@ use hubbub::hubbub;
use servo_msg::constellation_msg::{ConstellationChan, SubpageId};
use servo_net::image_cache_task::ImageCacheTask;
use servo_net::resource_task::{Load, Payload, Done, ResourceTask};
-use servo_util::tree::TreeNodeRef;
+use servo_util::tree::{TreeNodeRef, ElementLike};
use servo_util::url::make_url;
use extra::url::Url;
use extra::future::{Future, from_port};
diff --git a/src/components/script/layout_interface.rs b/src/components/script/layout_interface.rs
index ce7e6b5bd36..2349611ebaf 100644
--- a/src/components/script/layout_interface.rs
+++ b/src/components/script/layout_interface.rs
@@ -12,7 +12,7 @@ use std::comm::{Chan, SharedChan};
use geom::rect::Rect;
use geom::size::Size2D;
use geom::point::Point2D;
-use gfx::geometry::Au;
+use servo_util::geometry::Au;
use newcss::stylesheet::Stylesheet;
use extra::url::Url;
diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs
index 31a0bd6eb9d..9897be2b013 100644
--- a/src/components/script/script_task.rs
+++ b/src/components/script/script_task.rs
@@ -46,7 +46,7 @@ use js::rust::{Compartment, Cx};
use js;
use servo_net::image_cache_task::ImageCacheTask;
use servo_net::resource_task::ResourceTask;
-use servo_util::tree::TreeNodeRef;
+use servo_util::tree::{TreeNodeRef, ElementLike};
use servo_util::url::make_url;
use extra::url::Url;
use extra::future::{from_value, Future};
diff --git a/src/components/style/common_types.rs b/src/components/style/common_types.rs
index e7b54f0232b..48cbafa51ed 100644
--- a/src/components/style/common_types.rs
+++ b/src/components/style/common_types.rs
@@ -2,19 +2,20 @@
* 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/. */
+pub use servo_util::geometry::Au;
+
pub type Float = f64;
-pub type Integer = i64;
pub mod specified {
use std::ascii::StrAsciiExt;
use cssparser::*;
- use super::{Integer, Float};
+ use super::{Au, Float};
pub use CSSColor = cssparser::Color;
#[deriving(Clone)]
pub enum Length {
- Au(Integer), // application units
+ Au_(Au), // application units
Em(Float),
Ex(Float),
// XXX uncomment when supported:
@@ -37,7 +38,7 @@ pub mod specified {
match input {
&Dimension(ref value, ref unit) if negative_ok || value.value >= 0.
=> Length::parse_dimension(value.value, unit.as_slice()),
- &Number(ref value) if value.value == 0. => Some(Au(0)),
+ &Number(ref value) if value.value == 0. => Some(Au_(Au(0))),
_ => None
}
}
@@ -50,11 +51,11 @@ pub mod specified {
pub fn parse_dimension(value: Float, unit: &str) -> Option<Length> {
match unit.to_ascii_lower().as_slice() {
"px" => Some(Length::from_px(value)),
- "in" => Some(Au((value * AU_PER_IN) as Integer)),
- "cm" => Some(Au((value * AU_PER_CM) as Integer)),
- "mm" => Some(Au((value * AU_PER_MM) as Integer)),
- "pt" => Some(Au((value * AU_PER_PT) as Integer)),
- "pc" => Some(Au((value * AU_PER_PC) as Integer)),
+ "in" => Some(Au_(Au((value * AU_PER_IN) as i32))),
+ "cm" => Some(Au_(Au((value * AU_PER_CM) as i32))),
+ "mm" => Some(Au_(Au((value * AU_PER_MM) as i32))),
+ "pt" => Some(Au_(Au((value * AU_PER_PT) as i32))),
+ "pc" => Some(Au_(Au((value * AU_PER_PC) as i32))),
"em" => Some(Em(value)),
"ex" => Some(Ex(value)),
_ => None
@@ -62,7 +63,7 @@ pub mod specified {
}
#[inline]
pub fn from_px(px_value: Float) -> Length {
- Au((px_value * AU_PER_PX) as Integer)
+ Au_(Au((px_value * AU_PER_PX) as i32))
}
}
@@ -79,7 +80,7 @@ pub mod specified {
=> Length::parse_dimension(value.value, unit.as_slice()).map_move(LP_Length),
&ast::Percentage(ref value) if negative_ok || value.value >= 0.
=> Some(LP_Percentage(value.value / 100.)),
- &Number(ref value) if value.value == 0. => Some(LP_Length(Au(0))),
+ &Number(ref value) if value.value == 0. => Some(LP_Length(Au_(Au(0)))),
_ => None
}
}
@@ -107,7 +108,7 @@ pub mod specified {
=> Length::parse_dimension(value.value, unit.as_slice()).map_move(LPA_Length),
&ast::Percentage(ref value) if negative_ok || value.value >= 0.
=> Some(LPA_Percentage(value.value / 100.)),
- &Number(ref value) if value.value == 0. => Some(LPA_Length(Au(0))),
+ &Number(ref value) if value.value == 0. => Some(LPA_Length(Au_(Au(0)))),
&Ident(ref value) if value.eq_ignore_ascii_case("auto") => Some(LPA_Auto),
_ => None
}
@@ -129,9 +130,11 @@ pub mod computed {
pub use compute_CSSColor = super::super::longhands::computed_as_specified;
use super::*;
use super::super::longhands;
+ pub use servo_util::geometry::Au;
+
pub struct Context {
current_color: cssparser::RGBA,
- font_size: Length,
+ font_size: Au,
font_weight: longhands::font_weight::ComputedValue,
position: longhands::position::SpecifiedValue,
float: longhands::float::SpecifiedValue,
@@ -142,48 +145,44 @@ pub mod computed {
has_border_left: bool,
// TODO, as needed: root font size, viewport size, etc.
}
- #[deriving(Clone)]
- pub struct Length(Integer); // in application units
- impl Length {
- pub fn times(self, factor: Float) -> Length {
- Length(((*self as Float) * factor) as Integer)
- }
- }
- pub fn compute_Length(value: specified::Length, context: &Context) -> Length {
+ #[inline]
+ fn mul(a: Au, b: Float) -> Au { Au(((*a as Float) * b) as i32) }
+
+ pub fn compute_Au(value: specified::Length, context: &Context) -> Au {
match value {
- specified::Au(value) => Length(value),
- specified::Em(value) => context.font_size.times(value),
+ specified::Au_(value) => value,
+ specified::Em(value) => mul(context.font_size, value),
specified::Ex(value) => {
let x_height = 0.5; // TODO: find that from the font
- context.font_size.times(value * x_height)
+ mul(context.font_size, value * x_height)
},
}
}
#[deriving(Clone)]
pub enum LengthOrPercentage {
- LP_Length(Length),
+ LP_Length(Au),
LP_Percentage(Float),
}
pub fn compute_LengthOrPercentage(value: specified::LengthOrPercentage, context: &Context)
-> LengthOrPercentage {
match value {
- specified::LP_Length(value) => LP_Length(compute_Length(value, context)),
+ specified::LP_Length(value) => LP_Length(compute_Au(value, context)),
specified::LP_Percentage(value) => LP_Percentage(value),
}
}
#[deriving(Clone)]
pub enum LengthOrPercentageOrAuto {
- LPA_Length(Length),
+ LPA_Length(Au),
LPA_Percentage(Float),
LPA_Auto,
}
pub fn compute_LengthOrPercentageOrAuto(value: specified::LengthOrPercentageOrAuto,
context: &Context) -> LengthOrPercentageOrAuto {
match value {
- specified::LPA_Length(value) => LPA_Length(compute_Length(value, context)),
+ specified::LPA_Length(value) => LPA_Length(compute_Au(value, context)),
specified::LPA_Percentage(value) => LPA_Percentage(value),
specified::LPA_Auto => LPA_Auto,
}
diff --git a/src/components/style/properties.rs.mako b/src/components/style/properties.rs.mako
index 871a6b34af2..b8ea608b212 100644
--- a/src/components/style/properties.rs.mako
+++ b/src/components/style/properties.rs.mako
@@ -146,14 +146,14 @@ pub mod longhands {
% for side in ["top", "right", "bottom", "left"]:
${predefined_type("margin-" + side, "LengthOrPercentageOrAuto",
- "computed::LPA_Length(computed::Length(0))")}
+ "computed::LPA_Length(Au(0))")}
% endfor
${new_style_struct("Padding")}
% for side in ["top", "right", "bottom", "left"]:
${predefined_type("padding-" + side, "LengthOrPercentage",
- "computed::LP_Length(computed::Length(0))",
+ "computed::LP_Length(Au(0))",
"parse_non_negative")}
% endfor
@@ -187,17 +187,17 @@ pub mod longhands {
% for side in ["top", "right", "bottom", "left"]:
<%self:longhand name="border-${side}-width">
pub type SpecifiedValue = specified::Length;
- pub type ComputedValue = computed::Length;
+ pub type ComputedValue = Au;
#[inline] pub fn get_initial_value() -> ComputedValue {
- computed::Length(3 * 60) // medium
+ Au::from_px(3) // medium
}
pub fn parse(input: &[ComponentValue]) -> Option<SpecifiedValue> {
one_component_value(input).chain(parse_border_width)
}
pub fn to_computed_value(value: SpecifiedValue, context: &computed::Context)
-> ComputedValue {
- if context.has_border_${side} { computed::compute_Length(value, context) }
- else { computed::Length(0) }
+ if context.has_border_${side} { computed::compute_Au(value, context) }
+ else { Au(0) }
}
</%self:longhand>
% endfor
@@ -252,7 +252,7 @@ pub mod longhands {
#[deriving(Clone)]
pub enum ComputedValue {
Normal,
- Length(computed::Length),
+ Length(Au),
Number(Float),
}
#[inline] pub fn get_initial_value() -> ComputedValue { Normal }
@@ -260,7 +260,7 @@ pub mod longhands {
-> ComputedValue {
match value {
SpecifiedNormal => Normal,
- SpecifiedLength(value) => Length(computed::compute_Length(value, context)),
+ SpecifiedLength(value) => Length(computed::compute_Au(value, context)),
SpecifiedNumber(value) => Number(value),
}
}
@@ -295,7 +295,7 @@ pub mod longhands {
% for keyword in vertical_align_keywords:
${to_rust_ident(keyword)},
% endfor
- Length(computed::Length),
+ Length(Au),
Percentage(Float),
}
#[inline] pub fn get_initial_value() -> ComputedValue { baseline }
@@ -502,11 +502,11 @@ pub mod longhands {
</%self:single_component_value>
<%self:single_component_value name="font-size" inherited="True">
- pub use to_computed_value = super::super::common_types::computed::compute_Length;
+ pub use to_computed_value = super::super::common_types::computed::compute_Au;
pub type SpecifiedValue = specified::Length; // Percentages are the same as em.
- pub type ComputedValue = computed::Length;
+ pub type ComputedValue = Au;
#[inline] pub fn get_initial_value() -> ComputedValue {
- computed::Length(16 * 60) // medium
+ Au::from_px(16) // medium
}
/// <length> | <percentage>
/// TODO: support <absolute-size> and <relative-size>
diff --git a/src/components/style/selector_matching.rs b/src/components/style/selector_matching.rs
index 9ce4325291b..f40cfe5c8e6 100644
--- a/src/components/style/selector_matching.rs
+++ b/src/components/style/selector_matching.rs
@@ -8,9 +8,8 @@ use extra::sort::tim_sort;
use selectors::*;
use stylesheets::parse_stylesheet;
use media_queries::{Device, Screen};
-use properties::{ComputedValues, cascade, PropertyDeclaration};
-use script::dom::node::{AbstractNode, ScriptView};
-use script::dom::element::Element;
+use properties::{PropertyDeclaration, PropertyDeclarationBlock};
+use servo_util::tree::{TreeNodeRefAsElement, TreeNode, ElementLike};
pub enum StylesheetOrigin {
@@ -77,26 +76,18 @@ impl Stylist {
}
}
- pub fn get_computed_style(&self, element: AbstractNode<ScriptView>,
- parent_style: Option<&ComputedValues>,
- pseudo_element: Option<PseudoElement>)
- -> ComputedValues {
+ pub fn get_applicable_declarations<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: ElementLike>(
+ &self, element: &T, style_attribute: Option<&PropertyDeclarationBlock>,
+ pseudo_element: Option<PseudoElement>) -> ~[@[PropertyDeclaration]] {
assert!(element.is_element())
- // Only the root does not inherit.
- // The root has no parent or a non-element parent.
- assert_eq!(
- parent_style.is_none(),
- match element.parent_node() {
- None => true,
- Some(ref node) => !node.is_element()
- }
- );
+ assert!(style_attribute.is_none() || pseudo_element.is_none(),
+ "Style attributes do not apply to pseudo-elements")
let mut applicable_declarations = ~[]; // TODO: use an iterator?
macro_rules! append(
($rules: expr) => {
for rule in $rules.iter() {
- if matches_selector(rule.selector, element, pseudo_element) {
+ if matches_selector::<N, T, E>(rule.selector, element, pseudo_element) {
applicable_declarations.push(rule.declarations)
}
}
@@ -106,13 +97,18 @@ impl Stylist {
// In cascading order
append!(self.ua_rules.normal);
append!(self.user_rules.normal);
+
+ // Style attributes have author origin but higher specificity than style rules.
append!(self.author_rules.normal);
- // TODO add style attribute
+ style_attribute.map(|sa| applicable_declarations.push(sa.normal));
+
append!(self.author_rules.important);
+ style_attribute.map(|sa| applicable_declarations.push(sa.important));
+
append!(self.user_rules.important);
append!(self.ua_rules.important);
- cascade(applicable_declarations, parent_style)
+ applicable_declarations
}
}
@@ -145,16 +141,16 @@ impl Ord for Rule {
#[inline]
-fn matches_selector(selector: &Selector, element: AbstractNode<ScriptView>,
- pseudo_element: Option<PseudoElement>) -> bool {
+fn matches_selector<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: ElementLike>(
+ selector: &Selector, element: &T, pseudo_element: Option<PseudoElement>) -> bool {
selector.pseudo_element == pseudo_element &&
- matches_compound_selector(&selector.compound_selectors, element)
+ matches_compound_selector::<N, T, E>(&selector.compound_selectors, element)
}
-fn matches_compound_selector(selector: &CompoundSelector,
- element: AbstractNode<ScriptView>) -> bool {
- if do element.with_imm_element |element| {
+fn matches_compound_selector<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: ElementLike>(
+ selector: &CompoundSelector, element: &T) -> bool {
+ if do element.with_imm_element_like |element: &E| {
!do selector.simple_selectors.iter().all |simple_selector| {
matches_simple_selector(simple_selector, element)
}
@@ -170,14 +166,17 @@ fn matches_compound_selector(selector: &CompoundSelector,
NextSibling => (true, true),
LaterSibling => (true, false),
};
- let mut node = element;
+ let mut node = element.clone();
loop {
- match if siblings { node.prev_sibling() } else { node.parent_node() } {
+ let next_node = do node.with_base |node| {
+ if siblings { node.prev_sibling() } else { node.parent_node() }
+ };
+ match next_node {
None => return false,
Some(next_node) => node = next_node,
}
if node.is_element() {
- if matches_compound_selector(&**next_selector, node) {
+ if matches_compound_selector(&**next_selector, &node) {
return true
} else if just_one {
return false
@@ -189,12 +188,14 @@ fn matches_compound_selector(selector: &CompoundSelector,
}
#[inline]
-fn matches_simple_selector(selector: &SimpleSelector, element: &Element) -> bool {
+fn matches_simple_selector<E: ElementLike>(selector: &SimpleSelector, element: &E) -> bool {
static WHITESPACE: &'static [char] = &'static [' ', '\t', '\n', '\r', '\x0C'];
match *selector {
// TODO: case-sensitivity depends on the document type
- LocalNameSelector(ref name) => element.tag_name.eq_ignore_ascii_case(name.as_slice()),
+ // TODO: intern element names
+ LocalNameSelector(ref name)
+ => element.get_local_name().eq_ignore_ascii_case(name.as_slice()),
NamespaceSelector(_) => false, // TODO, when the DOM supports namespaces on elements.
// TODO: case-sensitivity depends on the document type and quirks mode
// TODO: cache and intern IDs on elements.
@@ -234,7 +235,7 @@ fn matches_simple_selector(selector: &SimpleSelector, element: &Element) -> bool
#[inline]
-fn match_attribute(attr: &AttrSelector, element: &Element, f: &fn(&str)-> bool) -> bool {
+fn match_attribute<E: ElementLike>(attr: &AttrSelector, element: &E, f: &fn(&str)-> bool) -> bool {
match attr.namespace {
Some(_) => false, // TODO, when the DOM supports namespaces on attributes
None => match element.get_attr(attr.name) {
diff --git a/src/components/style/style.rc b/src/components/style/style.rc
index 2944f074402..3527f3e9fea 100644
--- a/src/components/style/style.rc
+++ b/src/components/style/style.rc
@@ -14,11 +14,14 @@
extern mod extra;
extern mod cssparser;
-extern mod script;
+extern mod servo_util (name = "util");
// The "real" public API
pub use self::selector_matching::{Stylist, StylesheetOrigin};
+pub use self::properties::cascade;
+pub use self::properties::{PropertyDeclarationBlock,
+ parse_property_declaration_list}; // Style attributes
// Things that need to be public to make the compiler happy
diff --git a/src/components/gfx/geometry.rs b/src/components/util/geometry.rs
index b89d0f29343..b89d0f29343 100644
--- a/src/components/gfx/geometry.rs
+++ b/src/components/util/geometry.rs
diff --git a/src/components/util/tree.rs b/src/components/util/tree.rs
index 2b3b467ac45..96ef2c77c86 100644
--- a/src/components/util/tree.rs
+++ b/src/components/util/tree.rs
@@ -248,6 +248,12 @@ pub trait TreeNodeRef<Node>: Clone {
gather(self, &mut nodes, true, prune);
TreeIterator::new(nodes)
}
+
+ fn is_element(&self) -> bool;
+}
+
+pub trait TreeNodeRefAsElement<Node, E: ElementLike>: TreeNodeRef<Node> {
+ fn with_imm_element_like<R>(&self, f: &fn(&E) -> R) -> R;
}
fn gather<Node, Ref: TreeNodeRef<Node>>(cur: &Ref, refs: &mut ~[Ref],
@@ -324,3 +330,9 @@ pub trait TreeNode<Ref: TreeNodeRef<Self>> {
TreeNodeRef::<Self>::set_next_sibling(self, new_next_sibling)
}
}
+
+
+pub trait ElementLike {
+ fn get_local_name<'a>(&'a self) -> &'a str;
+ fn get_attr<'a>(&'a self, name: &str) -> Option<&'a str>;
+}
diff --git a/src/components/util/util.rc b/src/components/util/util.rc
index 44f3b13c0ac..946ffb21f4a 100644
--- a/src/components/util/util.rc
+++ b/src/components/util/util.rc
@@ -9,8 +9,10 @@
#[crate_type = "lib"];
extern mod extra;
+extern mod geom;
pub mod cache;
+pub mod geometry;
pub mod range;
pub mod time;
pub mod tree;