Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ DONE_script = $(B)src/components/script/libscript.dummy

DEPS_script = $(CRATE_script) $(SRC_script) $(DONE_SUBMODULES) $(DONE_util) $(DONE_style) $(DONE_net) $(DONE_msg) $(DONE_macros)

RFLAGS_style = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util
RFLAGS_style = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util -L$(B)src/components/macros
MAKO_ZIP = $(S)src/components/style/Mako-0.9.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.rs
DONE_style = $(B)src/components/style/libstyle.dummy

DEPS_style = $(CRATE_style) $(SRC_style) $(DONE_SUBMODULES) $(DONE_util)
DEPS_style = $(CRATE_style) $(SRC_style) $(DONE_SUBMODULES) $(DONE_util) $(DONE_macros)

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 -L$(B)src/components/macros

Expand Down
68 changes: 68 additions & 0 deletions src/components/macros/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

#![feature(macro_rules)]


#[cfg(test)]
extern crate sync;


#[macro_export]
macro_rules! bitfield(
($bitfieldname:ident, $getter:ident, $setter:ident, $value:expr) => (
Expand All @@ -28,3 +33,66 @@ macro_rules! bitfield(
)
)


#[macro_export]
macro_rules! lazy_init(
($(static ref $N:ident : $T:ty = $e:expr;)*) => (
$(
#[allow(non_camel_case_types)]
struct $N {__unit__: ()}
static $N: $N = $N {__unit__: ()};
impl Deref<$T> for $N {
fn deref<'a>(&'a self) -> &'a $T {
unsafe {
static mut s: *$T = 0 as *$T;
static mut ONCE: ::sync::one::Once = ::sync::one::ONCE_INIT;
ONCE.doit(|| {
s = ::std::cast::transmute::<~$T, *$T>(~($e));
});
&*s
}
}
}

)*
)
)


#[cfg(test)]
mod tests {
extern crate collections;

lazy_init! {
static ref NUMBER: uint = times_two(3);
static ref VEC: [~uint, ..3] = [~1, ~2, ~3];
static ref OWNED_STRING: ~str = ~"hello";
static ref HASHMAP: collections::HashMap<uint, &'static str> = {
let mut m = collections::HashMap::new();
m.insert(0u, "abc");
m.insert(1, "def");
m.insert(2, "ghi");
m
};
}

fn times_two(n: uint) -> uint {
n * 2
}

#[test]
fn test_basic() {
assert_eq!(*OWNED_STRING, ~"hello");
assert_eq!(*NUMBER, 6);
assert!(HASHMAP.find(&1).is_some());
assert!(HASHMAP.find(&3).is_none());
assert_eq!(VEC.as_slice(), &[~1, ~2, ~3]);
}

#[test]
fn test_repeat() {
assert_eq!(*NUMBER, 6);
assert_eq!(*NUMBER, 6);
assert_eq!(*NUMBER, 6);
}
}
11 changes: 0 additions & 11 deletions src/components/main/css/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ pub trait MatchMethods {

unsafe fn cascade_node(&self,
parent: Option<LayoutNode>,
initial_values: &ComputedValues,
applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache);
}
Expand All @@ -319,7 +318,6 @@ trait PrivateMatchMethods {
parent_style: Option<&Arc<ComputedValues>>,
applicable_declarations: &[MatchedProperty],
style: &mut Option<Arc<ComputedValues>>,
initial_values: &ComputedValues,
applicable_declarations_cache: &mut
ApplicableDeclarationsCache,
shareable: bool);
Expand All @@ -335,7 +333,6 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
parent_style: Option<&Arc<ComputedValues>>,
applicable_declarations: &[MatchedProperty],
style: &mut Option<Arc<ComputedValues>>,
initial_values: &ComputedValues,
applicable_declarations_cache: &mut
ApplicableDeclarationsCache,
shareable: bool) {
Expand All @@ -352,7 +349,6 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
let (the_style, is_cacheable) = cascade(applicable_declarations,
shareable,
Some(&***parent_style),
initial_values,
cached_computed_values);
cacheable = is_cacheable;
this_style = Arc::new(the_style);
Expand All @@ -361,7 +357,6 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
let (the_style, is_cacheable) = cascade(applicable_declarations,
shareable,
None,
initial_values,
None);
cacheable = is_cacheable;
this_style = Arc::new(the_style);
Expand Down Expand Up @@ -492,9 +487,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
}

