servo: Merge #10359 - Implement construction, destruction, and copying of gecko style structs (from bholley:style_struct_management); r=SimonSapin

This requires some new machinery on the gecko side, which I'll get up in bugzilla shortly.

Source-Repo: https://github.com/servo/servo
Source-Revision: a3b55d68a84dac301b3bc40d2444934b7df8e167
This commit is contained in:
Bobby Holley 2016-04-04 19:42:29 +05:01
Родитель 6882ae5bcf
Коммит 4d37b3664d
5 изменённых файлов: 192 добавлений и 18 удалений

Просмотреть файл

@ -6722,10 +6722,8 @@ pub type CascadePropertyFn<C /*: ComputedValues */> =
cacheable: &mut bool,
error_reporter: &mut Box<ParseErrorReporter + Send>);
// This is a thread-local rather than a lazy static to avoid atomic operations when cascading
// properties.
thread_local!(static CASCADE_PROPERTY: Vec<Option<CascadePropertyFn<ServoComputedValues>>> = {
let mut result: Vec<Option<CascadePropertyFn<ServoComputedValues>>> = Vec::new();
pub fn make_cascade_vec<C: ComputedValues>() -> Vec<Option<CascadePropertyFn<C>>> {
let mut result: Vec<Option<CascadePropertyFn<C>>> = Vec::new();
% for style_struct in STYLE_STRUCTS:
% for property in style_struct.longhands:
let discriminant;
@ -6741,6 +6739,12 @@ thread_local!(static CASCADE_PROPERTY: Vec<Option<CascadePropertyFn<ServoCompute
% endfor
% endfor
result
}
// This is a thread-local rather than a lazy static to avoid atomic operations when cascading
// properties.
thread_local!(static CASCADE_PROPERTY: Vec<Option<CascadePropertyFn<ServoComputedValues>>> = {
make_cascade_vec::<ServoComputedValues>()
});
/// Performs the CSS cascade, computing new styles for an element from its parent style and

Просмотреть файл

@ -11,6 +11,33 @@ pub enum ServoNodeData { }
pub enum ServoComputedValues { }
pub enum RawServoStyleSheet { }
pub enum RawServoStyleSet { }
// Temporary manual hack. This will be fixed soon in bindgen.
use gecko_style_structs::nsStyleFont;
use gecko_style_structs::nsStyleColor;
use gecko_style_structs::nsStyleList;
use gecko_style_structs::nsStyleText;
use gecko_style_structs::nsStyleVisibility;
use gecko_style_structs::nsStyleQuotes;
use gecko_style_structs::nsStyleUserInterface;
use gecko_style_structs::nsStyleTableBorder;
use gecko_style_structs::nsStyleSVG;
use gecko_style_structs::nsStyleVariables;
use gecko_style_structs::nsStyleBackground;
use gecko_style_structs::nsStylePosition;
use gecko_style_structs::nsStyleTextReset;
use gecko_style_structs::nsStyleDisplay;
use gecko_style_structs::nsStyleContent;
use gecko_style_structs::nsStyleUIReset;
use gecko_style_structs::nsStyleTable;
use gecko_style_structs::nsStyleMargin;
use gecko_style_structs::nsStylePadding;
use gecko_style_structs::nsStyleBorder;
use gecko_style_structs::nsStyleOutline;
use gecko_style_structs::nsStyleXUL;
use gecko_style_structs::nsStyleSVGReset;
use gecko_style_structs::nsStyleColumn;
extern "C" {
pub fn Gecko_ChildrenCount(node: *mut RawGeckoNode) -> u32;
pub fn Gecko_NodeIsElement(node: *mut RawGeckoNode) -> bool;
@ -56,13 +83,6 @@ extern "C" {
pub fn Servo_StyleSheetHasRules(sheet: *mut RawServoStyleSheet) -> bool;
pub fn Servo_InitStyleSet() -> *mut RawServoStyleSet;
pub fn Servo_DropStyleSet(set: *mut RawServoStyleSet);
pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, ns: *const u8,
name: *const u8, length: *mut u32)
-> *const ::std::os::raw::c_char;
pub fn Gecko_LocalName(element: *mut RawGeckoElement, length: *mut u32)
-> *const u16;
pub fn Gecko_Namespace(element: *mut RawGeckoElement, length: *mut u32)
-> *const u16;
pub fn Servo_GetComputedValues(element: *mut RawGeckoElement)
-> *mut ServoComputedValues;
pub fn Servo_GetComputedValuesForAnonymousBox(parentStyleOrNull:
@ -71,6 +91,118 @@ extern "C" {
-> *mut ServoComputedValues;
pub fn Servo_AddRefComputedValues(arg1: *mut ServoComputedValues);
pub fn Servo_ReleaseComputedValues(arg1: *mut ServoComputedValues);
pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, ns: *const u8,
name: *const u8, length: *mut u32)
-> *const ::std::os::raw::c_char;
pub fn Gecko_LocalName(element: *mut RawGeckoElement, length: *mut u32)
-> *const u16;
pub fn Gecko_Namespace(element: *mut RawGeckoElement, length: *mut u32)
-> *const u16;
pub fn Servo_RestyleDocument(doc: *mut RawGeckoDocument,
set: *mut RawServoStyleSet);
pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont);
pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont,
other: *const nsStyleFont);
pub fn Gecko_Destroy_nsStyleFont(ptr: *mut nsStyleFont);
pub fn Gecko_Construct_nsStyleColor(ptr: *mut nsStyleColor);
pub fn Gecko_CopyConstruct_nsStyleColor(ptr: *mut nsStyleColor,
other: *const nsStyleColor);
pub fn Gecko_Destroy_nsStyleColor(ptr: *mut nsStyleColor);
pub fn Gecko_Construct_nsStyleList(ptr: *mut nsStyleList);
pub fn Gecko_CopyConstruct_nsStyleList(ptr: *mut nsStyleList,
other: *const nsStyleList);
pub fn Gecko_Destroy_nsStyleList(ptr: *mut nsStyleList);
pub fn Gecko_Construct_nsStyleText(ptr: *mut nsStyleText);
pub fn Gecko_CopyConstruct_nsStyleText(ptr: *mut nsStyleText,
other: *const nsStyleText);
pub fn Gecko_Destroy_nsStyleText(ptr: *mut nsStyleText);
pub fn Gecko_Construct_nsStyleVisibility(ptr: *mut nsStyleVisibility);
pub fn Gecko_CopyConstruct_nsStyleVisibility(ptr: *mut nsStyleVisibility,
other:
*const nsStyleVisibility);
pub fn Gecko_Destroy_nsStyleVisibility(ptr: *mut nsStyleVisibility);
pub fn Gecko_Construct_nsStyleQuotes(ptr: *mut nsStyleQuotes);
pub fn Gecko_CopyConstruct_nsStyleQuotes(ptr: *mut nsStyleQuotes,
other: *const nsStyleQuotes);
pub fn Gecko_Destroy_nsStyleQuotes(ptr: *mut nsStyleQuotes);
pub fn Gecko_Construct_nsStyleUserInterface(ptr:
*mut nsStyleUserInterface);
pub fn Gecko_CopyConstruct_nsStyleUserInterface(ptr:
*mut nsStyleUserInterface,
other:
*const nsStyleUserInterface);
pub fn Gecko_Destroy_nsStyleUserInterface(ptr: *mut nsStyleUserInterface);
pub fn Gecko_Construct_nsStyleTableBorder(ptr: *mut nsStyleTableBorder);
pub fn Gecko_CopyConstruct_nsStyleTableBorder(ptr:
*mut nsStyleTableBorder,
other:
*const nsStyleTableBorder);
pub fn Gecko_Destroy_nsStyleTableBorder(ptr: *mut nsStyleTableBorder);
pub fn Gecko_Construct_nsStyleSVG(ptr: *mut nsStyleSVG);
pub fn Gecko_CopyConstruct_nsStyleSVG(ptr: *mut nsStyleSVG,
other: *const nsStyleSVG);
pub fn Gecko_Destroy_nsStyleSVG(ptr: *mut nsStyleSVG);
pub fn Gecko_Construct_nsStyleVariables(ptr: *mut nsStyleVariables);
pub fn Gecko_CopyConstruct_nsStyleVariables(ptr: *mut nsStyleVariables,
other:
*const nsStyleVariables);
pub fn Gecko_Destroy_nsStyleVariables(ptr: *mut nsStyleVariables);
pub fn Gecko_Construct_nsStyleBackground(ptr: *mut nsStyleBackground);
pub fn Gecko_CopyConstruct_nsStyleBackground(ptr: *mut nsStyleBackground,
other:
*const nsStyleBackground);
pub fn Gecko_Destroy_nsStyleBackground(ptr: *mut nsStyleBackground);
pub fn Gecko_Construct_nsStylePosition(ptr: *mut nsStylePosition);
pub fn Gecko_CopyConstruct_nsStylePosition(ptr: *mut nsStylePosition,
other: *const nsStylePosition);
pub fn Gecko_Destroy_nsStylePosition(ptr: *mut nsStylePosition);
pub fn Gecko_Construct_nsStyleTextReset(ptr: *mut nsStyleTextReset);
pub fn Gecko_CopyConstruct_nsStyleTextReset(ptr: *mut nsStyleTextReset,
other:
*const nsStyleTextReset);
pub fn Gecko_Destroy_nsStyleTextReset(ptr: *mut nsStyleTextReset);
pub fn Gecko_Construct_nsStyleDisplay(ptr: *mut nsStyleDisplay);
pub fn Gecko_CopyConstruct_nsStyleDisplay(ptr: *mut nsStyleDisplay,
other: *const nsStyleDisplay);
pub fn Gecko_Destroy_nsStyleDisplay(ptr: *mut nsStyleDisplay);
pub fn Gecko_Construct_nsStyleContent(ptr: *mut nsStyleContent);
pub fn Gecko_CopyConstruct_nsStyleContent(ptr: *mut nsStyleContent,
other: *const nsStyleContent);
pub fn Gecko_Destroy_nsStyleContent(ptr: *mut nsStyleContent);
pub fn Gecko_Construct_nsStyleUIReset(ptr: *mut nsStyleUIReset);
pub fn Gecko_CopyConstruct_nsStyleUIReset(ptr: *mut nsStyleUIReset,
other: *const nsStyleUIReset);
pub fn Gecko_Destroy_nsStyleUIReset(ptr: *mut nsStyleUIReset);
pub fn Gecko_Construct_nsStyleTable(ptr: *mut nsStyleTable);
pub fn Gecko_CopyConstruct_nsStyleTable(ptr: *mut nsStyleTable,
other: *const nsStyleTable);
pub fn Gecko_Destroy_nsStyleTable(ptr: *mut nsStyleTable);
pub fn Gecko_Construct_nsStyleMargin(ptr: *mut nsStyleMargin);
pub fn Gecko_CopyConstruct_nsStyleMargin(ptr: *mut nsStyleMargin,
other: *const nsStyleMargin);
pub fn Gecko_Destroy_nsStyleMargin(ptr: *mut nsStyleMargin);
pub fn Gecko_Construct_nsStylePadding(ptr: *mut nsStylePadding);
pub fn Gecko_CopyConstruct_nsStylePadding(ptr: *mut nsStylePadding,
other: *const nsStylePadding);
pub fn Gecko_Destroy_nsStylePadding(ptr: *mut nsStylePadding);
pub fn Gecko_Construct_nsStyleBorder(ptr: *mut nsStyleBorder);
pub fn Gecko_CopyConstruct_nsStyleBorder(ptr: *mut nsStyleBorder,
other: *const nsStyleBorder);
pub fn Gecko_Destroy_nsStyleBorder(ptr: *mut nsStyleBorder);
pub fn Gecko_Construct_nsStyleOutline(ptr: *mut nsStyleOutline);
pub fn Gecko_CopyConstruct_nsStyleOutline(ptr: *mut nsStyleOutline,
other: *const nsStyleOutline);
pub fn Gecko_Destroy_nsStyleOutline(ptr: *mut nsStyleOutline);
pub fn Gecko_Construct_nsStyleXUL(ptr: *mut nsStyleXUL);
pub fn Gecko_CopyConstruct_nsStyleXUL(ptr: *mut nsStyleXUL,
other: *const nsStyleXUL);
pub fn Gecko_Destroy_nsStyleXUL(ptr: *mut nsStyleXUL);
pub fn Gecko_Construct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset);
pub fn Gecko_CopyConstruct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset,
other: *const nsStyleSVGReset);
pub fn Gecko_Destroy_nsStyleSVGReset(ptr: *mut nsStyleSVGReset);
pub fn Gecko_Construct_nsStyleColumn(ptr: *mut nsStyleColumn);
pub fn Gecko_CopyConstruct_nsStyleColumn(ptr: *mut nsStyleColumn,
other: *const nsStyleColumn);
pub fn Gecko_Destroy_nsStyleColumn(ptr: *mut nsStyleColumn);
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
@ -16,6 +19,7 @@ use style::custom_properties::ComputedValuesMap;
use style::logical_geometry::WritingMode;
use style::properties::{CascadePropertyFn, ServoComputedValues, ComputedValues};
use style::properties::longhands;
use style::properties::make_cascade_vec;
use style::properties::style_struct_traits::*;
#[derive(Clone)]
@ -58,10 +62,10 @@ 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!()
fn do_cascade_property<F: FnOnce(&Vec<Option<CascadePropertyFn<Self>>>)>(f: F) {
CASCADE_PROPERTY.with(|x| f(x));
}
% for style_struct in STYLE_STRUCTS:
@ -104,8 +108,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 +121,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 +218,21 @@ ${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(),
};
}
// This is a thread-local rather than a lazy static to avoid atomic operations when cascading
// properties.
thread_local!(static CASCADE_PROPERTY: Vec<Option<CascadePropertyFn<GeckoComputedValues>>> = {
make_cascade_vec::<GeckoComputedValues>()
});

Просмотреть файл

@ -38,3 +38,4 @@ fi
-no-type-renaming \
"$DIST_INCLUDE/mozilla/ServoBindings.h" \
-match "ServoBindings.h" \
-match "nsStyleStructList.h" \