Navigation Menu

Skip to content

Commit

Permalink
Auto-generate 'image-rendering' using 'single_keyword'
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Oct 26, 2016
1 parent 12f429e commit e7cbd10
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 80 deletions.
2 changes: 1 addition & 1 deletion components/gfx/paint_context.rs
Expand Up @@ -223,7 +223,7 @@ impl<'a> PaintContext<'a> {
// Something like Scale2x would be ideal.
let draw_surface_filter = match image_rendering {
image_rendering::T::auto => Filter::Linear,
image_rendering::T::crispedges | image_rendering::T::pixelated => Filter::Point,
image_rendering::T::crisp_edges | image_rendering::T::pixelated => Filter::Point,
};

let draw_surface_options = DrawSurfaceOptions::new(draw_surface_filter, true);
Expand Down
2 changes: 1 addition & 1 deletion components/layout/webrender_helpers.rs
Expand Up @@ -213,7 +213,7 @@ trait ToImageRendering {
impl ToImageRendering for image_rendering::T {
fn to_image_rendering(&self) -> webrender_traits::ImageRendering {
match *self {
image_rendering::T::crispedges => webrender_traits::ImageRendering::CrispEdges,
image_rendering::T::crisp_edges => webrender_traits::ImageRendering::CrispEdges,
image_rendering::T::auto => webrender_traits::ImageRendering::Auto,
image_rendering::T::pixelated => webrender_traits::ImageRendering::Pixelated,
}
Expand Down
11 changes: 0 additions & 11 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -1625,17 +1625,6 @@ fn static_assert() {
</%self:impl_trait>


<%self:impl_trait style_struct_name="InheritedBox"
skip_longhands="image-rendering">

<% render_keyword = Keyword("image-rendering",
"auto optimizequality optimizespeed crispedges") %>

${impl_keyword('image_rendering', 'mImageRendering', render_keyword, need_clone=False)}

</%self:impl_trait>


<%self:impl_trait style_struct_name="InheritedText"
skip_longhands="text-align text-emphasis-style text-shadow line-height letter-spacing word-spacing">

Expand Down
76 changes: 9 additions & 67 deletions components/style/properties/longhand/inherited_box.mako.rs
Expand Up @@ -40,73 +40,15 @@ ${helpers.single_keyword("color-adjust",
"economy exact", products="gecko",
animatable=False)}

<%helpers:longhand name="image-rendering" animatable="False">
pub mod computed_value {
use cssparser::ToCss;
use std::fmt;

#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub enum T {
auto,
crispedges,
% if product == "gecko":
optimizequality,
optimizespeed,
% else:
pixelated, // firefox doesn't support it (https://bugzilla.mozilla.org/show_bug.cgi?id=856337)
% endif
}

impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
T::auto => dest.write_str("auto"),
T::crispedges => dest.write_str("crisp-edges"),
% if product == "gecko":
T::optimizequality => dest.write_str("optimizeQuality"),
T::optimizespeed => dest.write_str("optimizeSpeed"),
% else:
T::pixelated => dest.write_str("pixelated"),
% endif
}
}
}
}

use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}

pub type SpecifiedValue = computed_value::T;

#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::auto
}

pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
// According to to CSS-IMAGES-3, `optimizespeed` and `optimizequality` are synonyms for
// `auto`.
match_ignore_ascii_case! {
try!(input.expect_ident()),
"auto" => Ok(computed_value::T::auto),
"crisp-edges" => Ok(computed_value::T::crispedges),
% if product == "gecko":
"optimizequality" => Ok(computed_value::T::optimizequality),
"optimizespeed" => Ok(computed_value::T::optimizespeed),
% else:
"optimizequality" => Ok(computed_value::T::auto),
"optimizespeed" => Ok(computed_value::T::auto),
"pixelated" => Ok(computed_value::T::pixelated),
% endif
_ => Err(())
}
}

use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue { }
</%helpers:longhand>
<% image_rendering_custom_consts = { "crisp-edges": "CRISPEDGES" } %>
// According to to CSS-IMAGES-3, `optimizespeed` and `optimizequality` are synonyms for `auto`
// And, firefox doesn't support `pixelated` yet (https://bugzilla.mozilla.org/show_bug.cgi?id=856337)
${helpers.single_keyword("image-rendering",
"auto crisp-edges",
extra_gecko_values="optimizespeed optimizequality",
extra_servo_values="pixelated",
custom_consts=image_rendering_custom_consts,
animatable=False)}

// Used in the bottom-up flow construction traversal to avoid constructing flows for
// descendants of nodes with `display: none`.
Expand Down

0 comments on commit e7cbd10

Please sign in to comment.