unsafe {
let initial_values = &*layout_context.initial_css_values;
self.cascade_node(parent,
initial_values,
applicable_declarations,
applicable_declarations_cache)
}
Expand Down Expand Up @@ -528,7 +521,6 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {

unsafe fn cascade_node(&self,
parent: Option<LayoutNode>,
initial_values: &ComputedValues,
applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache) {
// Get our parent's style. This must be unsafe so that we don't touch the parent's
Expand Down Expand Up @@ -559,22 +551,19 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
self.cascade_node_pseudo_element(parent_style,
applicable_declarations.normal.as_slice(),
&mut layout_data.shared_data.style,
initial_values,
applicable_declarations_cache,
applicable_declarations.normal_shareable);
if applicable_declarations.before.len() > 0 {
self.cascade_node_pseudo_element(parent_style,
applicable_declarations.before.as_slice(),
&mut layout_data.data.before_style,
initial_values,
applicable_declarations_cache,
false);
}
if applicable_declarations.after.len() > 0 {
self.cascade_node_pseudo_element(parent_style,
applicable_declarations.after.as_slice(),
&mut layout_data.data.after_style,
initial_values,
applicable_declarations_cache,
false);
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/main/layout/box_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use std::from_str::FromStr;
use std::iter::AdditiveIterator;
use std::mem;
use std::num::Zero;
use style::{ComputedValues, TElement, TNode, cascade, initial_values};
use style::{ComputedValues, TElement, TNode, cascade_anonymous};
use style::computed_values::{LengthOrPercentageOrAuto, overflow, LPA_Auto, background_attachment};
use style::computed_values::{background_repeat, border_style, clear, position, text_align};
use style::computed_values::{text_decoration, vertical_align, visibility, white_space};
Expand Down Expand Up @@ -343,8 +343,7 @@ impl Box {
//
// Anonymous table boxes, TableRowBox and TableCellBox, are generated around `Foo`, but it shouldn't inherit the border.

let (node_style, _) = cascade(&[], false, Some(&**node.style()),
&initial_values(), None);
let node_style = cascade_anonymous(&**node.style());
Box {
node: OpaqueNodeMethods::from_thread_safe_layout_node(node),
style: Arc::new(node_style),
Expand Down
6 changes: 1 addition & 5 deletions src/components/main/layout/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use std::ptr;
use std::rt::local::Local;
#[cfg(not(target_os="android"))]
use std::rt::task::Task;
use style::{ComputedValues, Stylist};
use sync::Arc;
use style::Stylist;
use url::Url;

#[cfg(target_os="android")]
Expand Down Expand Up @@ -77,9 +76,6 @@ pub struct LayoutContext {
/// FIXME(pcwalton): Make this no longer an unsafe pointer once we have fast `RWArc`s.
pub stylist: *Stylist,

/// The initial set of CSS properties.
pub initial_css_values: Arc<ComputedValues>,

/// The root node at which we're starting the layout.
pub reflow_root: OpaqueNode,

Expand Down
8 changes: 1 addition & 7 deletions src/components/main/layout/layout_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ use std::comm::{channel, Sender, Receiver};
use std::mem;
use std::ptr;
use std::task;
use style::{AuthorOrigin, ComputedValues, Stylesheet, Stylist};
use style;
use style::{AuthorOrigin, Stylesheet, Stylist};
use sync::{Arc, Mutex};
use url::Url;

Expand Down Expand Up @@ -98,9 +97,6 @@ pub struct LayoutTask {

pub stylist: ~Stylist,

/// The initial set of CSS values.
pub initial_css_values: Arc<ComputedValues>,

/// The workers that we use for parallel operation.
pub parallel_traversal: Option<WorkQueue<*mut LayoutContext,PaddedUnsafeFlow>>,

Expand Down Expand Up @@ -344,7 +340,6 @@ impl LayoutTask {

display_list: None,
stylist: ~new_stylist(),
initial_css_values: Arc::new(style::initial_values()),
parallel_traversal: parallel_traversal,
profiler_chan: profiler_chan,
opts: opts.clone(),
Expand Down Expand Up @@ -374,7 +369,6 @@ impl LayoutTask {
layout_chan: self.chan.clone(),
font_context_info: font_context_info,
stylist: &*self.stylist,
initial_css_values: self.initial_css_values.clone(),
url: (*url).clone(),
reflow_root: OpaqueNodeMethods::from_layout_node(reflow_root),
opts: self.opts.clone(),
Expand Down
1 change: 0 additions & 1 deletion src/components/main/layout/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ fn recalc_style_for_node(unsafe_layout_node: UnsafeLayoutNode,

// Perform the CSS cascade.
node.cascade_node(parent_opt,
&*layout_context.initial_css_values,
&applicable_declarations,
layout_context.applicable_declarations_cache());

Expand Down
42 changes: 35 additions & 7 deletions src/components/style/properties.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -1593,9 +1593,9 @@ impl ComputedValues {
}
}

/// Returns the initial values for all style structs as defined by the specification.
pub fn initial_values() -> ComputedValues {
ComputedValues {
/// The initial values for all style structs as defined by the specification.
lazy_init! {
static ref INITIAL_VALUES: ComputedValues = ComputedValues {
% for style_struct in STYLE_STRUCTS:
${style_struct.name}: CowArc::new(style_structs::${style_struct.name} {
% for longhand in style_struct.longhands:
Expand All @@ -1604,7 +1604,7 @@ pub fn initial_values() -> ComputedValues {
}),
% endfor
shareable: true,
}
};
}

/// Fast path for the function below. Only computes new inherited styles.
Expand Down Expand Up @@ -1702,8 +1702,6 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty],
///
/// * `parent_style`: The parent style, if applicable; if `None`, this is the root node.
///
/// * `initial_values`: The initial set of CSS values as defined by the specification.
///
/// * `cached_style`: If present, cascading is short-circuited for everything but inherited
/// values and these values are used instead. Obviously, you must be careful when supplying
/// this that it is safe to only provide inherited declarations. If `parent_style` is `None`,
Expand All @@ -1713,9 +1711,9 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty],
pub fn cascade(applicable_declarations: &[MatchedProperty],
shareable: bool,
parent_style: Option< &ComputedValues >,
initial_values: &ComputedValues,
cached_style: Option< &ComputedValues >)
-> (ComputedValues, bool) {
let initial_values = &*INITIAL_VALUES;
let (is_root_element, inherited_style) = match parent_style {
Some(parent_style) => (false, parent_style),
None => (true, initial_values),
Expand Down Expand Up @@ -1913,6 +1911,36 @@ pub fn cascade(applicable_declarations: &[MatchedProperty],
}


/// Equivalent to `cascade()` with an empty `applicable_declarations`
/// Performs the CSS cascade for an anonymous box.
///
/// * `parent_style`: Computed style of the element this anonymous box inherits from.
pub fn cascade_anonymous(parent_style: &ComputedValues) -> ComputedValues {
let initial_values = &*INITIAL_VALUES;
let mut result = ComputedValues {
% for style_struct in STYLE_STRUCTS:
${style_struct.name}:
% if style_struct.inherited:
parent_style
% else:
initial_values
% endif
.${style_struct.name}.clone(),
% endfor
shareable: false,
};
{
let border = result.Border.get_mut();
% for side in ["top", "right", "bottom", "left"]:
// Like calling to_computed_value, which wouldn't type check.
border.border_${side}_width = Au(0);
% endfor
}
// None of the teaks on 'display' apply here.
result
}


// Only re-export the types for computed values.
pub mod computed_values {
% for property in LONGHANDS:
Expand Down
15 changes: 10 additions & 5 deletions src/components/style/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@
#![feature(phase)]
#[phase(syntax, link)] extern crate log;

extern crate cssparser;
extern crate collections;
extern crate encoding;
extern crate num;
extern crate serialize;
extern crate servo_util = "util";
extern crate sync;
extern crate url;

extern crate cssparser;
extern crate encoding;

#[phase(syntax)]
extern crate servo_macros = "macros";
extern crate servo_util = "util";


// Public API
pub use stylesheets::{Stylesheet, CSSRule, StyleRule};
pub use selector_matching::{Stylist, StylesheetOrigin, UserAgentOrigin, AuthorOrigin, UserOrigin};
pub use selector_matching::{MatchedProperty};
pub use properties::{cascade, PropertyDeclaration, ComputedValues, computed_values, style_structs};
pub use properties::{cascade, cascade_anonymous};
pub use properties::{PropertyDeclaration, ComputedValues, computed_values, style_structs};
pub use properties::{PropertyDeclarationBlock, parse_style_attribute}; // Style attributes
pub use properties::{initial_values, CSSFloat, DeclaredValue, PropertyDeclarationParseResult};
pub use properties::{CSSFloat, DeclaredValue, PropertyDeclarationParseResult};
pub use properties::longhands;
pub use errors::with_errors_silenced;
pub use node::{TElement, TNode};
Expand Down