#include "ui/views/widget/desktop_aura/desktop_window_tree_host_platform.h"
#include <memory>
#include <string>
#include <utility>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/client/transient_window_client.h"
#include "ui/aura/native_window_occlusion_tracker.h"
#include "ui/base/hit_test.h"
#include "ui/base/owned_window_anchor.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_types.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/display/types/display_constants.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/platform_window/extensions/workspace_extension.h"
#include "ui/platform_window/platform_window.h"
#include "ui/platform_window/platform_window_delegate.h"
#include "ui/platform_window/platform_window_init_properties.h"
#include "ui/platform_window/wm/wm_move_loop_handler.h"
#include "ui/views/corewm/tooltip_controller.h"
#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/widget/widget_aura_utils.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/window/native_frame_view.h"
#include "ui/wm/core/window_properties.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/public/window_move_client.h"
#if BUILDFLAG(IS_LINUX)
#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone_linux.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "ui/views/corewm/tooltip_lacros.h"
#else
#include "ui/views/corewm/tooltip_aura.h"
#endif
DEFINE_UI_CLASS_PROPERTY_TYPE(…)
namespace views {
DEFINE_UI_CLASS_PROPERTY_KEY(…)
namespace {
std::list<gfx::AcceleratedWidget>* open_windows_ = …;
bool DetermineInactivity(ui::WindowShowState show_state) { … }
ui::PlatformWindowOpacity GetPlatformWindowOpacity(
Widget::InitParams::WindowOpacity opacity) { … }
ui::PlatformWindowType GetPlatformWindowType(
Widget::InitParams::Type window_type) { … }
ui::PlatformWindowShadowType GetPlatformWindowShadowType(
Widget::InitParams::ShadowType shadow_type) { … }
ui::PlatformWindowInitProperties ConvertWidgetInitParamsToInitProperties(
const Widget::InitParams& params) { … }
SkPath GetWindowMask(const Widget* widget) { … }
}
DesktopWindowTreeHostPlatform::DesktopWindowTreeHostPlatform(
internal::NativeWidgetDelegate* native_widget_delegate,
DesktopNativeWidgetAura* desktop_native_widget_aura)
: … { … }
DesktopWindowTreeHostPlatform::~DesktopWindowTreeHostPlatform() { … }
aura::Window* DesktopWindowTreeHostPlatform::GetContentWindowForWidget(
gfx::AcceleratedWidget widget) { … }
DesktopWindowTreeHostPlatform* DesktopWindowTreeHostPlatform::GetHostForWidget(
gfx::AcceleratedWidget widget) { … }
std::vector<aura::Window*> DesktopWindowTreeHostPlatform::GetAllOpenWindows() { … }
void DesktopWindowTreeHostPlatform::CleanUpWindowList(
void (*func)(aura::Window* window)) { … }
aura::Window* DesktopWindowTreeHostPlatform::GetContentWindow() { … }
void DesktopWindowTreeHostPlatform::Init(const Widget::InitParams& params) { … }
void DesktopWindowTreeHostPlatform::OnNativeWidgetCreated(
const Widget::InitParams& params) { … }
void DesktopWindowTreeHostPlatform::OnWidgetInitDone() { … }
void DesktopWindowTreeHostPlatform::OnActiveWindowChanged(bool active) { … }
std::unique_ptr<corewm::Tooltip>
DesktopWindowTreeHostPlatform::CreateTooltip() { … }
std::unique_ptr<aura::client::DragDropClient>
DesktopWindowTreeHostPlatform::CreateDragDropClient() { … }
void DesktopWindowTreeHostPlatform::Close() { … }
void DesktopWindowTreeHostPlatform::CloseNow() { … }
aura::WindowTreeHost* DesktopWindowTreeHostPlatform::AsWindowTreeHost() { … }
void DesktopWindowTreeHostPlatform::Show(ui::WindowShowState show_state,
const gfx::Rect& restore_bounds) { … }
bool DesktopWindowTreeHostPlatform::IsVisible() const { … }
void DesktopWindowTreeHostPlatform::SetSize(const gfx::Size& size) { … }
void DesktopWindowTreeHostPlatform::StackAbove(aura::Window* window) { … }
void DesktopWindowTreeHostPlatform::StackAtTop() { … }
bool DesktopWindowTreeHostPlatform::IsStackedAbove(aura::Window* window) { … }
void DesktopWindowTreeHostPlatform::CenterWindow(const gfx::Size& size) { … }
void DesktopWindowTreeHostPlatform::GetWindowPlacement(
gfx::Rect* bounds,
ui::WindowShowState* show_state) const { … }
gfx::Rect DesktopWindowTreeHostPlatform::GetWindowBoundsInScreen() const { … }
gfx::Rect DesktopWindowTreeHostPlatform::GetClientAreaBoundsInScreen() const { … }
gfx::Rect DesktopWindowTreeHostPlatform::GetRestoredBounds() const { … }
std::string DesktopWindowTreeHostPlatform::GetWorkspace() const { … }
gfx::Rect DesktopWindowTreeHostPlatform::GetWorkAreaBoundsInScreen() const { … }
void DesktopWindowTreeHostPlatform::SetShape(
std::unique_ptr<Widget::ShapeRects> native_shape) { … }
void DesktopWindowTreeHostPlatform::SetParent(gfx::AcceleratedWidget parent) { … }
void DesktopWindowTreeHostPlatform::Activate() { … }
void DesktopWindowTreeHostPlatform::Deactivate() { … }
bool DesktopWindowTreeHostPlatform::IsActive() const { … }
void DesktopWindowTreeHostPlatform::Maximize() { … }
void DesktopWindowTreeHostPlatform::Minimize() { … }
void DesktopWindowTreeHostPlatform::Restore() { … }
bool DesktopWindowTreeHostPlatform::IsMaximized() const { … }
bool DesktopWindowTreeHostPlatform::IsMinimized() const { … }
bool DesktopWindowTreeHostPlatform::HasCapture() const { … }
void DesktopWindowTreeHostPlatform::SetZOrderLevel(ui::ZOrderLevel order) { … }
ui::ZOrderLevel DesktopWindowTreeHostPlatform::GetZOrderLevel() const { … }
void DesktopWindowTreeHostPlatform::SetVisibleOnAllWorkspaces(
bool always_visible) { … }
bool DesktopWindowTreeHostPlatform::IsVisibleOnAllWorkspaces() const { … }
bool DesktopWindowTreeHostPlatform::SetWindowTitle(
const std::u16string& title) { … }
void DesktopWindowTreeHostPlatform::ClearNativeFocus() { … }
bool DesktopWindowTreeHostPlatform::IsMoveLoopSupported() const { … }
Widget::MoveLoopResult DesktopWindowTreeHostPlatform::RunMoveLoop(
const gfx::Vector2d& drag_offset,
Widget::MoveLoopSource source,
Widget::MoveLoopEscapeBehavior escape_behavior) { … }
void DesktopWindowTreeHostPlatform::EndMoveLoop() { … }
void DesktopWindowTreeHostPlatform::SetVisibilityChangedAnimationsEnabled(
bool value) { … }
std::unique_ptr<NonClientFrameView>
DesktopWindowTreeHostPlatform::CreateNonClientFrameView() { … }
bool DesktopWindowTreeHostPlatform::ShouldUseNativeFrame() const { … }
bool DesktopWindowTreeHostPlatform::ShouldWindowContentsBeTransparent() const { … }
void DesktopWindowTreeHostPlatform::FrameTypeChanged() { … }
void DesktopWindowTreeHostPlatform::SetFullscreen(bool fullscreen,
int64_t target_display_id) { … }
bool DesktopWindowTreeHostPlatform::IsFullscreen() const { … }
void DesktopWindowTreeHostPlatform::SetOpacity(float opacity) { … }
void DesktopWindowTreeHostPlatform::SetAspectRatio(
const gfx::SizeF& aspect_ratio,
const gfx::Size& excluded_margin) { … }
void DesktopWindowTreeHostPlatform::SetWindowIcons(
const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) { … }
void DesktopWindowTreeHostPlatform::InitModalType(
ui::mojom::ModalType modal_type) { … }
void DesktopWindowTreeHostPlatform::FlashFrame(bool flash_frame) { … }
bool DesktopWindowTreeHostPlatform::IsAnimatingClosed() const { … }
void DesktopWindowTreeHostPlatform::SizeConstraintsChanged() { … }
bool DesktopWindowTreeHostPlatform::ShouldUpdateWindowTransparency() const { … }
bool DesktopWindowTreeHostPlatform::ShouldUseDesktopNativeCursorManager()
const { … }
bool DesktopWindowTreeHostPlatform::ShouldCreateVisibilityController() const { … }
void DesktopWindowTreeHostPlatform::UpdateWindowShapeIfNeeded(
const ui::PaintContext& context) { … }
void DesktopWindowTreeHostPlatform::SetBoundsInDIP(const gfx::Rect& bounds) { … }
void DesktopWindowTreeHostPlatform::SetAllowScreenshots(bool allow) { … }
bool DesktopWindowTreeHostPlatform::AreScreenshotsAllowed() { … }
gfx::Transform DesktopWindowTreeHostPlatform::GetRootTransform() const { … }
void DesktopWindowTreeHostPlatform::ShowImpl() { … }
void DesktopWindowTreeHostPlatform::HideImpl() { … }
gfx::Rect DesktopWindowTreeHostPlatform::CalculateRootWindowBounds() const { … }
gfx::Rect DesktopWindowTreeHostPlatform::GetBoundsInDIP() const { … }
void DesktopWindowTreeHostPlatform::OnCompositorVisibilityChanging(
ui::Compositor* compositor,
bool visible) { … }
void DesktopWindowTreeHostPlatform::OnCompositorVisibilityChanged(
ui::Compositor* compositor,
bool visible) { … }
gfx::Insets DesktopWindowTreeHostPlatform::CalculateInsetsInDIP(
ui::PlatformWindowState window_state) const { … }
void DesktopWindowTreeHostPlatform::OnClosed() { … }
void DesktopWindowTreeHostPlatform::OnWindowStateChanged(
ui::PlatformWindowState old_state,
ui::PlatformWindowState new_state) { … }
void DesktopWindowTreeHostPlatform::OnCloseRequest() { … }
void DesktopWindowTreeHostPlatform::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) { … }
void DesktopWindowTreeHostPlatform::OnWillDestroyAcceleratedWidget() { … }
bool DesktopWindowTreeHostPlatform::OnRotateFocus(
ui::PlatformWindowDelegate::RotateDirection direction,
bool reset) { … }
void DesktopWindowTreeHostPlatform::OnActivationChanged(bool active) { … }
std::optional<gfx::Size>
DesktopWindowTreeHostPlatform::GetMinimumSizeForWindow() const { … }
std::optional<gfx::Size>
DesktopWindowTreeHostPlatform::GetMaximumSizeForWindow() const { … }
bool DesktopWindowTreeHostPlatform::CanMaximize() const { … }
bool DesktopWindowTreeHostPlatform::CanFullscreen() const { … }
SkPath DesktopWindowTreeHostPlatform::GetWindowMaskForWindowShapeInPixels() { … }
std::optional<ui::OwnedWindowAnchor>
DesktopWindowTreeHostPlatform::GetOwnedWindowAnchorAndRectInDIP() { … }
gfx::Rect DesktopWindowTreeHostPlatform::ConvertRectToPixels(
const gfx::Rect& rect_in_dip) const { … }
gfx::Rect DesktopWindowTreeHostPlatform::ConvertRectToDIP(
const gfx::Rect& rect_in_pixels) const { … }
gfx::PointF DesktopWindowTreeHostPlatform::ConvertScreenPointToLocalDIP(
const gfx::Point& screen_in_pixels) const { … }
gfx::Insets DesktopWindowTreeHostPlatform::ConvertInsetsToPixels(
const gfx::Insets& insets_dip) const { … }
void DesktopWindowTreeHostPlatform::OnWorkspaceChanged() { … }
gfx::Rect DesktopWindowTreeHostPlatform::ToDIPRect(
const gfx::Rect& rect_in_pixels) const { … }
gfx::Rect DesktopWindowTreeHostPlatform::ToPixelRect(
const gfx::Rect& rect_in_dip) const { … }
Widget* DesktopWindowTreeHostPlatform::GetWidget() { … }
const Widget* DesktopWindowTreeHostPlatform::GetWidget() const { … }
views::corewm::TooltipController*
DesktopWindowTreeHostPlatform::tooltip_controller() { … }
void DesktopWindowTreeHostPlatform::ScheduleRelayout() { … }
void DesktopWindowTreeHostPlatform::SetVisible(bool visible) { … }
void DesktopWindowTreeHostPlatform::AddAdditionalInitProperties(
const Widget::InitParams& params,
ui::PlatformWindowInitProperties* properties) { … }
SkPath DesktopWindowTreeHostPlatform::GetWindowMaskForClipping() const { … }
display::Display DesktopWindowTreeHostPlatform::GetDisplayNearestRootWindow()
const { … }
bool DesktopWindowTreeHostPlatform::RotateFocusForWidget(
Widget& widget,
ui::PlatformWindowDelegate::RotateDirection direction,
bool reset) { … }
#if !BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS)
DesktopWindowTreeHost* DesktopWindowTreeHost::Create(
internal::NativeWidgetDelegate* native_widget_delegate,
DesktopNativeWidgetAura* desktop_native_widget_aura) {
return new DesktopWindowTreeHostPlatform(native_widget_delegate,
desktop_native_widget_aura);
}
#endif
std::list<gfx::AcceleratedWidget>&
DesktopWindowTreeHostPlatform::open_windows() { … }
bool DesktopWindowTreeHostPlatform::has_open_windows() { … }
}