Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit cbc6985

Browse files
committed
Merge pull request #38 from metajack/rustup
Upgrade Rust.
2 parents bb31565 + cd5cae4 commit cbc6985

File tree

3 files changed

+46
-35
lines changed

3 files changed

+46
-35
lines changed

complete.rs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use color::Color;
77
use select::SelectResults;
88
use computed::ComputedStyle;
99
use n::h::CssHintLength;
10+
use n::c::ComputeFontSize;
1011
use n::u::float_to_css_fixed;
1112
use values::*;
1213
use n;
@@ -15,6 +16,16 @@ pub struct CompleteSelectResults {
1516
inner: SelectResults
1617
}
1718

19+
struct ComputeFontSizeCallback {
20+
callback: ~fn(parent: &Option<n::h::CssHint>, child: &n::h::CssHint) -> n::h::CssHint,
21+
}
22+
23+
impl ComputeFontSize for ComputeFontSizeCallback {
24+
fn compute_font_size(&self, parent: &Option<n::h::CssHint>, child: &n::h::CssHint) -> n::h::CssHint {
25+
(self.callback)(parent, child)
26+
}
27+
}
28+
1829
impl<'self> CompleteSelectResults {
1930
pub fn new_root(root: SelectResults) -> CompleteSelectResults {
2031
CompleteSelectResults {
@@ -31,50 +42,51 @@ impl<'self> CompleteSelectResults {
3142
//let net_parent_computed = &parent_computed.inner.inner;
3243
let net_child_computed = &/*mut*/ child_computed.inner;
3344
// FIXME: Need to get real font sizes
34-
let cb: n::c::ComputeFontSizeCb =
35-
|parent: &Option<n::h::CssHint>, child: &n::h::CssHint| -> n::h::CssHint {
36-
match *child {
37-
// Handle relative units
38-
CssHintLength(n::t::CssUnitEm(child_em)) => {
39-
match *parent {
40-
Some(CssHintLength(parent_unit)) => {
41-
// CSS3 Values 5.1.1: Multiply parent unit by child unit.
42-
let mut new_value =
43-
n::u::css_fixed_to_float(parent_unit.to_css_fixed());
44-
new_value *= n::u::css_fixed_to_float(child_em);
45-
let unit = parent_unit.modify(n::u::float_to_css_fixed(
46-
new_value));
47-
CssHintLength(unit)
45+
let cb = @ComputeFontSizeCallback {
46+
callback: |parent: &Option<n::h::CssHint>, child: &n::h::CssHint| -> n::h::CssHint {
47+
match *child {
48+
// Handle relative units
49+
CssHintLength(n::t::CssUnitEm(child_em)) => {
50+
match *parent {
51+
Some(CssHintLength(parent_unit)) => {
52+
// CSS3 Values 5.1.1: Multiply parent unit by child unit.
53+
let mut new_value =
54+
n::u::css_fixed_to_float(parent_unit.to_css_fixed());
55+
new_value *= n::u::css_fixed_to_float(child_em);
56+
let unit = parent_unit.modify(n::u::float_to_css_fixed(
57+
new_value));
58+
CssHintLength(unit)
59+
}
60+
_ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))),
4861
}
49-
_ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))),
5062
}
51-
}
52-
CssHintLength(n::t::CssUnitPct(child_pct)) => {
53-
match *parent {
54-
Some(CssHintLength(parent_unit)) => {
55-
// CSS3 Values 5.1.1: Multiply parent unit by child unit.
56-
let mut new_value =
57-
n::u::css_fixed_to_float(parent_unit.to_css_fixed());
58-
new_value *= n::u::css_fixed_to_float(child_pct) / 100.0;
59-
let unit = parent_unit.modify(n::u::float_to_css_fixed(
60-
new_value));
61-
CssHintLength(unit)
63+
CssHintLength(n::t::CssUnitPct(child_pct)) => {
64+
match *parent {
65+
Some(CssHintLength(parent_unit)) => {
66+
// CSS3 Values 5.1.1: Multiply parent unit by child unit.
67+
let mut new_value =
68+
n::u::css_fixed_to_float(parent_unit.to_css_fixed());
69+
new_value *= n::u::css_fixed_to_float(child_pct) / 100.0;
70+
let unit = parent_unit.modify(n::u::float_to_css_fixed(
71+
new_value));
72+
CssHintLength(unit)
73+
}
74+
_ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))),
6275
}
63-
_ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))),
6476
}
65-
}
66-
// Pass through absolute units
67-
CssHintLength(unit) => CssHintLength(unit),
68-
_ => {
69-
n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0)))
77+
// Pass through absolute units
78+
CssHintLength(unit) => CssHintLength(unit),
79+
_ => {
80+
n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0)))
81+
}
7082
}
7183
}
7284
};
7385
// XXX: Need an aliasable &mut here
7486
let net_result_computed: &mut n::c::CssComputedStyle = unsafe { cast::transmute(net_child_computed) };
7587
let net_child_computed: &mut n::c::CssComputedStyle = unsafe { cast::transmute(&child_computed.inner) };
7688
let net_parent_computed = &parent_computed.inner.inner;
77-
n::c::compose(net_parent_computed, net_child_computed, cb, net_result_computed);
89+
n::c::compose(net_parent_computed, net_child_computed, cb as @ComputeFontSize, net_result_computed);
7890
}
7991

8092
CompleteSelectResults {

test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use extra::url::Url;
6-
use std::FromStr;
76
use std::cast;
87
use std::libc;
98
use std::cell::Cell;

util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
pub use netsurfcss::util::VoidPtrLike;
66

7-
pub type DataStream = @fn() -> Option<~[u8]>;
7+
pub type DataStream = ~fn() -> Option<~[u8]>;

0 commit comments

Comments
 (0)