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

Side by Side Diff: ui/views/widget/x11_desktop_window_move_client.cc

Issue 10828133: Desktop Aura: Allow tab drags out of window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better mouse tracking Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/widget/x11_desktop_window_move_client.h"
6
7 #include <X11/Xlib.h>
8 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
9 #undef RootWindow
10
11 #include "base/message_loop.h"
12 #include "base/message_pump_aurax11.h"
13 #include "base/run_loop.h"
14 #include "ui/aura/env.h"
15 #include "ui/aura/root_window.h"
16 #include "ui/base/event.h"
17 #include "ui/base/x/x11_util.h"
18 #include "ui/gfx/screen.h"
19
20 namespace views {
21
22 X11DesktopWindowMoveClient::X11DesktopWindowMoveClient()
23 : in_move_loop_(false) {
24 }
25
26 X11DesktopWindowMoveClient::~X11DesktopWindowMoveClient() {}
27
28 bool X11DesktopWindowMoveClient::PreHandleKeyEvent(aura::Window* target,
29 ui::KeyEvent* event) {
Daniel Erat 2012/08/15 20:30:57 i think you may want to break out of the loop when
Elliot Glaysher 2012/08/15 20:55:59 I used to have that code here that did just that.
30 return false;
31 }
32
33 bool X11DesktopWindowMoveClient::PreHandleMouseEvent(aura::Window* target,
34 ui::MouseEvent* event) {
35 if (in_move_loop_) {
36 switch (event->type()) {
37 case ui::ET_MOUSE_DRAGGED:
38 case ui::ET_MOUSE_MOVED: {
39 DCHECK(event->valid_system_location());
40 gfx::Point system_loc =
41 event->system_location().Subtract(window_offset_);
42 aura::RootWindow* root_window = target->GetRootWindow();
43 root_window->SetHostBounds(gfx::Rect(
44 system_loc, root_window->GetHostSize()));
45 return true;
46 }
47 case ui::ET_MOUSE_CAPTURE_CHANGED:
48 case ui::ET_MOUSE_RELEASED: {
49 EndMoveLoop();
50 return true;
51 }
52 default:
53 break;
54 }
55 }
56
57 return false;
58 }
59
60 ui::TouchStatus X11DesktopWindowMoveClient::PreHandleTouchEvent(
61 aura::Window* target,
62 ui::TouchEvent* event) {
63 return ui::TOUCH_STATUS_UNKNOWN;
64 }
65
66 ui::GestureStatus X11DesktopWindowMoveClient::PreHandleGestureEvent(
67 aura::Window* target,
68 ui::GestureEvent* event) {
69 return ui::GESTURE_STATUS_UNKNOWN;
70 }
71
72 void X11DesktopWindowMoveClient::RunMoveLoop(aura::Window* source,
73 const gfx::Point& drag_offset) {
74 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time.
75 in_move_loop_ = true;
76 window_offset_ = drag_offset;
77
78 source->GetRootWindow()->ShowRootWindow();
79
80 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
81 XGrabServer(display);
82 XUngrabPointer(display, CurrentTime);
Daniel Erat 2012/08/15 20:30:57 refresh my memory: where's the previous pointer gr
Elliot Glaysher 2012/08/15 20:55:59 The implicit mousedown grab that began this drag.
83
84 aura::RootWindow* root_window = source->GetRootWindow();
85 int ret = XGrabPointer(display,
86 root_window->GetAcceleratedWidget(),
87 False,
88 ButtonReleaseMask | PointerMotionMask,
89 GrabModeAsync,
90 GrabModeAsync,
91 None,
92 None,
93 CurrentTime);
94 if (ret != GrabSuccess) {
95 NOTREACHED() << "Grab failed: " << ret;
Daniel Erat 2012/08/15 20:30:57 this shouldn't be a NOTREACHED(); it can legitimat
Elliot Glaysher 2012/08/15 20:55:59 What should it be instead? A return? Given that I
Daniel Erat 2012/08/16 00:25:17 Assuming that the pointer is grabbed before you gr
Elliot Glaysher 2012/08/16 19:32:53 Done. Also handled the error after we free the ser
96 }
97 XUngrabServer(display);
98
99 MessageLoopForUI* loop = MessageLoopForUI::current();
100 MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
101 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
102 quit_closure_ = run_loop.QuitClosure();
103 run_loop.Run();
104 }
105
106 void X11DesktopWindowMoveClient::EndMoveLoop() {
107 if (!in_move_loop_)
108 return;
109
110 // TODO(erg): Is this ungrab the cause of having to click to give input focus
111 // on drawn out windows? Not ungrabing here screws the X server until I kill
Daniel Erat 2012/08/15 20:30:57 nit: s/ungrabing/ungrabbing/
112 // the chrome process.
113
114 // Ungrab before we let go of the window.
115 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
116 XUngrabPointer(display, CurrentTime);
117
118 in_move_loop_ = false;
119 quit_closure_.Run();
120 }
121
122 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698