Auto merge of #19964 - emilio:font-shorthand, r=nox

style: Don't serialize default values of the font shorthand.

This makes us consistent with the old style system and Blink / WebKit.

Not adding a test because shorthands serialization is a mess... :(

Anyway, nothing like fixing bugs by removing code.

Bug: 1436031

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19964)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-02-06 16:42:23 -05:00 committed by GitHub
commit dde15d8d65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 67 deletions

View file

@ -143,27 +143,14 @@
None
}
% endif
enum SerializeFor {
Normal,
% if product == "gecko":
Canvas,
% endif
}
impl<'a> LonghandsToSerialize<'a> {
fn to_css_for<W>(
&self,
serialize_for: SerializeFor,
dest: &mut CssWriter<W>,
) -> fmt::Result
where
W: Write,
{
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
% if product == "gecko":
match self.check_system() {
CheckSystemResult::AllSystem(sys) => return sys.to_css(dest),
CheckSystemResult::SomeSystem => return Ok(()),
CheckSystemResult::None => ()
CheckSystemResult::None => {}
}
% endif
@ -178,14 +165,7 @@
// In case of serialization for canvas font, we need to drop
// initial values of properties other than size and family.
% for name in "style variant_caps weight stretch".split():
let needs_this_property = match serialize_for {
SerializeFor::Normal => true,
% if product == "gecko":
SerializeFor::Canvas =>
self.font_${name} != &font_${name}::get_initial_specified_value(),
% endif
};
if needs_this_property {
if self.font_${name} != &font_${name}::get_initial_specified_value() {
self.font_${name}.to_css(dest)?;
dest.write_str(" ")?;
}
@ -203,7 +183,9 @@
Ok(())
}
}
impl<'a> LonghandsToSerialize<'a> {
% if product == "gecko":
/// Check if some or all members are system fonts
fn check_system(&self) -> CheckSystemResult {
@ -229,20 +211,8 @@
CheckSystemResult::None
}
}
/// Serialize the shorthand value for canvas font attribute.
pub fn to_css_for_canvas<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.to_css_for(SerializeFor::Canvas, dest)
}
% endif
}
// This may be a bit off, unsure, possibly needs changes
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.to_css_for(SerializeFor::Normal, dest)
}
}
</%helpers:shorthand>
<%helpers:shorthand name="font-variant"

View file

@ -2670,12 +2670,11 @@ pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
}
#[no_mangle]
pub extern "C" fn Servo_SerializeFontValueForCanvas(
pub unsafe extern "C" fn Servo_SerializeFontValueForCanvas(
declarations: RawServoDeclarationBlockBorrowed,
buffer: *mut nsAString,
) {
use style::properties::shorthands::font;
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
let longhands = match font::LonghandsToSerialize::from_iter(decls.declarations().iter()) {
Ok(l) => l,
@ -2685,12 +2684,8 @@ pub extern "C" fn Servo_SerializeFontValueForCanvas(
}
};
let mut string = String::new();
let rv = longhands.to_css_for_canvas(&mut CssWriter::new(&mut string));
let rv = longhands.to_css(&mut CssWriter::new(&mut *buffer));
debug_assert!(rv.is_ok());
let buffer = unsafe { buffer.as_mut().unwrap() };
buffer.assign_utf8(&string);
})
}