-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
box.mako.rs
1882 lines (1691 loc) · 77.6 KB
/
box.mako.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import Keyword, Method, to_rust_ident %>
<% data.new_style_struct("Box",
inherited=False,
gecko_name="Display") %>
// TODO(SimonSapin): don't parse `inline-table`, since we don't support it
<%helpers:longhand name="display"
need_clone="True"
animatable="False"
custom_cascade="${product == 'servo'}"
spec="https://drafts.csswg.org/css-display/#propdef-display">
<%
values = """inline block inline-block
table inline-table table-row-group table-header-group table-footer-group
table-row table-column-group table-column table-cell table-caption
list-item flex none
""".split()
if product == "gecko":
values += """inline-flex grid inline-grid ruby ruby-base ruby-base-container
ruby-text ruby-text-container contents flow-root -webkit-box
-webkit-inline-box -moz-box -moz-inline-box -moz-grid -moz-inline-grid
-moz-grid-group -moz-grid-line -moz-stack -moz-inline-stack -moz-deck
-moz-popup -moz-groupbox""".split()
%>
pub use self::computed_value::T as SpecifiedValue;
use values::computed::ComputedValueAsSpecified;
use style_traits::ToCss;
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
pub mod computed_value {
use style_traits::ToCss;
#[allow(non_camel_case_types)]
#[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub enum T {
% for value in values:
${to_rust_ident(value)},
% endfor
}
impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
where W: ::std::fmt::Write,
{
match *self {
% for value in values:
T::${to_rust_ident(value)} => dest.write_str("${value}"),
% endfor
}
}
}
}
/// The initial display value.
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::${to_rust_ident(values[0])}
}
/// Parse a display value.
pub fn parse(_context: &ParserContext, input: &mut Parser)
-> Result<SpecifiedValue, ()> {
match_ignore_ascii_case! { try!(input.expect_ident()),
% for value in values:
"${value}" => {
Ok(computed_value::T::${to_rust_ident(value)})
},
% endfor
_ => Err(())
}
}
impl ComputedValueAsSpecified for SpecifiedValue {}
% if product == "servo":
fn cascade_property_custom(_declaration: &PropertyDeclaration,
_inherited_style: &ComputedValues,
context: &mut computed::Context,
_seen: &mut PropertyBitField,
_cacheable: &mut bool,
_error_reporter: &mut StdBox<ParseErrorReporter + Send>) {
longhands::_servo_display_for_hypothetical_box::derive_from_display(context);
longhands::_servo_text_decorations_in_effect::derive_from_display(context);
longhands::_servo_under_display_none::derive_from_display(context);
}
% endif
</%helpers:longhand>
${helpers.single_keyword("-moz-top-layer", "none top",
gecko_constant_prefix="NS_STYLE_TOP_LAYER",
gecko_ffi_name="mTopLayer", need_clone=True,
products="gecko", animatable=False, internal=True,
spec="Internal (not web-exposed)")}
<%helpers:single_keyword_computed name="position"
values="static absolute relative fixed"
need_clone="True"
extra_gecko_values="sticky"
animatable="False"
spec="https://drafts.csswg.org/css-position/#position-property">
impl SpecifiedValue {
pub fn is_absolutely_positioned_style(&self) -> bool {
matches!(*self, SpecifiedValue::absolute | SpecifiedValue::fixed)
}
}
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
% if product == "gecko":
// https://fullscreen.spec.whatwg.org/#new-stacking-layer
// Any position value other than 'absolute' and 'fixed' are
// computed to 'absolute' if the element is in a top layer.
if !self.is_absolutely_positioned_style() &&
matches!(_context.style().get_box().clone__moz_top_layer(),
longhands::_moz_top_layer::SpecifiedValue::top) {
SpecifiedValue::absolute
} else {
*self
}
% else:
*self
% endif
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
*computed
}
}
</%helpers:single_keyword_computed>
<%helpers:single_keyword_computed name="float"
values="none left right"
// https://drafts.csswg.org/css-logical-props/#float-clear
extra_specified="inline-start inline-end"
animatable="False"
need_clone="True"
gecko_enum_prefix="StyleFloat"
gecko_inexhaustive="True"
gecko_ffi_name="mFloat"
spec="https://drafts.csswg.org/css-box/#propdef-float">
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
if context.style().get_box().clone_position().is_absolutely_positioned_style() {
computed_value::T::none
} else {
let ltr = context.style().writing_mode.is_bidi_ltr();
// https://drafts.csswg.org/css-logical-props/#float-clear
match *self {
SpecifiedValue::inline_start if ltr => computed_value::T::left,
SpecifiedValue::inline_start => computed_value::T::right,
SpecifiedValue::inline_end if ltr => computed_value::T::right,
SpecifiedValue::inline_end => computed_value::T::left,
% for value in "none left right".split():
SpecifiedValue::${value} => computed_value::T::${value},
% endfor
}
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
match *computed {
% for value in "none left right".split():
computed_value::T::${value} => SpecifiedValue::${value},
% endfor
}
}
}
</%helpers:single_keyword_computed>
<%helpers:single_keyword_computed name="clear"
values="none left right both"
// https://drafts.csswg.org/css-logical-props/#float-clear
extra_specified="inline-start inline-end"
animatable="False"
gecko_enum_prefix="StyleClear"
gecko_ffi_name="mBreakType"
spec="https://www.w3.org/TR/CSS2/visuren.html#flow-control">
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
let ltr = context.style().writing_mode.is_bidi_ltr();
// https://drafts.csswg.org/css-logical-props/#float-clear
match *self {
SpecifiedValue::inline_start if ltr => computed_value::T::left,
SpecifiedValue::inline_start => computed_value::T::right,
SpecifiedValue::inline_end if ltr => computed_value::T::right,
SpecifiedValue::inline_end => computed_value::T::left,
% for value in "none left right both".split():
SpecifiedValue::${value} => computed_value::T::${value},
% endfor
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
match *computed {
% for value in "none left right both".split():
computed_value::T::${value} => SpecifiedValue::${value},
% endfor
}
}
}
</%helpers:single_keyword_computed>
<%helpers:longhand name="-servo-display-for-hypothetical-box"
animatable="False"
derived_from="display"
products="servo"
spec="Internal (not web-exposed)">
pub use super::display::{SpecifiedValue, get_initial_value};
pub use super::display::{parse};
pub mod computed_value {
pub type T = super::SpecifiedValue;
}
#[inline]
pub fn derive_from_display(context: &mut Context) {
let d = context.style().get_box().clone_display();
context.mutate_style().mutate_box().set__servo_display_for_hypothetical_box(d);
}
</%helpers:longhand>
<%helpers:longhand name="vertical-align" animatable="True"
spec="https://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align">
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
<% vertical_align = data.longhands_by_name["vertical-align"] %>
<% vertical_align.keyword = Keyword("vertical-align",
"baseline sub super top text-top middle bottom text-bottom",
extra_gecko_values="middle-with-baseline") %>
<% vertical_align_keywords = vertical_align.keyword.values_for(product) %>
impl HasViewportPercentage for SpecifiedValue {
fn has_viewport_percentage(&self) -> bool {
match *self {
SpecifiedValue::LengthOrPercentage(length) => length.has_viewport_percentage(),
_ => false
}
}
}
/// The `vertical-align` value.
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, PartialEq, Copy)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
% for keyword in vertical_align_keywords:
${to_rust_ident(keyword)},
% endfor
LengthOrPercentage(specified::LengthOrPercentage),
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
% for keyword in vertical_align_keywords:
SpecifiedValue::${to_rust_ident(keyword)} => dest.write_str("${keyword}"),
% endfor
SpecifiedValue::LengthOrPercentage(value) => value.to_css(dest),
}
}
}
/// baseline | sub | super | top | text-top | middle | bottom | text-bottom
/// | <percentage> | <length>
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
input.try(|i| specified::LengthOrPercentage::parse(context, i))
.map(SpecifiedValue::LengthOrPercentage)
.or_else(|_| {
match_ignore_ascii_case! { try!(input.expect_ident()),
% for keyword in vertical_align_keywords:
"${keyword}" => Ok(SpecifiedValue::${to_rust_ident(keyword)}),
% endfor
_ => Err(())
}
})
}
/// The computed value for `vertical-align`.
pub mod computed_value {
use app_units::Au;
use std::fmt;
use style_traits::ToCss;
use values::{CSSFloat, computed};
/// The keywords are the same, and the `LengthOrPercentage` is computed
/// here.
#[allow(non_camel_case_types)]
#[derive(PartialEq, Copy, Clone, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum T {
% for keyword in vertical_align_keywords:
${to_rust_ident(keyword)},
% endfor
LengthOrPercentage(computed::LengthOrPercentage),
}
impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
% for keyword in vertical_align_keywords:
T::${to_rust_ident(keyword)} => dest.write_str("${keyword}"),
% endfor
T::LengthOrPercentage(value) => value.to_css(dest),
}
}
}
}
/// The initial computed value for `vertical-align`.
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::baseline
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self {
% for keyword in vertical_align_keywords:
SpecifiedValue::${to_rust_ident(keyword)} => {
computed_value::T::${to_rust_ident(keyword)}
}
% endfor
SpecifiedValue::LengthOrPercentage(value) =>
computed_value::T::LengthOrPercentage(value.to_computed_value(context)),
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
% for keyword in vertical_align_keywords:
computed_value::T::${to_rust_ident(keyword)} => {
SpecifiedValue::${to_rust_ident(keyword)}
}
% endfor
computed_value::T::LengthOrPercentage(value) =>
SpecifiedValue::LengthOrPercentage(
ToComputedValue::from_computed_value(&value)
),
}
}
}
</%helpers:longhand>
// CSS 2.1, Section 11 - Visual effects
${helpers.single_keyword("-servo-overflow-clip-box", "padding-box content-box",
products="servo", animatable=False, internal=True,
spec="Internal, not web-exposed, \
may be standardized in the future (https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-clip-box)")}
${helpers.single_keyword("overflow-clip-box", "padding-box content-box",
products="gecko", animatable=False, internal=True,
spec="Internal, not web-exposed, \
may be standardized in the future (https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-clip-box)")}
// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
need_clone=True, animatable=False,
gecko_constant_prefix="NS_STYLE_OVERFLOW",
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-x")}
// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
<%helpers:longhand name="overflow-y" need_clone="True" animatable="False"
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-y">
use super::overflow_x;
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
use values::NoViewportPercentage;
pub use self::computed_value::T as SpecifiedValue;
impl NoViewportPercentage for SpecifiedValue {}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.0.to_css(dest)
}
}
/// The specified and computed value for overflow-y is a wrapper on top of
/// `overflow-x`, so we re-use the logic, but prevent errors from mistakenly
/// assign one to other.
///
/// TODO(Manishearth, emilio): We may want to just use the same value.
pub mod computed_value {
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub super::super::overflow_x::computed_value::T);
}
impl ComputedValueAsSpecified for SpecifiedValue {}
#[inline]
#[allow(missing_docs)]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(overflow_x::get_initial_value())
}
#[inline]
#[allow(missing_docs)]
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
overflow_x::parse(context, input).map(SpecifiedValue)
}
</%helpers:longhand>
<%helpers:vector_longhand name="transition-duration"
need_index="True"
animatable="False"
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-duration">
use values::specified::Time;
pub use values::specified::Time as SpecifiedValue;
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
pub mod computed_value {
pub use values::computed::Time as T;
}
#[inline]
pub fn get_initial_value() -> Time {
Time(0.0)
}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
Time::parse(context, input)
}
</%helpers:vector_longhand>
// TODO(pcwalton): Lots more timing functions.
<%helpers:vector_longhand name="transition-timing-function"
need_index="True"
animatable="False"
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-timing-function">
use self::computed_value::StartEnd;
use euclid::point::{Point2D, TypedPoint2D};
use std::fmt;
use std::marker::PhantomData;
use style_traits::ToCss;
// FIXME: This could use static variables and const functions when they are available.
#[inline(always)]
fn ease() -> computed_value::T {
computed_value::T::CubicBezier(TypedPoint2D::new(0.25, 0.1),
TypedPoint2D::new(0.25, 1.0))
}
#[inline(always)]
fn linear() -> computed_value::T {
computed_value::T::CubicBezier(TypedPoint2D::new(0.0, 0.0),
TypedPoint2D::new(1.0, 1.0))
}
#[inline(always)]
fn ease_in() -> computed_value::T {
computed_value::T::CubicBezier(TypedPoint2D::new(0.42, 0.0),
TypedPoint2D::new(1.0, 1.0))
}
#[inline(always)]
fn ease_out() -> computed_value::T {
computed_value::T::CubicBezier(TypedPoint2D::new(0.0, 0.0),
TypedPoint2D::new(0.58, 1.0))
}
#[inline(always)]
fn ease_in_out() -> computed_value::T {
computed_value::T::CubicBezier(TypedPoint2D::new(0.42, 0.0),
TypedPoint2D::new(0.58, 1.0))
}
static STEP_START: computed_value::T =
computed_value::T::Steps(1, StartEnd::Start);
static STEP_END: computed_value::T =
computed_value::T::Steps(1, StartEnd::End);
pub mod computed_value {
use euclid::point::Point2D;
use parser::{Parse, ParserContext};
use std::fmt;
use style_traits::ToCss;
pub use super::parse;
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum T {
CubicBezier(Point2D<f32>, Point2D<f32>),
Steps(u32, StartEnd),
}
impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
T::CubicBezier(p1, p2) => {
try!(dest.write_str("cubic-bezier("));
try!(p1.x.to_css(dest));
try!(dest.write_str(", "));
try!(p1.y.to_css(dest));
try!(dest.write_str(", "));
try!(p2.x.to_css(dest));
try!(dest.write_str(", "));
try!(p2.y.to_css(dest));
dest.write_str(")")
}
T::Steps(steps, start_end) => {
super::serialize_steps(dest, steps, start_end)
}
}
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum StartEnd {
Start,
End,
}
impl ToCss for StartEnd {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
StartEnd::Start => dest.write_str("start"),
StartEnd::End => dest.write_str("end"),
}
}
}
}
define_css_keyword_enum!(FunctionKeyword:
"ease" => Ease,
"linear" => Linear,
"ease-in" => EaseIn,
"ease-out" => EaseOut,
"ease-in-out" => EaseInOut,
"step-start" => StepStart,
"step-end" => StepEnd);
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
CubicBezier(Point2D<f32>, Point2D<f32>),
Steps(u32, StartEnd),
Keyword(FunctionKeyword),
}
impl Parse for SpecifiedValue {
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
if let Ok(function_name) = input.try(|input| input.expect_function()) {
return match_ignore_ascii_case! { function_name,
"cubic-bezier" => {
let (mut p1x, mut p1y, mut p2x, mut p2y) = (0.0, 0.0, 0.0, 0.0);
try!(input.parse_nested_block(|input| {
p1x = try!(specified::parse_number(input));
try!(input.expect_comma());
p1y = try!(specified::parse_number(input));
try!(input.expect_comma());
p2x = try!(specified::parse_number(input));
try!(input.expect_comma());
p2y = try!(specified::parse_number(input));
Ok(())
}));
let (p1, p2) = (Point2D::new(p1x, p1y), Point2D::new(p2x, p2y));
Ok(SpecifiedValue::CubicBezier(p1, p2))
},
"steps" => {
let (mut step_count, mut start_end) = (0, StartEnd::End);
try!(input.parse_nested_block(|input| {
step_count = try!(specified::parse_integer(input));
if input.try(|input| input.expect_comma()).is_ok() {
start_end = try!(match_ignore_ascii_case! {
try!(input.expect_ident()),
"start" => Ok(StartEnd::Start),
"end" => Ok(StartEnd::End),
_ => Err(())
});
}
Ok(())
}));
Ok(SpecifiedValue::Steps(step_count as u32, start_end))
},
_ => Err(())
}
}
Ok(SpecifiedValue::Keyword(try!(FunctionKeyword::parse(input))))
}
}
fn serialize_steps<W>(dest: &mut W, steps: u32,
start_end: StartEnd) -> fmt::Result where W: fmt::Write {
try!(dest.write_str("steps("));
try!(steps.to_css(dest));
if let StartEnd::Start = start_end {
try!(dest.write_str(", start"));
}
dest.write_str(")")
}
// https://drafts.csswg.org/css-transitions/#serializing-a-timing-function
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::CubicBezier(p1, p2) => {
try!(dest.write_str("cubic-bezier("));
try!(p1.x.to_css(dest));
try!(dest.write_str(", "));
try!(p1.y.to_css(dest));
try!(dest.write_str(", "));
try!(p2.x.to_css(dest));
try!(dest.write_str(", "));
try!(p2.y.to_css(dest));
dest.write_str(")")
},
SpecifiedValue::Steps(steps, start_end) => {
serialize_steps(dest, steps, start_end)
},
SpecifiedValue::Keyword(keyword) => {
match keyword {
FunctionKeyword::StepStart => {
serialize_steps(dest, 1, StartEnd::Start)
},
FunctionKeyword::StepEnd => {
serialize_steps(dest, 1, StartEnd::End)
},
_ => {
keyword.to_css(dest)
},
}
},
}
}
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
match *self {
SpecifiedValue::CubicBezier(p1, p2) => {
computed_value::T::CubicBezier(p1, p2)
},
SpecifiedValue::Steps(count, start_end) => {
computed_value::T::Steps(count, start_end)
},
SpecifiedValue::Keyword(keyword) => {
match keyword {
FunctionKeyword::Ease => ease(),
FunctionKeyword::Linear => linear(),
FunctionKeyword::EaseIn => ease_in(),
FunctionKeyword::EaseOut => ease_out(),
FunctionKeyword::EaseInOut => ease_in_out(),
FunctionKeyword::StepStart => STEP_START,
FunctionKeyword::StepEnd => STEP_END,
}
},
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
computed_value::T::CubicBezier(p1, p2) => {
SpecifiedValue::CubicBezier(p1, p2)
},
computed_value::T::Steps(count, start_end) => {
SpecifiedValue::Steps(count, start_end)
},
}
}
}
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
#[inline]
pub fn get_initial_value() -> computed_value::T {
ease()
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
ToComputedValue::from_computed_value(&ease())
}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
SpecifiedValue::parse(context, input)
}
</%helpers:vector_longhand>
<%helpers:vector_longhand name="transition-property"
allow_empty="True"
need_index="True"
animatable="False"
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-property">
use values::computed::ComputedValueAsSpecified;
pub use properties::animated_properties::TransitionProperty;
pub use properties::animated_properties::TransitionProperty as SpecifiedValue;
pub mod computed_value {
use std::fmt;
use style_traits::ToCss;
// NB: Can't generate the type here because it needs all the longhands
// generated beforehand.
pub use super::SpecifiedValue as T;
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
SpecifiedValue::parse(input)
}
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
impl ComputedValueAsSpecified for SpecifiedValue { }
</%helpers:vector_longhand>
<%helpers:vector_longhand name="transition-delay"
need_index="True"
animatable="False"
spec="https://drafts.csswg.org/css-transitions/#propdef-transition-delay">
pub use properties::longhands::transition_duration::single_value::SpecifiedValue;
pub use properties::longhands::transition_duration::single_value::computed_value;
pub use properties::longhands::transition_duration::single_value::{get_initial_value, parse};
</%helpers:vector_longhand>
<%helpers:vector_longhand name="animation-name"
allow_empty="True"
need_index="True"
animatable="False",
allowed_in_keyframe_block="False"
spec="https://drafts.csswg.org/css-animations/#propdef-animation-name">
use Atom;
use std::fmt;
use std::ops::Deref;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
use values::NoViewportPercentage;
pub mod computed_value {
pub use super::SpecifiedValue as T;
}
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue(pub Atom);
impl fmt::Display for SpecifiedValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str(&*self.0.to_string())
}
}
impl Parse for SpecifiedValue {
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
use cssparser::Token;
Ok(match input.next() {
Ok(Token::Ident(ref value)) if value != "none" => SpecifiedValue(Atom::from(&**value)),
Ok(Token::QuotedString(value)) => SpecifiedValue(Atom::from(&*value)),
_ => return Err(()),
})
}
}
impl NoViewportPercentage for SpecifiedValue {}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
SpecifiedValue::parse(context, input)
}
impl ComputedValueAsSpecified for SpecifiedValue {}
</%helpers:vector_longhand>
<%helpers:vector_longhand name="animation-duration"
need_index="True"
animatable="False",
spec="https://drafts.csswg.org/css-animations/#propdef-animation-duration",
allowed_in_keyframe_block="False">
pub use properties::longhands::transition_duration::single_value::computed_value;
pub use properties::longhands::transition_duration::single_value::{get_initial_value, parse};
pub use properties::longhands::transition_duration::single_value::SpecifiedValue;
</%helpers:vector_longhand>
<%helpers:vector_longhand name="animation-timing-function"
need_index="True"
animatable="False",
spec="https://drafts.csswg.org/css-animations/#propdef-animation-timing-function",
allowed_in_keyframe_block="False">
pub use properties::longhands::transition_timing_function::single_value::computed_value;
pub use properties::longhands::transition_timing_function::single_value::get_initial_value;
pub use properties::longhands::transition_timing_function::single_value::get_initial_specified_value;
pub use properties::longhands::transition_timing_function::single_value::parse;
pub use properties::longhands::transition_timing_function::single_value::SpecifiedValue;
</%helpers:vector_longhand>
<%helpers:vector_longhand name="animation-iteration-count"
need_index="True"
animatable="False",
spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count",
allowed_in_keyframe_block="False">
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
use values::NoViewportPercentage;
pub mod computed_value {
pub use super::SpecifiedValue as T;
}
// https://drafts.csswg.org/css-animations/#animation-iteration-count
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
Number(f32),
Infinite,
}
impl Parse for SpecifiedValue {
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
if input.try(|input| input.expect_ident_matching("infinite")).is_ok() {
return Ok(SpecifiedValue::Infinite)
}
let number = try!(input.expect_number());
if number < 0.0 {
return Err(());
}
Ok(SpecifiedValue::Number(number))
}
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::Number(n) => write!(dest, "{}", n),
SpecifiedValue::Infinite => dest.write_str("infinite"),
}
}
}
impl NoViewportPercentage for SpecifiedValue {}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::Number(1.0)
}
#[inline]
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
SpecifiedValue::parse(context, input)
}
impl ComputedValueAsSpecified for SpecifiedValue {}
</%helpers:vector_longhand>
${helpers.single_keyword("animation-direction",
"normal reverse alternate alternate-reverse",
need_index=True,
animatable=False,
vector=True,
spec="https://drafts.csswg.org/css-animations/#propdef-animation-direction",
allowed_in_keyframe_block=False)}
// animation-play-state is the exception to the rule for allowed_in_keyframe_block:
// https://drafts.csswg.org/css-animations/#keyframes
${helpers.single_keyword("animation-play-state",
"running paused",
need_clone=True,
need_index=True,
animatable=False,
vector=True,
spec="https://drafts.csswg.org/css-animations/#propdef-animation-play-state",
allowed_in_keyframe_block=True)}
${helpers.single_keyword("animation-fill-mode",
"none forwards backwards both",
need_index=True,
animatable=False,
vector=True,
spec="https://drafts.csswg.org/css-animations/#propdef-animation-fill-mode",
allowed_in_keyframe_block=False)}
<%helpers:vector_longhand name="animation-delay"
need_index="True"
animatable="False",
spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay",
allowed_in_keyframe_block="False">
pub use properties::longhands::transition_duration::single_value::computed_value;
pub use properties::longhands::transition_duration::single_value::{get_initial_value, parse};
pub use properties::longhands::transition_duration::single_value::SpecifiedValue;
</%helpers:vector_longhand>
<%helpers:longhand products="gecko" name="scroll-snap-points-y" animatable="False"
spec="Nonstandard (https://www.w3.org/TR/2015/WD-css-snappoints-1-20150326/#scroll-snap-points)">
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
use values::specified::LengthOrPercentage;
impl HasViewportPercentage for SpecifiedValue {
fn has_viewport_percentage(&self) -> bool {
match *self {
SpecifiedValue::Repeat(length) => length.has_viewport_percentage(),
_ => false
}
}
}
pub mod computed_value {
use values::computed::LengthOrPercentage;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<LengthOrPercentage>);
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
None,
Repeat(LengthOrPercentage),
}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match self.0 {
None => dest.write_str("none"),
Some(l) => {
try!(dest.write_str("repeat("));
try!(l.to_css(dest));
dest.write_str(")")
},
}
}
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::None => dest.write_str("none"),
SpecifiedValue::Repeat(ref l) => {
try!(dest.write_str("repeat("));
try!(l.to_css(dest));
dest.write_str(")")
},
}
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(None)
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self {
SpecifiedValue::None => computed_value::T(None),
SpecifiedValue::Repeat(l) =>