mirror of
https://github.com/servo/servo.git
synced 2025-07-02 13:03:43 +01:00
Implement a URL-generic type for ListStyleImage <!-- Please describe your changes on the following line: --> This should fix the following two "expected to fail" tests described in https://github.com/servo/servo/issues/18015: - getComputedStyle(elem) for url() listStyleImage uses the resolved URL and elem.style uses the original URL - getComputedStyle(elem) for url() listStyle uses the resolved URL and elem.style uses the original URL I updated the test failure expectations by removing the corresponding `.ini` file. --- <!-- 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 #18015 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- 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/20482) <!-- Reviewable:end -->
114 lines
4.6 KiB
Rust
114 lines
4.6 KiB
Rust
/* 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" />
|
|
|
|
<%helpers:shorthand name="list-style"
|
|
sub_properties="list-style-position list-style-image list-style-type"
|
|
derive_serialize="True"
|
|
spec="https://drafts.csswg.org/css-lists/#propdef-list-style">
|
|
use properties::longhands::{list_style_image, list_style_position, list_style_type};
|
|
use values::specified::url::ImageUrlOrNone;
|
|
|
|
pub fn parse_value<'i, 't>(
|
|
context: &ParserContext,
|
|
input: &mut Parser<'i, 't>,
|
|
) -> Result<Longhands, ParseError<'i>> {
|
|
// `none` is ambiguous until we've finished parsing the shorthands, so we count the number
|
|
// of times we see it.
|
|
let mut nones = 0u8;
|
|
let (mut image, mut position, mut list_style_type, mut any) = (None, None, None, false);
|
|
loop {
|
|
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
|
nones = nones + 1;
|
|
if nones > 2 {
|
|
return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("none".into())))
|
|
}
|
|
any = true;
|
|
continue
|
|
}
|
|
|
|
if image.is_none() {
|
|
if let Ok(value) = input.try(|input| list_style_image::parse(context, input)) {
|
|
image = Some(value);
|
|
any = true;
|
|
continue
|
|
}
|
|
}
|
|
|
|
if position.is_none() {
|
|
if let Ok(value) = input.try(|input| list_style_position::parse(context, input)) {
|
|
position = Some(value);
|
|
any = true;
|
|
continue
|
|
}
|
|
}
|
|
|
|
// list-style-type must be checked the last, because it accepts
|
|
// arbitrary identifier for custom counter style, and thus may
|
|
// affect values of list-style-position.
|
|
if list_style_type.is_none() {
|
|
if let Ok(value) = input.try(|input| list_style_type::parse(context, input)) {
|
|
list_style_type = Some(value);
|
|
any = true;
|
|
continue
|
|
}
|
|
}
|
|
break
|
|
}
|
|
|
|
let position = unwrap_or_initial!(list_style_position, position);
|
|
|
|
fn list_style_type_none() -> list_style_type::SpecifiedValue {
|
|
% if product == "servo":
|
|
list_style_type::SpecifiedValue::None
|
|
% else:
|
|
use values::generics::CounterStyleOrNone;
|
|
list_style_type::SpecifiedValue::CounterStyle(CounterStyleOrNone::None)
|
|
% endif
|
|
}
|
|
|
|
// If there are two `none`s, then we can't have a type or image; if there is one `none`,
|
|
// then we can't have both a type *and* an image; if there is no `none` then we're fine as
|
|
// long as we parsed something.
|
|
match (any, nones, list_style_type, image) {
|
|
(true, 2, None, None) => {
|
|
Ok(expanded! {
|
|
list_style_position: position,
|
|
list_style_image: ImageUrlOrNone::none(),
|
|
list_style_type: list_style_type_none(),
|
|
})
|
|
}
|
|
(true, 1, None, Some(image)) => {
|
|
Ok(expanded! {
|
|
list_style_position: position,
|
|
list_style_image: image,
|
|
list_style_type: list_style_type_none(),
|
|
})
|
|
}
|
|
(true, 1, Some(list_style_type), None) => {
|
|
Ok(expanded! {
|
|
list_style_position: position,
|
|
list_style_image: ImageUrlOrNone::none(),
|
|
list_style_type: list_style_type,
|
|
})
|
|
}
|
|
(true, 1, None, None) => {
|
|
Ok(expanded! {
|
|
list_style_position: position,
|
|
list_style_image: ImageUrlOrNone::none(),
|
|
list_style_type: list_style_type_none(),
|
|
})
|
|
}
|
|
(true, 0, list_style_type, image) => {
|
|
Ok(expanded! {
|
|
list_style_position: position,
|
|
list_style_image: unwrap_or_initial!(list_style_image, image),
|
|
list_style_type: unwrap_or_initial!(list_style_type),
|
|
})
|
|
}
|
|
_ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
|
}
|
|
}
|
|
</%helpers:shorthand>
|