Auto merge of #11445 - mbrubeck:line-height, r=emilio

Support line-height in geckolib

r? @bholley

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11445)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-01 05:58:56 -05:00
commit 8caa17a466
4 changed files with 64 additions and 7 deletions

View file

@ -15,6 +15,9 @@
#[derive(Debug, Clone, PartialEq, Copy, HeapSizeOf)] #[derive(Debug, Clone, PartialEq, Copy, HeapSizeOf)]
pub enum SpecifiedValue { pub enum SpecifiedValue {
Normal, Normal,
% if product == "gecko":
MozBlockHeight,
% endif
Number(CSSFloat), Number(CSSFloat),
LengthOrPercentage(specified::LengthOrPercentage), LengthOrPercentage(specified::LengthOrPercentage),
} }
@ -23,6 +26,9 @@
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self { match *self {
SpecifiedValue::Normal => dest.write_str("normal"), 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::LengthOrPercentage(value) => value.to_css(dest),
SpecifiedValue::Number(number) => write!(dest, "{}", number), SpecifiedValue::Number(number) => write!(dest, "{}", number),
} }
@ -42,6 +48,11 @@
Token::Ident(ref value) if value.eq_ignore_ascii_case("normal") => { Token::Ident(ref value) if value.eq_ignore_ascii_case("normal") => {
Ok(SpecifiedValue::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(()), _ => Err(()),
} }
}) })
@ -53,6 +64,9 @@
#[derive(PartialEq, Copy, Clone, HeapSizeOf, Debug)] #[derive(PartialEq, Copy, Clone, HeapSizeOf, Debug)]
pub enum T { pub enum T {
Normal, Normal,
% if product == "gecko":
MozBlockHeight,
% endif
Length(Au), Length(Au),
Number(CSSFloat), Number(CSSFloat),
} }
@ -61,6 +75,9 @@
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self { match *self {
computed_value::T::Normal => dest.write_str("normal"), 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::Length(length) => length.to_css(dest),
computed_value::T::Number(number) => write!(dest, "{}", number), computed_value::T::Number(number) => write!(dest, "{}", number),
} }
@ -76,6 +93,9 @@
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T {
match *self { match *self {
SpecifiedValue::Normal => computed_value::T::Normal, 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::Number(value) => computed_value::T::Number(value),
SpecifiedValue::LengthOrPercentage(value) => { SpecifiedValue::LengthOrPercentage(value) => {
match value { match value {

View file

@ -20,7 +20,6 @@ use gecko_bindings::bindings::{Gecko_CopyMozBindingFrom, Gecko_CopyListStyleType
use gecko_bindings::bindings::{Gecko_SetMozBinding, Gecko_SetListStyleType}; use gecko_bindings::bindings::{Gecko_SetMozBinding, Gecko_SetListStyleType};
use gecko_bindings::structs; use gecko_bindings::structs;
use glue::ArcHelpers; use glue::ArcHelpers;
use heapsize::HeapSizeOf;
use std::fmt::{self, Debug}; use std::fmt::{self, Debug};
use std::mem::{transmute, zeroed}; use std::mem::{transmute, zeroed};
use std::sync::Arc; use std::sync::Arc;
@ -149,6 +148,12 @@ pub struct ${style_struct.gecko_struct_name} {
} }
</%def> </%def>
<%def name="impl_coord_copy(ident, gecko_ffi_name)">
fn copy_${ident}_from(&mut self, other: &Self) {
self.gecko.${gecko_ffi_name}.copy_from(&other.gecko.${gecko_ffi_name});
}
</%def>
<%! <%!
def is_border_style_masked(ffi_name): def is_border_style_masked(ffi_name):
return ffi_name.split("[")[0] in ["mBorderStyle", "mOutlineStyle", "mTextDecorationStyle"] return ffi_name.split("[")[0] in ["mBorderStyle", "mOutlineStyle", "mTextDecorationStyle"]
@ -673,11 +678,8 @@ fn static_assert() {
T::LengthOrPercentage(v) => self.gecko.mVerticalAlign.set(v), T::LengthOrPercentage(v) => self.gecko.mVerticalAlign.set(v),
} }
} }
fn copy_vertical_align_from(&mut self, other: &Self) {
debug_assert_unit_is_safe_to_copy(self.gecko.mVerticalAlign.mUnit); <%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"></%call>
self.gecko.mVerticalAlign.mUnit = other.gecko.mVerticalAlign.mUnit;
self.gecko.mVerticalAlign.mValue = other.gecko.mVerticalAlign.mValue;
}
fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) { fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) {
use style::properties::longhands::_moz_binding::SpecifiedValue as BindingValue; use style::properties::longhands::_moz_binding::SpecifiedValue as BindingValue;
@ -719,12 +721,26 @@ fn static_assert() {
</%self:impl_trait> </%self:impl_trait>
<%self:impl_trait style_struct_name="InheritedText" <%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 " + <% text_align_keyword = Keyword("text-align", "start end left right center justify -moz-center -moz-left " +
"-moz-right match-parent") %> "-moz-right match-parent") %>
<%call expr="impl_keyword('text_align', 'mTextAlign', text_align_keyword, need_clone=False)"></%call> <%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),
}
}
<%call expr="impl_coord_copy('line_height', 'mLineHeight')"></%call>
</%self:impl_trait> </%self:impl_trait>
<%self:impl_trait style_struct_name="Text" <%self:impl_trait style_struct_name="Text"

