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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/widget/x11_desktop_window_move_client.cc
diff --git a/ui/views/widget/x11_desktop_window_move_client.cc b/ui/views/widget/x11_desktop_window_move_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..70ef3876fd8f9b74ebad624ffc0ad11cd9aa251f
--- /dev/null
+++ b/ui/views/widget/x11_desktop_window_move_client.cc
@@ -0,0 +1,122 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/widget/x11_desktop_window_move_client.h"
+
+#include <X11/Xlib.h>
+// Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
+#undef RootWindow
+
+#include "base/message_loop.h"
+#include "base/message_pump_aurax11.h"
+#include "base/run_loop.h"
+#include "ui/aura/env.h"
+#include "ui/aura/root_window.h"
+#include "ui/base/event.h"
+#include "ui/base/x/x11_util.h"
+#include "ui/gfx/screen.h"
+
+namespace views {
+
+X11DesktopWindowMoveClient::X11DesktopWindowMoveClient()
+ : in_move_loop_(false) {
+}
+
+X11DesktopWindowMoveClient::~X11DesktopWindowMoveClient() {}
+
+bool X11DesktopWindowMoveClient::PreHandleKeyEvent(aura::Window* target,
+ 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.
+ return false;
+}
+
+bool X11DesktopWindowMoveClient::PreHandleMouseEvent(aura::Window* target,
+ ui::MouseEvent* event) {
+ if (in_move_loop_) {
+ switch (event->type()) {
+ case ui::ET_MOUSE_DRAGGED:
+ case ui::ET_MOUSE_MOVED: {
+ DCHECK(event->valid_system_location());
+ gfx::Point system_loc =
+ event->system_location().Subtract(window_offset_);
+ aura::RootWindow* root_window = target->GetRootWindow();
+ root_window->SetHostBounds(gfx::Rect(
+ system_loc, root_window->GetHostSize()));
+ return true;
+ }
+ case ui::ET_MOUSE_CAPTURE_CHANGED:
+ case ui::ET_MOUSE_RELEASED: {
+ EndMoveLoop();
+ return true;
+ }
+ default:
+ break;
+ }
+ }
+
+ return false;
+}
+
+ui::TouchStatus X11DesktopWindowMoveClient::PreHandleTouchEvent(
+ aura::Window* target,
+ ui::TouchEvent* event) {
+ return ui::TOUCH_STATUS_UNKNOWN;
+}
+
+ui::GestureStatus X11DesktopWindowMoveClient::PreHandleGestureEvent(
+ aura::Window* target,
+ ui::GestureEvent* event) {
+ return ui::GESTURE_STATUS_UNKNOWN;
+}
+
+void X11DesktopWindowMoveClient::RunMoveLoop(aura::Window* source,
+ const gfx::Point& drag_offset) {
+ DCHECK(!in_move_loop_); // Can only handle one nested loop at a time.
+ in_move_loop_ = true;
+ window_offset_ = drag_offset;
+
+ source->GetRootWindow()->ShowRootWindow();
+
+ Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
+ XGrabServer(display);
+ 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.
+
+ aura::RootWindow* root_window = source->GetRootWindow();
+ int ret = XGrabPointer(display,
+ root_window->GetAcceleratedWidget(),
+ False,
+ ButtonReleaseMask | PointerMotionMask,
+ GrabModeAsync,
+ GrabModeAsync,
+ None,
+ None,
+ CurrentTime);
+ if (ret != GrabSuccess) {
+ 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
+ }
+ XUngrabServer(display);
+
+ MessageLoopForUI* loop = MessageLoopForUI::current();
+ MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
+ base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
+ quit_closure_ = run_loop.QuitClosure();
+ run_loop.Run();
+}
+
+void X11DesktopWindowMoveClient::EndMoveLoop() {
+ if (!in_move_loop_)
+ return;
+
+ // TODO(erg): Is this ungrab the cause of having to click to give input focus
+ // 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/
+ // the chrome process.
+
+ // Ungrab before we let go of the window.
+ Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
+ XUngrabPointer(display, CurrentTime);
+
+ in_move_loop_ = false;
+ quit_closure_.Run();
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698