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,
}
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 Send for Device {}

View file

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

View file

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

View file

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