mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
auto merge of #1075 : SimonSapin/servo/newnewcss, r=kmcallister
I believe this is all the preparatory work discussed in #1006 and #1057: The new 'style' crate implements the whole style system (including parsing, matching and cascading) and only depends on cssparser and util, so that gfx, script and main can all depend on it. Next: porting the layout code to this. (Really, this time! I think.)
This commit is contained in:
commit
6db57e6f72
38 changed files with 161 additions and 125 deletions
|
@ -235,7 +235,7 @@ DONE_script = $(B)src/components/script/libscript.dummy
|
|||
|
||||
DEPS_script = $(CRATE_script) $(SRC_script) $(DONE_SUBMODULES) $(DONE_util) $(DONE_net) $(DONE_gfx) $(DONE_msg)
|
||||
|
||||
RFLAGS_style = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util -L $(B)src/components/script -L $(B)src/components/gfx -L $(B)src/components/net -L $(B)src/components/msg
|
||||
RFLAGS_style = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util
|
||||
MAKO_ZIP = $(S)src/components/style/Mako-0.8.1.zip
|
||||
MAKO_style = $(S)src/components/style/properties.rs
|
||||
MAKO_SRC_style = $(MAKO_style).mako
|
||||
|
@ -243,8 +243,7 @@ SRC_style = $(call rwildcard,$(S)src/components/style/,*.rs) $(MAKO_style)
|
|||
CRATE_style = $(S)src/components/style/style.rc
|
||||
DONE_style = $(B)src/components/style/libstyle.dummy
|
||||
|
||||
# TODO: reverse the dependency with script
|
||||
DEPS_style = $(CRATE_style) $(SRC_style) $(DONE_SUBMODULES) $(DONE_util) $(DONE_script)
|
||||
DEPS_style = $(CRATE_style) $(SRC_style) $(DONE_SUBMODULES) $(DONE_util)
|
||||
|
||||
RFLAGS_servo = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/gfx -L $(B)src/components/util -L $(B)src/components/net -L $(B)src/components/script -L $(B)src/components/style -L $(B)src/components/msg
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -41,7 +41,6 @@ mod render_context;
|
|||
// Rendering
|
||||
pub mod color;
|
||||
pub mod display_list;
|
||||
pub mod geometry;
|
||||
pub mod render_task;
|
||||
pub mod surface;
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue