Skip to content

Commit

Permalink
Support line-height in geckolib
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrubeck committed May 26, 2016
1 parent bf3c437 commit 1389fbe
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
20 changes: 20 additions & 0 deletions components/style/properties/longhand/inherited_text.mako.rs
Expand Up @@ -15,6 +15,9 @@
#[derive(Debug, Clone, PartialEq, Copy, HeapSizeOf)]
pub enum SpecifiedValue {
Normal,
% if product == "gecko":
MozBlockHeight,
% endif
Number(CSSFloat),
LengthOrPercentage(specified::LengthOrPercentage),
}
Expand All @@ -23,6 +26,9 @@
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::Normal => dest.write_str("normal"),
% if product == "gecko":
SpecifiedValue::MozBlockHeight => dest.write_str("-moz-block-height"),
% endif
SpecifiedValue::LengthOrPercentage(value) => value.to_css(dest),
SpecifiedValue::Number(number) => write!(dest, "{}", number),
}
Expand All @@ -42,6 +48,11 @@
Token::Ident(ref value) if value.eq_ignore_ascii_case("normal") => {
Ok(SpecifiedValue::Normal)
}
% if product == "gecko":
Token::Ident(ref value) if value.eq_ignore_ascii_case("-moz-block-height") => {
Ok(SpecifiedValue::MozBlockHeight)
}
% endif
_ => Err(()),
}
})
Expand All @@ -53,6 +64,9 @@
#[derive(PartialEq, Copy, Clone, HeapSizeOf, Debug)]
pub enum T {
Normal,
% if product == "gecko":
MozBlockHeight,
% endif
Length(Au),
Number(CSSFloat),
}
Expand All @@ -61,6 +75,9 @@
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
computed_value::T::Normal => dest.write_str("normal"),
% if product == "gecko":
computed_value::T::MozBlockHeight => dest.write_str("-moz-block-height"),
% endif
computed_value::T::Length(length) => length.to_css(dest),
computed_value::T::Number(number) => write!(dest, "{}", number),
}
Expand All @@ -76,6 +93,9 @@
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T {
match *self {
SpecifiedValue::Normal => computed_value::T::Normal,
% if product == "gecko":
SpecifiedValue::MozBlockHeight => computed_value::T::MozBlockHeight,
% endif
SpecifiedValue::Number(value) => computed_value::T::Number(value),
SpecifiedValue::LengthOrPercentage(value) => {
match value {
Expand Down
19 changes: 18 additions & 1 deletion ports/geckolib/properties.mako.rs
Expand Up @@ -719,12 +719,29 @@ fn static_assert() {
</%self:impl_trait>

<%self:impl_trait style_struct_name="InheritedText"
skip_longhands="text-align">
skip_longhands="text-align line-height">

<% text_align_keyword = Keyword("text-align", "start end left right center justify -moz-center -moz-left " +
"-moz-right match-parent") %>
<%call expr="impl_keyword('text_align', 'mTextAlign', text_align_keyword, need_clone=False)"></%call>

fn set_line_height(&mut self, v: longhands::line_height::computed_value::T) {
use style::properties::longhands::line_height::computed_value::T;
// FIXME: Align binary representations and ditch |match| for cast + static_asserts
match v {
T::Normal => self.gecko.mLineHeight.set_normal(),
T::Length(val) => self.gecko.mLineHeight.set_coord(val),
T::Number(val) => self.gecko.mLineHeight.set_factor(val),
T::MozBlockHeight =>
self.gecko.mLineHeight.set_enum(structs::NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT as i32),
}
}
fn copy_line_height_from(&mut self, other: &Self) {
debug_assert_unit_is_safe_to_copy(self.gecko.mLineHeight.mUnit);
self.gecko.mLineHeight.mUnit = other.gecko.mLineHeight.mUnit;
self.gecko.mLineHeight.mValue = other.gecko.mLineHeight.mValue;
}

</%self:impl_trait>

<%self:impl_trait style_struct_name="Text"
Expand Down
12 changes: 12 additions & 0 deletions ports/geckolib/values.rs
Expand Up @@ -11,10 +11,12 @@ use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, Leng
pub trait StyleCoordHelpers {
fn set<T: ToGeckoStyleCoord>(&mut self, val: T);
fn set_auto(&mut self);
fn set_normal(&mut self);
fn set_coord(&mut self, val: Au);
fn set_int(&mut self, val: i32);
fn set_enum(&mut self, val: i32);
fn set_percent(&mut self, val: f32);
fn set_factor(&mut self, val: f32);
}

impl StyleCoordHelpers for nsStyleCoord {
Expand All @@ -27,6 +29,11 @@ impl StyleCoordHelpers for nsStyleCoord {
unsafe { *self.mValue.mInt.as_mut() = 0; }
}

fn set_normal(&mut self) {
self.mUnit = nsStyleUnit::eStyleUnit_Normal;
unsafe { *self.mValue.mInt.as_mut() = 0; }
}

fn set_coord(&mut self, val: Au) {
self.mUnit = nsStyleUnit::eStyleUnit_Coord;
unsafe { *self.mValue.mInt.as_mut() = val.0; }
Expand All @@ -46,6 +53,11 @@ impl StyleCoordHelpers for nsStyleCoord {
self.mUnit = nsStyleUnit::eStyleUnit_Enumerated;
unsafe { *self.mValue.mInt.as_mut() = val; }
}

fn set_factor(&mut self, val: f32) {
self.mUnit = nsStyleUnit::eStyleUnit_Factor;
unsafe { *self.mValue.mFloat.as_mut() = val; }
}
}

pub trait ToGeckoStyleCoord {
Expand Down

0 comments on commit 1389fbe

Please sign in to comment.