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

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: For review 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) {
30 return false;
31 }
32
33 bool X11DesktopWindowMoveClient::PreHandleMouseEvent(aura::Window* target,
34 ui::MouseEvent* event) {
35 gfx::Point system_loc = event->system_location().Subtract(window_offset_);
36
37 if (in_move_loop_) {
38 switch (event->type()) {
39 case ui::ET_MOUSE_DRAGGED:
40 case ui::ET_MOUSE_MOVED: {
41 aura::RootWindow* root_window = target->GetRootWindow();
42 root_window->SetHostBounds(gfx::Rect(
43 system_loc, root_window->GetHostSize()));
44 return true;
45 }
46 case ui::ET_MOUSE_CAPTURE_CHANGED:
47 case ui::ET_MOUSE_RELEASED: {
48 EndMoveLoop();
49 return true;
50 }
51 default:
52 break;
53 }
54 }
55
56 return false;
57 }
58
59 ui::TouchStatus X11DesktopWindowMoveClient::PreHandleTouchEvent(
60 aura::Window* target,
61 ui::TouchEvent* event) {
62 return ui::TOUCH_STATUS_UNKNOWN;
63 }
64
65 ui::GestureStatus X11DesktopWindowMoveClient::PreHandleGestureEvent(
66 aura::Window* target,
67 ui::GestureEvent* event) {
68 return ui::GESTURE_STATUS_UNKNOWN;
69 }
70
71 void X11DesktopWindowMoveClient::RunMoveLoop(aura::Window* source,
72 const gfx::Point& drag_offset) {
73 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time.
74 in_move_loop_ = true;
75 window_offset_ = drag_offset;
76
77 source->GetRootWindow()->ShowRootWindow();
78
79 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
80 XGrabServer(display);
81 XUngrabPointer(display, CurrentTime);
82
83 aura::RootWindow* root_window = source->GetRootWindow();
84 int ret = XGrabPointer(display,
85 root_window->GetAcceleratedWidget(),
86 False,
87 ButtonReleaseMask | PointerMotionMask,
88 GrabModeAsync,
89 GrabModeAsync,
90 None,
91 None,
92 CurrentTime);
93 if (ret != GrabSuccess) {
94 NOTREACHED() << "Grab failed: " << ret;
95 }
96 XUngrabServer(display);
97
98 MessageLoopForUI* loop = MessageLoopForUI::current();
99 MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
100 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
101 quit_closure_ = run_loop.QuitClosure();
102 run_loop.Run();
103 }
104
105 void X11DesktopWindowMoveClient::EndMoveLoop() {
106 if (!in_move_loop_)
107 return;
108
109 // TODO(erg): Is this ungrab the cause of having to click to give input focus
110 // on drawn out windows? Not ungrabing here screws the X server until I kill
111 // the chrome process.
Elliot Glaysher 2012/08/14 21:49:54 derat: Off the top of your head, do you have any i
112
113 // Ungrab before we let go of the window.
114 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
115 XUngrabPointer(display, CurrentTime);
116
117 in_move_loop_ = false;
118 quit_closure_.Run();
119 }
120
121 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698