/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Computed types for box properties.
usecrate::values::animated::{Animate, Procedure, ToAnimatedValue}; usecrate::values::computed::font::FixedPoint; usecrate::values::computed::length::{LengthPercentage, NonNegativeLength}; usecrate::values::computed::{Context, Integer, Number, ToComputedValue}; usecrate::values::generics::box_::{
GenericContainIntrinsicSize, GenericLineClamp, GenericPerspective, GenericVerticalAlign,
}; usecrate::values::specified::box_ as specified; use std::fmt; use style_traits::{CssWriter, ToCss};
/// We use an unsigned 10.6 fixed-point value (range 0.0 - 1023.984375). pubconst ZOOM_FRACTION_BITS: u16 = 6;
/// This is an alias which is useful mostly as a cbindgen / C++ inference workaround. pubtype ZoomFixedPoint = FixedPoint<u16, ZOOM_FRACTION_BITS>;
/// The computed `zoom` property value. We store it as a 16-bit fixed point because we need to /// store it efficiently in the ComputedStyle representation. The assumption being that zooms over /// 1000 aren't quite useful. #[derive(
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Hash,
MallocSizeOf,
PartialEq,
PartialOrd,
ToResolvedValue,
)] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] #[repr(C)] pubstruct Zoom(ZoomFixedPoint);
impl ToComputedValue for specified::Zoom { type ComputedValue = Zoom;
#[inline] fn to_computed_value(&self, _: &Context) -> Self::ComputedValue { let n = match *self { Self::Normal => return Zoom::ONE, Self::Document => return Zoom::DOCUMENT, Self::Value(ref n) => n.0.to_number().get(),
}; if n == 0.0 { // For legacy reasons, zoom: 0 (and 0%) computes to 1. ¯\_(ツ)_/¯ return Zoom::ONE;
}
Zoom(ZoomFixedPoint::from_float(n))
}
impl Zoom { /// The value 1. This is by far the most common value. pubconst ONE: Zoom = Zoom(ZoomFixedPoint {
value: 1 << ZOOM_FRACTION_BITS,
});
/// The `document` value. This can appear in the computed zoom property value, but not in the /// `effective_zoom` field. pubconst DOCUMENT: Zoom = Zoom(ZoomFixedPoint { value: 0 });
/// Returns whether we're the number 1. #[inline] pubfn is_one(self) -> bool { self == Self::ONE
}
/// Returns the value as a float. #[inline] pubfn value(&self) -> f32 { self.0.to_float()
}
/// Computes the effective zoom for a given new zoom value in rhs. pubfn compute_effective(self, specified: Self) -> Self { if specified == Self::DOCUMENT { returnSelf::ONE;
} ifself == Self::ONE { return specified;
} if specified == Self::ONE { returnself;
}
Zoom(self.0 * specified.0)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.