Bug 1702879 - Respect the document's ColorScheme when drawing native themed widgets. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D110766
This commit is contained in:
Markus Stange 2021-04-04 15:48:02 +00:00
parent c9a43eb1f1
commit 05cea55db6
2 changed files with 13 additions and 10 deletions

View File

@ -11,6 +11,7 @@
#include "mozilla/Variant.h"
#include "LookAndFeel.h"
#include "nsITheme.h"
#include "nsCOMPtr.h"
#include "nsAtom.h"
@ -315,8 +316,7 @@ class nsNativeThemeCocoa : private nsNativeTheme, public nsITheme {
// The nsITheme interface.
NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance, const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow) override;
const nsRect& aDirtyRect, DrawOverflow) override;
bool CreateWebRenderCommandsForWidget(mozilla::wr::DisplayListBuilder& aBuilder,
mozilla::wr::IpcResourceUpdateQueue& aResources,
const mozilla::layers::StackingContextHelper& aSc,
@ -423,9 +423,9 @@ class nsNativeThemeCocoa : private nsNativeTheme, public nsITheme {
void DrawSourceListSelection(CGContextRef aContext, const CGRect& aRect, bool aWindowIsActive,
bool aSelectionIsActive);
void RenderWidget(const WidgetInfo& aWidgetInfo, mozilla::gfx::DrawTarget& aDrawTarget,
const mozilla::gfx::Rect& aWidgetRect, const mozilla::gfx::Rect& aDirtyRect,
float aScale);
void RenderWidget(const WidgetInfo& aWidgetInfo, mozilla::LookAndFeel::ColorScheme,
mozilla::gfx::DrawTarget& aDrawTarget, const mozilla::gfx::Rect& aWidgetRect,
const mozilla::gfx::Rect& aDirtyRect, float aScale);
private:
NSButtonCell* mDisclosureButtonCell;

View File

@ -5,7 +5,6 @@
#include "nsNativeThemeCocoa.h"
#include "AppearanceOverride.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Helpers.h"
#include "mozilla/gfx/PathHelpers.h"
@ -41,6 +40,7 @@
#include "mozilla/StaticPrefs_widget.h"
#include "nsLookAndFeel.h"
#include "MacThemeGeometryType.h"
#include "SDKDeclarations.h"
#include "VibrancyManager.h"
#include "gfxContext.h"
@ -2649,7 +2649,9 @@ nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
bool hidpi = IsHiDPIContext(aFrame->PresContext()->DeviceContext());
RenderWidget(*widgetInfo, *aContext->GetDrawTarget(), nativeWidgetRect,
auto colorScheme = LookAndFeel::ColorSchemeForDocument(*aFrame->PresContext()->Document());
RenderWidget(*widgetInfo, colorScheme, *aContext->GetDrawTarget(), nativeWidgetRect,
NSRectToRect(aDirtyRect, p2a), hidpi ? 2.0f : 1.0f);
return NS_OK;
@ -2657,12 +2659,13 @@ nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
}
void nsNativeThemeCocoa::RenderWidget(const WidgetInfo& aWidgetInfo, DrawTarget& aDrawTarget,
void nsNativeThemeCocoa::RenderWidget(const WidgetInfo& aWidgetInfo,
LookAndFeel::ColorScheme aScheme, DrawTarget& aDrawTarget,
const gfx::Rect& aWidgetRect, const gfx::Rect& aDirtyRect,
float aScale) {
// Some of the drawing below uses NSAppearance.currentAppearance behind the scenes.
// Set it to the appearance we want.
NSAppearance.currentAppearance = MOZGlobalAppearance.sharedInstance.effectiveAppearance;
// Set it to the appearance we want, the same way as nsLookAndFeel::NativeGetColor.
NSAppearance.currentAppearance = NSAppearanceForColorScheme(aScheme);
// Also set the cell draw window's appearance; this is respected by NSTextFieldCell (and its
// subclass NSSearchFieldCell).