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() {
|
||||
items = vec![
|
||||
generic::GradientItem::ComplexColorStop {
|
||||
color: Color::transparent().into(),
|
||||
position: Percentage::zero().into(),
|
||||
color: Color::transparent(),
|
||||
position: LengthPercentage::zero_percent(),
|
||||
},
|
||||
generic::GradientItem::ComplexColorStop {
|
||||
color: Color::transparent().into(),
|
||||
position: Percentage::hundred().into(),
|
||||
color: Color::transparent(),
|
||||
position: LengthPercentage::hundred_percent(),
|
||||
},
|
||||
];
|
||||
} else if items.len() == 1 {
|
||||
|
|
|
@ -1328,10 +1328,9 @@ impl From<NoCalcLength> for LengthPercentage {
|
|||
impl From<Percentage> for LengthPercentage {
|
||||
#[inline]
|
||||
fn from(pc: Percentage) -> Self {
|
||||
if pc.is_calc() {
|
||||
// FIXME(emilio): Hard-coding the clamping mode is suspect.
|
||||
if let Some(clamping_mode) = pc.calc_clamping_mode() {
|
||||
LengthPercentage::Calc(Box::new(CalcLengthPercentage {
|
||||
clamping_mode: AllowedNumericType::All,
|
||||
clamping_mode,
|
||||
node: CalcNode::Leaf(calc::Leaf::Percentage(pc.get())),
|
||||
}))
|
||||
} else {
|
||||
|
@ -1364,6 +1363,12 @@ impl LengthPercentage {
|
|||
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>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
|
|
|
@ -97,6 +97,11 @@ impl Percentage {
|
|||
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.
|
||||
///
|
||||
/// For example: If it was 20%, convert it into 80%.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue