cef/libcef/browser/alloy/alloy_browser_main.h

113 lines
3.3 KiB
C
Raw Normal View History

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_MAIN_H_
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_MAIN_H_
#pragma once
#include <string_view>
#include "base/command_line.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "cef/libcef/browser/request_context_impl.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_main_parts.h"
#include "ui/display/screen.h"
#if defined(USE_AURA)
namespace wm {
class WMState;
}
#endif
namespace views {
class ViewsDelegate;
#if BUILDFLAG(IS_MAC)
class LayoutProvider;
#endif
} // namespace views
#if BUILDFLAG(IS_LINUX)
namespace ui {
class LinuxUiGetter;
views: Add support for OS and Chrome themes (fixes #3610, fixes #3671) Controls now respect OS and Chrome themes by default for both Alloy and Chrome runtimes. Chrome themes (mode and colors) can be configured using the new CefRequestContext::SetChromeColorScheme method. Individual theme colors can be overridden using the new CefWindowDelegate:: OnThemeColorsChanged and CefWindow::SetThemeColor methods. The `--force-light-mode` and `--force-dark-mode` command-line flags are now respected on all platforms as an override for the OS theme. The current Chrome theme, if any, will take precedence over the OS theme when determining light/dark status. On Windows and MacOS the titlebar color will also be updated to match the light/dark theme. Testable as follows: - Run: `cefclient --enable-chrome-runtime` OR `cefclient --use-views --persist-user-preferences --cache-path=...` - App launches with default OS light/dark theme colors. - Change OS dark/light theme under system settings. Notice that theme colors change as expected. - Right click, select items from the new Theme sub-menu. Notice that theme colors behave as expected. - Exit and relaunch the app. Notice that the last-used theme colors are applied on app restart. - Add `--background-color=green` to above command-line. - Perform the same actions as above. Notice that all controls start and remain green throughout (except some icons with Chrome runtime). - Add `--force-light-mode` or `--force-dark-mode` to above command-line. - Perform the same actions as above. Notice that OS dark/light theme changes are ignored, but Chrome theme changes work as expected.
2024-03-29 17:48:33 +01:00
#if defined(USE_DBUS)
class DarkModeManagerLinux;
#endif
} // namespace ui
#endif
class CefDevToolsDelegate;
class AlloyBrowserMainParts : public content::BrowserMainParts {
public:
AlloyBrowserMainParts();
AlloyBrowserMainParts(const AlloyBrowserMainParts&) = delete;
AlloyBrowserMainParts& operator=(const AlloyBrowserMainParts&) = delete;
~AlloyBrowserMainParts() override;
void ToolkitInitialized() override;
void PreCreateMainMessageLoop() override;
void PostCreateMainMessageLoop() override;
int PreCreateThreads() override;
void PostCreateThreads() override;
int PreMainMessageLoopRun() override;
void PostMainMessageLoopRun() override;
void PostDestroyThreads() override;
CefRefPtr<CefRequestContextImpl> request_context() const {
return global_request_context_;
}
CefDevToolsDelegate* devtools_delegate() const { return devtools_delegate_; }
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner() const {
return background_task_runner_;
}
scoped_refptr<base::SingleThreadTaskRunner> user_visible_task_runner() const {
return user_visible_task_runner_;
}
scoped_refptr<base::SingleThreadTaskRunner> user_blocking_task_runner()
const {
return user_blocking_task_runner_;
}
private:
#if BUILDFLAG(IS_WIN)
void PlatformInitialize();
#endif // BUILDFLAG(IS_WIN)
CefRefPtr<CefRequestContextImpl> global_request_context_;
raw_ptr<CefDevToolsDelegate> devtools_delegate_ = nullptr; // Deletes itself.
// Blocking task runners exposed via CefTaskRunner. For consistency with
// previous named thread behavior always execute all pending tasks before
// shutdown (e.g. to make sure critical data is saved to disk).
// |background_task_runner_| is also passed to SQLitePersistentCookieStore.
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> user_visible_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> user_blocking_task_runner_;
#if defined(USE_AURA)
std::unique_ptr<display::Screen> screen_;
std::unique_ptr<wm::WMState> wm_state_;
#endif
std::unique_ptr<views::ViewsDelegate> views_delegate_;
#if BUILDFLAG(IS_MAC)
std::unique_ptr<display::ScopedNativeScreen> screen_;
std::unique_ptr<views::LayoutProvider> layout_provider_;
#endif
#if BUILDFLAG(IS_LINUX)
std::unique_ptr<ui::LinuxUiGetter> linux_ui_getter_;
views: Add support for OS and Chrome themes (fixes #3610, fixes #3671) Controls now respect OS and Chrome themes by default for both Alloy and Chrome runtimes. Chrome themes (mode and colors) can be configured using the new CefRequestContext::SetChromeColorScheme method. Individual theme colors can be overridden using the new CefWindowDelegate:: OnThemeColorsChanged and CefWindow::SetThemeColor methods. The `--force-light-mode` and `--force-dark-mode` command-line flags are now respected on all platforms as an override for the OS theme. The current Chrome theme, if any, will take precedence over the OS theme when determining light/dark status. On Windows and MacOS the titlebar color will also be updated to match the light/dark theme. Testable as follows: - Run: `cefclient --enable-chrome-runtime` OR `cefclient --use-views --persist-user-preferences --cache-path=...` - App launches with default OS light/dark theme colors. - Change OS dark/light theme under system settings. Notice that theme colors change as expected. - Right click, select items from the new Theme sub-menu. Notice that theme colors behave as expected. - Exit and relaunch the app. Notice that the last-used theme colors are applied on app restart. - Add `--background-color=green` to above command-line. - Perform the same actions as above. Notice that all controls start and remain green throughout (except some icons with Chrome runtime). - Add `--force-light-mode` or `--force-dark-mode` to above command-line. - Perform the same actions as above. Notice that OS dark/light theme changes are ignored, but Chrome theme changes work as expected.
2024-03-29 17:48:33 +01:00
#if defined(USE_DBUS)
std::unique_ptr<ui::DarkModeManagerLinux> dark_mode_manager_;
#endif
#endif
};
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_MAIN_H_