diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /servo/components/style/values/computed/length_percentage.rs | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'servo/components/style/values/computed/length_percentage.rs')
-rw-r--r-- | servo/components/style/values/computed/length_percentage.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/servo/components/style/values/computed/length_percentage.rs b/servo/components/style/values/computed/length_percentage.rs index 898281a7ef..0dbd2de76d 100644 --- a/servo/components/style/values/computed/length_percentage.rs +++ b/servo/components/style/values/computed/length_percentage.rs @@ -443,6 +443,19 @@ impl LengthPercentage { } } + /// Converts to a `<percentage>` with given basis. Returns None if the basis is 0. + #[inline] + pub fn to_percentage_of(&self, basis: Length) -> Option<Percentage> { + if basis.px() == 0. { + return None; + } + Some(match self.unpack() { + Unpacked::Length(l) => Percentage(l.px() / basis.px()), + Unpacked::Percentage(p) => p, + Unpacked::Calc(ref c) => Percentage(c.resolve(basis).px() / basis.px()), + }) + } + /// Returns the used value. #[inline] pub fn to_used_value(&self, containing_length: Au) -> Au { |