mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Introduce CSSPixelLength and update NonNegativeLength.
First, we define computed::CSSPixelLength which contains a CSSFloat, a pixel value, and then we replace computed::Length with CSSPixelLength. Therefore, the |ComputedValue| of NoCalcLength, AbsoluteLength, FontRelativeLength, ViewportPercentageLength, CharacterWidth, and PhysicalLength is CSSPixelLength. Besides, we drop NonNegativeAu, and replace computed::NonNegativeLength with NonNegative<computed::Length>. (i.e. NonNegative<CSSPixelLength>)
This commit is contained in:
parent
cad3aff508
commit
a949e2a057
40 changed files with 502 additions and 406 deletions
|
@ -14,7 +14,7 @@ use properties;
|
|||
use properties::{ComputedValues, StyleBuilder};
|
||||
#[cfg(feature = "servo")]
|
||||
use servo_url::ServoUrl;
|
||||
use std::{f32, fmt, ops};
|
||||
use std::{f32, fmt};
|
||||
#[cfg(feature = "servo")]
|
||||
use std::sync::Arc;
|
||||
use style_traits::ToCss;
|
||||
|
@ -46,7 +46,7 @@ pub use super::{Auto, Either, None_};
|
|||
pub use super::specified::BorderStyle;
|
||||
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage};
|
||||
pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
|
||||
pub use self::length::NonNegativeLengthOrPercentage;
|
||||
pub use self::length::{CSSPixelLength, NonNegativeLength, NonNegativeLengthOrPercentage};
|
||||
pub use self::percentage::Percentage;
|
||||
pub use self::position::Position;
|
||||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth};
|
||||
|
@ -146,12 +146,12 @@ impl<'a> Context<'a> {
|
|||
|
||||
/// Apply text-zoom if enabled.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn maybe_zoom_text(&self, size: NonNegativeAu) -> NonNegativeAu {
|
||||
pub fn maybe_zoom_text(&self, size: CSSPixelLength) -> CSSPixelLength {
|
||||
// We disable zoom for <svg:text> by unsetting the
|
||||
// -x-text-zoom property, which leads to a false value
|
||||
// in mAllowZoom
|
||||
if self.style().get_font().gecko.mAllowZoom {
|
||||
self.device().zoom_text(size.0).into()
|
||||
self.device().zoom_text(Au::from(size)).into()
|
||||
} else {
|
||||
size
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ impl<'a> Context<'a> {
|
|||
|
||||
/// (Servo doesn't do text-zoom)
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn maybe_zoom_text(&self, size: NonNegativeAu) -> NonNegativeAu {
|
||||
pub fn maybe_zoom_text(&self, size: CSSPixelLength) -> CSSPixelLength {
|
||||
size
|
||||
}
|
||||
}
|
||||
|
@ -450,13 +450,13 @@ pub type NonNegativeLengthOrPercentageOrNumber = Either<NonNegativeNumber, NonNe
|
|||
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, PartialEq)]
|
||||
/// A computed cliprect for clip and image-region
|
||||
pub struct ClipRect {
|
||||
pub top: Option<Au>,
|
||||
pub right: Option<Au>,
|
||||
pub bottom: Option<Au>,
|
||||
pub left: Option<Au>,
|
||||
pub top: Option<Length>,
|
||||
pub right: Option<Length>,
|
||||
pub bottom: Option<Length>,
|
||||
pub left: Option<Length>,
|
||||
}
|
||||
|
||||
impl ToCss for ClipRect {
|
||||
|
@ -529,50 +529,6 @@ impl ClipRectOrAuto {
|
|||
/// <color> | auto
|
||||
pub type ColorOrAuto = Either<Color, Auto>;
|
||||
|
||||
/// A wrapper of Au, but the value >= 0.
|
||||
pub type NonNegativeAu = NonNegative<Au>;
|
||||
|
||||
impl NonNegativeAu {
|
||||
/// Return a zero value.
|
||||
#[inline]
|
||||
pub fn zero() -> Self {
|
||||
NonNegative::<Au>(Au(0))
|
||||
}
|
||||
|
||||
/// Return a NonNegativeAu from pixel.
|
||||
#[inline]
|
||||
pub fn from_px(px: i32) -> Self {
|
||||
NonNegative::<Au>(Au::from_px(::std::cmp::max(px, 0)))
|
||||
}
|
||||
|
||||
/// Get the inner value of |NonNegativeAu.0|.
|
||||
#[inline]
|
||||
pub fn value(self) -> i32 {
|
||||
(self.0).0
|
||||
}
|
||||
|
||||
/// Scale this NonNegativeAu.
|
||||
#[inline]
|
||||
pub fn scale_by(self, factor: f32) -> Self {
|
||||
// scale this by zero if factor is negative.
|
||||
NonNegative::<Au>(self.0.scale_by(factor.max(0.)))
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Add<NonNegativeAu> for NonNegativeAu {
|
||||
type Output = NonNegativeAu;
|
||||
fn add(self, other: Self) -> Self {
|
||||
(self.0 + other.0).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Au> for NonNegativeAu {
|
||||
#[inline]
|
||||
fn from(au: Au) -> NonNegativeAu {
|
||||
NonNegative::<Au>(au)
|
||||
}
|
||||
}
|
||||
|
||||
/// The computed value of a CSS `url()`, resolved relative to the stylesheet URL.
|
||||
#[cfg(feature = "servo")]
|
||||
#[derive(Clone, Debug, Deserialize, HeapSizeOf, PartialEq, Serialize)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue