OLD | NEW |
(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 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); |
| 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 XUngrabServer(display); |
| 95 if (ret != GrabSuccess) { |
| 96 DLOG(ERROR) << "Grabbing new tab for dragging failed: " << ret; |
| 97 return; |
| 98 } |
| 99 |
| 100 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 101 MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
| 102 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); |
| 103 quit_closure_ = run_loop.QuitClosure(); |
| 104 run_loop.Run(); |
| 105 } |
| 106 |
| 107 void X11DesktopWindowMoveClient::EndMoveLoop() { |
| 108 if (!in_move_loop_) |
| 109 return; |
| 110 |
| 111 // TODO(erg): Is this ungrab the cause of having to click to give input focus |
| 112 // on drawn out windows? Not ungrabbing here screws the X server until I kill |
| 113 // the chrome process. |
| 114 |
| 115 // Ungrab before we let go of the window. |
| 116 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay(); |
| 117 XUngrabPointer(display, CurrentTime); |
| 118 |
| 119 in_move_loop_ = false; |
| 120 quit_closure_.Run(); |
| 121 } |
| 122 |
| 123 } // namespace views |
OLD | NEW |