Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move specified and computed percentages to submodules
- Loading branch information
Showing
7 changed files
with
212 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/. */ | ||
|
||
//! Computed percentages. | ||
|
||
use properties::animated_properties::Animatable; | ||
use std::fmt; | ||
use style_traits::ToCss; | ||
use values::CSSFloat; | ||
use values::animated::ToAnimatedZero; | ||
|
||
/// A computed percentage. | ||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, Default, HasViewportPercentage, PartialEq)] | ||
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] | ||
pub struct Percentage(pub CSSFloat); | ||
|
||
impl Percentage { | ||
/// 0% | ||
#[inline] | ||
pub fn zero() -> Self { | ||
Percentage(0.) | ||
} | ||
|
||
/// 100% | ||
#[inline] | ||
pub fn hundred() -> Self { | ||
Percentage(1.) | ||
} | ||
} | ||
|
||
/// https://drafts.csswg.org/css-transitions/#animtype-percentage | ||
impl Animatable for Percentage { | ||
#[inline] | ||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { | ||
Ok(Percentage((self.0 as f64 * self_portion + other.0 as f64 * other_portion) as f32)) | ||
} | ||
} | ||
|
||
impl ToAnimatedZero for Percentage { | ||
#[inline] | ||
fn to_animated_zero(&self) -> Result<Self, ()> { | ||
Ok(Percentage(0.)) | ||
} | ||
} | ||
|
||
impl ToCss for Percentage { | ||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result | ||
where | ||
W: fmt::Write, | ||
{ | ||
write!(dest, "{}%", self.0 * 100.) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.