2019-08-14 20:42:55 +00:00
|
|
|
// Copyright (c) 2019 Slack Technologies, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NATIVE_THEME_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NATIVE_THEME_H_
|
2019-08-14 20:42:55 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2020-07-22 18:01:30 +00:00
|
|
|
#include "gin/handle.h"
|
|
|
|
#include "gin/wrappable.h"
|
|
|
|
#include "shell/browser/event_emitter_mixin.h"
|
2019-09-05 17:57:04 +00:00
|
|
|
#include "ui/native_theme/native_theme.h"
|
2019-08-14 20:42:55 +00:00
|
|
|
#include "ui/native_theme/native_theme_observer.h"
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::api {
|
2019-08-14 20:42:55 +00:00
|
|
|
|
2020-07-22 18:01:30 +00:00
|
|
|
class NativeTheme : public gin::Wrappable<NativeTheme>,
|
|
|
|
public gin_helper::EventEmitterMixin<NativeTheme>,
|
2019-10-25 13:03:28 +00:00
|
|
|
public ui::NativeThemeObserver {
|
2019-08-14 20:42:55 +00:00
|
|
|
public:
|
2020-07-22 18:01:30 +00:00
|
|
|
static gin::Handle<NativeTheme> Create(v8::Isolate* isolate);
|
2019-08-14 20:42:55 +00:00
|
|
|
|
2020-07-22 18:01:30 +00:00
|
|
|
// gin::Wrappable
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
const char* GetTypeName() override;
|
2019-08-14 20:42:55 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
NativeTheme(const NativeTheme&) = delete;
|
|
|
|
NativeTheme& operator=(const NativeTheme&) = delete;
|
|
|
|
|
2019-08-14 20:42:55 +00:00
|
|
|
protected:
|
2020-03-30 22:39:50 +00:00
|
|
|
NativeTheme(v8::Isolate* isolate,
|
|
|
|
ui::NativeTheme* ui_theme,
|
|
|
|
ui::NativeTheme* web_theme);
|
2019-08-14 20:42:55 +00:00
|
|
|
~NativeTheme() override;
|
|
|
|
|
2019-09-05 17:57:04 +00:00
|
|
|
void SetThemeSource(ui::NativeTheme::ThemeSource override);
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-09-05 17:57:04 +00:00
|
|
|
void UpdateMacOSAppearanceForOverrideValue(
|
|
|
|
ui::NativeTheme::ThemeSource override);
|
|
|
|
#endif
|
|
|
|
ui::NativeTheme::ThemeSource GetThemeSource() const;
|
2019-08-14 20:42:55 +00:00
|
|
|
bool ShouldUseDarkColors();
|
|
|
|
bool ShouldUseHighContrastColors();
|
|
|
|
bool ShouldUseInvertedColorScheme();
|
2022-03-21 09:30:02 +00:00
|
|
|
bool InForcedColorsMode();
|
2019-08-14 20:42:55 +00:00
|
|
|
|
|
|
|
// ui::NativeThemeObserver:
|
|
|
|
void OnNativeThemeUpdated(ui::NativeTheme* theme) override;
|
2019-09-16 23:08:01 +00:00
|
|
|
void OnNativeThemeUpdatedOnUI();
|
2019-08-14 20:42:55 +00:00
|
|
|
|
|
|
|
private:
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<ui::NativeTheme> ui_theme_;
|
|
|
|
raw_ptr<ui::NativeTheme> web_theme_;
|
2019-08-14 20:42:55 +00:00
|
|
|
};
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api
|
2019-08-14 20:42:55 +00:00
|
|
|
|
2019-10-02 00:30:55 +00:00
|
|
|
namespace gin {
|
2019-09-05 17:57:04 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct Converter<ui::NativeTheme::ThemeSource> {
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
const ui::NativeTheme::ThemeSource& val);
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
ui::NativeTheme::ThemeSource* out);
|
|
|
|
};
|
|
|
|
|
2019-10-02 00:30:55 +00:00
|
|
|
} // namespace gin
|
2019-09-05 17:57:04 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NATIVE_THEME_H_
|