diff --git a/complete.rs b/complete.rs index 4b2af32..77c0a8e 100644 --- a/complete.rs +++ b/complete.rs @@ -7,6 +7,7 @@ use color::Color; use select::SelectResults; use computed::ComputedStyle; use n::h::CssHintLength; +use n::c::ComputeFontSize; use n::u::float_to_css_fixed; use values::*; use n; @@ -15,6 +16,16 @@ pub struct CompleteSelectResults { inner: SelectResults } +struct ComputeFontSizeCallback { + callback: ~fn(parent: &Option, child: &n::h::CssHint) -> n::h::CssHint, +} + +impl ComputeFontSize for ComputeFontSizeCallback { + fn compute_font_size(&self, parent: &Option, child: &n::h::CssHint) -> n::h::CssHint { + (self.callback)(parent, child) + } +} + impl<'self> CompleteSelectResults { pub fn new_root(root: SelectResults) -> CompleteSelectResults { CompleteSelectResults { @@ -31,42 +42,43 @@ impl<'self> CompleteSelectResults { //let net_parent_computed = &parent_computed.inner.inner; let net_child_computed = &/*mut*/ child_computed.inner; // FIXME: Need to get real font sizes - let cb: n::c::ComputeFontSizeCb = - |parent: &Option, child: &n::h::CssHint| -> n::h::CssHint { - match *child { - // Handle relative units - CssHintLength(n::t::CssUnitEm(child_em)) => { - match *parent { - Some(CssHintLength(parent_unit)) => { - // CSS3 Values 5.1.1: Multiply parent unit by child unit. - let mut new_value = - n::u::css_fixed_to_float(parent_unit.to_css_fixed()); - new_value *= n::u::css_fixed_to_float(child_em); - let unit = parent_unit.modify(n::u::float_to_css_fixed( - new_value)); - CssHintLength(unit) + let cb = @ComputeFontSizeCallback { + callback: |parent: &Option, child: &n::h::CssHint| -> n::h::CssHint { + match *child { + // Handle relative units + CssHintLength(n::t::CssUnitEm(child_em)) => { + match *parent { + Some(CssHintLength(parent_unit)) => { + // CSS3 Values 5.1.1: Multiply parent unit by child unit. + let mut new_value = + n::u::css_fixed_to_float(parent_unit.to_css_fixed()); + new_value *= n::u::css_fixed_to_float(child_em); + let unit = parent_unit.modify(n::u::float_to_css_fixed( + new_value)); + CssHintLength(unit) + } + _ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))), } - _ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))), } - } - CssHintLength(n::t::CssUnitPct(child_pct)) => { - match *parent { - Some(CssHintLength(parent_unit)) => { - // CSS3 Values 5.1.1: Multiply parent unit by child unit. - let mut new_value = - n::u::css_fixed_to_float(parent_unit.to_css_fixed()); - new_value *= n::u::css_fixed_to_float(child_pct) / 100.0; - let unit = parent_unit.modify(n::u::float_to_css_fixed( - new_value)); - CssHintLength(unit) + CssHintLength(n::t::CssUnitPct(child_pct)) => { + match *parent { + Some(CssHintLength(parent_unit)) => { + // CSS3 Values 5.1.1: Multiply parent unit by child unit. + let mut new_value = + n::u::css_fixed_to_float(parent_unit.to_css_fixed()); + new_value *= n::u::css_fixed_to_float(child_pct) / 100.0; + let unit = parent_unit.modify(n::u::float_to_css_fixed( + new_value)); + CssHintLength(unit) + } + _ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))), } - _ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))), } - } - // Pass through absolute units - CssHintLength(unit) => CssHintLength(unit), - _ => { - n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))) + // Pass through absolute units + CssHintLength(unit) => CssHintLength(unit), + _ => { + n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))) + } } } }; @@ -74,7 +86,7 @@ impl<'self> CompleteSelectResults { let net_result_computed: &mut n::c::CssComputedStyle = unsafe { cast::transmute(net_child_computed) }; let net_child_computed: &mut n::c::CssComputedStyle = unsafe { cast::transmute(&child_computed.inner) }; let net_parent_computed = &parent_computed.inner.inner; - n::c::compose(net_parent_computed, net_child_computed, cb, net_result_computed); + n::c::compose(net_parent_computed, net_child_computed, cb as @ComputeFontSize, net_result_computed); } CompleteSelectResults { diff --git a/test.rs b/test.rs index 40e5655..005a395 100644 --- a/test.rs +++ b/test.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use extra::url::Url; -use std::FromStr; use std::cast; use std::libc; use std::cell::Cell; diff --git a/util.rs b/util.rs index dce59a3..efeb67d 100644 --- a/util.rs +++ b/util.rs @@ -4,4 +4,4 @@ pub use netsurfcss::util::VoidPtrLike; -pub type DataStream = @fn() -> Option<~[u8]>; +pub type DataStream = ~fn() -> Option<~[u8]>;