Commit 9616c57e authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

X11 and Ozone: Clean up and move trivial code to DWTHPlatform/Linux

No functionality changes here, but just moving the code and implementing
missing interfaces in PlatformWindow.

Bug: 990756
Change-Id: Ia39b15c580ea831a5e31bb6d76a807b3321c4f4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1844820
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@{#704605}
parent de63ca3b
......@@ -11,6 +11,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/base/hit_test_x11.h"
#include "ui/base/x/x11_pointer_grab.h"
#include "ui/base/x/x11_util.h"
......@@ -25,6 +26,7 @@
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_rep.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/x11_path.h"
#include "ui/platform_window/common/platform_window_defaults.h"
......@@ -377,7 +379,7 @@ void XWindow::Init(const Configuration& config) {
ui::SetIntProperty(xwindow_, "_NET_WM_BYPASS_COMPOSITOR", "CARDINAL", 2);
if (config.icon)
SetWindowIcons(gfx::ImageSkia(), *config.icon);
SetXWindowIcons(gfx::ImageSkia(), *config.icon);
}
void XWindow::Map(bool inactive) {
......@@ -712,7 +714,7 @@ bool XWindow::SetTitle(base::string16 title) {
return true;
}
void XWindow::SetOpacity(float opacity) {
void XWindow::SetXWindowOpacity(float opacity) {
// X server opacity is in terms of 32 bit unsigned int space, and counts from
// the opposite direction.
// XChangeProperty() expects "cardinality" to be long.
......@@ -734,7 +736,7 @@ void XWindow::SetOpacity(float opacity) {
}
}
void XWindow::SetAspectRatio(const gfx::SizeF& aspect_ratio) {
void XWindow::SetXWindowAspectRatio(const gfx::SizeF& aspect_ratio) {
XSizeHints size_hints;
size_hints.flags = 0;
long supplied_return;
......@@ -746,7 +748,7 @@ void XWindow::SetAspectRatio(const gfx::SizeF& aspect_ratio) {
XSetWMNormalHints(xdisplay_, xwindow_, &size_hints);
}
void XWindow::SetWindowIcons(const gfx::ImageSkia& window_icon,
void XWindow::SetXWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
// TODO(erg): The way we handle icons across different versions of chrome
// could be substantially improved. The Windows version does its own thing
......@@ -924,12 +926,6 @@ void XWindow::SetUseNativeFrame(bool use_native_frame) {
ResetWindowRegion();
}
void XWindow::SetShape(XRegion* xregion) {
custom_window_shape_ = !!xregion;
window_shape_.reset(xregion);
ResetWindowRegion();
}
void XWindow::OnCrossingEvent(bool enter,
bool focus_in_window_or_ancestor,
int mode,
......@@ -1561,6 +1557,39 @@ void XWindow::ConfineCursorTo(const gfx::Rect& bounds) {
has_pointer_barriers_ = true;
}
bool XWindow::ContainsPointInRegion(const gfx::Point& point) const {
if (!shape())
return true;
return XPointInRegion(shape(), point.x(), point.y()) == x11::True;
}
void XWindow::SetXWindowShape(std::unique_ptr<NativeShapeRects> native_shape,
const gfx::Transform& transform) {
XRegion* xregion = nullptr;
if (native_shape) {
SkRegion native_region;
for (const gfx::Rect& rect : *native_shape)
native_region.op(gfx::RectToSkIRect(rect), SkRegion::kUnion_Op);
if (!transform.IsIdentity() && !native_region.isEmpty()) {
SkPath path_in_dip;
if (native_region.getBoundaryPath(&path_in_dip)) {
SkPath path_in_pixels;
path_in_dip.transform(transform.matrix(), &path_in_pixels);
xregion = gfx::CreateRegionFromSkPath(path_in_pixels);
} else {
xregion = XCreateRegion();
}
} else {
xregion = gfx::CreateRegionFromSkRegion(native_region);
}
}
custom_window_shape_ = !!xregion;
window_shape_.reset(xregion);
ResetWindowRegion();
}
void XWindow::UnconfineCursor() {
if (!has_pointer_barriers_)
return;
......
......@@ -27,6 +27,7 @@ class SkPath;
namespace gfx {
class ImageSkia;
class Transform;
} // namespace gfx
namespace ui {
......@@ -50,6 +51,8 @@ class COMPONENT_EXPORT(UI_BASE_X) XWindow {
public:
class Delegate;
using NativeShapeRects = std::vector<gfx::Rect>;
enum class WindowType {
kWindow,
kPopup,
......@@ -121,9 +124,9 @@ class COMPONENT_EXPORT(UI_BASE_X) XWindow {
void SetCursor(::Cursor cursor);
bool SetTitle(base::string16 title);
void SetOpacity(float opacity);
void SetAspectRatio(const gfx::SizeF& aspect_ratio);
void SetWindowIcons(const gfx::ImageSkia& window_icon,
void SetXWindowOpacity(float opacity);
void SetXWindowAspectRatio(const gfx::SizeF& aspect_ratio);
void SetXWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon);
void SetXWindowVisibleOnAllWorkspaces(bool visible);
bool IsXWindowVisibleOnAllWorkspaces() const;
......@@ -132,12 +135,18 @@ class COMPONENT_EXPORT(UI_BASE_X) XWindow {
void SetFlashFrameHint(bool flash_frame);
void UpdateMinAndMaxSize();
void SetUseNativeFrame(bool use_native_frame);
void SetShape(XRegion* xregion);
void DispatchResize();
void CancelResize();
void NotifySwapAfterResize();
void ConfineCursorTo(const gfx::Rect& bounds);
// Returns if the point is within XWindow shape. If shape is not set, always
// returns true.
bool ContainsPointInRegion(const gfx::Point& point) const;
void SetXWindowShape(std::unique_ptr<NativeShapeRects> native_shape,
const gfx::Transform& transform);
// Resets the window region for the current window bounds if necessary.
void ResetWindowRegion();
......
......@@ -153,6 +153,15 @@ gfx::Rect DrmWindowHost::GetRestoredBoundsInPixels() const {
return gfx::Rect();
}
void DrmWindowHost::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
NOTREACHED();
}
void DrmWindowHost::SizeConstraintsChanged() {
NOTREACHED();
}
void DrmWindowHost::OnMouseEnter() {
delegate_->OnMouseEnter();
}
......
......@@ -83,6 +83,10 @@ class DrmWindowHost : public PlatformWindowBase,
void ConfineCursorToBounds(const gfx::Rect& bounds) override;
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
void SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) override;
void SizeConstraintsChanged() override;
void OnMouseEnter();
// PlatformEventDispatcher:
......
......@@ -184,6 +184,15 @@ gfx::Rect ScenicWindow::GetRestoredBoundsInPixels() const {
return gfx::Rect();
}
void ScenicWindow::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
NOTIMPLEMENTED();
}
void ScenicWindow::SizeConstraintsChanged() {
NOTIMPLEMENTED();
}
void ScenicWindow::UpdateSize() {
gfx::SizeF scaled = ScaleSize(size_dips_, device_pixel_ratio_);
size_pixels_ = gfx::Size(ceilf(scaled.width()), ceilf(scaled.height()));
......
......@@ -72,6 +72,9 @@ class COMPONENT_EXPORT(OZONE) ScenicWindow
void ConfineCursorToBounds(const gfx::Rect& bounds) override;
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
void SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) override;
void SizeConstraintsChanged() override;
private:
// Callbacks for |scenic_session_|.
......
......@@ -545,6 +545,19 @@ bool WaylandWindow::ShouldWindowContentsBeTransparent() const {
return false;
}
void WaylandWindow::SetAspectRatio(const gfx::SizeF& aspect_ratio) {
NOTIMPLEMENTED_LOG_ONCE();
}
void WaylandWindow::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
NOTIMPLEMENTED_LOG_ONCE();
}
void WaylandWindow::SizeConstraintsChanged() {
NOTIMPLEMENTED_LOG_ONCE();
}
bool WaylandWindow::CanDispatchEvent(const PlatformEvent& event) {
// This window is a nested popup window, all the events must be forwarded
// to the main popup window.
......
......@@ -139,6 +139,10 @@ class WaylandWindow : public PlatformWindowLinux,
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
bool ShouldWindowContentsBeTransparent() const override;
void SetAspectRatio(const gfx::SizeF& aspect_ratio) override;
void SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) override;
void SizeConstraintsChanged() override;
// PlatformEventDispatcher
bool CanDispatchEvent(const PlatformEvent& event) override;
......
......@@ -4,6 +4,8 @@
#include "ui/platform_window/platform_window_base.h"
#include "ui/gfx/geometry/rect.h"
namespace ui {
PlatformWindowBase::PlatformWindowBase() = default;
......@@ -26,4 +28,20 @@ void PlatformWindowBase::StackAtTop() {}
void PlatformWindowBase::FlashFrame(bool flash_frame) {}
void PlatformWindowBase::SetShape(std::unique_ptr<ShapeRects> native_shape,
const gfx::Transform& transform) {}
void PlatformWindowBase::SetAspectRatio(const gfx::SizeF& aspect_ratio) {}
void PlatformWindowBase::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {}
bool PlatformWindowBase::IsAnimatingClosed() const {
return false;
}
bool PlatformWindowBase::IsTranslucentWindowOpacitySupported() const {
return false;
}
} // namespace ui
......@@ -15,8 +15,11 @@
#include "ui/platform_window/platform_window_delegate.h"
namespace gfx {
class ImageSkia;
class Point;
class Rect;
class SizeF;
class Transform;
} // namespace gfx
namespace ui {
......@@ -84,6 +87,16 @@ class PlatformWindowBase : public PropertyHandler {
virtual void SetRestoredBoundsInPixels(const gfx::Rect& bounds) = 0;
virtual gfx::Rect GetRestoredBoundsInPixels() const = 0;
// Sets the Window icons. |window_icon| is a 16x16 icon suitable for use in
// a title bar. |app_icon| is a larger size for use in the host environment
// app switching UI.
virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) = 0;
// Notifies that size constraints of the host have been changed and the
// PlatformWindow must react on them accordingly.
virtual void SizeConstraintsChanged() = 0;
// Tells if the content of the platform window should be transparent. By
// default returns false.
virtual bool ShouldWindowContentsBeTransparent() const;
......@@ -102,6 +115,25 @@ class PlatformWindowBase : public PropertyHandler {
// is set, the PlatformWindow must draw attention to it. If |flash_frame| is
// not set, flashing must be stopped.
virtual void FlashFrame(bool flash_frame);
using ShapeRects = std::vector<gfx::Rect>;
// Sets shape of the PlatformWindow. ShapeRects corresponds to the
// Widget::ShapeRects that is a vector of gfx::Rects that describe the shape.
virtual void SetShape(std::unique_ptr<ShapeRects> native_shape,
const gfx::Transform& transform);
// Sets the aspect ratio of the Platform Window, which will be
// maintained during interactive resizing. This size disregards title bar and
// borders. Once set, some platforms ensure the content will only size to
// integer multiples of |aspect_ratio|.
virtual void SetAspectRatio(const gfx::SizeF& aspect_ratio);
// Returns true if the window was closed but is still showing because of
// animations.
virtual bool IsAnimatingClosed() const;
// Returns true if the window supports translucency.
virtual bool IsTranslucentWindowOpacitySupported() const;
};
} // namespace ui
......
......@@ -26,4 +26,15 @@ bool PlatformWindowLinux::IsVisibleOnAllWorkspaces() const {
return false;
}
gfx::Rect PlatformWindowLinux::GetXRootWindowOuterBounds() const {
return {};
}
bool PlatformWindowLinux::ContainsPointInXRegion(
const gfx::Point& point) const {
return false;
}
void PlatformWindowLinux::SetOpacityForXWindow(float opacity) {}
} // namespace ui
......@@ -6,6 +6,7 @@
#define UI_PLATFORM_WINDOW_PLATFORM_WINDOW_LINUX_H_
#include "base/optional.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/platform_window/platform_window_base.h"
namespace ui {
......@@ -30,6 +31,18 @@ class PlatformWindowLinux : public PlatformWindowBase {
// X11-specific. Returns true if the PlatformWindow is visible on all
// workspaces.
virtual bool IsVisibleOnAllWorkspaces() const;
// X11-specific. Returns the current bounds in terms of the X11 Root Window
// including the borders provided by the window manager (if any).
virtual gfx::Rect GetXRootWindowOuterBounds() const;
// X11-specific. Says if the X11 Root Window contains the point within its
// set shape. If shape is not set, returns true.
virtual bool ContainsPointInXRegion(const gfx::Point& point) const;
// X11-specific. Asks X11 to set transparency of the X11 Root Window. Not
// used for Wayland as it uses alpha channel to blend a window instead.
virtual void SetOpacityForXWindow(float opacity);
};
} // namespace ui
......
......@@ -96,4 +96,9 @@ gfx::Rect StubWindow::GetRestoredBoundsInPixels() const {
return gfx::Rect();
}
void StubWindow::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {}
void StubWindow::SizeConstraintsChanged() {}
} // namespace ui
......@@ -53,6 +53,9 @@ class STUB_WINDOW_EXPORT StubWindow : public PlatformWindowBase {
void ConfineCursorToBounds(const gfx::Rect& bounds) override;
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
void SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) override;
void SizeConstraintsChanged() override;
PlatformWindowDelegate* delegate_;
gfx::Rect bounds_;
......
......@@ -195,6 +195,34 @@ void WinWindow::SetVisibilityChangedAnimationsEnabled(bool enabled) {
NOTIMPLEMENTED_LOG_ONCE();
}
void WinWindow::SetShape(std::unique_ptr<ShapeRects> native_shape,
const gfx::Transform& transform) {
NOTIMPLEMENTED_LOG_ONCE();
}
void WinWindow::SetAspectRatio(const gfx::SizeF& aspect_ratio) {
NOTIMPLEMENTED_LOG_ONCE();
}
void WinWindow::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
NOTIMPLEMENTED_LOG_ONCE();
}
void WinWindow::SizeConstraintsChanged() {
NOTIMPLEMENTED_LOG_ONCE();
}
bool WinWindow::IsAnimatingClosed() const {
NOTIMPLEMENTED_LOG_ONCE();
return false;
}
bool WinWindow::IsTranslucentWindowOpacitySupported() const {
NOTIMPLEMENTED_LOG_ONCE();
return false;
}
bool WinWindow::IsFullscreen() const {
return GetPlatformWindowState() == PlatformWindowState::kFullScreen;
}
......
......@@ -59,6 +59,14 @@ class WIN_WINDOW_EXPORT WinWindow : public PlatformWindowWin,
void StackAtTop() override;
void FlashFrame(bool flash_frame) override;
void SetVisibilityChangedAnimationsEnabled(bool enabled) override;
void SetShape(std::unique_ptr<ShapeRects> native_shape,
const gfx::Transform& transform) override;
void SetAspectRatio(const gfx::SizeF& aspect_ratio) override;
void SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) override;
void SizeConstraintsChanged() override;
bool IsAnimatingClosed() const override;
bool IsTranslucentWindowOpacitySupported() const override;
bool IsFullscreen() const;
......
......@@ -6,6 +6,7 @@
#include "base/trace_event/trace_event.h"
#include "ui/base/x/x11_util.h"
#include "ui/base/x/x11_util_internal.h"
#include "ui/display/screen.h"
#include "ui/events/devices/x11/touch_factory_x11.h"
#include "ui/events/event.h"
......@@ -398,6 +399,43 @@ void X11Window::FlashFrame(bool flash_frame) {
XWindow::SetFlashFrameHint(flash_frame);
}
gfx::Rect X11Window::GetXRootWindowOuterBounds() const {
return XWindow::GetOutterBounds();
}
bool X11Window::ContainsPointInXRegion(const gfx::Point& point) const {
return XWindow::ContainsPointInRegion(point);
}
void X11Window::SetShape(std::unique_ptr<ShapeRects> native_shape,
const gfx::Transform& transform) {
return XWindow::SetXWindowShape(std::move(native_shape), transform);
}
void X11Window::SetOpacityForXWindow(float opacity) {
XWindow::SetXWindowOpacity(opacity);
}
void X11Window::SetAspectRatio(const gfx::SizeF& aspect_ratio) {
XWindow::SetXWindowAspectRatio(aspect_ratio);
}
void X11Window::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
XWindow::SetXWindowIcons(window_icon, app_icon);
}
void X11Window::SizeConstraintsChanged() {
XWindow::UpdateMinAndMaxSize();
}
bool X11Window::IsTranslucentWindowOpacitySupported() const {
// This function may be called before InitX11Window() (which
// initializes |visual_has_alpha_|), so we cannot simply return
// |visual_has_alpha_|.
return ui::XVisualManager::GetInstance()->ArgbVisualAvailable();
}
bool X11Window::CanDispatchEvent(const PlatformEvent& xev) {
#if defined(USE_X11)
return XWindow::IsTargetedBy(*xev);
......
......@@ -92,6 +92,16 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindowLinux,
void SetVisibleOnAllWorkspaces(bool always_visible) override;
bool IsVisibleOnAllWorkspaces() const override;
void FlashFrame(bool flash_frame) override;
gfx::Rect GetXRootWindowOuterBounds() const override;
bool ContainsPointInXRegion(const gfx::Point& point) const override;
void SetShape(std::unique_ptr<ShapeRects> native_shape,
const gfx::Transform& transform) override;
void SetOpacityForXWindow(float opacity) override;
void SetAspectRatio(const gfx::SizeF& aspect_ratio) override;
void SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) override;
void SizeConstraintsChanged() override;
bool IsTranslucentWindowOpacitySupported() const override;
protected:
PlatformWindowDelegateLinux* platform_window_delegate() const {
......
......@@ -59,6 +59,9 @@ class FakePlatformWindow : public ui::PlatformWindowBase,
gfx::Rect GetRestoredBoundsInPixels() const override { return gfx::Rect(); }
void SetUseNativeFrame(bool use_native_frame) override {}
bool ShouldUseNativeFrame() const override { return false; }
void SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) override {}
void SizeConstraintsChanged() override {}
// ui::WmDragHandler
void StartDrag(const OSExchangeData& data,
......
......@@ -31,8 +31,7 @@ namespace {
float GetDeviceScaleFactor() {
float device_scale_factor = 1.0f;
if (views::LinuxUI::instance()) {
device_scale_factor =
views::LinuxUI::instance()->GetDeviceScaleFactor();
device_scale_factor = views::LinuxUI::instance()->GetDeviceScaleFactor();
} else if (display::Display::HasForceDeviceScaleFactor()) {
device_scale_factor = display::Display::GetForcedDeviceScaleFactor();
}
......@@ -119,10 +118,10 @@ display::Display DesktopScreenX11::GetDisplayNearestWindow(
// aura::Window's screen bounds.
aura::WindowTreeHost* host = window->GetHost();
if (host) {
DesktopWindowTreeHostX11* rwh = DesktopWindowTreeHostX11::GetHostForXID(
host->GetAcceleratedWidget());
DesktopWindowTreeHostX11* rwh =
DesktopWindowTreeHostX11::GetHostForXID(host->GetAcceleratedWidget());
if (rwh) {
const gfx::Rect pixel_rect = rwh->GetX11RootWindowBounds();
const gfx::Rect pixel_rect = rwh->GetBoundsInPixels();
const gfx::Rect dip_rect =
gfx::ConvertRectToDIP(GetDeviceScaleFactor(), pixel_rect);
return GetDisplayMatching(dip_rect);
......
......@@ -4,6 +4,8 @@
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
#include "ui/aura/null_window_targeter.h"
#include "ui/aura/scoped_window_targeter.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/display/display.h"
......@@ -67,6 +69,29 @@ void DesktopWindowTreeHostLinux::SetPendingXVisualId(int x_visual_id) {
pending_x_visual_id_ = x_visual_id;
}
gfx::Rect DesktopWindowTreeHostLinux::GetXRootWindowOuterBounds() const {
return GetPlatformWindowLinux()->GetXRootWindowOuterBounds();
}
bool DesktopWindowTreeHostLinux::ContainsPointInXRegion(
const gfx::Point& point) const {
return GetPlatformWindowLinux()->ContainsPointInXRegion(point);
}
base::OnceClosure DesktopWindowTreeHostLinux::DisableEventListening() {
// Allows to open multiple file-pickers. See https://crbug.com/678982
modal_dialog_counter_++;
if (modal_dialog_counter_ == 1) {
// ScopedWindowTargeter is used to temporarily replace the event-targeter
// with NullWindowEventTargeter to make |dialog| modal.
targeter_for_modal_ = std::make_unique<aura::ScopedWindowTargeter>(
window(), std::make_unique<aura::NullWindowTargeter>());
}
return base::BindOnce(&DesktopWindowTreeHostLinux::EnableEventListening,
weak_factory_.GetWeakPtr());
}
void DesktopWindowTreeHostLinux::Init(const Widget::InitParams& params) {
DesktopWindowTreeHostPlatform::Init(params);
......@@ -99,6 +124,31 @@ bool DesktopWindowTreeHostLinux::IsVisibleOnAllWorkspaces() const {
return GetPlatformWindowLinux()->IsVisibleOnAllWorkspaces();
}
void DesktopWindowTreeHostLinux::SetOpacity(float opacity) {
DesktopWindowTreeHostPlatform::SetOpacity(opacity);
// Note that this is no-op for Wayland.
GetPlatformWindowLinux()->SetOpacityForXWindow(opacity);
}
base::flat_map<std::string, std::string>
DesktopWindowTreeHostLinux::GetKeyboardLayoutMap() {
if (views::LinuxUI::instance())
return views::LinuxUI::instance()->GetKeyboardLayoutMap();
return {};
}
void DesktopWindowTreeHostLinux::InitModalType(ui::ModalType modal_type) {
switch (modal_type) {
case ui::MODAL_TYPE_NONE:
break;
default:
// TODO(erg): Figure out under what situations |modal_type| isn't
// none. The comment in desktop_native_widget_aura.cc suggests that this
// is rare.
NOTIMPLEMENTED();
}
}
void DesktopWindowTreeHostLinux::OnDisplayMetricsChanged(
const display::Display& display,
uint32_t changed_metrics) {
......@@ -249,6 +299,16 @@ void DesktopWindowTreeHostLinux::GetWindowMask(const gfx::Size& size,
}
}
void DesktopWindowTreeHostLinux::OnLostMouseGrab() {
dispatcher()->OnHostLostMouseGrab();
}
void DesktopWindowTreeHostLinux::EnableEventListening() {
DCHECK_GT(modal_dialog_counter_, 0UL);
if (!--modal_dialog_counter_)
targeter_for_modal_.reset();
}
const ui::PlatformWindowLinux*
DesktopWindowTreeHostLinux::GetPlatformWindowLinux() const {
return static_cast<const ui::PlatformWindowLinux*>(platform_window());
......
......@@ -6,11 +6,18 @@
#define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_LINUX_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura/scoped_window_targeter.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_platform.h"
class SkPath;
namespace aura {
class ScopedWindowTargeter;
} // namespace aura
namespace ui {
class PlatformWindowLinux;
} // namespace ui
......@@ -32,6 +39,17 @@ class VIEWS_EXPORT DesktopWindowTreeHostLinux
// be changed after. Useful for X11. Not in use for Wayland.
void SetPendingXVisualId(int x_visual_id);
// Returns the current bounds in terms of the X11 Root Window including the
// borders provided by the window manager (if any). Not in use for Wayland.
gfx::Rect GetXRootWindowOuterBounds() const;
// Tells if the point is within X11 Root Window's region. Not in use for
// Wayland.
bool ContainsPointInXRegion(const gfx::Point& point) const;
// Disables event listening to make |dialog| modal.
base::OnceClosure DisableEventListening();
protected:
// Overridden from DesktopWindowTreeHost:
void Init(const Widget::InitParams& params) override;
......@@ -39,6 +57,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostLinux
std::string GetWorkspace() const override;
void SetVisibleOnAllWorkspaces(bool always_visible) override;
bool IsVisibleOnAllWorkspaces() const override;
void SetOpacity(float opacity) override;
base::flat_map<std::string, std::string> GetKeyboardLayoutMap() override;
void InitModalType(ui::ModalType modal_type) override;
// PlatformWindowDelegateBase:
void DispatchEvent(ui::Event* event) override;
......@@ -65,6 +86,10 @@ class VIEWS_EXPORT DesktopWindowTreeHostLinux
// PlatformWindowDelegateLinux overrides:
void OnWorkspaceChanged() override;
void GetWindowMask(const gfx::Size& size, SkPath* window_mask) override;
void OnLostMouseGrab() override;
// Enables event listening after closing |dialog|.
void EnableEventListening();
const ui::PlatformWindowLinux* GetPlatformWindowLinux() const;
ui::PlatformWindowLinux* GetPlatformWindowLinux();
......@@ -81,6 +106,13 @@ class VIEWS_EXPORT DesktopWindowTreeHostLinux
std::unique_ptr<CompositorObserver> compositor_observer_;
std::unique_ptr<aura::ScopedWindowTargeter> targeter_for_modal_;
uint32_t modal_dialog_counter_ = 0;
// The display and the native X window hosting the root window.
base::WeakPtrFactory<DesktopWindowTreeHostLinux> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostLinux);
};
......
......@@ -402,7 +402,7 @@ gfx::Rect DesktopWindowTreeHostPlatform::GetWorkAreaBoundsInScreen() const {
void DesktopWindowTreeHostPlatform::SetShape(
std::unique_ptr<Widget::ShapeRects> native_shape) {
NOTIMPLEMENTED_LOG_ONCE();
platform_window()->SetShape(std::move(native_shape), GetRootTransform());
}
void DesktopWindowTreeHostPlatform::Activate() {
......@@ -559,26 +559,21 @@ bool DesktopWindowTreeHostPlatform::IsFullscreen() const {
}
void DesktopWindowTreeHostPlatform::SetOpacity(float opacity) {
// TODO: needs PlatformWindow support.
NOTIMPLEMENTED_LOG_ONCE();
GetContentWindow()->layer()->SetOpacity(opacity);
}
void DesktopWindowTreeHostPlatform::SetAspectRatio(
const gfx::SizeF& aspect_ratio) {
// TODO: needs PlatformWindow support.
NOTIMPLEMENTED_LOG_ONCE();
platform_window()->SetAspectRatio(aspect_ratio);
}
void DesktopWindowTreeHostPlatform::SetWindowIcons(
const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
// TODO: needs PlatformWindow support.
NOTIMPLEMENTED_LOG_ONCE();
platform_window()->SetWindowIcons(window_icon, app_icon);
}
void DesktopWindowTreeHostPlatform::InitModalType(ui::ModalType modal_type) {
// TODO: needs PlatformWindow support (alternatively, remove as
// DesktopWindowTreeHostX11 doesn't support at all).
NOTIMPLEMENTED_LOG_ONCE();
}
......@@ -587,21 +582,16 @@ void DesktopWindowTreeHostPlatform::FlashFrame(bool flash_frame) {
}
bool DesktopWindowTreeHostPlatform::IsAnimatingClosed() const {
// TODO: needs PlatformWindow support.
NOTIMPLEMENTED_LOG_ONCE();
return false;
return platform_window()->IsAnimatingClosed();
}
bool DesktopWindowTreeHostPlatform::IsTranslucentWindowOpacitySupported()
const {
// TODO: needs PlatformWindow support.
NOTIMPLEMENTED_LOG_ONCE();
return false;
return platform_window()->IsTranslucentWindowOpacitySupported();
}
void DesktopWindowTreeHostPlatform::SizeConstraintsChanged() {
// TODO: needs PlatformWindow support.
NOTIMPLEMENTED_LOG_ONCE();
platform_window()->SizeConstraintsChanged();
}
bool DesktopWindowTreeHostPlatform::ShouldUpdateWindowTransparency() const {
......
......@@ -129,18 +129,6 @@ std::vector<aura::Window*> DesktopWindowTreeHostX11::GetAllOpenWindows() {
return windows;
}
gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowBounds() const {
return GetBoundsInPixels();
}
gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowOuterBounds() const {
return GetXWindow()->GetOutterBounds();
}
::Region DesktopWindowTreeHostX11::GetWindowShape() const {
return GetXWindow()->shape();
}
void DesktopWindowTreeHostX11::AddObserver(
DesktopWindowTreeHostObserverX11* observer) {
observer_list_.AddObserver(observer);
......@@ -206,30 +194,6 @@ DesktopWindowTreeHostX11::CreateDragDropClient(
return base::WrapUnique(drag_drop_client_);
}
void DesktopWindowTreeHostX11::SetShape(
std::unique_ptr<Widget::ShapeRects> native_shape) {
XRegion* xregion = nullptr;
if (native_shape) {
SkRegion native_region;
for (const gfx::Rect& rect : *native_shape)
native_region.op(gfx::RectToSkIRect(rect), SkRegion::kUnion_Op);
gfx::Transform transform = GetRootTransform();
if (!transform.IsIdentity() && !native_region.isEmpty()) {
SkPath path_in_dip;
if (native_region.getBoundaryPath(&path_in_dip)) {
SkPath path_in_pixels;
path_in_dip.transform(transform.matrix(), &path_in_pixels);
xregion = gfx::CreateRegionFromSkPath(path_in_pixels);
} else {
xregion = XCreateRegion();
}
} else {
xregion = gfx::CreateRegionFromSkRegion(native_region);
}
}
GetXWindow()->SetShape(xregion);
}
Widget::MoveLoopResult DesktopWindowTreeHostX11::RunMoveLoop(
const gfx::Vector2d& drag_offset,
Widget::MoveLoopSource source,
......@@ -249,54 +213,6 @@ void DesktopWindowTreeHostX11::EndMoveLoop() {
x11_window_move_client_->EndMoveLoop();
}
void DesktopWindowTreeHostX11::SetOpacity(float opacity) {
GetXWindow()->SetOpacity(opacity);
}
void DesktopWindowTreeHostX11::SetAspectRatio(const gfx::SizeF& aspect_ratio) {
GetXWindow()->SetAspectRatio(aspect_ratio);
}
void DesktopWindowTreeHostX11::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
GetXWindow()->SetWindowIcons(window_icon, app_icon);
}
void DesktopWindowTreeHostX11::InitModalType(ui::ModalType modal_type) {
switch (modal_type) {
case ui::MODAL_TYPE_NONE:
break;
default:
// TODO(erg): Figure out under what situations |modal_type| isn't
// none. The comment in desktop_native_widget_aura.cc suggests that this
// is rare.
NOTIMPLEMENTED();
}
}
bool DesktopWindowTreeHostX11::IsAnimatingClosed() const {
return false;
}
bool DesktopWindowTreeHostX11::IsTranslucentWindowOpacitySupported() const {
// This function may be called before InitX11Window() (which
// initializes |visual_has_alpha_|), so we cannot simply return
// |visual_has_alpha_|.
return ui::XVisualManager::GetInstance()->ArgbVisualAvailable();
}
void DesktopWindowTreeHostX11::SizeConstraintsChanged() {
GetXWindow()->UpdateMinAndMaxSize();
}
bool DesktopWindowTreeHostX11::ShouldUseDesktopNativeCursorManager() const {
return true;
}
bool DesktopWindowTreeHostX11::ShouldCreateVisibilityController() const {
return true;
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, private:
......@@ -309,38 +225,6 @@ std::list<gfx::AcceleratedWidget>& DesktopWindowTreeHostX11::open_windows() {
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11 implementation:
base::OnceClosure DesktopWindowTreeHostX11::DisableEventListening() {
// Allows to open multiple file-pickers. See https://crbug.com/678982
modal_dialog_counter_++;
if (modal_dialog_counter_ == 1) {
// ScopedWindowTargeter is used to temporarily replace the event-targeter
// with NullWindowEventTargeter to make |dialog| modal.
targeter_for_modal_ = std::make_unique<aura::ScopedWindowTargeter>(
window(), std::make_unique<aura::NullWindowTargeter>());
}
return base::BindOnce(&DesktopWindowTreeHostX11::EnableEventListening,
weak_factory_.GetWeakPtr());
}
void DesktopWindowTreeHostX11::EnableEventListening() {
DCHECK_GT(modal_dialog_counter_, 0UL);
if (!--modal_dialog_counter_)
targeter_for_modal_.reset();
}
void DesktopWindowTreeHostX11::OnCompleteSwapWithNewSize(
const gfx::Size& size) {
GetXWindow()->NotifySwapAfterResize();
}
base::flat_map<std::string, std::string>
DesktopWindowTreeHostX11::GetKeyboardLayoutMap() {
if (views::LinuxUI::instance())
return views::LinuxUI::instance()->GetKeyboardLayoutMap();
return {};
}
void DesktopWindowTreeHostX11::OnClosed() {
open_windows().remove(GetAcceleratedWidget());
DesktopWindowTreeHostLinux::OnClosed();
......@@ -375,10 +259,6 @@ void DesktopWindowTreeHostX11::OnXWindowUnmapped() {
observer.OnWindowUnmapped(GetXWindow()->window());
}
void DesktopWindowTreeHostX11::OnLostMouseGrab() {
dispatcher()->OnHostLostMouseGrab();
}
void DesktopWindowTreeHostX11::OnXWindowSelectionEvent(XEvent* xev) {
DCHECK(xev);
DCHECK(drag_drop_client_);
......@@ -431,13 +311,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.
......
......@@ -18,7 +18,6 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "ui/aura/scoped_window_targeter.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/x/x11_types.h"
......@@ -27,10 +26,6 @@
#include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
namespace gfx {
class ImageSkia;
}
namespace ui {
enum class DomCode;
class X11Window;
......@@ -61,17 +56,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
// is the topmost window.
static std::vector<aura::Window*> GetAllOpenWindows();
// Returns the current bounds in terms of the X11 Root Window.
gfx::Rect GetX11RootWindowBounds() const;
// Returns the current bounds in terms of the X11 Root Window including the
// borders provided by the window manager (if any).
gfx::Rect GetX11RootWindowOuterBounds() const;
// Returns the window shape if the window is not rectangular. Returns NULL
// otherwise.
::Region GetWindowShape() const;
void AddObserver(DesktopWindowTreeHostObserverX11* observer);
void RemoveObserver(DesktopWindowTreeHostObserverX11* observer);
......@@ -79,34 +63,17 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
// internal list of open windows.
static void CleanUpWindowList(void (*func)(aura::Window* window));
// Disables event listening to make |dialog| modal.
base::OnceClosure DisableEventListening();
// Returns a map of KeyboardEvent code to KeyboardEvent key values.
base::flat_map<std::string, std::string> GetKeyboardLayoutMap() override;
protected:
// Overridden from DesktopWindowTreeHost:
void Init(const Widget::InitParams& params) override;
void OnNativeWidgetCreated(const Widget::InitParams& params) override;
std::unique_ptr<aura::client::DragDropClient> CreateDragDropClient(
DesktopNativeCursorManager* cursor_manager) override;
void SetShape(std::unique_ptr<Widget::ShapeRects> native_shape) override;
Widget::MoveLoopResult RunMoveLoop(
const gfx::Vector2d& drag_offset,
Widget::MoveLoopSource source,
Widget::MoveLoopEscapeBehavior escape_behavior) override;
void EndMoveLoop() override;
void SetOpacity(float opacity) override;
void SetAspectRatio(const gfx::SizeF& aspect_ratio) override;
void SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) override;
void InitModalType(ui::ModalType modal_type) override;
bool IsAnimatingClosed() const override;
bool IsTranslucentWindowOpacitySupported() const override;
void SizeConstraintsChanged() override;
bool ShouldUseDesktopNativeCursorManager() const override;
bool ShouldCreateVisibilityController() const override;
private:
friend class DesktopWindowTreeHostX11HighDPITest;
......@@ -114,12 +81,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
// See comment for variable open_windows_.
static std::list<XID>& open_windows();
// Enables event listening after closing |dialog|.
void EnableEventListening();
// Callback for a swapbuffer after resize.
void OnCompleteSwapWithNewSize(const gfx::Size& size) override;
// PlatformWindowDelegate overrides:
//
// DWTHX11 temporarily overrides the PlatformWindowDelegate methods instead of
......@@ -131,7 +92,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
void OnActivationChanged(bool active) override;
void OnXWindowMapped() override;
void OnXWindowUnmapped() override;
void OnLostMouseGrab() override;
// Overridden from ui::XEventDelegate.
void OnXWindowSelectionEvent(XEvent* xev) override;
......@@ -142,7 +102,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
// 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;
DesktopDragDropClientAuraX11* drag_drop_client_ = nullptr;
......@@ -156,10 +115,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
// destroyed.
static std::list<gfx::AcceleratedWidget>* open_windows_;
std::unique_ptr<aura::ScopedWindowTargeter> targeter_for_modal_;
uint32_t modal_dialog_counter_ = 0;
// The display and the native X window hosting the root window.
base::WeakPtrFactory<DesktopWindowTreeHostX11> weak_factory_{this};
......
......@@ -72,21 +72,16 @@ bool X11TopmostWindowFinder::ShouldStopIteratingAtLocalProcessWindow(
if (!window->IsVisible())
return false;
DesktopWindowTreeHostX11* host =
DesktopWindowTreeHostX11::GetHostForXID(
DesktopWindowTreeHostX11* host = DesktopWindowTreeHostX11::GetHostForXID(
window->GetHost()->GetAcceleratedWidget());
if (!host->GetX11RootWindowOuterBounds().Contains(screen_loc_in_pixels_))
if (!host->GetXRootWindowOuterBounds().Contains(screen_loc_in_pixels_))
return false;
::Region shape = host->GetWindowShape();
if (!shape)
return true;
aura::client::ScreenPositionClient* screen_position_client =
aura::client::GetScreenPositionClient(window->GetRootWindow());
gfx::Point window_loc(screen_loc_in_pixels_);
screen_position_client->ConvertPointFromScreen(window, &window_loc);
return XPointInRegion(shape, window_loc.x(), window_loc.y()) == x11::True;
return host->ContainsPointInXRegion(window_loc);
}
} // namespace views
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