mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #16067 - Wafflespeanut:grid, r=nox,Wafflespeanut
Stylo: Add support for grid-template-{rows,columns} This has the implementation of grid's `<track-list>` nightmare. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15311 <!-- Either: --> - [x] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16067) <!-- Reviewable:end -->
This commit is contained in:
commit
0b3fd8de76
11 changed files with 908 additions and 49 deletions
|
@ -5,10 +5,16 @@
|
|||
//! Tests for parsing and serialization of values/properties
|
||||
|
||||
use cssparser::Parser;
|
||||
use euclid::size::TypedSize2D;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::context::QuirksMode;
|
||||
use style::font_metrics::ServoMetricsProvider;
|
||||
use style::media_queries::{Device, MediaType};
|
||||
use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
||||
use style::properties::{ComputedValues, StyleBuilder};
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style::values::computed::{Context, ToComputedValue};
|
||||
use style_traits::ToCss;
|
||||
|
||||
fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
|
@ -24,6 +30,32 @@ fn parse_entirely<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F,
|
|||
parse(|context, parser| parser.parse_entirely(|p| f(context, p)), s)
|
||||
}
|
||||
|
||||
fn assert_computed_serialization<C, F, T>(f: F, input: &str, output: &str)
|
||||
where F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>,
|
||||
T: ToComputedValue<ComputedValue=C>, C: ToCss
|
||||
{
|
||||
let viewport_size = TypedSize2D::new(0., 0.);
|
||||
let initial_style = ComputedValues::initial_values();
|
||||
let device = Device::new(MediaType::Screen, viewport_size);
|
||||
|
||||
let context = Context {
|
||||
is_root_element: true,
|
||||
device: &device,
|
||||
inherited_style: initial_style,
|
||||
layout_parent_style: initial_style,
|
||||
style: StyleBuilder::for_derived_style(&initial_style),
|
||||
cached_system_font: None,
|
||||
font_metrics_provider: &ServoMetricsProvider,
|
||||
in_media_query: false,
|
||||
quirks_mode: QuirksMode::NoQuirks,
|
||||
};
|
||||
|
||||
let parsed = parse(f, input).unwrap();
|
||||
let computed = parsed.to_computed_value(&context);
|
||||
let serialized = ToCss::to_css_string(&computed);
|
||||
assert_eq!(serialized, output);
|
||||
}
|
||||
|
||||
// This is a macro so that the file/line information
|
||||
// is preserved in the panic
|
||||
macro_rules! assert_roundtrip_with_context {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use parsing::{parse, parse_entirely};
|
||||
use parsing::{assert_computed_serialization, parse, parse_entirely};
|
||||
use style::parser::Parse;
|
||||
use style::values::specified::position::*;
|
||||
use style_traits::ToCss;
|
||||
|
@ -168,3 +168,68 @@ fn test_grid_auto_flow() {
|
|||
assert!(parse(grid_auto_flow::parse, "column 'dense'").is_err());
|
||||
assert!(parse(grid_auto_flow::parse, "column 2px dense").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_grid_auto_rows_columns() {
|
||||
use style::properties::longhands::grid_auto_rows;
|
||||
|
||||
// the grammar is <track-size>+ but gecko supports only a single value, so we've clamped ourselves
|
||||
assert_roundtrip_with_context!(grid_auto_rows::parse, "55%");
|
||||
assert_roundtrip_with_context!(grid_auto_rows::parse, "0.5fr");
|
||||
assert_roundtrip_with_context!(grid_auto_rows::parse, "fit-content(11%)");
|
||||
// only <inflexible-breadth> is allowed in first arg of minmax
|
||||
assert!(parse(grid_auto_rows::parse, "minmax(1fr, max-content)").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_grid_template_rows_columns() {
|
||||
use style::properties::longhands::grid_template_rows;
|
||||
|
||||
assert_roundtrip_with_context!(grid_template_rows::parse, "none"); // none keyword
|
||||
// <track-size>{2} with `<track-breadth> minmax(<inflexible-breadth>, <track-breadth>)`
|
||||
assert_roundtrip_with_context!(grid_template_rows::parse, "1fr minmax(min-content, 1fr)");
|
||||
// <track-size> with <track-breadth> as <length-percentage>
|
||||
assert_roundtrip_with_context!(grid_template_rows::parse, "calc(4em + 5px)");
|
||||
// <track-size> with <length> followed by <track-repeat> with `<track-size>{3}` (<flex>, auto, minmax)
|
||||
assert_roundtrip_with_context!(grid_template_rows::parse, "10px repeat(2, 1fr auto minmax(200px, 1fr))");
|
||||
// <track-repeat> with `<track-size> <line-names>` followed by <track-size>
|
||||
assert_roundtrip_with_context!(grid_template_rows::parse, "repeat(4, 10px [col-start] 250px [col-end]) 10px");
|
||||
// mixture of <track-size>, <track-repeat> and <line-names>
|
||||
assert_roundtrip_with_context!(grid_template_rows::parse,
|
||||
"[a] auto [b] minmax(min-content, 1fr) [b c d] repeat(2, [e] 40px) repeat(5, [f g] auto [h]) [i]");
|
||||
|
||||
// no span allowed in <line-names>
|
||||
assert!(parse(grid_template_rows::parse, "[a span] 10px").is_err());
|
||||
// <track-list> needs at least one <track-size> | <track-repeat>
|
||||
assert!(parse(grid_template_rows::parse, "[a b c]").is_err());
|
||||
// at least one argument of <fixed-size> should be a <fixed-breadth> (i.e., <length-percentage>)
|
||||
assert!(parse(grid_template_rows::parse, "[a b] repeat(auto-fill, 50px) minmax(auto, 1fr)").is_err());
|
||||
// fit-content is not a <fixed-size>
|
||||
assert!(parse(grid_template_rows::parse, "[a b] repeat(auto-fill, fit-content(20%))").is_err());
|
||||
// <auto-track-list> only allows <fixed-size> | <fixed-repeat>
|
||||
assert!(parse(grid_template_rows::parse, "[a] repeat(2, auto) repeat(auto-fill, 10px)").is_err());
|
||||
// only <inflexible-breadth> allowed in <auto-track-repeat>
|
||||
assert!(parse(grid_template_rows::parse, "[a] repeat(auto-fill, 1fr)").is_err());
|
||||
// <auto-track-repeat> is allowed only once
|
||||
assert!(parse(grid_template_rows::parse, "[a] repeat(auto-fit, [b] 8px) [c] repeat(auto-fill, [c] 8px)").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_computed_grid_template_rows_colums() {
|
||||
use style::properties::longhands::grid_template_rows;
|
||||
|
||||
assert_computed_serialization(grid_template_rows::parse,
|
||||
"[a] repeat(calc(1 + 1), [b] auto)", "[a b] auto [b] auto");
|
||||
|
||||
assert_computed_serialization(grid_template_rows::parse,
|
||||
"[a] repeat(2, [b c] auto [e] auto [d])",
|
||||
"[a b c] auto [e] auto [d b c] auto [e] auto [d]");
|
||||
|
||||
assert_computed_serialization(grid_template_rows::parse,
|
||||
"[a] 50px [b] 10% [b c d] repeat(2, [e] 40px [f]) [g] repeat(auto-fill, [h i] 20px [j]) [k] 10px [l]",
|
||||
"[a] 50px [b] 10% [b c d e] 40px [f e] 40px [f g] repeat(auto-fill, [h i] 20px [j]) [k] 10px [l]");
|
||||
|
||||
assert_computed_serialization(grid_template_rows::parse,
|
||||
"10px repeat(2, 1fr auto minmax(200px, 1fr))",
|
||||
"10px minmax(auto, 1fr) auto minmax(200px, 1fr) minmax(auto, 1fr) auto minmax(200px, 1fr)");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue