mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
style: Cleanup a bit the calc code.
I happened to be looking at it. MozReview-Commit-ID: Ketot34XtOX
This commit is contained in:
parent
4f09987611
commit
49535d6987
2 changed files with 27 additions and 18 deletions
|
@ -92,15 +92,12 @@ impl CalcLengthOrPercentage {
|
||||||
|
|
||||||
/// Returns a new `CalcLengthOrPercentage` with a specific clamping mode.
|
/// Returns a new `CalcLengthOrPercentage` with a specific clamping mode.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_clamping_mode(length: Length,
|
pub fn with_clamping_mode(
|
||||||
|
length: Length,
|
||||||
percentage: Option<Percentage>,
|
percentage: Option<Percentage>,
|
||||||
clamping_mode: AllowedNumericType)
|
clamping_mode: AllowedNumericType,
|
||||||
-> Self {
|
) -> Self {
|
||||||
Self {
|
Self { clamping_mode, length, percentage, }
|
||||||
clamping_mode: clamping_mode,
|
|
||||||
length: length,
|
|
||||||
percentage: percentage,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns this `calc()` as a `<length>`.
|
/// Returns this `calc()` as a `<length>`.
|
||||||
|
@ -136,8 +133,9 @@ impl CalcLengthOrPercentage {
|
||||||
self.to_pixel_length(container_len).map(Au::from)
|
self.to_pixel_length(container_len).map(Au::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If there are special rules for computing percentages in a value (e.g. the height property),
|
/// If there are special rules for computing percentages in a value (e.g.
|
||||||
/// they apply whenever a calc() expression contains percentages.
|
/// the height property), they apply whenever a calc() expression contains
|
||||||
|
/// percentages.
|
||||||
pub fn to_pixel_length(&self, container_len: Option<Au>) -> Option<Length> {
|
pub fn to_pixel_length(&self, container_len: Option<Au>) -> Option<Length> {
|
||||||
match (container_len, self.percentage) {
|
match (container_len, self.percentage) {
|
||||||
(Some(len), Some(percent)) => {
|
(Some(len), Some(percent)) => {
|
||||||
|
@ -226,9 +224,15 @@ impl ToCss for CalcLengthOrPercentage {
|
||||||
|
|
||||||
impl specified::CalcLengthOrPercentage {
|
impl specified::CalcLengthOrPercentage {
|
||||||
/// Compute the value, zooming any absolute units by the zoom function.
|
/// Compute the value, zooming any absolute units by the zoom function.
|
||||||
fn to_computed_value_with_zoom<F>(&self, context: &Context, zoom_fn: F,
|
fn to_computed_value_with_zoom<F>(
|
||||||
base_size: FontBaseSize) -> CalcLengthOrPercentage
|
&self,
|
||||||
where F: Fn(Length) -> Length {
|
context: &Context,
|
||||||
|
zoom_fn: F,
|
||||||
|
base_size: FontBaseSize,
|
||||||
|
) -> CalcLengthOrPercentage
|
||||||
|
where
|
||||||
|
F: Fn(Length) -> Length,
|
||||||
|
{
|
||||||
use std::f32;
|
use std::f32;
|
||||||
let mut length = 0.;
|
let mut length = 0.;
|
||||||
|
|
||||||
|
@ -263,7 +267,11 @@ impl specified::CalcLengthOrPercentage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute font-size or line-height taking into account text-zoom if necessary.
|
/// Compute font-size or line-height taking into account text-zoom if necessary.
|
||||||
pub fn to_computed_value_zoomed(&self, context: &Context, base_size: FontBaseSize) -> CalcLengthOrPercentage {
|
pub fn to_computed_value_zoomed(
|
||||||
|
&self,
|
||||||
|
context: &Context,
|
||||||
|
base_size: FontBaseSize,
|
||||||
|
) -> CalcLengthOrPercentage {
|
||||||
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0, base_size)
|
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0, base_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,9 +64,10 @@ pub enum CalcUnit {
|
||||||
|
|
||||||
/// A struct to hold a simplified `<length>` or `<percentage>` expression.
|
/// A struct to hold a simplified `<length>` or `<percentage>` expression.
|
||||||
///
|
///
|
||||||
/// In some cases, e.g. DOMMatrix, we support calc(), but reject all the relative lengths, and
|
/// In some cases, e.g. DOMMatrix, we support calc(), but reject all the
|
||||||
/// to_computed_pixel_length_without_context() handles this case. Therefore, if you want to add a
|
/// relative lengths, and to_computed_pixel_length_without_context() handles
|
||||||
/// new field, please make sure this function work properly.
|
/// this case. Therefore, if you want to add a new field, please make sure this
|
||||||
|
/// function work properly.
|
||||||
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq)]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub struct CalcLengthOrPercentage {
|
pub struct CalcLengthOrPercentage {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue