Skip to content

Commit

Permalink
Add inital support for a tab drag window.
Browse files Browse the repository at this point in the history
This patch adds an initial support to start a move loop and create
a new window by dragging a tab. To start with, this commit
extends WindowTree::PerformWindowMove, which calls
WindowServer::StartMoveLoop -> PlatformWindow::RunMoveLoop.

X11 Ozone implementation of PlatformWindow uses
WindowMoveLoopClient, which instantiates the move loop and
WholeScreenMoveLoop, which creates an invisible window
and intercepts all the events from it. Then the system screen
location is taken and sent to WindowMoveLoopClient, which
updates actual bounds of X11WindowBase.

The way it works is precisly the same as in stock X11, but
further work to share the code is needed, because there are
some difference between stock x11 and ozone x11 event
handlings, bounds set and etc.

Issue #264

fixup! [ozone/wayland] Add inital support for a tab drag window.

adapt to
https://crrev.com/c/774778

CanDispatchEvent is modified in such a way that it also tests if
the client in a move loop right now. If so, it must dispatch events
further once whole_screen_move_loop processes them in order to update
mouse locations on aura side.

fixup! [ozone/wayland] Add inital support for a tab drag window.

It removed changes at services from previous change to make it
available without mus and made WindowFinder with ozone work without
mus with creating GetLocalProcessWindowAtPointOzone to
get gfx::NativeWindow at input position.

Issue #430

fixup! Add inital support for a tab drag window.

Remove the non-existing code and fix ozone/drm build.

Change-Id: I9d3a94a9e47ed2bddaef0253de193d92e01768b0
  • Loading branch information
msisov committed Jan 15, 2019
1 parent 6ba0dd8 commit de201e1
Show file tree
Hide file tree
Showing 19 changed files with 541 additions and 9 deletions.
3 changes: 3 additions & 0 deletions chrome/browser/ui/views/tabs/window_finder_ozone.cc
Expand Up @@ -2,7 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/tabs/window_finder.h"
#include "ui/views/widget/widget.h"

