Commit 61047d70 authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Fix flakiness of DesktopDragDropClientAuraX11Tests

I suspect that the flakiness was caused by X11WholeScreenMoveLoop::RunMoveLoop()
sometimes failing. This CL fixes this potential source of flakiness by using
a stub move loop in tests.

BUG=396468
TEST=None
TBR=erg

Review URL: https://codereview.chromium.org/431973006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287622 0039d316-1c4b-4281-b951-d872f2087c98
parent dfb3f13e
...@@ -417,11 +417,12 @@ ...@@ -417,11 +417,12 @@
'widget/desktop_aura/x11_desktop_handler.h', 'widget/desktop_aura/x11_desktop_handler.h',
'widget/desktop_aura/x11_desktop_window_move_client.cc', 'widget/desktop_aura/x11_desktop_window_move_client.cc',
'widget/desktop_aura/x11_desktop_window_move_client.h', 'widget/desktop_aura/x11_desktop_window_move_client.h',
'widget/desktop_aura/x11_move_loop.h',
'widget/desktop_aura/x11_move_loop_delegate.h',
'widget/desktop_aura/x11_topmost_window_finder.cc', 'widget/desktop_aura/x11_topmost_window_finder.cc',
'widget/desktop_aura/x11_topmost_window_finder.h', 'widget/desktop_aura/x11_topmost_window_finder.h',
'widget/desktop_aura/x11_whole_screen_move_loop.cc', 'widget/desktop_aura/x11_whole_screen_move_loop.cc',
'widget/desktop_aura/x11_whole_screen_move_loop.h', 'widget/desktop_aura/x11_whole_screen_move_loop.h',
'widget/desktop_aura/x11_whole_screen_move_loop_delegate.h',
'widget/desktop_aura/x11_window_event_filter.cc', 'widget/desktop_aura/x11_window_event_filter.cc',
'widget/desktop_aura/x11_window_event_filter.h', 'widget/desktop_aura/x11_window_event_filter.h',
], ],
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/platform_event_source.h"
#include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
#include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
#include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h"
#include "ui/wm/public/drag_drop_client.h" #include "ui/wm/public/drag_drop_client.h"
#include "ui/wm/public/drag_drop_delegate.h" #include "ui/wm/public/drag_drop_delegate.h"
...@@ -361,8 +362,7 @@ DesktopDragDropClientAuraX11::DesktopDragDropClientAuraX11( ...@@ -361,8 +362,7 @@ DesktopDragDropClientAuraX11::DesktopDragDropClientAuraX11(
views::DesktopNativeCursorManager* cursor_manager, views::DesktopNativeCursorManager* cursor_manager,
Display* xdisplay, Display* xdisplay,
::Window xwindow) ::Window xwindow)
: move_loop_(this), : root_window_(root_window),
root_window_(root_window),
xdisplay_(xdisplay), xdisplay_(xdisplay),
xwindow_(xwindow), xwindow_(xwindow),
atom_cache_(xdisplay_, kAtomsToCache), atom_cache_(xdisplay_, kAtomsToCache),
...@@ -407,6 +407,10 @@ DesktopDragDropClientAuraX11* DesktopDragDropClientAuraX11::GetForWindow( ...@@ -407,6 +407,10 @@ DesktopDragDropClientAuraX11* DesktopDragDropClientAuraX11::GetForWindow(
return it->second; return it->second;
} }
void DesktopDragDropClientAuraX11::Init() {
move_loop_ = CreateMoveLoop(this);
}
void DesktopDragDropClientAuraX11::OnXdndEnter( void DesktopDragDropClientAuraX11::OnXdndEnter(
const XClientMessageEvent& event) { const XClientMessageEvent& event) {
DVLOG(1) << "XdndEnter"; DVLOG(1) << "XdndEnter";
...@@ -483,7 +487,7 @@ void DesktopDragDropClientAuraX11::OnXdndStatus( ...@@ -483,7 +487,7 @@ void DesktopDragDropClientAuraX11::OnXdndStatus(
if (source_state_ == SOURCE_STATE_PENDING_DROP) { if (source_state_ == SOURCE_STATE_PENDING_DROP) {
// We were waiting on the status message so we could send the XdndDrop. // We were waiting on the status message so we could send the XdndDrop.
if (negotiated_operation_ == ui::DragDropTypes::DRAG_NONE) { if (negotiated_operation_ == ui::DragDropTypes::DRAG_NONE) {
move_loop_.EndMoveLoop(); move_loop_->EndMoveLoop();
return; return;
} }
source_state_ = SOURCE_STATE_DROPPED; source_state_ = SOURCE_STATE_DROPPED;
...@@ -493,13 +497,13 @@ void DesktopDragDropClientAuraX11::OnXdndStatus( ...@@ -493,13 +497,13 @@ void DesktopDragDropClientAuraX11::OnXdndStatus(
switch (negotiated_operation_) { switch (negotiated_operation_) {
case ui::DragDropTypes::DRAG_COPY: case ui::DragDropTypes::DRAG_COPY:
move_loop_.UpdateCursor(copy_grab_cursor_); move_loop_->UpdateCursor(copy_grab_cursor_);
break; break;
case ui::DragDropTypes::DRAG_MOVE: case ui::DragDropTypes::DRAG_MOVE:
move_loop_.UpdateCursor(move_grab_cursor_); move_loop_->UpdateCursor(move_grab_cursor_);
break; break;
default: default:
move_loop_.UpdateCursor(grab_cursor_); move_loop_->UpdateCursor(grab_cursor_);
break; break;
} }
...@@ -534,7 +538,7 @@ void DesktopDragDropClientAuraX11::OnXdndFinished( ...@@ -534,7 +538,7 @@ void DesktopDragDropClientAuraX11::OnXdndFinished(
// Clear |source_current_window_| to avoid sending XdndLeave upon ending the // Clear |source_current_window_| to avoid sending XdndLeave upon ending the
// move loop. // move loop.
source_current_window_ = None; source_current_window_ = None;
move_loop_.EndMoveLoop(); move_loop_->EndMoveLoop();
} }
void DesktopDragDropClientAuraX11::OnXdndDrop( void DesktopDragDropClientAuraX11::OnXdndDrop(
...@@ -627,12 +631,12 @@ int DesktopDragDropClientAuraX11::StartDragAndDrop( ...@@ -627,12 +631,12 @@ int DesktopDragDropClientAuraX11::StartDragAndDrop(
// Windows has a specific method, DoDragDrop(), which performs the entire // Windows has a specific method, DoDragDrop(), which performs the entire
// drag. We have to emulate this, so we spin off a nested runloop which will // drag. We have to emulate this, so we spin off a nested runloop which will
// track all cursor movement and reroute events to a specific handler. // track all cursor movement and reroute events to a specific handler.
move_loop_.SetDragImage(source_provider_->GetDragImage(), move_loop_->SetDragImage(source_provider_->GetDragImage(),
source_provider_->GetDragImageOffset()); source_provider_->GetDragImageOffset());
move_loop_.RunMoveLoop(source_window, grab_cursor_); move_loop_->RunMoveLoop(source_window, grab_cursor_);
if (alive) { if (alive) {
move_loop_.SetDragImage(gfx::ImageSkia(), gfx::Vector2dF()); move_loop_->SetDragImage(gfx::ImageSkia(), gfx::Vector2dF());
source_provider_ = NULL; source_provider_ = NULL;
g_current_drag_drop_client = NULL; g_current_drag_drop_client = NULL;
...@@ -656,7 +660,7 @@ void DesktopDragDropClientAuraX11::Drop(aura::Window* target, ...@@ -656,7 +660,7 @@ void DesktopDragDropClientAuraX11::Drop(aura::Window* target,
} }
void DesktopDragDropClientAuraX11::DragCancel() { void DesktopDragDropClientAuraX11::DragCancel() {
move_loop_.EndMoveLoop(); move_loop_->EndMoveLoop();
} }
bool DesktopDragDropClientAuraX11::IsDragDropInProgress() { bool DesktopDragDropClientAuraX11::IsDragDropInProgress() {
...@@ -679,7 +683,7 @@ void DesktopDragDropClientAuraX11::OnMouseReleased() { ...@@ -679,7 +683,7 @@ void DesktopDragDropClientAuraX11::OnMouseReleased() {
if (source_state_ != SOURCE_STATE_OTHER) { if (source_state_ != SOURCE_STATE_OTHER) {
// The user has previously released the mouse and is clicking in // The user has previously released the mouse and is clicking in
// frustration. // frustration.
move_loop_.EndMoveLoop(); move_loop_->EndMoveLoop();
return; return;
} }
...@@ -696,7 +700,7 @@ void DesktopDragDropClientAuraX11::OnMouseReleased() { ...@@ -696,7 +700,7 @@ void DesktopDragDropClientAuraX11::OnMouseReleased() {
return; return;
} }
move_loop_.EndMoveLoop(); move_loop_->EndMoveLoop();
return; return;
} }
...@@ -715,7 +719,7 @@ void DesktopDragDropClientAuraX11::OnMouseReleased() { ...@@ -715,7 +719,7 @@ void DesktopDragDropClientAuraX11::OnMouseReleased() {
} }
} }
move_loop_.EndMoveLoop(); move_loop_->EndMoveLoop();
} }
void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { void DesktopDragDropClientAuraX11::OnMoveLoopEnded() {
...@@ -728,6 +732,11 @@ void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { ...@@ -728,6 +732,11 @@ void DesktopDragDropClientAuraX11::OnMoveLoopEnded() {
end_move_loop_timer_.Stop(); end_move_loop_timer_.Stop();
} }
scoped_ptr<X11MoveLoop> DesktopDragDropClientAuraX11::CreateMoveLoop(
X11MoveLoopDelegate* delegate) {
return scoped_ptr<X11MoveLoop>(new X11WholeScreenMoveLoop(this));
}
XID DesktopDragDropClientAuraX11::FindWindowFor( XID DesktopDragDropClientAuraX11::FindWindowFor(
const gfx::Point& screen_point) { const gfx::Point& screen_point) {
views::X11TopmostWindowFinder finder; views::X11TopmostWindowFinder finder;
...@@ -832,7 +841,7 @@ void DesktopDragDropClientAuraX11::StartEndMoveLoopTimer() { ...@@ -832,7 +841,7 @@ void DesktopDragDropClientAuraX11::StartEndMoveLoopTimer() {
} }
void DesktopDragDropClientAuraX11::EndMoveLoop() { void DesktopDragDropClientAuraX11::EndMoveLoop() {
move_loop_.EndMoveLoop(); move_loop_->EndMoveLoop();
} }
void DesktopDragDropClientAuraX11::DragTranslate( void DesktopDragDropClientAuraX11::DragTranslate(
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
#include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/x11_atom_cache.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h" #include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h"
#include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop_delegate.h"
#include "ui/wm/public/drag_drop_client.h" #include "ui/wm/public/drag_drop_client.h"
namespace aura { namespace aura {
...@@ -42,6 +41,7 @@ class SelectionFormatMap; ...@@ -42,6 +41,7 @@ class SelectionFormatMap;
namespace views { namespace views {
class DesktopNativeCursorManager; class DesktopNativeCursorManager;
class X11MoveLoop;
// Implements drag and drop on X11 for aura. On one side, this class takes raw // Implements drag and drop on X11 for aura. On one side, this class takes raw
// X11 events forwarded from DesktopWindowTreeHostLinux, while on the other, it // X11 events forwarded from DesktopWindowTreeHostLinux, while on the other, it
...@@ -49,7 +49,7 @@ class DesktopNativeCursorManager; ...@@ -49,7 +49,7 @@ class DesktopNativeCursorManager;
class VIEWS_EXPORT DesktopDragDropClientAuraX11 class VIEWS_EXPORT DesktopDragDropClientAuraX11
: public aura::client::DragDropClient, : public aura::client::DragDropClient,
public aura::WindowObserver, public aura::WindowObserver,
public X11WholeScreenMoveLoopDelegate { public X11MoveLoopDelegate {
public: public:
DesktopDragDropClientAuraX11( DesktopDragDropClientAuraX11(
aura::Window* root_window, aura::Window* root_window,
...@@ -63,6 +63,8 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11 ...@@ -63,6 +63,8 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11
// X11 messages to windows in our process. // X11 messages to windows in our process.
static DesktopDragDropClientAuraX11* GetForWindow(::Window window); static DesktopDragDropClientAuraX11* GetForWindow(::Window window);
void Init();
// These methods handle the various X11 client messages from the platform. // These methods handle the various X11 client messages from the platform.
void OnXdndEnter(const XClientMessageEvent& event); void OnXdndEnter(const XClientMessageEvent& event);
void OnXdndLeave(const XClientMessageEvent& event); void OnXdndLeave(const XClientMessageEvent& event);
...@@ -100,6 +102,10 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11 ...@@ -100,6 +102,10 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11
protected: protected:
// The following methods are virtual for the sake of testing. // The following methods are virtual for the sake of testing.
// Creates a move loop.
virtual scoped_ptr<X11MoveLoop> CreateMoveLoop(
X11MoveLoopDelegate* delegate);
// Finds the topmost X11 window at |screen_point| and returns it if it is // Finds the topmost X11 window at |screen_point| and returns it if it is
// Xdnd aware. Returns NULL otherwise. // Xdnd aware. Returns NULL otherwise.
virtual ::Window FindWindowFor(const gfx::Point& screen_point); virtual ::Window FindWindowFor(const gfx::Point& screen_point);
...@@ -178,8 +184,8 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11 ...@@ -178,8 +184,8 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11
void SendXdndDrop(::Window dest_window); void SendXdndDrop(::Window dest_window);
// A nested message loop that notifies this object of events through the // A nested message loop that notifies this object of events through the
// X11WholeScreenMoveLoopDelegate interface. // X11MoveLoopDelegate interface.
X11WholeScreenMoveLoop move_loop_; scoped_ptr<X11MoveLoop> move_loop_;
aura::Window* root_window_; aura::Window* root_window_;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h"
#include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/widget/desktop_aura/x11_move_loop.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
...@@ -73,6 +75,34 @@ class ClientMessageEventCollector { ...@@ -73,6 +75,34 @@ class ClientMessageEventCollector {
DISALLOW_COPY_AND_ASSIGN(ClientMessageEventCollector); DISALLOW_COPY_AND_ASSIGN(ClientMessageEventCollector);
}; };
// An implementation of X11MoveLoop where RunMoveLoop() always starts the move
// loop.
class TestMoveLoop : public X11MoveLoop {
public:
explicit TestMoveLoop(X11MoveLoopDelegate* delegate);
virtual ~TestMoveLoop();
// Returns true if the move loop is running.
bool IsRunning() const;
// X11MoveLoop:
virtual bool RunMoveLoop(aura::Window* window,
gfx::NativeCursor cursor) OVERRIDE;
virtual void UpdateCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void EndMoveLoop() OVERRIDE;
virtual void SetDragImage(const gfx::ImageSkia& image,
const gfx::Vector2dF& offset) OVERRIDE;
private:
// Not owned.
X11MoveLoopDelegate* delegate_;
// Ends the move loop.
base::Closure quit_closure_;
bool is_running_;
};
// Implementation of DesktopDragDropClientAuraX11 which works with a fake // Implementation of DesktopDragDropClientAuraX11 which works with a fake
// |DesktopDragDropClientAuraX11::source_current_window_|. // |DesktopDragDropClientAuraX11::source_current_window_|.
class TestDragDropClient : public DesktopDragDropClientAuraX11 { class TestDragDropClient : public DesktopDragDropClientAuraX11 {
...@@ -122,18 +152,10 @@ class TestDragDropClient : public DesktopDragDropClientAuraX11 { ...@@ -122,18 +152,10 @@ class TestDragDropClient : public DesktopDragDropClientAuraX11 {
// Returns true if the move loop is running. // Returns true if the move loop is running.
bool IsMoveLoopRunning(); bool IsMoveLoopRunning();
// DesktopDragDropClientAuraX11:
virtual int StartDragAndDrop(
const ui::OSExchangeData& data,
aura::Window* root_window,
aura::Window* source_window,
const gfx::Point& root_location,
int operation,
ui::DragDropTypes::DragEventSource source) OVERRIDE;
virtual void OnMoveLoopEnded() OVERRIDE;
private: private:
// DesktopDragDropClientAuraX11: // DesktopDragDropClientAuraX11:
virtual scoped_ptr<X11MoveLoop> CreateMoveLoop(
X11MoveLoopDelegate* delegate) OVERRIDE;
virtual ::Window FindWindowFor(const gfx::Point& screen_point) OVERRIDE; virtual ::Window FindWindowFor(const gfx::Point& screen_point) OVERRIDE;
virtual void SendXClientEvent(::Window xid, XEvent* event) OVERRIDE; virtual void SendXClientEvent(::Window xid, XEvent* event) OVERRIDE;
...@@ -144,8 +166,8 @@ class TestDragDropClient : public DesktopDragDropClientAuraX11 { ...@@ -144,8 +166,8 @@ class TestDragDropClient : public DesktopDragDropClientAuraX11 {
// current mouse position. // current mouse position.
::Window target_xid_; ::Window target_xid_;
// Whether the move loop is running. // The move loop. Not owned.
bool move_loop_running_; TestMoveLoop* loop_;
// Map of ::Windows to the collector which intercepts XClientMessageEvents // Map of ::Windows to the collector which intercepts XClientMessageEvents
// for that window. // for that window.
...@@ -182,6 +204,46 @@ void ClientMessageEventCollector::RecordEvent( ...@@ -182,6 +204,46 @@ void ClientMessageEventCollector::RecordEvent(
events_.push_back(event); events_.push_back(event);
} }
///////////////////////////////////////////////////////////////////////////////
// TestMoveLoop
TestMoveLoop::TestMoveLoop(X11MoveLoopDelegate* delegate)
: delegate_(delegate),
is_running_(false) {
}
TestMoveLoop::~TestMoveLoop() {
}
bool TestMoveLoop::IsRunning() const {
return is_running_;
}
bool TestMoveLoop::RunMoveLoop(
aura::Window* window,
gfx::NativeCursor cursor) {
is_running_ = true;
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure();
run_loop.Run();
return true;
}
void TestMoveLoop::UpdateCursor(gfx::NativeCursor cursor) {
}
void TestMoveLoop::EndMoveLoop() {
if (is_running_) {
delegate_->OnMoveLoopEnded();
is_running_ = false;
quit_closure_.Run();
}
}
void TestMoveLoop::SetDragImage(const gfx::ImageSkia& image,
const gfx::Vector2dF& offset) {
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// TestDragDropClient // TestDragDropClient
...@@ -200,7 +262,7 @@ TestDragDropClient::TestDragDropClient( ...@@ -200,7 +262,7 @@ TestDragDropClient::TestDragDropClient(
window->GetHost()->GetAcceleratedWidget()), window->GetHost()->GetAcceleratedWidget()),
source_xid_(window->GetHost()->GetAcceleratedWidget()), source_xid_(window->GetHost()->GetAcceleratedWidget()),
target_xid_(None), target_xid_(None),
move_loop_running_(false), loop_(NULL),
atom_cache_(gfx::GetXDisplay(), kAtomsToCache) { atom_cache_(gfx::GetXDisplay(), kAtomsToCache) {
} }
...@@ -266,24 +328,13 @@ void TestDragDropClient::SetTopmostXWindowAndMoveMouse(::Window xid) { ...@@ -266,24 +328,13 @@ void TestDragDropClient::SetTopmostXWindowAndMoveMouse(::Window xid) {
} }
bool TestDragDropClient::IsMoveLoopRunning() { bool TestDragDropClient::IsMoveLoopRunning() {
return move_loop_running_; return loop_->IsRunning();
}
int TestDragDropClient::StartDragAndDrop(
const ui::OSExchangeData& data,
aura::Window* root_window,
aura::Window* source_window,
const gfx::Point& root_location,
int operation,
ui::DragDropTypes::DragEventSource source) {
move_loop_running_ = true;
return DesktopDragDropClientAuraX11::StartDragAndDrop(data, root_window,
source_window, root_location, operation, source);
} }
void TestDragDropClient::OnMoveLoopEnded() { scoped_ptr<X11MoveLoop> TestDragDropClient::CreateMoveLoop(
DesktopDragDropClientAuraX11::OnMoveLoopEnded(); X11MoveLoopDelegate* delegate) {
move_loop_running_ = false; loop_ = new TestMoveLoop(delegate);
return scoped_ptr<X11MoveLoop>(loop_);
} }
::Window TestDragDropClient::FindWindowFor(const gfx::Point& screen_point) { ::Window TestDragDropClient::FindWindowFor(const gfx::Point& screen_point) {
...@@ -338,6 +389,7 @@ class DesktopDragDropClientAuraX11Test : public ViewsTestBase { ...@@ -338,6 +389,7 @@ class DesktopDragDropClientAuraX11Test : public ViewsTestBase {
client_.reset(new TestDragDropClient(widget_->GetNativeWindow(), client_.reset(new TestDragDropClient(widget_->GetNativeWindow(),
cursor_manager_.get())); cursor_manager_.get()));
client_->Init();
} }
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
......
...@@ -291,6 +291,7 @@ DesktopWindowTreeHostX11::CreateDragDropClient( ...@@ -291,6 +291,7 @@ DesktopWindowTreeHostX11::CreateDragDropClient(
DesktopNativeCursorManager* cursor_manager) { DesktopNativeCursorManager* cursor_manager) {
drag_drop_client_ = new DesktopDragDropClientAuraX11( drag_drop_client_ = new DesktopDragDropClientAuraX11(
window(), cursor_manager, xdisplay_, xwindow_); window(), cursor_manager, xdisplay_, xwindow_);
drag_drop_client_->Init();
return scoped_ptr<aura::client::DragDropClient>(drag_drop_client_).Pass(); return scoped_ptr<aura::client::DragDropClient>(drag_drop_client_).Pass();
} }
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
#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_whole_screen_move_loop.h" #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h"
#include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop_delegate.h"
#include "ui/wm/public/window_move_client.h" #include "ui/wm/public/window_move_client.h"
namespace aura { namespace aura {
...@@ -24,7 +24,7 @@ namespace views { ...@@ -24,7 +24,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::X11WholeScreenMoveLoopDelegate, public views::X11MoveLoopDelegate,
public aura::client::WindowMoveClient { public aura::client::WindowMoveClient {
public: public:
X11DesktopWindowMoveClient(); X11DesktopWindowMoveClient();
......
// Copyright 2014 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_X11_MOVE_LOOP_H_
#define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_MOVE_LOOP_H_
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/x/x11_types.h"
namespace views {
// Runs a nested message loop and grabs the mouse. This is used to implement
// dragging.
class X11MoveLoop {
public:
virtual ~X11MoveLoop() {}
// Runs the nested message loop. While the mouse is grabbed, use |cursor| as
// the mouse cursor. Returns true if the move-loop is completed successfully.
// If the pointer-grab fails, or the move-loop is canceled by the user (e.g.
// by pressing escape), then returns false.
virtual bool RunMoveLoop(aura::Window* window, gfx::NativeCursor cursor) = 0;
// Updates the cursor while the move loop is running.
virtual void UpdateCursor(gfx::NativeCursor cursor) = 0;
// Ends the RunMoveLoop() that's currently in progress.
virtual void EndMoveLoop() = 0;
// Sets an image to be used during the drag.
virtual void SetDragImage(const gfx::ImageSkia& image,
const gfx::Vector2dF& offset) = 0;
};
} // namespace views
#endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_MOVE_LOOP_H_
// Copyright (c) 2013 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_DELEGATE_H_ #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_X11_MOVE_LOOP_DELEGATE_H_
#define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_DELEGATE_H_ #define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_MOVE_LOOP_DELEGATE_H_
#include <X11/Xlib.h> #include <X11/Xlib.h>
// Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
#undef RootWindow
namespace views { namespace views {
// Receives mouse events while the X11WholeScreenMoveLoop is tracking a drag on // Receives mouse events while the X11MoveLoop is tracking a drag.
// the screen. class X11MoveLoopDelegate {
class X11WholeScreenMoveLoopDelegate {
public: public:
// Called when we receive a motion event. // Called when we receive a motion event.
virtual void OnMouseMovement(XMotionEvent* event) = 0; virtual void OnMouseMovement(XMotionEvent* event) = 0;
...@@ -28,4 +25,4 @@ class X11WholeScreenMoveLoopDelegate { ...@@ -28,4 +25,4 @@ class X11WholeScreenMoveLoopDelegate {
} // namespace views } // namespace views
#endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_DELEGATE_H_ #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_MOVE_LOOP_DELEGATE_H_
...@@ -55,8 +55,7 @@ class ScopedCapturer { ...@@ -55,8 +55,7 @@ class ScopedCapturer {
} // namespace } // namespace
X11WholeScreenMoveLoop::X11WholeScreenMoveLoop( X11WholeScreenMoveLoop::X11WholeScreenMoveLoop(X11MoveLoopDelegate* delegate)
X11WholeScreenMoveLoopDelegate* delegate)
: delegate_(delegate), : delegate_(delegate),
in_move_loop_(false), in_move_loop_(false),
should_reset_mouse_flags_(false), should_reset_mouse_flags_(false),
...@@ -277,7 +276,7 @@ void X11WholeScreenMoveLoop::EndMoveLoop() { ...@@ -277,7 +276,7 @@ void X11WholeScreenMoveLoop::EndMoveLoop() {
} }
void X11WholeScreenMoveLoop::SetDragImage(const gfx::ImageSkia& image, void X11WholeScreenMoveLoop::SetDragImage(const gfx::ImageSkia& image,
gfx::Vector2dF offset) { const gfx::Vector2dF& offset) {
drag_image_ = image; drag_image_ = image;
drag_offset_ = offset; drag_offset_ = offset;
} }
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gfx/vector2d_f.h" #include "ui/gfx/vector2d_f.h"
#include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop_delegate.h" #include "ui/views/widget/desktop_aura/x11_move_loop.h"
#include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h"
typedef struct _XDisplay XDisplay; typedef struct _XDisplay XDisplay;
...@@ -30,29 +31,23 @@ class Widget; ...@@ -30,29 +31,23 @@ class Widget;
// Runs a nested message loop and grabs the mouse. This is used to implement // Runs a nested message loop and grabs the mouse. This is used to implement
// dragging. // dragging.
class X11WholeScreenMoveLoop : public ui::PlatformEventDispatcher { class X11WholeScreenMoveLoop : public X11MoveLoop,
public ui::PlatformEventDispatcher {
public: public:
explicit X11WholeScreenMoveLoop(X11WholeScreenMoveLoopDelegate* delegate); explicit X11WholeScreenMoveLoop(X11MoveLoopDelegate* delegate);
virtual ~X11WholeScreenMoveLoop(); virtual ~X11WholeScreenMoveLoop();
// ui:::PlatformEventDispatcher: // ui:::PlatformEventDispatcher:
virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE; virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE; virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
// Runs the nested message loop. While the mouse is grabbed, use |cursor| as // X11MoveLoop:
// the mouse cursor. Returns true if the move-loop is completed successfully. virtual bool RunMoveLoop(aura::Window* window,
// If the pointer-grab fails, or the move-loop is canceled by the user (e.g. gfx::NativeCursor cursor) OVERRIDE;
// by pressing escape), then returns false. virtual void UpdateCursor(gfx::NativeCursor cursor) OVERRIDE;
bool RunMoveLoop(aura::Window* window, gfx::NativeCursor cursor); virtual void EndMoveLoop() OVERRIDE;
virtual void SetDragImage(const gfx::ImageSkia& image,
// Updates the cursor while the move loop is running. const gfx::Vector2dF& offset) OVERRIDE;
void UpdateCursor(gfx::NativeCursor cursor);
// Ends the RunMoveLoop() that's currently in progress.
void EndMoveLoop();
// Sets an image to be used during the drag.
void SetDragImage(const gfx::ImageSkia& image, gfx::Vector2dF offset);
private: private:
// Grabs the pointer and keyboard, setting the mouse cursor to |cursor|. // Grabs the pointer and keyboard, setting the mouse cursor to |cursor|.
...@@ -72,7 +67,7 @@ class X11WholeScreenMoveLoop : public ui::PlatformEventDispatcher { ...@@ -72,7 +67,7 @@ class X11WholeScreenMoveLoop : public ui::PlatformEventDispatcher {
// Dispatch mouse movement event to |delegate_| in a posted task. // Dispatch mouse movement event to |delegate_| in a posted task.
void DispatchMouseMovement(); void DispatchMouseMovement();
X11WholeScreenMoveLoopDelegate* delegate_; X11MoveLoopDelegate* delegate_;
// Are we running a nested message loop from RunMoveLoop()? // Are we running a nested message loop from RunMoveLoop()?
bool in_move_loop_; bool in_move_loop_;
......
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