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_;
......
...@@ -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