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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h" 5 #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h"
6 6
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. 8 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
9 #undef RootWindow 9 #undef RootWindow
10 10
11 #include "base/bind.h"
11 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_pump_x11.h" 13 #include "base/message_loop/message_pump_x11.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/aura/env.h" 16 #include "ui/aura/env.h"
16 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h" 18 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/aura/window_tree_host.h" 19 #include "ui/aura/window_tree_host.h"
19 #include "ui/base/x/x11_util.h" 20 #include "ui/base/x/x11_util.h"
20 #include "ui/events/event.h" 21 #include "ui/events/event.h"
(...skipping 28 matching lines...) Expand all
49 DISALLOW_COPY_AND_ASSIGN(ScopedCapturer); 50 DISALLOW_COPY_AND_ASSIGN(ScopedCapturer);
50 }; 51 };
51 52
52 } // namespace 53 } // namespace
53 54
54 X11WholeScreenMoveLoop::X11WholeScreenMoveLoop( 55 X11WholeScreenMoveLoop::X11WholeScreenMoveLoop(
55 X11WholeScreenMoveLoopDelegate* delegate) 56 X11WholeScreenMoveLoopDelegate* delegate)
56 : delegate_(delegate), 57 : delegate_(delegate),
57 in_move_loop_(false), 58 in_move_loop_(false),
58 should_reset_mouse_flags_(false), 59 should_reset_mouse_flags_(false),
59 grab_input_window_(None) { 60 grab_input_window_(None),
61 weak_factory_(this) {
62 last_xmotion_.type = NoEventMask;
sadrul 2014/03/27 19:25:09 Set this to LASTEvent instead.
varkha 2014/03/27 21:00:54 Done.
60 } 63 }
61 64
62 X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {} 65 X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {}
63 66
64 //////////////////////////////////////////////////////////////////////////////// 67 ////////////////////////////////////////////////////////////////////////////////
65 // DesktopWindowTreeHostLinux, MessagePumpDispatcher implementation: 68 // DesktopWindowTreeHostLinux, MessagePumpDispatcher implementation:
66 69
70 void X11WholeScreenMoveLoop::DispatchMouseMovement() {
71 if (!weak_factory_.HasWeakPtrs())
72 return;
73 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.
74 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.
75 }
76
67 uint32_t X11WholeScreenMoveLoop::Dispatch(const base::NativeEvent& event) { 77 uint32_t X11WholeScreenMoveLoop::Dispatch(const base::NativeEvent& event) {
68 XEvent* xev = event; 78 XEvent* xev = event;
69 79
70 // Note: the escape key is handled in the tab drag controller, which has 80 // Note: the escape key is handled in the tab drag controller, which has
71 // keyboard focus even though we took pointer grab. 81 // keyboard focus even though we took pointer grab.
72 switch (xev->type) { 82 switch (xev->type) {
73 case MotionNotify: { 83 case MotionNotify: {
74 if (drag_widget_.get()) { 84 if (drag_widget_.get()) {
75 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 85 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
76 gfx::Point location = gfx::ToFlooredPoint( 86 gfx::Point location = gfx::ToFlooredPoint(
77 screen->GetCursorScreenPoint() - drag_offset_); 87 screen->GetCursorScreenPoint() - drag_offset_);
78 drag_widget_->SetBounds(gfx::Rect(location, drag_image_.size())); 88 drag_widget_->SetBounds(gfx::Rect(location, drag_image_.size()));
79 } 89 }
80 delegate_->OnMouseMovement(&xev->xmotion); 90 last_xmotion_ = xev->xmotion;
91 if (!weak_factory_.HasWeakPtrs()) {
92 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.
93 FROM_HERE,
94 base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement,
95 weak_factory_.GetWeakPtr()));
96 }
81 break; 97 break;
82 } 98 }
83 case ButtonRelease: { 99 case ButtonRelease: {
84 if (xev->xbutton.button == Button1) { 100 if (xev->xbutton.button == Button1) {
85 // Assume that drags are being done with the left mouse button. Only 101 // Assume that drags are being done with the left mouse button. Only
86 // break the drag if the left mouse button was released. 102 // break the drag if the left mouse button was released.
103 DispatchMouseMovement();
87 delegate_->OnMouseReleased(); 104 delegate_->OnMouseReleased();
88 } 105 }
89 break; 106 break;
90 } 107 }
91 case KeyPress: { 108 case KeyPress: {
92 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) 109 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) {
110 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.
93 EndMoveLoop(); 111 EndMoveLoop();
112 }
94 break; 113 break;
95 } 114 }
96 } 115 }
97 116
98 return POST_DISPATCH_NONE; 117 return POST_DISPATCH_NONE;
99 } 118 }
100 119
101 //////////////////////////////////////////////////////////////////////////////// 120 ////////////////////////////////////////////////////////////////////////////////
102 // DesktopWindowTreeHostLinux, aura::client::WindowMoveClient implementation: 121 // DesktopWindowTreeHostLinux, aura::client::WindowMoveClient implementation:
103 122
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 for (int x = 0; x < in_bitmap->width(); ++x) { 318 for (int x = 0; x < in_bitmap->width(); ++x) {
300 if (SkColorGetA(in_row[x]) > kMinAlpha) 319 if (SkColorGetA(in_row[x]) > kMinAlpha)
301 return true; 320 return true;
302 } 321 }
303 } 322 }
304 323
305 return false; 324 return false;
306 } 325 }
307 326
308 } // namespace views 327 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698