mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Add dark mode to plaintext.css, and a document rule to target plaintext documents.
We add two @-moz-document functions: `plain-text-document()`, matching the obvious, and `unobservable-document()`, which matches a top-level document with no opener. This is the equivalent check we do for automatic darkening of `about:blank` here: https://searchfox.org/mozilla-central/rev/014fe72eaba26dcf6082fb9bbaf208f97a38594e/layout/base/PresShell.cpp#5282 The former we don't need to use, but it's nice to let user stylesheets target plaintext documents properly (rather than relying on extensions or what not). Note that these are not content-observable. Add two tests: One showing that we produce different rendering when on dark mode, and one showing that we produce the same one from an iframe, regardless of dark mode. Depends on D101517 Differential Revision: https://phabricator.services.mozilla.com/D101518
This commit is contained in:
parent
df7ea837d8
commit
45b837399f
1 changed files with 27 additions and 2 deletions
|
@ -110,6 +110,13 @@ pub enum DocumentMatchingFunction {
|
|||
/// Matching function for a media document.
|
||||
#[css(function)]
|
||||
MediaDocument(MediaDocumentKind),
|
||||
/// Matching function for a plain-text document.
|
||||
#[css(function)]
|
||||
PlainTextDocument(()),
|
||||
/// Matching function for a document that can be observed by other content
|
||||
/// documents.
|
||||
#[css(function)]
|
||||
UnobservableDocument(()),
|
||||
}
|
||||
|
||||
macro_rules! parse_quoted_or_unquoted_string {
|
||||
|
@ -161,6 +168,21 @@ impl DocumentMatchingFunction {
|
|||
Ok(DocumentMatchingFunction::MediaDocument(kind))
|
||||
})
|
||||
},
|
||||
|
||||
"plain-text-document" => {
|
||||
input.parse_nested_block(|input| {
|
||||
input.expect_exhausted()?;
|
||||
Ok(DocumentMatchingFunction::PlainTextDocument(()))
|
||||
})
|
||||
},
|
||||
|
||||
"unobservable-document" => {
|
||||
input.parse_nested_block(|input| {
|
||||
input.expect_exhausted()?;
|
||||
Ok(DocumentMatchingFunction::UnobservableDocument(()))
|
||||
})
|
||||
},
|
||||
|
||||
_ => {
|
||||
Err(location.new_custom_error(
|
||||
StyleParseErrorKind::UnexpectedFunction(function.clone())
|
||||
|
@ -184,6 +206,8 @@ impl DocumentMatchingFunction {
|
|||
DocumentMatchingFunction::MediaDocument(_) => {
|
||||
GeckoDocumentMatchingFunction::MediaDocument
|
||||
},
|
||||
DocumentMatchingFunction::PlainTextDocument(..) => GeckoDocumentMatchingFunction::PlainTextDocument,
|
||||
DocumentMatchingFunction::UnobservableDocument(..) => GeckoDocumentMatchingFunction::UnobservableDocument,
|
||||
};
|
||||
|
||||
let pattern = nsCStr::from(match *self {
|
||||
|
@ -197,6 +221,8 @@ impl DocumentMatchingFunction {
|
|||
MediaDocumentKind::Plugin => "plugin",
|
||||
MediaDocumentKind::Video => "video",
|
||||
},
|
||||
DocumentMatchingFunction::PlainTextDocument(()) |
|
||||
DocumentMatchingFunction::UnobservableDocument(()) => "",
|
||||
});
|
||||
unsafe { Gecko_DocumentRule_UseForPresentation(device.document(), &*pattern, func) }
|
||||
}
|
||||
|
@ -253,10 +279,9 @@ impl DocumentCondition {
|
|||
|
||||
#[cfg(feature = "gecko")]
|
||||
fn allowed_in(&self, context: &ParserContext) -> bool {
|
||||
use crate::stylesheets::Origin;
|
||||
use static_prefs::pref;
|
||||
|
||||
if context.stylesheet_origin != Origin::Author {
|
||||
if context.in_ua_or_chrome_sheet() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue