From 5072843ee383bd8ae42e50aac304a33f803c0e6a Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 19 Oct 2020 19:35:03 +0000 Subject: Issue #1671 - Unprefix ::-moz-selection This actually keeps both pseudo-elements for now, since the prefixed version is still used internally, but we need the unprefixed version for web compat. Note: while unprefixing a non-spec-compliant pseudo here, it's exactly in line with what other browsers do. Nobody is following the spec here and at least we'll be doing what everyone else is with our unprefixed version. --- .../inspector/rules/test/browser_rules_pseudo-element_01.js | 6 +++--- devtools/shared/css/generated/properties-db.js | 1 + layout/generic/nsTextFrame.cpp | 11 +++++++++-- layout/inspector/tests/test_getCSSPseudoElementNames.html | 1 + layout/style/nsCSSPseudoElementList.h | 3 +++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/devtools/client/inspector/rules/test/browser_rules_pseudo-element_01.js b/devtools/client/inspector/rules/test/browser_rules_pseudo-element_01.js index 77b8c0688..72cc7f898 100644 --- a/devtools/client/inspector/rules/test/browser_rules_pseudo-element_01.js +++ b/devtools/client/inspector/rules/test/browser_rules_pseudo-element_01.js @@ -29,7 +29,7 @@ function* testTopLeft(inspector, view) { elementRulesNb: 4, firstLineRulesNb: 2, firstLetterRulesNb: 1, - selectionRulesNb: 0, + selectionRulesNb: 1, afterRulesNb: 1, beforeRulesNb: 2 } @@ -166,7 +166,7 @@ function* testParagraph(inspector, view) { elementRulesNb: 3, firstLineRulesNb: 1, firstLetterRulesNb: 1, - selectionRulesNb: 1, + selectionRulesNb: 2, beforeRulesNb: 0, afterRulesNb: 0 }); @@ -216,7 +216,7 @@ function* assertPseudoElementRulesNumbers(selector, inspector, view, ruleNbs) { firstLetterRules: elementStyle.rules.filter(rule => rule.pseudoElement === ":first-letter"), selectionRules: elementStyle.rules.filter(rule => - rule.pseudoElement === ":-moz-selection"), + rule.pseudoElement === ":selection"), beforeRules: elementStyle.rules.filter(rule => rule.pseudoElement === ":before"), afterRules: elementStyle.rules.filter(rule => diff --git a/devtools/shared/css/generated/properties-db.js b/devtools/shared/css/generated/properties-db.js index 316352771..50d849e79 100644 --- a/devtools/shared/css/generated/properties-db.js +++ b/devtools/shared/css/generated/properties-db.js @@ -9375,6 +9375,7 @@ exports.PSEUDO_ELEMENTS = [ ":backdrop", ":first-letter", ":first-line", + ":selection", ":-moz-selection", ":-moz-focus-inner", ":-moz-focus-outer", diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index fcce7f3f6..4decdc8ec 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -3947,11 +3947,18 @@ nsTextPaintStyle::InitSelectionColorsAndShadow() if (selectionElement && selectionStatus == nsISelectionController::SELECTION_ON) { RefPtr sc = nullptr; + // Probe for both selection and -moz-selection sc = mPresContext->StyleSet()-> ProbePseudoElementStyle(selectionElement, - CSSPseudoElementType::mozSelection, + CSSPseudoElementType::selection, mFrame->StyleContext()); - // Use -moz-selection pseudo class. + if (!sc) { + sc = mPresContext->StyleSet()-> + ProbePseudoElementStyle(selectionElement, + CSSPseudoElementType::mozSelection, + mFrame->StyleContext()); + } + // Use selection pseudo class. if (sc) { mSelectionBGColor = sc->GetVisitedDependentColor(eCSSProperty_background_color); diff --git a/layout/inspector/tests/test_getCSSPseudoElementNames.html b/layout/inspector/tests/test_getCSSPseudoElementNames.html index cdb4572d4..8879f21dc 100644 --- a/layout/inspector/tests/test_getCSSPseudoElementNames.html +++ b/layout/inspector/tests/test_getCSSPseudoElementNames.html @@ -16,6 +16,7 @@ ":first-letter", ":first-line", ":placeholder", + ":selection", ":-moz-color-swatch", ":-moz-focus-inner", ":-moz-focus-outer", diff --git a/layout/style/nsCSSPseudoElementList.h b/layout/style/nsCSSPseudoElementList.h index 552c76734..b8393d395 100644 --- a/layout/style/nsCSSPseudoElementList.h +++ b/layout/style/nsCSSPseudoElementList.h @@ -37,6 +37,9 @@ CSS_PSEUDO_ELEMENT(firstLine, ":first-line", CSS_PSEUDO_ELEMENT_IS_CSS2 | CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS) +CSS_PSEUDO_ELEMENT(selection, ":selection", + CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS) +// Keep the prefixed version for now. CSS_PSEUDO_ELEMENT(mozSelection, ":-moz-selection", CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS) -- cgit v1.2.3