aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-04-04 20:11:29 +0530
committerbors-servo <lbergstrom+bors@mozilla.com>2016-04-04 20:11:29 +0530
commita3b55d68a84dac301b3bc40d2444934b7df8e167 (patch)
tree6af50c1da4d24753e0d9563f802f070f2505a664
parentca3d120f4abaa40c9377ac450420372fd00cf668 (diff)
parent43e49705be1f762088b506e0a746393a79731b7a (diff)
downloadservo-a3b55d68a84dac301b3bc40d2444934b7df8e167.tar.gz
servo-a3b55d68a84dac301b3bc40d2444934b7df8e167.zip
Auto merge of #10359 - bholley:style_struct_management, r=SimonSapin
Implement construction, destruction, and copying of gecko style structs This requires some new machinery on the gecko side, which I'll get up in bugzilla shortly. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10359) <!-- Reviewable:end -->
-rw-r--r--components/style/properties.mako.rs12
-rw-r--r--ports/geckolib/bindings.rs146
-rw-r--r--ports/geckolib/glue.rs6
-rw-r--r--ports/geckolib/properties.mako.rs45
-rwxr-xr-xports/geckolib/tools/regen_bindings.sh1
5 files changed, 192 insertions, 18 deletions
diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs
index ce285c4d71b..0b9dcd11217 100644
--- a/components/style/properties.mako.rs
+++ b/components/style/properties.mako.rs
@@ -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
diff --git a/ports/geckolib/bindings.rs b/ports/geckolib/bindings.rs
index 5dcb7be670a..2c92184f8e7 100644
--- a/ports/geckolib/bindings.rs
+++ b/ports/geckolib/bindings.rs
@@ -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);
}
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..94407b18c8f 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;
@@ -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>()
+});
diff --git a/ports/geckolib/tools/regen_bindings.sh b/ports/geckolib/tools/regen_bindings.sh
index 77ee56ee5bf..02291c07084 100755
--- a/ports/geckolib/tools/regen_bindings.sh
+++ b/ports/geckolib/tools/regen_bindings.sh
@@ -38,3 +38,4 @@ fi
-no-type-renaming \
"$DIST_INCLUDE/mozilla/ServoBindings.h" \
-match "ServoBindings.h" \
+ -match "nsStyleStructList.h" \