aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBobby Holley <bobbyholley@gmail.com>2016-03-16 13:02:22 -0700
committerBobby Holley <bobbyholley@gmail.com>2016-03-24 11:50:58 -0700
commit3c44dbae21ea7d944772d6eaacb2cbee0f7536f8 (patch)
treed774d3159d97ff851ac0af0eaae1a9ca1d78df6f
parentc2daea2c9c490b4cd36dfa4a8da094cdd3ff4712 (diff)
downloadservo-3c44dbae21ea7d944772d6eaacb2cbee0f7536f8.tar.gz
servo-3c44dbae21ea7d944772d6eaacb2cbee0f7536f8.zip
Add a skeleton implementation of TComputedValues in geckolib.
-rw-r--r--components/style/lib.rs2
-rw-r--r--ports/geckolib/Cargo.toml2
-rw-r--r--ports/geckolib/build.rs80
-rw-r--r--ports/geckolib/lib.rs8
-rw-r--r--ports/geckolib/properties.mako.rs168
-rw-r--r--ports/geckolib/properties.rs8
-rw-r--r--ports/geckolib/selector_impl.rs8
7 files changed, 260 insertions, 16 deletions
diff --git a/components/style/lib.rs b/components/style/lib.rs
index a696b882d43..951a32cd3ce 100644
--- a/components/style/lib.rs
+++ b/components/style/lib.rs
@@ -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;
diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml
index c8d5dcabcea..cd9031ee98e 100644
--- a/ports/geckolib/Cargo.toml
+++ b/ports/geckolib/Cargo.toml
@@ -3,6 +3,8 @@ name = "geckoservo"
version = "0.0.1"
authors = ["The Servo Project Developers"]
+build = "build.rs"
+
[lib]
name = "geckoservo"
path = "lib.rs"
diff --git a/ports/geckolib/build.rs b/ports/geckolib/build.rs
new file mode 100644
index 00000000000..0cb930b072b
--- /dev/null
+++ b/ports/geckolib/build.rs
@@ -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();
+}
diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs
index 70f265526d9..e28bf611a5c 100644
--- a/ports/geckolib/lib.rs
+++ b/ports/geckolib/lib.rs
@@ -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"));
+}
diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs
new file mode 100644
index 00000000000..4d2010dcecd
--- /dev/null
+++ b/ports/geckolib/properties.mako.rs
@@ -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
diff --git a/ports/geckolib/properties.rs b/ports/geckolib/properties.rs
deleted file mode 100644
index 176c2927e14..00000000000
--- a/ports/geckolib/properties.rs
+++ /dev/null
@@ -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;
diff --git a/ports/geckolib/selector_impl.rs b/ports/geckolib/selector_impl.rs
index 0b3b883e4ef..0bd84ab9782 100644
--- a/ports/geckolib/selector_impl.rs
+++ b/ports/geckolib/selector_impl.rs
@@ -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;