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)
|
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_ZIP = $(S)src/components/style/Mako-0.8.1.zip
|
||||||
MAKO_style = $(S)src/components/style/properties.rs
|
MAKO_style = $(S)src/components/style/properties.rs
|
||||||
MAKO_SRC_style = $(MAKO_style).mako
|
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
|
CRATE_style = $(S)src/components/style/style.rc
|
||||||
DONE_style = $(B)src/components/style/libstyle.dummy
|
DONE_style = $(B)src/components/style/libstyle.dummy
|
||||||
|
|
||||||
# TODO: reverse the dependency with script
|
DEPS_style = $(CRATE_style) $(SRC_style) $(DONE_SUBMODULES) $(DONE_util)
|
||||||
DEPS_style = $(CRATE_style) $(SRC_style) $(DONE_SUBMODULES) $(DONE_util) $(DONE_script)
|
|
||||||
|
|
||||||
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
|
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.
|
/// low-level drawing primitives.
|
||||||
|
|
||||||
use color::Color;
|
use color::Color;
|
||||||
use geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use newcss::values::CSSBorderStyle;
|
use newcss::values::CSSBorderStyle;
|
||||||
use render_context::RenderContext;
|
use render_context::RenderContext;
|
||||||
use text::SendableTextRun;
|
use text::SendableTextRun;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use color::Color;
|
use color::Color;
|
||||||
use font_context::FontContext;
|
use font_context::FontContext;
|
||||||
use geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use platform::font_context::FontContextHandle;
|
use platform::font_context::FontContextHandle;
|
||||||
use platform::font::{FontHandle, FontTable};
|
use platform::font::{FontHandle, FontTable};
|
||||||
use render_context::RenderContext;
|
use render_context::RenderContext;
|
||||||
|
|
|
@ -41,7 +41,6 @@ mod render_context;
|
||||||
// Rendering
|
// Rendering
|
||||||
pub mod color;
|
pub mod color;
|
||||||
pub mod display_list;
|
pub mod display_list;
|
||||||
pub mod geometry;
|
|
||||||
pub mod render_task;
|
pub mod render_task;
|
||||||
pub mod surface;
|
pub mod surface;
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
|
||||||
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
|
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
|
||||||
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
|
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
|
||||||
use font::{FontWeight700, FontWeight800, FontWeight900};
|
use font::{FontWeight700, FontWeight800, FontWeight900};
|
||||||
use geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use geometry;
|
use servo_util::geometry;
|
||||||
use platform::font_context::FontContextHandle;
|
use platform::font_context::FontContextHandle;
|
||||||
use text::glyph::GlyphIndex;
|
use text::glyph::GlyphIndex;
|
||||||
use text::util::{float_to_fixed, fixed_to_float};
|
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::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
|
||||||
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
|
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
|
||||||
use font::{FontWeight700, FontWeight800, FontWeight900};
|
use font::{FontWeight700, FontWeight800, FontWeight900};
|
||||||
use geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use geometry;
|
use servo_util::geometry;
|
||||||
use platform::font_context::FontContextHandle;
|
use platform::font_context::FontContextHandle;
|
||||||
use text::glyph::GlyphIndex;
|
use text::glyph::GlyphIndex;
|
||||||
use text::util::{float_to_fixed, fixed_to_float};
|
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::{FontTableTag, FontWeight100, FontWeight200, FontWeight300, FontWeight400};
|
||||||
use font::{FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900};
|
use font::{FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900};
|
||||||
use font::{FractionalPixel, SpecifiedFontStyle};
|
use font::{FractionalPixel, SpecifiedFontStyle};
|
||||||
use geometry::{Au, px_to_pt};
|
use servo_util::geometry::{Au, px_to_pt};
|
||||||
use geometry;
|
use servo_util::geometry;
|
||||||
use platform::macos::font_context::FontContextHandle;
|
use platform::macos::font_context::FontContextHandle;
|
||||||
use text::glyph::GlyphIndex;
|
use text::glyph::GlyphIndex;
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
* 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 servo_msg::compositor_msg::LayerBuffer;
|
use servo_msg::compositor_msg::LayerBuffer;
|
||||||
|
use servo_util::geometry::Au;
|
||||||
use font_context::FontContext;
|
use font_context::FontContext;
|
||||||
use geometry::Au;
|
|
||||||
use newcss::values::CSSBorderStyle;
|
use newcss::values::CSSBorderStyle;
|
||||||
use newcss::values::{CSSBorderStyleNone, CSSBorderStyleHidden, CSSBorderStyleDotted, CSSBorderStyleDashed, CSSBorderStyleSolid, CSSBorderStyleDouble, CSSBorderStyleGroove, CSSBorderStyleRidge, CSSBorderStyleInset, CSSBorderStyleOutset};
|
use newcss::values::{CSSBorderStyleNone, CSSBorderStyleHidden, CSSBorderStyleDotted, CSSBorderStyleDashed, CSSBorderStyleSolid, CSSBorderStyleDouble, CSSBorderStyleGroove, CSSBorderStyleRidge, CSSBorderStyleInset, CSSBorderStyleOutset};
|
||||||
use opts::Opts;
|
use opts::Opts;
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
|
|
||||||
use servo_util::vec::*;
|
use servo_util::vec::*;
|
||||||
use servo_util::range::Range;
|
use servo_util::range::Range;
|
||||||
|
use servo_util::geometry::Au;
|
||||||
use geometry::Au;
|
use servo_util::geometry;
|
||||||
use geometry;
|
|
||||||
|
|
||||||
use std::cmp::{Ord, Eq};
|
use std::cmp::{Ord, Eq};
|
||||||
use std::num::NumCast;
|
use std::num::NumCast;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
extern mod harfbuzz;
|
extern mod harfbuzz;
|
||||||
|
|
||||||
use font::{Font, FontHandleMethods, FontTableMethods, FontTableTag};
|
use font::{Font, FontHandleMethods, FontTableMethods, FontTableTag};
|
||||||
use geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use platform::font::FontTable;
|
use platform::font::FontTable;
|
||||||
use text::glyph::{GlyphStore, GlyphIndex, GlyphData};
|
use text::glyph::{GlyphStore, GlyphIndex, GlyphData};
|
||||||
use text::shaping::ShaperMethods;
|
use text::shaping::ShaperMethods;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use std::vec::VecIterator;
|
use std::vec::VecIterator;
|
||||||
|
|
||||||
use font_context::FontContext;
|
use font_context::FontContext;
|
||||||
use geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use text::glyph::GlyphStore;
|
use text::glyph::GlyphStore;
|
||||||
use font::{Font, FontDescriptor, RunMetrics};
|
use font::{Font, FontDescriptor, RunMetrics};
|
||||||
use servo_util::range::Range;
|
use servo_util::range::Range;
|
||||||
|
|
|
@ -9,6 +9,8 @@ use layout::incremental::RestyleDamage;
|
||||||
|
|
||||||
use newcss::complete::CompleteStyle;
|
use newcss::complete::CompleteStyle;
|
||||||
use script::dom::node::{AbstractNode, LayoutView};
|
use script::dom::node::{AbstractNode, LayoutView};
|
||||||
|
use servo_util::tree::TreeNodeRef;
|
||||||
|
|
||||||
|
|
||||||
/// Node mixin providing `style` method that returns a `NodeStyle`
|
/// Node mixin providing `style` method that returns a `NodeStyle`
|
||||||
pub trait StyledNode {
|
pub trait StyledNode {
|
||||||
|
|
|
@ -8,6 +8,8 @@ use std::cast;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use newcss::complete::CompleteSelectResults;
|
use newcss::complete::CompleteSelectResults;
|
||||||
use script::dom::node::{AbstractNode, LayoutView};
|
use script::dom::node::{AbstractNode, LayoutView};
|
||||||
|
use servo_util::tree::TreeNodeRef;
|
||||||
|
|
||||||
|
|
||||||
pub trait NodeUtil<'self> {
|
pub trait NodeUtil<'self> {
|
||||||
fn get_css_select_results(self) -> &'self CompleteSelectResults;
|
fn get_css_select_results(self) -> &'self CompleteSelectResults;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
use std::str::eq_slice;
|
use std::str::eq_slice;
|
||||||
use newcss::select::SelectHandler;
|
use newcss::select::SelectHandler;
|
||||||
use script::dom::node::{AbstractNode, LayoutView};
|
use script::dom::node::{AbstractNode, LayoutView};
|
||||||
|
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||||
|
|
||||||
pub struct NodeSelectHandler {
|
pub struct NodeSelectHandler {
|
||||||
node: AbstractNode<LayoutView>,
|
node: AbstractNode<LayoutView>,
|
||||||
|
|
|
@ -17,8 +17,8 @@ use geom::point::Point2D;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use gfx::display_list::DisplayList;
|
use gfx::display_list::DisplayList;
|
||||||
use gfx::geometry::{Au, to_frac_px};
|
use servo_util::geometry::{Au, to_frac_px};
|
||||||
use gfx::geometry;
|
use servo_util::geometry;
|
||||||
|
|
||||||
pub struct BlockFlowData {
|
pub struct BlockFlowData {
|
||||||
/// Data common to all flows.
|
/// 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::{SolidColorDisplayItem, SolidColorDisplayItemClass, TextDisplayItem};
|
||||||
use gfx::display_list::{TextDisplayItemClass};
|
use gfx::display_list::{TextDisplayItemClass};
|
||||||
use gfx::font::{FontStyle, FontWeight300};
|
use gfx::font::{FontStyle, FontWeight300};
|
||||||
use gfx::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use gfx::text::text_run::TextRun;
|
use gfx::text::text_run::TextRun;
|
||||||
use newcss::color::rgb;
|
use newcss::color::rgb;
|
||||||
use newcss::complete::CompleteStyle;
|
use newcss::complete::CompleteStyle;
|
||||||
|
@ -38,6 +38,7 @@ use script::dom::node::{AbstractNode, LayoutView};
|
||||||
use servo_net::image::holder::ImageHolder;
|
use servo_net::image::holder::ImageHolder;
|
||||||
use servo_net::local_image_cache::LocalImageCache;
|
use servo_net::local_image_cache::LocalImageCache;
|
||||||
use servo_util::range::*;
|
use servo_util::range::*;
|
||||||
|
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||||
use extra::url::Url;
|
use extra::url::Url;
|
||||||
|
|
||||||
/// Render boxes (`struct RenderBox`) are the leaves of the layout tree. They cannot position
|
/// Render boxes (`struct RenderBox`) are the leaves of the layout tree. They cannot position
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use gfx::font_context::FontContext;
|
use gfx::font_context::FontContext;
|
||||||
use gfx::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use servo_net::local_image_cache::LocalImageCache;
|
use servo_net::local_image_cache::LocalImageCache;
|
||||||
|
|
||||||
/// Data needed by the layout task.
|
/// Data needed by the layout task.
|
||||||
|
|
|
@ -13,8 +13,8 @@ use std::cell::Cell;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use gfx::display_list::DisplayList;
|
use gfx::display_list::DisplayList;
|
||||||
use gfx::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use gfx::geometry;
|
use servo_util::geometry;
|
||||||
|
|
||||||
pub struct FloatFlowData {
|
pub struct FloatFlowData {
|
||||||
/// Data common to all flows.
|
/// Data common to all flows.
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use gfx::geometry::{Au, max, min};
|
use servo_util::geometry::{Au, max, min};
|
||||||
use std::util::replace;
|
use std::util::replace;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
use std::i32::max_value;
|
use std::i32::max_value;
|
||||||
|
|
|
@ -42,7 +42,7 @@ use std::io::stderr;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use gfx::display_list::DisplayList;
|
use gfx::display_list::DisplayList;
|
||||||
use gfx::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use script::dom::node::{AbstractNode, LayoutView};
|
use script::dom::node::{AbstractNode, LayoutView};
|
||||||
|
|
||||||
/// The type of the formatting context and data specific to each context, such as line box
|
/// 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 std::util;
|
||||||
use geom::{Point2D, Rect, Size2D};
|
use geom::{Point2D, Rect, Size2D};
|
||||||
use gfx::display_list::DisplayList;
|
use gfx::display_list::DisplayList;
|
||||||
use gfx::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use newcss::units::{Em, Px};
|
use newcss::units::{Em, Px};
|
||||||
use newcss::values::{CSSFontSizeLength};
|
use newcss::values::{CSSFontSizeLength};
|
||||||
use newcss::values::{CSSTextAlignLeft, CSSTextAlignCenter, CSSTextAlignRight, CSSTextAlignJustify};
|
use newcss::values::{CSSTextAlignLeft, CSSTextAlignCenter, CSSTextAlignRight, CSSTextAlignJustify};
|
||||||
|
|
|
@ -23,7 +23,7 @@ use geom::rect::Rect;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use gfx::display_list::DisplayList;
|
use gfx::display_list::DisplayList;
|
||||||
use gfx::font_context::FontContext;
|
use gfx::font_context::FontContext;
|
||||||
use gfx::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use gfx::opts::Opts;
|
use gfx::opts::Opts;
|
||||||
use gfx::render_task::{RenderMsg, RenderChan, RenderLayer};
|
use gfx::render_task::{RenderMsg, RenderChan, RenderLayer};
|
||||||
use gfx::render_task;
|
use gfx::render_task;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use std::num::Zero;
|
use std::num::Zero;
|
||||||
use geom::side_offsets::SideOffsets2D;
|
use geom::side_offsets::SideOffsets2D;
|
||||||
use gfx::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use newcss::complete::CompleteStyle;
|
use newcss::complete::CompleteStyle;
|
||||||
use newcss::units::{Length, Em, Px};
|
use newcss::units::{Length, Em, Px};
|
||||||
use newcss::values::{CSSBorderWidth, CSSBorderWidthLength, CSSBorderWidthMedium};
|
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::{JSObject, JSContext, JSVal};
|
||||||
use js::jsapi::{JSTRACE_OBJECT, JSTracer, JS_CallTracer};
|
use js::jsapi::{JSTRACE_OBJECT, JSTracer, JS_CallTracer};
|
||||||
use js::glue::RUST_OBJECT_TO_JSVAL;
|
use js::glue::RUST_OBJECT_TO_JSVAL;
|
||||||
use servo_util::tree::TreeNodeRef;
|
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||||
|
|
||||||
use std::hashmap::HashMap;
|
use std::hashmap::HashMap;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ use dom::node::{ElementNodeTypeId, Node, ScriptView, AbstractNode};
|
||||||
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
|
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
|
||||||
use layout_interface::{ContentBoxesResponse};
|
use layout_interface::{ContentBoxesResponse};
|
||||||
use newcss::stylesheet::Stylesheet;
|
use newcss::stylesheet::Stylesheet;
|
||||||
|
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||||
|
|
||||||
use js::jsapi::{JSContext, JSObject};
|
use js::jsapi::{JSContext, JSObject};
|
||||||
|
|
||||||
|
@ -119,17 +120,12 @@ pub enum ElementTypeId {
|
||||||
// Element methods
|
// Element methods
|
||||||
//
|
//
|
||||||
|
|
||||||
impl<'self> Element {
|
impl ElementLike for Element {
|
||||||
pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> Element {
|
fn get_local_name<'a>(&'a self) -> &'a str {
|
||||||
Element {
|
self.tag_name.as_slice()
|
||||||
node: Node::new(ElementNodeTypeId(type_id), document),
|
|
||||||
tag_name: tag_name,
|
|
||||||
attrs: ~[],
|
|
||||||
style_attribute: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
// FIXME: Need an each() that links lifetimes in Rust.
|
||||||
for attr in self.attrs.iter() {
|
for attr in self.attrs.iter() {
|
||||||
// FIXME: only case-insensitive in the HTML namespace (as opposed to SVG, etc.)
|
// FIXME: only case-insensitive in the HTML namespace (as opposed to SVG, etc.)
|
||||||
|
@ -140,6 +136,17 @@ impl<'self> Element {
|
||||||
}
|
}
|
||||||
return None;
|
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,
|
pub fn set_attr(&mut self,
|
||||||
abstract_self: AbstractNode<ScriptView>,
|
abstract_self: AbstractNode<ScriptView>,
|
||||||
|
|
|
@ -13,7 +13,7 @@ use dom::window::Window;
|
||||||
|
|
||||||
use js::jsapi::{JSObject, JSContext, JSTracer};
|
use js::jsapi::{JSObject, JSContext, JSTracer};
|
||||||
|
|
||||||
use servo_util::tree::TreeNodeRef;
|
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||||
|
|
||||||
use std::libc;
|
use std::libc;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
|
@ -6,11 +6,12 @@ use dom::bindings::utils::{DOMString, ErrorResult, null_str_as_empty};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{ScriptView, AbstractNode};
|
use dom::node::{ScriptView, AbstractNode};
|
||||||
use extra::url::Url;
|
use extra::url::Url;
|
||||||
use gfx::geometry::to_px;
|
use servo_util::geometry::to_px;
|
||||||
use layout_interface::{ContentBoxQuery, ContentBoxResponse};
|
use layout_interface::{ContentBoxQuery, ContentBoxResponse};
|
||||||
use servo_net::image_cache_task;
|
use servo_net::image_cache_task;
|
||||||
use servo_net::image_cache_task::ImageCacheTask;
|
use servo_net::image_cache_task::ImageCacheTask;
|
||||||
use servo_util::url::make_url;
|
use servo_util::url::make_url;
|
||||||
|
use servo_util::tree::ElementLike;
|
||||||
|
|
||||||
pub struct HTMLImageElement {
|
pub struct HTMLImageElement {
|
||||||
htmlelement: HTMLElement,
|
htmlelement: HTMLElement,
|
||||||
|
|
|
@ -25,7 +25,7 @@ use extra::arc::Arc;
|
||||||
use js::jsapi::{JSObject, JSContext};
|
use js::jsapi::{JSObject, JSContext};
|
||||||
use netsurfcss::util::VoidPtrLike;
|
use netsurfcss::util::VoidPtrLike;
|
||||||
use newcss::complete::CompleteSelectResults;
|
use newcss::complete::CompleteSelectResults;
|
||||||
use servo_util::tree::{TreeNode, TreeNodeRef};
|
use servo_util::tree::{TreeNode, TreeNodeRef, TreeNodeRefAsElement};
|
||||||
use servo_util::range::Range;
|
use servo_util::range::Range;
|
||||||
use gfx::display_list::DisplayList;
|
use gfx::display_list::DisplayList;
|
||||||
|
|
||||||
|
@ -154,7 +154,22 @@ impl<View> TreeNodeRef<Node<View>> for AbstractNode<View> {
|
||||||
fn with_mut_base<R>(&self, callback: &fn(&mut Node<View>) -> R) -> R {
|
fn with_mut_base<R>(&self, callback: &fn(&mut Node<View>) -> R) -> R {
|
||||||
self.transmute_mut(callback)
|
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<View> TreeNode<AbstractNode<View>> for Node<View> { }
|
||||||
|
|
||||||
|
@ -309,13 +324,6 @@ impl<'self, View> AbstractNode<View> {
|
||||||
self.transmute_mut(f)
|
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.
|
// FIXME: This should be doing dynamic borrow checking for safety.
|
||||||
pub fn with_imm_element<R>(self, f: &fn(&Element) -> R) -> R {
|
pub fn with_imm_element<R>(self, f: &fn(&Element) -> R) -> R {
|
||||||
if !self.is_element() {
|
if !self.is_element() {
|
||||||
|
|
|
@ -26,7 +26,7 @@ use hubbub::hubbub;
|
||||||
use servo_msg::constellation_msg::{ConstellationChan, SubpageId};
|
use servo_msg::constellation_msg::{ConstellationChan, SubpageId};
|
||||||
use servo_net::image_cache_task::ImageCacheTask;
|
use servo_net::image_cache_task::ImageCacheTask;
|
||||||
use servo_net::resource_task::{Load, Payload, Done, ResourceTask};
|
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 servo_util::url::make_url;
|
||||||
use extra::url::Url;
|
use extra::url::Url;
|
||||||
use extra::future::{Future, from_port};
|
use extra::future::{Future, from_port};
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::comm::{Chan, SharedChan};
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use gfx::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use newcss::stylesheet::Stylesheet;
|
use newcss::stylesheet::Stylesheet;
|
||||||
use extra::url::Url;
|
use extra::url::Url;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ use js::rust::{Compartment, Cx};
|
||||||
use js;
|
use js;
|
||||||
use servo_net::image_cache_task::ImageCacheTask;
|
use servo_net::image_cache_task::ImageCacheTask;
|
||||||
use servo_net::resource_task::ResourceTask;
|
use servo_net::resource_task::ResourceTask;
|
||||||
use servo_util::tree::TreeNodeRef;
|
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||||
use servo_util::url::make_url;
|
use servo_util::url::make_url;
|
||||||
use extra::url::Url;
|
use extra::url::Url;
|
||||||
use extra::future::{from_value, Future};
|
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
|
* 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/. */
|
||||||
|
|
||||||
|
pub use servo_util::geometry::Au;
|
||||||
|
|
||||||
pub type Float = f64;
|
pub type Float = f64;
|
||||||
pub type Integer = i64;
|
|
||||||
|
|
||||||
|
|
||||||
pub mod specified {
|
pub mod specified {
|
||||||
use std::ascii::StrAsciiExt;
|
use std::ascii::StrAsciiExt;
|
||||||
use cssparser::*;
|
use cssparser::*;
|
||||||
use super::{Integer, Float};
|
use super::{Au, Float};
|
||||||
pub use CSSColor = cssparser::Color;
|
pub use CSSColor = cssparser::Color;
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
pub enum Length {
|
pub enum Length {
|
||||||
Au(Integer), // application units
|
Au_(Au), // application units
|
||||||
Em(Float),
|
Em(Float),
|
||||||
Ex(Float),
|
Ex(Float),
|
||||||
// XXX uncomment when supported:
|
// XXX uncomment when supported:
|
||||||
|
@ -37,7 +38,7 @@ pub mod specified {
|
||||||
match input {
|
match input {
|
||||||
&Dimension(ref value, ref unit) if negative_ok || value.value >= 0.
|
&Dimension(ref value, ref unit) if negative_ok || value.value >= 0.
|
||||||
=> Length::parse_dimension(value.value, unit.as_slice()),
|
=> 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
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,11 +51,11 @@ pub mod specified {
|
||||||
pub fn parse_dimension(value: Float, unit: &str) -> Option<Length> {
|
pub fn parse_dimension(value: Float, unit: &str) -> Option<Length> {
|
||||||
match unit.to_ascii_lower().as_slice() {
|
match unit.to_ascii_lower().as_slice() {
|
||||||
"px" => Some(Length::from_px(value)),
|
"px" => Some(Length::from_px(value)),
|
||||||
"in" => Some(Au((value * AU_PER_IN) as Integer)),
|
"in" => Some(Au_(Au((value * AU_PER_IN) as i32))),
|
||||||
"cm" => Some(Au((value * AU_PER_CM) as Integer)),
|
"cm" => Some(Au_(Au((value * AU_PER_CM) as i32))),
|
||||||
"mm" => Some(Au((value * AU_PER_MM) as Integer)),
|
"mm" => Some(Au_(Au((value * AU_PER_MM) as i32))),
|
||||||
"pt" => Some(Au((value * AU_PER_PT) as Integer)),
|
"pt" => Some(Au_(Au((value * AU_PER_PT) as i32))),
|
||||||
"pc" => Some(Au((value * AU_PER_PC) as Integer)),
|
"pc" => Some(Au_(Au((value * AU_PER_PC) as i32))),
|
||||||
"em" => Some(Em(value)),
|
"em" => Some(Em(value)),
|
||||||
"ex" => Some(Ex(value)),
|
"ex" => Some(Ex(value)),
|
||||||
_ => None
|
_ => None
|
||||||
|
@ -62,7 +63,7 @@ pub mod specified {
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_px(px_value: Float) -> Length {
|
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),
|
=> Length::parse_dimension(value.value, unit.as_slice()).map_move(LP_Length),
|
||||||
&ast::Percentage(ref value) if negative_ok || value.value >= 0.
|
&ast::Percentage(ref value) if negative_ok || value.value >= 0.
|
||||||
=> Some(LP_Percentage(value.value / 100.)),
|
=> 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
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +108,7 @@ pub mod specified {
|
||||||
=> Length::parse_dimension(value.value, unit.as_slice()).map_move(LPA_Length),
|
=> Length::parse_dimension(value.value, unit.as_slice()).map_move(LPA_Length),
|
||||||
&ast::Percentage(ref value) if negative_ok || value.value >= 0.
|
&ast::Percentage(ref value) if negative_ok || value.value >= 0.
|
||||||
=> Some(LPA_Percentage(value.value / 100.)),
|
=> 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),
|
&Ident(ref value) if value.eq_ignore_ascii_case("auto") => Some(LPA_Auto),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
|
@ -129,9 +130,11 @@ pub mod computed {
|
||||||
pub use compute_CSSColor = super::super::longhands::computed_as_specified;
|
pub use compute_CSSColor = super::super::longhands::computed_as_specified;
|
||||||
use super::*;
|
use super::*;
|
||||||
use super::super::longhands;
|
use super::super::longhands;
|
||||||
|
pub use servo_util::geometry::Au;
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
current_color: cssparser::RGBA,
|
current_color: cssparser::RGBA,
|
||||||
font_size: Length,
|
font_size: Au,
|
||||||
font_weight: longhands::font_weight::ComputedValue,
|
font_weight: longhands::font_weight::ComputedValue,
|
||||||
position: longhands::position::SpecifiedValue,
|
position: longhands::position::SpecifiedValue,
|
||||||
float: longhands::float::SpecifiedValue,
|
float: longhands::float::SpecifiedValue,
|
||||||
|
@ -142,48 +145,44 @@ pub mod computed {
|
||||||
has_border_left: bool,
|
has_border_left: bool,
|
||||||
// TODO, as needed: root font size, viewport size, etc.
|
// 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 {
|
match value {
|
||||||
specified::Au(value) => Length(value),
|
specified::Au_(value) => value,
|
||||||
specified::Em(value) => context.font_size.times(value),
|
specified::Em(value) => mul(context.font_size, value),
|
||||||
specified::Ex(value) => {
|
specified::Ex(value) => {
|
||||||
let x_height = 0.5; // TODO: find that from the font
|
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)]
|
#[deriving(Clone)]
|
||||||
pub enum LengthOrPercentage {
|
pub enum LengthOrPercentage {
|
||||||
LP_Length(Length),
|
LP_Length(Au),
|
||||||
LP_Percentage(Float),
|
LP_Percentage(Float),
|
||||||
}
|
}
|
||||||
pub fn compute_LengthOrPercentage(value: specified::LengthOrPercentage, context: &Context)
|
pub fn compute_LengthOrPercentage(value: specified::LengthOrPercentage, context: &Context)
|
||||||
-> LengthOrPercentage {
|
-> LengthOrPercentage {
|
||||||
match value {
|
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),
|
specified::LP_Percentage(value) => LP_Percentage(value),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
pub enum LengthOrPercentageOrAuto {
|
pub enum LengthOrPercentageOrAuto {
|
||||||
LPA_Length(Length),
|
LPA_Length(Au),
|
||||||
LPA_Percentage(Float),
|
LPA_Percentage(Float),
|
||||||
LPA_Auto,
|
LPA_Auto,
|
||||||
}
|
}
|
||||||
pub fn compute_LengthOrPercentageOrAuto(value: specified::LengthOrPercentageOrAuto,
|
pub fn compute_LengthOrPercentageOrAuto(value: specified::LengthOrPercentageOrAuto,
|
||||||
context: &Context) -> LengthOrPercentageOrAuto {
|
context: &Context) -> LengthOrPercentageOrAuto {
|
||||||
match value {
|
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_Percentage(value) => LPA_Percentage(value),
|
||||||
specified::LPA_Auto => LPA_Auto,
|
specified::LPA_Auto => LPA_Auto,
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,14 +146,14 @@ pub mod longhands {
|
||||||
|
|
||||||
% for side in ["top", "right", "bottom", "left"]:
|
% for side in ["top", "right", "bottom", "left"]:
|
||||||
${predefined_type("margin-" + side, "LengthOrPercentageOrAuto",
|
${predefined_type("margin-" + side, "LengthOrPercentageOrAuto",
|
||||||
"computed::LPA_Length(computed::Length(0))")}
|
"computed::LPA_Length(Au(0))")}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
${new_style_struct("Padding")}
|
${new_style_struct("Padding")}
|
||||||
|
|
||||||
% for side in ["top", "right", "bottom", "left"]:
|
% for side in ["top", "right", "bottom", "left"]:
|
||||||
${predefined_type("padding-" + side, "LengthOrPercentage",
|
${predefined_type("padding-" + side, "LengthOrPercentage",
|
||||||
"computed::LP_Length(computed::Length(0))",
|
"computed::LP_Length(Au(0))",
|
||||||
"parse_non_negative")}
|
"parse_non_negative")}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
|
@ -187,17 +187,17 @@ pub mod longhands {
|
||||||
% for side in ["top", "right", "bottom", "left"]:
|
% for side in ["top", "right", "bottom", "left"]:
|
||||||
<%self:longhand name="border-${side}-width">
|
<%self:longhand name="border-${side}-width">
|
||||||
pub type SpecifiedValue = specified::Length;
|
pub type SpecifiedValue = specified::Length;
|
||||||
pub type ComputedValue = computed::Length;
|
pub type ComputedValue = Au;
|
||||||
#[inline] pub fn get_initial_value() -> ComputedValue {
|
#[inline] pub fn get_initial_value() -> ComputedValue {
|
||||||
computed::Length(3 * 60) // medium
|
Au::from_px(3) // medium
|
||||||
}
|
}
|
||||||
pub fn parse(input: &[ComponentValue]) -> Option<SpecifiedValue> {
|
pub fn parse(input: &[ComponentValue]) -> Option<SpecifiedValue> {
|
||||||
one_component_value(input).chain(parse_border_width)
|
one_component_value(input).chain(parse_border_width)
|
||||||
}
|
}
|
||||||
pub fn to_computed_value(value: SpecifiedValue, context: &computed::Context)
|
pub fn to_computed_value(value: SpecifiedValue, context: &computed::Context)
|
||||||
-> ComputedValue {
|
-> ComputedValue {
|
||||||
if context.has_border_${side} { computed::compute_Length(value, context) }
|
if context.has_border_${side} { computed::compute_Au(value, context) }
|
||||||
else { computed::Length(0) }
|
else { Au(0) }
|
||||||
}
|
}
|
||||||
</%self:longhand>
|
</%self:longhand>
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -252,7 +252,7 @@ pub mod longhands {
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
pub enum ComputedValue {
|
pub enum ComputedValue {
|
||||||
Normal,
|
Normal,
|
||||||
Length(computed::Length),
|
Length(Au),
|
||||||
Number(Float),
|
Number(Float),
|
||||||
}
|
}
|
||||||
#[inline] pub fn get_initial_value() -> ComputedValue { Normal }
|
#[inline] pub fn get_initial_value() -> ComputedValue { Normal }
|
||||||
|
@ -260,7 +260,7 @@ pub mod longhands {
|
||||||
-> ComputedValue {
|
-> ComputedValue {
|
||||||
match value {
|
match value {
|
||||||
SpecifiedNormal => Normal,
|
SpecifiedNormal => Normal,
|
||||||
SpecifiedLength(value) => Length(computed::compute_Length(value, context)),
|
SpecifiedLength(value) => Length(computed::compute_Au(value, context)),
|
||||||
SpecifiedNumber(value) => Number(value),
|
SpecifiedNumber(value) => Number(value),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ pub mod longhands {
|
||||||
% for keyword in vertical_align_keywords:
|
% for keyword in vertical_align_keywords:
|
||||||
${to_rust_ident(keyword)},
|
${to_rust_ident(keyword)},
|
||||||
% endfor
|
% endfor
|
||||||
Length(computed::Length),
|
Length(Au),
|
||||||
Percentage(Float),
|
Percentage(Float),
|
||||||
}
|
}
|
||||||
#[inline] pub fn get_initial_value() -> ComputedValue { baseline }
|
#[inline] pub fn get_initial_value() -> ComputedValue { baseline }
|
||||||
|
@ -502,11 +502,11 @@ pub mod longhands {
|
||||||
</%self:single_component_value>
|
</%self:single_component_value>
|
||||||
|
|
||||||
<%self:single_component_value name="font-size" inherited="True">
|
<%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 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 {
|
#[inline] pub fn get_initial_value() -> ComputedValue {
|
||||||
computed::Length(16 * 60) // medium
|
Au::from_px(16) // medium
|
||||||
}
|
}
|
||||||
/// <length> | <percentage>
|
/// <length> | <percentage>
|
||||||
/// TODO: support <absolute-size> and <relative-size>
|
/// TODO: support <absolute-size> and <relative-size>
|
||||||
|
|
|
@ -8,9 +8,8 @@ use extra::sort::tim_sort;
|
||||||
use selectors::*;
|
use selectors::*;
|
||||||
use stylesheets::parse_stylesheet;
|
use stylesheets::parse_stylesheet;
|
||||||
use media_queries::{Device, Screen};
|
use media_queries::{Device, Screen};
|
||||||
use properties::{ComputedValues, cascade, PropertyDeclaration};
|
use properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
||||||
use script::dom::node::{AbstractNode, ScriptView};
|
use servo_util::tree::{TreeNodeRefAsElement, TreeNode, ElementLike};
|
||||||
use script::dom::element::Element;
|
|
||||||
|
|
||||||
|
|
||||||
pub enum StylesheetOrigin {
|
pub enum StylesheetOrigin {
|
||||||
|
@ -77,26 +76,18 @@ impl Stylist {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_computed_style(&self, element: AbstractNode<ScriptView>,
|
pub fn get_applicable_declarations<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: ElementLike>(
|
||||||
parent_style: Option<&ComputedValues>,
|
&self, element: &T, style_attribute: Option<&PropertyDeclarationBlock>,
|
||||||
pseudo_element: Option<PseudoElement>)
|
pseudo_element: Option<PseudoElement>) -> ~[@[PropertyDeclaration]] {
|
||||||
-> ComputedValues {
|
|
||||||
assert!(element.is_element())
|
assert!(element.is_element())
|
||||||
// Only the root does not inherit.
|
assert!(style_attribute.is_none() || pseudo_element.is_none(),
|
||||||
// The root has no parent or a non-element parent.
|
"Style attributes do not apply to pseudo-elements")
|
||||||
assert_eq!(
|
|
||||||
parent_style.is_none(),
|
|
||||||
match element.parent_node() {
|
|
||||||
None => true,
|
|
||||||
Some(ref node) => !node.is_element()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let mut applicable_declarations = ~[]; // TODO: use an iterator?
|
let mut applicable_declarations = ~[]; // TODO: use an iterator?
|
||||||
|
|
||||||
macro_rules! append(
|
macro_rules! append(
|
||||||
($rules: expr) => {
|
($rules: expr) => {
|
||||||
for rule in $rules.iter() {
|
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)
|
applicable_declarations.push(rule.declarations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,13 +97,18 @@ impl Stylist {
|
||||||
// In cascading order
|
// In cascading order
|
||||||
append!(self.ua_rules.normal);
|
append!(self.ua_rules.normal);
|
||||||
append!(self.user_rules.normal);
|
append!(self.user_rules.normal);
|
||||||
|
|
||||||
|
// Style attributes have author origin but higher specificity than style rules.
|
||||||
append!(self.author_rules.normal);
|
append!(self.author_rules.normal);
|
||||||
// TODO add style attribute
|
style_attribute.map(|sa| applicable_declarations.push(sa.normal));
|
||||||
|
|
||||||
append!(self.author_rules.important);
|
append!(self.author_rules.important);
|
||||||
|
style_attribute.map(|sa| applicable_declarations.push(sa.important));
|
||||||
|
|
||||||
append!(self.user_rules.important);
|
append!(self.user_rules.important);
|
||||||
append!(self.ua_rules.important);
|
append!(self.ua_rules.important);
|
||||||
|
|
||||||
cascade(applicable_declarations, parent_style)
|
applicable_declarations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,16 +141,16 @@ impl Ord for Rule {
|
||||||
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn matches_selector(selector: &Selector, element: AbstractNode<ScriptView>,
|
fn matches_selector<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: ElementLike>(
|
||||||
pseudo_element: Option<PseudoElement>) -> bool {
|
selector: &Selector, element: &T, pseudo_element: Option<PseudoElement>) -> bool {
|
||||||
selector.pseudo_element == pseudo_element &&
|
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,
|
fn matches_compound_selector<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: ElementLike>(
|
||||||
element: AbstractNode<ScriptView>) -> bool {
|
selector: &CompoundSelector, element: &T) -> bool {
|
||||||
if do element.with_imm_element |element| {
|
if do element.with_imm_element_like |element: &E| {
|
||||||
!do selector.simple_selectors.iter().all |simple_selector| {
|
!do selector.simple_selectors.iter().all |simple_selector| {
|
||||||
matches_simple_selector(simple_selector, element)
|
matches_simple_selector(simple_selector, element)
|
||||||
}
|
}
|
||||||
|
@ -170,14 +166,17 @@ fn matches_compound_selector(selector: &CompoundSelector,
|
||||||
NextSibling => (true, true),
|
NextSibling => (true, true),
|
||||||
LaterSibling => (true, false),
|
LaterSibling => (true, false),
|
||||||
};
|
};
|
||||||
let mut node = element;
|
let mut node = element.clone();
|
||||||
loop {
|
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,
|
None => return false,
|
||||||
Some(next_node) => node = next_node,
|
Some(next_node) => node = next_node,
|
||||||
}
|
}
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
if matches_compound_selector(&**next_selector, node) {
|
if matches_compound_selector(&**next_selector, &node) {
|
||||||
return true
|
return true
|
||||||
} else if just_one {
|
} else if just_one {
|
||||||
return false
|
return false
|
||||||
|
@ -189,12 +188,14 @@ fn matches_compound_selector(selector: &CompoundSelector,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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'];
|
static WHITESPACE: &'static [char] = &'static [' ', '\t', '\n', '\r', '\x0C'];
|
||||||
|
|
||||||
match *selector {
|
match *selector {
|
||||||
// TODO: case-sensitivity depends on the document type
|
// 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.
|
NamespaceSelector(_) => false, // TODO, when the DOM supports namespaces on elements.
|
||||||
// TODO: case-sensitivity depends on the document type and quirks mode
|
// TODO: case-sensitivity depends on the document type and quirks mode
|
||||||
// TODO: cache and intern IDs on elements.
|
// TODO: cache and intern IDs on elements.
|
||||||
|
@ -234,7 +235,7 @@ fn matches_simple_selector(selector: &SimpleSelector, element: &Element) -> bool
|
||||||
|
|
||||||
|
|
||||||
#[inline]
|
#[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 {
|
match attr.namespace {
|
||||||
Some(_) => false, // TODO, when the DOM supports namespaces on attributes
|
Some(_) => false, // TODO, when the DOM supports namespaces on attributes
|
||||||
None => match element.get_attr(attr.name) {
|
None => match element.get_attr(attr.name) {
|
||||||
|
|
|
@ -14,11 +14,14 @@
|
||||||
|
|
||||||
extern mod extra;
|
extern mod extra;
|
||||||
extern mod cssparser;
|
extern mod cssparser;
|
||||||
extern mod script;
|
extern mod servo_util (name = "util");
|
||||||
|
|
||||||
|
|
||||||
// The "real" public API
|
// The "real" public API
|
||||||
pub use self::selector_matching::{Stylist, StylesheetOrigin};
|
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
|
// 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);
|
gather(self, &mut nodes, true, prune);
|
||||||
TreeIterator::new(nodes)
|
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],
|
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)
|
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"];
|
#[crate_type = "lib"];
|
||||||
|
|
||||||
extern mod extra;
|
extern mod extra;
|
||||||
|
extern mod geom;
|
||||||
|
|
||||||
pub mod cache;
|
pub mod cache;
|
||||||
|
pub mod geometry;
|
||||||
pub mod range;
|
pub mod range;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod tree;
|
pub mod tree;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue