mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
style: Remove a couple trivial dependencies on nsPresContext.
Differential Revision: https://phabricator.services.mozilla.com/D20141
This commit is contained in:
parent
3231714758
commit
dcfe30ff18
9 changed files with 32 additions and 34 deletions
|
@ -461,7 +461,7 @@ fn eval_moz_is_glyph(
|
||||||
query_value: Option<bool>,
|
query_value: Option<bool>,
|
||||||
_: Option<RangeOrOperator>,
|
_: Option<RangeOrOperator>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let is_glyph = unsafe { (*device.document()).mIsSVGGlyphsDocument() };
|
let is_glyph = device.document().mIsSVGGlyphsDocument();
|
||||||
query_value.map_or(is_glyph, |v| v == is_glyph)
|
query_value.map_or(is_glyph, |v| v == is_glyph)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl Device {
|
||||||
assert!(!pres_context.is_null());
|
assert!(!pres_context.is_null());
|
||||||
Device {
|
Device {
|
||||||
pres_context,
|
pres_context,
|
||||||
default_values: ComputedValues::default_values(unsafe { &*pres_context }),
|
default_values: ComputedValues::default_values(unsafe { &*(*pres_context).mDocument.mRawPtr }),
|
||||||
// FIXME(bz): Seems dubious?
|
// FIXME(bz): Seems dubious?
|
||||||
root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize),
|
root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize),
|
||||||
body_text_color: AtomicUsize::new(unsafe { &*pres_context }.mDefaultColor as usize),
|
body_text_color: AtomicUsize::new(unsafe { &*pres_context }.mDefaultColor as usize),
|
||||||
|
@ -162,13 +162,13 @@ impl Device {
|
||||||
|
|
||||||
/// Gets the document pointer.
|
/// Gets the document pointer.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn document(&self) -> *mut structs::Document {
|
pub fn document(&self) -> &structs::Document {
|
||||||
self.pres_context().mDocument.mRawPtr
|
unsafe { &*self.pres_context().mDocument.mRawPtr }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recreates the default computed values.
|
/// Recreates the default computed values.
|
||||||
pub fn reset_computed_values(&mut self) {
|
pub fn reset_computed_values(&mut self) {
|
||||||
self.default_values = ComputedValues::default_values(self.pres_context());
|
self.default_values = ComputedValues::default_values(self.document());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rebuild all the cached data.
|
/// Rebuild all the cached data.
|
||||||
|
|
|
@ -10,7 +10,6 @@ use crate::counter_style::{Symbol, Symbols};
|
||||||
use crate::gecko_bindings::structs::{nsStyleCoord, CounterStylePtr};
|
use crate::gecko_bindings::structs::{nsStyleCoord, CounterStylePtr};
|
||||||
use crate::gecko_bindings::structs::{StyleGridTrackBreadth, StyleShapeRadius};
|
use crate::gecko_bindings::structs::{StyleGridTrackBreadth, StyleShapeRadius};
|
||||||
use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||||
use crate::media_queries::Device;
|
|
||||||
use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
|
use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
|
||||||
use crate::values::computed::{Angle, Length, LengthPercentage};
|
use crate::values::computed::{Angle, Length, LengthPercentage};
|
||||||
use crate::values::computed::{Number, NumberOrPercentage, Percentage};
|
use crate::values::computed::{Number, NumberOrPercentage, Percentage};
|
||||||
|
@ -387,16 +386,15 @@ pub fn round_border_to_device_pixels(width: Au, au_per_device_px: Au) -> Au {
|
||||||
|
|
||||||
impl CounterStyleOrNone {
|
impl CounterStyleOrNone {
|
||||||
/// Convert this counter style to a Gecko CounterStylePtr.
|
/// Convert this counter style to a Gecko CounterStylePtr.
|
||||||
pub fn to_gecko_value(self, gecko_value: &mut CounterStylePtr, device: &Device) {
|
pub fn to_gecko_value(self, gecko_value: &mut CounterStylePtr) {
|
||||||
use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToName as set_name;
|
use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToName as set_name;
|
||||||
use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToSymbols as set_symbols;
|
use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToSymbols as set_symbols;
|
||||||
let pres_context = device.pres_context();
|
|
||||||
match self {
|
match self {
|
||||||
CounterStyleOrNone::None => unsafe {
|
CounterStyleOrNone::None => unsafe {
|
||||||
set_name(gecko_value, atom!("none").into_addrefed(), pres_context);
|
set_name(gecko_value, atom!("none").into_addrefed());
|
||||||
},
|
},
|
||||||
CounterStyleOrNone::Name(name) => unsafe {
|
CounterStyleOrNone::Name(name) => unsafe {
|
||||||
set_name(gecko_value, name.0.into_addrefed(), pres_context);
|
set_name(gecko_value, name.0.into_addrefed());
|
||||||
},
|
},
|
||||||
CounterStyleOrNone::Symbols(symbols_type, symbols) => {
|
CounterStyleOrNone::Symbols(symbols_type, symbols) => {
|
||||||
let symbols: Vec<_> = symbols
|
let symbols: Vec<_> = symbols
|
||||||
|
|
|
@ -745,13 +745,13 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
||||||
|
|
||||||
// FIXME(emilio): Why both setting the generic and passing it
|
// FIXME(emilio): Why both setting the generic and passing it
|
||||||
// down?
|
// down?
|
||||||
let pres_context = self.context.builder.device.pres_context();
|
let doc = self.context.builder.device.document();
|
||||||
let gecko_font = self.context.builder.mutate_font().gecko_mut();
|
let gecko_font = self.context.builder.mutate_font().gecko_mut();
|
||||||
gecko_font.mGenericID = generic;
|
gecko_font.mGenericID = generic;
|
||||||
unsafe {
|
unsafe {
|
||||||
crate::gecko_bindings::bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric(
|
crate::gecko_bindings::bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric(
|
||||||
gecko_font,
|
gecko_font,
|
||||||
pres_context,
|
doc,
|
||||||
generic,
|
generic,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,6 @@ use crate::gecko_bindings::bindings::Gecko_SetListStyleImageNone;
|
||||||
use crate::gecko_bindings::bindings::Gecko_SetListStyleImageImageValue;
|
use crate::gecko_bindings::bindings::Gecko_SetListStyleImageImageValue;
|
||||||
use crate::gecko_bindings::bindings::Gecko_SetNullImageValue;
|
use crate::gecko_bindings::bindings::Gecko_SetNullImageValue;
|
||||||
use crate::gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
|
use crate::gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
|
||||||
use crate::gecko_bindings::bindings::RawGeckoPresContextBorrowed;
|
|
||||||
use crate::gecko_bindings::structs;
|
use crate::gecko_bindings::structs;
|
||||||
use crate::gecko_bindings::structs::nsCSSPropertyID;
|
use crate::gecko_bindings::structs::nsCSSPropertyID;
|
||||||
use crate::gecko_bindings::structs::mozilla::PseudoStyleType;
|
use crate::gecko_bindings::structs::mozilla::PseudoStyleType;
|
||||||
|
@ -102,7 +101,7 @@ impl ComputedValues {
|
||||||
).to_outer(pseudo)
|
).to_outer(pseudo)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
|
pub fn default_values(doc: &structs::Document) -> Arc<Self> {
|
||||||
ComputedValuesInner::new(
|
ComputedValuesInner::new(
|
||||||
/* custom_properties = */ None,
|
/* custom_properties = */ None,
|
||||||
/* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious
|
/* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious
|
||||||
|
@ -110,7 +109,7 @@ impl ComputedValues {
|
||||||
/* rules = */ None,
|
/* rules = */ None,
|
||||||
/* visited_style = */ None,
|
/* visited_style = */ None,
|
||||||
% for style_struct in data.style_structs:
|
% for style_struct in data.style_structs:
|
||||||
style_structs::${style_struct.name}::default(pres_context),
|
style_structs::${style_struct.name}::default(doc),
|
||||||
% endfor
|
% endfor
|
||||||
).to_outer(None)
|
).to_outer(None)
|
||||||
}
|
}
|
||||||
|
@ -1247,11 +1246,13 @@ pub fn clone_transform_from_list(
|
||||||
<%def name="impl_style_struct(style_struct)">
|
<%def name="impl_style_struct(style_struct)">
|
||||||
impl ${style_struct.gecko_struct_name} {
|
impl ${style_struct.gecko_struct_name} {
|
||||||
#[allow(dead_code, unused_variables)]
|
#[allow(dead_code, unused_variables)]
|
||||||
pub fn default(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
|
pub fn default(document: &structs::Document) -> Arc<Self> {
|
||||||
let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } });
|
let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } });
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_Construct_Default_${style_struct.gecko_ffi_name}(&mut Arc::get_mut(&mut result).unwrap().gecko,
|
Gecko_Construct_Default_${style_struct.gecko_ffi_name}(
|
||||||
pres_context);
|
&mut Arc::get_mut(&mut result).unwrap().gecko,
|
||||||
|
document,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -2199,7 +2200,7 @@ fn static_assert() {
|
||||||
pub fn fixup_none_generic(&mut self, device: &Device) {
|
pub fn fixup_none_generic(&mut self, device: &Device) {
|
||||||
self.gecko.mFont.systemFont = false;
|
self.gecko.mFont.systemFont = false;
|
||||||
unsafe {
|
unsafe {
|
||||||
bindings::Gecko_nsStyleFont_FixupNoneGeneric(&mut self.gecko, device.pres_context())
|
bindings::Gecko_nsStyleFont_FixupNoneGeneric(&mut self.gecko, device.document())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2315,7 +2316,7 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fixup_font_min_size(&mut self, device: &Device) {
|
pub fn fixup_font_min_size(&mut self, device: &Device) {
|
||||||
unsafe { bindings::Gecko_nsStyleFont_FixupMinFontSize(&mut self.gecko, device.pres_context()) }
|
unsafe { bindings::Gecko_nsStyleFont_FixupMinFontSize(&mut self.gecko, device.document()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_unconstrained_font_size(&mut self, v: NonNegativeLength) {
|
pub fn apply_unconstrained_font_size(&mut self, v: NonNegativeLength) {
|
||||||
|
@ -2637,9 +2638,11 @@ fn static_assert() {
|
||||||
${impl_simple("_moz_script_level", "mScriptLevel")}
|
${impl_simple("_moz_script_level", "mScriptLevel")}
|
||||||
<% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %>
|
<% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %>
|
||||||
|
|
||||||
pub fn set_font_variant_alternates(&mut self,
|
pub fn set_font_variant_alternates(
|
||||||
|
&mut self,
|
||||||
v: values::computed::font::FontVariantAlternates,
|
v: values::computed::font::FontVariantAlternates,
|
||||||
device: &Device) {
|
device: &Device,
|
||||||
|
) {
|
||||||
use crate::gecko_bindings::bindings::{Gecko_ClearAlternateValues, Gecko_AppendAlternateValues};
|
use crate::gecko_bindings::bindings::{Gecko_ClearAlternateValues, Gecko_AppendAlternateValues};
|
||||||
use crate::gecko_bindings::bindings::Gecko_nsFont_ResetFontFeatureValuesLookup;
|
use crate::gecko_bindings::bindings::Gecko_nsFont_ResetFontFeatureValuesLookup;
|
||||||
use crate::gecko_bindings::bindings::Gecko_nsFont_SetFontFeatureValuesLookup;
|
use crate::gecko_bindings::bindings::Gecko_nsFont_SetFontFeatureValuesLookup;
|
||||||
|
@ -3953,12 +3956,12 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_list_style_type(&mut self, v: longhands::list_style_type::computed_value::T, device: &Device) {
|
pub fn set_list_style_type(&mut self, v: longhands::list_style_type::computed_value::T) {
|
||||||
use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToString;
|
use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToString;
|
||||||
use nsstring::{nsACString, nsCStr};
|
use nsstring::{nsACString, nsCStr};
|
||||||
use self::longhands::list_style_type::computed_value::T;
|
use self::longhands::list_style_type::computed_value::T;
|
||||||
match v {
|
match v {
|
||||||
T::CounterStyle(s) => s.to_gecko_value(&mut self.gecko.mCounterStyle, device),
|
T::CounterStyle(s) => s.to_gecko_value(&mut self.gecko.mCounterStyle),
|
||||||
T::String(s) => unsafe {
|
T::String(s) => unsafe {
|
||||||
Gecko_SetCounterStyleToString(&mut self.gecko.mCounterStyle,
|
Gecko_SetCounterStyleToString(&mut self.gecko.mCounterStyle,
|
||||||
&nsCStr::from(&s) as &nsACString)
|
&nsCStr::from(&s) as &nsACString)
|
||||||
|
@ -5200,7 +5203,7 @@ clip-path
|
||||||
self.gecko.mContents.is_empty()
|
self.gecko.mContents.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_content(&mut self, v: longhands::content::computed_value::T, device: &Device) {
|
pub fn set_content(&mut self, v: longhands::content::computed_value::T) {
|
||||||
use crate::values::CustomIdent;
|
use crate::values::CustomIdent;
|
||||||
use crate::values::generics::counters::{Content, ContentItem};
|
use crate::values::generics::counters::{Content, ContentItem};
|
||||||
use crate::values::generics::CounterStyleOrNone;
|
use crate::values::generics::CounterStyleOrNone;
|
||||||
|
@ -5225,7 +5228,6 @@ clip-path
|
||||||
name: &CustomIdent,
|
name: &CustomIdent,
|
||||||
sep: &str,
|
sep: &str,
|
||||||
style: CounterStyleOrNone,
|
style: CounterStyleOrNone,
|
||||||
device: &Device,
|
|
||||||
) {
|
) {
|
||||||
debug_assert!(content_type == StyleContentType::Counter ||
|
debug_assert!(content_type == StyleContentType::Counter ||
|
||||||
content_type == StyleContentType::Counters);
|
content_type == StyleContentType::Counters);
|
||||||
|
@ -5236,7 +5238,7 @@ clip-path
|
||||||
if content_type == StyleContentType::Counters {
|
if content_type == StyleContentType::Counters {
|
||||||
counter_func.mSeparator.assign_str(sep);
|
counter_func.mSeparator.assign_str(sep);
|
||||||
}
|
}
|
||||||
style.to_gecko_value(&mut counter_func.mCounterStyle, device);
|
style.to_gecko_value(&mut counter_func.mCounterStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
match v {
|
match v {
|
||||||
|
@ -5311,7 +5313,6 @@ clip-path
|
||||||
&name,
|
&name,
|
||||||
"",
|
"",
|
||||||
style.clone(),
|
style.clone(),
|
||||||
device,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ContentItem::Counters(ref name, ref sep, ref style) => {
|
ContentItem::Counters(ref name, ref sep, ref style) => {
|
||||||
|
@ -5321,7 +5322,6 @@ clip-path
|
||||||
&name,
|
&name,
|
||||||
&sep,
|
&sep,
|
||||||
style.clone(),
|
style.clone(),
|
||||||
device,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ContentItem::Url(ref url) => {
|
ContentItem::Url(ref url) => {
|
||||||
|
|
|
@ -98,7 +98,7 @@ pub mod system_colors {
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_GetLookAndFeelSystemColor(
|
Gecko_GetLookAndFeelSystemColor(
|
||||||
*self as i32,
|
*self as i32,
|
||||||
cx.device().pres_context(),
|
cx.device().document(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,7 +396,7 @@ ${helpers.predefined_type(
|
||||||
&mut system,
|
&mut system,
|
||||||
id as i32,
|
id as i32,
|
||||||
cx.style().get_font().gecko(),
|
cx.style().get_font().gecko(),
|
||||||
cx.device().pres_context()
|
cx.device().document()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
let font_weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
let font_weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
||||||
|
|
|
@ -3507,7 +3507,7 @@ impl<'a> StyleBuilder<'a> {
|
||||||
self.modified_reset = true;
|
self.modified_reset = true;
|
||||||
% endif
|
% endif
|
||||||
|
|
||||||
<% props_need_device = ["content", "list_style_type", "font_variant_alternates"] %>
|
<% props_need_device = ["font_variant_alternates"] %>
|
||||||
self.${property.style_struct.ident}.mutate()
|
self.${property.style_struct.ident}.mutate()
|
||||||
.set_${property.ident}(
|
.set_${property.ident}(
|
||||||
value,
|
value,
|
||||||
|
|
|
@ -198,7 +198,7 @@ impl DocumentMatchingFunction {
|
||||||
MediaDocumentKind::Video => "video",
|
MediaDocumentKind::Video => "video",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
unsafe { Gecko_DocumentRule_UseForPresentation(device.pres_context(), &*pattern, func) }
|
unsafe { Gecko_DocumentRule_UseForPresentation(device.document(), &*pattern, func) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "gecko"))]
|
#[cfg(not(feature = "gecko"))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue