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

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: 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 unified diff | Download patch
« no previous file with comments | « ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 motion_task_posted_(false) {
62 last_xmotion_.type = NoEventMask;
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 (!motion_task_posted_)
72 return;
73
74 motion_task_posted_ = false;
75 delegate_->OnMouseMovement(&last_xmotion_);
76 }
77
67 uint32_t X11WholeScreenMoveLoop::Dispatch(const base::NativeEvent& event) { 78 uint32_t X11WholeScreenMoveLoop::Dispatch(const base::NativeEvent& event) {
68 XEvent* xev = event; 79 XEvent* xev = event;
69 80
70 // Note: the escape key is handled in the tab drag controller, which has 81 // Note: the escape key is handled in the tab drag controller, which has
71 // keyboard focus even though we took pointer grab. 82 // keyboard focus even though we took pointer grab.
72 switch (xev->type) { 83 switch (xev->type) {
73 case MotionNotify: { 84 case MotionNotify: {
74 if (drag_widget_.get()) { 85 if (drag_widget_.get()) {
75 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 86 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
76 gfx::Point location = gfx::ToFlooredPoint( 87 gfx::Point location = gfx::ToFlooredPoint(
77 screen->GetCursorScreenPoint() - drag_offset_); 88 screen->GetCursorScreenPoint() - drag_offset_);
78 drag_widget_->SetBounds(gfx::Rect(location, drag_image_.size())); 89 drag_widget_->SetBounds(gfx::Rect(location, drag_image_.size()));
79 } 90 }
80 delegate_->OnMouseMovement(&xev->xmotion); 91 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
92 if (!motion_task_posted_) {
93 motion_task_posted_ = true;
94 base::MessageLoopForUI::current()->PostTask(
95 FROM_HERE,
96 base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement,
97 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.
98 }
81 break; 99 break;
82 } 100 }
83 case ButtonRelease: { 101 case ButtonRelease: {
84 if (xev->xbutton.button == Button1) { 102 if (xev->xbutton.button == Button1) {
85 // Assume that drags are being done with the left mouse button. Only 103 // Assume that drags are being done with the left mouse button. Only
86 // break the drag if the left mouse button was released. 104 // break the drag if the left mouse button was released.
105 if (motion_task_posted_)
106 DispatchMouseMovement();
87 delegate_->OnMouseReleased(); 107 delegate_->OnMouseReleased();
88 } 108 }
89 break; 109 break;
90 } 110 }
91 case KeyPress: { 111 case KeyPress: {
92 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) 112 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) {
113 motion_task_posted_ = false;
93 EndMoveLoop(); 114 EndMoveLoop();
115 }
94 break; 116 break;
95 } 117 }
96 } 118 }
97 119
98 return POST_DISPATCH_NONE; 120 return POST_DISPATCH_NONE;
99 } 121 }
100 122
101 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
102 // DesktopWindowTreeHostLinux, aura::client::WindowMoveClient implementation: 124 // DesktopWindowTreeHostLinux, aura::client::WindowMoveClient implementation:
103 125
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 for (int x = 0; x < in_bitmap->width(); ++x) { 321 for (int x = 0; x < in_bitmap->width(); ++x) {
300 if (SkColorGetA(in_row[x]) > kMinAlpha) 322 if (SkColorGetA(in_row[x]) > kMinAlpha)
301 return true; 323 return true;
302 } 324 }
303 } 325 }
304 326
305 return false; 327 return false;
306 } 328 }
307 329
308 } // namespace views 330 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698