diff --git a/components/style/gecko_glue.rs b/components/style/gecko_glue.rs new file mode 100644 index 00000000000..fadae2f57bc --- /dev/null +++ b/components/style/gecko_glue.rs @@ -0,0 +1,57 @@ +/* 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/. */ + +#![allow(unsafe_code)] + +use std::marker::PhantomData; +use std::mem::{forget, transmute}; +use std::sync::Arc; + +pub struct ArcHelpers { + phantom1: PhantomData, + phantom2: PhantomData, +} + + +impl ArcHelpers { + pub fn with(raw: *mut GeckoType, cb: F) -> Output + where F: FnOnce(&Arc) -> Output { + debug_assert!(!raw.is_null()); + + let owned = unsafe { Self::into(raw) }; + let result = cb(&owned); + forget(owned); + result + } + + pub fn maybe_with(maybe_raw: *mut GeckoType, cb: F) -> Output + where F: FnOnce(Option<&Arc>) -> Output { + let owned = if maybe_raw.is_null() { + None + } else { + Some(unsafe { Self::into(maybe_raw) }) + }; + + let result = cb(owned.as_ref()); + forget(owned); + + result + } + + pub unsafe fn into(ptr: *mut GeckoType) -> Arc { + transmute(ptr) + } + + pub fn from(owned: Arc) -> *mut GeckoType { + unsafe { transmute(owned) } + } + + pub unsafe fn addref(ptr: *mut GeckoType) { + Self::with(ptr, |arc| forget(arc.clone())); + } + + pub unsafe fn release(ptr: *mut GeckoType) { + let _ = Self::into(ptr); + } +} diff --git a/components/style/lib.rs b/components/style/lib.rs index cf1ba6d8c7e..4fa0fe1eeb6 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -83,6 +83,7 @@ pub mod error_reporting; pub mod font_face; #[cfg(feature = "gecko")] pub mod gecko_conversions; #[cfg(feature = "gecko")] pub mod gecko_values; +#[cfg(feature = "gecko")] pub mod gecko_glue; pub mod keyframes; pub mod logical_geometry; pub mod matching; @@ -116,6 +117,12 @@ pub mod properties { include!(concat!(env!("OUT_DIR"), "/properties.rs")); } +#[cfg(feature = "gecko")] +#[allow(unsafe_code)] +pub mod gecko_properties { + include!(concat!(env!("OUT_DIR"), "/gecko_properties.rs")); +} + macro_rules! reexport_computed_values { ( $( $name: ident )+ ) => { /// Types for [computed values][computed]. diff --git a/components/style/properties/build.py b/components/style/properties/build.py index eeb78817f3f..daa9140fd02 100644 --- a/components/style/properties/build.py +++ b/components/style/properties/build.py @@ -18,7 +18,7 @@ import data def main(): - usage = "Usage: %s [ servo | gecko ] [ style-crate | geckolib | html ]" % sys.argv[0] + usage = "Usage: %s [ servo | gecko ] [ style-crate | html ]" % sys.argv[0] if len(sys.argv) < 3: abort(usage) product = sys.argv[1] @@ -30,10 +30,10 @@ def main(): rust = render(os.path.join(BASE, "properties.mako.rs"), product=product, data=properties) if output == "style-crate": write(os.environ["OUT_DIR"], "properties.rs", rust) - if output == "geckolib": - template = os.path.join(BASE, "..", "..", "..", "ports", "geckolib", "properties.mako.rs") - rust = render(template, data=properties) - write(os.environ["OUT_DIR"], "properties.rs", rust) + if product == "gecko": + template = os.path.join(BASE, "gecko.mako.rs") + rust = render(template, data=properties) + write(os.environ["OUT_DIR"], "gecko_properties.rs", rust) elif output == "html": write_html(properties) diff --git a/ports/geckolib/properties.mako.rs b/components/style/properties/gecko.mako.rs similarity index 95% rename from ports/geckolib/properties.mako.rs rename to components/style/properties/gecko.mako.rs index e2332cce1f8..e77ef1dfa6e 100644 --- a/ports/geckolib/properties.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -10,6 +10,7 @@ %> use app_units::Au; +use custom_properties::ComputedValuesMap; % for style_struct in data.style_structs: use gecko_bindings::structs::${style_struct.gecko_ffi_name}; use gecko_bindings::bindings::Gecko_Construct_${style_struct.gecko_ffi_name}; @@ -24,19 +25,18 @@ use gecko_bindings::bindings::{Gecko_CopyImageValueFrom, Gecko_CopyFontFamilyFro use gecko_bindings::bindings::{Gecko_FontFamilyList_AppendGeneric, Gecko_FontFamilyList_AppendNamed}; use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear, Gecko_InitializeImageLayer}; use gecko_bindings::structs; -use glue::ArcHelpers; +use gecko_glue::ArcHelpers; +use gecko_values::{StyleCoordHelpers, GeckoStyleCoordConvertible, convert_nscolor_to_rgba}; +use gecko_values::convert_rgba_to_nscolor; +use gecko_values::round_border_to_device_pixels; +use logical_geometry::WritingMode; +use properties::{CascadePropertyFn, ServoComputedValues, ComputedValues}; +use properties::longhands; +use properties::style_struct_traits::*; use std::fmt::{self, Debug}; use std::mem::{transmute, uninitialized, zeroed}; use std::sync::Arc; use std::cmp; -use style::custom_properties::ComputedValuesMap; -use style::logical_geometry::WritingMode; -use style::properties::{CascadePropertyFn, ServoComputedValues, ComputedValues}; -use style::properties::longhands; -use style::properties::style_struct_traits::*; -use values::{StyleCoordHelpers, GeckoStyleCoordConvertible, convert_nscolor_to_rgba}; -use values::convert_rgba_to_nscolor; -use values::round_border_to_device_pixels; #[derive(Clone, Debug)] pub struct GeckoComputedValues { @@ -181,7 +181,7 @@ def set_gecko_property(ffi_name, expr): <%def name="impl_keyword_setter(ident, gecko_ffi_name, keyword)"> fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { - use style::properties::longhands::${ident}::computed_value::T as Keyword; + use properties::longhands::${ident}::computed_value::T as Keyword; // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts let result = match v { % for value in keyword.values_for('gecko'): @@ -194,7 +194,7 @@ def set_gecko_property(ffi_name, expr): <%def name="impl_keyword_clone(ident, gecko_ffi_name, keyword)"> fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - use style::properties::longhands::${ident}::computed_value::T as Keyword; + use properties::longhands::${ident}::computed_value::T as Keyword; // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts match ${get_gecko_property(gecko_ffi_name)} as u32 { % for value in keyword.values_for('gecko'): @@ -324,7 +324,7 @@ def set_gecko_property(ffi_name, expr): } % if need_clone: fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - use style::properties::longhands::${ident}::computed_value::T; + use properties::longhands::${ident}::computed_value::T; T::from_gecko_style_coord(&self.gecko.${unit_ffi_name}, &self.gecko.${union_ffi_name}) .expect("clone for ${ident} failed") @@ -359,7 +359,7 @@ ${impl_split_style_coord(ident, } % if need_clone: fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - use style::properties::longhands::${ident}::computed_value::T; + use properties::longhands::${ident}::computed_value::T; use euclid::Size2D; let width = GeckoStyleCoordConvertible::from_gecko_style_coord(&self.gecko.${x_unit_ffi_name}, &self.gecko.${x_union_ffi_name}) @@ -622,7 +622,7 @@ fn static_assert() { % endfor fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) { - use style::properties::longhands::z_index::computed_value::T; + use properties::longhands::z_index::computed_value::T; match v { T::Auto => self.gecko.mZIndex.set_auto(), T::Number(n) => self.gecko.mZIndex.set_int(n), @@ -639,7 +639,7 @@ fn static_assert() { } fn clone_z_index(&self) -> longhands::z_index::computed_value::T { - use style::properties::longhands::z_index::computed_value::T; + use properties::longhands::z_index::computed_value::T; if self.gecko.mZIndex.is_auto() { return T::Auto; @@ -650,7 +650,7 @@ fn static_assert() { } fn set_box_sizing(&mut self, v: longhands::box_sizing::computed_value::T) { - use style::computed_values::box_sizing::T; + use computed_values::box_sizing::T; use gecko_bindings::structs::StyleBoxSizing; // TODO: guess what to do with box-sizing: padding-box self.gecko.mBoxSizing = match v { @@ -694,7 +694,7 @@ fn static_assert() { skip_additionals="*"> fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) { - use style::properties::longhands::font_family::computed_value::FontFamily; + use properties::longhands::font_family::computed_value::FontFamily; use gecko_bindings::structs::FontFamilyType; let list = &mut self.gecko.mFont.fontlist; @@ -774,7 +774,7 @@ fn static_assert() { // We could generalize this if we run into other newtype keywords. <% overflow_x = data.longhands_by_name["overflow-x"] %> fn set_overflow_y(&mut self, v: longhands::overflow_y::computed_value::T) { - use style::properties::longhands::overflow_x::computed_value::T as BaseType; + use properties::longhands::overflow_x::computed_value::T as BaseType; // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts self.gecko.mOverflowY = match v.0 { % for value in overflow_x.keyword.values_for('gecko'): @@ -784,8 +784,8 @@ fn static_assert() { } ${impl_simple_copy('overflow_y', 'mOverflowY')} fn clone_overflow_y(&self) -> longhands::overflow_y::computed_value::T { - use style::properties::longhands::overflow_x::computed_value::T as BaseType; - use style::properties::longhands::overflow_y::computed_value::T as NewType; + use properties::longhands::overflow_x::computed_value::T as BaseType; + use properties::longhands::overflow_y::computed_value::T as NewType; // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts match self.gecko.mOverflowY as u32 { % for value in overflow_x.keyword.values_for('gecko'): @@ -797,7 +797,7 @@ fn static_assert() { fn set_vertical_align(&mut self, v: longhands::vertical_align::computed_value::T) { <% keyword = data.longhands_by_name["vertical-align"].keyword %> - use style::properties::longhands::vertical_align::computed_value::T; + use properties::longhands::vertical_align::computed_value::T; // FIXME: Align binary representations and ditch |match| for cast + static_asserts match v { % for value in keyword.values_for('gecko'): @@ -809,8 +809,8 @@ fn static_assert() { } fn clone_vertical_align(&self) -> longhands::vertical_align::computed_value::T { - use style::properties::longhands::vertical_align::computed_value::T; - use style::values::computed::LengthOrPercentage; + use properties::longhands::vertical_align::computed_value::T; + use values::computed::LengthOrPercentage; if self.gecko.mVerticalAlign.is_enum() { match self.gecko.mVerticalAlign.get_enum() as u32 { @@ -831,7 +831,7 @@ fn static_assert() { <%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"> fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) { - use style::properties::longhands::_moz_binding::SpecifiedValue as BindingValue; + use properties::longhands::_moz_binding::SpecifiedValue as BindingValue; match v { BindingValue::None => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()), BindingValue::Url(ref url, ref extra_data) => { @@ -855,7 +855,7 @@ fn static_assert() { // "A conforming user agent may interpret the values 'left' and 'right' // as 'always'." - CSS2.1, section 13.3.1 fn set_page_break_before(&mut self, v: longhands::page_break_before::computed_value::T) { - use style::computed_values::page_break_before::T; + use computed_values::page_break_before::T; let result = match v { T::auto => false, T::always => true, @@ -872,7 +872,7 @@ fn static_assert() { // Temp fix for Bugzilla bug 24000. // See set_page_break_before for detail. fn set_page_break_after(&mut self, v: longhands::page_break_after::computed_value::T) { - use style::computed_values::page_break_after::T; + use computed_values::page_break_after::T; let result = match v { T::auto => false, T::always => true, @@ -907,7 +907,7 @@ fn static_assert() { } fn set_background_repeat(&mut self, v: longhands::background_repeat::computed_value::T) { - use style::properties::longhands::background_repeat::computed_value::T; + use properties::longhands::background_repeat::computed_value::T; use gecko_bindings::structs::{NS_STYLE_IMAGELAYER_REPEAT_REPEAT, NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT}; use gecko_bindings::structs::nsStyleImageLayers_Repeat; let (repeat_x, repeat_y) = match v { @@ -935,7 +935,7 @@ fn static_assert() { } fn set_background_clip(&mut self, v: longhands::background_clip::computed_value::T) { - use style::properties::longhands::background_clip::computed_value::T; + use properties::longhands::background_clip::computed_value::T; self.gecko.mImage.mClipCount = 1; // TODO: Gecko supports background-clip: text, but just on -webkit- @@ -954,7 +954,7 @@ fn static_assert() { } fn set_background_origin(&mut self, v: longhands::background_origin::computed_value::T) { - use style::properties::longhands::background_origin::computed_value::T; + use properties::longhands::background_origin::computed_value::T; self.gecko.mImage.mOriginCount = 1; self.gecko.mImage.mLayers.mFirstElement.mOrigin = match v { @@ -971,7 +971,7 @@ fn static_assert() { } fn set_background_attachment(&mut self, v: longhands::background_attachment::computed_value::T) { - use style::properties::longhands::background_attachment::computed_value::T; + use properties::longhands::background_attachment::computed_value::T; self.gecko.mImage.mAttachmentCount = 1; self.gecko.mImage.mLayers.mFirstElement.mAttachment = match v { @@ -992,8 +992,8 @@ fn static_assert() { use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType; use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_LINEAR, NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER}; use gecko_bindings::structs::nsStyleCoord; - use style::values::computed::Image; - use style::values::specified::AngleOrCorner; + use values::computed::Image; + use values::specified::AngleOrCorner; use cssparser::Color as CSSColor; unsafe { @@ -1104,7 +1104,7 @@ fn static_assert() { ${impl_keyword('text_align', 'mTextAlign', text_align_keyword, need_clone=False)} fn set_line_height(&mut self, v: longhands::line_height::computed_value::T) { - use style::properties::longhands::line_height::computed_value::T; + use properties::longhands::line_height::computed_value::T; // FIXME: Align binary representations and ditch |match| for cast + static_asserts match v { T::Normal => self.gecko.mLineHeight.set_normal(), @@ -1116,7 +1116,7 @@ fn static_assert() { } fn clone_line_height(&self) -> longhands::line_height::computed_value::T { - use style::properties::longhands::line_height::computed_value::T; + use properties::longhands::line_height::computed_value::T; if self.gecko.mLineHeight.is_normal() { return T::Normal; } @@ -1204,7 +1204,7 @@ fn static_assert() { <%self:impl_trait style_struct_name="Pointing" skip_longhands="cursor"> fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) { - use style::properties::longhands::cursor::computed_value::T; + use properties::longhands::cursor::computed_value::T; use style_traits::cursor::Cursor; self.gecko.mCursor = match v { diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml index 8c93b0a7177..b0a71c7874b 100644 --- a/ports/geckolib/Cargo.toml +++ b/ports/geckolib/Cargo.toml @@ -4,8 +4,6 @@ version = "0.0.1" authors = ["The Servo Project Developers"] license = "MPL-2.0" -build = "build.rs" - [lib] name = "geckoservo" path = "lib.rs" diff --git a/ports/geckolib/build.rs b/ports/geckolib/build.rs deleted file mode 100644 index fbcedacde80..00000000000 --- a/ports/geckolib/build.rs +++ /dev/null @@ -1,58 +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 std::env; -use std::path::Path; -use std::process::{Command, exit}; - -#[cfg(windows)] -fn find_python() -> String { - if Command::new("python2.7.exe").arg("--version").output().is_ok() { - return "python2.7.exe".to_owned(); - } - - 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!(concat!("Can't find python (tried python2.7.exe, 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 = env::var("PYTHON").ok().unwrap_or_else(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 properties_dir = Path::new("components").join("style").join("properties"); - println!("cargo:rerun-if-changed={}", top_dir.join(&properties_dir).to_str().unwrap()); - println!("cargo:rerun-if-changed={}", geckolib_dir.join("properties.mako.rs").to_str().unwrap()); - - let status = Command::new(python) - .current_dir(&top_dir) - .arg(&properties_dir.join("build.py")) - .arg("gecko") - .arg("geckolib") - .status() - .unwrap(); - if !status.success() { - exit(1) - } -} diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 18966777469..60fdefcd331 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -16,8 +16,7 @@ use gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI}; use gecko_bindings::structs::{SheetParsingMode, nsIAtom}; use properties::GeckoComputedValues; use selector_impl::{GeckoSelectorImpl, PseudoElement, SharedStyleContext, Stylesheet}; -use std::marker::PhantomData; -use std::mem::{forget, transmute}; +use std::mem::transmute; use std::ptr; use std::slice; use std::str::from_utf8_unchecked; @@ -26,6 +25,7 @@ use style::arc_ptr_eq; use style::context::{LocalStyleContextCreationInfo, ReflowGoal}; use style::dom::{TDocument, TElement, TNode}; use style::error_reporting::StdoutErrorReporter; +use style::gecko_glue::ArcHelpers; use style::parallel; use style::parser::ParserContextExtraData; use style::properties::{ComputedValues, PropertyDeclarationBlock, parse_one_declaration}; @@ -178,54 +178,6 @@ pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8, } } -pub struct ArcHelpers { - phantom1: PhantomData, - phantom2: PhantomData, -} - - -impl ArcHelpers { - pub fn with(raw: *mut GeckoType, cb: F) -> Output - where F: FnOnce(&Arc) -> Output { - debug_assert!(!raw.is_null()); - - let owned = unsafe { Self::into(raw) }; - let result = cb(&owned); - forget(owned); - result - } - - pub fn maybe_with(maybe_raw: *mut GeckoType, cb: F) -> Output - where F: FnOnce(Option<&Arc>) -> Output { - let owned = if maybe_raw.is_null() { - None - } else { - Some(unsafe { Self::into(maybe_raw) }) - }; - - let result = cb(owned.as_ref()); - forget(owned); - - result - } - - pub unsafe fn into(ptr: *mut GeckoType) -> Arc { - transmute(ptr) - } - - pub fn from(owned: Arc) -> *mut GeckoType { - unsafe { transmute(owned) } - } - - pub unsafe fn addref(ptr: *mut GeckoType) { - Self::with(ptr, |arc| forget(arc.clone())); - } - - pub unsafe fn release(ptr: *mut GeckoType) { - let _ = Self::into(ptr); - } -} - #[no_mangle] pub extern "C" fn Servo_AppendStyleSheet(raw_sheet: *mut RawServoStyleSheet, raw_data: *mut RawServoStyleSet) { diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index 4e38a8681d1..dba84f0b069 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -30,13 +30,7 @@ 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")); -} - +pub use style::gecko_properties as properties; pub use style::gecko_values as values; // FIXME(bholley): This should probably go away once we harmonize the allocators.