Chromium Code Reviews| 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/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 8 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
| 9 #undef RootWindow | 9 #undef RootWindow |
| 10 | 10 |
| 11 #include "base/bind.h" | |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/message_loop/message_pump_x11.h" | 13 #include "base/message_loop/message_pump_x11.h" |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_event_dispatcher.h" |
| 18 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/base/x/x11_util.h" | 20 #include "ui/base/x/x11_util.h" |
| 20 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 21 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 22 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 22 #include "ui/gfx/point_conversions.h" | 23 #include "ui/gfx/point_conversions.h" |
| 23 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
| 24 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
| 25 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 26 | 27 |
| 27 namespace views { | 28 namespace views { |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // The minimum alpha before we declare a pixel transparent when searching in | 32 // The minimum alpha before we declare a pixel transparent when searching in |
| 32 // our source image. | 33 // our source image. |
| 33 const uint32 kMinAlpha = 32; | 34 const uint32 kMinAlpha = 32; |
| 35 const unsigned char kDragWidgetOpacity = 0xc0; | |
| 34 | 36 |
| 35 class ScopedCapturer { | 37 class ScopedCapturer { |
| 36 public: | 38 public: |
| 37 explicit ScopedCapturer(aura::WindowTreeHost* host) | 39 explicit ScopedCapturer(aura::WindowTreeHost* host) |
| 38 : host_(host) { | 40 : host_(host) { |
| 39 host_->SetCapture(); | 41 host_->SetCapture(); |
| 40 } | 42 } |
| 41 | 43 |
| 42 ~ScopedCapturer() { | 44 ~ScopedCapturer() { |
| 43 host_->ReleaseCapture(); | 45 host_->ReleaseCapture(); |
| 44 } | 46 } |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 aura::WindowTreeHost* host_; | 49 aura::WindowTreeHost* host_; |
| 48 | 50 |
| 49 DISALLOW_COPY_AND_ASSIGN(ScopedCapturer); | 51 DISALLOW_COPY_AND_ASSIGN(ScopedCapturer); |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 } // namespace | 54 } // namespace |
| 53 | 55 |
| 54 X11WholeScreenMoveLoop::X11WholeScreenMoveLoop( | 56 X11WholeScreenMoveLoop::X11WholeScreenMoveLoop( |
| 55 X11WholeScreenMoveLoopDelegate* delegate) | 57 X11WholeScreenMoveLoopDelegate* delegate) |
| 56 : delegate_(delegate), | 58 : delegate_(delegate), |
| 57 in_move_loop_(false), | 59 in_move_loop_(false), |
| 58 should_reset_mouse_flags_(false), | 60 should_reset_mouse_flags_(false), |
| 59 grab_input_window_(None) { | 61 grab_input_window_(None), |
| 62 motion_task_posted_(false) { | |
| 63 last_xmotion_.type = NoEventMask; | |
| 60 } | 64 } |
| 61 | 65 |
| 62 X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {} | 66 X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {} |
| 63 | 67 |
| 64 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
| 65 // DesktopWindowTreeHostLinux, MessagePumpDispatcher implementation: | 69 // DesktopWindowTreeHostLinux, MessagePumpDispatcher implementation: |
| 66 | 70 |
| 71 void X11WholeScreenMoveLoop::DispatchMouseMovement() | |
|
sadrul
2014/03/26 18:01:07
{ EOL here
varkha
2014/03/27 04:48:13
Done (moved to https://codereview.chromium.org/214
| |
| 72 { | |
| 73 if (!motion_task_posted_) | |
| 74 return; | |
| 75 | |
| 76 motion_task_posted_ = false; | |
| 77 gfx::Point screen_point(last_xmotion_.x_root, last_xmotion_.y_root); | |
| 78 delegate_->OnMouseMovement(&last_xmotion_); | |
| 79 } | |
| 80 | |
| 67 uint32_t X11WholeScreenMoveLoop::Dispatch(const base::NativeEvent& event) { | 81 uint32_t X11WholeScreenMoveLoop::Dispatch(const base::NativeEvent& event) { |
| 68 XEvent* xev = event; | 82 XEvent* xev = event; |
| 69 | 83 |
| 70 // Note: the escape key is handled in the tab drag controller, which has | 84 // Note: the escape key is handled in the tab drag controller, which has |
| 71 // keyboard focus even though we took pointer grab. | 85 // keyboard focus even though we took pointer grab. |
| 72 switch (xev->type) { | 86 switch (xev->type) { |
| 73 case MotionNotify: { | 87 case MotionNotify: { |
| 74 if (drag_widget_.get()) { | 88 if (drag_widget_.get()) { |
| 75 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 89 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
| 76 gfx::Point location = gfx::ToFlooredPoint( | 90 gfx::Point location = gfx::ToFlooredPoint( |
| 77 screen->GetCursorScreenPoint() - drag_offset_); | 91 screen->GetCursorScreenPoint() - drag_offset_); |
| 78 drag_widget_->SetBounds(gfx::Rect(location, drag_image_.size())); | 92 drag_widget_->SetBounds(gfx::Rect(location, drag_image_.size())); |
| 93 drag_widget_->StackAtTop(); | |
| 79 } | 94 } |
| 80 delegate_->OnMouseMovement(&xev->xmotion); | 95 last_xmotion_ = xev->xmotion; |
|
sadrul
2014/03/26 18:01:07
Don't copy the whole event. Just keep track of the
varkha
2014/03/27 04:48:13
This was moved to https://codereview.chromium.org/
| |
| 96 if (!motion_task_posted_) { | |
| 97 gfx::Point screen_point(xev->xmotion.x_root, xev->xmotion.y_root); | |
| 98 motion_task_posted_ = true; | |
| 99 base::MessageLoopForUI::current()->PostTask( | |
| 100 FROM_HERE, | |
| 101 base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement, | |
| 102 base::Unretained(this))); | |
|
sadrul
2014/03/26 18:01:07
You should use a WeakPtr<> here, instead of using
varkha
2014/03/27 04:48:13
Will do in https://codereview.chromium.org/2141130
| |
| 103 } | |
| 81 break; | 104 break; |
| 82 } | 105 } |
| 83 case ButtonRelease: { | 106 case ButtonRelease: { |
| 84 if (xev->xbutton.button == Button1) { | 107 if (xev->xbutton.button == Button1) { |
| 85 // Assume that drags are being done with the left mouse button. Only | 108 // Assume that drags are being done with the left mouse button. Only |
| 86 // break the drag if the left mouse button was released. | 109 // break the drag if the left mouse button was released. |
| 110 if (motion_task_posted_) | |
| 111 DispatchMouseMovement(); | |
| 87 delegate_->OnMouseReleased(); | 112 delegate_->OnMouseReleased(); |
| 88 } | 113 } |
| 89 break; | 114 break; |
| 90 } | 115 } |
| 91 case KeyPress: { | 116 case KeyPress: { |
| 92 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) | 117 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) { |
| 118 motion_task_posted_ = false; | |
| 93 EndMoveLoop(); | 119 EndMoveLoop(); |
| 120 } | |
| 94 break; | 121 break; |
| 95 } | 122 } |
| 96 } | 123 } |
| 97 | 124 |
| 98 return POST_DISPATCH_NONE; | 125 return POST_DISPATCH_NONE; |
| 99 } | 126 } |
| 100 | 127 |
| 101 //////////////////////////////////////////////////////////////////////////////// | 128 //////////////////////////////////////////////////////////////////////////////// |
| 102 // DesktopWindowTreeHostLinux, aura::client::WindowMoveClient implementation: | 129 // DesktopWindowTreeHostLinux, aura::client::WindowMoveClient implementation: |
| 103 | 130 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 params.opacity = Widget::InitParams::OPAQUE_WINDOW; | 287 params.opacity = Widget::InitParams::OPAQUE_WINDOW; |
| 261 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 288 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 262 params.accept_events = false; | 289 params.accept_events = false; |
| 263 | 290 |
| 264 gfx::Point location = gfx::ToFlooredPoint( | 291 gfx::Point location = gfx::ToFlooredPoint( |
| 265 gfx::Screen::GetNativeScreen()->GetCursorScreenPoint() - drag_offset_); | 292 gfx::Screen::GetNativeScreen()->GetCursorScreenPoint() - drag_offset_); |
| 266 params.bounds = gfx::Rect(location, drag_image_.size()); | 293 params.bounds = gfx::Rect(location, drag_image_.size()); |
| 267 widget->set_focus_on_creation(false); | 294 widget->set_focus_on_creation(false); |
| 268 widget->set_frame_type(Widget::FRAME_TYPE_FORCE_NATIVE); | 295 widget->set_frame_type(Widget::FRAME_TYPE_FORCE_NATIVE); |
| 269 widget->Init(params); | 296 widget->Init(params); |
| 297 widget->SetOpacity(kDragWidgetOpacity); | |
| 270 widget->GetNativeWindow()->SetName("DragWindow"); | 298 widget->GetNativeWindow()->SetName("DragWindow"); |
| 271 | 299 |
| 272 ImageView* image = new ImageView(); | 300 ImageView* image = new ImageView(); |
| 273 image->SetImage(drag_image_); | 301 image->SetImage(drag_image_); |
| 274 image->SetBounds(0, 0, drag_image_.width(), drag_image_.height()); | 302 image->SetBounds(0, 0, drag_image_.width(), drag_image_.height()); |
| 275 widget->SetContentsView(image); | 303 widget->SetContentsView(image); |
| 276 widget->Show(); | 304 widget->Show(); |
| 277 widget->GetNativeWindow()->layer()->SetFillsBoundsOpaquely(false); | 305 widget->GetNativeWindow()->layer()->SetFillsBoundsOpaquely(false); |
| 278 | 306 |
| 279 drag_widget_.reset(widget); | 307 drag_widget_.reset(widget); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 299 for (int x = 0; x < in_bitmap->width(); ++x) { | 327 for (int x = 0; x < in_bitmap->width(); ++x) { |
| 300 if (SkColorGetA(in_row[x]) > kMinAlpha) | 328 if (SkColorGetA(in_row[x]) > kMinAlpha) |
| 301 return true; | 329 return true; |
| 302 } | 330 } |
| 303 } | 331 } |
| 304 | 332 |
| 305 return false; | 333 return false; |
| 306 } | 334 } |
| 307 | 335 |
| 308 } // namespace views | 336 } // namespace views |
| OLD | NEW |