Skip to content

Commit

Permalink
stylo: Move font-size stuff to values::*::font
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Sep 23, 2017
1 parent e1a39a2 commit df9d7cd
Show file tree
Hide file tree
Showing 8 changed files with 430 additions and 389 deletions.
7 changes: 4 additions & 3 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -2161,7 +2161,7 @@ fn static_assert() {
}

pub fn set_font_size(&mut self, v: longhands::font_size::computed_value::T) {
use self::longhands::font_size::KeywordSize;
use values::specified::font::KeywordSize;
self.gecko.mSize = v.size().0;
self.gecko.mScriptUnconstrainedSize = v.size().0;
if let Some(info) = v.info {
Expand Down Expand Up @@ -2370,7 +2370,8 @@ fn static_assert() {
}

pub fn clone_font_size(&self) -> longhands::font_size::computed_value::T {
use self::longhands::font_size::KeywordSize;
use values::computed::font::KeywordInfo;
use values::specified::font::KeywordSize;
let size = Au(self.gecko.mSize).into();
let kw = match self.gecko.mFontSizeKeyword as u32 {
structs::NS_STYLE_FONT_SIZE_XXSMALL => KeywordSize::XXSmall,
Expand All @@ -2391,7 +2392,7 @@ fn static_assert() {
};
longhands::font_size::computed_value::T {
size: size,
info: Some(longhands::font_size::computed_value::KeywordInfo {
info: Some(KeywordInfo {
kw: kw,
factor: self.gecko.mFontSizeFactor,
offset: Au(self.gecko.mFontSizeOffset).into()
Expand Down
383 changes: 7 additions & 376 deletions components/style/properties/longhand/font.mako.rs

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions components/style/values/computed/font.rs
@@ -0,0 +1,61 @@
/* 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 values for font properties

use app_units::Au;
use std::fmt;
use style_traits::ToCss;
use values::computed::NonNegativeLength;
use values::specified::font as specified;

#[derive(Copy, Clone, PartialEq, Debug)]
#[derive(ToAnimatedValue, Animate, ToAnimatedZero, ComputeSquaredDistance)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
/// The computed value of font-size
pub struct FontSize {
/// The size.
pub size: NonNegativeLength,
/// If derived from a keyword, the keyword and additional transformations applied to it
pub info: Option<KeywordInfo>,
}

#[derive(Copy, Clone, PartialEq, Debug)]
#[derive(ToAnimatedValue, Animate, ToAnimatedZero, ComputeSquaredDistance)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
/// Additional information for keyword-derived font sizes.
pub struct KeywordInfo {
/// The keyword used
pub kw: specified::KeywordSize,
/// A factor to be multiplied by the computed size of the keyword
pub factor: f32,
/// An additional Au offset to add to the kw*factor in the case of calcs
pub offset: NonNegativeLength,
}

impl KeywordInfo {
/// Given a parent keyword info (self), apply an additional factor/offset to it
pub fn compose(self, factor: f32, offset: NonNegativeLength) -> Self {
KeywordInfo {
kw: self.kw,
factor: self.factor * factor,
offset: self.offset.scale_by(factor) + offset,
}
}
}

impl FontSize {
/// The actual computed font size.
pub fn size(self) -> Au {
self.size.into()
}
}

impl ToCss for FontSize {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.size.to_css(dest)
}
}
1 change: 1 addition & 0 deletions components/style/values/computed/mod.rs
Expand Up @@ -67,6 +67,7 @@ pub mod box_;
pub mod color;
pub mod effects;
pub mod flex;
pub mod font;
pub mod image;
#[cfg(feature = "gecko")]
pub mod gecko;
Expand Down
3 changes: 0 additions & 3 deletions components/style/values/mod.rs
Expand Up @@ -29,9 +29,6 @@ pub type CSSFloat = f32;
/// A CSS integer value.
pub type CSSInteger = i32;

/// The default font size.
pub const FONT_MEDIUM_PX: i32 = 16;

define_keyword_type!(None_, "none");
define_keyword_type!(Auto, "auto");
define_keyword_type!(Normal, "normal");
Expand Down

0 comments on commit df9d7cd

Please sign in to comment.