mirror of
https://github.com/servo/servo.git
synced 2025-07-08 16:03:40 +01:00
Auto merge of #15237 - samuknet:negative-letter-spacing-word-spacing, r=emilio
Allow negative values for letter-spacing and word-spacing. Inline Le… <!-- Please describe your changes on the following line: --> Allow negative values when parsing `letter-spacing` and `word-spacing`. Inline `parse_non_negative` in `Length`. --- <!-- 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 #15204 (github issue number if applicable). <!-- 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/15237) <!-- Reviewable:end -->
This commit is contained in:
commit
449147b8df
5 changed files with 28 additions and 11 deletions
|
@ -335,11 +335,11 @@ ${helpers.single_keyword("text-align-last",
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
||||
Ok(SpecifiedValue::Normal)
|
||||
} else {
|
||||
specified::Length::parse_non_negative(input).map(SpecifiedValue::Specified)
|
||||
specified::Length::parse(context, input).map(SpecifiedValue::Specified)
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
|
@ -416,11 +416,11 @@ ${helpers.single_keyword("text-align-last",
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
||||
Ok(SpecifiedValue::Normal)
|
||||
} else {
|
||||
specified::LengthOrPercentage::parse_non_negative(input)
|
||||
specified::LengthOrPercentage::parse(context, input)
|
||||
.map(SpecifiedValue::Specified)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -463,6 +463,7 @@ impl Length {
|
|||
}
|
||||
|
||||
/// Parse a non-negative length
|
||||
#[inline]
|
||||
pub fn parse_non_negative(input: &mut Parser) -> Result<Length, ()> {
|
||||
Length::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,29 @@ use media_queries::CSSErrorReporterTest;
|
|||
use style::parser::ParserContext;
|
||||
use style::stylesheets::Origin;
|
||||
|
||||
#[test]
|
||||
fn negative_letter_spacing_should_parse_properly() {
|
||||
use style::properties::longhands::letter_spacing;
|
||||
use style::properties::longhands::letter_spacing::SpecifiedValue;
|
||||
use style::values::specified::length::{Length, NoCalcLength, FontRelativeLength};
|
||||
|
||||
let negative_value = parse_longhand!(letter_spacing, "-0.5em");
|
||||
let expected = SpecifiedValue::Specified(Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(-0.5))));
|
||||
assert_eq!(negative_value, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn negative_word_spacing_should_parse_properly() {
|
||||
use style::properties::longhands::word_spacing;
|
||||
use style::properties::longhands::word_spacing::SpecifiedValue;
|
||||
use style::values::specified::length::{NoCalcLength, LengthOrPercentage, FontRelativeLength};
|
||||
|
||||
let negative_value = parse_longhand!(word_spacing, "-0.5em");
|
||||
let expected = SpecifiedValue::Specified(LengthOrPercentage::Length(NoCalcLength::FontRelative(
|
||||
FontRelativeLength::Em(-0.5))));
|
||||
assert_eq!(negative_value, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_emphasis_style_longhand_should_parse_properly() {
|
||||
use style::properties::longhands::text_emphasis_style;
|
||||
|
@ -79,7 +102,6 @@ fn test_text_emphasis_position() {
|
|||
assert_eq!(left_under, SpecifiedValue(HorizontalWritingModeValue::Under, VerticalWritingModeValue::Left));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn webkit_text_stroke_shorthand_should_parse_properly() {
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[text-word-spacing-001.htm]
|
||||
type: reftest
|
||||
expected: FAIL
|
|
@ -1,3 +0,0 @@
|
|||
[c542-letter-sp-001.htm]
|
||||
type: reftest
|
||||
expected: FAIL
|
Loading…
Add table
Add a link
Reference in a new issue