mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Remove some magic from the bindings
This simplifies a tiny bit our bindings in some places, and complicates it in others, but over all I think it's better. It requires a bit more manual code in the rust side to drop and cast the relevant pointers (which was done implicitly before), but it's a lot less magic than it used to be, and that's all autogenerated so consumers don't need to care about it. The set up is still not ideal. I don't like that we rely on destructors running in both sides of the FFI boundary, but that's for another day. This is the last usage of RawOffsetArc, so remove that. We now support proper Arc<> in structs (GridTemplateAreas uses it), so I don't think we'll need it any time soon. Differential Revision: https://phabricator.services.mozilla.com/D177905
This commit is contained in:
parent
e9bf977369
commit
d1046739fc
7 changed files with 320 additions and 472 deletions
|
@ -131,7 +131,7 @@ impl Device {
|
|||
line_height,
|
||||
pres_context.map_or(std::ptr::null(), |pc| pc),
|
||||
vertical,
|
||||
font.gecko(),
|
||||
&**font,
|
||||
element.map_or(std::ptr::null(), |e| e.0)
|
||||
)
|
||||
});
|
||||
|
@ -231,7 +231,7 @@ impl Device {
|
|||
bindings::Gecko_GetFontMetrics(
|
||||
pc,
|
||||
vertical,
|
||||
font.gecko(),
|
||||
&**font,
|
||||
base_size,
|
||||
// we don't use the user font set in a media query
|
||||
!in_media_query,
|
||||
|
|
|
@ -900,7 +900,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
|
||||
let builder = &mut self.context.builder;
|
||||
let default_font_type = {
|
||||
let font = builder.get_font().gecko();
|
||||
let font = builder.get_font();
|
||||
|
||||
if !font.mFont.family.is_initial {
|
||||
return;
|
||||
|
@ -922,9 +922,8 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
default_font_type
|
||||
};
|
||||
|
||||
let font = builder.mutate_font().gecko_mut();
|
||||
// NOTE: Leaves is_initial untouched.
|
||||
font.mFont.family.families = FontFamily::generic(default_font_type).families.clone();
|
||||
builder.mutate_font().mFont.family.families = FontFamily::generic(default_font_type).families.clone();
|
||||
}
|
||||
|
||||
/// Prioritize user fonts if needed by pref.
|
||||
|
@ -943,7 +942,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
|
||||
let builder = &mut self.context.builder;
|
||||
let default_font_type = {
|
||||
let font = builder.get_font().gecko();
|
||||
let font = builder.get_font();
|
||||
|
||||
if font.mFont.family.is_system_font {
|
||||
return;
|
||||
|
@ -961,7 +960,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
}
|
||||
};
|
||||
|
||||
let font = builder.mutate_font().gecko_mut();
|
||||
let font = builder.mutate_font();
|
||||
font.mFont.family.families.prioritize_first_generic_or_prepend(default_font_type);
|
||||
}
|
||||
|
||||
|
@ -986,7 +985,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
},
|
||||
};
|
||||
|
||||
if font.gecko().mScriptUnconstrainedSize == new_size.computed_size {
|
||||
if font.mScriptUnconstrainedSize == new_size.computed_size {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1013,9 +1012,9 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
|
||||
let builder = &mut self.context.builder;
|
||||
let min_font_size = {
|
||||
let font = builder.get_font().gecko();
|
||||
let font = builder.get_font();
|
||||
let min_font_size = unsafe {
|
||||
bindings::Gecko_nsStyleFont_ComputeMinSize(font, builder.device.document())
|
||||
bindings::Gecko_nsStyleFont_ComputeMinSize(&**font, builder.device.document())
|
||||
};
|
||||
|
||||
if font.mFont.size.0 >= min_font_size {
|
||||
|
@ -1025,7 +1024,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
NonNegative(min_font_size)
|
||||
};
|
||||
|
||||
builder.mutate_font().gecko_mut().mFont.size = min_font_size;
|
||||
builder.mutate_font().mFont.size = min_font_size;
|
||||
}
|
||||
|
||||
/// <svg:text> is not affected by text zoom, and it uses a preshint to disable it. We fix up
|
||||
|
@ -1133,8 +1132,8 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
|
||||
let (new_size, new_unconstrained_size) = {
|
||||
let builder = &self.context.builder;
|
||||
let font = builder.get_font().gecko();
|
||||
let parent_font = builder.get_parent_font().gecko();
|
||||
let font = builder.get_font();
|
||||
let parent_font = builder.get_parent_font();
|
||||
|
||||
let delta = font.mMathDepth.saturating_sub(parent_font.mMathDepth);
|
||||
|
||||
|
@ -1195,7 +1194,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
)
|
||||
}
|
||||
};
|
||||
let font = self.context.builder.mutate_font().gecko_mut();
|
||||
let font = self.context.builder.mutate_font();
|
||||
font.mFont.size = NonNegative(new_size);
|
||||
font.mSize = NonNegative(new_size);
|
||||
font.mScriptUnconstrainedSize = NonNegative(new_unconstrained_size);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -401,7 +401,7 @@ pub mod system_font {
|
|||
bindings::Gecko_nsFont_InitSystem(
|
||||
system.as_mut_ptr(),
|
||||
*self,
|
||||
cx.style().get_font().gecko(),
|
||||
&**cx.style().get_font(),
|
||||
cx.device().document()
|
||||
);
|
||||
&mut *system.as_mut_ptr()
|
||||
|
|
|
@ -3098,14 +3098,9 @@ impl ComputedValues {
|
|||
self.rules.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// Returns the visited style, if any.
|
||||
pub fn visited_style(&self) -> Option<<&ComputedValues> {
|
||||
self.visited_style.as_deref()
|
||||
}
|
||||
|
||||
/// Returns the visited rules, if applicable.
|
||||
pub fn visited_rules(&self) -> Option<<&StrongRuleNode> {
|
||||
self.visited_style.as_ref().and_then(|s| s.rules.as_ref())
|
||||
self.visited_style().and_then(|s| s.rules.as_ref())
|
||||
}
|
||||
|
||||
/// Gets a reference to the custom properties map (if one exists).
|
||||
|
@ -3346,6 +3341,11 @@ impl ops::DerefMut for ComputedValues {
|
|||
|
||||
#[cfg(feature = "servo")]
|
||||
impl ComputedValuesInner {
|
||||
/// Returns the visited style, if any.
|
||||
pub fn visited_style(&self) -> Option<<&ComputedValues> {
|
||||
self.visited_style.as_deref()
|
||||
}
|
||||
|
||||
% for style_struct in data.active_style_structs():
|
||||
/// Clone the ${style_struct.name} struct.
|
||||
#[inline]
|
||||
|
@ -3359,12 +3359,6 @@ impl ComputedValuesInner {
|
|||
&self.${style_struct.ident}
|
||||
}
|
||||
|
||||
/// Gets an immutable reference to the refcounted value that wraps
|
||||
/// `${style_struct.name}`.
|
||||
pub fn ${style_struct.name_lower}_arc(&self) -> &Arc<style_structs::${style_struct.name}> {
|
||||
&self.${style_struct.ident}
|
||||
}
|
||||
|
||||
/// Get a mutable reference to the ${style_struct.name} struct.
|
||||
#[inline]
|
||||
pub fn mutate_${style_struct.name_lower}(&mut self) -> &mut style_structs::${style_struct.name} {
|
||||
|
@ -3563,24 +3557,10 @@ impl ComputedValuesInner {
|
|||
}
|
||||
}
|
||||
|
||||
% if engine == "gecko":
|
||||
pub use crate::servo_arc::RawOffsetArc as BuilderArc;
|
||||
/// Clone an arc, returning a regular arc
|
||||
fn clone_arc<T: 'static>(x: &BuilderArc<T>) -> Arc<T> {
|
||||
Arc::from_raw_offset(x.clone())
|
||||
}
|
||||
% else:
|
||||
pub use crate::servo_arc::Arc as BuilderArc;
|
||||
/// Clone an arc, returning a regular arc
|
||||
fn clone_arc<T: 'static>(x: &BuilderArc<T>) -> Arc<T> {
|
||||
x.clone()
|
||||
}
|
||||
% endif
|
||||
|
||||
/// A reference to a style struct of the parent, or our own style struct.
|
||||
pub enum StyleStructRef<'a, T: 'static> {
|
||||
/// A borrowed struct from the parent, for example, for inheriting style.
|
||||
Borrowed(&'a BuilderArc<T>),
|
||||
Borrowed(&'a T),
|
||||
/// An owned struct, that we've already mutated.
|
||||
Owned(UniqueArc<T>),
|
||||
/// Temporarily vacated, will panic if accessed
|
||||
|
@ -3595,7 +3575,7 @@ where
|
|||
/// borrowed value, or returning the owned one.
|
||||
pub fn mutate(&mut self) -> &mut T {
|
||||
if let StyleStructRef::Borrowed(v) = *self {
|
||||
*self = StyleStructRef::Owned(UniqueArc::new((**v).clone()));
|
||||
*self = StyleStructRef::Owned(UniqueArc::new(v.clone()));
|
||||
}
|
||||
|
||||
match *self {
|
||||
|
@ -3614,8 +3594,8 @@ where
|
|||
pub fn ptr_eq(&self, struct_to_copy_from: &T) -> bool {
|
||||
match *self {
|
||||
StyleStructRef::Owned(..) => false,
|
||||
StyleStructRef::Borrowed(arc) => {
|
||||
&**arc as *const T == struct_to_copy_from as *const T
|
||||
StyleStructRef::Borrowed(s) => {
|
||||
s as *const T == struct_to_copy_from as *const T
|
||||
}
|
||||
StyleStructRef::Vacated => panic!("Accessed vacated style struct")
|
||||
}
|
||||
|
@ -3632,7 +3612,7 @@ where
|
|||
|
||||
match inner {
|
||||
StyleStructRef::Owned(arc) => arc,
|
||||
StyleStructRef::Borrowed(arc) => UniqueArc::new((**arc).clone()),
|
||||
StyleStructRef::Borrowed(s) => UniqueArc::new(s.clone()),
|
||||
StyleStructRef::Vacated => panic!("Accessed vacated style struct"),
|
||||
}
|
||||
}
|
||||
|
@ -3658,7 +3638,8 @@ where
|
|||
pub fn build(self) -> Arc<T> {
|
||||
match self {
|
||||
StyleStructRef::Owned(v) => v.shareable(),
|
||||
StyleStructRef::Borrowed(v) => clone_arc(v),
|
||||
// SAFETY: We know all style structs are arc-allocated.
|
||||
StyleStructRef::Borrowed(v) => unsafe { Arc::from_raw_addrefed(v) },
|
||||
StyleStructRef::Vacated => panic!("Accessed vacated style struct")
|
||||
}
|
||||
}
|
||||
|
@ -3670,7 +3651,7 @@ impl<'a, T: 'a> ops::Deref for StyleStructRef<'a, T> {
|
|||
fn deref(&self) -> &T {
|
||||
match *self {
|
||||
StyleStructRef::Owned(ref v) => &**v,
|
||||
StyleStructRef::Borrowed(v) => &**v,
|
||||
StyleStructRef::Borrowed(v) => v,
|
||||
StyleStructRef::Vacated => panic!("Accessed vacated style struct")
|
||||
}
|
||||
}
|
||||
|
@ -3773,9 +3754,9 @@ impl<'a> StyleBuilder<'a> {
|
|||
visited_style: None,
|
||||
% for style_struct in data.active_style_structs():
|
||||
% if style_struct.inherited:
|
||||
${style_struct.ident}: StyleStructRef::Borrowed(inherited_style.${style_struct.name_lower}_arc()),
|
||||
${style_struct.ident}: StyleStructRef::Borrowed(inherited_style.get_${style_struct.name_lower}()),
|
||||
% else:
|
||||
${style_struct.ident}: StyleStructRef::Borrowed(reset_style.${style_struct.name_lower}_arc()),
|
||||
${style_struct.ident}: StyleStructRef::Borrowed(reset_style.get_${style_struct.name_lower}()),
|
||||
% endif
|
||||
% endfor
|
||||
}
|
||||
|
@ -3813,7 +3794,7 @@ impl<'a> StyleBuilder<'a> {
|
|||
visited_style: None,
|
||||
% for style_struct in data.active_style_structs():
|
||||
${style_struct.ident}: StyleStructRef::Borrowed(
|
||||
style_to_derive_from.${style_struct.name_lower}_arc()
|
||||
style_to_derive_from.get_${style_struct.name_lower}()
|
||||
),
|
||||
% endfor
|
||||
}
|
||||
|
@ -3824,7 +3805,7 @@ impl<'a> StyleBuilder<'a> {
|
|||
% for style_struct in data.active_style_structs():
|
||||
% if not style_struct.inherited:
|
||||
self.${style_struct.ident} =
|
||||
StyleStructRef::Borrowed(style.${style_struct.name_lower}_arc());
|
||||
StyleStructRef::Borrowed(style.get_${style_struct.name_lower}());
|
||||
% endif
|
||||
% endfor
|
||||
}
|
||||
|
@ -3991,7 +3972,7 @@ impl<'a> StyleBuilder<'a> {
|
|||
/// Reset the current `${style_struct.name}` style to its default value.
|
||||
pub fn reset_${style_struct.name_lower}_struct(&mut self) {
|
||||
self.${style_struct.ident} =
|
||||
StyleStructRef::Borrowed(self.reset_style.${style_struct.name_lower}_arc());
|
||||
StyleStructRef::Borrowed(self.reset_style.get_${style_struct.name_lower}());
|
||||
}
|
||||
% endfor
|
||||
<% del style_struct %>
|
||||
|
|
|
@ -775,13 +775,13 @@ impl FontSizeKeyword {
|
|||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
fn to_length(&self, cx: &Context) -> NonNegativeLength {
|
||||
let gecko_font = cx.style().get_font().gecko();
|
||||
let family = &gecko_font.mFont.family.families;
|
||||
let font = cx.style().get_font();
|
||||
let family = &font.mFont.family.families;
|
||||
let generic = family
|
||||
.single_generic()
|
||||
.unwrap_or(computed::GenericFontFamily::None);
|
||||
let base_size = unsafe {
|
||||
Atom::with(gecko_font.mLanguage.mRawPtr, |language| {
|
||||
Atom::with(font.mLanguage.mRawPtr, |language| {
|
||||
cx.device().base_size_for_generic(language, generic)
|
||||
})
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue