Roll src/third_party/WebKit 6f84130:7353389 (svn 184386:184391)
[chromium-blink-merge.git] / ui / views / widget / desktop_aura / x11_desktop_window_move_client.cc
blob821dd230b58e35d975a0513216017f57deca6b2f
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.
5 #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h"
7 #include <X11/Xlib.h>
9 #include "base/debug/stack_trace.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
12 #include "ui/aura/env.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_tree_host.h"
15 #include "ui/base/x/x11_util.h"
16 #include "ui/events/event.h"
17 #include "ui/gfx/screen.h"
19 namespace views {
21 X11DesktopWindowMoveClient::X11DesktopWindowMoveClient()
22 : move_loop_(this),
23 host_(NULL) {
26 X11DesktopWindowMoveClient::~X11DesktopWindowMoveClient() {}
28 void X11DesktopWindowMoveClient::OnMouseMovement(XMotionEvent* event) {
29 gfx::Point cursor_point(event->x_root, event->y_root);
30 gfx::Point system_loc = cursor_point - window_offset_;
31 host_->SetBounds(gfx::Rect(system_loc, host_->GetBounds().size()));
34 void X11DesktopWindowMoveClient::OnMouseReleased() {
35 EndMoveLoop();
38 void X11DesktopWindowMoveClient::OnMoveLoopEnded() {
39 host_ = NULL;
42 ////////////////////////////////////////////////////////////////////////////////
43 // DesktopWindowTreeHostLinux, aura::client::WindowMoveClient implementation:
45 aura::client::WindowMoveResult X11DesktopWindowMoveClient::RunMoveLoop(
46 aura::Window* source,
47 const gfx::Vector2d& drag_offset,
48 aura::client::WindowMoveSource move_source) {
49 window_offset_ = drag_offset;
50 host_ = source->GetHost();
52 source->SetCapture();
53 bool success = move_loop_.RunMoveLoop(source, host_->last_cursor());
54 return success ? aura::client::MOVE_SUCCESSFUL : aura::client::MOVE_CANCELED;
57 void X11DesktopWindowMoveClient::EndMoveLoop() {
58 move_loop_.EndMoveLoop();
61 } // namespace views