34445c89b24f39ebe728219e44f75e5a2e063df3
[platform/framework/web/crosswalk.git] / src / ui / views / widget / desktop_aura / x11_desktop_window_move_client.cc
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/desktop_aura/x11_desktop_window_move_client.h"
6
7 #include <X11/Xlib.h>
8
9 #include "base/debug/stack_trace.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/message_loop/message_pump_x11.h"
12 #include "base/run_loop.h"
13 #include "ui/aura/env.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_tree_host.h"
16 #include "ui/base/x/x11_util.h"
17 #include "ui/events/event.h"
18 #include "ui/gfx/screen.h"
19
20 namespace views {
21
22 X11DesktopWindowMoveClient::X11DesktopWindowMoveClient()
23     : move_loop_(this),
24       host_(NULL) {
25 }
26
27 X11DesktopWindowMoveClient::~X11DesktopWindowMoveClient() {}
28
29 void X11DesktopWindowMoveClient::OnMouseMovement(XMotionEvent* event) {
30   gfx::Point cursor_point(event->x_root, event->y_root);
31   gfx::Point system_loc = cursor_point - window_offset_;
32   host_->SetBounds(gfx::Rect(system_loc, host_->GetBounds().size()));
33 }
34
35 void X11DesktopWindowMoveClient::OnMouseReleased() {
36   EndMoveLoop();
37 }
38
39 void X11DesktopWindowMoveClient::OnMoveLoopEnded() {
40   host_ = NULL;
41 }
42
43 ////////////////////////////////////////////////////////////////////////////////
44 // DesktopWindowTreeHostLinux, aura::client::WindowMoveClient implementation:
45
46 aura::client::WindowMoveResult X11DesktopWindowMoveClient::RunMoveLoop(
47     aura::Window* source,
48     const gfx::Vector2d& drag_offset,
49     aura::client::WindowMoveSource move_source) {
50   window_offset_ = drag_offset;
51   host_ = source->GetHost();
52
53   bool success = move_loop_.RunMoveLoop(source, host_->last_cursor());
54   return success ? aura::client::MOVE_SUCCESSFUL : aura::client::MOVE_CANCELED;
55 }
56
57 void X11DesktopWindowMoveClient::EndMoveLoop() {
58   move_loop_.EndMoveLoop();
59 }
60
61 }  // namespace views