Skip to content

Commit

Permalink
Bug 1298588 part 3, servo piece. Add a default ComputedValues member …
Browse files Browse the repository at this point in the history
…to PerDocumentStyleData. r=bholley
  • Loading branch information
bzbarsky committed Jan 5, 2017
1 parent 8908743 commit 34bb2f1
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/style/gecko/data.rs
Expand Up @@ -14,6 +14,7 @@ use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use media_queries::{Device, MediaType};
use num_cpus;
use parking_lot::RwLock;
use properties::ComputedValues;
use rayon;
use std::cmp;
use std::collections::HashMap;
Expand Down Expand Up @@ -56,6 +57,9 @@ pub struct PerDocumentStyleDataImpl {

/// The number of threads of the work queue.
pub num_threads: usize,

/// Default computed values for this document.
pub default_computed_values: Arc<ComputedValues>
}

/// The data itself is an `AtomicRefCell`, which guarantees the proper semantics
Expand All @@ -74,7 +78,6 @@ lazy_static! {

impl PerDocumentStyleData {
/// Create a dummy `PerDocumentStyleData`.
#[allow(unused_variables)] // temporary until we make use of the ctor arg.
pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
// FIXME(bholley): Real window size.
let window_size: TypedSize2D<f32, ViewportPx> = TypedSize2D::new(800.0, 600.0);
Expand All @@ -98,6 +101,7 @@ impl PerDocumentStyleData {
rayon::ThreadPool::new(configuration).ok()
},
num_threads: *NUM_THREADS,
default_computed_values: ComputedValues::default_values(pres_context),
}))
}

