mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Better debugging for stylesheets and URLs.
Bug: 1470145 Reviewed-by: xidorn MozReview-Commit-ID: FIcz2K1ZYX0
This commit is contained in:
parent
46e572a497
commit
f564b32b75
6 changed files with 63 additions and 28 deletions
|
@ -7,7 +7,6 @@
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
use cssparser::{BasicParseErrorKind, ParseErrorKind, SourceLocation, Token};
|
use cssparser::{BasicParseErrorKind, ParseErrorKind, SourceLocation, Token};
|
||||||
use log;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ParseError;
|
use style_traits::ParseError;
|
||||||
use stylesheets::UrlExtraData;
|
use stylesheets::UrlExtraData;
|
||||||
|
@ -229,8 +228,10 @@ pub trait ParseErrorReporter {
|
||||||
/// This logging is silent by default, and can be enabled with a `RUST_LOG=style=info`
|
/// This logging is silent by default, and can be enabled with a `RUST_LOG=style=info`
|
||||||
/// environment variable.
|
/// environment variable.
|
||||||
/// (See [`env_logger`](https://rust-lang-nursery.github.io/log/env_logger/).)
|
/// (See [`env_logger`](https://rust-lang-nursery.github.io/log/env_logger/).)
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
pub struct RustLogReporter;
|
pub struct RustLogReporter;
|
||||||
|
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
impl ParseErrorReporter for RustLogReporter {
|
impl ParseErrorReporter for RustLogReporter {
|
||||||
fn report_error(
|
fn report_error(
|
||||||
&self,
|
&self,
|
||||||
|
@ -238,6 +239,7 @@ impl ParseErrorReporter for RustLogReporter {
|
||||||
location: SourceLocation,
|
location: SourceLocation,
|
||||||
error: ContextualParseError,
|
error: ContextualParseError,
|
||||||
) {
|
) {
|
||||||
|
use log;
|
||||||
if log_enabled!(log::Level::Info) {
|
if log_enabled!(log::Level::Info) {
|
||||||
info!(
|
info!(
|
||||||
"Url:\t{}\n{}:{} {}",
|
"Url:\t{}\n{}:{} {}",
|
||||||
|
|
|
@ -17,14 +17,25 @@ use media_queries::{Device, MediaList};
|
||||||
use properties::ComputedValues;
|
use properties::ComputedValues;
|
||||||
use selector_parser::SnapshotMap;
|
use selector_parser::SnapshotMap;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
|
use std::fmt;
|
||||||
use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards};
|
use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards};
|
||||||
use stylesheets::{CssRule, Origin, StylesheetContents, StylesheetInDocument};
|
use stylesheets::{CssRule, Origin, StylesheetContents, StylesheetInDocument};
|
||||||
use stylist::Stylist;
|
use stylist::Stylist;
|
||||||
|
|
||||||
/// Little wrapper to a Gecko style sheet.
|
/// Little wrapper to a Gecko style sheet.
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Eq, PartialEq)]
|
||||||
pub struct GeckoStyleSheet(*const DomStyleSheet);
|
pub struct GeckoStyleSheet(*const DomStyleSheet);
|
||||||
|
|
||||||
|
impl fmt::Debug for GeckoStyleSheet {
|
||||||
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
let contents = self.contents();
|
||||||
|
formatter.debug_struct("GeckoStyleSheet")
|
||||||
|
.field("origin", &contents.origin)
|
||||||
|
.field("url_data", &*contents.url_data.read())
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ToMediaListKey for ::gecko::data::GeckoStyleSheet {
|
impl ToMediaListKey for ::gecko::data::GeckoStyleSheet {
|
||||||
fn to_media_list_key(&self) -> MediaListKey {
|
fn to_media_list_key(&self) -> MediaListKey {
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use gecko_bindings::bindings;
|
use gecko_bindings::bindings;
|
||||||
use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
|
use gecko_bindings::structs::ServoBundledURI;
|
||||||
use gecko_bindings::structs::mozilla::css::URLValueData;
|
use gecko_bindings::structs::mozilla::css::URLValueData;
|
||||||
use gecko_bindings::structs::root::{RustString, nsStyleImageRequest};
|
use gecko_bindings::structs::root::{RustString, nsStyleImageRequest};
|
||||||
use gecko_bindings::structs::root::mozilla::css::{ImageValue, URLValue};
|
use gecko_bindings::structs::root::mozilla::css::{ImageValue, URLValue};
|
||||||
|
@ -17,6 +17,7 @@ use parser::{Parse, ParserContext};
|
||||||
use servo_arc::{Arc, RawOffsetArc};
|
use servo_arc::{Arc, RawOffsetArc};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use stylesheets::UrlExtraData;
|
||||||
use style_traits::{CssWriter, ParseError, ToCss};
|
use style_traits::{CssWriter, ParseError, ToCss};
|
||||||
use values::computed::{Context, ToComputedValue};
|
use values::computed::{Context, ToComputedValue};
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ pub struct CssUrl {
|
||||||
|
|
||||||
/// The URL extra data.
|
/// The URL extra data.
|
||||||
#[css(skip)]
|
#[css(skip)]
|
||||||
pub extra_data: RefPtr<URLExtraData>,
|
pub extra_data: UrlExtraData,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CssUrl {
|
impl CssUrl {
|
||||||
|
@ -58,7 +59,7 @@ impl CssUrl {
|
||||||
&url.mString as *const _ as *const RawOffsetArc<String>;
|
&url.mString as *const _ as *const RawOffsetArc<String>;
|
||||||
CssUrl {
|
CssUrl {
|
||||||
serialization: Arc::from_raw_offset((*arc_type).clone()),
|
serialization: Arc::from_raw_offset((*arc_type).clone()),
|
||||||
extra_data: url.mExtraData.to_safe(),
|
extra_data: UrlExtraData(url.mExtraData.to_safe()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ impl CssUrl {
|
||||||
let arc_offset = Arc::into_raw_offset(self.serialization.clone());
|
let arc_offset = Arc::into_raw_offset(self.serialization.clone());
|
||||||
ServoBundledURI {
|
ServoBundledURI {
|
||||||
mURLString: unsafe { mem::transmute::<_, RawOffsetArc<RustString>>(arc_offset) },
|
mURLString: unsafe { mem::transmute::<_, RawOffsetArc<RustString>>(arc_offset) },
|
||||||
mExtraData: self.extra_data.get(),
|
mExtraData: self.extra_data.0.get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,15 +78,6 @@ impl<T: RefCounted> RefPtr<T> {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a reference to RefPtr from a reference to pointer.
|
|
||||||
///
|
|
||||||
/// The pointer must be valid and non null.
|
|
||||||
///
|
|
||||||
/// This method doesn't touch refcount.
|
|
||||||
pub unsafe fn from_ptr_ref(ptr: &*mut T) -> &Self {
|
|
||||||
mem::transmute(ptr)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Produces an FFI-compatible RefPtr that can be stored in style structs.
|
/// Produces an FFI-compatible RefPtr that can be stored in style structs.
|
||||||
///
|
///
|
||||||
/// structs::RefPtr does not have a destructor, so this may leak
|
/// structs::RefPtr does not have a destructor, so this may leak
|
||||||
|
|
|
@ -61,22 +61,52 @@ pub type UrlExtraData = ::servo_url::ServoUrl;
|
||||||
|
|
||||||
/// Extra data that the backend may need to resolve url values.
|
/// Extra data that the backend may need to resolve url values.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub type UrlExtraData =
|
#[derive(Clone, PartialEq)]
|
||||||
::gecko_bindings::sugar::refptr::RefPtr<::gecko_bindings::structs::URLExtraData>;
|
pub struct UrlExtraData(
|
||||||
|
pub ::gecko_bindings::sugar::refptr::RefPtr<::gecko_bindings::structs::URLExtraData>
|
||||||
|
);
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl UrlExtraData {
|
impl UrlExtraData {
|
||||||
/// Returns a string for the url.
|
/// True if this URL scheme is chrome.
|
||||||
///
|
#[inline]
|
||||||
/// Unimplemented currently.
|
pub fn is_chrome(&self) -> bool {
|
||||||
pub fn as_str(&self) -> &str {
|
self.0.mIsChrome
|
||||||
// TODO
|
|
||||||
"(stylo: not supported)"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// True if this URL scheme is chrome.
|
/// Create a reference to this `UrlExtraData` from a reference to pointer.
|
||||||
pub fn is_chrome(&self) -> bool {
|
///
|
||||||
self.mIsChrome
|
/// The pointer must be valid and non null.
|
||||||
|
///
|
||||||
|
/// This method doesn't touch refcount.
|
||||||
|
#[inline]
|
||||||
|
pub unsafe fn from_ptr_ref(ptr: &*mut ::gecko_bindings::structs::URLExtraData) -> &Self {
|
||||||
|
::std::mem::transmute(ptr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
impl fmt::Debug for UrlExtraData {
|
||||||
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use gecko_bindings::{structs, bindings};
|
||||||
|
|
||||||
|
struct DebugURI(*mut structs::nsIURI);
|
||||||
|
impl fmt::Debug for DebugURI {
|
||||||
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use nsstring::nsCString;
|
||||||
|
let mut spec = nsCString::new();
|
||||||
|
unsafe {
|
||||||
|
bindings::Gecko_nsIURI_Debug(self.0, &mut spec);
|
||||||
|
}
|
||||||
|
spec.fmt(formatter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formatter.debug_struct("URLExtraData")
|
||||||
|
.field("is_chrome", &self.is_chrome())
|
||||||
|
.field("base", &DebugURI(self.0.mBaseURI.raw::<structs::nsIURI>()))
|
||||||
|
.field("referrer", &DebugURI(self.0.mReferrer.raw::<structs::nsIURI>()))
|
||||||
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ macro_rules! rule_filter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait to represent a given stylesheet in a document.
|
/// A trait to represent a given stylesheet in a document.
|
||||||
pub trait StylesheetInDocument {
|
pub trait StylesheetInDocument : ::std::fmt::Debug {
|
||||||
/// Get the stylesheet origin.
|
/// Get the stylesheet origin.
|
||||||
fn origin(&self, guard: &SharedRwLockReadGuard) -> Origin;
|
fn origin(&self, guard: &SharedRwLockReadGuard) -> Origin;
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ impl StylesheetInDocument for Stylesheet {
|
||||||
|
|
||||||
/// A simple wrapper over an `Arc<Stylesheet>`, with pointer comparison, and
|
/// A simple wrapper over an `Arc<Stylesheet>`, with pointer comparison, and
|
||||||
/// suitable for its use in a `StylesheetSet`.
|
/// suitable for its use in a `StylesheetSet`.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
||||||
pub struct DocumentStyleSheet(
|
pub struct DocumentStyleSheet(
|
||||||
#[cfg_attr(feature = "servo", ignore_malloc_size_of = "Arc")] pub Arc<Stylesheet>,
|
#[cfg_attr(feature = "servo", ignore_malloc_size_of = "Arc")] pub Arc<Stylesheet>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue