Commit e66472c7 authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Add method to query system dark mode status in NativeTheme

Bug: 850098, 893598
Change-Id: I0ec85e12ae0714974e4d8122914afe330ac0fe93
Reviewed-on: https://chromium-review.googlesource.com/c/1240172Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600008}
parent 4e73edc2
......@@ -344,11 +344,19 @@ typedef NSString* VNBarcodeSymbology NS_STRING_ENUM;
#if !defined(MAC_OS_X_VERSION_10_14) || \
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_14
typedef NSString* NSAppearanceName;
@interface NSApplication (ForwardDeclare)
@property(strong) NSAppearance* appearance;
@property(readonly, strong) NSAppearance* effectiveAppearance;
@end
@interface NSAppearance (ForwardDeclare)
- (NSAppearanceName)bestMatchFromAppearancesWithNames:
(NSArray<NSAppearanceName>*)appearances;
@end
BASE_EXPORT extern NSString* const NSAppearanceNameDarkAqua;
BASE_EXPORT extern NSAppearanceName const NSAppearanceNameDarkAqua;
#endif
......
......@@ -6,6 +6,8 @@
#include <cstring>
#include "base/command_line.h"
#include "ui/base/ui_base_switches.h"
#include "ui/native_theme/native_theme_observer.h"
namespace ui {
......@@ -47,4 +49,9 @@ NativeTheme::NativeTheme()
NativeTheme::~NativeTheme() {}
bool NativeTheme::SystemDarkModeEnabled() const {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceDarkMode);
}
} // namespace ui
......@@ -408,6 +408,9 @@ class NATIVE_THEME_EXPORT NativeTheme {
// system accessibility settings and the system theme.
virtual bool UsesHighContrastColors() const = 0;
// Whether OS-level dark mode (as in macOS Mojave or Windows 10) is enabled.
virtual bool SystemDarkModeEnabled() const;
protected:
NativeTheme();
virtual ~NativeTheme();
......
......@@ -47,6 +47,7 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
const gfx::Rect& rect,
const MenuItemExtraParams& menu_item) const override;
bool UsesHighContrastColors() const override;
bool SystemDarkModeEnabled() const override;
// Paints the styled button shape used for default controls on Mac. The basic
// style is used for dialog buttons, comboboxes, and tabbed pane tabs.
......
......@@ -196,6 +196,17 @@ bool NativeThemeMac::UsesHighContrastColors() const {
return false;
}
bool NativeThemeMac::SystemDarkModeEnabled() const {
if (@available(macOS 10.14, *)) {
NSAppearanceName appearance =
[[NSApp effectiveAppearance] bestMatchFromAppearancesWithNames:@[
NSAppearanceNameAqua, NSAppearanceNameDarkAqua
]];
return [appearance isEqual:NSAppearanceNameDarkAqua];
}
return NativeThemeBase::SystemDarkModeEnabled();
}
NativeThemeMac::NativeThemeMac() {
}
......
......@@ -4814,6 +4814,7 @@ class TestNativeTheme : public ui::NativeTheme {
return gfx::Rect();
}
bool UsesHighContrastColors() const override { return false; }
bool SystemDarkModeEnabled() const override { return false; }
private:
DISALLOW_COPY_AND_ASSIGN(TestNativeTheme);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment