Bug 1760342 - Remove :-moz-lwtheme-{brighttext,darktext}. r=dao,Gijs

They are just convenience for :root[lwthemetextcolor="light"] (and dark,
respectively), but they generally shouldn't be used for dark mode
theming. In the past it was the only way to do it but now we have
prefers-color-scheme.

While at it, change lwthemetextcolor to be "lwtheme-brighttext" for
consistency with similar code we have for popups etc, and move it to
_setDarkModeAttributes.

While at it, remove layout.css.moz-lwtheme.content.enabled (which is
false always, we unshipped these from content successfully).

Differential Revision: https://phabricator.services.mozilla.com/D141593
This commit is contained in:
Emilio Cobos Álvarez 2022-03-25 14:58:59 +00:00
Родитель 35916358ca
Коммит dd020d602a
22 изменённых файлов: 71 добавлений и 138 удалений

Просмотреть файл

@ -119,21 +119,17 @@
--focus-outline-color: #0061E0;
}
:root:-moz-lwtheme-brighttext {
--focus-outline-color: #00DDFF;
@media (prefers-color-scheme: dark) {
:root:-moz-lwtheme {
--focus-outline-color: #00DDFF;
}
}
}
/* Increase the contrast of urlbar boxes in brighttext LWT.
/* Increase the contrast of urlbar boxes in dark mode.
In practice these are bumped-up --button(-hover)-bgcolor rules */
:root:-moz-lwtheme-brighttext:not([lwt-default-theme-in-dark-mode]) {
--urlbar-box-bgcolor: color-mix(in srgb, currentColor 16%, transparent);
--urlbar-box-focus-bgcolor: color-mix(in srgb, currentColor 16%, transparent);
--urlbar-box-hover-bgcolor: color-mix(in srgb, currentColor 22%, transparent);
}
/* Linux dark OS */
@media (prefers-color-scheme: dark) {
:root:not(:-moz-lwtheme) {
:root {
--urlbar-box-bgcolor: color-mix(in srgb, currentColor 16%, transparent);
--urlbar-box-focus-bgcolor: color-mix(in srgb, currentColor 16%, transparent);
--urlbar-box-hover-bgcolor: color-mix(in srgb, currentColor 22%, transparent);

Просмотреть файл

@ -12384,23 +12384,11 @@ void Document::UpdateDocumentStates(EventStates aMaybeChangedStates,
}
}
if (aMaybeChangedStates.HasAtLeastOneOfStates(
NS_DOCUMENT_STATE_ALL_LWTHEME_BITS)) {
mDocumentState &= ~NS_DOCUMENT_STATE_ALL_LWTHEME_BITS;
switch (GetDocumentLWTheme()) {
case DocumentTheme::None:
break;
case DocumentTheme::Bright:
mDocumentState |=
NS_DOCUMENT_STATE_LWTHEME | NS_DOCUMENT_STATE_LWTHEME_BRIGHTTEXT;
break;
case DocumentTheme::Dark:
mDocumentState |=
NS_DOCUMENT_STATE_LWTHEME | NS_DOCUMENT_STATE_LWTHEME_DARKTEXT;
break;
case DocumentTheme::Neutral:
mDocumentState |= NS_DOCUMENT_STATE_LWTHEME;
break;
if (aMaybeChangedStates.HasAtLeastOneOfStates(NS_DOCUMENT_STATE_LWTHEME)) {
if (ComputeDocumentLWTheme()) {
mDocumentState |= NS_DOCUMENT_STATE_LWTHEME;
} else {
mDocumentState &= ~NS_DOCUMENT_STATE_LWTHEME;
}
}
@ -15847,26 +15835,14 @@ void Document::SetStateObject(nsIStructuredCloneContainer* scContainer) {
mStateObjectCached.reset();
}
Document::DocumentTheme Document::GetDocumentLWTheme() const {
bool Document::ComputeDocumentLWTheme() const {
if (!NodePrincipal()->IsSystemPrincipal()) {
return DocumentTheme::None;
return false;
}
auto theme = DocumentTheme::None; // No lightweight theme by default
Element* element = GetRootElement();
if (element && element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::lwtheme,
nsGkAtoms::_true, eCaseMatters)) {
theme = DocumentTheme::Neutral;
nsAutoString lwTheme;
element->GetAttr(kNameSpaceID_None, nsGkAtoms::lwthemetextcolor, lwTheme);
if (lwTheme.EqualsLiteral("dark")) {
theme = DocumentTheme::Dark;
} else if (lwTheme.EqualsLiteral("bright")) {
theme = DocumentTheme::Bright;
}
}
return theme;
return element && element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::lwtheme,
nsGkAtoms::_true, eCaseMatters);
}
already_AddRefed<Element> Document::CreateHTMLElement(nsAtom* aTag) {

Просмотреть файл

@ -358,14 +358,9 @@ enum class DeprecatedOperations : uint16_t {
#define NS_DOCUMENT_STATE_LTR_LOCALE NS_DEFINE_EVENT_STATE_MACRO(2)
// Lightweight-theme status.
#define NS_DOCUMENT_STATE_LWTHEME NS_DEFINE_EVENT_STATE_MACRO(3)
#define NS_DOCUMENT_STATE_LWTHEME_BRIGHTTEXT NS_DEFINE_EVENT_STATE_MACRO(4)
#define NS_DOCUMENT_STATE_LWTHEME_DARKTEXT NS_DEFINE_EVENT_STATE_MACRO(5)
#define NS_DOCUMENT_STATE_ALL_LOCALEDIR_BITS \
(NS_DOCUMENT_STATE_RTL_LOCALE | NS_DOCUMENT_STATE_LTR_LOCALE)
#define NS_DOCUMENT_STATE_ALL_LWTHEME_BITS \
(NS_DOCUMENT_STATE_LWTHEME | NS_DOCUMENT_STATE_LWTHEME_BRIGHTTEXT | \
NS_DOCUMENT_STATE_LWTHEME_DARKTEXT)
class ExternalResourceMap {
using SubDocEnumFunc = FunctionRef<CallState(Document&)>;
@ -3035,17 +3030,13 @@ class Document : public nsINode,
SetStateObject(aDocument->mStateObjectContainer);
}
enum class DocumentTheme { None, Neutral, Dark, Bright };
/**
* Returns DocumentTheme::None if there is no lightweight theme specified,
* Dark for a dark theme, Bright for a light theme, and Neutral for any other
* theme. This is used to determine the state of the pseudoclasses
* :-moz-lwtheme and :-moz-lwtheme-*text.
* Returns true if there is a lightweight theme specified. This is used to
* determine the state of the :-moz-lwtheme pseudo-class.
*/
DocumentTheme GetDocumentLWTheme() const;
bool ComputeDocumentLWTheme() const;
void ResetDocumentLWTheme() {
UpdateDocumentStates(NS_DOCUMENT_STATE_ALL_LWTHEME_BITS, true);
UpdateDocumentStates(NS_DOCUMENT_STATE_LWTHEME, true);
}
// Whether we're a media document or not.

Просмотреть файл

@ -175,8 +175,7 @@ void ChromeObserver::AttributeChanged(dom::Element* aElement,
// if the localedir changed on the root element, reset the document
// direction
mDocument->ResetDocumentDirection();
} else if (aName == nsGkAtoms::lwtheme ||
aName == nsGkAtoms::lwthemetextcolor) {
} else if (aName == nsGkAtoms::lwtheme) {
// if the lwtheme changed, make sure to reset the document lwtheme
// cache
mDocument->ResetDocumentLWTheme();
@ -190,8 +189,7 @@ void ChromeObserver::AttributeChanged(dom::Element* aElement,
// if the localedir changed on the root element, reset the document
// direction
mDocument->ResetDocumentDirection();
} else if ((aName == nsGkAtoms::lwtheme ||
aName == nsGkAtoms::lwthemetextcolor)) {
} else if (aName == nsGkAtoms::lwtheme) {
// if the lwtheme changed, make sure to restyle appropriately
mDocument->ResetDocumentLWTheme();
} else if (aName == nsGkAtoms::drawintitlebar) {

Просмотреть файл

@ -3366,8 +3366,6 @@ void RestyleManager::TakeSnapshotForAttributeChange(Element& aElement,
// For some attribute changes we must restyle the whole subtree:
//
// * <td> is affected by the cellpadding on its ancestor table
// * lwtheme and lwthemetextcolor on root element of XUL document
// affects all descendants due to :-moz-lwtheme* pseudo-classes
// * lang="" and xml:lang="" can affect all descendants due to :lang()
// * exportparts can affect all descendant parts. We could certainly integrate
// it better in the invalidation machinery if it was necessary.
@ -3376,10 +3374,6 @@ static inline bool AttributeChangeRequiresSubtreeRestyle(
if (aAttr == nsGkAtoms::cellpadding) {
return aElement.IsHTMLElement(nsGkAtoms::table);
}
if (aAttr == nsGkAtoms::lwtheme || aAttr == nsGkAtoms::lwthemetextcolor) {
Document* doc = aElement.OwnerDoc();
return doc->IsInChromeDocShell() && &aElement == doc->GetRootElement();
}
// TODO(emilio, bug 1598094): Maybe finer-grained invalidation for exportparts
// attribute changes?
if (aAttr == nsGkAtoms::exportparts) {

Просмотреть файл

@ -32,8 +32,6 @@ const NON_CONTENT_ACCESIBLE_PSEUDOS = [
":-moz-dir-attr-like-auto",
":-moz-autofill-preview",
":-moz-lwtheme",
":-moz-lwtheme-brighttext",
":-moz-lwtheme-darkttext",
":-moz-locale-dir(rtl)",
":-moz-locale-dir(ltr)",

Просмотреть файл

@ -1076,10 +1076,8 @@ function runTests() {
test_balanced_unparseable(":dir(ltr other)");
test_balanced_unparseable(":dir");
// Test chrome-only -moz-lwtheme and -moz-lwtheme-[darktext|brighttext]
// Test chrome-only -moz-lwtheme
test_balanced_unparseable(":-moz-lwtheme");
test_balanced_unparseable(":-moz-lwtheme-brighttext");
test_balanced_unparseable(":-moz-lwtheme-darktext");
test_balanced_unparseable(":-moz-tree-row(selected)");
test_balanced_unparseable("::-moz-tree-row(selected)");

Просмотреть файл

@ -7325,13 +7325,6 @@
mirror: always
rust: true
# Whether the `:-moz-lwtheme` pseudo-class is exposed to content.
- name: layout.css.moz-lwtheme.content.enabled
type: RelaxedAtomicBool
value: false
mirror: always
rust: true
# Whether the `:-moz-locale-dir()` pseudo-class is exposed to content.
- name: layout.css.moz-locale-dir.content.enabled
type: RelaxedAtomicBool

Просмотреть файл

@ -148,9 +148,5 @@ bitflags! {
const LTR_LOCALE = 1 << 2;
/// LWTheme status
const LWTHEME = 1 << 3;
/// LWTheme status
const LWTHEME_BRIGHTTEXT = 1 << 4;
/// LWTheme status
const LWTHEME_DARKTEXT = 1 << 5;
}
}

Просмотреть файл

@ -92,8 +92,6 @@ macro_rules! apply_non_ts_list {
("-moz-is-html", MozIsHTML, _, _),
("-moz-placeholder", MozPlaceholder, _, _),
("-moz-lwtheme", MozLWTheme, _, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME),
("-moz-lwtheme-brighttext", MozLWThemeBrightText, _, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME),
("-moz-lwtheme-darktext", MozLWThemeDarkText, _, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME),
("-moz-window-inactive", MozWindowInactive, _, _),
]
}

Просмотреть файл

@ -139,12 +139,6 @@ impl NonTSPseudoClass {
/// Returns whether the pseudo-class is enabled in content sheets.
#[inline]
fn is_enabled_in_content(&self) -> bool {
if matches!(
*self,
Self::MozLWTheme | Self::MozLWThemeBrightText | Self::MozLWThemeDarkText
) {
return static_prefs::pref!("layout.css.moz-lwtheme.content.enabled");
}
if let NonTSPseudoClass::MozLocaleDir(..) = *self {
return static_prefs::pref!("layout.css.moz-locale-dir.content.enabled");
}
@ -184,8 +178,6 @@ impl NonTSPseudoClass {
},
NonTSPseudoClass::MozWindowInactive => DocumentState::WINDOW_INACTIVE,
NonTSPseudoClass::MozLWTheme => DocumentState::LWTHEME,
NonTSPseudoClass::MozLWThemeBrightText => DocumentState::LWTHEME_BRIGHTTEXT,
NonTSPseudoClass::MozLWThemeDarkText => DocumentState::LWTHEME_DARKTEXT,
_ => DocumentState::empty(),
}
}
@ -208,15 +200,13 @@ impl NonTSPseudoClass {
NonTSPseudoClass::MozNativeAnonymous |
// :-moz-placeholder is parsed but never matches.
NonTSPseudoClass::MozPlaceholder |
// :-moz-locale-dir and :-moz-window-inactive depend only on
// the state of the document, which is invariant across all
// the elements involved in a given style cache.
NonTSPseudoClass::MozLocaleDir(_) |
NonTSPseudoClass::MozWindowInactive |
// Similar for the document themes.
// :-moz-lwtheme, :-moz-locale-dir and
// :-moz-window-inactive depend only on the state of the
// document, which is invariant across all the elements
// involved in a given style cache.
NonTSPseudoClass::MozLWTheme |
NonTSPseudoClass::MozLWThemeBrightText |
NonTSPseudoClass::MozLWThemeDarkText
NonTSPseudoClass::MozLocaleDir(_) |
NonTSPseudoClass::MozWindowInactive
)
}
}

Просмотреть файл

@ -2198,8 +2198,6 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
NonTSPseudoClass::MozIsHTML => self.is_html_element_in_html_document(),
NonTSPseudoClass::MozLWTheme |
NonTSPseudoClass::MozLWThemeBrightText |
NonTSPseudoClass::MozLWThemeDarkText |
NonTSPseudoClass::MozLocaleDir(..) |
NonTSPseudoClass::MozWindowInactive => {
let state_bit = pseudo_class.document_state_flag();

Просмотреть файл

@ -31,9 +31,9 @@ add_task(async function test_support_theme_frame() {
);
Assert.equal(
docEl.getAttribute("lwthemetextcolor"),
"dark",
"LWT text color attribute should be set"
docEl.getAttribute("lwtheme-brighttext"),
null,
"LWT text color attribute should not be set"
);
let toolbox = document.querySelector("#navigator-toolbox");
@ -77,7 +77,7 @@ add_task(async function test_support_theme_frame() {
);
Assert.ok(
!docEl.hasAttribute("lwthemetextcolor"),
!docEl.hasAttribute("lwtheme-brighttext"),
"LWT text color attribute should not be set"
);
});

Просмотреть файл

@ -29,8 +29,8 @@ function validateTheme(backgroundImage, accentColor, textColor, isLWT) {
if (isLWT) {
Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");
Assert.equal(
docEl.getAttribute("lwthemetextcolor"),
"bright",
docEl.getAttribute("lwtheme-brighttext"),
"true",
"LWT text color attribute should be set"
);
}

Просмотреть файл

@ -37,9 +37,8 @@ add_task(async function test_deprecated_LWT_properties_ignored() {
!docEl.hasAttribute("lwtheme-image"),
"LWT image attribute should not be set on deprecated headerURL alias"
);
Assert.equal(
docEl.getAttribute("lwthemetextcolor"),
"dark",
Assert.ok(
!docEl.getAttribute("lwtheme-brighttext"),
"LWT text color attribute should not be set on deprecated textcolor alias"
);

Просмотреть файл

@ -34,8 +34,8 @@ add_task(async function test_support_backgrounds_position() {
Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");
Assert.equal(
docEl.getAttribute("lwthemetextcolor"),
"bright",
docEl.getAttribute("lwtheme-brighttext"),
"true",
"LWT text color attribute should be set"
);
@ -134,8 +134,8 @@ add_task(async function test_support_backgrounds_repeat() {
Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");
Assert.equal(
docEl.getAttribute("lwthemetextcolor"),
"bright",
docEl.getAttribute("lwtheme-brighttext"),
"true",
"LWT text color attribute should be set"
);
@ -233,8 +233,8 @@ add_task(async function test_additional_images_check() {
Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");
Assert.equal(
docEl.getAttribute("lwthemetextcolor"),
"bright",
docEl.getAttribute("lwtheme-brighttext"),
"true",
"LWT text color attribute should be set"
);

Просмотреть файл

@ -51,14 +51,14 @@ async function testWindowColorScheme({
if (expectLWTAttributes) {
ok(docEl.hasAttribute("lwtheme"), "Window should have LWT attribute.");
is(
docEl.getAttribute("lwthemetextcolor"),
expectDark ? "bright" : "dark",
docEl.getAttribute("lwtheme-brighttext"),
expectDark ? "true" : null,
"LWT text color attribute should be set."
);
} else {
ok(!docEl.hasAttribute("lwtheme"), "Window should not have LWT attribute.");
ok(
!docEl.hasAttribute("lwthemetextcolor"),
!docEl.hasAttribute("lwtheme-brighttext"),
"LWT text color attribute should not be set."
);
}

Просмотреть файл

@ -31,8 +31,8 @@ add_task(async function test_multiple_windows() {
Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");
Assert.equal(
docEl.getAttribute("lwthemetextcolor"),
"bright",
docEl.getAttribute("lwtheme-brighttext"),
"true",
"LWT text color attribute should be set"
);
Assert.ok(
@ -50,8 +50,8 @@ add_task(async function test_multiple_windows() {
Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");
Assert.equal(
docEl.getAttribute("lwthemetextcolor"),
"bright",
docEl.getAttribute("lwtheme-brighttext"),
"true",
"LWT text color attribute should be set"
);
Assert.ok(

Просмотреть файл

@ -60,10 +60,6 @@ const toolkitVariableMap = [
}
// Remove the alpha channel
const { r, g, b } = rgbaChannels;
element.setAttribute(
"lwthemetextcolor",
_isColorDark(r, g, b) ? "dark" : "bright"
);
return `rgba(${r}, ${g}, ${b})`;
},
},
@ -323,7 +319,6 @@ LightweightThemeConsumer.prototype = {
} else {
_determineToolbarAndContentTheme(this._doc, null);
root.removeAttribute("lwtheme");
root.removeAttribute("lwthemetextcolor");
}
if (theme.id == DEFAULT_THEME_ID && useDarkTheme) {
root.setAttribute("lwt-default-theme-in-dark-mode", "true");
@ -543,6 +538,15 @@ function _determineToolbarAndContentTheme(
* The `_processedColors` object from the object created for our theme.
*/
function _setDarkModeAttributes(doc, root, colors) {
{
let textColor = _cssColorToRGBA(doc, colors.textcolor);
if (textColor && !_isColorDark(textColor.r, textColor.g, textColor.b)) {
root.setAttribute("lwtheme-brighttext", "true");
} else {
root.removeAttribute("lwtheme-brighttext");
}
}
if (
_determineIfColorPairIsDark(
doc,

Просмотреть файл

@ -61,11 +61,11 @@
/* Lightweight theme roots */
:root[lwtheme-image]:-moz-lwtheme-darktext {
:root[lwtheme-image] {
text-shadow: 0 -0.5px 1.5px white;
}
:root[lwtheme-image]:-moz-lwtheme-brighttext {
:root[lwtheme-image][lwtheme-brighttext] {
text-shadow: 1px 1px 1.5px black;
}

Просмотреть файл

@ -40,12 +40,17 @@ notification {
--notification-primary-button-text: rgb(249, 249, 250);
}
notification[type="info"]:-moz-lwtheme-brighttext {
--notification-background: #38383d;
--notification-text: rgb(249, 249, 250);
--notification-button-background: rgba(249,249,250,.1);
--notification-button-background-hover: rgba(249,249,250,.2);
--notification-button-background-active: rgba(249,249,250,.3);
@media (prefers-color-scheme: dark) {
notification[type="info"]:-moz-lwtheme {
--notification-background: #38383d;
--notification-text: rgb(249, 249, 250);
}
notification[type="info"] {
--notification-button-background: rgba(249,249,250,.1);
--notification-button-background-hover: rgba(249,249,250,.2);
--notification-button-background-active: rgba(249,249,250,.3);
}
}
html|notification-message.animated,

Просмотреть файл

@ -622,7 +622,6 @@ STATIC_ATOMS = [
Atom("lowsrc", "lowsrc"),
Atom("ltr", "ltr"),
Atom("lwtheme", "lwtheme"),
Atom("lwthemetextcolor", "lwthemetextcolor"),
Atom("main", "main"),
Atom("map", "map"),
Atom("manifest", "manifest"),