diff options
-rw-r--r-- | ports/geckolib/glue.rs | 6 | ||||
-rw-r--r-- | ports/geckolib/properties.mako.rs | 34 |
2 files changed, 35 insertions, 5 deletions
diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 72fbf90e4ff..1bb4797e92e 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -22,6 +22,7 @@ use style::context::{ReflowGoal, StylistWrapper}; use style::dom::{TDocument, TElement, TNode}; use style::error_reporting::StdoutErrorReporter; use style::parallel; +use style::properties::ComputedValues; use style::stylesheets::Origin; use traversal::RecalcStyleOnly; use url::Url; @@ -45,6 +46,11 @@ pub extern "C" fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, raw_data: *m }; let data = unsafe { &mut *(raw_data as *mut PerDocumentStyleData) }; + // Force the creation of our lazily-constructed initial computed values on + // the main thread, since it's not safe to call elsewhere. This should move + // into a runtime-wide init hook at some point. + GeckoComputedValues::initial_values(); + let _needs_dirtying = data.stylist.update(&data.stylesheets, data.stylesheets_changed); data.stylesheets_changed = false; diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 053e730281c..38e3b0ead44 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -6,6 +6,9 @@ use app_units::Au; % for style_struct in STYLE_STRUCTS: %if style_struct.gecko_name: use gecko_style_structs::${style_struct.gecko_name}; +use bindings::Gecko_Construct_${style_struct.gecko_name}; +use bindings::Gecko_CopyConstruct_${style_struct.gecko_name}; +use bindings::Gecko_Destroy_${style_struct.gecko_name}; % endif % endfor use heapsize::HeapSizeOf; @@ -58,7 +61,7 @@ impl ComputedValues for GeckoComputedValues { } } - fn initial_values() -> &'static Self { unimplemented!() } + fn initial_values() -> &'static Self { &*INITIAL_GECKO_VALUES } fn do_cascade_property<F: FnOnce(&Vec<Option<CascadePropertyFn<Self>>>)>(_: F) { unimplemented!() @@ -104,8 +107,11 @@ 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"); + let mut result = Gecko${style_struct.name} { gecko: unsafe { zeroed() } }; + unsafe { + Gecko_Construct_${style_struct.gecko_name}(&mut result.gecko); + } + result % else: Gecko${style_struct.name} % endif @@ -114,12 +120,18 @@ impl Gecko${style_struct.name} { %if style_struct.gecko_name: impl Drop for Gecko${style_struct.name} { fn drop(&mut self) { - panic!("Need to invoke Gecko destructor"); + unsafe { + Gecko_Destroy_${style_struct.gecko_name}(&mut self.gecko); + } } } impl Clone for ${style_struct.gecko_name} { fn clone(&self) -> Self { - panic!("Need to invoke Gecko copy constructor"); + unsafe { + let mut result: Self = zeroed(); + Gecko_CopyConstruct_${style_struct.gecko_name}(&mut result, self); + result + } } } unsafe impl Send for ${style_struct.gecko_name} {} @@ -205,3 +217,15 @@ ${impl_style_struct(style_struct)} <%self:raw_impl_trait style_struct="${style_struct}"></%self:raw_impl_trait> % endif % endfor + +lazy_static! { + pub static ref INITIAL_GECKO_VALUES: GeckoComputedValues = GeckoComputedValues { + % for style_struct in STYLE_STRUCTS: + ${style_struct.ident}: Arc::new(Gecko${style_struct.name}::initial()), + % endfor + custom_properties: None, + shareable: true, + writing_mode: WritingMode::empty(), + root_font_size: longhands::font_size::get_initial_value(), + }; +} |