Commit 37fdac8f authored by Findit's avatar Findit Committed by Maksim Sisov

Revert "X11 and Ozone: Move initialization to DWTHPlatform"

This reverts commit 543a7657.

Reason for revert:

Findit (https://goo.gl/kROfz5) identified CL at revision 693093 as the
culprit for failures in the build cycles as shown on:
https://analysis.chromium.org/waterfall/culprit?key=ag9zfmZpbmRpdC1mb3ItbWVyRAsSDVdmU3VzcGVjdGVkQ0wiMWNocm9taXVtLzU0M2E3NjU3MDA4ODVkMmRiMzU4NzgzOWRjZmZjNGVjOGFhZTI5ODYM

Sample Failed Build: https://ci.chromium.org/buildbot/chromium.linux/fuchsia-x64-cast/51291

Sample Failed Step: compile

Original change's description:
> 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: Scott Violet <sky@chromium.org>
> Reviewed-by: Thomas Anderson <thomasanderson@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#693093}


Change-Id: I1312146ae26ae17fed7985bba81ee81ad055ae32
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 990756
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1783522
Cr-Commit-Position: refs/heads/master@{#693104}
parent 03441a1e
......@@ -119,7 +119,7 @@ class DemoWindow : public ui::PlatformWindowDelegate {
#elif defined(OS_WIN)
return std::make_unique<ui::WinWindow>(this, props.bounds);
#elif defined(USE_X11)
auto x11_window = std::make_unique<ui::X11Window>(this);
auto x11_window = std::make_unique<ui::X11Window>(this, nullptr);
x11_window->Initialize(std::move(props));
return x11_window;
#else
......
......@@ -44,7 +44,7 @@ void VulkanDemo::Initialize() {
ui::PlatformWindowInitProperties properties;
properties.bounds = gfx::Rect(100, 100, 800, 600);
auto x11_window = std::make_unique<ui::X11Window>(this);
auto x11_window = std::make_unique<ui::X11Window>(this, nullptr);
x11_window->Initialize(std::move(properties));
window_ = std::move(x11_window);
......
......@@ -74,7 +74,7 @@ void WindowTreeHostPlatform::CreateAndSetPlatformWindow(
#elif defined(OS_WIN)
platform_window_.reset(new ui::WinWindow(this, properties.bounds));
#elif defined(USE_X11)
auto x11_window = std::make_unique<ui::X11Window>(this);
auto x11_window = std::make_unique<ui::X11Window>(this, nullptr);
x11_window->Initialize(std::move(properties));
SetPlatformWindow(std::move(x11_window));
#else
......
......@@ -25,7 +25,7 @@ namespace ui {
X11WindowOzone::X11WindowOzone(PlatformWindowDelegate* delegate,
X11WindowManagerOzone* window_manager)
: X11Window(delegate), window_manager_(window_manager) {
: X11Window(delegate, nullptr), window_manager_(window_manager) {
DCHECK(window_manager_);
// Set a class property key, which allows |this| to be used for interactive
......
......@@ -73,18 +73,18 @@ struct PlatformWindowInitProperties {
bool remove_standard_frame = false;
std::string workspace;
#if defined(OS_LINUX)
#if defined(USE_X11)
// Only used by X11:
bool prefer_dark_theme = false;
gfx::ImageSkia* icon = nullptr;
base::Optional<int> background_color;
#endif
// Specifies the res_name and res_class fields,
// respectively, of the WM_CLASS window property. Controls window grouping
// and desktop file matching in Linux window managers.
std::string wm_role_name;
std::string wm_class_name;
std::string wm_class_class;
#endif
};
} // namespace ui
......
......@@ -71,8 +71,10 @@ ui::XWindow::Configuration ConvertInitPropertiesToXWindowConfig(
} // namespace
X11Window::X11Window(PlatformWindowDelegateLinux* platform_window_delegate)
: platform_window_delegate_(platform_window_delegate) {}
X11Window::X11Window(PlatformWindowDelegateLinux* platform_window_delegate,
XEventDelegate* x_event_delegate)
: platform_window_delegate_(platform_window_delegate),
x_event_delegate_(x_event_delegate) {}
X11Window::~X11Window() {
PrepareForShutdown();
......@@ -85,11 +87,6 @@ void X11Window::Initialize(PlatformWindowInitProperties properties) {
Init(config);
}
void X11Window::SetXEventDelegate(XEventDelegate* delegate) {
DCHECK(!x_event_delegate_);
x_event_delegate_ = delegate;
}
void X11Window::Show() {
// TODO(msisov): pass inactivity to PlatformWindow::Show.
XWindow::Map(false /* inactive */);
......
......@@ -14,6 +14,8 @@
namespace ui {
class PlatformWindowDelegateLinux;
// Delegate interface used to communicate the X11PlatformWindow API client about
// XEvents of interest.
class X11_WINDOW_EXPORT XEventDelegate {
......@@ -36,13 +38,12 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
public XWindow,
public PlatformEventDispatcher {
public:
explicit X11Window(PlatformWindowDelegateLinux* platform_window_delegate);
X11Window(PlatformWindowDelegateLinux* platform_window_delegate,
XEventDelegate* x_event_delegate);
~X11Window() override;
void Initialize(PlatformWindowInitProperties properties);
void SetXEventDelegate(XEventDelegate* delegate);
// PlatformWindow:
void Show() override;
void Hide() override;
......@@ -109,7 +110,7 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
PlatformWindowDelegateLinux* const platform_window_delegate_;
XEventDelegate* x_event_delegate_ = nullptr;
XEventDelegate* const x_event_delegate_;
// Tells if the window got a ::Close call.
bool is_shutting_down_ = false;
......
......@@ -756,10 +756,8 @@ jumbo_component("views") {
]
}
if (is_linux) {
public += [ "widget/desktop_aura/desktop_window_tree_host_linux.h" ]
sources += [
"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.h",
]
......
......@@ -19,13 +19,13 @@ class Window;
namespace client {
class DragDropClient;
class ScreenPositionClient;
} // namespace client
}
} // namespace aura
namespace gfx {
class ImageSkia;
class Rect;
} // namespace gfx
}
namespace views {
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,7 +7,6 @@
#include "base/bind.h"
#include "base/threading/thread_task_runner_handle.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/transient_window_client.h"
#include "ui/base/hit_test.h"
......@@ -27,71 +26,6 @@
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:
......@@ -112,22 +46,15 @@ DesktopWindowTreeHostPlatform::~DesktopWindowTreeHostPlatform() {
}
void DesktopWindowTreeHostPlatform::Init(const Widget::InitParams& params) {
if (params.type == Widget::InitParams::TYPE_WINDOW)
content_window()->SetProperty(aura::client::kAnimationsDisabledKey, true);
ui::PlatformWindowInitProperties properties =
ConvertWidgetInitParamsToInitProperties(params);
AddAdditionalInitProperties(&properties);
CreateAndSetPlatformWindow(std::move(properties));
// 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);
WindowTreeHost::OnAcceleratedWidgetAvailable();
CreateCompositor(viz::FrameSinkId(), params.force_software_compositing);
aura::WindowTreeHost::OnAcceleratedWidgetAvailable();
InitHost();
if (!params.bounds.IsEmpty())
SetBoundsInDIP(params.bounds);
window()->Show();
}
......@@ -159,6 +86,18 @@ void DesktopWindowTreeHostPlatform::OnWidgetInitDone() {}
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>
DesktopWindowTreeHostPlatform::CreateTooltip() {
return std::make_unique<corewm::TooltipAura>();
......@@ -540,19 +479,6 @@ bool DesktopWindowTreeHostPlatform::ShouldCreateVisibilityController() const {
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) {
#if defined(USE_OZONE)
// Make sure the |event| is marked as a non-client if it's a non-client
......@@ -611,34 +537,70 @@ void DesktopWindowTreeHostPlatform::OnActivationChanged(bool active) {
desktop_native_widget_aura_->HandleActivationChanged(active);
}
base::Optional<gfx::Size>
DesktopWindowTreeHostPlatform::GetMinimumSizeForWindow() {
return ToPixelRect(gfx::Rect(native_widget_delegate()->GetMinimumSize()))
.size();
}
ui::PlatformWindowInitProperties
DesktopWindowTreeHostPlatform::ConvertWidgetInitParamsToInitProperties(
const Widget::InitParams& params) {
ui::PlatformWindowInitProperties properties;
base::Optional<gfx::Size>
DesktopWindowTreeHostPlatform::GetMaximumSizeForWindow() {
return ToPixelRect(gfx::Rect(native_widget_delegate()->GetMaximumSize()))
.size();
}
switch (params.type) {
case Widget::InitParams::TYPE_WINDOW:
properties.type = ui::PlatformWindowType::kWindow;
break;
aura::Window* DesktopWindowTreeHostPlatform::content_window() {
return desktop_native_widget_aura_->content_window();
}
case Widget::InitParams::TYPE_MENU:
properties.type = ui::PlatformWindowType::kMenu;
break;
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);
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;
}
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);
aura::Window* DesktopWindowTreeHostPlatform::content_window() {
return desktop_native_widget_aura_->content_window();
}
void DesktopWindowTreeHostPlatform::Relayout() {
......@@ -665,12 +627,19 @@ Widget* DesktopWindowTreeHostPlatform::GetWidget() {
return native_widget_delegate_->AsWidget();
}
const Widget* DesktopWindowTreeHostPlatform::GetWidget() const {
return native_widget_delegate_->AsWidget();
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);
}
void DesktopWindowTreeHostPlatform::AddAdditionalInitProperties(
ui::PlatformWindowInitProperties* properties) {}
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);
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHost:
......
......@@ -90,9 +90,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
bool ShouldUseDesktopNativeCursorManager() const override;
bool ShouldCreateVisibilityController() const override;
// WindowTreeHost:
gfx::Transform GetRootTransform() const override;
// PlatformWindowDelegateBase:
void DispatchEvent(ui::Event* event) override;
void OnClosed() override;
......@@ -103,8 +100,11 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
base::Optional<gfx::Size> GetMaximumSizeForWindow() override;
protected:
// TODO(https://crbug.com/990756): move these methods back to private
// once DWTHX11 stops using them.
// TODO(https://crbug.com/990756): move this back to unnamed namespace, when
// DWTHX11 stops initialization of the PlatformWindow. Also, remove these
// accessor methods.
ui::PlatformWindowInitProperties ConvertWidgetInitParamsToInitProperties(
const Widget::InitParams& params);
internal::NativeWidgetDelegate* native_widget_delegate() {
return native_widget_delegate_;
}
......@@ -114,11 +114,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
// Accessor for DesktopNativeWidgetAura::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:
FRIEND_TEST_ALL_PREFIXES(DesktopWindowTreeHostPlatformTest, HitTest);
......@@ -127,11 +122,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
void RemoveNonClientEventFilter();
Widget* GetWidget();
const Widget* GetWidget() const;
// There are platform specific properties that Linux may want to add.
virtual void AddAdditionalInitProperties(
ui::PlatformWindowInitProperties* properties);
gfx::Rect ToDIPRect(const gfx::Rect& rect_in_pixels) const;
gfx::Rect ToPixelRect(const gfx::Rect& rect_in_dip) const;
internal::NativeWidgetDelegate* const native_widget_delegate_;
DesktopNativeWidgetAura* const desktop_native_widget_aura_;
......
......@@ -53,8 +53,10 @@
#include "ui/gfx/path_x11.h"
#include "ui/gfx/x/x11.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/linux_ui/linux_ui.h"
#include "ui/views/views_delegate.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_native_cursor_manager.h"
......@@ -153,8 +155,9 @@ bool ShouldDiscardKeyEvent(XEvent* xev) {
DesktopWindowTreeHostX11::DesktopWindowTreeHostX11(
internal::NativeWidgetDelegate* native_widget_delegate,
DesktopNativeWidgetAura* desktop_native_widget_aura)
: DesktopWindowTreeHostLinux(native_widget_delegate,
desktop_native_widget_aura) {}
: DesktopWindowTreeHostPlatform(native_widget_delegate,
desktop_native_widget_aura),
x11_window_(std::make_unique<ui::X11Window>(this, this)) {}
DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() {
window()->ClearProperty(kHostForRootWindow);
......@@ -186,15 +189,15 @@ std::vector<aura::Window*> DesktopWindowTreeHostX11::GetAllOpenWindows() {
}
gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowBounds() const {
return GetBoundsInPixels();
return x11_window_->bounds();
}
gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowOuterBounds() const {
return GetXWindow()->GetOutterBounds();
return x11_window_->GetOutterBounds();
}
::Region DesktopWindowTreeHostX11::GetWindowShape() const {
return GetXWindow()->shape();
return x11_window_->shape();
}
void DesktopWindowTreeHostX11::AddObserver(
......@@ -227,9 +230,9 @@ void DesktopWindowTreeHostX11::CleanUpWindowList(
if (!open_windows_)
return;
while (!open_windows_->empty()) {
gfx::AcceleratedWidget widget = open_windows_->front();
func(GetContentWindowForXID(widget));
if (!open_windows_->empty() && open_windows_->front() == widget)
XID xid = open_windows_->front();
func(GetContentWindowForXID(xid));
if (!open_windows_->empty() && open_windows_->front() == xid)
open_windows_->erase(open_windows_->begin());
}
......@@ -241,34 +244,12 @@ void DesktopWindowTreeHostX11::CleanUpWindowList(
// DesktopWindowTreeHostX11, DesktopWindowTreeHost implementation:
void DesktopWindowTreeHostX11::Init(const Widget::InitParams& params) {
// If we have a parent, record the parent/child relationship. We use this
// 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);
if (params.type == Widget::InitParams::TYPE_WINDOW)
content_window()->SetProperty(aura::client::kAnimationsDisabledKey, true);
// Set XEventDelegate to receive selection, drag&drop and raw key events.
//
// 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)));
}
InitX11Window(params);
InitHost();
window()->Show();
}
void DesktopWindowTreeHostX11::OnNativeWidgetCreated(
......@@ -303,9 +284,8 @@ std::unique_ptr<corewm::Tooltip> DesktopWindowTreeHostX11::CreateTooltip() {
std::unique_ptr<aura::client::DragDropClient>
DesktopWindowTreeHostX11::CreateDragDropClient(
DesktopNativeCursorManager* cursor_manager) {
drag_drop_client_ = new DesktopDragDropClientAuraX11(window(), cursor_manager,
GetXWindow()->display(),
GetXWindow()->window());
drag_drop_client_ = new DesktopDragDropClientAuraX11(
window(), cursor_manager, x11_window_->display(), x11_window_->window());
drag_drop_client_->Init();
return base::WrapUnique(drag_drop_client_);
}
......@@ -314,7 +294,7 @@ void DesktopWindowTreeHostX11::Close() {
content_window()->Hide();
// TODO(erg): Might need to do additional hiding tasks here.
GetXWindow()->CancelResize();
x11_window_->CancelResize();
if (!close_widget_factory_.HasWeakPtrs()) {
// And we delay the close so that if we are called from an ATL callback,
......@@ -328,9 +308,9 @@ void DesktopWindowTreeHostX11::Close() {
}
void DesktopWindowTreeHostX11::CloseNow() {
if (GetXWindow()->window() == x11::None)
if (x11_window_->window() == x11::None)
return;
platform_window()->PrepareForShutdown();
x11_window_->PrepareForShutdown();
ReleaseCapture();
RemoveNonClientEventFilter();
......@@ -354,9 +334,9 @@ void DesktopWindowTreeHostX11::CloseNow() {
// causes a crash with in-process renderer.
DestroyCompositor();
open_windows().remove(GetAcceleratedWidget());
open_windows().remove(x11_window_->window());
platform_window()->Close();
x11_window_->Close();
}
aura::WindowTreeHost* DesktopWindowTreeHostX11::AsWindowTreeHost() {
......@@ -368,7 +348,7 @@ void DesktopWindowTreeHostX11::Show(ui::WindowShowState show_state,
if (compositor())
SetVisible(true);
if (!GetXWindow()->mapped_in_client() || IsMinimized())
if (!x11_window_->mapped_in_client() || IsMinimized())
MapWindow(show_state);
switch (show_state) {
......@@ -396,16 +376,16 @@ void DesktopWindowTreeHostX11::Show(ui::WindowShowState show_state,
}
bool DesktopWindowTreeHostX11::IsVisible() const {
return platform_window() ? GetXWindow()->IsVisible() : false;
return x11_window_->IsVisible();
}
void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) {
gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size();
size_in_pixels = AdjustSizeForDisplay(size_in_pixels);
size_in_pixels = AdjustSize(size_in_pixels);
bool size_changed = GetBoundsInPixels().size() != size_in_pixels;
bool size_changed = x11_window_->bounds().size() != size_in_pixels;
GetXWindow()->SetSize(size_in_pixels);
x11_window_->SetSize(size_in_pixels);
if (size_changed) {
OnHostResizedInPixels(size_in_pixels);
......@@ -414,8 +394,8 @@ void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) {
}
void DesktopWindowTreeHostX11::StackAbove(aura::Window* window) {
XDisplay* display = GetXWindow()->display();
::Window xwindow = GetXWindow()->window();
XDisplay* display = x11_window_->display();
::Window xwindow = x11_window_->window();
if (window && window->GetRootWindow()) {
::Window window_below = window->GetHost()->GetAcceleratedWidget();
......@@ -448,7 +428,7 @@ void DesktopWindowTreeHostX11::StackAbove(aura::Window* window) {
}
void DesktopWindowTreeHostX11::StackAtTop() {
GetXWindow()->StackAtTop();
x11_window_->StackAtTop();
}
void DesktopWindowTreeHostX11::CenterWindow(const gfx::Size& size) {
......@@ -498,7 +478,8 @@ void DesktopWindowTreeHostX11::GetWindowPlacement(
}
gfx::Rect DesktopWindowTreeHostX11::GetWindowBoundsInScreen() const {
return ToDIPRect(GetBoundsInPixels());
gfx::Rect bounds_in_pixels = x11_window_->bounds();
return ToDIPRect(bounds_in_pixels);
}
gfx::Rect DesktopWindowTreeHostX11::GetClientAreaBoundsInScreen() const {
......@@ -525,7 +506,7 @@ gfx::Rect DesktopWindowTreeHostX11::GetRestoredBounds() const {
}
std::string DesktopWindowTreeHostX11::GetWorkspace() const {
base::Optional<int> workspace = GetXWindow()->workspace();
base::Optional<int> workspace = x11_window_->workspace();
return workspace ? base::NumberToString(workspace.value()) : std::string();
}
......@@ -556,37 +537,37 @@ void DesktopWindowTreeHostX11::SetShape(
xregion = gfx::CreateRegionFromSkRegion(native_region);
}
}
GetXWindow()->SetShape(xregion);
x11_window_->SetShape(xregion);
ResetWindowRegion();
}
void DesktopWindowTreeHostX11::Activate() {
GetXWindow()->Activate();
x11_window_->Activate();
}
void DesktopWindowTreeHostX11::Deactivate() {
ReleaseCapture();
GetXWindow()->Deactivate();
x11_window_->Deactivate();
}
bool DesktopWindowTreeHostX11::IsActive() const {
return GetXWindow()->IsActive();
return x11_window_->IsActive();
}
void DesktopWindowTreeHostX11::Maximize() {
// TODO(nickdiego): Move into XWindow. For now, it is kept outside
// it due to |AdjustSizeForDisplay|, which depends on display::Display, which
// is not accessible at Ozone layer.
if (GetXWindow()->IsFullscreen()) {
// it due to |AdjustSize|, which depends on display::Display, which is not
// accessible at Ozone layer.
if (x11_window_->IsFullscreen()) {
// Unfullscreen the window if it is fullscreen.
GetXWindow()->SetFullscreen(false);
x11_window_->SetFullscreen(false);
// 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
// fullscreen mode).
gfx::Rect bounds = GetBoundsInPixels();
gfx::Rect bounds = x11_window_->bounds();
gfx::Rect adjusted_bounds_in_pixels(bounds.origin(),
AdjustSizeForDisplay(bounds.size()));
AdjustSize(bounds.size()));
if (adjusted_bounds_in_pixels != bounds)
SetBoundsInPixels(adjusted_bounds_in_pixels);
}
......@@ -594,30 +575,30 @@ void DesktopWindowTreeHostX11::Maximize() {
// 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
// heuristics that are in the PropertyNotify and ConfigureNotify handlers.
restored_bounds_in_pixels_ = GetBoundsInPixels();
restored_bounds_in_pixels_ = x11_window_->bounds();
GetXWindow()->Maximize();
x11_window_->Maximize();
if (IsMinimized())
Show(ui::SHOW_STATE_NORMAL, gfx::Rect());
}
void DesktopWindowTreeHostX11::Minimize() {
ReleaseCapture();
GetXWindow()->Minimize();
x11_window_->Minimize();
}
void DesktopWindowTreeHostX11::Restore() {
GetXWindow()->Unmaximize();
x11_window_->Unmaximize();
Show(ui::SHOW_STATE_NORMAL, gfx::Rect());
GetXWindow()->Unhide();
x11_window_->Unhide();
}
bool DesktopWindowTreeHostX11::IsMaximized() const {
return GetXWindow()->IsMaximized();
return x11_window_->IsMaximized();
}
bool DesktopWindowTreeHostX11::IsMinimized() const {
return GetXWindow()->IsMinimized();
return x11_window_->IsMinimized();
}
bool DesktopWindowTreeHostX11::HasCapture() const {
......@@ -630,11 +611,11 @@ void DesktopWindowTreeHostX11::SetZOrderLevel(ui::ZOrderLevel order) {
// Emulate the multiple window levels provided by other platforms by
// collapsing the z-order enum into kNormal = normal, everything else = always
// on top.
GetXWindow()->SetAlwaysOnTop(order != ui::ZOrderLevel::kNormal);
x11_window_->SetAlwaysOnTop(order != ui::ZOrderLevel::kNormal);
}
ui::ZOrderLevel DesktopWindowTreeHostX11::GetZOrderLevel() const {
bool window_always_on_top = GetXWindow()->is_always_on_top();
bool window_always_on_top = x11_window_->is_always_on_top();
bool level_always_on_top = z_order_ != ui::ZOrderLevel::kNormal;
if (window_always_on_top == level_always_on_top)
......@@ -658,15 +639,17 @@ void DesktopWindowTreeHostX11::SetVisible(bool visible) {
}
void DesktopWindowTreeHostX11::SetVisibleOnAllWorkspaces(bool always_visible) {
GetXWindow()->SetVisibleOnAllWorkspaces(always_visible);
x11_window_->SetVisibleOnAllWorkspaces(always_visible);
}
bool DesktopWindowTreeHostX11::IsVisibleOnAllWorkspaces() const {
return GetXWindow()->IsVisibleOnAllWorkspaces();
return x11_window_->IsVisibleOnAllWorkspaces();
}
bool DesktopWindowTreeHostX11::SetWindowTitle(const base::string16& title) {
return GetXWindow()->SetTitle(title);
auto* x_window = static_cast<ui::XWindow*>(x11_window_.get());
DCHECK(x_window);
return x_window->SetTitle(title);
}
void DesktopWindowTreeHostX11::ClearNativeFocus() {
......@@ -712,11 +695,11 @@ NonClientFrameView* DesktopWindowTreeHostX11::CreateNonClientFrameView() {
}
bool DesktopWindowTreeHostX11::ShouldUseNativeFrame() const {
return GetXWindow()->use_native_frame();
return x11_window_->use_native_frame();
}
bool DesktopWindowTreeHostX11::ShouldWindowContentsBeTransparent() const {
return GetXWindow()->has_alpha();
return x11_window_->has_alpha();
}
void DesktopWindowTreeHostX11::FrameTypeChanged() {
......@@ -744,7 +727,7 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) {
is_fullscreen_ = fullscreen;
if (is_fullscreen_)
GetXWindow()->CancelResize();
x11_window_->CancelResize();
// Work around a bug where if we try to unfullscreen, metacity immediately
// fullscreens us again. This is a little flickery and not necessary if
......@@ -756,7 +739,7 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) {
if (unmaximize_and_remaximize)
Restore();
GetXWindow()->SetFullscreen(fullscreen);
x11_window_->SetFullscreen(fullscreen);
if (unmaximize_and_remaximize)
Maximize();
......@@ -766,7 +749,7 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) {
// - works around Flash content which expects to have the size updated
// synchronously.
// See https://crbug.com/361408
gfx::Rect bounds = GetXWindow()->bounds();
gfx::Rect bounds = x11_window_->bounds();
if (fullscreen) {
display::Screen* screen = display::Screen::GetScreen();
const display::Display display = screen->GetDisplayNearestWindow(window());
......@@ -775,12 +758,12 @@ void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) {
} else {
bounds = restored_bounds_in_pixels_;
}
GetXWindow()->set_bounds(bounds);
x11_window_->set_bounds(bounds);
OnHostMovedInPixels(bounds.origin());
OnHostResizedInPixels(bounds.size());
if (GetXWindow()->IsFullscreen() == fullscreen) {
if (x11_window_->IsFullscreen() == fullscreen) {
Relayout();
ResetWindowRegion();
}
......@@ -793,16 +776,16 @@ bool DesktopWindowTreeHostX11::IsFullscreen() const {
}
void DesktopWindowTreeHostX11::SetOpacity(float opacity) {
GetXWindow()->SetOpacity(opacity);
x11_window_->SetOpacity(opacity);
}
void DesktopWindowTreeHostX11::SetAspectRatio(const gfx::SizeF& aspect_ratio) {
GetXWindow()->SetAspectRatio(aspect_ratio);
x11_window_->SetAspectRatio(aspect_ratio);
}
void DesktopWindowTreeHostX11::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
GetXWindow()->SetWindowIcons(window_icon, app_icon);
x11_window_->SetWindowIcons(window_icon, app_icon);
}
void DesktopWindowTreeHostX11::InitModalType(ui::ModalType modal_type) {
......@@ -818,7 +801,7 @@ void DesktopWindowTreeHostX11::InitModalType(ui::ModalType modal_type) {
}
void DesktopWindowTreeHostX11::FlashFrame(bool flash_frame) {
GetXWindow()->FlashFrame(flash_frame);
x11_window_->FlashFrame(flash_frame);
}
bool DesktopWindowTreeHostX11::IsAnimatingClosed() const {
......@@ -833,7 +816,7 @@ bool DesktopWindowTreeHostX11::IsTranslucentWindowOpacitySupported() const {
}
void DesktopWindowTreeHostX11::SizeConstraintsChanged() {
GetXWindow()->UpdateMinAndMaxSize();
x11_window_->UpdateMinAndMaxSize();
}
bool DesktopWindowTreeHostX11::ShouldUpdateWindowTransparency() const {
......@@ -849,45 +832,63 @@ bool DesktopWindowTreeHostX11::ShouldCreateVisibilityController() const {
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, aura::WindowTreeHost implementatio
// DesktopWindowTreeHostX11, aura::WindowTreeHost implementation:
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() {
return this;
}
gfx::AcceleratedWidget DesktopWindowTreeHostX11::GetAcceleratedWidget() {
return x11_window_->window();
}
void DesktopWindowTreeHostX11::ShowImpl() {
Show(ui::SHOW_STATE_NORMAL, gfx::Rect());
}
void DesktopWindowTreeHostX11::HideImpl() {
if (GetXWindow()->Hide())
auto* x_window = static_cast<ui::XWindow*>(x11_window_.get());
DCHECK(x_window);
if (x_window->Hide())
SetVisible(false);
}
gfx::Rect DesktopWindowTreeHostX11::GetBoundsInPixels() const {
return GetXWindow()->bounds();
return x11_window_->bounds();
}
void DesktopWindowTreeHostX11::SetBoundsInPixels(
const gfx::Rect& requested_bounds_in_pixel) {
gfx::Rect bounds = GetXWindow()->bounds();
gfx::Rect bounds_in_pixels(
requested_bounds_in_pixel.origin(),
AdjustSizeForDisplay(requested_bounds_in_pixel.size()));
gfx::Rect bounds = x11_window_->bounds();
gfx::Rect bounds_in_pixels(requested_bounds_in_pixel.origin(),
AdjustSize(requested_bounds_in_pixel.size()));
bool size_changed = bounds.size() != bounds_in_pixels.size();
if (size_changed) {
// Only cancel the delayed resize task if we're already about to call
// OnHostResized in this function.
GetXWindow()->CancelResize();
x11_window_->CancelResize();
}
platform_window()->SetBounds(bounds_in_pixels);
x11_window_->SetBounds(bounds_in_pixels);
}
gfx::Point DesktopWindowTreeHostX11::GetLocationOnScreenInPixels() const {
return GetXWindow()->bounds().origin();
return x11_window_->bounds().origin();
}
void DesktopWindowTreeHostX11::SetCapture() {
......@@ -909,7 +910,7 @@ void DesktopWindowTreeHostX11::SetCapture() {
if (old_capturer)
old_capturer->OnHostLostWindowCapture();
GetXWindow()->GrabPointer();
x11_window_->GrabPointer();
}
void DesktopWindowTreeHostX11::ReleaseCapture() {
......@@ -918,7 +919,7 @@ void DesktopWindowTreeHostX11::ReleaseCapture() {
// the topmost window underneath the mouse so the capture release being
// asynchronous is likely inconsequential.
g_current_capture = nullptr;
GetXWindow()->ReleasePointerGrab();
x11_window_->ReleasePointerGrab();
OnHostLostWindowCapture();
}
......@@ -947,12 +948,12 @@ bool DesktopWindowTreeHostX11::IsKeyLocked(ui::DomCode dom_code) {
}
void DesktopWindowTreeHostX11::SetCursorNative(gfx::NativeCursor cursor) {
GetXWindow()->SetCursor(cursor.platform());
x11_window_->SetCursor(cursor.platform());
}
void DesktopWindowTreeHostX11::MoveCursorToScreenLocationInPixels(
const gfx::Point& location_in_pixels) {
GetXWindow()->MoveCursorTo(location_in_pixels);
x11_window_->MoveCursorTo(location_in_pixels);
}
void DesktopWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) {
......@@ -976,21 +977,92 @@ void DesktopWindowTreeHostX11::OnDisplayMetricsChanged(
// compositor redraw will be scheduled. This is weird, but works.
// TODO(thomasanderson): Figure out a more direct way of doing
// this.
GetXWindow()->DispatchResize();
x11_window_->DispatchResize();
}
}
////////////////////////////////////////////////////////////////////////////////
// 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(
int hittest,
const gfx::Point& pointer_location) {
GetXWindow()->WmMoveResize(hittest, pointer_location);
x11_window_->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) {
GetXWindow()->SetUseNativeFrame(use_native_frame);
x11_window_->SetUseNativeFrame(use_native_frame);
ResetWindowRegion();
}
......@@ -1062,25 +1134,25 @@ void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) {
void DesktopWindowTreeHostX11::ResetWindowRegion() {
_XRegion* xregion = nullptr;
if (!GetXWindow()->use_custom_shape() && !IsMaximized() && !IsFullscreen()) {
if (!x11_window_->use_custom_shape() && !IsMaximized() && !IsFullscreen()) {
SkPath window_mask;
Widget* widget = native_widget_delegate()->AsWidget();
if (widget->non_client_view()) {
// Some frame views define a custom (non-rectangular) window mask. If
// so, use it to define the window shape. If not, fall through.
widget->non_client_view()->GetWindowMask(GetXWindow()->bounds().size(),
widget->non_client_view()->GetWindowMask(x11_window_->bounds().size(),
&window_mask);
if (window_mask.countPoints() > 0) {
xregion = gfx::CreateRegionFromSkPath(window_mask);
}
}
}
GetXWindow()->UpdateWindowRegion(xregion);
x11_window_->UpdateWindowRegion(xregion);
}
std::list<gfx::AcceleratedWidget>& DesktopWindowTreeHostX11::open_windows() {
std::list<XID>& DesktopWindowTreeHostX11::open_windows() {
if (!open_windows_)
open_windows_ = new std::list<gfx::AcceleratedWidget>();
open_windows_ = new std::list<XID>();
return *open_windows_;
}
......@@ -1098,11 +1170,11 @@ void DesktopWindowTreeHostX11::MapWindow(ui::WindowShowState show_state) {
// http://standards.freedesktop.org/wm-spec/latest/ar01s05.html
bool inactive = show_state == ui::SHOW_STATE_INACTIVE;
GetXWindow()->Map(inactive);
x11_window_->Map(inactive);
}
void DesktopWindowTreeHostX11::SetWindowTransparency() {
bool has_alpha = GetXWindow()->has_alpha();
bool has_alpha = x11_window_->has_alpha();
compositor()->SetBackgroundColor(has_alpha ? SK_ColorTRANSPARENT
: SK_ColorWHITE);
window()->SetTransparent(has_alpha);
......@@ -1130,6 +1202,20 @@ void DesktopWindowTreeHostX11::DelayedChangeFrameType(Widget::FrameType type) {
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() {
// Allows to open multiple file-pickers. See https://crbug.com/678982
modal_dialog_counter_++;
......@@ -1152,7 +1238,7 @@ void DesktopWindowTreeHostX11::EnableEventListening() {
void DesktopWindowTreeHostX11::OnCompleteSwapWithNewSize(
const gfx::Size& size) {
GetXWindow()->NotifySwapAfterResize();
x11_window_->NotifySwapAfterResize();
}
base::flat_map<std::string, std::string>
......@@ -1163,8 +1249,8 @@ DesktopWindowTreeHostX11::GetKeyboardLayoutMap() {
}
void DesktopWindowTreeHostX11::SetVisualId(VisualID visual_id) {
DCHECK_EQ(GetXWindow()->window(), x11::None);
GetXWindow()->set_visual_id(visual_id);
DCHECK_EQ(x11_window_->window(), x11::None);
x11_window_->set_visual_id(visual_id);
}
void DesktopWindowTreeHostX11::OnBoundsChanged(const gfx::Rect& new_bounds) {
......@@ -1189,7 +1275,7 @@ void DesktopWindowTreeHostX11::OnClosed() {
void DesktopWindowTreeHostX11::OnWindowStateChanged(
ui::PlatformWindowState new_state) {
bool was_minimized = GetXWindow()->was_minimized();
bool was_minimized = x11_window_->was_minimized();
bool is_minimized = IsMinimized();
// Propagate the window minimization information to the content window, so
......@@ -1221,7 +1307,7 @@ void DesktopWindowTreeHostX11::OnWindowStateChanged(
// 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
// off since we'd otherwise be returning our maximized bounds).
restored_bounds_in_pixels_ = GetXWindow()->previous_bounds();
restored_bounds_in_pixels_ = x11_window_->previous_bounds();
}
} else if (!IsMaximized() && !IsFullscreen()) {
// If we have restored bounds, but WM_STATE no longer claims to be
......@@ -1238,8 +1324,8 @@ void DesktopWindowTreeHostX11::OnWindowStateChanged(
void DesktopWindowTreeHostX11::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) {
open_windows().push_front(widget);
WindowTreeHostPlatform::OnAcceleratedWidgetAvailable(widget);
open_windows().push_front(x11_window_->window());
WindowTreeHost::OnAcceleratedWidgetAvailable();
}
void DesktopWindowTreeHostX11::OnAcceleratedWidgetDestroyed() {}
......@@ -1248,9 +1334,9 @@ void DesktopWindowTreeHostX11::OnActivationChanged(bool active) {
if (active) {
// TODO(thomasanderson): Remove this window shuffling and use XWindowCache
// instead.
auto widget = GetAcceleratedWidget();
open_windows().remove(widget);
open_windows().insert(open_windows().begin(), widget);
::Window xwindow = x11_window_->window();
open_windows().remove(xwindow);
open_windows().insert(open_windows().begin(), xwindow);
}
desktop_native_widget_aura()->HandleActivationChanged(active);
native_widget_delegate()->AsWidget()->GetRootView()->SchedulePaint();
......@@ -1258,12 +1344,12 @@ void DesktopWindowTreeHostX11::OnActivationChanged(bool active) {
void DesktopWindowTreeHostX11::OnXWindowMapped() {
for (DesktopWindowTreeHostObserverX11& observer : observer_list_)
observer.OnWindowMapped(GetXWindow()->window());
observer.OnWindowMapped(x11_window_->window());
}
void DesktopWindowTreeHostX11::OnXWindowUnmapped() {
for (DesktopWindowTreeHostObserverX11& observer : observer_list_)
observer.OnWindowUnmapped(GetXWindow()->window());
observer.OnWindowUnmapped(x11_window_->window());
}
void DesktopWindowTreeHostX11::OnLostMouseGrab() {
......@@ -1326,20 +1412,6 @@ 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:
......
......@@ -19,6 +19,7 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.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/size.h"
#include "ui/gfx/x/x11_types.h"
......@@ -26,7 +27,7 @@
#include "ui/platform_window/platform_window_handler/wm_move_resize_handler.h"
#include "ui/platform_window/x11/x11_window.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_platform.h"
namespace gfx {
class ImageSkia;
......@@ -48,7 +49,8 @@ class NonClientFrameView;
class X11DesktopWindowMoveClient;
class WindowEventFilter;
class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
class VIEWS_EXPORT DesktopWindowTreeHostX11
: public DesktopWindowTreeHostPlatform,
public ui::WmMoveResizeHandler,
public ui::XEventDelegate {
public:
......@@ -168,7 +170,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
bool ShouldCreateVisibilityController() const override;
// Overridden from aura::WindowTreeHost:
gfx::Transform GetRootTransform() const override;
ui::EventSource* GetEventSource() override;
gfx::AcceleratedWidget GetAcceleratedWidget() override;
void ShowImpl() override;
void HideImpl() override;
gfx::Rect GetBoundsInPixels() const override;
......@@ -205,6 +209,11 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
// along with all aura client objects that direct behavior.
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.
void SetUseNativeFrame(bool use_native_frame);
......@@ -237,6 +246,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
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|.
void EnableEventListening();
......@@ -268,13 +280,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
void OnXWindowDragDropEvent(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.
gfx::Rect restored_bounds_in_pixels_;
......@@ -304,7 +309,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
// A list of all (top-level) windows that have been created but not yet
// destroyed.
static std::list<gfx::AcceleratedWidget>* open_windows_;
static std::list<XID>* open_windows_;
// Cached value for SetVisible. Not the same as the IsVisible public API.
bool is_compositor_set_visible_ = false;
......@@ -318,6 +323,8 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
std::unique_ptr<CompositorObserver> compositor_observer_;
std::unique_ptr<ui::X11Window> x11_window_;
// The display and the native X window hosting the root window.
base::WeakPtrFactory<DesktopWindowTreeHostX11> close_widget_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