Commit 543a7657 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

X11 and Ozone: Move initialization to DWTHPlatform

This CL moves the initialization of the X11Window aka PlatformWindow
to the DWTHPlatform and let the WTHPlatform to own the window instead.

Also, instead of storing of XID in open_windows_, we store
AcceleratedWidget now, which is ok as XID and AcceleratedWidget
have the same type and it has already been used around the code.

In the follow up CLs, I will start moving all the other codes from
DWTHX11 and add extend the existing PlatformWindow interface in
order to be able stop accessing the XWindow directly from the
DWTHX11.

Also, AdjustSize and GetRootTransform have been moved to DWTHPlatform
and declared as protected so that DWTHX11 could access them. What is
more, the ToPixelRect and ToDIPRect have been removed from DWTHX11 as
the DWTHPlatform has already had those methods.

Bug: 990756
Change-Id: I077773fe3154d12696dcbfb606bb3eb3122c0936
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769442
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693093}
parent 2fee7fa7
...@@ -119,7 +119,7 @@ class DemoWindow : public ui::PlatformWindowDelegate { ...@@ -119,7 +119,7 @@ class DemoWindow : public ui::PlatformWindowDelegate {
#elif defined(OS_WIN) #elif defined(OS_WIN)
return std::make_unique<ui::WinWindow>(this, props.bounds); return std::make_unique<ui::WinWindow>(this, props.bounds);
#elif defined(USE_X11) #elif defined(USE_X11)
auto x11_window = std::make_unique<ui::X11Window>(this, nullptr); auto x11_window = std::make_unique<ui::X11Window>(this);
x11_window->Initialize(std::move(props)); x11_window->Initialize(std::move(props));
return x11_window; return x11_window;
#else #else
......
...@@ -44,7 +44,7 @@ void VulkanDemo::Initialize() { ...@@ -44,7 +44,7 @@ void VulkanDemo::Initialize() {
ui::PlatformWindowInitProperties properties; ui::PlatformWindowInitProperties properties;
properties.bounds = gfx::Rect(100, 100, 800, 600); properties.bounds = gfx::Rect(100, 100, 800, 600);
auto x11_window = std::make_unique<ui::X11Window>(this, nullptr); auto x11_window = std::make_unique<ui::X11Window>(this);
x11_window->Initialize(std::move(properties)); x11_window->Initialize(std::move(properties));
window_ = std::move(x11_window); window_ = std::move(x11_window);
......
...@@ -74,7 +74,7 @@ void WindowTreeHostPlatform::CreateAndSetPlatformWindow( ...@@ -74,7 +74,7 @@ void WindowTreeHostPlatform::CreateAndSetPlatformWindow(
#elif defined(OS_WIN) #elif defined(OS_WIN)
platform_window_.reset(new ui::WinWindow(this, properties.bounds)); platform_window_.reset(new ui::WinWindow(this, properties.bounds));
#elif defined(USE_X11) #elif defined(USE_X11)
auto x11_window = std::make_unique<ui::X11Window>(this, nullptr); auto x11_window = std::make_unique<ui::X11Window>(this);
x11_window->Initialize(std::move(properties)); x11_window->Initialize(std::move(properties));
SetPlatformWindow(std::move(x11_window)); SetPlatformWindow(std::move(x11_window));
#else #else
......
...@@ -25,7 +25,7 @@ namespace ui { ...@@ -25,7 +25,7 @@ namespace ui {
X11WindowOzone::X11WindowOzone(PlatformWindowDelegate* delegate, X11WindowOzone::X11WindowOzone(PlatformWindowDelegate* delegate,
X11WindowManagerOzone* window_manager) X11WindowManagerOzone* window_manager)
: X11Window(delegate, nullptr), window_manager_(window_manager) { : X11Window(delegate), window_manager_(window_manager) {
DCHECK(window_manager_); DCHECK(window_manager_);
// Set a class property key, which allows |this| to be used for interactive // Set a class property key, which allows |this| to be used for interactive
......
...@@ -73,18 +73,18 @@ struct PlatformWindowInitProperties { ...@@ -73,18 +73,18 @@ struct PlatformWindowInitProperties {
bool remove_standard_frame = false; bool remove_standard_frame = false;
std::string workspace; std::string workspace;
#if defined(USE_X11) #if defined(OS_LINUX)
// Only used by X11:
bool prefer_dark_theme = false; bool prefer_dark_theme = false;
gfx::ImageSkia* icon = nullptr; gfx::ImageSkia* icon = nullptr;
base::Optional<int> background_color; base::Optional<int> background_color;
#endif
// Specifies the res_name and res_class fields, // Specifies the res_name and res_class fields,
// respectively, of the WM_CLASS window property. Controls window grouping // respectively, of the WM_CLASS window property. Controls window grouping
// and desktop file matching in Linux window managers. // and desktop file matching in Linux window managers.
std::string wm_role_name; std::string wm_role_name;
std::string wm_class_name; std::string wm_class_name;
std::string wm_class_class; std::string wm_class_class;
#endif
}; };
} // namespace ui } // namespace ui
......
...@@ -71,10 +71,8 @@ ui::XWindow::Configuration ConvertInitPropertiesToXWindowConfig( ...@@ -71,10 +71,8 @@ ui::XWindow::Configuration ConvertInitPropertiesToXWindowConfig(
} // namespace } // namespace
X11Window::X11Window(PlatformWindowDelegateLinux* platform_window_delegate, X11Window::X11Window(PlatformWindowDelegateLinux* platform_window_delegate)
XEventDelegate* x_event_delegate) : platform_window_delegate_(platform_window_delegate) {}
: platform_window_delegate_(platform_window_delegate),
x_event_delegate_(x_event_delegate) {}
X11Window::~X11Window() { X11Window::~X11Window() {
PrepareForShutdown(); PrepareForShutdown();
...@@ -87,6 +85,11 @@ void X11Window::Initialize(PlatformWindowInitProperties properties) { ...@@ -87,6 +85,11 @@ void X11Window::Initialize(PlatformWindowInitProperties properties) {
Init(config); Init(config);
} }
void X11Window::SetXEventDelegate(XEventDelegate* delegate) {
DCHECK(!x_event_delegate_);
x_event_delegate_ = delegate;
}
void X11Window::Show() { void X11Window::Show() {
// TODO(msisov): pass inactivity to PlatformWindow::Show. // TODO(msisov): pass inactivity to PlatformWindow::Show.
XWindow::Map(false /* inactive */); XWindow::Map(false /* inactive */);
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
namespace ui { namespace ui {
class PlatformWindowDelegateLinux;
// Delegate interface used to communicate the X11PlatformWindow API client about // Delegate interface used to communicate the X11PlatformWindow API client about
// XEvents of interest. // XEvents of interest.
class X11_WINDOW_EXPORT XEventDelegate { class X11_WINDOW_EXPORT XEventDelegate {
...@@ -38,12 +36,13 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow, ...@@ -38,12 +36,13 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
public XWindow, public XWindow,
public PlatformEventDispatcher { public PlatformEventDispatcher {
public: public:
X11Window(PlatformWindowDelegateLinux* platform_window_delegate, explicit X11Window(PlatformWindowDelegateLinux* platform_window_delegate);
XEventDelegate* x_event_delegate);
~X11Window() override; ~X11Window() override;
void Initialize(PlatformWindowInitProperties properties); void Initialize(PlatformWindowInitProperties properties);
void SetXEventDelegate(XEventDelegate* delegate);
// PlatformWindow: // PlatformWindow:
void Show() override; void Show() override;
void Hide() override; void Hide() override;
...@@ -110,7 +109,7 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow, ...@@ -110,7 +109,7 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
PlatformWindowDelegateLinux* const platform_window_delegate_; PlatformWindowDelegateLinux* const platform_window_delegate_;
XEventDelegate* const x_event_delegate_; XEventDelegate* x_event_delegate_ = nullptr;
// Tells if the window got a ::Close call. // Tells if the window got a ::Close call.
bool is_shutting_down_ = false; bool is_shutting_down_ = false;
......
...@@ -756,8 +756,10 @@ jumbo_component("views") { ...@@ -756,8 +756,10 @@ jumbo_component("views") {
] ]
} }
if (is_linux) { if (is_linux) {
public += [ "widget/desktop_aura/desktop_window_tree_host_linux.h" ]
sources += [ sources += [
"style/platform_style_linux.cc", "style/platform_style_linux.cc",
"widget/desktop_aura/desktop_window_tree_host_linux.cc",
"widget/desktop_aura/window_event_filter.cc", "widget/desktop_aura/window_event_filter.cc",
"widget/desktop_aura/window_event_filter.h", "widget/desktop_aura/window_event_filter.h",
] ]
......
...@@ -19,13 +19,13 @@ class Window; ...@@ -19,13 +19,13 @@ class Window;
namespace client { namespace client {
class DragDropClient; class DragDropClient;
class ScreenPositionClient; class ScreenPositionClient;
} } // namespace client
} // namespace aura } // namespace aura
namespace gfx { namespace gfx {
class ImageSkia; class ImageSkia;
class Rect; class Rect;
} } // namespace gfx
namespace views { namespace views {
namespace corewm { namespace corewm {
......
// Copyright 2019 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.
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/platform_window/platform_window_init_properties.h"
#include "ui/views/linux_ui/linux_ui.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
namespace views {
DesktopWindowTreeHostLinux::DesktopWindowTreeHostLinux(
internal::NativeWidgetDelegate* native_widget_delegate,
DesktopNativeWidgetAura* desktop_native_widget_aura)
: DesktopWindowTreeHostPlatform(native_widget_delegate,
desktop_native_widget_aura) {}
DesktopWindowTreeHostLinux::~DesktopWindowTreeHostLinux() = default;
gfx::Size DesktopWindowTreeHostLinux::AdjustSizeForDisplay(
const gfx::Size& requested_size_in_pixels) {
std::vector<display::Display> displays =
display::Screen::GetScreen()->GetAllDisplays();
// Compare against all monitor sizes. The window manager can move the window
// to whichever monitor it wants.
for (const auto& display : displays) {
if (requested_size_in_pixels == display.GetSizeInPixel()) {
return gfx::Size(requested_size_in_pixels.width() - 1,
requested_size_in_pixels.height() - 1);
}
}
// Do not request a 0x0 window size. It causes an XError.
gfx::Size size_in_pixels = requested_size_in_pixels;
size_in_pixels.SetToMax(gfx::Size(1, 1));
return size_in_pixels;
}
void DesktopWindowTreeHostLinux::AddAdditionalInitProperties(
ui::PlatformWindowInitProperties* properties) {
// Calculate initial bounds
gfx::Rect bounds_in_pixels = ToPixelRect(properties->bounds);
gfx::Size adjusted_size = AdjustSizeForDisplay(bounds_in_pixels.size());
bounds_in_pixels.set_size(adjusted_size);
properties->bounds = bounds_in_pixels;
// Set the background color on startup to make the initial flickering
// happening between the XWindow is mapped and the first expose event
// is completely handled less annoying. If possible, we use the content
// window's background color, otherwise we fallback to white.
base::Optional<int> background_color;
const views::LinuxUI* linux_ui = views::LinuxUI::instance();
if (linux_ui && content_window()) {
ui::NativeTheme::ColorId target_color;
switch (properties->type) {
case ui::PlatformWindowType::kBubble:
target_color = ui::NativeTheme::kColorId_BubbleBackground;
break;
case ui::PlatformWindowType::kTooltip:
target_color = ui::NativeTheme::kColorId_TooltipBackground;
break;
default:
target_color = ui::NativeTheme::kColorId_WindowBackground;
break;
}
ui::NativeTheme* theme = linux_ui->GetNativeTheme(content_window());
background_color = theme->GetSystemColor(target_color);
}
properties->prefer_dark_theme = linux_ui && linux_ui->PreferDarkTheme();
properties->background_color = background_color;
properties->icon = ViewsDelegate::GetInstance()->GetDefaultWindowIcon();
}
} // namespace views
// Copyright 2019 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 UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_LINUX_H_
#define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_LINUX_H_
#include "base/macros.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_platform.h"
namespace views {
// Contains Linux specific implementation.
class VIEWS_EXPORT DesktopWindowTreeHostLinux
: public DesktopWindowTreeHostPlatform {
public:
DesktopWindowTreeHostLinux(
internal::NativeWidgetDelegate* native_widget_delegate,
DesktopNativeWidgetAura* desktop_native_widget_aura);
~DesktopWindowTreeHostLinux() override;
protected:
// Adjusts |requested_size| to avoid the WM "feature" where setting the
// window size to the monitor size causes the WM to set the EWMH for
// fullscreen.
//
// TODO(https://crbug.com/990756)): this method is mainly for X11
// impl (Wayland does not need this workaround). Move this to X11Window
// instead. We can't do it now as there are some methods that depend on this.
gfx::Size AdjustSizeForDisplay(const gfx::Size& requested_size_in_pixels);
private:
// DesktopWindowTreeHostPlatform overrides:
void AddAdditionalInitProperties(
ui::PlatformWindowInitProperties* properties) override;
DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostLinux);
};
} // namespace views
#endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_LINUX_H_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/drag_drop_client.h" #include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/transient_window_client.h" #include "ui/aura/client/transient_window_client.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
...@@ -26,6 +27,71 @@ ...@@ -26,6 +27,71 @@
namespace views { namespace views {
namespace {
ui::PlatformWindowInitProperties ConvertWidgetInitParamsToInitProperties(
const Widget::InitParams& params) {
ui::PlatformWindowInitProperties properties;
switch (params.type) {
case Widget::InitParams::TYPE_WINDOW:
properties.type = ui::PlatformWindowType::kWindow;
break;
case Widget::InitParams::TYPE_MENU:
properties.type = ui::PlatformWindowType::kMenu;
break;
case Widget::InitParams::TYPE_TOOLTIP:
properties.type = ui::PlatformWindowType::kTooltip;
break;
case Widget::InitParams::TYPE_DRAG:
properties.type = ui::PlatformWindowType::kDrag;
break;
case Widget::InitParams::TYPE_BUBBLE:
properties.type = ui::PlatformWindowType::kBubble;
break;
default:
properties.type = ui::PlatformWindowType::kPopup;
break;
}
properties.bounds = params.bounds;
properties.activatable =
params.activatable == Widget::InitParams::ACTIVATABLE_YES;
properties.force_show_in_taskbar = params.force_show_in_taskbar;
properties.keep_on_top =
params.EffectiveZOrderLevel() != ui::ZOrderLevel::kNormal;
properties.visible_on_all_workspaces = params.visible_on_all_workspaces;
properties.remove_standard_frame = params.remove_standard_frame;
properties.workspace = params.workspace;
properties.wm_class_name = params.wm_class_name;
properties.wm_class_class = params.wm_class_class;
properties.wm_role_name = params.wm_role_name;
if (params.parent && params.parent->GetHost())
properties.parent_widget = params.parent->GetHost()->GetAcceleratedWidget();
switch (params.opacity) {
case Widget::InitParams::WindowOpacity::INFER_OPACITY:
properties.opacity = ui::PlatformWindowOpacity::kInferOpacity;
break;
case Widget::InitParams::WindowOpacity::OPAQUE_WINDOW:
properties.opacity = ui::PlatformWindowOpacity::kOpaqueWindow;
break;
case Widget::InitParams::WindowOpacity::TRANSLUCENT_WINDOW:
properties.opacity = ui::PlatformWindowOpacity::kTranslucentWindow;
break;
}
return properties;
}
} // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostPlatform: // DesktopWindowTreeHostPlatform:
...@@ -46,15 +112,22 @@ DesktopWindowTreeHostPlatform::~DesktopWindowTreeHostPlatform() { ...@@ -46,15 +112,22 @@ DesktopWindowTreeHostPlatform::~DesktopWindowTreeHostPlatform() {
} }
void DesktopWindowTreeHostPlatform::Init(const Widget::InitParams& params) { void DesktopWindowTreeHostPlatform::Init(const Widget::InitParams& params) {
if (params.type == Widget::InitParams::TYPE_WINDOW)
content_window()->SetProperty(aura::client::kAnimationsDisabledKey, true);
ui::PlatformWindowInitProperties properties = ui::PlatformWindowInitProperties properties =
ConvertWidgetInitParamsToInitProperties(params); ConvertWidgetInitParamsToInitProperties(params);
AddAdditionalInitProperties(&properties);
CreateAndSetPlatformWindow(std::move(properties)); CreateAndSetPlatformWindow(std::move(properties));
CreateCompositor(viz::FrameSinkId(), params.force_software_compositing); // Disable compositing on tooltips as a workaround for
aura::WindowTreeHost::OnAcceleratedWidgetAvailable(); // https://crbug.com/442111.
CreateCompositor(viz::FrameSinkId(),
params.force_software_compositing ||
params.type == Widget::InitParams::TYPE_TOOLTIP);
WindowTreeHost::OnAcceleratedWidgetAvailable();
InitHost(); InitHost();
if (!params.bounds.IsEmpty())
SetBoundsInDIP(params.bounds);
window()->Show(); window()->Show();
} }
...@@ -86,18 +159,6 @@ void DesktopWindowTreeHostPlatform::OnWidgetInitDone() {} ...@@ -86,18 +159,6 @@ void DesktopWindowTreeHostPlatform::OnWidgetInitDone() {}
void DesktopWindowTreeHostPlatform::OnActiveWindowChanged(bool active) {} void DesktopWindowTreeHostPlatform::OnActiveWindowChanged(bool active) {}
base::Optional<gfx::Size>
DesktopWindowTreeHostPlatform::GetMinimumSizeForWindow() {
return ToPixelRect(gfx::Rect(native_widget_delegate()->GetMinimumSize()))
.size();
}
base::Optional<gfx::Size>
DesktopWindowTreeHostPlatform::GetMaximumSizeForWindow() {
return ToPixelRect(gfx::Rect(native_widget_delegate()->GetMaximumSize()))
.size();
}
std::unique_ptr<corewm::Tooltip> std::unique_ptr<corewm::Tooltip>
DesktopWindowTreeHostPlatform::CreateTooltip() { DesktopWindowTreeHostPlatform::CreateTooltip() {
return std::make_unique<corewm::TooltipAura>(); return std::make_unique<corewm::TooltipAura>();
...@@ -479,6 +540,19 @@ bool DesktopWindowTreeHostPlatform::ShouldCreateVisibilityController() const { ...@@ -479,6 +540,19 @@ bool DesktopWindowTreeHostPlatform::ShouldCreateVisibilityController() const {
return true; return true;
} }
gfx::Transform DesktopWindowTreeHostPlatform::GetRootTransform() const {
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
if (IsVisible()) {
display = display::Screen::GetScreen()->GetDisplayNearestWindow(
GetWidget()->GetNativeWindow());
}
float scale = display.device_scale_factor();
gfx::Transform transform;
transform.Scale(scale, scale);
return transform;
}
void DesktopWindowTreeHostPlatform::DispatchEvent(ui::Event* event) { void DesktopWindowTreeHostPlatform::DispatchEvent(ui::Event* event) {
#if defined(USE_OZONE) #if defined(USE_OZONE)
// Make sure the |event| is marked as a non-client if it's a non-client // Make sure the |event| is marked as a non-client if it's a non-client
...@@ -537,72 +611,36 @@ void DesktopWindowTreeHostPlatform::OnActivationChanged(bool active) { ...@@ -537,72 +611,36 @@ void DesktopWindowTreeHostPlatform::OnActivationChanged(bool active) {
desktop_native_widget_aura_->HandleActivationChanged(active); desktop_native_widget_aura_->HandleActivationChanged(active);
} }
ui::PlatformWindowInitProperties base::Optional<gfx::Size>
DesktopWindowTreeHostPlatform::ConvertWidgetInitParamsToInitProperties( DesktopWindowTreeHostPlatform::GetMinimumSizeForWindow() {
const Widget::InitParams& params) { return ToPixelRect(gfx::Rect(native_widget_delegate()->GetMinimumSize()))
ui::PlatformWindowInitProperties properties; .size();
}
switch (params.type) {
case Widget::InitParams::TYPE_WINDOW:
properties.type = ui::PlatformWindowType::kWindow;
break;
case Widget::InitParams::TYPE_MENU:
properties.type = ui::PlatformWindowType::kMenu;
break;
case Widget::InitParams::TYPE_TOOLTIP:
properties.type = ui::PlatformWindowType::kTooltip;
break;
case Widget::InitParams::TYPE_DRAG:
properties.type = ui::PlatformWindowType::kDrag;
break;
case Widget::InitParams::TYPE_BUBBLE:
properties.type = ui::PlatformWindowType::kBubble;
break;
default:
properties.type = ui::PlatformWindowType::kPopup;
break;
}
properties.bounds = params.bounds;
properties.activatable =
params.activatable == Widget::InitParams::ACTIVATABLE_YES;
properties.force_show_in_taskbar = params.force_show_in_taskbar;
properties.keep_on_top =
params.EffectiveZOrderLevel() != ui::ZOrderLevel::kNormal;
properties.visible_on_all_workspaces = params.visible_on_all_workspaces;
properties.remove_standard_frame = params.remove_standard_frame;
properties.workspace = params.workspace;
properties.wm_class_name = params.wm_class_name;
properties.wm_class_class = params.wm_class_class;
properties.wm_role_name = params.wm_role_name;
if (params.parent && params.parent->GetHost())
properties.parent_widget = params.parent->GetHost()->GetAcceleratedWidget();
switch (params.opacity) {
case Widget::InitParams::WindowOpacity::INFER_OPACITY:
properties.opacity = ui::PlatformWindowOpacity::kInferOpacity;
break;
case Widget::InitParams::WindowOpacity::OPAQUE_WINDOW:
properties.opacity = ui::PlatformWindowOpacity::kOpaqueWindow;
break;
case Widget::InitParams::WindowOpacity::TRANSLUCENT_WINDOW:
properties.opacity = ui::PlatformWindowOpacity::kTranslucentWindow;
break;
}
return properties; base::Optional<gfx::Size>
DesktopWindowTreeHostPlatform::GetMaximumSizeForWindow() {
return ToPixelRect(gfx::Rect(native_widget_delegate()->GetMaximumSize()))
.size();
} }
aura::Window* DesktopWindowTreeHostPlatform::content_window() { aura::Window* DesktopWindowTreeHostPlatform::content_window() {
return desktop_native_widget_aura_->content_window(); return desktop_native_widget_aura_->content_window();
} }
gfx::Rect DesktopWindowTreeHostPlatform::ToDIPRect(
const gfx::Rect& rect_in_pixels) const {
gfx::RectF rect_in_dip = gfx::RectF(rect_in_pixels);
GetRootTransform().TransformRectReverse(&rect_in_dip);
return gfx::ToEnclosingRect(rect_in_dip);
}
gfx::Rect DesktopWindowTreeHostPlatform::ToPixelRect(
const gfx::Rect& rect_in_dip) const {
gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip);
GetRootTransform().TransformRect(&rect_in_pixels);
return gfx::ToEnclosingRect(rect_in_pixels);
}
void DesktopWindowTreeHostPlatform::Relayout() { void DesktopWindowTreeHostPlatform::Relayout() {
Widget* widget = native_widget_delegate_->AsWidget(); Widget* widget = native_widget_delegate_->AsWidget();
NonClientView* non_client_view = widget->non_client_view(); NonClientView* non_client_view = widget->non_client_view();
...@@ -627,19 +665,12 @@ Widget* DesktopWindowTreeHostPlatform::GetWidget() { ...@@ -627,19 +665,12 @@ Widget* DesktopWindowTreeHostPlatform::GetWidget() {
return native_widget_delegate_->AsWidget(); return native_widget_delegate_->AsWidget();
} }
gfx::Rect DesktopWindowTreeHostPlatform::ToDIPRect( const Widget* DesktopWindowTreeHostPlatform::GetWidget() const {
const gfx::Rect& rect_in_pixels) const { return native_widget_delegate_->AsWidget();
gfx::RectF rect_in_dip = gfx::RectF(rect_in_pixels);
GetRootTransform().TransformRectReverse(&rect_in_dip);
return gfx::ToEnclosingRect(rect_in_dip);
} }
gfx::Rect DesktopWindowTreeHostPlatform::ToPixelRect( void DesktopWindowTreeHostPlatform::AddAdditionalInitProperties(
const gfx::Rect& rect_in_dip) const { ui::PlatformWindowInitProperties* properties) {}
gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip);
GetRootTransform().TransformRect(&rect_in_pixels);
return gfx::ToEnclosingRect(rect_in_pixels);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHost: // DesktopWindowTreeHost:
......
...@@ -90,6 +90,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform ...@@ -90,6 +90,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
bool ShouldUseDesktopNativeCursorManager() const override; bool ShouldUseDesktopNativeCursorManager() const override;
bool ShouldCreateVisibilityController() const override; bool ShouldCreateVisibilityController() const override;
// WindowTreeHost:
gfx::Transform GetRootTransform() const override;
// PlatformWindowDelegateBase: // PlatformWindowDelegateBase:
void DispatchEvent(ui::Event* event) override; void DispatchEvent(ui::Event* event) override;
void OnClosed() override; void OnClosed() override;
...@@ -100,11 +103,8 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform ...@@ -100,11 +103,8 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
base::Optional<gfx::Size> GetMaximumSizeForWindow() override; base::Optional<gfx::Size> GetMaximumSizeForWindow() override;
protected: protected:
// TODO(https://crbug.com/990756): move this back to unnamed namespace, when // TODO(https://crbug.com/990756): move these methods back to private
// DWTHX11 stops initialization of the PlatformWindow. Also, remove these // once DWTHX11 stops using them.
// accessor methods.
ui::PlatformWindowInitProperties ConvertWidgetInitParamsToInitProperties(
const Widget::InitParams& params);
internal::NativeWidgetDelegate* native_widget_delegate() { internal::NativeWidgetDelegate* native_widget_delegate() {
return native_widget_delegate_; return native_widget_delegate_;
} }
...@@ -114,6 +114,11 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform ...@@ -114,6 +114,11 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
// Accessor for DesktopNativeWidgetAura::content_window(). // Accessor for DesktopNativeWidgetAura::content_window().
aura::Window* content_window(); aura::Window* content_window();
// These are not general purpose methods and must be used with care. Please
// make sure you understand the rounding direction before using.
gfx::Rect ToDIPRect(const gfx::Rect& rect_in_pixels) const;
gfx::Rect ToPixelRect(const gfx::Rect& rect_in_dip) const;
private: private:
FRIEND_TEST_ALL_PREFIXES(DesktopWindowTreeHostPlatformTest, HitTest); FRIEND_TEST_ALL_PREFIXES(DesktopWindowTreeHostPlatformTest, HitTest);
...@@ -122,9 +127,11 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform ...@@ -122,9 +127,11 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
void RemoveNonClientEventFilter(); void RemoveNonClientEventFilter();
Widget* GetWidget(); Widget* GetWidget();
const Widget* GetWidget() const;
gfx::Rect ToDIPRect(const gfx::Rect& rect_in_pixels) const; // There are platform specific properties that Linux may want to add.
gfx::Rect ToPixelRect(const gfx::Rect& rect_in_dip) const; virtual void AddAdditionalInitProperties(
ui::PlatformWindowInitProperties* properties);
internal::NativeWidgetDelegate* const native_widget_delegate_; internal::NativeWidgetDelegate* const native_widget_delegate_;
DesktopNativeWidgetAura* const desktop_native_widget_aura_; DesktopNativeWidgetAura* const desktop_native_widget_aura_;
......
...@@ -53,10 +53,8 @@ ...@@ -53,10 +53,8 @@
#include "ui/gfx/path_x11.h" #include "ui/gfx/path_x11.h"
#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/x11_atom_cache.h"
#include "ui/platform_window/x11/x11_window.h"
#include "ui/views/corewm/tooltip_aura.h" #include "ui/views/corewm/tooltip_aura.h"
#include "ui/views/linux_ui/linux_ui.h" #include "ui/views/linux_ui/linux_ui.h"
#include "ui/views/views_delegate.h"
#include "ui/views/views_switches.h" #include "ui/views/views_switches.h"
#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h"
#include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
...@@ -155,9 +153,8 @@ bool ShouldDiscardKeyEvent(XEvent* xev) { ...@@ -155,9 +153,8 @@ bool ShouldDiscardKeyEvent(XEvent* xev) {
DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( DesktopWindowTreeHostX11::DesktopWindowTreeHostX11(
internal::NativeWidgetDelegate* native_widget_delegate, internal::NativeWidgetDelegate* native_widget_delegate,
DesktopNativeWidgetAura* desktop_native_widget_aura) DesktopNativeWidgetAura* desktop_native_widget_aura)
: DesktopWindowTreeHostPlatform(native_widget_delegate, : DesktopWindowTreeHostLinux(native_widget_delegate,
desktop_native_widget_aura), desktop_native_widget_aura) {}
x11_window_(std::make_unique<ui::X11Window>(this, this)) {}
DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() {
window()->ClearProperty(kHostForRootWindow); window()->ClearProperty(kHostForRootWindow);
...@@ -189,15 +186,15 @@ std::vector<aura::Window*> DesktopWindowTreeHostX11::GetAllOpenWindows() { ...@@ -189,15 +186,15 @@ std::vector<aura::Window*> DesktopWindowTreeHostX11::GetAllOpenWindows() {
} }
gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowBounds() const { gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowBounds() const {
return x11_window_->bounds(); return GetBoundsInPixels();
} }
gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowOuterBounds() const { gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowOuterBounds() const {
return x11_window_->GetOutterBounds(); return GetXWindow()->GetOutterBounds();
} }
::Region DesktopWindowTreeHostX11::GetWindowShape() const { ::Region DesktopWindowTreeHostX11::GetWindowShape() const {
return x11_window_->shape(); return GetXWindow()->shape();
} }
void DesktopWindowTreeHostX11::AddObserver( void DesktopWindowTreeHostX11::AddObserver(
...@@ -230,9 +227,9 @@ void DesktopWindowTreeHostX11::CleanUpWindowList( ...@@ -230,9 +227,9 @@ void DesktopWindowTreeHostX11::CleanUpWindowList(
if (!open_windows_) if (!open_windows_)
return; return;
while (!open_windows_->empty()) { while (!open_windows_->empty()) {
XID xid = open_windows_->front(); gfx::AcceleratedWidget widget = open_windows_->front();
func(GetContentWindowForXID(xid)); func(GetContentWindowForXID(widget));
if (!open_windows_->empty() && open_windows_->front() == xid) if (!open_windows_->empty() && open_windows_->front() == widget)
open_windows_->erase(open_windows_->begin()); open_windows_->erase(open_windows_->begin());
} }
...@@ -244,12 +241,34 @@ void DesktopWindowTreeHostX11::CleanUpWindowList( ...@@ -244,12 +241,34 @@ void DesktopWindowTreeHostX11::CleanUpWindowList(
// DesktopWindowTreeHostX11, DesktopWindowTreeHost implementation: // DesktopWindowTreeHostX11, DesktopWindowTreeHost implementation:
void DesktopWindowTreeHostX11::Init(const Widget::InitParams& params) { void DesktopWindowTreeHostX11::Init(const Widget::InitParams& params) {
if (params.type == Widget::InitParams::TYPE_WINDOW) // If we have a parent, record the parent/child relationship. We use this
content_window()->SetProperty(aura::client::kAnimationsDisabledKey, true); // data during destruction to make sure that when we try to close a parent
// window, we also destroy all child windows.
if (params.parent && params.parent->GetHost()) {
window_parent_ =
static_cast<DesktopWindowTreeHostX11*>(params.parent->GetHost());
DCHECK(window_parent_);
window_parent_->window_children_.insert(this);
}
DesktopWindowTreeHostPlatform::Init(params);
InitX11Window(params); // Set XEventDelegate to receive selection, drag&drop and raw key events.
InitHost(); //
window()->Show(); // TODO(https://crbug.com/990756): There are two cases of this delegate:
// XEvents for DragAndDrop client and raw key events. DragAndDrop could be
// unified so that DragAndrDropClientOzone is used and XEvent are handled on
// platform level.
static_cast<ui::X11Window*>(platform_window())->SetXEventDelegate(this);
// Can it be unified and will Ozone benefit from this? Check comment above
// where this class is defined and declared.
if (ui::IsSyncExtensionAvailable()) {
compositor_observer_ = std::make_unique<SwapWithNewSizeObserverHelper>(
compositor(), base::BindRepeating(
&DesktopWindowTreeHostX11::OnCompleteSwapWithNewSize,
base::Unretained(this)));
}
} }
void DesktopWindowTreeHostX11::OnNativeWidgetCreated( void DesktopWindowTreeHostX11::OnNativeWidgetCreated(
...@@ -284,8 +303,9 @@ std::unique_ptr<corewm::Tooltip> DesktopWindowTreeHostX11::CreateTooltip() { ...@@ -284,8 +303,9 @@ std::unique_ptr<corewm::Tooltip> DesktopWindowTreeHostX11::CreateTooltip() {
std::unique_ptr<aura::client::DragDropClient> std::unique_ptr<aura::client::DragDropClient>
DesktopWindowTreeHostX11::CreateDragDropClient( DesktopWindowTreeHostX11::CreateDragDropClient(
DesktopNativeCursorManager* cursor_manager) { DesktopNativeCursorManager* cursor_manager) {
drag_drop_client_ = new DesktopDragDropClientAuraX11( drag_drop_client_ = new DesktopDragDropClientAuraX11(window(), cursor_manager,
window(), cursor_manager, x11_window_->display(), x11_window_->window()); GetXWindow()->display(),
GetXWindow()->window());
drag_drop_client_->Init(); drag_drop_client_->Init();
return base::WrapUnique(drag_drop_client_); return base::WrapUnique(drag_drop_client_);
} }
...@@ -294,7 +314,7 @@ void DesktopWindowTreeHostX11::Close() { ...@@ -294,7 +314,7 @@ void DesktopWindowTreeHostX11::Close() {
content_window()->Hide(); content_window()->Hide();
// TODO(erg): Might need to do additional hiding tasks here. // TODO(erg): Might need to do additional hiding tasks here.
x11_window_->CancelResize(); GetXWindow()->CancelResize();
if (!close_widget_factory_.HasWeakPtrs()) { if (!close_widget_factory_.HasWeakPtrs()) {
// And we delay the close so that if we are called from an ATL callback, // And we delay the close so that if we are called from an ATL callback,
...@@ -308,9 +328,9 @@ void DesktopWindowTreeHostX11::Close() { ...@@ -308,9 +328,9 @@ void DesktopWindowTreeHostX11::Close() {
} }
void DesktopWindowTreeHostX11::CloseNow() { void DesktopWindowTreeHostX11::CloseNow() {
if (x11_window_->window() == x11::None) if (GetXWindow()->window() == x11::None)
return; return;
x11_window_->PrepareForShutdown(); platform_window()->PrepareForShutdown();
ReleaseCapture(); ReleaseCapture();
RemoveNonClientEventFilter(); RemoveNonClientEventFilter();
...@@ -334,9 +354,9 @@ void DesktopWindowTreeHostX11::CloseNow() { ...@@ -334,9 +354,9 @@ void DesktopWindowTreeHostX11::CloseNow() {
// causes a crash with in-process renderer. // causes a crash with in-process renderer.
DestroyCompositor(); DestroyCompositor();
open_windows().remove(x11_window_->window()); open_windows().remove(GetAcceleratedWidget());
x11_window_->Close(); platform_window()->Close();
} }
aura::WindowTreeHost* DesktopWindowTreeHostX11::AsWindowTreeHost() { aura::WindowTreeHost* DesktopWindowTreeHostX11::AsWindowTreeHost() {
...@@ -348,7 +368,7 @@ void DesktopWindowTreeHostX11::Show(ui::WindowShowState show_state, ...@@ -348,7 +368,7 @@ void DesktopWindowTreeHostX11::Show(ui::WindowShowState show_state,
if (compositor()) if (compositor())
SetVisible(true); SetVisible(true);
if (!x11_window_->mapped_in_client() || IsMinimized()) if (!GetXWindow()->mapped_in_client() || IsMinimized())
MapWindow(show_state); MapWindow(show_state);
switch (show_state) { switch (show_state) {
...@@ -376,16 +396,16 @@ void DesktopWindowTreeHostX11::Show(ui::WindowShowState show_state, ...@@ -376,16 +396,16 @@ void DesktopWindowTreeHostX11::Show(ui::WindowShowState show_state,
} }
bool DesktopWindowTreeHostX11::IsVisible() const { bool DesktopWindowTreeHostX11::IsVisible() const {
return x11_window_->IsVisible(); return platform_window() ? GetXWindow()->IsVisible() : false;
} }
void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) {
gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size(); gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size();
size_in_pixels = AdjustSize(size_in_pixels); size_in_pixels = AdjustSizeForDisplay(size_in_pixels);
bool size_changed = x11_window_->bounds().size() != size_in_pixels; bool size_changed = GetBoundsInPixels().size() != size_in_pixels;
x11_window_->SetSize(size_in_pixels); GetXWindow()->SetSize(size_in_pixels);
if (size_changed) { if (size_changed) {
OnHostResizedInPixels(size_in_pixels); OnHostResizedInPixels(size_in_pixels);
...@@ -394,8 +414,8 @@ void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { ...@@ -394,8 +414,8 @@ void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) {
} }
void DesktopWindowTreeHostX11::StackAbove(aura::Window* window) { void DesktopWindowTreeHostX11::StackAbove(aura::Window* window) {
XDisplay* display = x11_window_->display(); XDisplay* display = GetXWindow()->display();
::Window xwindow = x11_window_->window(); ::Window xwindow = GetXWindow()->window();
if (window && window->GetRootWindow()) { if (window && window->GetRootWindow()) {
::Window window_below = window->GetHost()->GetAcceleratedWidget(); ::Window window_below = window->GetHost()->GetAcceleratedWidget();
...@@ -428,7 +448,7 @@ void DesktopWindowTreeHostX11::StackAbove(aura::Window* window) { ...@@ -428,7 +448,7 @@ void DesktopWindowTreeHostX11::StackAbove(aura::Window* window) {
} }
void DesktopWindowTreeHostX11::StackAtTop() { void DesktopWindowTreeHostX11::StackAtTop() {
x11_window_->StackAtTop(); GetXWindow()->StackAtTop();
} }
void DesktopWindowTreeHostX11::CenterWindow(const gfx::Size& size) { void DesktopWindowTreeHostX11::CenterWindow(const gfx::Size& size) {
...@@ -478,8 +498,7 @@ void DesktopWindowTreeHostX11::GetWindowPlacement( ...@@ -478,8 +498,7 @@ void DesktopWindowTreeHostX11::GetWindowPlacement(
} }
gfx::Rect DesktopWindowTreeHostX11::GetWindowBoundsInScreen() const { gfx::Rect DesktopWindowTreeHostX11::GetWindowBoundsInScreen() const {
gfx::Rect bounds_in_pixels = x11_window_->bounds(); return ToDIPRect(GetBoundsInPixels());
return ToDIPRect(bounds_in_pixels);
} }
gfx::Rect DesktopWindowTreeHostX11::GetClientAreaBoundsInScreen() const { gfx::Rect DesktopWindowTreeHostX11::GetClientAreaBoundsInScreen() const {
...@@ -506,7 +525,7 @@ gfx::Rect DesktopWindowTreeHostX11::GetRestoredBounds() const { ...@@ -506,7 +525,7 @@ gfx::Rect DesktopWindowTreeHostX11::GetRestoredBounds() const {
} }
std::string DesktopWindowTreeHostX11::GetWorkspace() const { std::string DesktopWindowTreeHostX11::GetWorkspace() const {
base::Optional<int> workspace = x11_window_->workspace(); base::Optional<int> workspace = GetXWindow()->workspace();
return workspace ? base::NumberToString(workspace.value()) : std::string(); return workspace ? base::NumberToString(workspace.value()) : std::string();
} }
...@@ -537,37 +556,37 @@ void DesktopWindowTreeHostX11::SetShape( ...@@ -537,37 +556,37 @@ void DesktopWindowTreeHostX11::SetShape(
xregion = gfx::CreateRegionFromSkRegion(native_region); xregion = gfx::CreateRegionFromSkRegion(native_region);
} }
} }
x11_window_->SetShape(xregion); GetXWindow()->SetShape(xregion);
ResetWindowRegion(); ResetWindowRegion();
} }
void DesktopWindowTreeHostX11::Activate() { void DesktopWindowTreeHostX11::Activate() {
x11_window_->Activate(); GetXWindow()->Activate();
} }
void DesktopWindowTreeHostX11::Deactivate() { void DesktopWindowTreeHostX11::Deactivate() {
ReleaseCapture(); ReleaseCapture();
x11_window_->Deactivate(); GetXWindow()->Deactivate();
} }
bool DesktopWindowTreeHostX11::IsActive() const { bool DesktopWindowTreeHostX11::IsActive() const {
return x11_window_->IsActive(); return GetXWindow()->IsActive();
} }
void DesktopWindowTreeHostX11::Maximize() { void DesktopWindowTreeHostX11::Maximize() {
// TODO(nickdiego): Move into XWindow. For now, it is kept outside // TODO(nickdiego): Move into XWindow. For now, it is kept outside
// it due to |AdjustSize|, which depends on display::Display, which is not // it due to |AdjustSizeForDisplay|, which depends on display::Display, which
// accessible at Ozone layer. // is not accessible at Ozone layer.
if (x11_window_->IsFullscreen()) { if (GetXWindow()->IsFullscreen()) {
// Unfullscreen the window if it is fullscreen. // Unfullscreen the window if it is fullscreen.
x11_window_->SetFullscreen(false); GetXWindow()->SetFullscreen(false);
// Resize the window so that it does not have the same size as a monitor. // Resize the window so that it does not have the same size as a monitor.
// (Otherwise, some window managers immediately put the window back in // (Otherwise, some window managers immediately put the window back in
// fullscreen mode). // fullscreen mode).
gfx::Rect bounds = x11_window_->bounds(); gfx::Rect bounds = GetBoundsInPixels();
gfx::Rect adjusted_bounds_in_pixels(bounds.origin(), gfx::Rect adjusted_bounds_in_pixels(bounds.origin(),
AdjustSize(bounds.size())); AdjustSizeForDisplay(bounds.size()));
if (adjusted_bounds_in_pixels != bounds) if (adjusted_bounds_in_pixels != bounds)
SetBoundsInPixels(adjusted_bounds_in_pixels); SetBoundsInPixels(adjusted_bounds_in_pixels);
} }
...@@ -575,30 +594,30 @@ void DesktopWindowTreeHostX11::Maximize() { ...@@ -575,30 +594,30 @@ void DesktopWindowTreeHostX11::Maximize() {
// When we are in the process of requesting to maximize a window, we can // When we are in the process of requesting to maximize a window, we can
// accurately keep track of our restored bounds instead of relying on the // accurately keep track of our restored bounds instead of relying on the
// heuristics that are in the PropertyNotify and ConfigureNotify handlers. // heuristics that are in the PropertyNotify and ConfigureNotify handlers.
restored_bounds_in_pixels_ = x11_window_->bounds(); restored_bounds_in_pixels_ = GetBoundsInPixels();
x11_window_->Maximize(); GetXWindow()->Maximize();
if (IsMinimized()) if (IsMinimized())
Show(ui::SHOW_STATE_NORMAL, gfx::Rect()); Show(ui::SHOW_STATE_NORMAL, gfx::Rect());
} }
void DesktopWindowTreeHostX11::Minimize() { void DesktopWindowTreeHostX11::Minimize() {
ReleaseCapture(); ReleaseCapture();
x11_window_->Minimize(); GetXWindow()->Minimize();
} }
void DesktopWindowTreeHostX11::Restore() { void DesktopWindowTreeHostX11::Restore() {
x11_window_->Unmaximize(); GetXWindow()->Unmaximize();
Show(ui::SHOW_STATE_NORMAL, gfx::Rect()); Show(ui::SHOW_STATE_NORMAL, gfx::Rect());
x11_window_->Unhide(); GetXWindow()->Unhide();
} }
bool DesktopWindowTreeHostX11::IsMaximized() const { bool DesktopWindowTreeHostX11::IsMaximized() const {
return x11_window_->IsMaximized(); return GetXWindow()->IsMaximized();
} }
bool DesktopWindowTreeHostX11::IsMinimized() const { bool DesktopWindowTreeHostX11::IsMinimized() const {
return x11_window_->IsMinimized(); return GetXWindow()->IsMinimized();
} }
bool DesktopWindowTreeHostX11::HasCapture() const { bool DesktopWindowTreeHostX11::HasCapture() const {
...@@ -611,11 +630,11 @@ void DesktopWindowTreeHostX11::SetZOrderLevel(ui::ZOrderLevel order) { ...@@ -611,11 +630,11 @@ void DesktopWindowTreeHostX11::SetZOrderLevel(ui::ZOrderLevel order) {
// Emulate the multiple window levels provided by other platforms by // Emulate the multiple window levels provided by other platforms by
// collapsing the z-order enum into kNormal = normal, everything else = always // collapsing the z-order enum into kNormal = normal, everything else = always
// on top. // on top.
x11_window_->SetAlwaysOnTop(order != ui::ZOrderLevel::kNormal); GetXWindow()->SetAlwaysOnTop(order != ui::ZOrderLevel::kNormal);
} }
ui::ZOrderLevel DesktopWindowTreeHostX11::GetZOrderLevel() const { ui::ZOrderLevel DesktopWindowTreeHostX11::GetZOrderLevel() const {
bool window_always_on_top = x11_window_->is_always_on_top(); bool window_always_on_top = GetXWindow()->is_always_on_top();
bool level_always_on_top = z_order_ != ui::ZOrderLevel::kNormal; bool level_always_on_top = z_order_ != ui::ZOrderLevel::kNormal;
if (window_always_on_top == level_always_on_top) if (window_always_on_top == level_always_on_top)
...@@ -639,17 +658,15 @@ void DesktopWindowTreeHostX11::SetVisible(bool visible) { ...@@ -639,17 +658,15 @@ void DesktopWindowTreeHostX11::SetVisible(bool visible) {
} }
void DesktopWindowTreeHostX11::SetVisibleOnAllWorkspaces(bool always_visible) { void DesktopWindowTreeHostX11::SetVisibleOnAllWorkspaces(bool always_visible) {
x11_window_->SetVisibleOnAllWorkspaces(always_visible); GetXWindow()->SetVisibleOnAllWorkspaces(always_visible);
} }
bool DesktopWindowTreeHostX11::IsVisibleOnAllWorkspaces() const { bool DesktopWindowTreeHostX11::IsVisibleOnAllWorkspaces() const {
return x11_window_->IsVisibleOnAllWorkspaces(); return GetXWindow()->IsVisibleOnAllWorkspaces();
} }
bool DesktopWindowTreeHostX11::SetWindowTitle(const base::string16& title) { bool DesktopWindowTreeHostX11::SetWindowTitle(const base::string16& title) {
auto* x_window = static_cast<ui::XWindow*>(x11_window_.get()); return GetXWindow()->SetTitle(title);
DCHECK(x_window);
return x_window->SetTitle(title);
} }
void DesktopWindowTreeHostX11::ClearNativeFocus() { void DesktopWindowTreeHostX11::ClearNativeFocus() {
...@@ -695,11 +712,11 @@ NonClientFrameView* DesktopWindowTreeHostX11::CreateNonClientFrameView() { ...@@ -695,11 +712,11 @@ NonClientFrameView* DesktopWindowTreeHostX11::CreateNonClientFrameView() {
} }
bool DesktopWindowTreeHostX11::ShouldUseNativeFrame() const { bool DesktopWindowTreeHostX11::ShouldUseNativeFrame() const {
return x11_window_->use_native_frame(); return GetXWindow()->use_native_frame();
} }
bool DesktopWindowTreeHostX11::ShouldWindowContentsBeTransparent() const { bool DesktopWindowTreeHostX11::ShouldWindowContentsBeTransparent() const {
return x11_window_->has_alpha(); return GetXWindow()->has_alpha();
} }
void DesktopWindowTreeHostX11::FrameTypeChanged() { void DesktopWindowTreeHostX11::FrameTypeChanged() {
...@@ -727,7 +744,7 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) { ...@@ -727,7 +744,7 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) {
is_fullscreen_ = fullscreen; is_fullscreen_ = fullscreen;
if (is_fullscreen_) if (is_fullscreen_)
x11_window_->CancelResize(); GetXWindow()->CancelResize();
// Work around a bug where if we try to unfullscreen, metacity immediately // Work around a bug where if we try to unfullscreen, metacity immediately
// fullscreens us again. This is a little flickery and not necessary if // fullscreens us again. This is a little flickery and not necessary if
...@@ -739,7 +756,7 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) { ...@@ -739,7 +756,7 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) {
if (unmaximize_and_remaximize) if (unmaximize_and_remaximize)
Restore(); Restore();
x11_window_->SetFullscreen(fullscreen); GetXWindow()->SetFullscreen(fullscreen);
if (unmaximize_and_remaximize) if (unmaximize_and_remaximize)
Maximize(); Maximize();
...@@ -749,7 +766,7 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) { ...@@ -749,7 +766,7 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) {
// - works around Flash content which expects to have the size updated // - works around Flash content which expects to have the size updated
// synchronously. // synchronously.
// See https://crbug.com/361408 // See https://crbug.com/361408
gfx::Rect bounds = x11_window_->bounds(); gfx::Rect bounds = GetXWindow()->bounds();
if (fullscreen) { if (fullscreen) {
display::Screen* screen = display::Screen::GetScreen(); display::Screen* screen = display::Screen::GetScreen();
const display::Display display = screen->GetDisplayNearestWindow(window()); const display::Display display = screen->GetDisplayNearestWindow(window());
...@@ -758,12 +775,12 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) { ...@@ -758,12 +775,12 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) {
} else { } else {
bounds = restored_bounds_in_pixels_; bounds = restored_bounds_in_pixels_;
} }
x11_window_->set_bounds(bounds); GetXWindow()->set_bounds(bounds);
OnHostMovedInPixels(bounds.origin()); OnHostMovedInPixels(bounds.origin());
OnHostResizedInPixels(bounds.size()); OnHostResizedInPixels(bounds.size());
if (x11_window_->IsFullscreen() == fullscreen) { if (GetXWindow()->IsFullscreen() == fullscreen) {
Relayout(); Relayout();
ResetWindowRegion(); ResetWindowRegion();
} }
...@@ -776,16 +793,16 @@ bool DesktopWindowTreeHostX11::IsFullscreen() const { ...@@ -776,16 +793,16 @@ bool DesktopWindowTreeHostX11::IsFullscreen() const {
} }
void DesktopWindowTreeHostX11::SetOpacity(float opacity) { void DesktopWindowTreeHostX11::SetOpacity(float opacity) {
x11_window_->SetOpacity(opacity); GetXWindow()->SetOpacity(opacity);
} }
void DesktopWindowTreeHostX11::SetAspectRatio(const gfx::SizeF& aspect_ratio) { void DesktopWindowTreeHostX11::SetAspectRatio(const gfx::SizeF& aspect_ratio) {
x11_window_->SetAspectRatio(aspect_ratio); GetXWindow()->SetAspectRatio(aspect_ratio);
} }
void DesktopWindowTreeHostX11::SetWindowIcons(const gfx::ImageSkia& window_icon, void DesktopWindowTreeHostX11::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) { const gfx::ImageSkia& app_icon) {
x11_window_->SetWindowIcons(window_icon, app_icon); GetXWindow()->SetWindowIcons(window_icon, app_icon);
} }
void DesktopWindowTreeHostX11::InitModalType(ui::ModalType modal_type) { void DesktopWindowTreeHostX11::InitModalType(ui::ModalType modal_type) {
...@@ -801,7 +818,7 @@ void DesktopWindowTreeHostX11::InitModalType(ui::ModalType modal_type) { ...@@ -801,7 +818,7 @@ void DesktopWindowTreeHostX11::InitModalType(ui::ModalType modal_type) {
} }
void DesktopWindowTreeHostX11::FlashFrame(bool flash_frame) { void DesktopWindowTreeHostX11::FlashFrame(bool flash_frame) {
x11_window_->FlashFrame(flash_frame); GetXWindow()->FlashFrame(flash_frame);
} }
bool DesktopWindowTreeHostX11::IsAnimatingClosed() const { bool DesktopWindowTreeHostX11::IsAnimatingClosed() const {
...@@ -816,7 +833,7 @@ bool DesktopWindowTreeHostX11::IsTranslucentWindowOpacitySupported() const { ...@@ -816,7 +833,7 @@ bool DesktopWindowTreeHostX11::IsTranslucentWindowOpacitySupported() const {
} }
void DesktopWindowTreeHostX11::SizeConstraintsChanged() { void DesktopWindowTreeHostX11::SizeConstraintsChanged() {
x11_window_->UpdateMinAndMaxSize(); GetXWindow()->UpdateMinAndMaxSize();
} }
bool DesktopWindowTreeHostX11::ShouldUpdateWindowTransparency() const { bool DesktopWindowTreeHostX11::ShouldUpdateWindowTransparency() const {
...@@ -832,63 +849,45 @@ bool DesktopWindowTreeHostX11::ShouldCreateVisibilityController() const { ...@@ -832,63 +849,45 @@ bool DesktopWindowTreeHostX11::ShouldCreateVisibilityController() const {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, aura::WindowTreeHost implementation: // DesktopWindowTreeHostX11, aura::WindowTreeHost implementatio
gfx::Transform DesktopWindowTreeHostX11::GetRootTransform() const {
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
if (IsVisible()) {
aura::Window* win = const_cast<aura::Window*>(window());
display = display::Screen::GetScreen()->GetDisplayNearestWindow(win);
}
float scale = display.device_scale_factor();
gfx::Transform transform;
transform.Scale(scale, scale);
return transform;
}
ui::EventSource* DesktopWindowTreeHostX11::GetEventSource() { ui::EventSource* DesktopWindowTreeHostX11::GetEventSource() {
return this; return this;
} }
gfx::AcceleratedWidget DesktopWindowTreeHostX11::GetAcceleratedWidget() {
return x11_window_->window();
}
void DesktopWindowTreeHostX11::ShowImpl() { void DesktopWindowTreeHostX11::ShowImpl() {
Show(ui::SHOW_STATE_NORMAL, gfx::Rect()); Show(ui::SHOW_STATE_NORMAL, gfx::Rect());
} }
void DesktopWindowTreeHostX11::HideImpl() { void DesktopWindowTreeHostX11::HideImpl() {
auto* x_window = static_cast<ui::XWindow*>(x11_window_.get()); if (GetXWindow()->Hide())
DCHECK(x_window);
if (x_window->Hide())
SetVisible(false); SetVisible(false);
} }
gfx::Rect DesktopWindowTreeHostX11::GetBoundsInPixels() const { gfx::Rect DesktopWindowTreeHostX11::GetBoundsInPixels() const {
return x11_window_->bounds(); return GetXWindow()->bounds();
} }
void DesktopWindowTreeHostX11::SetBoundsInPixels( void DesktopWindowTreeHostX11::SetBoundsInPixels(
const gfx::Rect& requested_bounds_in_pixel) { const gfx::Rect& requested_bounds_in_pixel) {
gfx::Rect bounds = x11_window_->bounds(); gfx::Rect bounds = GetXWindow()->bounds();
gfx::Rect bounds_in_pixels(requested_bounds_in_pixel.origin(), gfx::Rect bounds_in_pixels(
AdjustSize(requested_bounds_in_pixel.size())); requested_bounds_in_pixel.origin(),
AdjustSizeForDisplay(requested_bounds_in_pixel.size()));
bool size_changed = bounds.size() != bounds_in_pixels.size(); bool size_changed = bounds.size() != bounds_in_pixels.size();
if (size_changed) { if (size_changed) {
// Only cancel the delayed resize task if we're already about to call // Only cancel the delayed resize task if we're already about to call
// OnHostResized in this function. // OnHostResized in this function.
x11_window_->CancelResize(); GetXWindow()->CancelResize();
} }
x11_window_->SetBounds(bounds_in_pixels); platform_window()->SetBounds(bounds_in_pixels);
} }
gfx::Point DesktopWindowTreeHostX11::GetLocationOnScreenInPixels() const { gfx::Point DesktopWindowTreeHostX11::GetLocationOnScreenInPixels() const {
return x11_window_->bounds().origin(); return GetXWindow()->bounds().origin();
} }
void DesktopWindowTreeHostX11::SetCapture() { void DesktopWindowTreeHostX11::SetCapture() {
...@@ -910,7 +909,7 @@ void DesktopWindowTreeHostX11::SetCapture() { ...@@ -910,7 +909,7 @@ void DesktopWindowTreeHostX11::SetCapture() {
if (old_capturer) if (old_capturer)
old_capturer->OnHostLostWindowCapture(); old_capturer->OnHostLostWindowCapture();
x11_window_->GrabPointer(); GetXWindow()->GrabPointer();
} }
void DesktopWindowTreeHostX11::ReleaseCapture() { void DesktopWindowTreeHostX11::ReleaseCapture() {
...@@ -919,7 +918,7 @@ void DesktopWindowTreeHostX11::ReleaseCapture() { ...@@ -919,7 +918,7 @@ void DesktopWindowTreeHostX11::ReleaseCapture() {
// the topmost window underneath the mouse so the capture release being // the topmost window underneath the mouse so the capture release being
// asynchronous is likely inconsequential. // asynchronous is likely inconsequential.
g_current_capture = nullptr; g_current_capture = nullptr;
x11_window_->ReleasePointerGrab(); GetXWindow()->ReleasePointerGrab();
OnHostLostWindowCapture(); OnHostLostWindowCapture();
} }
...@@ -948,12 +947,12 @@ bool DesktopWindowTreeHostX11::IsKeyLocked(ui::DomCode dom_code) { ...@@ -948,12 +947,12 @@ bool DesktopWindowTreeHostX11::IsKeyLocked(ui::DomCode dom_code) {
} }
void DesktopWindowTreeHostX11::SetCursorNative(gfx::NativeCursor cursor) { void DesktopWindowTreeHostX11::SetCursorNative(gfx::NativeCursor cursor) {
x11_window_->SetCursor(cursor.platform()); GetXWindow()->SetCursor(cursor.platform());
} }
void DesktopWindowTreeHostX11::MoveCursorToScreenLocationInPixels( void DesktopWindowTreeHostX11::MoveCursorToScreenLocationInPixels(
const gfx::Point& location_in_pixels) { const gfx::Point& location_in_pixels) {
x11_window_->MoveCursorTo(location_in_pixels); GetXWindow()->MoveCursorTo(location_in_pixels);
} }
void DesktopWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { void DesktopWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) {
...@@ -977,92 +976,21 @@ void DesktopWindowTreeHostX11::OnDisplayMetricsChanged( ...@@ -977,92 +976,21 @@ void DesktopWindowTreeHostX11::OnDisplayMetricsChanged(
// compositor redraw will be scheduled. This is weird, but works. // compositor redraw will be scheduled. This is weird, but works.
// TODO(thomasanderson): Figure out a more direct way of doing // TODO(thomasanderson): Figure out a more direct way of doing
// this. // this.
x11_window_->DispatchResize(); GetXWindow()->DispatchResize();
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, private: // DesktopWindowTreeHostX11, private:
void DesktopWindowTreeHostX11::InitX11Window(const Widget::InitParams& params) {
// Disable compositing on tooltips as a workaround for
// https://crbug.com/442111.
CreateCompositor(viz::FrameSinkId(),
params.force_software_compositing ||
params.type == Widget::InitParams::TYPE_TOOLTIP);
// Calculate initial bounds
gfx::Rect bounds_in_pixels = ToPixelRect(params.bounds);
gfx::Size adjusted_size = AdjustSize(bounds_in_pixels.size());
bounds_in_pixels.set_size(adjusted_size);
// Set the background color on startup to make the initial flickering
// happening between the XWindow is mapped and the first expose event
// is completely handled less annoying. If possible, we use the content
// window's background color, otherwise we fallback to white.
base::Optional<int> background_color;
const views::LinuxUI* linux_ui = views::LinuxUI::instance();
if (linux_ui && content_window()) {
ui::NativeTheme::ColorId target_color;
switch (params.type) {
case Widget::InitParams::TYPE_BUBBLE:
target_color = ui::NativeTheme::kColorId_BubbleBackground;
break;
case Widget::InitParams::TYPE_TOOLTIP:
target_color = ui::NativeTheme::kColorId_TooltipBackground;
break;
default:
target_color = ui::NativeTheme::kColorId_WindowBackground;
break;
}
ui::NativeTheme* theme = linux_ui->GetNativeTheme(content_window());
background_color = theme->GetSystemColor(target_color);
}
// Create PlatformWindowInitProperties and initialize it
ui::PlatformWindowInitProperties properties =
ConvertWidgetInitParamsToInitProperties(params);
properties.bounds = bounds_in_pixels;
properties.background_color = background_color;
properties.prefer_dark_theme = linux_ui && linux_ui->PreferDarkTheme();
properties.icon = ViewsDelegate::GetInstance()->GetDefaultWindowIcon();
x11_window_->Initialize(std::move(properties));
if (ui::IsSyncExtensionAvailable()) {
compositor_observer_ = std::make_unique<SwapWithNewSizeObserverHelper>(
compositor(), base::BindRepeating(
&DesktopWindowTreeHostX11::OnCompleteSwapWithNewSize,
base::Unretained(this)));
}
}
void DesktopWindowTreeHostX11::DispatchHostWindowDragMovement( void DesktopWindowTreeHostX11::DispatchHostWindowDragMovement(
int hittest, int hittest,
const gfx::Point& pointer_location) { const gfx::Point& pointer_location) {
x11_window_->WmMoveResize(hittest, pointer_location); GetXWindow()->WmMoveResize(hittest, pointer_location);
}
gfx::Size DesktopWindowTreeHostX11::AdjustSize(
const gfx::Size& requested_size_in_pixels) {
std::vector<display::Display> displays =
display::Screen::GetScreen()->GetAllDisplays();
// Compare against all monitor sizes. The window manager can move the window
// to whichever monitor it wants.
for (const auto& display : displays) {
if (requested_size_in_pixels == display.GetSizeInPixel()) {
return gfx::Size(requested_size_in_pixels.width() - 1,
requested_size_in_pixels.height() - 1);
}
}
// Do not request a 0x0 window size. It causes an XError.
gfx::Size size_in_pixels = requested_size_in_pixels;
size_in_pixels.SetToMax(gfx::Size(1, 1));
return size_in_pixels;
} }
void DesktopWindowTreeHostX11::SetUseNativeFrame(bool use_native_frame) { void DesktopWindowTreeHostX11::SetUseNativeFrame(bool use_native_frame) {
x11_window_->SetUseNativeFrame(use_native_frame); GetXWindow()->SetUseNativeFrame(use_native_frame);
ResetWindowRegion(); ResetWindowRegion();
} }
...@@ -1134,25 +1062,25 @@ void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) { ...@@ -1134,25 +1062,25 @@ void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) {
void DesktopWindowTreeHostX11::ResetWindowRegion() { void DesktopWindowTreeHostX11::ResetWindowRegion() {
_XRegion* xregion = nullptr; _XRegion* xregion = nullptr;
if (!x11_window_->use_custom_shape() && !IsMaximized() && !IsFullscreen()) { if (!GetXWindow()->use_custom_shape() && !IsMaximized() && !IsFullscreen()) {
SkPath window_mask; SkPath window_mask;
Widget* widget = native_widget_delegate()->AsWidget(); Widget* widget = native_widget_delegate()->AsWidget();
if (widget->non_client_view()) { if (widget->non_client_view()) {
// Some frame views define a custom (non-rectangular) window mask. If // Some frame views define a custom (non-rectangular) window mask. If
// so, use it to define the window shape. If not, fall through. // so, use it to define the window shape. If not, fall through.
widget->non_client_view()->GetWindowMask(x11_window_->bounds().size(), widget->non_client_view()->GetWindowMask(GetXWindow()->bounds().size(),
&window_mask); &window_mask);
if (window_mask.countPoints() > 0) { if (window_mask.countPoints() > 0) {
xregion = gfx::CreateRegionFromSkPath(window_mask); xregion = gfx::CreateRegionFromSkPath(window_mask);
} }
} }
} }
x11_window_->UpdateWindowRegion(xregion); GetXWindow()->UpdateWindowRegion(xregion);
} }
std::list<XID>& DesktopWindowTreeHostX11::open_windows() { std::list<gfx::AcceleratedWidget>& DesktopWindowTreeHostX11::open_windows() {
if (!open_windows_) if (!open_windows_)
open_windows_ = new std::list<XID>(); open_windows_ = new std::list<gfx::AcceleratedWidget>();
return *open_windows_; return *open_windows_;
} }
...@@ -1170,11 +1098,11 @@ void DesktopWindowTreeHostX11::MapWindow(ui::WindowShowState show_state) { ...@@ -1170,11 +1098,11 @@ void DesktopWindowTreeHostX11::MapWindow(ui::WindowShowState show_state) {
// http://standards.freedesktop.org/wm-spec/latest/ar01s05.html // http://standards.freedesktop.org/wm-spec/latest/ar01s05.html
bool inactive = show_state == ui::SHOW_STATE_INACTIVE; bool inactive = show_state == ui::SHOW_STATE_INACTIVE;
x11_window_->Map(inactive); GetXWindow()->Map(inactive);
} }
void DesktopWindowTreeHostX11::SetWindowTransparency() { void DesktopWindowTreeHostX11::SetWindowTransparency() {
bool has_alpha = x11_window_->has_alpha(); bool has_alpha = GetXWindow()->has_alpha();
compositor()->SetBackgroundColor(has_alpha ? SK_ColorTRANSPARENT compositor()->SetBackgroundColor(has_alpha ? SK_ColorTRANSPARENT
: SK_ColorWHITE); : SK_ColorWHITE);
window()->SetTransparent(has_alpha); window()->SetTransparent(has_alpha);
...@@ -1202,20 +1130,6 @@ void DesktopWindowTreeHostX11::DelayedChangeFrameType(Widget::FrameType type) { ...@@ -1202,20 +1130,6 @@ void DesktopWindowTreeHostX11::DelayedChangeFrameType(Widget::FrameType type) {
native_widget_delegate()->AsWidget()->non_client_view()->UpdateFrame(); native_widget_delegate()->AsWidget()->non_client_view()->UpdateFrame();
} }
gfx::Rect DesktopWindowTreeHostX11::ToDIPRect(
const gfx::Rect& rect_in_pixels) const {
gfx::RectF rect_in_dip = gfx::RectF(rect_in_pixels);
GetRootTransform().TransformRectReverse(&rect_in_dip);
return gfx::ToEnclosingRect(rect_in_dip);
}
gfx::Rect DesktopWindowTreeHostX11::ToPixelRect(
const gfx::Rect& rect_in_dip) const {
gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip);
GetRootTransform().TransformRect(&rect_in_pixels);
return gfx::ToEnclosingRect(rect_in_pixels);
}
base::OnceClosure DesktopWindowTreeHostX11::DisableEventListening() { base::OnceClosure DesktopWindowTreeHostX11::DisableEventListening() {
// Allows to open multiple file-pickers. See https://crbug.com/678982 // Allows to open multiple file-pickers. See https://crbug.com/678982
modal_dialog_counter_++; modal_dialog_counter_++;
...@@ -1238,7 +1152,7 @@ void DesktopWindowTreeHostX11::EnableEventListening() { ...@@ -1238,7 +1152,7 @@ void DesktopWindowTreeHostX11::EnableEventListening() {
void DesktopWindowTreeHostX11::OnCompleteSwapWithNewSize( void DesktopWindowTreeHostX11::OnCompleteSwapWithNewSize(
const gfx::Size& size) { const gfx::Size& size) {
x11_window_->NotifySwapAfterResize(); GetXWindow()->NotifySwapAfterResize();
} }
base::flat_map<std::string, std::string> base::flat_map<std::string, std::string>
...@@ -1249,8 +1163,8 @@ DesktopWindowTreeHostX11::GetKeyboardLayoutMap() { ...@@ -1249,8 +1163,8 @@ DesktopWindowTreeHostX11::GetKeyboardLayoutMap() {
} }
void DesktopWindowTreeHostX11::SetVisualId(VisualID visual_id) { void DesktopWindowTreeHostX11::SetVisualId(VisualID visual_id) {
DCHECK_EQ(x11_window_->window(), x11::None); DCHECK_EQ(GetXWindow()->window(), x11::None);
x11_window_->set_visual_id(visual_id); GetXWindow()->set_visual_id(visual_id);
} }
void DesktopWindowTreeHostX11::OnBoundsChanged(const gfx::Rect& new_bounds) { void DesktopWindowTreeHostX11::OnBoundsChanged(const gfx::Rect& new_bounds) {
...@@ -1275,7 +1189,7 @@ void DesktopWindowTreeHostX11::OnClosed() { ...@@ -1275,7 +1189,7 @@ void DesktopWindowTreeHostX11::OnClosed() {
void DesktopWindowTreeHostX11::OnWindowStateChanged( void DesktopWindowTreeHostX11::OnWindowStateChanged(
ui::PlatformWindowState new_state) { ui::PlatformWindowState new_state) {
bool was_minimized = x11_window_->was_minimized(); bool was_minimized = GetXWindow()->was_minimized();
bool is_minimized = IsMinimized(); bool is_minimized = IsMinimized();
// Propagate the window minimization information to the content window, so // Propagate the window minimization information to the content window, so
...@@ -1307,7 +1221,7 @@ void DesktopWindowTreeHostX11::OnWindowStateChanged( ...@@ -1307,7 +1221,7 @@ void DesktopWindowTreeHostX11::OnWindowStateChanged(
// a best effort attempt to get restored bounds by setting it to our // a best effort attempt to get restored bounds by setting it to our
// previously set bounds (and if we get this wrong, we aren't any worse // previously set bounds (and if we get this wrong, we aren't any worse
// off since we'd otherwise be returning our maximized bounds). // off since we'd otherwise be returning our maximized bounds).
restored_bounds_in_pixels_ = x11_window_->previous_bounds(); restored_bounds_in_pixels_ = GetXWindow()->previous_bounds();
} }
} else if (!IsMaximized() && !IsFullscreen()) { } else if (!IsMaximized() && !IsFullscreen()) {
// If we have restored bounds, but WM_STATE no longer claims to be // If we have restored bounds, but WM_STATE no longer claims to be
...@@ -1324,8 +1238,8 @@ void DesktopWindowTreeHostX11::OnWindowStateChanged( ...@@ -1324,8 +1238,8 @@ void DesktopWindowTreeHostX11::OnWindowStateChanged(
void DesktopWindowTreeHostX11::OnAcceleratedWidgetAvailable( void DesktopWindowTreeHostX11::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) { gfx::AcceleratedWidget widget) {
open_windows().push_front(x11_window_->window()); open_windows().push_front(widget);
WindowTreeHost::OnAcceleratedWidgetAvailable(); WindowTreeHostPlatform::OnAcceleratedWidgetAvailable(widget);
} }
void DesktopWindowTreeHostX11::OnAcceleratedWidgetDestroyed() {} void DesktopWindowTreeHostX11::OnAcceleratedWidgetDestroyed() {}
...@@ -1334,9 +1248,9 @@ void DesktopWindowTreeHostX11::OnActivationChanged(bool active) { ...@@ -1334,9 +1248,9 @@ void DesktopWindowTreeHostX11::OnActivationChanged(bool active) {
if (active) { if (active) {
// TODO(thomasanderson): Remove this window shuffling and use XWindowCache // TODO(thomasanderson): Remove this window shuffling and use XWindowCache
// instead. // instead.
::Window xwindow = x11_window_->window(); auto widget = GetAcceleratedWidget();
open_windows().remove(xwindow); open_windows().remove(widget);
open_windows().insert(open_windows().begin(), xwindow); open_windows().insert(open_windows().begin(), widget);
} }
desktop_native_widget_aura()->HandleActivationChanged(active); desktop_native_widget_aura()->HandleActivationChanged(active);
native_widget_delegate()->AsWidget()->GetRootView()->SchedulePaint(); native_widget_delegate()->AsWidget()->GetRootView()->SchedulePaint();
...@@ -1344,12 +1258,12 @@ void DesktopWindowTreeHostX11::OnActivationChanged(bool active) { ...@@ -1344,12 +1258,12 @@ void DesktopWindowTreeHostX11::OnActivationChanged(bool active) {
void DesktopWindowTreeHostX11::OnXWindowMapped() { void DesktopWindowTreeHostX11::OnXWindowMapped() {
for (DesktopWindowTreeHostObserverX11& observer : observer_list_) for (DesktopWindowTreeHostObserverX11& observer : observer_list_)
observer.OnWindowMapped(x11_window_->window()); observer.OnWindowMapped(GetXWindow()->window());
} }
void DesktopWindowTreeHostX11::OnXWindowUnmapped() { void DesktopWindowTreeHostX11::OnXWindowUnmapped() {
for (DesktopWindowTreeHostObserverX11& observer : observer_list_) for (DesktopWindowTreeHostObserverX11& observer : observer_list_)
observer.OnWindowUnmapped(x11_window_->window()); observer.OnWindowUnmapped(GetXWindow()->window());
} }
void DesktopWindowTreeHostX11::OnLostMouseGrab() { void DesktopWindowTreeHostX11::OnLostMouseGrab() {
...@@ -1412,6 +1326,20 @@ void DesktopWindowTreeHostX11::OnXWindowRawKeyEvent(XEvent* xev) { ...@@ -1412,6 +1326,20 @@ void DesktopWindowTreeHostX11::OnXWindowRawKeyEvent(XEvent* xev) {
} }
} }
ui::XWindow* DesktopWindowTreeHostX11::GetXWindow() {
DCHECK(platform_window());
// ui::X11Window inherits both PlatformWindow and ui::XWindow.
return static_cast<ui::XWindow*>(
static_cast<ui::X11Window*>(platform_window()));
}
const ui::XWindow* DesktopWindowTreeHostX11::GetXWindow() const {
DCHECK(platform_window());
// ui::X11Window inherits both PlatformWindow and ui::XWindow.
return static_cast<const ui::XWindow*>(
static_cast<const ui::X11Window*>(platform_window()));
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHost, public: // DesktopWindowTreeHost, public:
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "ui/aura/scoped_window_targeter.h" #include "ui/aura/scoped_window_targeter.h"
#include "ui/aura/window_tree_host.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
...@@ -27,7 +26,7 @@ ...@@ -27,7 +26,7 @@
#include "ui/platform_window/platform_window_handler/wm_move_resize_handler.h" #include "ui/platform_window/platform_window_handler/wm_move_resize_handler.h"
#include "ui/platform_window/x11/x11_window.h" #include "ui/platform_window/x11/x11_window.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_platform.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
namespace gfx { namespace gfx {
class ImageSkia; class ImageSkia;
...@@ -49,10 +48,9 @@ class NonClientFrameView; ...@@ -49,10 +48,9 @@ class NonClientFrameView;
class X11DesktopWindowMoveClient; class X11DesktopWindowMoveClient;
class WindowEventFilter; class WindowEventFilter;
class VIEWS_EXPORT DesktopWindowTreeHostX11 class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
: public DesktopWindowTreeHostPlatform, public ui::WmMoveResizeHandler,
public ui::WmMoveResizeHandler, public ui::XEventDelegate {
public ui::XEventDelegate {
public: public:
DesktopWindowTreeHostX11( DesktopWindowTreeHostX11(
internal::NativeWidgetDelegate* native_widget_delegate, internal::NativeWidgetDelegate* native_widget_delegate,
...@@ -170,9 +168,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -170,9 +168,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
bool ShouldCreateVisibilityController() const override; bool ShouldCreateVisibilityController() const override;
// Overridden from aura::WindowTreeHost: // Overridden from aura::WindowTreeHost:
gfx::Transform GetRootTransform() const override;
ui::EventSource* GetEventSource() override; ui::EventSource* GetEventSource() override;
gfx::AcceleratedWidget GetAcceleratedWidget() override;
void ShowImpl() override; void ShowImpl() override;
void HideImpl() override; void HideImpl() override;
gfx::Rect GetBoundsInPixels() const override; gfx::Rect GetBoundsInPixels() const override;
...@@ -209,11 +205,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -209,11 +205,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
// along with all aura client objects that direct behavior. // along with all aura client objects that direct behavior.
aura::WindowEventDispatcher* InitDispatcher(const Widget::InitParams& params); aura::WindowEventDispatcher* InitDispatcher(const Widget::InitParams& params);
// Adjusts |requested_size| to avoid the WM "feature" where setting the
// window size to the monitor size causes the WM to set the EWMH for
// fullscreen.
gfx::Size AdjustSize(const gfx::Size& requested_size);
// Sets whether the window's borders are provided by the window manager. // Sets whether the window's borders are provided by the window manager.
void SetUseNativeFrame(bool use_native_frame); void SetUseNativeFrame(bool use_native_frame);
...@@ -246,9 +237,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -246,9 +237,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
void DelayedChangeFrameType(Widget::FrameType new_type); void DelayedChangeFrameType(Widget::FrameType new_type);
gfx::Rect ToDIPRect(const gfx::Rect& rect_in_pixels) const;
gfx::Rect ToPixelRect(const gfx::Rect& rect_in_dip) const;
// Enables event listening after closing |dialog|. // Enables event listening after closing |dialog|.
void EnableEventListening(); void EnableEventListening();
...@@ -280,6 +268,13 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -280,6 +268,13 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
void OnXWindowDragDropEvent(XEvent* xev) override; void OnXWindowDragDropEvent(XEvent* xev) override;
void OnXWindowRawKeyEvent(XEvent* xev) override; void OnXWindowRawKeyEvent(XEvent* xev) override;
// Casts PlatformWindow into XWindow and returns the result. This is a temp
// solution to access XWindow, which is subclassed by the X11Window, which is
// PlatformWindow. This will be removed once we no longer to access XWindow
// directly. See https://crbug.com/990756.
ui::XWindow* GetXWindow();
const ui::XWindow* GetXWindow() const;
// The bounds of our window before we were maximized. // The bounds of our window before we were maximized.
gfx::Rect restored_bounds_in_pixels_; gfx::Rect restored_bounds_in_pixels_;
...@@ -309,7 +304,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -309,7 +304,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
// A list of all (top-level) windows that have been created but not yet // A list of all (top-level) windows that have been created but not yet
// destroyed. // destroyed.
static std::list<XID>* open_windows_; static std::list<gfx::AcceleratedWidget>* open_windows_;
// Cached value for SetVisible. Not the same as the IsVisible public API. // Cached value for SetVisible. Not the same as the IsVisible public API.
bool is_compositor_set_visible_ = false; bool is_compositor_set_visible_ = false;
...@@ -323,8 +318,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -323,8 +318,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
std::unique_ptr<CompositorObserver> compositor_observer_; std::unique_ptr<CompositorObserver> compositor_observer_;
std::unique_ptr<ui::X11Window> x11_window_;
// The display and the native X window hosting the root window. // The display and the native X window hosting the root window.
base::WeakPtrFactory<DesktopWindowTreeHostX11> close_widget_factory_{this}; base::WeakPtrFactory<DesktopWindowTreeHostX11> close_widget_factory_{this};
base::WeakPtrFactory<DesktopWindowTreeHostX11> weak_factory_{this}; base::WeakPtrFactory<DesktopWindowTreeHostX11> weak_factory_{this};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment