#ifndef EXTENSIONS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_AURA_H_
#define EXTENSIONS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_AURA_H_
#include <map>
#include <memory>
#include "base/compiler_specific.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/keep_alive_registry/keep_alive_state_observer.h"
#include "extensions/shell/browser/desktop_controller.h"
#include "extensions/shell/browser/root_window_controller.h"
#include "ui/aura/window.h"
#include "ui/base/ime/ime_key_event_dispatcher.h"
#include "ui/display/display.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/dbus/power/power_manager_client.h"
#include "ui/display/manager/display_configurator.h"
#endif
namespace aura {
class WindowTreeHost;
}
namespace content {
class BrowserContext;
}
namespace display {
class Screen;
}
namespace gfx {
class Size;
}
namespace ui {
class InputMethod;
#if BUILDFLAG(IS_CHROMEOS)
class UserActivityPowerManagerNotifier;
#endif
}
namespace wm {
class CompoundEventFilter;
class CursorManager;
class FocusController;
}
namespace extensions {
class AppWindowClient;
class ShellDesktopControllerAura
: public DesktopController,
public RootWindowController::DesktopDelegate,
#if BUILDFLAG(IS_CHROMEOS)
public chromeos::PowerManagerClient::Observer,
public display::DisplayConfigurator::Observer,
#endif
public ui::ImeKeyEventDispatcher,
public KeepAliveStateObserver {
public:
explicit ShellDesktopControllerAura(content::BrowserContext* browser_context);
ShellDesktopControllerAura(const ShellDesktopControllerAura&) = delete;
ShellDesktopControllerAura& operator=(const ShellDesktopControllerAura&) =
delete;
~ShellDesktopControllerAura() override;
void PreMainMessageLoopRun() override;
void WillRunMainMessageLoop(
std::unique_ptr<base::RunLoop>& run_loop) override;
void PostMainMessageLoopRun() override;
void AddAppWindow(AppWindow* app_window, gfx::NativeWindow window) override;
void CloseAppWindows() override;
void CloseRootWindowController(
RootWindowController* root_window_controller) override;
#if BUILDFLAG(IS_CHROMEOS)
void PowerButtonEventReceived(bool down, base::TimeTicks timestamp) override;
void OnDisplayConfigurationChanged(
const display::DisplayConfigurator::DisplayStateList& displays) override;
#endif
ui::EventDispatchDetails DispatchKeyEventPostIME(
ui::KeyEvent* key_event) override;
void OnKeepAliveStateChanged(bool is_keeping_alive) override;
void OnKeepAliveRestartStateChanged(bool can_restart) override;
aura::WindowTreeHost* GetPrimaryHost();
aura::Window::Windows GetAllRootWindows();
void SetWindowBoundsInScreen(AppWindow* app_window, const gfx::Rect& bounds);
protected:
virtual void InitWindowManager();
virtual void TearDownWindowManager();
private:
std::unique_ptr<RootWindowController> CreateRootWindowControllerForDisplay(
const display::Display& display);
void TearDownRootWindowController(RootWindowController* root);
void MaybeQuit();
#if BUILDFLAG(IS_CHROMEOS)
gfx::Size GetStartingWindowSize();
gfx::Size GetPrimaryDisplaySize();
#endif
const raw_ptr<content::BrowserContext> browser_context_;
#if BUILDFLAG(IS_CHROMEOS)
std::unique_ptr<display::DisplayConfigurator> display_configurator_;
#endif
std::unique_ptr<display::Screen> screen_;
std::unique_ptr<wm::CompoundEventFilter> root_window_event_filter_;
std::map<int64_t, std::unique_ptr<RootWindowController>>
root_window_controllers_;
std::unique_ptr<ui::InputMethod> input_method_;
std::unique_ptr<wm::FocusController> focus_controller_;
std::unique_ptr<wm::CursorManager> cursor_manager_;
#if BUILDFLAG(IS_CHROMEOS)
std::unique_ptr<ui::UserActivityPowerManagerNotifier> user_activity_notifier_;
#endif
std::unique_ptr<AppWindowClient> app_window_client_;
std::list<raw_ptr<AppWindow, CtnExperimental>> app_windows_;
base::OnceClosure quit_when_idle_closure_;
};
}
#endif