servo: Merge #13937 - Implements parser/serialization for font-synthesis (from iamrohit7:font-synthesis); r=emilio

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #13876 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 0193f987f6b8cdce02c297529f823e403da49b20
This commit is contained in:
Rohit Burra 2016-10-28 06:09:27 -05:00
parent 3ae4693949
commit ae75313198
2 changed files with 80 additions and 1 deletions

View File

@ -765,7 +765,7 @@ fn static_assert() {
</%self:impl_trait>
<%self:impl_trait style_struct_name="Font"
skip_longhands="font-family font-size font-weight"
skip_longhands="font-family font-size font-weight font-synthesis"
skip_additionals="*">
pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {
@ -828,6 +828,22 @@ fn static_assert() {
// This is used for PartialEq, which we don't implement for gecko style structs.
pub fn compute_font_hash(&mut self) {}
pub fn set_font_synthesis(&mut self, v: longhands::font_synthesis::computed_value::T) {
use gecko_bindings::structs::{NS_FONT_SYNTHESIS_WEIGHT, NS_FONT_SYNTHESIS_STYLE};
self.gecko.mFont.synthesis = 0;
if v.weight {
self.gecko.mFont.synthesis |= NS_FONT_SYNTHESIS_WEIGHT as u8;
}
if v.style {
self.gecko.mFont.synthesis |= NS_FONT_SYNTHESIS_STYLE as u8;
}
}
pub fn copy_font_synthesis_from(&mut self, other: &Self) {
self.gecko.mFont.synthesis = other.gecko.mFont.synthesis;
}
</%self:impl_trait>
<% skip_box_longhands= """display overflow-y vertical-align

View File

@ -344,6 +344,69 @@ ${helpers.single_keyword("font-variant",
}
</%helpers:longhand>
<%helpers:longhand products="gecko" name="font-synthesis" animatable="False">
use cssparser::ToCss;
use std::fmt;
use values::LocalToCss;
use values::computed::ComputedValueAsSpecified;
use values::NoViewportPercentage;
impl ComputedValueAsSpecified for SpecifiedValue {}
impl NoViewportPercentage for SpecifiedValue {}
pub mod computed_value {
pub use super::SpecifiedValue as T;
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue {
pub weight: bool,
pub style: bool,
}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.weight && self.style {
dest.write_str("weight style")
} else if self.style {
dest.write_str("style")
} else if self.weight {
dest.write_str("weight")
} else {
dest.write_str("none")
}
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
SpecifiedValue { weight: true, style: true }
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
let mut result = SpecifiedValue { weight: false, style: false };
match_ignore_ascii_case! {try!(input.expect_ident()),
"none" => Ok(result),
"weight" => {
result.weight = true;
if input.try(|input| input.expect_ident_matching("style")).is_ok() {
result.style = true;
}
Ok(result)
},
"style" => {
result.style = true;
if input.try(|input| input.expect_ident_matching("weight")).is_ok() {
result.weight = true;
}
Ok(result)
},
_ => Err(())
}
}
</%helpers:longhand>
// FIXME: This prop should be animatable
${helpers.single_keyword("font-stretch",
"normal ultra-condensed extra-condensed condensed \