| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h" | 5 #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <X11/keysym.h> | 8 #include <X11/keysym.h> |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/logging.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "ui/aura/client/capture_client.h" | 19 #include "ui/aura/client/capture_client.h" |
| 18 #include "ui/aura/env.h" | 20 #include "ui/aura/env.h" |
| 19 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
| 21 #include "ui/aura/window_tree_host.h" | 23 #include "ui/aura/window_tree_host.h" |
| 22 #include "ui/base/x/x11_util.h" | 24 #include "ui/base/x/x11_util.h" |
| 23 #include "ui/base/x/x11_window_event_manager.h" | 25 #include "ui/base/x/x11_window_event_manager.h" |
| 24 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
| 25 #include "ui/events/event_utils.h" | 27 #include "ui/events/event_utils.h" |
| 26 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 28 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 68 } |
| 67 | 69 |
| 68 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
| 69 // DesktopWindowTreeHostLinux, ui::PlatformEventDispatcher implementation: | 71 // DesktopWindowTreeHostLinux, ui::PlatformEventDispatcher implementation: |
| 70 | 72 |
| 71 bool X11WholeScreenMoveLoop::CanDispatchEvent(const ui::PlatformEvent& event) { | 73 bool X11WholeScreenMoveLoop::CanDispatchEvent(const ui::PlatformEvent& event) { |
| 72 return in_move_loop_; | 74 return in_move_loop_; |
| 73 } | 75 } |
| 74 | 76 |
| 75 uint32_t X11WholeScreenMoveLoop::DispatchEvent(const ui::PlatformEvent& event) { | 77 uint32_t X11WholeScreenMoveLoop::DispatchEvent(const ui::PlatformEvent& event) { |
| 78 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 79 |
| 76 // This method processes all events while the move loop is active. | 80 // This method processes all events while the move loop is active. |
| 77 if (!in_move_loop_) | 81 if (!in_move_loop_) |
| 78 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 82 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 79 | 83 |
| 80 XEvent* xev = event; | 84 XEvent* xev = event; |
| 81 ui::EventType type = ui::EventTypeFromNative(xev); | 85 ui::EventType type = ui::EventTypeFromNative(xev); |
| 82 switch (type) { | 86 switch (type) { |
| 83 case ui::ET_MOUSE_MOVED: | 87 case ui::ET_MOUSE_MOVED: |
| 84 case ui::ET_MOUSE_DRAGGED: { | 88 case ui::ET_MOUSE_DRAGGED: { |
| 85 bool dispatch_mouse_event = !last_motion_in_screen_.get(); | 89 bool dispatch_mouse_event = !last_motion_in_screen_.get(); |
| 86 last_motion_in_screen_.reset( | 90 last_motion_in_screen_.reset( |
| 87 ui::EventFromNative(xev).release()->AsMouseEvent()); | 91 ui::EventFromNative(xev).release()->AsMouseEvent()); |
| 88 last_motion_in_screen_->set_location( | 92 last_motion_in_screen_->set_location( |
| 89 ui::EventSystemLocationFromNative(xev)); | 93 ui::EventSystemLocationFromNative(xev)); |
| 90 if (dispatch_mouse_event) { | 94 if (dispatch_mouse_event) { |
| 91 // Post a task to dispatch mouse movement event when control returns to | 95 // Post a task to dispatch mouse movement event when control returns to |
| 92 // the message loop. This allows smoother dragging since the events are | 96 // the message loop. This allows smoother dragging since the events are |
| 93 // dispatched without waiting for the drag widget updates. | 97 // dispatched without waiting for the drag widget updates. |
| 94 base::MessageLoopForUI::current()->task_runner()->PostTask( | 98 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 95 FROM_HERE, | 99 FROM_HERE, |
| 96 base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement, | 100 base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement, |
| 97 weak_factory_.GetWeakPtr())); | 101 weak_factory_.GetWeakPtr())); |
| 98 } | 102 } |
| 99 return ui::POST_DISPATCH_NONE; | 103 return ui::POST_DISPATCH_NONE; |
| 100 } | 104 } |
| 101 case ui::ET_MOUSE_RELEASED: { | 105 case ui::ET_MOUSE_RELEASED: { |
| 102 int button = (xev->type == ButtonRelease) | 106 int button = (xev->type == ButtonRelease) |
| 103 ? xev->xbutton.button | 107 ? xev->xbutton.button |
| 104 : ui::EventButtonFromNative(xev); | 108 : ui::EventButtonFromNative(xev); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 PointerMotionMask | KeyPressMask | KeyReleaseMask | | 276 PointerMotionMask | KeyPressMask | KeyReleaseMask | |
| 273 StructureNotifyMask; | 277 StructureNotifyMask; |
| 274 grab_input_window_events_.reset( | 278 grab_input_window_events_.reset( |
| 275 new ui::XScopedEventSelector(grab_input_window_, event_mask)); | 279 new ui::XScopedEventSelector(grab_input_window_, event_mask)); |
| 276 | 280 |
| 277 XMapRaised(display, grab_input_window_); | 281 XMapRaised(display, grab_input_window_); |
| 278 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(grab_input_window_); | 282 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(grab_input_window_); |
| 279 } | 283 } |
| 280 | 284 |
| 281 } // namespace views | 285 } // namespace views |
| OLD | NEW |