Chromium Code Reviews| Index: ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc |
| diff --git a/ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc b/ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc |
| index 3f48b8993b7e83b6f4a9ddd878f6a85951fbb4bb..0b201d998e594abfea371c9be8a08ee3c22439d5 100644 |
| --- a/ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc |
| +++ b/ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc |
| @@ -8,6 +8,7 @@ |
| // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
| #undef RootWindow |
| +#include "base/bind.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/message_loop/message_pump_x11.h" |
| #include "base/run_loop.h" |
| @@ -56,7 +57,9 @@ X11WholeScreenMoveLoop::X11WholeScreenMoveLoop( |
| : delegate_(delegate), |
| in_move_loop_(false), |
| should_reset_mouse_flags_(false), |
| - grab_input_window_(None) { |
| + grab_input_window_(None), |
| + motion_task_posted_(false) { |
| + last_xmotion_.type = NoEventMask; |
| } |
| X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {} |
| @@ -64,6 +67,14 @@ X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {} |
| //////////////////////////////////////////////////////////////////////////////// |
| // DesktopWindowTreeHostLinux, MessagePumpDispatcher implementation: |
| +void X11WholeScreenMoveLoop::DispatchMouseMovement() { |
| + if (!motion_task_posted_) |
| + return; |
| + |
| + motion_task_posted_ = false; |
| + delegate_->OnMouseMovement(&last_xmotion_); |
| +} |
| + |
| uint32_t X11WholeScreenMoveLoop::Dispatch(const base::NativeEvent& event) { |
| XEvent* xev = event; |
| @@ -77,20 +88,31 @@ uint32_t X11WholeScreenMoveLoop::Dispatch(const base::NativeEvent& event) { |
| screen->GetCursorScreenPoint() - drag_offset_); |
| drag_widget_->SetBounds(gfx::Rect(location, drag_image_.size())); |
| } |
| - delegate_->OnMouseMovement(&xev->xmotion); |
| + last_xmotion_ = xev->xmotion; |
|
varkha
2014/03/27 05:41:39
From sadrul@: Don't copy the whole event. Just kee
varkha
2014/03/27 05:46:33
We need a NativeEvent& to pass to the delegate->On
|
| + if (!motion_task_posted_) { |
| + motion_task_posted_ = true; |
| + base::MessageLoopForUI::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement, |
| + base::Unretained(this))); |
|
varkha
2014/03/27 05:41:39
From sadrul@: You should use a WeakPtr<> here, ins
varkha
2014/03/27 05:46:33
Done.
|
| + } |
| break; |
| } |
| case ButtonRelease: { |
| if (xev->xbutton.button == Button1) { |
| // Assume that drags are being done with the left mouse button. Only |
| // break the drag if the left mouse button was released. |
| + if (motion_task_posted_) |
| + DispatchMouseMovement(); |
| delegate_->OnMouseReleased(); |
| } |
| break; |
| } |
| case KeyPress: { |
| - if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) |
| + if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) { |
| + motion_task_posted_ = false; |
| EndMoveLoop(); |
| + } |
| break; |
| } |
| } |