Invoke the ctor/copy/dtor when managing gecko style structs from servo, and implement GeckoComputedValues::initial_values().

This commit is contained in:
Bobby Holley 2016-04-01 17:42:44 -07:00
parent 6db8dc218c
commit 899d6a9f64
2 changed files with 35 additions and 5 deletions

View file

@ -22,6 +22,7 @@ use style::context::{ReflowGoal, StylistWrapper};
use style::dom::{TDocument, TElement, TNode}; use style::dom::{TDocument, TElement, TNode};
use style::error_reporting::StdoutErrorReporter; use style::error_reporting::StdoutErrorReporter;
use style::parallel; use style::parallel;
use style::properties::ComputedValues;
use style::stylesheets::Origin; use style::stylesheets::Origin;
use traversal::RecalcStyleOnly; use traversal::RecalcStyleOnly;
use url::Url; 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) }; 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); let _needs_dirtying = data.stylist.update(&data.stylesheets, data.stylesheets_changed);
data.stylesheets_changed = false; data.stylesheets_changed = false;

View file

@ -6,6 +6,9 @@ use app_units::Au;
% for style_struct in STYLE_STRUCTS: % for style_struct in STYLE_STRUCTS:
%if style_struct.gecko_name: %if style_struct.gecko_name:
use gecko_style_structs::${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 % endif
% endfor % endfor
use heapsize::HeapSizeOf; 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) { fn do_cascade_property<F: FnOnce(&Vec<Option<CascadePropertyFn<Self>>>)>(_: F) {
unimplemented!() unimplemented!()
@ -104,8 +107,11 @@ impl Gecko${style_struct.name} {
#[allow(dead_code, unused_variables)] #[allow(dead_code, unused_variables)]
fn initial() -> Self { fn initial() -> Self {
% if style_struct.gecko_name: % if style_struct.gecko_name:
let result = Gecko${style_struct.name} { gecko: unsafe { zeroed() } }; let mut result = Gecko${style_struct.name} { gecko: unsafe { zeroed() } };
panic!("Need to invoke Gecko placement new"); unsafe {
Gecko_Construct_${style_struct.gecko_name}(&mut result.gecko);
}
result
% else: % else:
Gecko${style_struct.name} Gecko${style_struct.name}
% endif % endif
@ -114,12 +120,18 @@ impl Gecko${style_struct.name} {
%if style_struct.gecko_name: %if style_struct.gecko_name:
impl Drop for Gecko${style_struct.name} { impl Drop for Gecko${style_struct.name} {
fn drop(&mut self) { 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} { impl Clone for ${style_struct.gecko_name} {
fn clone(&self) -> Self { 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} {} 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> <%self:raw_impl_trait style_struct="${style_struct}"></%self:raw_impl_trait>
% endif % endif
% endfor % 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(),
};
}