Commit fcfd6906 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

Move WindowMoveClient out of X11DesktopWindowMoveClient

In order to be able to move X11DesktopWindowMoveClient out of
ui/views to ui/base/x, we need to stop subclassing
wm::WindowMoveClient. This CL does it.

Basically, we implement WindowMoveClientPlatform that reroutes
the requests for RunMoveLoop to DWTHPlatform::RunMoveLoop,
which then is supposed to call PlatformWindow::RunMoveLoop.

Current, for X11, these calls are routed to DWTHX11::RunMoveLoop.

Test: verify Tab Drag works on chrome/x11.
Bug: 1069469
Change-Id: I60cd60001c47ddfcefe8248cb7a0a087c85bb164
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144053
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@{#758151}
parent 37f7868d
...@@ -808,9 +808,14 @@ jumbo_component("views") { ...@@ -808,9 +808,14 @@ jumbo_component("views") {
] ]
} }
if (is_linux || is_fuchsia) { if (is_linux || is_fuchsia) {
public += [ "widget/desktop_aura/desktop_window_tree_host_platform.h" ] public += [
sources += "widget/desktop_aura/desktop_window_tree_host_platform.h",
[ "widget/desktop_aura/desktop_window_tree_host_platform.cc" ] "widget/desktop_aura/window_move_client_platform.h",
]
sources += [
"widget/desktop_aura/desktop_window_tree_host_platform.cc",
"widget/desktop_aura/window_move_client_platform.cc",
]
deps += [ "//ui/platform_window/extensions" ] deps += [ "//ui/platform_window/extensions" ]
} }
if (use_atk) { if (use_atk) {
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "ui/views/widget/widget_aura_utils.h" #include "ui/views/widget/widget_aura_utils.h"
#include "ui/views/window/native_frame_view.h" #include "ui/views/window/native_frame_view.h"
#include "ui/wm/core/window_util.h" #include "ui/wm/core/window_util.h"
#include "ui/wm/public/window_move_client.h"
namespace views { namespace views {
...@@ -108,7 +109,8 @@ DesktopWindowTreeHostPlatform::DesktopWindowTreeHostPlatform( ...@@ -108,7 +109,8 @@ DesktopWindowTreeHostPlatform::DesktopWindowTreeHostPlatform(
internal::NativeWidgetDelegate* native_widget_delegate, internal::NativeWidgetDelegate* native_widget_delegate,
DesktopNativeWidgetAura* desktop_native_widget_aura) DesktopNativeWidgetAura* desktop_native_widget_aura)
: native_widget_delegate_(native_widget_delegate), : native_widget_delegate_(native_widget_delegate),
desktop_native_widget_aura_(desktop_native_widget_aura) {} desktop_native_widget_aura_(desktop_native_widget_aura),
window_move_client_(this) {}
DesktopWindowTreeHostPlatform::~DesktopWindowTreeHostPlatform() { DesktopWindowTreeHostPlatform::~DesktopWindowTreeHostPlatform() {
DCHECK(!platform_window()) << "The host must be closed before destroying it."; DCHECK(!platform_window()) << "The host must be closed before destroying it.";
...@@ -160,6 +162,10 @@ void DesktopWindowTreeHostPlatform::Init(const Widget::InitParams& params) { ...@@ -160,6 +162,10 @@ void DesktopWindowTreeHostPlatform::Init(const Widget::InitParams& params) {
void DesktopWindowTreeHostPlatform::OnNativeWidgetCreated( void DesktopWindowTreeHostPlatform::OnNativeWidgetCreated(
const Widget::InitParams& params) { const Widget::InitParams& params) {
// This reroutes RunMoveLoop requests to the DesktopWindowTreeHostPlatform.
// The availability of this feature depends on a platform (PlatformWindow)
// that implements RunMoveLoop.
wm::SetWindowMoveClient(window(), &window_move_client_);
platform_window()->SetUseNativeFrame(params.type == platform_window()->SetUseNativeFrame(params.type ==
Widget::InitParams::TYPE_WINDOW && Widget::InitParams::TYPE_WINDOW &&
!params.remove_standard_frame); !params.remove_standard_frame);
...@@ -646,6 +652,7 @@ void DesktopWindowTreeHostPlatform::HideImpl() { ...@@ -646,6 +652,7 @@ void DesktopWindowTreeHostPlatform::HideImpl() {
} }
void DesktopWindowTreeHostPlatform::OnClosed() { void DesktopWindowTreeHostPlatform::OnClosed() {
wm::SetWindowMoveClient(window(), nullptr);
SetPlatformWindow(nullptr); SetPlatformWindow(nullptr);
desktop_native_widget_aura_->OnHostClosed(); desktop_native_widget_aura_->OnHostClosed();
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/platform_window/extensions/workspace_extension_delegate.h" #include "ui/platform_window/extensions/workspace_extension_delegate.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
#include "ui/views/widget/desktop_aura/window_move_client_platform.h"
namespace views { namespace views {
...@@ -161,6 +162,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform ...@@ -161,6 +162,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostPlatform
// normal state. // normal state.
ui::PlatformWindowState old_state_ = ui::PlatformWindowState::kUnknown; ui::PlatformWindowState old_state_ = ui::PlatformWindowState::kUnknown;
// Used for tab dragging in move loop requests.
WindowMoveClientPlatform window_move_client_;
base::WeakPtrFactory<DesktopWindowTreeHostPlatform> close_widget_factory_{ base::WeakPtrFactory<DesktopWindowTreeHostPlatform> close_widget_factory_{
this}; this};
......
...@@ -72,12 +72,7 @@ DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( ...@@ -72,12 +72,7 @@ DesktopWindowTreeHostX11::DesktopWindowTreeHostX11(
: DesktopWindowTreeHostLinux(native_widget_delegate, : DesktopWindowTreeHostLinux(native_widget_delegate,
desktop_native_widget_aura) {} desktop_native_widget_aura) {}
DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() = default;
wm::SetWindowMoveClient(window(), nullptr);
// ~DWTHPlatform notifies the DestkopNativeWidgetAura about destruction and
// also destroyes the dispatcher.
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, DesktopWindowTreeHost implementation: // DesktopWindowTreeHostX11, DesktopWindowTreeHost implementation:
...@@ -97,8 +92,6 @@ void DesktopWindowTreeHostX11::Init(const Widget::InitParams& params) { ...@@ -97,8 +92,6 @@ void DesktopWindowTreeHostX11::Init(const Widget::InitParams& params) {
void DesktopWindowTreeHostX11::OnNativeWidgetCreated( void DesktopWindowTreeHostX11::OnNativeWidgetCreated(
const Widget::InitParams& params) { const Widget::InitParams& params) {
x11_window_move_client_ = std::make_unique<X11DesktopWindowMoveClient>(); x11_window_move_client_ = std::make_unique<X11DesktopWindowMoveClient>();
wm::SetWindowMoveClient(window(), x11_window_move_client_.get());
DesktopWindowTreeHostLinux::OnNativeWidgetCreated(params); DesktopWindowTreeHostLinux::OnNativeWidgetCreated(params);
} }
...@@ -116,14 +109,8 @@ Widget::MoveLoopResult DesktopWindowTreeHostX11::RunMoveLoop( ...@@ -116,14 +109,8 @@ Widget::MoveLoopResult DesktopWindowTreeHostX11::RunMoveLoop(
const gfx::Vector2d& drag_offset, const gfx::Vector2d& drag_offset,
Widget::MoveLoopSource source, Widget::MoveLoopSource source,
Widget::MoveLoopEscapeBehavior escape_behavior) { Widget::MoveLoopEscapeBehavior escape_behavior) {
wm::WindowMoveSource window_move_source = if (x11_window_move_client_->RunMoveLoop(GetContentWindow(), drag_offset))
source == Widget::MoveLoopSource::kMouse ? wm::WINDOW_MOVE_SOURCE_MOUSE
: wm::WINDOW_MOVE_SOURCE_TOUCH;
if (x11_window_move_client_->RunMoveLoop(GetContentWindow(), drag_offset,
window_move_source) ==
wm::MOVE_SUCCESSFUL)
return Widget::MOVE_LOOP_SUCCESSFUL; return Widget::MOVE_LOOP_SUCCESSFUL;
return Widget::MOVE_LOOP_CANCELED; return Widget::MOVE_LOOP_CANCELED;
} }
......
// Copyright 2020 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/window_move_client_platform.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_platform.h"
namespace views {
WindowMoveClientPlatform::WindowMoveClientPlatform(
DesktopWindowTreeHostPlatform* host)
: host_(host) {}
WindowMoveClientPlatform::~WindowMoveClientPlatform() = default;
wm::WindowMoveResult WindowMoveClientPlatform::RunMoveLoop(
aura::Window* source,
const gfx::Vector2d& drag_offset,
wm::WindowMoveSource move_source) {
DCHECK(host_->GetContentWindow()->Contains(source));
auto move_loop_result = host_->RunMoveLoop(
drag_offset,
move_source == wm::WindowMoveSource::WINDOW_MOVE_SOURCE_MOUSE
? Widget::MoveLoopSource::kMouse
: Widget::MoveLoopSource::kTouch,
Widget::MoveLoopEscapeBehavior::MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE);
return move_loop_result == Widget::MOVE_LOOP_SUCCESSFUL ? wm::MOVE_SUCCESSFUL
: wm::MOVE_CANCELED;
}
void WindowMoveClientPlatform::EndMoveLoop() {
host_->EndMoveLoop();
}
} // namespace views
// Copyright 2020 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_WINDOW_MOVE_CLIENT_PLATFORM_H_
#define UI_VIEWS_WIDGET_DESKTOP_AURA_WINDOW_MOVE_CLIENT_PLATFORM_H_
#include "ui/views/views_export.h"
#include "ui/wm/public/window_move_client.h"
namespace views {
class DesktopWindowTreeHostPlatform;
// Reroutes move loop requests to DesktopWindowTreeHostPlatform.
class VIEWS_EXPORT WindowMoveClientPlatform : public wm::WindowMoveClient {
public:
explicit WindowMoveClientPlatform(DesktopWindowTreeHostPlatform* host);
WindowMoveClientPlatform(const WindowMoveClientPlatform& host) = delete;
WindowMoveClientPlatform& operator=(const WindowMoveClientPlatform& host) =
delete;
~WindowMoveClientPlatform() override;
// Overridden from wm::WindowMoveClient:
wm::WindowMoveResult RunMoveLoop(aura::Window* window,
const gfx::Vector2d& drag_offset,
wm::WindowMoveSource move_source) override;
void EndMoveLoop() override;
private:
// The RunMoveLoop request is forwarded to this host.
DesktopWindowTreeHostPlatform* host_ = nullptr;
};
} // namespace views
#endif // UI_VIEWS_WIDGET_DESKTOP_AURA_WINDOW_MOVE_CLIENT_PLATFORM_H_
...@@ -34,19 +34,13 @@ void X11DesktopWindowMoveClient::OnMoveLoopEnded() { ...@@ -34,19 +34,13 @@ void X11DesktopWindowMoveClient::OnMoveLoopEnded() {
host_ = nullptr; host_ = nullptr;
} }
//////////////////////////////////////////////////////////////////////////////// bool X11DesktopWindowMoveClient::RunMoveLoop(aura::Window* source,
// DesktopWindowTreeHostLinux, wm::WindowMoveClient implementation: const gfx::Vector2d& drag_offset) {
wm::WindowMoveResult X11DesktopWindowMoveClient::RunMoveLoop(
aura::Window* source,
const gfx::Vector2d& drag_offset,
wm::WindowMoveSource move_source) {
window_offset_ = drag_offset; window_offset_ = drag_offset;
host_ = source->GetHost(); host_ = source->GetHost();
source->SetCapture(); source->SetCapture();
bool success = move_loop_.RunMoveLoop(source, host_->last_cursor()); return move_loop_.RunMoveLoop(source, host_->last_cursor());
return success ? wm::MOVE_SUCCESSFUL : wm::MOVE_CANCELED;
} }
void X11DesktopWindowMoveClient::EndMoveLoop() { void X11DesktopWindowMoveClient::EndMoveLoop() {
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h" #include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h"
#include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h" #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h"
#include "ui/wm/public/window_move_client.h"
namespace aura { namespace aura {
class WindowTreeHost; class WindowTreeHost;
...@@ -22,8 +21,7 @@ namespace views { ...@@ -22,8 +21,7 @@ namespace views {
// When we're dragging tabs, we need to manually position our window. // When we're dragging tabs, we need to manually position our window.
class VIEWS_EXPORT X11DesktopWindowMoveClient class VIEWS_EXPORT X11DesktopWindowMoveClient
: public views::X11MoveLoopDelegate, : public views::X11MoveLoopDelegate {
public wm::WindowMoveClient {
public: public:
X11DesktopWindowMoveClient(); X11DesktopWindowMoveClient();
~X11DesktopWindowMoveClient() override; ~X11DesktopWindowMoveClient() override;
...@@ -35,11 +33,8 @@ class VIEWS_EXPORT X11DesktopWindowMoveClient ...@@ -35,11 +33,8 @@ class VIEWS_EXPORT X11DesktopWindowMoveClient
void OnMouseReleased() override; void OnMouseReleased() override;
void OnMoveLoopEnded() override; void OnMoveLoopEnded() override;
// Overridden from wm::WindowMoveClient: bool RunMoveLoop(aura::Window* window, const gfx::Vector2d& drag_offset);
wm::WindowMoveResult RunMoveLoop(aura::Window* window, void EndMoveLoop();
const gfx::Vector2d& drag_offset,
wm::WindowMoveSource move_source) override;
void EndMoveLoop() override;
private: private:
X11WholeScreenMoveLoop move_loop_{this}; X11WholeScreenMoveLoop move_loop_{this};
......
...@@ -14,6 +14,8 @@ namespace views { ...@@ -14,6 +14,8 @@ namespace views {
// Receives mouse events while the X11MoveLoop is tracking a drag. // Receives mouse events while the X11MoveLoop is tracking a drag.
class X11MoveLoopDelegate { class X11MoveLoopDelegate {
public: public:
virtual ~X11MoveLoopDelegate() = default;
// Called when we receive a mouse move event. // Called when we receive a mouse move event.
virtual void OnMouseMovement(const gfx::Point& screen_point, virtual void OnMouseMovement(const gfx::Point& screen_point,
int flags, int flags,
......
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