Backed out changeset 597b9606c3ca (bug 1702676) for reftest failures on mq_prefers_reduced_motion_reduce.html CLOSED TREE

This commit is contained in:
Narcis Beleuzu 2021-04-02 09:34:53 +03:00
Родитель a902adedc9
Коммит e9fb777466
18 изменённых файлов: 217 добавлений и 242 удалений

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

@ -216,10 +216,9 @@ void nsListControlFrame::PaintFocus(DrawTarget* aDrawTarget, nsPoint aPt) {
}
// set up back stop colors and then ask L&F service for the real colors
nscolor color = LookAndFeel::Color(
nscolor color = LookAndFeel::GetColor(
lastItemIsSelected ? LookAndFeel::ColorID::WidgetSelectForeground
: LookAndFeel::ColorID::WidgetSelectBackground,
this);
: LookAndFeel::ColorID::WidgetSelectBackground);
nsCSSRendering::PaintFocus(presContext, aDrawTarget, fRect, color);
}

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

@ -443,7 +443,7 @@ DeviceColor nsDisplaySelectionOverlay::ComputeColor() const {
}
return ApplyTransparencyIfNecessary(
LookAndFeel::Color(colorID, mFrame, NS_RGB(255, 255, 255)));
LookAndFeel::GetColor(colorID, NS_RGB(255, 255, 255)));
}
void nsDisplaySelectionOverlay::Paint(nsDisplayListBuilder* aBuilder,

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

@ -1363,17 +1363,17 @@ void nsHTMLFramesetBorderFrame::PaintBorder(DrawTarget* aDrawTarget,
if (widthInPixels <= 0) return;
ColorPattern bgColor(ToDeviceColor(LookAndFeel::Color(
LookAndFeel::ColorID::WidgetBackground, this, NS_RGB(200, 200, 200))));
ColorPattern bgColor(ToDeviceColor(LookAndFeel::GetColor(
LookAndFeel::ColorID::WidgetBackground, NS_RGB(200, 200, 200))));
ColorPattern fgColor(ToDeviceColor(LookAndFeel::Color(
LookAndFeel::ColorID::WidgetForeground, this, NS_RGB(0, 0, 0))));
ColorPattern fgColor(ToDeviceColor(LookAndFeel::GetColor(
LookAndFeel::ColorID::WidgetForeground, NS_RGB(0, 0, 0))));
ColorPattern hltColor(ToDeviceColor(LookAndFeel::Color(
LookAndFeel::ColorID::Widget3DHighlight, this, NS_RGB(255, 255, 255))));
ColorPattern hltColor(ToDeviceColor(LookAndFeel::GetColor(
LookAndFeel::ColorID::Widget3DHighlight, NS_RGB(255, 255, 255))));
ColorPattern sdwColor(ToDeviceColor(LookAndFeel::Color(
LookAndFeel::ColorID::Widget3DShadow, this, NS_RGB(128, 128, 128))));
ColorPattern sdwColor(ToDeviceColor(LookAndFeel::GetColor(
LookAndFeel::ColorID::Widget3DShadow, NS_RGB(128, 128, 128))));
ColorPattern color(ToDeviceColor(NS_RGB(255, 255, 255))); // default to white
if (mVisibility) {

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

@ -357,7 +357,7 @@ class nsTextPaintStyle {
float* aRelativeSize, uint8_t* aStyle);
// if this returns false, we don't need to draw underline.
static bool GetSelectionUnderline(nsIFrame*, int32_t aIndex,
static bool GetSelectionUnderline(nsPresContext* aPresContext, int32_t aIndex,
nscolor* aLineColor, float* aRelativeSize,
uint8_t* aStyle);
@ -3899,13 +3899,14 @@ void nsTextPaintStyle::GetHighlightColors(nscolor* aForeColor,
}
if (!customColors) {
nscolor backColor = LookAndFeel::Color(
LookAndFeel::ColorID::TextHighlightBackground, mFrame);
nscolor foreColor = LookAndFeel::Color(
LookAndFeel::ColorID::TextHighlightForeground, mFrame);
nscolor backColor =
LookAndFeel::GetColor(LookAndFeel::ColorID::TextHighlightBackground);
nscolor foreColor =
LookAndFeel::GetColor(LookAndFeel::ColorID::TextHighlightForeground);
EnsureSufficientContrast(&foreColor, &backColor);
*aForeColor = foreColor;
*aBackColor = backColor;
return;
}
@ -4033,9 +4034,9 @@ void nsTextPaintStyle::InitCommonColors() {
mFrameBackgroundColor = NS_ComposeColors(defaultBgColor, bgColor);
mSystemFieldForegroundColor =
LookAndFeel::Color(LookAndFeel::ColorID::Fieldtext, mFrame);
LookAndFeel::GetColor(LookAndFeel::ColorID::Fieldtext);
mSystemFieldBackgroundColor =
LookAndFeel::Color(LookAndFeel::ColorID::Field, mFrame);
LookAndFeel::GetColor(LookAndFeel::ColorID::Field);
if (bgFrame->IsThemed()) {
// Assume a native widget has sufficient contrast always
@ -4048,11 +4049,11 @@ void nsTextPaintStyle::InitCommonColors() {
"default background color is not opaque");
nscolor defaultWindowBackgroundColor =
LookAndFeel::Color(LookAndFeel::ColorID::WindowBackground, mFrame);
LookAndFeel::GetColor(LookAndFeel::ColorID::WindowBackground);
nscolor selectionTextColor =
LookAndFeel::Color(LookAndFeel::ColorID::TextSelectForeground, mFrame);
LookAndFeel::GetColor(LookAndFeel::ColorID::TextSelectForeground);
nscolor selectionBGColor =
LookAndFeel::Color(LookAndFeel::ColorID::TextSelectBackground, mFrame);
LookAndFeel::GetColor(LookAndFeel::ColorID::TextSelectBackground);
mSufficientContrast = std::min(
std::min(NS_SUFFICIENT_LUMINOSITY_DIFFERENCE,
@ -4100,12 +4101,12 @@ bool nsTextPaintStyle::InitSelectionColorsAndShadow() {
}
nscolor selectionBGColor =
LookAndFeel::Color(LookAndFeel::ColorID::TextSelectBackground, mFrame);
LookAndFeel::GetColor(LookAndFeel::ColorID::TextSelectBackground);
switch (selectionStatus) {
case nsISelectionController::SELECTION_ATTENTION: {
mSelectionBGColor = LookAndFeel::Color(
LookAndFeel::ColorID::TextSelectBackgroundAttention, mFrame);
mSelectionBGColor = LookAndFeel::GetColor(
LookAndFeel::ColorID::TextSelectBackgroundAttention);
mSelectionBGColor =
EnsureDifferentColors(mSelectionBGColor, selectionBGColor);
break;
@ -4115,8 +4116,8 @@ bool nsTextPaintStyle::InitSelectionColorsAndShadow() {
break;
}
default: {
mSelectionBGColor = LookAndFeel::Color(
LookAndFeel::ColorID::TextSelectBackgroundDisabled, mFrame);
mSelectionBGColor = LookAndFeel::GetColor(
LookAndFeel::ColorID::TextSelectBackgroundDisabled);
mSelectionBGColor =
EnsureDifferentColors(mSelectionBGColor, selectionBGColor);
break;
@ -4124,7 +4125,7 @@ bool nsTextPaintStyle::InitSelectionColorsAndShadow() {
}
mSelectionTextColor =
LookAndFeel::Color(LookAndFeel::ColorID::TextSelectForeground, mFrame);
LookAndFeel::GetColor(LookAndFeel::ColorID::TextSelectForeground);
if (mResolveColors) {
// On MacOS X, only the background color gets set,
@ -4144,8 +4145,8 @@ bool nsTextPaintStyle::InitSelectionColorsAndShadow() {
: mFrame->GetVisitedDependentColor(
&nsStyleText::mWebkitTextFillColor);
if (frameColor == mSelectionBGColor) {
mSelectionTextColor = LookAndFeel::Color(
LookAndFeel::ColorID::TextSelectForegroundCustom, mFrame);
mSelectionTextColor = LookAndFeel::GetColor(
LookAndFeel::ColorID::TextSelectForegroundCustom);
}
} else {
EnsureSufficientContrast(&mSelectionTextColor, &mSelectionBGColor);
@ -4206,12 +4207,12 @@ void nsTextPaintStyle::InitSelectionStyle(int32_t aIndex) {
if (styleIDs->mForeground == LookAndFeel::ColorID::End) {
foreColor = NS_SAME_AS_FOREGROUND_COLOR;
} else {
foreColor = LookAndFeel::Color(styleIDs->mForeground, mFrame);
foreColor = LookAndFeel::GetColor(styleIDs->mForeground);
}
if (styleIDs->mBackground == LookAndFeel::ColorID::End) {
backColor = NS_TRANSPARENT;
} else {
backColor = LookAndFeel::Color(styleIDs->mBackground, mFrame);
backColor = LookAndFeel::GetColor(styleIDs->mBackground);
}
// Convert special color to actual color
@ -4232,7 +4233,8 @@ void nsTextPaintStyle::InitSelectionStyle(int32_t aIndex) {
nscolor lineColor;
float relativeSize;
uint8_t lineStyle;
GetSelectionUnderline(mFrame, aIndex, &lineColor, &relativeSize, &lineStyle);
GetSelectionUnderline(mPresContext, aIndex, &lineColor, &relativeSize,
&lineStyle);
if (mResolveColors)
lineColor = GetResolvedForeColor(lineColor, foreColor, backColor);
@ -4246,18 +4248,19 @@ void nsTextPaintStyle::InitSelectionStyle(int32_t aIndex) {
}
/* static */
bool nsTextPaintStyle::GetSelectionUnderline(nsIFrame* aFrame, int32_t aIndex,
bool nsTextPaintStyle::GetSelectionUnderline(nsPresContext* aPresContext,
int32_t aIndex,
nscolor* aLineColor,
float* aRelativeSize,
uint8_t* aStyle) {
NS_ASSERTION(aFrame, "aFrame is null");
NS_ASSERTION(aPresContext, "aPresContext is null");
NS_ASSERTION(aRelativeSize, "aRelativeSize is null");
NS_ASSERTION(aStyle, "aStyle is null");
NS_ASSERTION(aIndex >= 0 && aIndex < 5, "Index out of range");
StyleIDs& styleID = SelectionStyleIDs[aIndex];
nscolor color = LookAndFeel::Color(styleID.mLine, aFrame);
nscolor color = LookAndFeel::GetColor(styleID.mLine);
int32_t style = LookAndFeel::GetInt(styleID.mLineStyle);
if (style > NS_STYLE_TEXT_DECORATION_STYLE_MAX) {
NS_ERROR("Invalid underline style value is specified");
@ -7372,7 +7375,7 @@ bool nsTextFrame::CombineSelectionUnderlineRect(nsPresContext* aPresContext,
sd->mSelectionType);
if (sd->mSelectionType == SelectionType::eSpellCheck) {
if (!nsTextPaintStyle::GetSelectionUnderline(
this, index, nullptr, &relativeSize, &params.style)) {
aPresContext, index, nullptr, &relativeSize, &params.style)) {
continue;
}
} else {
@ -7386,7 +7389,8 @@ bool nsTextFrame::CombineSelectionUnderlineRect(nsPresContext* aPresContext,
params.style = ToStyleLineStyle(rangeStyle);
relativeSize = rangeStyle.mIsBoldLine ? 2.0f : 1.0f;
} else if (!nsTextPaintStyle::GetSelectionUnderline(
this, index, nullptr, &relativeSize, &params.style)) {
aPresContext, index, nullptr, &relativeSize,
&params.style)) {
continue;
}
}

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

@ -1713,8 +1713,8 @@ void nsDisplayMathMLSelectionRect::Paint(nsDisplayListBuilder* aBuilder,
mFrame->PresContext()->AppUnitsPerDevPixel(),
*drawTarget);
// get color to use for selection from the look&feel object
nscolor bgColor =
LookAndFeel::Color(LookAndFeel::ColorID::TextSelectBackground, mFrame);
nscolor bgColor = LookAndFeel::GetColor(
LookAndFeel::ColorID::TextSelectBackground, NS_RGB(0, 0, 0));
drawTarget->FillRect(rect, ColorPattern(ToDeviceColor(bgColor)));
}
@ -1869,8 +1869,8 @@ void nsMathMLChar::PaintForeground(nsIFrame* aForFrame,
&nsStyleText::mWebkitTextFillColor);
if (aIsSelected) {
// get color to use for selection from the look&feel object
fgColor = LookAndFeel::Color(LookAndFeel::ColorID::TextSelectForeground,
aForFrame, fgColor);
fgColor = LookAndFeel::GetColor(LookAndFeel::ColorID::TextSelectForeground,
fgColor);
}
aRenderingContext.SetColor(sRGBColor::FromABGR(fgColor));
aRenderingContext.Save();

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

@ -693,10 +693,52 @@ bool Gecko_IsDocumentBody(const Element* aElement) {
return doc && doc->GetBodyElement() == aElement;
}
static bool ShouldUseStandinsForNativeColorForNonNativeTheme(
const Document& aDoc, LookAndFeel::ColorID aColor) {
using ColorID = LookAndFeel::ColorID;
if (!aDoc.ShouldAvoidNativeTheme()) {
return false;
}
// The native theme doesn't use system colors backgrounds etc, except when in
// high-contrast mode, so spoof some of the colors with stand-ins to prevent
// lack of contrast.
switch (aColor) {
case ColorID::Buttonface:
case ColorID::Buttontext:
case ColorID::MozButtonhoverface:
case ColorID::MozButtonhovertext:
case ColorID::MozGtkButtonactivetext:
case ColorID::MozCombobox:
case ColorID::MozComboboxtext:
case ColorID::Field:
case ColorID::Fieldtext:
case ColorID::Graytext:
return !PreferenceSheet::PrefsFor(aDoc)
.NonNativeThemeShouldUseSystemColors();
default:
break;
}
return false;
}
nscolor Gecko_GetLookAndFeelSystemColor(int32_t aId, const Document* aDoc) {
auto colorId = static_cast<LookAndFeel::ColorID>(aId);
const bool useStandinsForNativeColors =
ShouldUseStandinsForNativeColorForNonNativeTheme(*aDoc, colorId) ||
(nsContentUtils::UseStandinsForNativeColors() &&
!nsContentUtils::IsChromeDoc(aDoc));
AutoWriteLock guard(*sServoFFILock);
return LookAndFeel::Color(colorId, *aDoc);
nscolor result = 0;
LookAndFeel::GetColor(colorId, useStandinsForNativeColors, &result);
return result;
}
bool Gecko_MatchLang(const Element* aElement, nsAtom* aOverrideLang,

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

@ -14,7 +14,6 @@
#include "mozilla/StaticPrefs_devtools.h"
#include "mozilla/Telemetry.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/dom/Document.h"
#include "nsContentUtils.h"
@ -89,28 +88,30 @@ void PreferenceSheet::Prefs::Load(bool aIsChrome) {
mFocusRingStyle = StaticPrefs::browser_display_focus_ring_style();
mFocusRingOnAnything = StaticPrefs::browser_display_focus_ring_on_anything();
const bool useStandins = nsContentUtils::UseStandinsForNativeColors();
const bool usePrefColors = !useStandins && !aIsChrome && !mUseAccessibilityTheme &&
const bool usePrefColors = !aIsChrome && !mUseAccessibilityTheme &&
!StaticPrefs::browser_display_use_system_colors();
if (usePrefColors) {
if (nsContentUtils::UseStandinsForNativeColors()) {
mDefaultColor = LookAndFeel::GetColorUsingStandins(
LookAndFeel::ColorID::Windowtext, mDefaultColor);
mDefaultBackgroundColor = LookAndFeel::GetColorUsingStandins(
LookAndFeel::ColorID::Window, mDefaultBackgroundColor);
mLinkColor = LookAndFeel::GetColorUsingStandins(
LookAndFeel::ColorID::MozNativehyperlinktext, mLinkColor);
} else if (usePrefColors) {
GetColor("browser.display.background_color", mDefaultBackgroundColor);
GetColor("browser.display.foreground_color", mDefaultColor);
GetColor("browser.anchor_color", mLinkColor);
} else {
using ColorID = LookAndFeel::ColorID;
const auto standins = LookAndFeel::UseStandins(useStandins);
// TODO(emilio): In the future we probably want to keep both sets of colors
// around or something.
const auto scheme = LookAndFeel::ColorScheme::Light;
mDefaultColor = LookAndFeel::Color(
ColorID::WindowForeground, scheme, standins, mDefaultColor);
mDefaultBackgroundColor = LookAndFeel::Color(
ColorID::WindowBackground, scheme, standins, mDefaultBackgroundColor);
mLinkColor = LookAndFeel::Color(
ColorID::MozNativehyperlinktext, scheme, standins, mLinkColor);
mDefaultColor = LookAndFeel::GetColor(
LookAndFeel::ColorID::WindowForeground, mDefaultColor);
mDefaultBackgroundColor = LookAndFeel::GetColor(
LookAndFeel::ColorID::WindowBackground, mDefaultBackgroundColor);
mLinkColor = LookAndFeel::GetColor(
LookAndFeel::ColorID::MozNativehyperlinktext, mLinkColor);
}
if (mUseAccessibilityTheme && !useStandins) {
if (mUseAccessibilityTheme && !nsContentUtils::UseStandinsForNativeColors()) {
mActiveLinkColor = mLinkColor;
// Visited link color is produced by preserving the foreground's green
// and averaging the foreground and background for the red and blue.

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

@ -294,8 +294,8 @@ void nsTableCellFrame::DecorateForSelection(DrawTarget* aDrawTarget,
if (displaySelection == nsISelectionController::SELECTION_DISABLED) {
bordercolor = NS_RGB(176, 176, 176); // disabled color
} else {
bordercolor = LookAndFeel::Color(
LookAndFeel::ColorID::TextSelectBackground, this);
bordercolor =
LookAndFeel::GetColor(LookAndFeel::ColorID::TextSelectBackground);
}
nscoord threePx = nsPresContext::CSSPixelsToAppUnits(3);
if ((mRect.width > threePx) && (mRect.height > threePx)) {

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

@ -55,6 +55,7 @@ using namespace mozilla;
using namespace mozilla::gfx;
using mozilla::dom::Document;
using mozilla::dom::Event;
using mozilla::layers::APZCCallbackHelper;
using mozilla::layers::AsyncDragMetrics;
using mozilla::layers::InputAPZContext;
using mozilla::layers::ScrollbarData;
@ -292,7 +293,7 @@ void nsDisplaySliderMarks::PaintMarks(nsDisplayListBuilder* aDisplayListBuilder,
// Use the text highlight color for the tick marks.
nscolor highlightColor =
LookAndFeel::Color(LookAndFeel::ColorID::TextHighlightBackground, mFrame);
LookAndFeel::GetColor(LookAndFeel::ColorID::TextHighlightBackground);
DeviceColor fillColor = ToDeviceColor(highlightColor);
fillColor.a = 0.3; // make the mark mostly transparent

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

@ -128,11 +128,8 @@ already_AddRefed<nsWebBrowser> nsWebBrowser::Create(
MOZ_ASSERT(browser->mDocShell == docShell);
// get the system default window background colour
//
// TODO(emilio): Can we get the color-scheme from somewhere here?
browser->mBackgroundColor = LookAndFeel::Color(
LookAndFeel::ColorID::WindowBackground, LookAndFeel::ColorScheme::Light,
LookAndFeel::UseStandins::No);
LookAndFeel::GetColor(LookAndFeel::ColorID::WindowBackground,
&browser->mBackgroundColor);
// HACK ALERT - this registration registers the nsDocShellTreeOwner as a
// nsIWebBrowserListener so it can setup its MouseListener in one of the

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

@ -14,19 +14,12 @@
#include "nsColor.h"
#include "nsString.h"
#include "nsTArray.h"
#include "mozilla/Maybe.h"
#include "mozilla/widget/ThemeChangeKind.h"
struct gfxFontStyle;
class nsIFrame;
namespace mozilla {
namespace dom {
class Document;
}
namespace widget {
class FullLookAndFeel;
} // namespace widget
@ -429,55 +422,31 @@ class LookAndFeel {
using FontID = mozilla::StyleSystemFont;
// Whether we should use a light or dark appearance.
//
// This is currently ignored (but won't be for long).
enum class ColorScheme : uint8_t { Light, Dark };
/**
* GetColor() return a native color value (might be overwritten by prefs) for
* aID. Some platforms don't return an error even if the index doesn't
* match any system colors. And also some platforms may initialize the
* return value even when it returns an error. Therefore, if you want to
* use a color for the default value, you should use the other GetColor()
* which returns nscolor directly.
*
* NOTE:
* ColorID::TextSelectForeground might return NS_DONT_CHANGE_COLOR.
* ColorID::IME* might return NS_TRANSPARENT, NS_SAME_AS_FOREGROUND_COLOR or
* NS_40PERCENT_FOREGROUND_COLOR.
* These values have particular meaning. Then, they are not an actual
* color value.
*/
static nsresult GetColor(ColorID aID, nscolor* aResult);
// Whether standins for native colors should be used (that is, colors faked,
// taken from win7, mostly). This forces light appearance, effectively.
enum class UseStandins : bool { No, Yes };
// Returns a native color value (might be overwritten by prefs) for a given
// color id.
//
// NOTE:
// ColorID::TextSelectForeground might return NS_DONT_CHANGE_COLOR.
// ColorID::IME* might return NS_TRANSPARENT, NS_SAME_AS_FOREGROUND_COLOR or
// NS_40PERCENT_FOREGROUND_COLOR.
// These values have particular meaning. Then, they are not an actual
// color value.
static Maybe<nscolor> GetColor(ColorID, ColorScheme, UseStandins);
// Gets the color with appropriate defaults for UseStandins, ColorScheme etc
// for a given document.
static Maybe<nscolor> GetColor(ColorID, const dom::Document&);
// Gets the color with appropriate defaults for UseStandins, ColorScheme etc
// for a given frame.
//
// TODO(emilio): This right now just peeks the document out of the frame's
// pres context, but in the future we actually want to look at the style to
// get the right color scheme, to implement the color-scheme property.
static Maybe<nscolor> GetColor(ColorID, const nsIFrame*);
// Versions of the above which returns the color if found, or a default (which
// defaults to opaque black) otherwise.
static nscolor Color(ColorID aId, ColorScheme aScheme,
UseStandins aUseStandins,
nscolor aDefault = NS_RGB(0, 0, 0)) {
return GetColor(aId, aScheme, aUseStandins).valueOr(aDefault);
}
static nscolor Color(ColorID aId, const dom::Document& aDoc,
nscolor aDefault = NS_RGB(0, 0, 0)) {
return GetColor(aId, aDoc).valueOr(aDefault);
}
static nscolor Color(ColorID aId, nsIFrame* aFrame,
nscolor aDefault = NS_RGB(0, 0, 0)) {
return GetColor(aId, aFrame).valueOr(aDefault);
}
/**
* This variant of GetColor() takes an extra Boolean parameter that allows
* the caller to ask that hard-coded color values be substituted for
* native colors (used when it is desireable to hide system colors to
* avoid system fingerprinting).
*/
static nsresult GetColor(ColorID aID, bool aUseStandinsForNativeColors,
nscolor* aResult);
/**
* GetInt() and GetFloat() return a int or float value for aID. The result
@ -487,9 +456,28 @@ class LookAndFeel {
* use a value for the default value, you should use the other method which
* returns int or float directly.
*/
static nsresult GetInt(IntID, int32_t* aResult);
static nsresult GetInt(IntID aID, int32_t* aResult);
static nsresult GetFloat(FloatID aID, float* aResult);
static nscolor GetColor(ColorID aID, nscolor aDefault = NS_RGB(0, 0, 0)) {
nscolor result = NS_RGB(0, 0, 0);
if (NS_FAILED(GetColor(aID, &result))) {
return aDefault;
}
return result;
}
static nscolor GetColorUsingStandins(ColorID aID,
nscolor aDefault = NS_RGB(0, 0, 0)) {
nscolor result = NS_RGB(0, 0, 0);
if (NS_FAILED(GetColor(aID,
true, // aUseStandinsForNativeColors
&result))) {
return aDefault;
}
return result;
}
static int32_t GetInt(IntID aID, int32_t aDefault = 0) {
int32_t result;
if (NS_FAILED(GetInt(aID, &result))) {

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

@ -33,6 +33,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
nscolor mColorTextSelectBackground;
nscolor mColorTextSelectBackgroundDisabled;
nscolor mColorHighlight;
nscolor mColorTextSelectForeground;
nscolor mColorAlternateSelectedControlText;
nscolor mColorControlText;
nscolor mColorText;

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

@ -30,6 +30,7 @@ nsLookAndFeel::nsLookAndFeel()
mColorTextSelectBackground(0),
mColorTextSelectBackgroundDisabled(0),
mColorHighlight(0),
mColorTextSelectForeground(0),
mColorAlternateSelectedControlText(0),
mColorControlText(0),
mColorText(0),
@ -166,7 +167,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
aColor = mColorHighlight;
break;
case ColorID::TextSelectForeground:
aColor = NS_DONT_CHANGE_COLOR;
aColor = mColorTextSelectForeground;
break;
case ColorID::Highlighttext: // CSS2 color
case ColorID::MozAccentColorForeground:
@ -601,6 +602,8 @@ void nsLookAndFeel::EnsureInit() {
NS_OBJC_BEGIN_TRY_IGNORE_BLOCK
nscolor color;
bool appearanceIsDark = false;
if (@available(macOS 10.14, *)) {
@ -624,6 +627,13 @@ void nsLookAndFeel::EnsureInit() {
mColorHighlight = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
GetColor(ColorID::TextSelectBackground, color);
if (color == 0x000000) {
mColorTextSelectForeground = NS_RGB(0xff, 0xff, 0xff);
} else {
mColorTextSelectForeground = NS_DONT_CHANGE_COLOR;
}
mColorAlternateSelectedControlText =
GetColorFromNSColor([NSColor alternateSelectedControlTextColor]);

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

@ -211,11 +211,6 @@ const static bool kUseSimpleContextDefault = false;
* to refer selection colors of GtkTextView via our widget.
******************************************************************************/
static Maybe<nscolor> GetSystemColor(LookAndFeel::ColorID aId) {
return LookAndFeel::GetColor(aId, LookAndFeel::ColorScheme::Light,
LookAndFeel::UseStandins::No);
}
class SelectionStyleProvider final {
public:
static SelectionStyleProvider* GetInstance() {
@ -259,27 +254,31 @@ class SelectionStyleProvider final {
// colors can be controlled by a ":selected" CSS rule.
nsAutoCString style(":selected{");
// FYI: LookAndFeel always returns selection colors of GtkTextView.
if (auto selectionForegroundColor =
GetSystemColor(LookAndFeel::ColorID::TextSelectForeground)) {
nscolor selectionForegroundColor;
if (NS_SUCCEEDED(
LookAndFeel::GetColor(LookAndFeel::ColorID::TextSelectForeground,
&selectionForegroundColor))) {
double alpha =
static_cast<double>(NS_GET_A(*selectionForegroundColor)) / 0xFF;
static_cast<double>(NS_GET_A(selectionForegroundColor)) / 0xFF;
style.AppendPrintf("color:rgba(%u,%u,%u,",
NS_GET_R(*selectionForegroundColor),
NS_GET_G(*selectionForegroundColor),
NS_GET_B(*selectionForegroundColor));
NS_GET_R(selectionForegroundColor),
NS_GET_G(selectionForegroundColor),
NS_GET_B(selectionForegroundColor));
// We can't use AppendPrintf here, because it does locale-specific
// formatting of floating-point values.
style.AppendFloat(alpha);
style.AppendPrintf(");");
}
if (auto selectionBackgroundColor =
GetSystemColor(LookAndFeel::ColorID::TextSelectBackground)) {
nscolor selectionBackgroundColor;
if (NS_SUCCEEDED(
LookAndFeel::GetColor(LookAndFeel::ColorID::TextSelectBackground,
&selectionBackgroundColor))) {
double alpha =
static_cast<double>(NS_GET_A(*selectionBackgroundColor)) / 0xFF;
static_cast<double>(NS_GET_A(selectionBackgroundColor)) / 0xFF;
style.AppendPrintf("background-color:rgba(%u,%u,%u,",
NS_GET_R(*selectionBackgroundColor),
NS_GET_G(*selectionBackgroundColor),
NS_GET_B(*selectionBackgroundColor));
NS_GET_R(selectionBackgroundColor),
NS_GET_G(selectionBackgroundColor),
NS_GET_B(selectionBackgroundColor));
style.AppendFloat(alpha);
style.AppendPrintf(");");
}

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

@ -1223,11 +1223,10 @@ bool nsNativeThemeGTK::CreateWebRenderCommandsForWidget(
switch (aAppearance) {
case StyleAppearance::Window:
case StyleAppearance::Dialog:
aBuilder.PushRect(bounds, bounds, true,
wr::ToColorF(ToDeviceColor(LookAndFeel::Color(
LookAndFeel::ColorID::WindowBackground,
LookAndFeel::ColorScheme::Light,
LookAndFeel::UseStandins::No, NS_TRANSPARENT))));
aBuilder.PushRect(
bounds, bounds, true,
wr::ToColorF(ToDeviceColor(LookAndFeel::GetColor(
LookAndFeel::ColorID::WindowBackground, NS_RGBA(0, 0, 0, 0)))));
return true;
default:

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

@ -85,7 +85,11 @@ nsresult HeadlessLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
aColor = NS_RGB(0xaa, 0xaa, 0xaa);
break;
case ColorID::TextSelectForeground:
aColor = NS_DONT_CHANGE_COLOR;
GetColor(ColorID::TextSelectBackground, aColor);
if (aColor == 0x000000)
aColor = NS_RGB(0xff, 0xff, 0xff);
else
aColor = NS_DONT_CHANGE_COLOR;
break;
case ColorID::Widget3DHighlight:
aColor = NS_RGB(0xa0, 0xa0, 0xa0);

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

@ -72,12 +72,9 @@ static LayoutDeviceIntCoord SnapBorderWidth(
static nscolor ThemedAccentColor(bool aBackground) {
MOZ_ASSERT(StaticPrefs::widget_non_native_theme_use_theme_accent());
// TODO(emilio): In the future we should probably add dark-color-scheme
// support for non-native form controls.
nscolor color = LookAndFeel::Color(
nscolor color = LookAndFeel::GetColor(
aBackground ? LookAndFeel::ColorID::MozAccentColor
: LookAndFeel::ColorID::MozAccentColorForeground,
LookAndFeel::ColorScheme::Light, LookAndFeel::UseStandins::No);
: LookAndFeel::ColorID::MozAccentColorForeground);
if (NS_GET_A(color) != 0xff) {
// Blend with white, ensuring the color is opaque to avoid surprises if we
// overdraw.
@ -199,20 +196,7 @@ static bool IsScrollbarWidthThin(nsIFrame* aFrame) {
}
static sRGBColor SystemColor(StyleSystemColor aColor) {
// TODO(emilio): We could not hardcode light appearance here with a bit of
// work, but doesn't matter for now.
return sRGBColor::FromABGR(LookAndFeel::Color(
aColor, LookAndFeel::ColorScheme::Light, LookAndFeel::UseStandins::No));
}
template <typename Compute>
static sRGBColor SystemColorOrElse(StyleSystemColor aColor, Compute aCompute) {
if (auto color =
LookAndFeel::GetColor(aColor, LookAndFeel::ColorScheme::Light,
LookAndFeel::UseStandins::No)) {
return sRGBColor::FromABGR(*color);
}
return aCompute();
return sRGBColor::FromABGR(LookAndFeel::GetColor(aColor));
}
static std::pair<sRGBColor, sRGBColor> SystemColorPair(
@ -555,16 +539,17 @@ sRGBColor nsNativeBasicTheme::ComputeScrollbarColor(
if (ShouldUseDarkScrollbar(aFrame, aStyle)) {
return sRGBColor::FromU8(20, 20, 25, 77);
}
nscolor color;
if (ui->mScrollbarColor.IsColors()) {
return sRGBColor::FromABGR(
ui->mScrollbarColor.AsColors().track.CalcColor(aStyle));
color = ui->mScrollbarColor.AsColors().track.CalcColor(aStyle);
} else if (aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarInactive,
sScrollbarColor.ToABGR());
} else {
color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbar,
sScrollbarColor.ToABGR());
}
if (aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
return SystemColorOrElse(StyleSystemColor::ThemedScrollbarInactive,
[] { return sScrollbarColor; });
}
return SystemColorOrElse(StyleSystemColor::ThemedScrollbar,
[] { return sScrollbarColor; });
return gfx::sRGBColor::FromABGR(color);
}
nscolor nsNativeBasicTheme::AdjustUnthemedScrollbarThumbColor(
@ -683,6 +668,7 @@ sRGBColor nsNativeBasicTheme::ComputeScrollbarThumbColor(
}
const nsStyleUI* ui = aStyle.StyleUI();
nscolor color;
if (ui->mScrollbarColor.IsColors()) {
return sRGBColor::FromABGR(AdjustUnthemedScrollbarThumbColor(
ui->mScrollbarColor.AsColors().thumb.CalcColor(aStyle), aElementState));
@ -710,10 +696,11 @@ sRGBColor nsNativeBasicTheme::ComputeScrollbarThumbColor(
return StyleSystemColor::ThemedScrollbarThumb;
}();
return SystemColorOrElse(systemColor, [&] {
return sRGBColor::FromABGR(AdjustUnthemedScrollbarThumbColor(
sScrollbarThumbColor.ToABGR(), aElementState));
});
if (NS_FAILED(LookAndFeel::GetColor(systemColor, &color))) {
color = AdjustUnthemedScrollbarThumbColor(sScrollbarThumbColor.ToABGR(),
aElementState);
}
return gfx::sRGBColor::FromABGR(color);
}
std::pair<sRGBColor, sRGBColor>

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

@ -14,7 +14,6 @@
#include "nsContentUtils.h"
#include "nsCRT.h"
#include "nsFont.h"
#include "nsIFrame.h"
#include "nsIXULRuntime.h"
#include "nsNativeBasicTheme.h"
#include "mozilla/dom/ContentChild.h"
@ -25,8 +24,6 @@
#include "mozilla/StaticPrefs_findbar.h"
#include "mozilla/StaticPrefs_ui.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/dom/Document.h"
#include "mozilla/PreferenceSheet.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/widget/WidgetMessageUtils.h"
#include "mozilla/Telemetry.h"
@ -65,7 +62,7 @@ struct nsLookAndFeelFloatPref {
template <typename Index, typename Value, Index kEnd>
class EnumeratedCache {
static constexpr uint32_t ChunkFor(Index aIndex) {
return uint32_t(aIndex) >> 5; // >> 5 is the same as / 32.
return uint32_t(aIndex) >> 5; // >> 5 is the same as / 32.
}
static constexpr uint32_t BitFor(Index aIndex) {
return 1u << (uint32_t(aIndex) & 31);
@ -1050,69 +1047,15 @@ void LookAndFeel::NotifyChangedAllWindows(widget::ThemeChangeKind aKind) {
}
}
static bool ShouldUseStandinsForNativeColorForNonNativeTheme(
const dom::Document& aDoc, LookAndFeel::ColorID aColor) {
using ColorID = LookAndFeel::ColorID;
if (!aDoc.ShouldAvoidNativeTheme()) {
return false;
}
// The native theme doesn't use system colors backgrounds etc, except when in
// high-contrast mode, so spoof some of the colors with stand-ins to prevent
// lack of contrast.
switch (aColor) {
case ColorID::Buttonface:
case ColorID::Buttontext:
case ColorID::MozButtonhoverface:
case ColorID::MozButtonhovertext:
case ColorID::MozGtkButtonactivetext:
case ColorID::MozCombobox:
case ColorID::MozComboboxtext:
case ColorID::Field:
case ColorID::Fieldtext:
case ColorID::Graytext:
return !PreferenceSheet::PrefsFor(aDoc)
.NonNativeThemeShouldUseSystemColors();
default:
break;
}
return false;
}
static LookAndFeel::ColorScheme ColorSchemeForDocument(const dom::Document&) {
// TODO(emilio): Actually compute a useful color scheme.
return LookAndFeel::ColorScheme::Light;
}
// static
Maybe<nscolor> LookAndFeel::GetColor(ColorID aId, ColorScheme,
UseStandins aUseStandins) {
// TODO(emilio): Actually use ColorScheme.
nscolor result;
nsresult rv = nsLookAndFeel::GetInstance()->GetColorValue(
aId, bool(aUseStandins), result);
if (NS_FAILED(rv)) {
return Nothing();
}
return Some(result);
nsresult LookAndFeel::GetColor(ColorID aID, nscolor* aResult) {
return nsLookAndFeel::GetInstance()->GetColorValue(aID, false, *aResult);
}
Maybe<nscolor> LookAndFeel::GetColor(ColorID aId, const dom::Document& aDoc) {
const bool useStandins =
ShouldUseStandinsForNativeColorForNonNativeTheme(aDoc, aId) ||
(nsContentUtils::UseStandinsForNativeColors() &&
!nsContentUtils::IsChromeDoc(&aDoc));
return GetColor(aId, ColorSchemeForDocument(aDoc), UseStandins(useStandins));
}
Maybe<nscolor> LookAndFeel::GetColor(ColorID aId, const nsIFrame* aFrame) {
return GetColor(aId, *aFrame->PresContext()->Document());
nsresult LookAndFeel::GetColor(ColorID aID, bool aUseStandinsForNativeColors,
nscolor* aResult) {
return nsLookAndFeel::GetInstance()->GetColorValue(
aID, aUseStandinsForNativeColors, *aResult);
}
// static