Add a skeleton implementation of TComputedValues in geckolib.

This commit is contained in:
Bobby Holley 2016-03-16 13:02:22 -07:00
parent c2daea2c9c
commit 3c44dbae21
7 changed files with 260 additions and 16 deletions

View file

@ -50,7 +50,7 @@ pub mod animation;
pub mod attr;
pub mod bezier;
pub mod context;
mod custom_properties;
pub mod custom_properties;
pub mod data;
pub mod dom;
pub mod element_state;

View file

@ -3,6 +3,8 @@ name = "geckoservo"
version = "0.0.1"
authors = ["The Servo Project Developers"]
build = "build.rs"
[lib]
name = "geckoservo"
path = "lib.rs"

80
ports/geckolib/build.rs Normal file
View file

@ -0,0 +1,80 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::process::{Command, Stdio, exit};
#[cfg(windows)]
fn find_python() -> String {
if Command::new("python27.exe").arg("--version").output().is_ok() {
return "python27.exe".to_owned();
}
if Command::new("python.exe").arg("--version").output().is_ok() {
return "python.exe".to_owned();
}
panic!("Can't find python (tried python27.exe and python.exe)! Try fixing PATH or setting the PYTHON env var");
}
#[cfg(not(windows))]
fn find_python() -> String {
if Command::new("python2.7").arg("--version").output().unwrap().status.success() {
"python2.7"
} else {
"python"
}.to_owned()
}
fn main() {
let python = match env::var("PYTHON") {
Ok(python_path) => python_path,
Err(_) => find_python(),
};
// Mako refuses to load templates outside the scope of the current working directory,
// so we need to run it from the top source directory.
let geckolib_dir = Path::new(file!()).parent().unwrap();
let top_dir = geckolib_dir.join("..").join("..");
let style_template = Path::new("components/style/properties.mako.rs");
let geckolib_template = Path::new("ports/geckolib/properties.mako.rs");
let mako = Path::new("components/style/Mako-0.9.1.zip");
let result = Command::new(python)
.current_dir(top_dir)
.env("PYTHONPATH", &mako)
.env("STYLE_TEMPLATE", &style_template)
.env("GECKOLIB_TEMPLATE", &geckolib_template)
.arg("-c")
.arg(r#"
import json
import os
import sys
from mako.template import Template
from mako import exceptions
try:
style_template = Template(filename=os.environ['STYLE_TEMPLATE'], input_encoding='utf8')
style_template.render()
geckolib_template = Template(filename=os.environ['GECKOLIB_TEMPLATE'], input_encoding='utf8')
output = geckolib_template.render(STYLE_STRUCTS = style_template.module.STYLE_STRUCTS,
LONGHANDS = style_template.module.LONGHANDS)
print(output.encode('utf8'))
except:
sys.stderr.write(exceptions.text_error_template().render().encode('utf8'))
sys.exit(1)
"#)
.stderr(Stdio::inherit())
.output()
.unwrap();
if !result.status.success() {
exit(1)
}
let out = env::var("OUT_DIR").unwrap();
File::create(&Path::new(&out).join("properties.rs")).unwrap().write_all(&result.stdout).unwrap();
}

View file

@ -37,7 +37,13 @@ mod bindings;
mod data;
#[allow(non_snake_case)]
pub mod glue;
mod properties;
mod selector_impl;
mod traversal;
mod wrapper;
// Generated from the properties.mako.rs template by build.rs
#[macro_use]
#[allow(unsafe_code)]
pub mod properties {
include!(concat!(env!("OUT_DIR"), "/properties.rs"));
}

View file

@ -0,0 +1,168 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use app_units::Au;
use std::sync::Arc;
use style::custom_properties::ComputedValuesMap;
use style::logical_geometry::WritingMode;
use style::properties::{CascadePropertyFn, ComputedValues, TComputedValues};
use style::properties::longhands;
use style::properties::style_struct_traits::*;
#[derive(Clone)]
pub struct GeckoComputedValues {
% for style_struct in STYLE_STRUCTS:
${style_struct.ident}: Arc<Gecko${style_struct.name}>,
% endfor
custom_properties: Option<Arc<ComputedValuesMap>>,
shareable: bool,
pub writing_mode: WritingMode,
pub root_font_size: Au,
}
impl TComputedValues for GeckoComputedValues {
% for style_struct in STYLE_STRUCTS:
type Concrete${style_struct.name} = Gecko${style_struct.name};
% endfor
// These will go away, and we will never implement them.
fn as_servo<'a>(&'a self) -> &'a ComputedValues { unimplemented!() }
fn as_servo_mut<'a>(&'a mut self) -> &'a mut ComputedValues { unimplemented!() }
fn new(custom_properties: Option<Arc<ComputedValuesMap>>,
shareable: bool,
writing_mode: WritingMode,
root_font_size: Au,
% for style_struct in STYLE_STRUCTS:
${style_struct.ident}: Arc<Gecko${style_struct.name}>,
% endfor
) -> Self {
GeckoComputedValues {
custom_properties: custom_properties,
shareable: shareable,
writing_mode: writing_mode,
root_font_size: root_font_size,
% for style_struct in STYLE_STRUCTS:
${style_struct.ident}: ${style_struct.ident},
% endfor
}
}
fn initial_values() -> &'static Self { unimplemented!() }
fn do_cascade_property<F: FnOnce(&Vec<Option<CascadePropertyFn<Self>>>)>(_: F) {
unimplemented!()
}
% for style_struct in STYLE_STRUCTS:
#[inline]
fn clone_${style_struct.name.lower()}(&self) -> Arc<Self::Concrete${style_struct.name}> {
self.${style_struct.ident}.clone()
}
#[inline]
fn get_${style_struct.name.lower()}<'a>(&'a self) -> &'a Self::Concrete${style_struct.name} {
&self.${style_struct.ident}
}
#[inline]
fn mutate_${style_struct.name.lower()}<'a>(&'a mut self) -> &'a mut Self::Concrete${style_struct.name} {
Arc::make_mut(&mut self.${style_struct.ident})
}
% endfor
fn custom_properties(&self) -> Option<Arc<ComputedValuesMap>> { self.custom_properties.as_ref().map(|x| x.clone())}
fn root_font_size(&self) -> Au { self.root_font_size }
fn set_root_font_size(&mut self, s: Au) { self.root_font_size = s; }
fn set_writing_mode(&mut self, mode: WritingMode) { self.writing_mode = mode; }
#[inline]
fn is_multicol(&self) -> bool { unimplemented!() }
}
% for style_struct in STYLE_STRUCTS:
#[derive(PartialEq, Clone, HeapSizeOf, Debug)]
pub struct Gecko${style_struct.name};
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) {
unimplemented!()
}
fn copy_${longhand.ident}_from(&mut self, _: &Self) {
unimplemented!()
}
% endfor
% if style_struct.name == "Animation":
fn transition_count(&self) -> usize {
unimplemented!()
}
% elif style_struct.name == "Border":
% for side in ["top", "right", "bottom", "left"]:
fn border_${side}_is_none_or_hidden_and_has_nonzero_width(&self) -> bool {
unimplemented!()
}
% endfor
% elif style_struct.name == "Box":
fn clone_display(&self) -> longhands::display::computed_value::T {
unimplemented!()
}
fn clone_position(&self) -> longhands::position::computed_value::T {
unimplemented!()
}
fn is_floated(&self) -> bool {
unimplemented!()
}
fn overflow_x_is_visible(&self) -> bool {
unimplemented!()
}
fn overflow_y_is_visible(&self) -> bool {
unimplemented!()
}
% elif style_struct.name == "Color":
fn clone_color(&self) -> longhands::color::computed_value::T {
unimplemented!()
}
% elif style_struct.name == "Font":
fn clone_font_size(&self) -> longhands::font_size::computed_value::T {
unimplemented!()
}
fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T {
unimplemented!()
}
fn compute_font_hash(&mut self) {
unimplemented!()
}
% elif style_struct.name == "InheritedBox":
fn clone_direction(&self) -> longhands::direction::computed_value::T {
unimplemented!()
}
fn clone_writing_mode(&self) -> longhands::writing_mode::computed_value::T {
unimplemented!()
}
fn clone_text_orientation(&self) -> longhands::text_orientation::computed_value::T {
unimplemented!()
}
% elif style_struct.name == "InheritedText":
fn clone__servo_text_decorations_in_effect(&self) ->
longhands::_servo_text_decorations_in_effect::computed_value::T {
unimplemented!()
}
% elif style_struct.name == "Outline":
fn outline_is_none_or_hidden_and_has_nonzero_width(&self) -> bool {
unimplemented!()
}
% elif style_struct.name == "Text":
fn has_underline(&self) -> bool {
unimplemented!()
}
fn has_overline(&self) -> bool {
unimplemented!()
}
fn has_line_through(&self) -> bool {
unimplemented!()
}
% endif
}
% endfor

View file

@ -1,8 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use style::properties::ComputedValues;
// FIXME(bholley): Create and use an actual Gecko type here.
pub type GeckoComputedValues = ComputedValues;

View file

@ -2,20 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use properties::GeckoComputedValues;
use selectors::parser::{ParserContext, SelectorImpl};
use std::process;
use style;
use style::element_state::ElementState;
use style::error_reporting::StdoutErrorReporter;
use style::properties::ComputedValues;
use style::selector_impl::SelectorImplExt;
use style::stylesheets::Origin;
use url::Url;
pub type Stylist = style::selector_matching::Stylist<GeckoSelectorImpl>;
pub type Stylesheet = style::stylesheets::Stylesheet<GeckoSelectorImpl>;
pub type SharedStyleContext = style::context::SharedStyleContext<GeckoSelectorImpl>;
pub type PrivateStyleData = style::data::PrivateStyleData<GeckoSelectorImpl, ComputedValues>;
pub type PrivateStyleData = style::data::PrivateStyleData<GeckoSelectorImpl, GeckoComputedValues>;
pub struct GeckoSelectorImpl;