gfx::NativeWindow WindowFinder::GetLocalProcessWindowAtPoint(
const gfx::Point& screen_point,
Expand Down
6 changes: 6 additions & 0 deletions ui/ozone/platform/drm/host/drm_window_host.cc
Expand Up @@ -146,6 +146,12 @@ gfx::Rect DrmWindowHost::GetRestoredBoundsInPixels() const {
return gfx::Rect();
}

bool DrmWindowHost::RunMoveLoop(const gfx::Vector2d& drag_offset) {
return false;
}

void DrmWindowHost::StopMoveLoop() {}

bool DrmWindowHost::CanDispatchEvent(const PlatformEvent& event) {
DCHECK(event);

Expand Down
2 changes: 2 additions & 0 deletions ui/ozone/platform/drm/host/drm_window_host.h
Expand Up @@ -79,6 +79,8 @@ class DrmWindowHost : public PlatformWindow,
PlatformImeController* GetPlatformImeController() override;
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
bool RunMoveLoop(const gfx::Vector2d& drag_offset) override;
void StopMoveLoop() override;

// PlatformEventDispatcher:
bool CanDispatchEvent(const PlatformEvent& event) override;
Expand Down
6 changes: 6 additions & 0 deletions ui/ozone/platform/wayland/wayland_window.cc
Expand Up @@ -446,6 +446,12 @@ gfx::Rect WaylandWindow::GetRestoredBoundsInPixels() const {
return restored_bounds_;
}

bool WaylandWindow::RunMoveLoop(const gfx::Vector2d& drag_offset) {
return true;
}

void WaylandWindow::StopMoveLoop() {}

bool WaylandWindow::CanDispatchEvent(const PlatformEvent& event) {
// This window is a nested popup window, all the events must be forwarded
// to the main popup window.
Expand Down
2 changes: 2 additions & 0 deletions ui/ozone/platform/wayland/wayland_window.h
Expand Up @@ -114,6 +114,8 @@ class WaylandWindow : public PlatformWindow,
PlatformImeController* GetPlatformImeController() override;
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
bool RunMoveLoop(const gfx::Vector2d& drag_offset) override;
void StopMoveLoop() override;

// PlatformEventDispatcher
bool CanDispatchEvent(const PlatformEvent& event) override;
Expand Down
33 changes: 31 additions & 2 deletions ui/ozone/platform/x11/x11_window_ozone.cc
Expand Up @@ -24,6 +24,11 @@ X11WindowOzone::X11WindowOzone(X11WindowManagerOzone* window_manager,
auto* event_source = X11EventSourceLibevent::GetInstance();
if (event_source)
event_source->AddXEventDispatcher(this);

// TODO(msisov, tonikitoo): Add a dummy implementation for chromeos.
#if !defined(OS_CHROMEOS)
move_loop_client_.reset(new WindowMoveLoopClient());
#endif
}

X11WindowOzone::~X11WindowOzone() {
Expand All @@ -49,6 +54,24 @@ void X11WindowOzone::SetCursor(PlatformCursor cursor) {
XDefineCursor(xdisplay(), xwindow(), cursor_ozone->xcursor());
}

bool X11WindowOzone::RunMoveLoop(const gfx::Vector2d& drag_offset) {
// TODO(msisov, tonikitoo): Add a dummy implementation for chromeos.
#if !defined(OS_CHROMEOS)
DCHECK(move_loop_client_);
ReleaseCapture();
return move_loop_client_->RunMoveLoop(this, drag_offset);
#endif
return true;
}

void X11WindowOzone::StopMoveLoop() {
// TODO(msisov, tonikitoo): Add a dummy implementation for chromeos.
#if !defined(OS_CHROMEOS)
ReleaseCapture();
move_loop_client_->EndMoveLoop();
#endif
}

void X11WindowOzone::CheckCanDispatchNextPlatformEvent(XEvent* xev) {
handle_next_event_ = xwindow() == x11::None ? false : IsEventForXWindow(*xev);
}
Expand All @@ -69,8 +92,14 @@ bool X11WindowOzone::DispatchXEvent(XEvent* xev) {
return true;
}

bool X11WindowOzone::CanDispatchEvent(const PlatformEvent& event) {
return handle_next_event_;
bool X11WindowOzone::CanDispatchEvent(const PlatformEvent& platform_event) {
bool in_move_loop =
#if !defined(OS_CHROMEOS)
move_loop_client_->IsInMoveLoop();
#else
false;
#endif
return handle_next_event_ || in_move_loop;
}

uint32_t X11WindowOzone::DispatchEvent(const PlatformEvent& event) {
Expand Down
9 changes: 9 additions & 0 deletions ui/ozone/platform/x11/x11_window_ozone.h
Expand Up @@ -8,6 +8,7 @@
#include "base/macros.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/x11/x11_event_source_libevent.h"
#include "ui/platform_window/x11/window_move_loop_client.h"
#include "ui/platform_window/x11/x11_window_base.h"

namespace ui {
Expand All @@ -30,8 +31,11 @@ class X11WindowOzone : public X11WindowBase,
// PlatformWindow:
void PrepareForShutdown() override;
void SetCapture() override;

void ReleaseCapture() override;
void SetCursor(PlatformCursor cursor) override;
bool RunMoveLoop(const gfx::Vector2d& drag_offset) override;
void StopMoveLoop() override;

// XEventDispatcher:
void CheckCanDispatchNextPlatformEvent(XEvent* xev) override;
Expand All @@ -46,6 +50,11 @@ class X11WindowOzone : public X11WindowBase,

X11WindowManagerOzone* window_manager_;

// TODO(msisov, tonikitoo): Add a dummy implementation for chromeos.
#if !defined(OS_CHROMEOS)
std::unique_ptr<WindowMoveLoopClient> move_loop_client_;
#endif

// Tells if this dispatcher can process next translated event based on a
// previous check in ::CheckCanDispatchNextPlatformEvent based on a XID
// target.
Expand Down
5 changes: 5 additions & 0 deletions ui/platform_window/platform_window.h
Expand Up @@ -71,6 +71,11 @@ class PlatformWindow : public PropertyHandler {
// Sets and gets the restored bounds of the platform-window.
virtual void SetRestoredBoundsInPixels(const gfx::Rect& bounds) = 0;
virtual gfx::Rect GetRestoredBoundsInPixels() const = 0;

// Asks to window move client to start move loop.
virtual bool RunMoveLoop(const gfx::Vector2d& drag_offset) = 0;

virtual void StopMoveLoop() = 0;
};

} // namespace ui
Expand Down
6 changes: 6 additions & 0 deletions ui/platform_window/stub/stub_window.cc
Expand Up @@ -80,4 +80,10 @@ gfx::Rect StubWindow::GetRestoredBoundsInPixels() const {
return gfx::Rect();
}

bool StubWindow::RunMoveLoop(const gfx::Vector2d& drag_offset) {
return false;
}

void StubWindow::StopMoveLoop() {}

} // namespace ui
2 changes: 2 additions & 0 deletions ui/platform_window/stub/stub_window.h
Expand Up @@ -50,6 +50,8 @@ class STUB_WINDOW_EXPORT StubWindow : public PlatformWindow {
PlatformImeController* GetPlatformImeController() override;
void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override;
gfx::Rect GetRestoredBoundsInPixels() const override;
bool RunMoveLoop(const gfx::Vector2d& drag_offset) override;
void StopMoveLoop() override;

PlatformWindowDelegate* delegate_;
gfx::Rect bounds_;
Expand Down
13 changes: 12 additions & 1 deletion ui/platform_window/x11/BUILD.gn
Expand Up @@ -34,7 +34,18 @@ jumbo_component("x11") {
"x11_window_export.h",
]

if (use_x11) {
if (ozone_platform_x11) {
sources += [
"whole_screen_move_loop.cc",
"whole_screen_move_loop.h",
"window_move_loop_client.cc",
"window_move_loop_client.h",
]
deps += [
"//ui/base",
"//ui/base/x",
]
} else if (use_x11) {
sources += [
"x11_window.cc",
"x11_window.h",
Expand Down

0 comments on commit de201e1

Please sign in to comment.