Take an initial pass of putting binding-generated gecko style structs inside GeckoComputedValues.

This commit is contained in:
Bobby Holley 2016-03-28 21:30:54 -07:00
parent a7447aaf74
commit 0bdbf815f9
3 changed files with 79 additions and 19 deletions

View file

@ -73,11 +73,12 @@ class Shorthand(object):
self.internal = internal
class StyleStruct(object):
def __init__(self, name, inherited):
def __init__(self, name, inherited, gecko_name):
self.name = name
self.ident = to_rust_ident(name.lower())
self.longhands = []
self.inherited = inherited
self.gecko_name = gecko_name
STYLE_STRUCTS = []
THIS_STYLE_STRUCT = None
@ -86,10 +87,10 @@ LONGHANDS_BY_NAME = {}
DERIVED_LONGHANDS = {}
SHORTHANDS = []
def new_style_struct(name, is_inherited):
def new_style_struct(name, is_inherited, gecko_name=None):
global THIS_STYLE_STRUCT
style_struct = StyleStruct(name, is_inherited)
style_struct = StyleStruct(name, is_inherited, gecko_name)
STYLE_STRUCTS.append(style_struct)
THIS_STYLE_STRUCT = style_struct
return ""
@ -312,14 +313,14 @@ pub mod longhands {
// CSS 2.1, Section 8 - Box model
${new_style_struct("Margin", is_inherited=False)}
${new_style_struct("Margin", is_inherited=False, gecko_name="nsStyleMargin")}
% for side in ["top", "right", "bottom", "left"]:
${predefined_type("margin-" + side, "LengthOrPercentageOrAuto",
"computed::LengthOrPercentageOrAuto::Length(Au(0))")}
% endfor
${new_style_struct("Padding", is_inherited=False)}
${new_style_struct("Padding", is_inherited=False, gecko_name="nsStylePadding")}
% for side in ["top", "right", "bottom", "left"]:
${predefined_type("padding-" + side, "LengthOrPercentage",
@ -327,7 +328,7 @@ pub mod longhands {
"parse_non_negative")}
% endfor
${new_style_struct("Border", is_inherited=False)}
${new_style_struct("Border", is_inherited=False, gecko_name="nsStyleBorder")}
% for side in ["top", "right", "bottom", "left"]:
${predefined_type("border-%s-color" % side, "CSSColor", "::cssparser::Color::CurrentColor")}
@ -382,7 +383,7 @@ pub mod longhands {
"parse")}
% endfor
${new_style_struct("Outline", is_inherited=False)}
${new_style_struct("Outline", is_inherited=False, gecko_name="nsStyleOutline")}
// TODO(pcwalton): `invert`
${predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor")}
@ -435,7 +436,7 @@ pub mod longhands {
${predefined_type("outline-offset", "Length", "Au(0)")}
${new_style_struct("PositionOffsets", is_inherited=False)}
${new_style_struct("PositionOffsets", is_inherited=False, gecko_name="nsStylePosition")}
% for side in ["top", "right", "bottom", "left"]:
${predefined_type(side, "LengthOrPercentageOrAuto",
@ -444,7 +445,7 @@ pub mod longhands {
// CSS 2.1, Section 9 - Visual formatting model
${new_style_struct("Box", is_inherited=False)}
${new_style_struct("Box", is_inherited=False, gecko_name="nsStyleDisplay")}
// TODO(SimonSapin): don't parse `inline-table`, since we don't support it
<%self:longhand name="display" custom_cascade="True">
@ -1031,7 +1032,7 @@ pub mod longhands {
}
</%self:longhand>
${new_style_struct("List", is_inherited=True)}
${new_style_struct("List", is_inherited=True, gecko_name="nsStyleList")}
${single_keyword("list-style-position", "outside inside")}
@ -1263,7 +1264,7 @@ pub mod longhands {
// CSS 2.1, Section 14 - Colors and Backgrounds
${new_style_struct("Background", is_inherited=False)}
${new_style_struct("Background", is_inherited=False, gecko_name="nsStyleBackground")}
${predefined_type(
"background-color", "CSSColor",
"::cssparser::Color::RGBA(::cssparser::RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */")}
@ -1585,7 +1586,7 @@ pub mod longhands {
}
</%self:longhand>
${new_style_struct("Color", is_inherited=True)}
${new_style_struct("Color", is_inherited=True, gecko_name="nsStyleColor")}
<%self:raw_longhand name="color">
use cssparser::{Color, RGBA};
@ -1624,7 +1625,7 @@ pub mod longhands {
// CSS 2.1, Section 15 - Fonts
${new_style_struct("Font", is_inherited=True)}
${new_style_struct("Font", is_inherited=True, gecko_name="nsStyleFont")}
<%self:longhand name="font-family">
use self::computed_value::FontFamily;
@ -1928,7 +1929,7 @@ pub mod longhands {
// CSS 2.1, Section 16 - Text
${new_style_struct("InheritedText", is_inherited=True)}
${new_style_struct("InheritedText", is_inherited=True, gecko_name="nsStyleText")}
<%self:longhand name="text-align">
pub use self::computed_value::T as SpecifiedValue;
@ -2120,7 +2121,7 @@ pub mod longhands {
// TODO(pcwalton): Support `text-justify: distribute`.
${single_keyword("text-justify", "auto none inter-word")}
${new_style_struct("Text", is_inherited=False)}
${new_style_struct("Text", is_inherited=False, gecko_name="nsStyleTextReset")}
${single_keyword("unicode-bidi", "normal embed isolate bidi-override isolate-override plaintext")}
@ -2343,7 +2344,7 @@ pub mod longhands {
${single_keyword("text-rendering", "auto optimizespeed optimizelegibility geometricprecision")}
// CSS 2.1, Section 17 - Tables
${new_style_struct("Table", is_inherited=False)}
${new_style_struct("Table", is_inherited=False, gecko_name="nsStyleTable")}
${single_keyword("table-layout", "auto fixed")}
@ -2515,7 +2516,7 @@ pub mod longhands {
${single_keyword("pointer-events", "auto none")}
${new_style_struct("Column", is_inherited=False)}
${new_style_struct("Column", is_inherited=False, gecko_name="nsStyleColumn")}
<%self:longhand name="column-width" experimental="True">
use cssparser::ToCss;

View file

@ -35,6 +35,8 @@ extern crate util;
#[allow(dead_code, non_camel_case_types)]
mod bindings;
mod data;
#[allow(dead_code, non_camel_case_types, non_snake_case, non_upper_case_globals)]
mod gecko_style_structs;
#[allow(non_snake_case)]
pub mod glue;
mod selector_impl;

View file

@ -3,6 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use app_units::Au;
% for style_struct in STYLE_STRUCTS:
%if style_struct.gecko_name:
use gecko_style_structs::${style_struct.gecko_name};
% endif
% endfor
use heapsize::HeapSizeOf;
use std::fmt::{self, Debug};
use std::mem::zeroed;
use std::sync::Arc;
use style::custom_properties::ComputedValuesMap;
use style::logical_geometry::WritingMode;
@ -80,9 +88,58 @@ impl ComputedValues for GeckoComputedValues {
fn is_multicol(&self) -> bool { unimplemented!() }
}
% for style_struct in STYLE_STRUCTS:
#[derive(PartialEq, Clone, HeapSizeOf, Debug)]
<%def name="declare_style_struct(style_struct)">
#[derive(Clone, HeapSizeOf, Debug)]
% if style_struct.gecko_name:
pub struct Gecko${style_struct.name} {
gecko: ${style_struct.gecko_name},
}
% else:
pub struct Gecko${style_struct.name};
% endif
</%def>
<%def name="impl_style_struct(style_struct)">
impl Gecko${style_struct.name} {
#[allow(dead_code, unused_variables)]
fn initial() -> Self {
% if style_struct.gecko_name:
let result = Gecko${style_struct.name} { gecko: unsafe { zeroed() } };
panic!("Need to invoke Gecko placement new");
% else:
Gecko${style_struct.name}
% endif
}
}
%if style_struct.gecko_name:
impl Drop for Gecko${style_struct.name} {
fn drop(&mut self) {
panic!("Need to invoke Gecko destructor");
}
}
impl Clone for ${style_struct.gecko_name} {
fn clone(&self) -> Self {
panic!("Need to invoke Gecko copy constructor");
}
}
unsafe impl Send for ${style_struct.gecko_name} {}
unsafe impl Sync for ${style_struct.gecko_name} {}
impl HeapSizeOf for ${style_struct.gecko_name} {
// Not entirely accurate, but good enough for now.
fn heap_size_of_children(&self) -> usize { 0 }
}
impl Debug for ${style_struct.gecko_name} {
// FIXME(bholley): Generate this.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GECKO STYLE STRUCT")
}
}
%endif
</%def>
% for style_struct in STYLE_STRUCTS:
${declare_style_struct(style_struct)}
${impl_style_struct(style_struct)}
impl T${style_struct.name} for Gecko${style_struct.name} {
% for longhand in style_struct.longhands:
fn set_${longhand.ident}(&mut self, _: longhands::${longhand.ident}::computed_value::T) {