mirror of
https://github.com/servo/servo.git
synced 2025-09-17 18:38:22 +01:00
Style: Do not immediately convert absolute specified lengths
The NoCalcLength::Absolute variant has been rewritten to accommodate other units than Au with the new AbsoluteLength enum. This avoids loss of precision for some operations. The conversion from floating point absolute lengths to integer application unit values adopts the same clamping limits as Gecko.
This commit is contained in:
parent
d77d752990
commit
7ecee05e4a
12 changed files with 161 additions and 51 deletions
|
@ -2,9 +2,13 @@
|
|||
* 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 cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::parser::Parse;
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::stylesheets::Origin;
|
||||
use style::values::specified::length::Length;
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
fn test_calc() {
|
||||
|
@ -13,3 +17,14 @@ fn test_calc() {
|
|||
assert!(parse(Length::parse, "calc(1px + 2px )").is_ok());
|
||||
assert!(parse(Length::parse, "calc( 1px + 2px)").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_length_literals() {
|
||||
assert_roundtrip_with_context!(Length::parse, "0.33px", "0.33px");
|
||||
assert_roundtrip_with_context!(Length::parse, "0.33in", "0.33in");
|
||||
assert_roundtrip_with_context!(Length::parse, "0.33cm", "0.33cm");
|
||||
assert_roundtrip_with_context!(Length::parse, "0.33mm", "0.33mm");
|
||||
assert_roundtrip_with_context!(Length::parse, "0.33q", "0.33q");
|
||||
assert_roundtrip_with_context!(Length::parse, "0.33pt", "0.33pt");
|
||||
assert_roundtrip_with_context!(Length::parse, "0.33pc", "0.33pc");
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use app_units::Au;
|
|||
use style::properties::PropertyDeclaration;
|
||||
use style::properties::longhands::border_top_width;
|
||||
use style::values::HasViewportPercentage;
|
||||
use style::values::specified::{Length, NoCalcLength, ViewportPercentageLength};
|
||||
use style::values::specified::{AbsoluteLength, Length, NoCalcLength, ViewportPercentageLength};
|
||||
|
||||
#[test]
|
||||
fn has_viewport_percentage_for_specified_value() {
|
||||
|
@ -20,7 +20,7 @@ fn has_viewport_percentage_for_specified_value() {
|
|||
|
||||
let pabs = PropertyDeclaration::BorderTopWidth(Box::new(
|
||||
border_top_width::SpecifiedValue::from_length(
|
||||
Length::NoCalc(NoCalcLength::Absolute(Au(100)))
|
||||
Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px())))
|
||||
)
|
||||
));
|
||||
assert!(!pabs.has_viewport_percentage());
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use style::values::HasViewportPercentage;
|
||||
use style::values::specified::{ViewportPercentageLength, NoCalcLength};
|
||||
use style::values::specified::{AbsoluteLength, ViewportPercentageLength, NoCalcLength};
|
||||
use style::values::specified::length::{CalcLengthOrPercentage, CalcUnit};
|
||||
|
||||
#[test]
|
||||
fn length_has_viewport_percentage() {
|
||||
let l = NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.));
|
||||
assert!(l.has_viewport_percentage());
|
||||
let l = NoCalcLength::Absolute(Au(100));
|
||||
let l = NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px()));
|
||||
assert!(!l.has_viewport_percentage());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[min-width-001.htm]
|
||||
type: reftest
|
||||
expected: FAIL
|
|
@ -3,15 +3,3 @@
|
|||
[uppercase value]
|
||||
expected: FAIL
|
||||
|
||||
[cssText order]
|
||||
expected: FAIL
|
||||
|
||||
[another cssText order (non-alphabetical order)]
|
||||
expected: FAIL
|
||||
|
||||
[whitespaces in value]
|
||||
expected: FAIL
|
||||
|
||||
[invalid property does not appear]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[min-width-001.htm]
|
||||
type: reftest
|
||||
expected: FAIL
|
|
@ -25171,7 +25171,7 @@
|
|||
"testharness"
|
||||
],
|
||||
"mozilla/calc.html": [
|
||||
"c239c441c90e4d4ed94458eae5b2defabb47e984",
|
||||
"028fc71bdc9a99d552ba552036d38fb4eef11bc1",
|
||||
"testharness"
|
||||
],
|
||||
"mozilla/canvas.initial.reset.2dstate.html": [
|
||||
|
|
|
@ -41,7 +41,7 @@ var widthTests = [
|
|||
['calc(10px + 10em - 10px)', 'calc(10em + 0px)', '160px'],
|
||||
|
||||
// Fold absolute units
|
||||
['calc(1px + 1pt + 1pc + 1in + 1cm + 1mm)', 'calc(155.88333333333333px)', '155.88333333333333px'],
|
||||
['calc(1px + 1pt + 1pc + 1in + 1cm + 1mm)', 'calc(155.91666666666666px)', '155.91666666666666px'],
|
||||
|
||||
// Alphabetical order
|
||||
['calc(0ch + 0px + 0pt + 0pc + 0in + 0cm + 0mm + 0rem + 0em + 0ex + 0% + 0vw + 0vh + 0vmin + 0vmax)',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue