mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Improve Percentage -> LengthPercentage conversion
This doesn't change behavior because we only use them for images that have no clamping. Depends on D147008 Differential Revision: https://phabricator.services.mozilla.com/D147511
This commit is contained in:
parent
079fce37d2
commit
6ae56890b3
3 changed files with 17 additions and 7 deletions
|
@ -733,12 +733,12 @@ impl Gradient {
|
||||||
if items.is_empty() {
|
if items.is_empty() {
|
||||||
items = vec![
|
items = vec![
|
||||||
generic::GradientItem::ComplexColorStop {
|
generic::GradientItem::ComplexColorStop {
|
||||||
color: Color::transparent().into(),
|
color: Color::transparent(),
|
||||||
position: Percentage::zero().into(),
|
position: LengthPercentage::zero_percent(),
|
||||||
},
|
},
|
||||||
generic::GradientItem::ComplexColorStop {
|
generic::GradientItem::ComplexColorStop {
|
||||||
color: Color::transparent().into(),
|
color: Color::transparent(),
|
||||||
position: Percentage::hundred().into(),
|
position: LengthPercentage::hundred_percent(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
} else if items.len() == 1 {
|
} else if items.len() == 1 {
|
||||||
|
|
|
@ -1328,10 +1328,9 @@ impl From<NoCalcLength> for LengthPercentage {
|
||||||
impl From<Percentage> for LengthPercentage {
|
impl From<Percentage> for LengthPercentage {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(pc: Percentage) -> Self {
|
fn from(pc: Percentage) -> Self {
|
||||||
if pc.is_calc() {
|
if let Some(clamping_mode) = pc.calc_clamping_mode() {
|
||||||
// FIXME(emilio): Hard-coding the clamping mode is suspect.
|
|
||||||
LengthPercentage::Calc(Box::new(CalcLengthPercentage {
|
LengthPercentage::Calc(Box::new(CalcLengthPercentage {
|
||||||
clamping_mode: AllowedNumericType::All,
|
clamping_mode,
|
||||||
node: CalcNode::Leaf(calc::Leaf::Percentage(pc.get())),
|
node: CalcNode::Leaf(calc::Leaf::Percentage(pc.get())),
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
|
@ -1364,6 +1363,12 @@ impl LengthPercentage {
|
||||||
LengthPercentage::Percentage(computed::Percentage::zero())
|
LengthPercentage::Percentage(computed::Percentage::zero())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
/// Returns a `100%` value.
|
||||||
|
pub fn hundred_percent() -> LengthPercentage {
|
||||||
|
LengthPercentage::Percentage(computed::Percentage::hundred())
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_internal<'i, 't>(
|
fn parse_internal<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
|
|
|
@ -97,6 +97,11 @@ impl Percentage {
|
||||||
self.calc_clamping_mode.is_some()
|
self.calc_clamping_mode.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the calc() clamping mode for this percentage.
|
||||||
|
pub fn calc_clamping_mode(&self) -> Option<AllowedNumericType> {
|
||||||
|
self.calc_clamping_mode
|
||||||
|
}
|
||||||
|
|
||||||
/// Reverses this percentage, preserving calc-ness.
|
/// Reverses this percentage, preserving calc-ness.
|
||||||
///
|
///
|
||||||
/// For example: If it was 20%, convert it into 80%.
|
/// For example: If it was 20%, convert it into 80%.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue