| 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 <X11/keysym.h> | 7 #include <X11/keysym.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 //////////////////////////////////////////////////////////////////////////////// | 62 //////////////////////////////////////////////////////////////////////////////// |
| 63 // DesktopWindowTreeHostLinux, ui::PlatformEventDispatcher implementation: | 63 // DesktopWindowTreeHostLinux, ui::PlatformEventDispatcher implementation: |
| 64 | 64 |
| 65 bool X11WholeScreenMoveLoop::CanDispatchEvent(const ui::PlatformEvent& event) { | 65 bool X11WholeScreenMoveLoop::CanDispatchEvent(const ui::PlatformEvent& event) { |
| 66 return in_move_loop_; | 66 return in_move_loop_; |
| 67 } | 67 } |
| 68 | 68 |
| 69 uint32_t X11WholeScreenMoveLoop::DispatchEvent(const ui::PlatformEvent& event) { | 69 uint32_t X11WholeScreenMoveLoop::DispatchEvent(const ui::PlatformEvent& event) { |
| 70 // This method processes all events while the move loop is active. | 70 // This method processes all events while the move loop is active. |
| 71 if (!in_move_loop_) | 71 if (!in_move_loop_) |
| 72 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 72 return ui::kPostDispatchPerformDefault; |
| 73 | 73 |
| 74 XEvent* xev = event; | 74 XEvent* xev = event; |
| 75 switch (xev->type) { | 75 switch (xev->type) { |
| 76 case MotionNotify: { | 76 case MotionNotify: { |
| 77 last_xmotion_ = xev->xmotion; | 77 last_xmotion_ = xev->xmotion; |
| 78 if (!weak_factory_.HasWeakPtrs()) { | 78 if (!weak_factory_.HasWeakPtrs()) { |
| 79 // Post a task to dispatch mouse movement event when control returns to | 79 // Post a task to dispatch mouse movement event when control returns to |
| 80 // the message loop. This allows smoother dragging since the events are | 80 // the message loop. This allows smoother dragging since the events are |
| 81 // dispatched without waiting for the drag widget updates. | 81 // dispatched without waiting for the drag widget updates. |
| 82 base::MessageLoopForUI::current()->PostTask( | 82 base::MessageLoopForUI::current()->PostTask( |
| 83 FROM_HERE, | 83 FROM_HERE, |
| 84 base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement, | 84 base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement, |
| 85 weak_factory_.GetWeakPtr())); | 85 weak_factory_.GetWeakPtr())); |
| 86 } | 86 } |
| 87 return ui::POST_DISPATCH_NONE; | 87 return ui::kPostDispatchNone; |
| 88 } | 88 } |
| 89 case ButtonRelease: { | 89 case ButtonRelease: { |
| 90 if (xev->xbutton.button == Button1) { | 90 if (xev->xbutton.button == Button1) { |
| 91 // Assume that drags are being done with the left mouse button. Only | 91 // Assume that drags are being done with the left mouse button. Only |
| 92 // break the drag if the left mouse button was released. | 92 // break the drag if the left mouse button was released. |
| 93 DispatchMouseMovement(); | 93 DispatchMouseMovement(); |
| 94 delegate_->OnMouseReleased(); | 94 delegate_->OnMouseReleased(); |
| 95 | 95 |
| 96 if (!grabbed_pointer_) { | 96 if (!grabbed_pointer_) { |
| 97 // If the source widget had capture prior to the move loop starting, | 97 // If the source widget had capture prior to the move loop starting, |
| 98 // it may be relying on views::Widget getting the mouse release and | 98 // it may be relying on views::Widget getting the mouse release and |
| 99 // releasing capture in Widget::OnMouseEvent(). | 99 // releasing capture in Widget::OnMouseEvent(). |
| 100 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 100 return ui::kPostDispatchPerformDefault; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 return ui::POST_DISPATCH_NONE; | 103 return ui::kPostDispatchNone; |
| 104 } | 104 } |
| 105 case KeyPress: { | 105 case KeyPress: { |
| 106 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) { | 106 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) { |
| 107 canceled_ = true; | 107 canceled_ = true; |
| 108 EndMoveLoop(); | 108 EndMoveLoop(); |
| 109 return ui::POST_DISPATCH_NONE; | 109 return ui::kPostDispatchNone; |
| 110 } | 110 } |
| 111 break; | 111 break; |
| 112 } | 112 } |
| 113 case GenericEvent: { | 113 case GenericEvent: { |
| 114 ui::EventType type = ui::EventTypeFromNative(xev); | 114 ui::EventType type = ui::EventTypeFromNative(xev); |
| 115 switch (type) { | 115 switch (type) { |
| 116 case ui::ET_MOUSE_MOVED: | 116 case ui::ET_MOUSE_MOVED: |
| 117 case ui::ET_MOUSE_DRAGGED: | 117 case ui::ET_MOUSE_DRAGGED: |
| 118 case ui::ET_MOUSE_RELEASED: { | 118 case ui::ET_MOUSE_RELEASED: { |
| 119 XEvent xevent = {0}; | 119 XEvent xevent = {0}; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 134 xevent.xmotion.x_root = point.x(); | 134 xevent.xmotion.x_root = point.x(); |
| 135 xevent.xmotion.y_root = point.y(); | 135 xevent.xmotion.y_root = point.y(); |
| 136 return DispatchEvent(&xevent); | 136 return DispatchEvent(&xevent); |
| 137 } | 137 } |
| 138 default: | 138 default: |
| 139 break; | 139 break; |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 144 return ui::kPostDispatchPerformDefault; |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool X11WholeScreenMoveLoop::RunMoveLoop(aura::Window* source, | 147 bool X11WholeScreenMoveLoop::RunMoveLoop(aura::Window* source, |
| 148 gfx::NativeCursor cursor) { | 148 gfx::NativeCursor cursor) { |
| 149 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. | 149 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. |
| 150 | 150 |
| 151 // Query the mouse cursor prior to the move loop starting so that it can be | 151 // Query the mouse cursor prior to the move loop starting so that it can be |
| 152 // restored when the move loop finishes. | 152 // restored when the move loop finishes. |
| 153 initial_cursor_ = source->GetHost()->last_cursor(); | 153 initial_cursor_ = source->GetHost()->last_cursor(); |
| 154 | 154 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 DefaultRootWindow(display), | 297 DefaultRootWindow(display), |
| 298 -100, -100, 10, 10, | 298 -100, -100, 10, 10, |
| 299 0, CopyFromParent, InputOnly, CopyFromParent, | 299 0, CopyFromParent, InputOnly, CopyFromParent, |
| 300 attribute_mask, &swa); | 300 attribute_mask, &swa); |
| 301 XMapRaised(display, window); | 301 XMapRaised(display, window); |
| 302 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(window); | 302 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(window); |
| 303 return window; | 303 return window; |
| 304 } | 304 } |
| 305 | 305 |
| 306 } // namespace views | 306 } // namespace views |
| OLD | NEW |