@@ -7,6 +7,7 @@ use color::Color;
7
7
use select:: SelectResults ;
8
8
use computed:: ComputedStyle ;
9
9
use n:: h:: CssHintLength ;
10
+ use n:: c:: ComputeFontSize ;
10
11
use n:: u:: float_to_css_fixed;
11
12
use values:: * ;
12
13
use n;
@@ -15,6 +16,16 @@ pub struct CompleteSelectResults {
15
16
inner : SelectResults
16
17
}
17
18
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
+
18
29
impl < ' self > CompleteSelectResults {
19
30
pub fn new_root ( root : SelectResults ) -> CompleteSelectResults {
20
31
CompleteSelectResults {
@@ -31,50 +42,51 @@ impl<'self> CompleteSelectResults {
31
42
//let net_parent_computed = &parent_computed.inner.inner;
32
43
let net_child_computed = & /*mut*/ child_computed. inner ;
33
44
// 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 ) ) ) ,
48
61
}
49
- _ => n:: h:: CssHintLength ( n:: t:: CssUnitPx ( float_to_css_fixed ( 16.0 ) ) ) ,
50
62
}
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 ) ) ) ,
62
75
}
63
- _ => n:: h:: CssHintLength ( n:: t:: CssUnitPx ( float_to_css_fixed ( 16.0 ) ) ) ,
64
76
}
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
+ }
70
82
}
71
83
}
72
84
} ;
73
85
// XXX: Need an aliasable &mut here
74
86
let net_result_computed: & mut n:: c:: CssComputedStyle = unsafe { cast:: transmute ( net_child_computed) } ;
75
87
let net_child_computed: & mut n:: c:: CssComputedStyle = unsafe { cast:: transmute ( & child_computed. inner ) } ;
76
88
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) ;
78
90
}
79
91
80
92
CompleteSelectResults {
0 commit comments