mirror of
https://github.com/servo/servo.git
synced 2025-08-26 23:58:20 +01:00
Auto merge of #10848 - heycam:struct-accessor, r=bholley
Add Servo_GetStyleFoo functions to get style structs from GeckoComputedValues r?@bholley <!-- 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/10848) <!-- Reviewable:end -->
This commit is contained in:
commit
e079e01320
27 changed files with 71 additions and 37 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)">
|
||||
|
@ -192,8 +187,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 {
|
||||
|
@ -227,7 +224,6 @@ impl Debug for ${style_struct.gecko_ffi_name} {
|
|||
}
|
||||
}
|
||||
%endif
|
||||
%endif
|
||||
</%def>
|
||||
|
||||
<%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')">
|
||||
|
@ -406,12 +402,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! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue