From dcfe30ff18d1ab282d7de724e5609c517765b877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 19 Feb 2019 11:17:28 +0000 Subject: [PATCH] style: Remove a couple trivial dependencies on nsPresContext. Differential Revision: https://phabricator.services.mozilla.com/D20141 --- components/style/gecko/media_features.rs | 2 +- components/style/gecko/media_queries.rs | 8 ++--- components/style/gecko/values.rs | 8 ++--- components/style/properties/cascade.rs | 4 +-- components/style/properties/gecko.mako.rs | 36 +++++++++---------- .../style/properties/longhands/color.mako.rs | 2 +- .../style/properties/longhands/font.mako.rs | 2 +- .../style/properties/properties.mako.rs | 2 +- components/style/stylesheets/document_rule.rs | 2 +- 9 files changed, 32 insertions(+), 34 deletions(-) diff --git a/components/style/gecko/media_features.rs b/components/style/gecko/media_features.rs index 24f2009a3a8..2547f2a45d4 100644 --- a/components/style/gecko/media_features.rs +++ b/components/style/gecko/media_features.rs @@ -461,7 +461,7 @@ fn eval_moz_is_glyph( query_value: Option, _: Option, ) -> bool { - let is_glyph = unsafe { (*device.document()).mIsSVGGlyphsDocument() }; + let is_glyph = device.document().mIsSVGGlyphsDocument(); query_value.map_or(is_glyph, |v| v == is_glyph) } diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 851422467ce..6d509cf6903 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -85,7 +85,7 @@ impl Device { assert!(!pres_context.is_null()); Device { pres_context, - default_values: ComputedValues::default_values(unsafe { &*pres_context }), + default_values: ComputedValues::default_values(unsafe { &*(*pres_context).mDocument.mRawPtr }), // FIXME(bz): Seems dubious? root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize), body_text_color: AtomicUsize::new(unsafe { &*pres_context }.mDefaultColor as usize), @@ -162,13 +162,13 @@ impl Device { /// Gets the document pointer. #[inline] - pub fn document(&self) -> *mut structs::Document { - self.pres_context().mDocument.mRawPtr + pub fn document(&self) -> &structs::Document { + unsafe { &*self.pres_context().mDocument.mRawPtr } } /// Recreates the default computed values. 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. diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 8aad380ab44..56f0ed4464d 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -10,7 +10,6 @@ use crate::counter_style::{Symbol, Symbols}; use crate::gecko_bindings::structs::{nsStyleCoord, CounterStylePtr}; use crate::gecko_bindings::structs::{StyleGridTrackBreadth, StyleShapeRadius}; 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::{Angle, Length, LengthPercentage}; 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 { /// 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_SetCounterStyleToSymbols as set_symbols; - let pres_context = device.pres_context(); match self { 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 { - set_name(gecko_value, name.0.into_addrefed(), pres_context); + set_name(gecko_value, name.0.into_addrefed()); }, CounterStyleOrNone::Symbols(symbols_type, symbols) => { let symbols: Vec<_> = symbols diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index c07f5255923..4a0e07fdcac 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -745,13 +745,13 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { // FIXME(emilio): Why both setting the generic and passing it // 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(); gecko_font.mGenericID = generic; unsafe { crate::gecko_bindings::bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric( gecko_font, - pres_context, + doc, generic, ); } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index a920042d08f..db7824c5f39 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -35,7 +35,6 @@ use crate::gecko_bindings::bindings::Gecko_SetListStyleImageNone; use crate::gecko_bindings::bindings::Gecko_SetListStyleImageImageValue; use crate::gecko_bindings::bindings::Gecko_SetNullImageValue; 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::nsCSSPropertyID; use crate::gecko_bindings::structs::mozilla::PseudoStyleType; @@ -102,7 +101,7 @@ impl ComputedValues { ).to_outer(pseudo) } - pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc { + pub fn default_values(doc: &structs::Document) -> Arc { ComputedValuesInner::new( /* custom_properties = */ None, /* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious @@ -110,7 +109,7 @@ impl ComputedValues { /* rules = */ None, /* visited_style = */ None, % for style_struct in data.style_structs: - style_structs::${style_struct.name}::default(pres_context), + style_structs::${style_struct.name}::default(doc), % endfor ).to_outer(None) } @@ -1247,11 +1246,13 @@ pub fn clone_transform_from_list( <%def name="impl_style_struct(style_struct)"> impl ${style_struct.gecko_struct_name} { #[allow(dead_code, unused_variables)] - pub fn default(pres_context: RawGeckoPresContextBorrowed) -> Arc { + pub fn default(document: &structs::Document) -> Arc { 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); + Gecko_Construct_Default_${style_struct.gecko_ffi_name}( + &mut Arc::get_mut(&mut result).unwrap().gecko, + document, + ); } result } @@ -2199,7 +2200,7 @@ fn static_assert() { pub fn fixup_none_generic(&mut self, device: &Device) { self.gecko.mFont.systemFont = false; 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) { - 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) { @@ -2637,9 +2638,11 @@ fn static_assert() { ${impl_simple("_moz_script_level", "mScriptLevel")} <% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %> - pub fn set_font_variant_alternates(&mut self, - v: values::computed::font::FontVariantAlternates, - device: &Device) { + pub fn set_font_variant_alternates( + &mut self, + v: values::computed::font::FontVariantAlternates, + device: &Device, + ) { use crate::gecko_bindings::bindings::{Gecko_ClearAlternateValues, Gecko_AppendAlternateValues}; use crate::gecko_bindings::bindings::Gecko_nsFont_ResetFontFeatureValuesLookup; 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 nsstring::{nsACString, nsCStr}; use self::longhands::list_style_type::computed_value::T; 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 { Gecko_SetCounterStyleToString(&mut self.gecko.mCounterStyle, &nsCStr::from(&s) as &nsACString) @@ -5200,7 +5203,7 @@ clip-path 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::generics::counters::{Content, ContentItem}; use crate::values::generics::CounterStyleOrNone; @@ -5225,7 +5228,6 @@ clip-path name: &CustomIdent, sep: &str, style: CounterStyleOrNone, - device: &Device, ) { debug_assert!(content_type == StyleContentType::Counter || content_type == StyleContentType::Counters); @@ -5236,7 +5238,7 @@ clip-path if content_type == StyleContentType::Counters { 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 { @@ -5311,7 +5313,6 @@ clip-path &name, "", style.clone(), - device, ); } ContentItem::Counters(ref name, ref sep, ref style) => { @@ -5321,7 +5322,6 @@ clip-path &name, &sep, style.clone(), - device, ); } ContentItem::Url(ref url) => { diff --git a/components/style/properties/longhands/color.mako.rs b/components/style/properties/longhands/color.mako.rs index 13b1fda545c..487814935aa 100644 --- a/components/style/properties/longhands/color.mako.rs +++ b/components/style/properties/longhands/color.mako.rs @@ -98,7 +98,7 @@ pub mod system_colors { unsafe { Gecko_GetLookAndFeelSystemColor( *self as i32, - cx.device().pres_context(), + cx.device().document(), ) } } diff --git a/components/style/properties/longhands/font.mako.rs b/components/style/properties/longhands/font.mako.rs index 755797711e1..047ec90c480 100644 --- a/components/style/properties/longhands/font.mako.rs +++ b/components/style/properties/longhands/font.mako.rs @@ -396,7 +396,7 @@ ${helpers.predefined_type( &mut system, id as i32, 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); diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 8e5dc02d6b9..727f5293fd5 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -3507,7 +3507,7 @@ impl<'a> StyleBuilder<'a> { self.modified_reset = true; % endif - <% props_need_device = ["content", "list_style_type", "font_variant_alternates"] %> + <% props_need_device = ["font_variant_alternates"] %> self.${property.style_struct.ident}.mutate() .set_${property.ident}( value, diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 4813a0e9150..c73b96bcd9d 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -198,7 +198,7 @@ impl DocumentMatchingFunction { MediaDocumentKind::Video => "video", }, }); - unsafe { Gecko_DocumentRule_UseForPresentation(device.pres_context(), &*pattern, func) } + unsafe { Gecko_DocumentRule_UseForPresentation(device.document(), &*pattern, func) } } #[cfg(not(feature = "gecko"))]