style: Better debugging for media-query related code and ua-cache.

Bug: 1470145
Reviewed-by: xidorn
MozReview-Commit-ID: 3XHAxK2BOTS
This commit is contained in:
Emilio Cobos Álvarez 2018-06-21 15:19:48 +02:00
parent f564b32b75
commit 82db42390d
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 49 additions and 11 deletions

View file

@ -64,6 +64,27 @@ pub struct Device {
used_viewport_size: AtomicBool, used_viewport_size: AtomicBool,
} }
impl fmt::Debug for Device {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use nsstring::nsCString;
let mut doc_uri = nsCString::new();
unsafe {
let doc =
&*self.pres_context().mDocument.raw::<structs::nsIDocument>();
bindings::Gecko_nsIURI_Debug(
doc.mDocumentURI.raw::<structs::nsIURI>(),
&mut doc_uri,
)
};
f.debug_struct("Device")
.field("document_url", &doc_uri)
.finish()
}
}
unsafe impl Sync for Device {} unsafe impl Sync for Device {}
unsafe impl Send for Device {} unsafe impl Send for Device {}

View file

@ -14,8 +14,8 @@ use parser::ParserContext;
use super::{Device, MediaQuery, Qualifier}; use super::{Device, MediaQuery, Qualifier};
/// A type that encapsulates a media query list. /// A type that encapsulates a media query list.
#[css(comma)] #[css(comma, derive_debug)]
#[derive(Clone, Debug, MallocSizeOf, ToCss)] #[derive(Clone, MallocSizeOf, ToCss)]
pub struct MediaList { pub struct MediaList {
/// The list of media queries. /// The list of media queries.
#[css(iterable)] #[css(iterable)]

View file

@ -75,6 +75,10 @@ impl UserAgentCascadeDataCache {
Self { entries: vec![] } Self { entries: vec![] }
} }
fn len(&self) -> usize {
self.entries.len()
}
// FIXME(emilio): This may need to be keyed on quirks-mode too, though there // FIXME(emilio): This may need to be keyed on quirks-mode too, though there
// aren't class / id selectors on those sheets, usually, so it's probably // aren't class / id selectors on those sheets, usually, so it's probably
// ok... // ok...
@ -90,6 +94,7 @@ impl UserAgentCascadeDataCache {
S: StylesheetInDocument + ToMediaListKey + PartialEq + 'static, S: StylesheetInDocument + ToMediaListKey + PartialEq + 'static,
{ {
let mut key = EffectiveMediaQueryResults::new(); let mut key = EffectiveMediaQueryResults::new();
debug!("UserAgentCascadeDataCache::lookup({:?})", device);
for sheet in sheets.clone() { for sheet in sheets.clone() {
CascadeData::collect_applicable_media_query_results_into(device, sheet, guard, &mut key) CascadeData::collect_applicable_media_query_results_into(device, sheet, guard, &mut key)
} }
@ -105,6 +110,8 @@ impl UserAgentCascadeDataCache {
precomputed_pseudo_element_decls: PrecomputedPseudoElementDeclarations::default(), precomputed_pseudo_element_decls: PrecomputedPseudoElementDeclarations::default(),
}; };
debug!("> Picking the slow path");
for sheet in sheets { for sheet in sheets {
new_data.cascade_data.add_stylesheet( new_data.cascade_data.add_stylesheet(
device, device,
@ -117,7 +124,6 @@ impl UserAgentCascadeDataCache {
} }
let new_data = Arc::new(new_data); let new_data = Arc::new(new_data);
self.entries.push(new_data.clone()); self.entries.push(new_data.clone());
Ok(new_data) Ok(new_data)
} }
@ -244,8 +250,8 @@ impl DocumentCascadeData {
let origin_sheets = flusher.origin_sheets(Origin::UserAgent); let origin_sheets = flusher.origin_sheets(Origin::UserAgent);
let ua_cascade_data = let ua_cascade_data =
ua_cache.lookup(origin_sheets, device, quirks_mode, guards.ua_or_user)?; ua_cache.lookup(origin_sheets, device, quirks_mode, guards.ua_or_user)?;
ua_cache.expire_unused(); ua_cache.expire_unused();
debug!("User agent data cache size {:?}", ua_cache.len());
self.user_agent = ua_cascade_data; self.user_agent = ua_cascade_data;
} }
} }
@ -1085,7 +1091,7 @@ impl Stylist {
guards: &StylesheetGuards, guards: &StylesheetGuards,
device: &Device, device: &Device,
) -> OriginSet { ) -> OriginSet {
debug!("Stylist::media_features_change_changed_style"); debug!("Stylist::media_features_change_changed_style {:?}", device);
let mut origins = OriginSet::empty(); let mut origins = OriginSet::empty();
let stylesheets = self.stylesheets.iter(); let stylesheets = self.stylesheets.iter();
@ -2145,16 +2151,19 @@ impl CascadeData {
return; return;
} }
debug!(" + {:?}", stylesheet);
results.saw_effective(stylesheet); results.saw_effective(stylesheet);
for rule in stylesheet.effective_rules(device, guard) { for rule in stylesheet.effective_rules(device, guard) {
match *rule { match *rule {
CssRule::Import(ref lock) => { CssRule::Import(ref lock) => {
let import_rule = lock.read_with(guard); let import_rule = lock.read_with(guard);
debug!(" + {:?}", import_rule.stylesheet.media(guard));
results.saw_effective(import_rule); results.saw_effective(import_rule);
}, },
CssRule::Media(ref lock) => { CssRule::Media(ref lock) => {
let media_rule = lock.read_with(guard); let media_rule = lock.read_with(guard);
debug!(" + {:?}", media_rule.media_queries.read_with(guard));
results.saw_effective(media_rule); results.saw_effective(media_rule);
}, },
_ => {}, _ => {},
@ -2346,8 +2355,10 @@ impl CascadeData {
if effective_now != effective_then { if effective_now != effective_then {
debug!( debug!(
" > Stylesheet changed -> {}, {}", " > Stylesheet {:?} changed -> {}, {}",
effective_then, effective_now stylesheet.media(guard),
effective_then,
effective_now
); );
return false; return false;
} }
@ -2382,8 +2393,10 @@ impl CascadeData {
.was_effective(import_rule); .was_effective(import_rule);
if effective_now != effective_then { if effective_now != effective_then {
debug!( debug!(
" > @import rule changed {} -> {}", " > @import rule {:?} changed {} -> {}",
effective_then, effective_now import_rule.stylesheet.media(guard),
effective_then,
effective_now
); );
return false; return false;
} }
@ -2401,8 +2414,10 @@ impl CascadeData {
if effective_now != effective_then { if effective_now != effective_then {
debug!( debug!(
" > @media rule changed {} -> {}", " > @media rule {:?} changed {} -> {}",
effective_then, effective_now mq,
effective_then,
effective_now
); );
return false; return false;
} }

View file

@ -231,6 +231,8 @@ pub struct CssInputAttrs {
#[derive(Default, FromVariant)] #[derive(Default, FromVariant)]
pub struct CssVariantAttrs { pub struct CssVariantAttrs {
pub function: Option<Override<String>>, pub function: Option<Override<String>>,
// Here because structs variants are also their whole type definition.
pub derive_debug: bool,
pub comma: bool, pub comma: bool,
pub dimension: bool, pub dimension: bool,
pub keyword: Option<String>, pub keyword: Option<String>,