@@ -20,7 +20,7 @@ use crate::stylesheets::{Origin, RulesMutateError};
20
20
use crate :: values:: computed:: image:: LineDirection ;
21
21
use crate :: values:: computed:: transform:: Matrix3D ;
22
22
use crate :: values:: computed:: url:: ComputedImageUrl ;
23
- use crate :: values:: computed:: { Angle , CalcLengthOrPercentage , Gradient , Image } ;
23
+ use crate :: values:: computed:: { Angle , Gradient , Image } ;
24
24
use crate :: values:: computed:: { Integer , LengthOrPercentage } ;
25
25
use crate :: values:: computed:: { LengthOrPercentageOrAuto , NonNegativeLengthOrPercentageOrAuto } ;
26
26
use crate :: values:: computed:: { Percentage , TextAlign } ;
@@ -31,9 +31,10 @@ use crate::values::generics::rect::Rect;
31
31
use crate :: values:: generics:: NonNegative ;
32
32
use app_units:: Au ;
33
33
use std:: f32:: consts:: PI ;
34
+ use style_traits:: values:: specified:: AllowedNumericType ;
34
35
35
- impl From < CalcLengthOrPercentage > for nsStyleCoord_CalcValue {
36
- fn from ( other : CalcLengthOrPercentage ) -> nsStyleCoord_CalcValue {
36
+ impl From < LengthOrPercentage > for nsStyleCoord_CalcValue {
37
+ fn from ( other : LengthOrPercentage ) -> nsStyleCoord_CalcValue {
37
38
let has_percentage = other. percentage . is_some ( ) ;
38
39
nsStyleCoord_CalcValue {
39
40
mLength : other. unclamped_length ( ) . to_i32_au ( ) ,
@@ -43,93 +44,54 @@ impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
43
44
}
44
45
}
45
46
46
- impl From < nsStyleCoord_CalcValue > for CalcLengthOrPercentage {
47
- fn from ( other : nsStyleCoord_CalcValue ) -> CalcLengthOrPercentage {
47
+ impl From < nsStyleCoord_CalcValue > for LengthOrPercentage {
48
+ fn from ( other : nsStyleCoord_CalcValue ) -> LengthOrPercentage {
48
49
let percentage = if other. mHasPercent {
49
50
Some ( Percentage ( other. mPercent ) )
50
51
} else {
51
52
None
52
53
} ;
53
- Self :: new ( Au ( other. mLength ) . into ( ) , percentage)
54
- }
55
- }
56
-
57
- impl From < LengthOrPercentage > for nsStyleCoord_CalcValue {
58
- fn from ( other : LengthOrPercentage ) -> nsStyleCoord_CalcValue {
59
- match other {
60
- LengthOrPercentage :: Length ( px) => nsStyleCoord_CalcValue {
61
- mLength : px. to_i32_au ( ) ,
62
- mPercent : 0.0 ,
63
- mHasPercent : false ,
64
- } ,
65
- LengthOrPercentage :: Percentage ( pc) => nsStyleCoord_CalcValue {
66
- mLength : 0 ,
67
- mPercent : pc. 0 ,
68
- mHasPercent : true ,
69
- } ,
70
- LengthOrPercentage :: Calc ( calc) => calc. into ( ) ,
71
- }
54
+ Self :: with_clamping_mode (
55
+ Au ( other. mLength ) . into ( ) ,
56
+ percentage,
57
+ AllowedNumericType :: All ,
58
+ /* was_calc = */ true ,
59
+ )
72
60
}
73
61
}
74
62
75
63
impl LengthOrPercentageOrAuto {
76
64
/// Convert this value in an appropriate `nsStyleCoord::CalcValue`.
77
65
pub fn to_calc_value ( & self ) -> Option < nsStyleCoord_CalcValue > {
78
66
match * self {
79
- LengthOrPercentageOrAuto :: Length ( px) => Some ( nsStyleCoord_CalcValue {
80
- mLength : px. to_i32_au ( ) ,
81
- mPercent : 0.0 ,
82
- mHasPercent : false ,
83
- } ) ,
84
- LengthOrPercentageOrAuto :: Percentage ( pc) => Some ( nsStyleCoord_CalcValue {
85
- mLength : 0 ,
86
- mPercent : pc. 0 ,
87
- mHasPercent : true ,
88
- } ) ,
89
- LengthOrPercentageOrAuto :: Calc ( calc) => Some ( calc. into ( ) ) ,
67
+ LengthOrPercentageOrAuto :: LengthOrPercentage ( len) => Some ( From :: from ( len) ) ,
90
68
LengthOrPercentageOrAuto :: Auto => None ,
91
69
}
92
70
}
93
71
}
94
72
95
- impl From < nsStyleCoord_CalcValue > for LengthOrPercentage {
96
- fn from ( other : nsStyleCoord_CalcValue ) -> LengthOrPercentage {
97
- match ( other. mHasPercent , other. mLength ) {
98
- ( false , _) => LengthOrPercentage :: Length ( Au ( other. mLength ) . into ( ) ) ,
99
- ( true , 0 ) => LengthOrPercentage :: Percentage ( Percentage ( other. mPercent ) ) ,
100
- _ => LengthOrPercentage :: Calc ( other. into ( ) ) ,
101
- }
102
- }
103
- }
104
-
105
73
impl From < nsStyleCoord_CalcValue > for LengthOrPercentageOrAuto {
106
74
fn from ( other : nsStyleCoord_CalcValue ) -> LengthOrPercentageOrAuto {
107
- match ( other. mHasPercent , other. mLength ) {
108
- ( false , _) => LengthOrPercentageOrAuto :: Length ( Au ( other. mLength ) . into ( ) ) ,
109
- ( true , 0 ) => LengthOrPercentageOrAuto :: Percentage ( Percentage ( other. mPercent ) ) ,
110
- _ => LengthOrPercentageOrAuto :: Calc ( other. into ( ) ) ,
111
- }
75
+ LengthOrPercentageOrAuto :: LengthOrPercentage ( LengthOrPercentage :: from ( other) )
112
76
}
113
77
}
114
78
115
79
// FIXME(emilio): A lot of these impl From should probably become explicit or
116
80
// disappear as we move more stuff to cbindgen.
117
81
impl From < nsStyleCoord_CalcValue > for NonNegativeLengthOrPercentageOrAuto {
118
82
fn from ( other : nsStyleCoord_CalcValue ) -> Self {
119
- use style_traits:: values:: specified:: AllowedNumericType ;
120
- NonNegative ( if other. mLength < 0 || other. mPercent < 0. {
121
- LengthOrPercentageOrAuto :: Calc ( CalcLengthOrPercentage :: with_clamping_mode (
83
+ NonNegative (
84
+ LengthOrPercentageOrAuto :: LengthOrPercentage ( LengthOrPercentage :: with_clamping_mode (
122
85
Au ( other. mLength ) . into ( ) ,
123
86
if other. mHasPercent {
124
87
Some ( Percentage ( other. mPercent ) )
125
88
} else {
126
89
None
127
90
} ,
128
91
AllowedNumericType :: NonNegative ,
92
+ /* was_calc = */ true ,
129
93
) )
130
- } else {
131
- other. into ( )
132
- } )
94
+ )
133
95
}
134
96
}
135
97
@@ -143,30 +105,23 @@ fn line_direction(horizontal: LengthOrPercentage, vertical: LengthOrPercentage)
143
105
use crate :: values:: computed:: position:: Position ;
144
106
use crate :: values:: specified:: position:: { X , Y } ;
145
107
146
- let horizontal_percentage = match horizontal {
147
- LengthOrPercentage :: Percentage ( percentage) => Some ( percentage. 0 ) ,
148
- _ => None ,
149
- } ;
150
-
151
- let vertical_percentage = match vertical {
152
- LengthOrPercentage :: Percentage ( percentage) => Some ( percentage. 0 ) ,
153
- _ => None ,
154
- } ;
108
+ let horizontal_percentage = horizontal. as_percentage ( ) ;
109
+ let vertical_percentage = vertical. as_percentage ( ) ;
155
110
156
111
let horizontal_as_corner = horizontal_percentage. and_then ( |percentage| {
157
- if percentage == 0.0 {
112
+ if percentage. 0 == 0.0 {
158
113
Some ( X :: Left )
159
- } else if percentage == 1.0 {
114
+ } else if percentage. 0 == 1.0 {
160
115
Some ( X :: Right )
161
116
} else {
162
117
None
163
118
}
164
119
} ) ;
165
120
166
121
let vertical_as_corner = vertical_percentage. and_then ( |percentage| {
167
- if percentage == 0.0 {
122
+ if percentage. 0 == 0.0 {
168
123
Some ( Y :: Top )
169
- } else if percentage == 1.0 {
124
+ } else if percentage. 0 == 1.0 {
170
125
Some ( Y :: Bottom )
171
126
} else {
172
127
None
@@ -178,13 +133,13 @@ fn line_direction(horizontal: LengthOrPercentage, vertical: LengthOrPercentage)
178
133
}
179
134
180
135
if let Some ( hc) = horizontal_as_corner {
181
- if vertical_percentage == Some ( 0.5 ) {
136
+ if vertical_percentage == Some ( Percentage ( 0.5 ) ) {
182
137
return LineDirection :: Horizontal ( hc) ;
183
138
}
184
139
}
185
140
186
141
if let Some ( vc) = vertical_as_corner {
187
- if horizontal_percentage == Some ( 0.5 ) {
142
+ if horizontal_percentage == Some ( Percentage ( 0.5 ) ) {
188
143
return LineDirection :: Vertical ( vc) ;
189
144
}
190
145
}
0 commit comments