mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
auto merge of #1059 : SimonSapin/servo/newnewcss, r=kmcallister
Some progress on #1006 and #1057.
This commit is contained in:
commit
ef524aec0d
20 changed files with 193 additions and 43 deletions
24
Makefile.in
24
Makefile.in
|
@ -229,21 +229,29 @@ DEPS_gfx = $(CRATE_gfx) $(SRC_gfx) $(DONE_SUBMODULES) $(DONE_util) $(DONE_net) $
|
|||
RFLAGS_script = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util -L $(B)src/components/net -L $(B)src/components/gfx -L $(B)src/components/msg
|
||||
WEBIDL_script = $(call rwildcard,$(S)src/components/script/,*.webidl)
|
||||
AUTOGEN_SRC_script = $(patsubst %.webidl, %Binding.rs, $(WEBIDL_script))
|
||||
MAKO_ZIP = $(S)src/components/script/style/properties/Mako-0.8.1.zip
|
||||
MAKO_script = $(S)src/components/script/style/properties/mod.rs
|
||||
MAKO_SRC_script = $(MAKO_script).mako
|
||||
SRC_script = $(call rwildcard,$(S)src/components/script/,*.rs) $(AUTOGEN_SRC_script) $(MAKO_script)
|
||||
SRC_script = $(call rwildcard,$(S)src/components/script/,*.rs) $(AUTOGEN_SRC_script)
|
||||
CRATE_script = $(S)src/components/script/script.rc
|
||||
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_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/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
|
||||
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
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
SRC_servo = $(call rwildcard,$(S)src/components/main/,*.rs)
|
||||
CRATE_servo = $(S)src/components/main/servo.rc
|
||||
|
||||
DEPS_servo = $(CRATE_servo) $(SRC_servo) $(DONE_SUBMODULES) $(DONE_util) $(DONE_gfx) $(DONE_script) $(DONE_net) $(DONE_msg)
|
||||
DEPS_servo = $(CRATE_servo) $(SRC_servo) $(DONE_SUBMODULES) $(DONE_util) $(DONE_gfx) $(DONE_script) $(DONE_style) $(DONE_net) $(DONE_msg)
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
.PHONY: all
|
||||
|
@ -251,7 +259,7 @@ all: servo package
|
|||
|
||||
# Servo helper libraries
|
||||
|
||||
SERVO_LIB_CRATES = util net msg gfx script
|
||||
SERVO_LIB_CRATES = util net msg gfx script style
|
||||
|
||||
define DEF_LIB_CRATE_RULES
|
||||
$$(DONE_$(1)): $$(DEPS_$(1))
|
||||
|
@ -285,7 +293,7 @@ $(AUTOGEN_SRC_script): %Binding.rs: $(bindinggen_dependencies) \
|
|||
|
||||
globalgen_dependencies := $(addprefix $(BINDINGS_SRC)/, GlobalGen.py Bindings.conf Configuration.py CodegenRust.py parser/WebIDL.py) $(CACHE_DIR)/.done
|
||||
|
||||
$(MAKO_script): $(MAKO_SRC_script)
|
||||
$(MAKO_style): $(MAKO_SRC_style)
|
||||
PYTHONPATH=$(MAKO_ZIP) python -c "from mako.template import Template; print(Template(filename='$<').render())" > $@
|
||||
|
||||
|
||||
|
|
1
configure
vendored
1
configure
vendored
|
@ -583,6 +583,7 @@ make_dir ${CFG_BUILD_DIR}src/components/msg
|
|||
make_dir ${CFG_BUILD_DIR}src/components/net
|
||||
make_dir ${CFG_BUILD_DIR}src/components/gfx
|
||||
make_dir ${CFG_BUILD_DIR}src/components/script
|
||||
make_dir ${CFG_BUILD_DIR}src/components/style
|
||||
make_dir ${CFG_BUILD_DIR}src/components/main
|
||||
make_dir src/test/html/ref
|
||||
make_dir src/compiler/rust
|
||||
|
|
|
@ -45,6 +45,10 @@ clean-script:
|
|||
@$(call E, "cleaning script")
|
||||
$(Q)cd $(B)/src/components/script/ && rm -rf libscript*.dylib libscript*.dSYM libscript*.so $(DONE_script)
|
||||
|
||||
clean-style:
|
||||
@$(call E, "cleaning style")
|
||||
$(Q)cd $(B)/src/components/style/ && rm -rf libstyle*.dylib libstyle*.dSYM libstyle*.so $(DONE_style)
|
||||
|
||||
clean-servo: clean-gfx clean-util clean-net clean-script clean-msg
|
||||
@$(call E, "cleaning servo")
|
||||
$(Q)rm -f servo servo-test $(foreach lib_crate,$(SERVO_LIB_CRATES),servo-test-$(lib_crate)) libservo*.so
|
||||
|
|
|
@ -17,7 +17,6 @@ extern mod hubbub;
|
|||
extern mod js;
|
||||
extern mod netsurfcss;
|
||||
extern mod newcss (name = "css");
|
||||
extern mod cssparser;
|
||||
extern mod servo_net (name = "net");
|
||||
extern mod servo_util (name = "util");
|
||||
extern mod servo_msg (name = "msg");
|
||||
|
@ -143,7 +142,3 @@ pub mod html {
|
|||
|
||||
pub mod layout_interface;
|
||||
pub mod script_task;
|
||||
|
||||
|
||||
// "New" (as of 2013-08) style system, not used yet but included to avoid bitrot.
|
||||
mod style;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
mod.rs
|
1
src/components/style/.gitignore
vendored
Normal file
1
src/components/style/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
properties.rs
|
|
@ -69,7 +69,7 @@ pub mod specified {
|
|||
#[deriving(Clone)]
|
||||
pub enum LengthOrPercentage {
|
||||
LP_Length(Length),
|
||||
LP_Percentage(Float),
|
||||
LP_Percentage(Float), // [0 .. 100%] maps to [0.0 .. 1.0]
|
||||
}
|
||||
impl LengthOrPercentage {
|
||||
fn parse_internal(input: &ComponentValue, negative_ok: bool)
|
||||
|
@ -78,7 +78,7 @@ pub mod specified {
|
|||
&Dimension(ref value, ref unit) if negative_ok || value.value >= 0.
|
||||
=> 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)),
|
||||
=> Some(LP_Percentage(value.value / 100.)),
|
||||
&Number(ref value) if value.value == 0. => Some(LP_Length(Au(0))),
|
||||
_ => None
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ pub mod specified {
|
|||
#[deriving(Clone)]
|
||||
pub enum LengthOrPercentageOrAuto {
|
||||
LPA_Length(Length),
|
||||
LPA_Percentage(Float),
|
||||
LPA_Percentage(Float), // [0 .. 100%] maps to [0.0 .. 1.0]
|
||||
LPA_Auto,
|
||||
}
|
||||
impl LengthOrPercentageOrAuto {
|
||||
|
@ -106,7 +106,7 @@ pub mod specified {
|
|||
&Dimension(ref value, ref unit) if negative_ok || value.value >= 0.
|
||||
=> 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)),
|
||||
=> Some(LPA_Percentage(value.value / 100.)),
|
||||
&Number(ref value) if value.value == 0. => Some(LPA_Length(Au(0))),
|
||||
&Ident(ref value) if value.eq_ignore_ascii_case("auto") => Some(LPA_Auto),
|
||||
_ => None
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
use std::ascii::StrAsciiExt;
|
||||
use cssparser::*;
|
||||
use style::errors::{ErrorLoggerIterator, log_css_error};
|
||||
use style::stylesheets::{CSSRule, CSSMediaRule, parse_style_rule, parse_nested_at_rule};
|
||||
use style::namespaces::NamespaceMap;
|
||||
use errors::{ErrorLoggerIterator, log_css_error};
|
||||
use stylesheets::{CSSRule, CSSMediaRule, parse_style_rule, parse_nested_at_rule};
|
||||
use namespaces::NamespaceMap;
|
||||
|
||||
|
||||
pub struct MediaRule {
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use std::hashmap::HashMap;
|
||||
use cssparser::*;
|
||||
use style::errors::log_css_error;
|
||||
use errors::log_css_error;
|
||||
|
||||
pub struct NamespaceMap {
|
||||
default: Option<~str>, // Optional URL
|
|
@ -8,8 +8,8 @@ use std::ascii::StrAsciiExt;
|
|||
use std::at_vec;
|
||||
pub use std::iterator;
|
||||
pub use cssparser::*;
|
||||
pub use style::errors::{ErrorLoggerIterator, log_css_error};
|
||||
pub use style::parsing_utils::*;
|
||||
pub use errors::{ErrorLoggerIterator, log_css_error};
|
||||
pub use parsing_utils::*;
|
||||
pub use self::common_types::*;
|
||||
|
||||
pub mod common_types;
|
||||
|
@ -19,7 +19,7 @@ pub mod common_types;
|
|||
|
||||
def to_rust_ident(name):
|
||||
name = name.replace("-", "_")
|
||||
if name in ["static"]: # Rust keywords
|
||||
if name in ["static", "super"]: # Rust keywords
|
||||
name += "_"
|
||||
return name
|
||||
|
||||
|
@ -128,15 +128,15 @@ pub mod longhands {
|
|||
</%def>
|
||||
|
||||
<%def name="predefined_type(name, type, initial_value, parse_method='parse', inherited=False)">
|
||||
<%self:longhand name="${name}" inherited="${inherited}">
|
||||
<%self:single_component_value name="${name}" inherited="${inherited}">
|
||||
pub use to_computed_value = super::super::common_types::computed::compute_${type};
|
||||
pub type SpecifiedValue = specified::${type};
|
||||
pub type ComputedValue = computed::${type};
|
||||
#[inline] pub fn get_initial_value() -> ComputedValue { ${initial_value} }
|
||||
pub fn parse(input: &[ComponentValue]) -> Option<SpecifiedValue> {
|
||||
one_component_value(input).chain(specified::${type}::${parse_method})
|
||||
#[inline] pub fn from_component_value(v: &ComponentValue) -> Option<SpecifiedValue> {
|
||||
specified::${type}::${parse_method}(v)
|
||||
}
|
||||
</%self:longhand>
|
||||
</%self:single_component_value>
|
||||
</%def>
|
||||
|
||||
|
||||
|
@ -240,7 +240,7 @@ pub mod longhands {
|
|||
&ast::Number(ref value) if value.value >= 0.
|
||||
=> Some(SpecifiedNumber(value.value)),
|
||||
&ast::Percentage(ref value) if value.value >= 0.
|
||||
=> Some(SpecifiedLength(specified::Em(value.value))),
|
||||
=> Some(SpecifiedLength(specified::Em(value.value / 100.))),
|
||||
&Dimension(ref value, ref unit) if value.value >= 0.
|
||||
=> specified::Length::parse_dimension(value.value, unit.as_slice())
|
||||
.map_move(SpecifiedLength),
|
||||
|
@ -266,6 +266,55 @@ pub mod longhands {
|
|||
}
|
||||
</%self:single_component_value>
|
||||
|
||||
<%self:single_component_value name="vertical-align">
|
||||
<% vertical_align_keywords = (
|
||||
"baseline sub super top text-top middle bottom text-bottom".split()) %>
|
||||
#[deriving(Clone)]
|
||||
pub enum SpecifiedValue {
|
||||
% for keyword in vertical_align_keywords:
|
||||
Specified_${to_rust_ident(keyword)},
|
||||
% endfor
|
||||
SpecifiedLengthOrPercentage(specified::LengthOrPercentage),
|
||||
}
|
||||
/// baseline | sub | super | top | text-top | middle | bottom | text-bottom
|
||||
/// | <percentage> | <length>
|
||||
pub fn from_component_value(input: &ComponentValue) -> Option<SpecifiedValue> {
|
||||
match input {
|
||||
&Ident(ref value) => match value.to_ascii_lower().as_slice() {
|
||||
% for keyword in vertical_align_keywords:
|
||||
"${keyword}" => Some(Specified_${to_rust_ident(keyword)}),
|
||||
% endfor
|
||||
_ => None,
|
||||
},
|
||||
_ => specified::LengthOrPercentage::parse_non_negative(input)
|
||||
.map_move(SpecifiedLengthOrPercentage)
|
||||
}
|
||||
}
|
||||
#[deriving(Clone)]
|
||||
pub enum ComputedValue {
|
||||
% for keyword in vertical_align_keywords:
|
||||
${to_rust_ident(keyword)},
|
||||
% endfor
|
||||
Length(computed::Length),
|
||||
Percentage(Float),
|
||||
}
|
||||
#[inline] pub fn get_initial_value() -> ComputedValue { baseline }
|
||||
pub fn to_computed_value(value: SpecifiedValue, context: &computed::Context)
|
||||
-> ComputedValue {
|
||||
match value {
|
||||
% for keyword in vertical_align_keywords:
|
||||
Specified_${to_rust_ident(keyword)} => ${to_rust_ident(keyword)},
|
||||
% endfor
|
||||
SpecifiedLengthOrPercentage(value)
|
||||
=> match computed::compute_LengthOrPercentage(value, context) {
|
||||
computed::LP_Length(value) => Length(value),
|
||||
computed::LP_Percentage(value) => Percentage(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
</%self:single_component_value>
|
||||
|
||||
|
||||
// CSS 2.1, Section 11 - Visual effects
|
||||
|
||||
// CSS 2.1, Section 12 - Generated content, automatic numbering, and lists
|
||||
|
@ -583,6 +632,9 @@ pub mod shorthands {
|
|||
}
|
||||
</%self:shorthand>
|
||||
|
||||
${four_sides_shorthand("margin", "margin-%s", "margin_top::from_component_value")}
|
||||
${four_sides_shorthand("padding", "padding-%s", "padding_top::from_component_value")}
|
||||
|
||||
${four_sides_shorthand("border-color", "border-%s-color", "specified::CSSColor::parse")}
|
||||
${four_sides_shorthand("border-style", "border-%s-style",
|
||||
"border_top_style::from_component_value")}
|
||||
|
@ -652,6 +704,81 @@ pub mod shorthands {
|
|||
}
|
||||
</%self:shorthand>
|
||||
|
||||
<%self:shorthand name="font" sub_properties="font-style font-variant font-weight
|
||||
font-size line-height font-family">
|
||||
let mut iter = input.skip_whitespace();
|
||||
let mut nb_normals = 0u;
|
||||
let mut style = None;
|
||||
let mut variant = None;
|
||||
let mut weight = None;
|
||||
let mut size = None;
|
||||
let mut line_height = None;
|
||||
for component_value in iter {
|
||||
// Special-case 'normal' because it is valid in each of
|
||||
// font-style, font-weight and font-variant.
|
||||
// Leaves the values to None, 'normal' is the initial value for each of them.
|
||||
if get_ident_lower(component_value).filtered(
|
||||
|v| v.eq_ignore_ascii_case("normal")).is_some() {
|
||||
nb_normals += 1;
|
||||
loop;
|
||||
}
|
||||
if style.is_none() {
|
||||
match font_style::from_component_value(component_value) {
|
||||
Some(s) => { style = Some(s); loop },
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
if weight.is_none() {
|
||||
match font_weight::from_component_value(component_value) {
|
||||
Some(w) => { weight = Some(w); loop },
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
if variant.is_none() {
|
||||
match font_variant::from_component_value(component_value) {
|
||||
Some(v) => { variant = Some(v); loop },
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
match font_size::from_component_value(component_value) {
|
||||
Some(s) => { size = Some(s); break },
|
||||
None => return None
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn count<T>(opt: &Option<T>) -> uint {
|
||||
match opt {
|
||||
&Some(_) => 1,
|
||||
&None => 0,
|
||||
}
|
||||
}
|
||||
if size.is_none() || (count(&style) + count(&weight) + count(&variant) + nb_normals) > 3 {
|
||||
return None
|
||||
}
|
||||
let mut copied_iter = iter.clone();
|
||||
match copied_iter.next() {
|
||||
Some(&Delim('/')) => {
|
||||
iter = copied_iter;
|
||||
line_height = match iter.next() {
|
||||
Some(v) => line_height::from_component_value(v),
|
||||
_ => return None,
|
||||
};
|
||||
if line_height.is_none() { return None }
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
let family = font_family::from_iter(iter);
|
||||
if family.is_none() { return None }
|
||||
Some(Longhands {
|
||||
font_style: style,
|
||||
font_variant: variant,
|
||||
font_weight: weight,
|
||||
font_size: size,
|
||||
line_height: line_height,
|
||||
font_family: family
|
||||
})
|
||||
</%self:shorthand>
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -5,12 +5,12 @@
|
|||
use std::ascii::StrAsciiExt;
|
||||
use extra::sort::tim_sort;
|
||||
|
||||
use style::selectors::*;
|
||||
use style::stylesheets::parse_stylesheet;
|
||||
use style::media_queries::{Device, Screen};
|
||||
use style::properties::{ComputedValues, cascade, PropertyDeclaration};
|
||||
use dom::node::{AbstractNode, ScriptView};
|
||||
use dom::element::Element;
|
||||
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;
|
||||
|
||||
|
||||
pub enum StylesheetOrigin {
|
|
@ -5,7 +5,7 @@
|
|||
use std::{vec, iterator};
|
||||
use std::ascii::StrAsciiExt;
|
||||
use cssparser::*;
|
||||
use style::namespaces::NamespaceMap;
|
||||
use namespaces::NamespaceMap;
|
||||
|
||||
|
||||
pub struct Selector {
|
|
@ -2,6 +2,21 @@
|
|||
* 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/. */
|
||||
|
||||
#[link(name = "style",
|
||||
vers = "0.1",
|
||||
uuid = "4a50ca00-3283-11e3-aa6e-0800200c9a66",
|
||||
url = "http://servo.org/")];
|
||||
|
||||
#[comment = "The Servo Parallel Browser Project"];
|
||||
#[license = "MPL"];
|
||||
#[crate_type = "lib"];
|
||||
|
||||
|
||||
extern mod extra;
|
||||
extern mod cssparser;
|
||||
extern mod script;
|
||||
|
||||
|
||||
// The "real" public API
|
||||
pub use self::selector_matching::{Stylist, StylesheetOrigin};
|
||||
|
|
@ -5,12 +5,12 @@
|
|||
use std::iterator::Iterator;
|
||||
use std::ascii::StrAsciiExt;
|
||||
use cssparser::*;
|
||||
use style::selectors;
|
||||
use style::properties;
|
||||
use style::errors::{ErrorLoggerIterator, log_css_error};
|
||||
use style::namespaces::{NamespaceMap, parse_namespace_rule};
|
||||
use style::media_queries::{MediaRule, parse_media_rule};
|
||||
use style::media_queries;
|
||||
use selectors;
|
||||
use properties;
|
||||
use errors::{ErrorLoggerIterator, log_css_error};
|
||||
use namespaces::{NamespaceMap, parse_namespace_rule};
|
||||
use media_queries::{MediaRule, parse_media_rule};
|
||||
use media_queries;
|
||||
|
||||
|
||||
pub struct Stylesheet {
|
Loading…
Add table
Add a link
Reference in a new issue