mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
Auto merge of #12783 - Wafflespeanut:word_spacing, r=Manishearth
Prefer length and percentage for word spacing <!-- Please describe your changes on the following line: --> The goal is to make use of `LengthOrPercentage` for word spacing in `ShapingOptions`, but since it makes use of `f32` which doesn't implement `Hash`, we're going for `NotNan<f32>` from [ordered-float](https://github.com/reem/rust-ordered-float/), which supports hashing. Instead of implementing `Hash` for `LengthOrPercentage` and thereby the inner types like `CSSFloat`, `CalcLengthOrPercentage`, etc., we convert it to `(Au, NotNan<f32>)`. --- <!-- 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 <!-- Either: --> - [ ] 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/12783) <!-- Reviewable:end -->
This commit is contained in:
commit
3b676bc85d
15 changed files with 135 additions and 10 deletions
|
@ -34,6 +34,7 @@ lazy_static = "0.2"
|
|||
log = "0.3.5"
|
||||
matches = "0.1"
|
||||
num-traits = "0.1.32"
|
||||
ordered-float = "0.2.2"
|
||||
rand = "0.3"
|
||||
rustc-serialize = "0.3"
|
||||
selectors = "0.7"
|
||||
|
|
|
@ -57,6 +57,7 @@ extern crate log;
|
|||
#[macro_use]
|
||||
extern crate matches;
|
||||
extern crate num_traits;
|
||||
extern crate ordered_float;
|
||||
extern crate rand;
|
||||
extern crate rustc_serialize;
|
||||
extern crate selectors;
|
||||
|
|
|
@ -285,7 +285,7 @@
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Normal,
|
||||
Specified(specified::Length), // FIXME(SimonSapin) support percentages
|
||||
Specified(specified::LengthOrPercentage),
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
|
@ -298,10 +298,10 @@
|
|||
}
|
||||
|
||||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
use values::computed::LengthOrPercentage;
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Option<Au>);
|
||||
pub struct T(pub Option<LengthOrPercentage>);
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
|
@ -326,7 +326,7 @@
|
|||
match *self {
|
||||
SpecifiedValue::Normal => computed_value::T(None),
|
||||
SpecifiedValue::Specified(l) =>
|
||||
computed_value::T(Some(l.to_computed_value(context)))
|
||||
computed_value::T(Some(l.to_computed_value(context))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +335,8 @@
|
|||
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::LengthOrPercentage::parse_non_negative(input)
|
||||
.map(SpecifiedValue::Specified)
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use app_units::Au;
|
||||
use euclid::size::Size2D;
|
||||
use ordered_float::NotNaN;
|
||||
use properties::ComputedValues;
|
||||
use std::fmt;
|
||||
use super::LocalToCss;
|
||||
|
@ -241,6 +242,15 @@ impl LengthOrPercentage {
|
|||
Length(_) | Percentage(_) | Calc(_) => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_hash_key(&self) -> (Au, NotNaN<f32>) {
|
||||
use self::LengthOrPercentage::*;
|
||||
match *self {
|
||||
Length(l) => (l, NotNaN::new(0.0).unwrap()),
|
||||
Percentage(p) => (Au(0), NotNaN::new(p).unwrap()),
|
||||
Calc(c) => (c.length(), NotNaN::new(c.percentage()).unwrap()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for LengthOrPercentage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue