Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc

Issue 214113003: Dispatches mouse movement messages in posted task to improve dragging smoothness (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dispatches mouse movement messages in posted task to improve dragging smoothness (comments) Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f03dcd1a0da045d114260d15937fc1b6d3bc621f 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),
+ weak_factory_(this) {
+ last_xmotion_.type = NoEventMask;
sadrul 2014/03/27 19:25:09 Set this to LASTEvent instead.
varkha 2014/03/27 21:00:54 Done.
}
X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {}
@@ -64,6 +67,13 @@ X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostLinux, MessagePumpDispatcher implementation:
+void X11WholeScreenMoveLoop::DispatchMouseMovement() {
+ if (!weak_factory_.HasWeakPtrs())
+ return;
+ weak_factory_.InvalidateWeakPtrs();
sadrul 2014/03/27 19:25:09 Add a CHECK that last_xmotion_.type == MotionNotif
varkha 2014/03/27 21:00:54 Done.
+ delegate_->OnMouseMovement(&last_xmotion_);
sadrul 2014/03/27 19:25:09 set last_xmotion_.type back to LASTEvent here?
varkha 2014/03/27 21:00:54 Done.
+}
+
uint32_t X11WholeScreenMoveLoop::Dispatch(const base::NativeEvent& event) {
XEvent* xev = event;
@@ -77,20 +87,29 @@ 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;
+ if (!weak_factory_.HasWeakPtrs()) {
+ base::MessageLoopForUI::current()->PostTask(
sadrul 2014/03/27 19:25:09 Add a comment here why we do this.
varkha 2014/03/27 21:00:54 Done.
+ FROM_HERE,
+ base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement,
+ weak_factory_.GetWeakPtr()));
+ }
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.
+ DispatchMouseMovement();
delegate_->OnMouseReleased();
}
break;
}
case KeyPress: {
- if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE)
+ if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) {
+ weak_factory_.InvalidateWeakPtrs();
sadrul 2014/03/27 19:25:09 Should this happen in EndMoveLoop() instead? Also
varkha 2014/03/27 21:00:54 Done.
EndMoveLoop();
+ }
break;
}
}

Powered by Google App Engine
This is Rietveld 408576698