Expand Down
126 changes: 126 additions & 0 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -735,6 +735,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleFont(ptr: *mut nsStyleFont,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont,
other: *const nsStyleFont);
Expand All @@ -745,6 +750,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleColor(ptr: *mut nsStyleColor);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleColor(ptr: *mut nsStyleColor,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleColor(ptr: *mut nsStyleColor,
other: *const nsStyleColor);
Expand All @@ -755,6 +765,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleList(ptr: *mut nsStyleList);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleList(ptr: *mut nsStyleList,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleList(ptr: *mut nsStyleList,
other: *const nsStyleList);
Expand All @@ -765,6 +780,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleText(ptr: *mut nsStyleText);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleText(ptr: *mut nsStyleText,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleText(ptr: *mut nsStyleText,
other: *const nsStyleText);
Expand All @@ -775,6 +795,12 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleVisibility(ptr: *mut nsStyleVisibility);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleVisibility(ptr:
*mut nsStyleVisibility,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleVisibility(ptr: *mut nsStyleVisibility,
other:
Expand All @@ -787,6 +813,12 @@ extern "C" {
pub fn Gecko_Construct_nsStyleUserInterface(ptr:
*mut nsStyleUserInterface);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleUserInterface(ptr:
*mut nsStyleUserInterface,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleUserInterface(ptr:
*mut nsStyleUserInterface,
Expand All @@ -799,6 +831,12 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleTableBorder(ptr: *mut nsStyleTableBorder);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleTableBorder(ptr:
*mut nsStyleTableBorder,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleTableBorder(ptr:
*mut nsStyleTableBorder,
Expand All @@ -811,6 +849,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleSVG(ptr: *mut nsStyleSVG);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleSVG(ptr: *mut nsStyleSVG,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleSVG(ptr: *mut nsStyleSVG,
other: *const nsStyleSVG);
Expand All @@ -821,6 +864,12 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleVariables(ptr: *mut nsStyleVariables);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleVariables(ptr:
*mut nsStyleVariables,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleVariables(ptr: *mut nsStyleVariables,
other:
Expand All @@ -832,6 +881,12 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleBackground(ptr: *mut nsStyleBackground);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleBackground(ptr:
*mut nsStyleBackground,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleBackground(ptr: *mut nsStyleBackground,
other:
Expand All @@ -843,6 +898,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStylePosition(ptr: *mut nsStylePosition);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStylePosition(ptr: *mut nsStylePosition,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStylePosition(ptr: *mut nsStylePosition,
other: *const nsStylePosition);
Expand All @@ -853,6 +913,12 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleTextReset(ptr: *mut nsStyleTextReset);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleTextReset(ptr:
*mut nsStyleTextReset,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleTextReset(ptr: *mut nsStyleTextReset,
other:
Expand All @@ -864,6 +930,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleDisplay(ptr: *mut nsStyleDisplay);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleDisplay(ptr: *mut nsStyleDisplay,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleDisplay(ptr: *mut nsStyleDisplay,
other: *const nsStyleDisplay);
Expand All @@ -874,6 +945,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleContent(ptr: *mut nsStyleContent);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleContent(ptr: *mut nsStyleContent,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleContent(ptr: *mut nsStyleContent,
other: *const nsStyleContent);
Expand All @@ -884,6 +960,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleUIReset(ptr: *mut nsStyleUIReset);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleUIReset(ptr: *mut nsStyleUIReset,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleUIReset(ptr: *mut nsStyleUIReset,
other: *const nsStyleUIReset);
Expand All @@ -894,6 +975,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleTable(ptr: *mut nsStyleTable);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleTable(ptr: *mut nsStyleTable,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleTable(ptr: *mut nsStyleTable,
other: *const nsStyleTable);
Expand All @@ -904,6 +990,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleMargin(ptr: *mut nsStyleMargin);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleMargin(ptr: *mut nsStyleMargin,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleMargin(ptr: *mut nsStyleMargin,
other: *const nsStyleMargin);
Expand All @@ -914,6 +1005,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStylePadding(ptr: *mut nsStylePadding);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStylePadding(ptr: *mut nsStylePadding,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStylePadding(ptr: *mut nsStylePadding,
other: *const nsStylePadding);
Expand All @@ -924,6 +1020,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleBorder(ptr: *mut nsStyleBorder);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleBorder(ptr: *mut nsStyleBorder,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleBorder(ptr: *mut nsStyleBorder,
other: *const nsStyleBorder);
Expand All @@ -934,6 +1035,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleOutline(ptr: *mut nsStyleOutline);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleOutline(ptr: *mut nsStyleOutline,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleOutline(ptr: *mut nsStyleOutline,
other: *const nsStyleOutline);
Expand All @@ -944,6 +1050,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleXUL(ptr: *mut nsStyleXUL);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleXUL(ptr: *mut nsStyleXUL,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleXUL(ptr: *mut nsStyleXUL,
other: *const nsStyleXUL);
Expand All @@ -954,6 +1065,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleSVGReset(ptr: *mut nsStyleSVGReset,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset,
other: *const nsStyleSVGReset);
Expand All @@ -964,6 +1080,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleColumn(ptr: *mut nsStyleColumn);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleColumn(ptr: *mut nsStyleColumn,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleColumn(ptr: *mut nsStyleColumn,
other: *const nsStyleColumn);
Expand All @@ -974,6 +1095,11 @@ extern "C" {
extern "C" {
pub fn Gecko_Construct_nsStyleEffects(ptr: *mut nsStyleEffects);
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleEffects(ptr: *mut nsStyleEffects,
pres_context:
RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_CopyConstruct_nsStyleEffects(ptr: *mut nsStyleEffects,
other: *const nsStyleEffects);
Expand Down
23 changes: 23 additions & 0 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -16,6 +16,7 @@ use gecko_bindings::bindings;
% 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};
use gecko_bindings::bindings::Gecko_Construct_Default_${style_struct.gecko_ffi_name};
use gecko_bindings::bindings::Gecko_CopyConstruct_${style_struct.gecko_ffi_name};
use gecko_bindings::bindings::Gecko_Destroy_${style_struct.gecko_ffi_name};
% endfor
Expand All @@ -40,6 +41,7 @@ use gecko_bindings::bindings::Gecko_SetMozBinding;
use gecko_bindings::bindings::Gecko_SetNullImageValue;
use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
use gecko_bindings::bindings::RawGeckoPresContextBorrowed;
use gecko_bindings::structs;
use gecko_bindings::structs::nsStyleVariables;
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
Expand Down Expand Up @@ -125,6 +127,18 @@ impl ComputedValues {
}
}

pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
Arc::new(ComputedValues {
custom_properties: None,
shareable: true,
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious?
% for style_struct in data.style_structs:
${style_struct.ident}: style_structs::${style_struct.name}::default(pres_context),
% endfor
})
}

pub unsafe fn initialize() {
debug_assert!(raw_initial_values().is_null());
set_raw_initial_values(Box::into_raw(Box::new(ComputedValues {
Expand Down Expand Up @@ -422,6 +436,15 @@ impl ${style_struct.gecko_struct_name} {
}
result
}
#[allow(dead_code, unused_variables)]
pub fn default(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } });
unsafe {
Gecko_Construct_Default_${style_struct.gecko_ffi_name}(&mut Arc::get_mut(&mut result).unwrap().gecko,
pres_context);
}
result
}
pub fn get_gecko(&self) -> &${style_struct.gecko_ffi_name} {
&self.gecko
}
Expand Down

0 comments on commit 34bb2f1

Please sign in to comment.