View file

@ -9,15 +9,25 @@ use std::cmp::max;
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
pub trait StyleCoordHelpers { pub trait StyleCoordHelpers {
fn copy_from(&mut self, other: &Self);
fn set<T: ToGeckoStyleCoord>(&mut self, val: T); fn set<T: ToGeckoStyleCoord>(&mut self, val: T);
fn set_auto(&mut self); fn set_auto(&mut self);
fn set_normal(&mut self);
fn set_coord(&mut self, val: Au); fn set_coord(&mut self, val: Au);
fn set_int(&mut self, val: i32); fn set_int(&mut self, val: i32);
fn set_enum(&mut self, val: i32); fn set_enum(&mut self, val: i32);
fn set_percent(&mut self, val: f32); fn set_percent(&mut self, val: f32);
fn set_factor(&mut self, val: f32);
} }
impl StyleCoordHelpers for nsStyleCoord { impl StyleCoordHelpers for nsStyleCoord {
fn copy_from(&mut self, other: &Self) {
debug_assert_unit_is_safe_to_copy(self.mUnit);
debug_assert_unit_is_safe_to_copy(other.mUnit);
self.mUnit = other.mUnit;
self.mValue = other.mValue;
}
fn set<T: ToGeckoStyleCoord>(&mut self, val: T) { fn set<T: ToGeckoStyleCoord>(&mut self, val: T) {
val.to_gecko_style_coord(&mut self.mUnit, &mut self.mValue); val.to_gecko_style_coord(&mut self.mUnit, &mut self.mValue);
} }
@ -27,6 +37,11 @@ impl StyleCoordHelpers for nsStyleCoord {
unsafe { *self.mValue.mInt.as_mut() = 0; } 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) { fn set_coord(&mut self, val: Au) {
self.mUnit = nsStyleUnit::eStyleUnit_Coord; self.mUnit = nsStyleUnit::eStyleUnit_Coord;
unsafe { *self.mValue.mInt.as_mut() = val.0; } unsafe { *self.mValue.mInt.as_mut() = val.0; }
@ -46,6 +61,11 @@ impl StyleCoordHelpers for nsStyleCoord {
self.mUnit = nsStyleUnit::eStyleUnit_Enumerated; self.mUnit = nsStyleUnit::eStyleUnit_Enumerated;
unsafe { *self.mValue.mInt.as_mut() = val; } 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 { pub trait ToGeckoStyleCoord {

View file

@ -41,6 +41,7 @@ use style::dom::{TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
use style::element_state::ElementState; use style::element_state::ElementState;
#[allow(unused_imports)] // Used in commented-out code. #[allow(unused_imports)] // Used in commented-out code.
use style::error_reporting::StdoutErrorReporter; use style::error_reporting::StdoutErrorReporter;
#[allow(unused_imports)] // Used in commented-out code.
use style::parser::ParserContextExtraData; use style::parser::ParserContextExtraData;
#[allow(unused_imports)] // Used in commented-out code. #[allow(unused_imports)] // Used in commented-out code.
use style::properties::parse_style_attribute; use style::properties::parse_style_attribute;