Add Servo_GetStyleFoo functions to get style structs from GeckoComputedValues.

While we're here we also:

* remove any code conditional on style_struct.gecko_ffi_name, since all
  style structs now do have a corresponding Geckos struct

* add new UIReset and XUL style structs, so that all Gecko structs are
  now present (apart from Variables, which is special)
This commit is contained in:
Cameron McCormack 2016-04-27 11:28:58 +10:00
parent aa078a0780
commit 88f51af3f8
27 changed files with 71 additions and 37 deletions

View file

@ -92,29 +92,29 @@ pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8,
}
}
struct ArcHelpers<GeckoType, ServoType> {
pub struct ArcHelpers<GeckoType, ServoType> {
phantom1: PhantomData<GeckoType>,
phantom2: PhantomData<ServoType>,
}
impl<GeckoType, ServoType> ArcHelpers<GeckoType, ServoType> {
fn with<F, Output>(raw: *mut GeckoType, cb: F) -> Output
where F: FnOnce(&Arc<ServoType>) -> Output {
pub fn with<F, Output>(raw: *mut GeckoType, cb: F) -> Output
where F: FnOnce(&Arc<ServoType>) -> Output {
let owned = unsafe { Self::into(raw) };
let result = cb(&owned);
forget(owned);
result
}
unsafe fn into(ptr: *mut GeckoType) -> Arc<ServoType> {
pub unsafe fn into(ptr: *mut GeckoType) -> Arc<ServoType> {
transmute(ptr)
}
unsafe fn addref(ptr: *mut GeckoType) {
pub unsafe fn addref(ptr: *mut GeckoType) {
Self::with(ptr, |arc| forget(arc.clone()));
}
unsafe fn release(ptr: *mut GeckoType) {
pub unsafe fn release(ptr: *mut GeckoType) {
let _ = Self::into(ptr);
}
}

View file

@ -11,14 +11,13 @@
use app_units::Au;
% for style_struct in data.style_structs:
%if style_struct.gecko_ffi_name:
use gecko_style_structs::${style_struct.gecko_ffi_name};
use bindings::Gecko_Construct_${style_struct.gecko_ffi_name};
use bindings::Gecko_CopyConstruct_${style_struct.gecko_ffi_name};
use bindings::Gecko_Destroy_${style_struct.gecko_ffi_name};
% endif
% endfor
use gecko_style_structs;
use glue::ArcHelpers;
use heapsize::HeapSizeOf;
use std::fmt::{self, Debug};
use std::mem::{transmute, zeroed};
@ -103,13 +102,9 @@ impl ComputedValues for GeckoComputedValues {
<%def name="declare_style_struct(style_struct)">
#[derive(Clone, HeapSizeOf, Debug)]
% if style_struct.gecko_ffi_name:
pub struct ${style_struct.gecko_struct_name} {
gecko: ${style_struct.gecko_ffi_name},
}
% else:
pub struct ${style_struct.gecko_struct_name};
% endif
</%def>
<%def name="impl_simple_copy(ident, gecko_ffi_name)">
@ -194,8 +189,10 @@ impl ${style_struct.gecko_struct_name} {
}
result
}
pub fn get_gecko(&self) -> &${style_struct.gecko_ffi_name} {
&self.gecko
}
}
%if style_struct.gecko_ffi_name:
impl Drop for ${style_struct.gecko_struct_name} {
fn drop(&mut self) {
unsafe {
@ -229,7 +226,6 @@ impl Debug for ${style_struct.gecko_ffi_name} {
}
}
%endif
%endif
</%def>
<%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')">
@ -404,12 +400,24 @@ for side in SIDES:
</%self:impl_trait>
<%def name="define_ffi_struct_accessor(style_struct)">
#[no_mangle]
#[allow(non_snake_case, unused_variables)]
pub extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values: *mut ServoComputedValues)
-> *const ${style_struct.gecko_ffi_name} {
type Helpers = ArcHelpers<ServoComputedValues, GeckoComputedValues>;
Helpers::with(computed_values, |values| values.get_${style_struct.trait_name_lower}().get_gecko()
as *const ${style_struct.gecko_ffi_name})
}
</%def>
% for style_struct in data.style_structs:
${declare_style_struct(style_struct)}
${impl_style_struct(style_struct)}
% if not style_struct.trait_name in data.manual_style_structs:
<%self:raw_impl_trait style_struct="${style_struct}"></%self:raw_impl_trait>
% endif
${define_ffi_struct_accessor(style_struct)}
% endfor
lazy_static! {