#include "extensions/shell/browser/shell_desktop_controller_aura.h"
#include <memory>
#include <string>
#include "base/check_op.h"
#include "base/memory/raw_ptr.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "build/chromeos_buildflags.h"
#include "components/keep_alive_registry/keep_alive_registry.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/native_app_window.h"
#include "extensions/shell/browser/shell_app_window_client.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/client/cursor_shape_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
#include "ui/base/ime/init/input_method_factory.h"
#include "ui/base/ime/input_method.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/wm/core/base_focus_rules.h"
#include "ui/wm/core/compound_event_filter.h"
#include "ui/wm/core/cursor_loader.h"
#include "ui/wm/core/cursor_manager.h"
#include "ui/wm/core/focus_controller.h"
#include "ui/wm/core/native_cursor_manager.h"
#include "ui/wm/core/native_cursor_manager_delegate.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "base/command_line.h"
#include "chromeos/dbus/power/power_manager_client.h"
#include "extensions/shell/browser/shell_screen.h"
#include "extensions/shell/common/switches.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/user_activity/user_activity_detector.h"
#include "ui/chromeos/user_activity_power_manager_notifier.h"
#include "ui/display/types/display_mode.h"
#include "ui/display/types/display_snapshot.h"
#include "ui/display/types/native_display_delegate.h"
#include "ui/ozone/public/ozone_platform.h"
#else
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#endif
namespace extensions {
namespace {
class ShellNativeCursorManager : public wm::NativeCursorManager { … };
class AppsFocusRules : public wm::BaseFocusRules { … };
}
ShellDesktopControllerAura::ShellDesktopControllerAura(
content::BrowserContext* browser_context)
: … { … }
ShellDesktopControllerAura::~ShellDesktopControllerAura() { … }
void ShellDesktopControllerAura::PreMainMessageLoopRun() { … }
void ShellDesktopControllerAura::WillRunMainMessageLoop(
std::unique_ptr<base::RunLoop>& run_loop) { … }
void ShellDesktopControllerAura::PostMainMessageLoopRun() { … }
void ShellDesktopControllerAura::AddAppWindow(AppWindow* app_window,
gfx::NativeWindow window) { … }
void ShellDesktopControllerAura::CloseAppWindows() { … }
void ShellDesktopControllerAura::CloseRootWindowController(
RootWindowController* root_window_controller) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void ShellDesktopControllerAura::PowerButtonEventReceived(
bool down,
base::TimeTicks timestamp) {
if (down) {
chromeos::PowerManagerClient::Get()->RequestShutdown(
power_manager::REQUEST_SHUTDOWN_FOR_USER, "AppShell power button");
}
}
void ShellDesktopControllerAura::OnDisplayConfigurationChanged(
const display::DisplayConfigurator::DisplayStateList& displays) {
for (const display::DisplaySnapshot* display_mode : displays) {
if (!display_mode->current_mode())
continue;
auto it = root_window_controllers_.find(display_mode->display_id());
if (it != root_window_controllers_.end())
it->second->UpdateSize(display_mode->current_mode()->size());
}
}
#endif
ui::EventDispatchDetails ShellDesktopControllerAura::DispatchKeyEventPostIME(
ui::KeyEvent* key_event) { … }
void ShellDesktopControllerAura::OnKeepAliveStateChanged(
bool is_keeping_alive) { … }
void ShellDesktopControllerAura::OnKeepAliveRestartStateChanged(
bool can_restart) { … }
aura::WindowTreeHost* ShellDesktopControllerAura::GetPrimaryHost() { … }
aura::Window::Windows ShellDesktopControllerAura::GetAllRootWindows() { … }
void ShellDesktopControllerAura::SetWindowBoundsInScreen(
AppWindow* app_window,
const gfx::Rect& bounds) { … }
void ShellDesktopControllerAura::InitWindowManager() { … }
void ShellDesktopControllerAura::TearDownWindowManager() { … }
std::unique_ptr<RootWindowController>
ShellDesktopControllerAura::CreateRootWindowControllerForDisplay(
const display::Display& display) { … }
void ShellDesktopControllerAura::TearDownRootWindowController(
RootWindowController* root) { … }
void ShellDesktopControllerAura::MaybeQuit() { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
gfx::Size ShellDesktopControllerAura::GetStartingWindowSize() {
gfx::Size size = GetPrimaryDisplaySize();
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kAppShellHostWindowSize)) {
const std::string size_str =
command_line->GetSwitchValueASCII(switches::kAppShellHostWindowSize);
int width, height;
CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
size = gfx::Size(width, height);
}
return size.IsEmpty() ? gfx::Size(1920, 1080) : size;
}
gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() {
const display::DisplayConfigurator::DisplayStateList& displays =
display_configurator_->cached_displays();
const display::DisplayMode* mode =
displays.empty() ? nullptr : displays[0]->current_mode();
return mode ? mode->size() : gfx::Size();
}
#endif
}