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/extensions/XInput2.h> | |
| 7 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 8 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 9 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
| 9 #undef RootWindow | 10 #undef RootWindow |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | |
| 15 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_event_dispatcher.h" | 17 #include "ui/aura/window_event_dispatcher.h" |
| 18 #include "ui/aura/window_tree_host.h" | |
| 19 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
| 20 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 21 #include "ui/events/event_utils.h" | 20 #include "ui/events/event_utils.h" |
| 22 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 21 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 23 #include "ui/events/platform/scoped_event_dispatcher.h" | 22 #include "ui/events/platform/scoped_event_dispatcher.h" |
| 24 #include "ui/events/platform/x11/x11_event_source.h" | 23 #include "ui/events/platform/x11/x11_event_source.h" |
| 25 #include "ui/gfx/point_conversions.h" | |
| 26 #include "ui/gfx/screen.h" | |
| 27 #include "ui/views/controls/image_view.h" | |
| 28 #include "ui/views/widget/widget.h" | |
| 29 | 24 |
| 30 namespace views { | 25 namespace views { |
| 31 | 26 |
| 32 namespace { | |
| 33 | |
| 34 // The minimum alpha before we declare a pixel transparent when searching in | |
| 35 // our source image. | |
| 36 const uint32 kMinAlpha = 32; | |
| 37 const unsigned char kDragWidgetOpacity = 0xc0; | |
| 38 | |
| 39 class ScopedCapturer { | |
| 40 public: | |
| 41 explicit ScopedCapturer(aura::WindowTreeHost* host) | |
| 42 : host_(host) { | |
| 43 host_->SetCapture(); | |
| 44 } | |
| 45 | |
| 46 ~ScopedCapturer() { | |
| 47 host_->ReleaseCapture(); | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 aura::WindowTreeHost* host_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(ScopedCapturer); | |
| 54 }; | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 X11WholeScreenMoveLoop::X11WholeScreenMoveLoop( | 27 X11WholeScreenMoveLoop::X11WholeScreenMoveLoop( |
| 59 X11WholeScreenMoveLoopDelegate* delegate) | 28 X11WholeScreenMoveLoopDelegate* delegate) |
| 60 : delegate_(delegate), | 29 : delegate_(delegate), |
| 61 in_move_loop_(false), | 30 in_move_loop_(false), |
| 62 should_reset_mouse_flags_(false), | 31 should_reset_mouse_flags_(false), |
| 63 grab_input_window_(None), | |
| 64 canceled_(false), | 32 canceled_(false), |
| 65 weak_factory_(this) { | 33 weak_factory_(this) { |
| 66 last_xmotion_.type = LASTEvent; | 34 last_xmotion_.type = LASTEvent; |
| 67 } | 35 } |
| 68 | 36 |
| 69 X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {} | 37 X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {} |
| 70 | 38 |
| 71 void X11WholeScreenMoveLoop::DispatchMouseMovement() { | 39 void X11WholeScreenMoveLoop::DispatchMouseMovement() { |
| 72 if (!weak_factory_.HasWeakPtrs()) | 40 if (!weak_factory_.HasWeakPtrs()) |
| 73 return; | 41 return; |
| 74 weak_factory_.InvalidateWeakPtrs(); | 42 weak_factory_.InvalidateWeakPtrs(); |
| 75 DCHECK_EQ(MotionNotify, last_xmotion_.type); | 43 DCHECK_EQ(MotionNotify, last_xmotion_.type); |
| 76 delegate_->OnMouseMovement(&last_xmotion_); | 44 delegate_->OnMouseMovement(&last_xmotion_); |
| 77 last_xmotion_.type = LASTEvent; | 45 last_xmotion_.type = LASTEvent; |
| 78 } | 46 } |
| 79 | 47 |
| 80 //////////////////////////////////////////////////////////////////////////////// | 48 //////////////////////////////////////////////////////////////////////////////// |
| 81 // DesktopWindowTreeHostLinux, ui::PlatformEventDispatcher implementation: | 49 // DesktopWindowTreeHostLinux, ui::PlatformEventDispatcher implementation: |
| 82 | 50 |
| 83 bool X11WholeScreenMoveLoop::CanDispatchEvent(const ui::PlatformEvent& event) { | 51 bool X11WholeScreenMoveLoop::CanDispatchEvent(const ui::PlatformEvent& event) { |
| 84 return in_move_loop_; | 52 NOTREACHED(); |
| 53 return true; | |
| 85 } | 54 } |
| 86 | 55 |
| 87 uint32_t X11WholeScreenMoveLoop::DispatchEvent(const ui::PlatformEvent& event) { | 56 uint32_t X11WholeScreenMoveLoop::DispatchEvent(const ui::PlatformEvent& event) { |
| 88 // This method processes all events for the grab_input_window_ as well as | 57 // This method processes all mouse events for all windows while the move loop |
| 89 // mouse events for all windows while the move loop is active - even before | 58 // is active. |
| 90 // the grab is granted by X. This allows mouse notification events that were | |
| 91 // sent after the capture was requested but before the capture was granted | |
| 92 // to be dispatched. It is especially important to process the mouse release | |
| 93 // event that should have stopped the drag even if that mouse release happened | |
| 94 // before the grab was granted. | |
| 95 if (!in_move_loop_) | 59 if (!in_move_loop_) |
| 96 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 60 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 97 XEvent* xev = event; | 61 XEvent* xev = event; |
| 98 | 62 |
| 99 // Note: the escape key is handled in the tab drag controller, which has | 63 // Note: the escape key is handled in the tab drag controller, which has |
| 100 // keyboard focus even though we took pointer grab. | 64 // keyboard focus even though we took pointer grab. |
| 101 switch (xev->type) { | 65 switch (xev->type) { |
| 102 case MotionNotify: { | 66 case MotionNotify: { |
| 103 if (drag_widget_.get()) { | |
| 104 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | |
| 105 gfx::Point location = gfx::ToFlooredPoint( | |
| 106 screen->GetCursorScreenPoint() - drag_offset_); | |
| 107 drag_widget_->SetBounds(gfx::Rect(location, drag_image_.size())); | |
| 108 drag_widget_->StackAtTop(); | |
| 109 } | |
| 110 last_xmotion_ = xev->xmotion; | 67 last_xmotion_ = xev->xmotion; |
| 111 if (!weak_factory_.HasWeakPtrs()) { | 68 if (!weak_factory_.HasWeakPtrs()) { |
| 112 // Post a task to dispatch mouse movement event when control returns to | 69 // Post a task to dispatch mouse movement event when control returns to |
| 113 // the message loop. This allows smoother dragging since the events are | 70 // the message loop. This allows smoother dragging since the events are |
| 114 // dispatched without waiting for the drag widget updates. | 71 // dispatched without waiting for the drag widget updates. |
| 115 base::MessageLoopForUI::current()->PostTask( | 72 base::MessageLoopForUI::current()->PostTask( |
| 116 FROM_HERE, | 73 FROM_HERE, |
| 117 base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement, | 74 base::Bind(&X11WholeScreenMoveLoop::DispatchMouseMovement, |
| 118 weak_factory_.GetWeakPtr())); | 75 weak_factory_.GetWeakPtr())); |
| 119 } | 76 } |
| 120 return ui::POST_DISPATCH_NONE; | 77 return ui::POST_DISPATCH_NONE; |
| 121 } | 78 } |
| 122 case ButtonRelease: { | 79 case ButtonRelease: { |
| 123 if (xev->xbutton.button == Button1) { | 80 if (xev->xbutton.button == Button1) { |
| 124 // Assume that drags are being done with the left mouse button. Only | 81 // Assume that drags are being done with the left mouse button. Only |
| 125 // break the drag if the left mouse button was released. | 82 // break the drag if the left mouse button was released. |
| 126 DispatchMouseMovement(); | 83 DispatchMouseMovement(); |
| 127 delegate_->OnMouseReleased(); | 84 delegate_->OnMouseReleased(); |
| 128 } | 85 } |
| 129 return ui::POST_DISPATCH_NONE; | 86 // default dispatch will release capture in Widget::OnMouseEvent(). |
|
sadrul
2014/05/07 14:18:16
I assume you mean the dispatcher for the browser e
varkha
2014/05/07 19:54:28
Hopefully this is a bit clearer. We get here re-en
| |
| 87 break; | |
| 130 } | 88 } |
| 131 case KeyPress: { | 89 case KeyPress: { |
| 132 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) { | 90 if (ui::KeyboardCodeFromXKeyEvent(xev) == ui::VKEY_ESCAPE) { |
| 133 canceled_ = true; | 91 canceled_ = true; |
| 134 EndMoveLoop(); | 92 EndMoveLoop(); |
| 135 return ui::POST_DISPATCH_NONE; | 93 return ui::POST_DISPATCH_NONE; |
| 136 } | 94 } |
| 137 break; | 95 break; |
| 138 } | 96 } |
| 139 case GenericEvent: { | 97 case GenericEvent: { |
| 140 ui::EventType type = ui::EventTypeFromNative(xev); | 98 ui::EventType type = ui::EventTypeFromNative(xev); |
| 141 switch (type) { | 99 switch (type) { |
| 142 case ui::ET_MOUSE_MOVED: | 100 case ui::ET_MOUSE_MOVED: |
| 143 case ui::ET_MOUSE_DRAGGED: | 101 case ui::ET_MOUSE_DRAGGED: |
| 144 case ui::ET_MOUSE_RELEASED: { | 102 case ui::ET_MOUSE_RELEASED: { |
| 145 XEvent xevent = {0}; | 103 XEvent xevent = {0}; |
| 146 if (type == ui::ET_MOUSE_RELEASED) { | 104 if (type == ui::ET_MOUSE_RELEASED) { |
| 147 xevent.type = ButtonRelease; | 105 xevent.type = ButtonRelease; |
| 148 xevent.xbutton.button = ui::EventButtonFromNative(xev); | 106 xevent.xbutton.button = ui::EventButtonFromNative(xev); |
| 149 } else { | 107 } else { |
| 150 xevent.type = MotionNotify; | 108 xevent.type = MotionNotify; |
| 151 } | 109 } |
| 152 xevent.xany.display = xev->xgeneric.display; | 110 xevent.xany.display = xev->xgeneric.display; |
| 153 xevent.xany.window = grab_input_window_; | 111 XIDeviceEvent* xievent = |
| 112 static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
| 113 xevent.xany.window = xievent->event; | |
| 154 // The fields used below are in the same place for all of events | 114 // The fields used below are in the same place for all of events |
| 155 // above. Using xmotion from XEvent's unions to avoid repeating | 115 // above. Using xmotion from XEvent's unions to avoid repeating |
| 156 // the code. | 116 // the code. |
| 157 xevent.xmotion.root = DefaultRootWindow(xev->xgeneric.display); | 117 xevent.xmotion.root = DefaultRootWindow(xev->xgeneric.display); |
| 158 xevent.xmotion.time = ui::EventTimeFromNative(xev).InMilliseconds(); | 118 xevent.xmotion.time = ui::EventTimeFromNative(xev).InMilliseconds(); |
| 159 gfx::Point point(ui::EventSystemLocationFromNative(xev)); | 119 gfx::Point point(ui::EventSystemLocationFromNative(xev)); |
| 160 xevent.xmotion.x_root = point.x(); | 120 xevent.xmotion.x_root = point.x(); |
| 161 xevent.xmotion.y_root = point.y(); | 121 xevent.xmotion.y_root = point.y(); |
| 162 DispatchEvent(&xevent); | 122 return DispatchEvent(&xevent); |
| 163 return ui::POST_DISPATCH_NONE; | |
| 164 } | 123 } |
| 165 default: | 124 default: |
| 166 break; | 125 break; |
| 167 } | 126 } |
| 168 } | 127 } |
| 169 } | 128 } |
| 170 | 129 |
| 171 return (event->xany.window == grab_input_window_) ? | 130 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 172 ui::POST_DISPATCH_NONE : ui::POST_DISPATCH_PERFORM_DEFAULT; | |
| 173 } | 131 } |
| 174 | 132 |
| 175 bool X11WholeScreenMoveLoop::RunMoveLoop(aura::Window* source, | 133 bool X11WholeScreenMoveLoop::RunMoveLoop(gfx::NativeCursor cursor) { |
| 176 gfx::NativeCursor cursor) { | |
| 177 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. | 134 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. |
| 178 | 135 |
| 179 // Start a capture on the host, so that it continues to receive events during | |
| 180 // the drag. This may be second time we are capturing the mouse events - the | |
| 181 // first being when a mouse is first pressed. That first capture needs to be | |
| 182 // released before the call to GrabPointerAndKeyboard below, otherwise it may | |
| 183 // get released while we still need the pointer grab, which is why we restrict | |
| 184 // the scope here. | |
| 185 { | |
| 186 ScopedCapturer capturer(source->GetHost()); | |
| 187 | |
| 188 grab_input_window_ = CreateDragInputWindow(gfx::GetXDisplay()); | |
| 189 // Releasing ScopedCapturer ensures that any other instance of | |
| 190 // X11ScopedCapture will not prematurely release grab that will be acquired | |
| 191 // below. | |
| 192 } | |
| 193 // TODO(varkha): Consider integrating GrabPointerAndKeyboard with | |
| 194 // ScopedCapturer to avoid possibility of logically keeping multiple grabs. | |
| 195 if (!GrabPointerAndKeyboard(cursor)) { | |
| 196 XDestroyWindow(gfx::GetXDisplay(), grab_input_window_); | |
| 197 return false; | |
| 198 } | |
| 199 | |
| 200 scoped_ptr<ui::ScopedEventDispatcher> old_dispatcher = | 136 scoped_ptr<ui::ScopedEventDispatcher> old_dispatcher = |
| 201 nested_dispatcher_.Pass(); | 137 nested_dispatcher_.Pass(); |
| 202 nested_dispatcher_ = | 138 nested_dispatcher_ = |
| 203 ui::PlatformEventSource::GetInstance()->OverrideDispatcher(this); | 139 ui::PlatformEventSource::GetInstance()->OverrideDispatcher(this); |
| 204 if (!drag_image_.isNull() && CheckIfIconValid()) | |
| 205 CreateDragImageWindow(); | |
| 206 | 140 |
| 207 // We are handling a mouse drag outside of the aura::RootWindow system. We | 141 // We are handling a mouse drag outside of the aura::RootWindow system. We |
| 208 // must manually make aura think that the mouse button is pressed so that we | 142 // must manually make aura think that the mouse button is pressed so that we |
| 209 // don't draw extraneous tooltips. | 143 // don't draw extraneous tooltips. |
| 210 aura::Env* env = aura::Env::GetInstance(); | 144 aura::Env* env = aura::Env::GetInstance(); |
| 211 if (!env->IsMouseButtonDown()) { | 145 if (!env->IsMouseButtonDown()) { |
| 212 env->set_mouse_button_flags(ui::EF_LEFT_MOUSE_BUTTON); | 146 env->set_mouse_button_flags(ui::EF_LEFT_MOUSE_BUTTON); |
| 213 should_reset_mouse_flags_ = true; | 147 should_reset_mouse_flags_ = true; |
| 214 } | 148 } |
| 215 | 149 |
| 216 in_move_loop_ = true; | 150 in_move_loop_ = true; |
| 217 canceled_ = false; | 151 canceled_ = false; |
| 218 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 152 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 219 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); | 153 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
| 220 base::RunLoop run_loop; | 154 base::RunLoop run_loop; |
| 221 quit_closure_ = run_loop.QuitClosure(); | 155 quit_closure_ = run_loop.QuitClosure(); |
| 222 run_loop.Run(); | 156 run_loop.Run(); |
| 223 nested_dispatcher_ = old_dispatcher.Pass(); | 157 nested_dispatcher_ = old_dispatcher.Pass(); |
| 224 return !canceled_; | 158 return !canceled_; |
| 225 } | 159 } |
| 226 | 160 |
| 227 void X11WholeScreenMoveLoop::UpdateCursor(gfx::NativeCursor cursor) { | |
| 228 if (in_move_loop_) { | |
| 229 // If we're still in the move loop, regrab the pointer with the updated | |
| 230 // cursor. Note: we can be called from handling an XdndStatus message after | |
| 231 // EndMoveLoop() was called, but before we return from the nested RunLoop. | |
| 232 GrabPointerAndKeyboard(cursor); | |
| 233 } | |
| 234 } | |
| 235 | |
| 236 void X11WholeScreenMoveLoop::EndMoveLoop() { | 161 void X11WholeScreenMoveLoop::EndMoveLoop() { |
| 237 if (!in_move_loop_) | 162 if (!in_move_loop_) |
| 238 return; | 163 return; |
| 239 | 164 |
| 240 // Prevent DispatchMouseMovement from dispatching any posted motion event. | 165 // Prevent DispatchMouseMovement from dispatching any posted motion event. |
| 241 weak_factory_.InvalidateWeakPtrs(); | 166 weak_factory_.InvalidateWeakPtrs(); |
| 242 last_xmotion_.type = LASTEvent; | 167 last_xmotion_.type = LASTEvent; |
| 243 | 168 |
| 244 // We undo our emulated mouse click from RunMoveLoop(); | 169 // We undo our emulated mouse click from RunMoveLoop(); |
| 245 if (should_reset_mouse_flags_) { | 170 if (should_reset_mouse_flags_) { |
| 246 aura::Env::GetInstance()->set_mouse_button_flags(0); | 171 aura::Env::GetInstance()->set_mouse_button_flags(0); |
| 247 should_reset_mouse_flags_ = false; | 172 should_reset_mouse_flags_ = false; |
| 248 } | 173 } |
| 249 | 174 |
| 250 // TODO(erg): Is this ungrab the cause of having to click to give input focus | |
| 251 // on drawn out windows? Not ungrabbing here screws the X server until I kill | |
| 252 // the chrome process. | |
| 253 | |
| 254 // Ungrab before we let go of the window. | |
| 255 XDisplay* display = gfx::GetXDisplay(); | |
| 256 XUngrabPointer(display, CurrentTime); | |
| 257 XUngrabKeyboard(display, CurrentTime); | |
| 258 | |
| 259 // Restore the previous dispatcher. | 175 // Restore the previous dispatcher. |
| 260 nested_dispatcher_.reset(); | 176 nested_dispatcher_.reset(); |
| 261 drag_widget_.reset(); | |
| 262 delegate_->OnMoveLoopEnded(); | 177 delegate_->OnMoveLoopEnded(); |
| 263 XDestroyWindow(display, grab_input_window_); | |
| 264 grab_input_window_ = None; | |
| 265 | 178 |
| 266 in_move_loop_ = false; | 179 in_move_loop_ = false; |
| 267 quit_closure_.Run(); | 180 quit_closure_.Run(); |
| 268 } | 181 } |
| 269 | 182 |
| 270 void X11WholeScreenMoveLoop::SetDragImage(const gfx::ImageSkia& image, | |
| 271 gfx::Vector2dF offset) { | |
| 272 drag_image_ = image; | |
| 273 drag_offset_ = offset; | |
| 274 // Reset the Y offset, so that the drag-image is always just below the cursor, | |
| 275 // so that it is possible to see where the cursor is going. | |
| 276 drag_offset_.set_y(0.f); | |
| 277 } | |
| 278 | |
| 279 bool X11WholeScreenMoveLoop::GrabPointerAndKeyboard(gfx::NativeCursor cursor) { | |
| 280 XDisplay* display = gfx::GetXDisplay(); | |
| 281 XGrabServer(display); | |
| 282 | |
| 283 XUngrabPointer(display, CurrentTime); | |
| 284 int ret = XGrabPointer( | |
| 285 display, | |
| 286 grab_input_window_, | |
| 287 False, | |
| 288 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, | |
| 289 GrabModeAsync, | |
| 290 GrabModeAsync, | |
| 291 None, | |
| 292 cursor.platform(), | |
| 293 CurrentTime); | |
| 294 if (ret != GrabSuccess) { | |
| 295 DLOG(ERROR) << "Grabbing pointer for dragging failed: " | |
| 296 << ui::GetX11ErrorString(display, ret); | |
| 297 } else { | |
| 298 XUngrabKeyboard(display, CurrentTime); | |
| 299 ret = XGrabKeyboard( | |
| 300 display, | |
| 301 grab_input_window_, | |
| 302 False, | |
| 303 GrabModeAsync, | |
| 304 GrabModeAsync, | |
| 305 CurrentTime); | |
| 306 if (ret != GrabSuccess) { | |
| 307 DLOG(ERROR) << "Grabbing keyboard for dragging failed: " | |
| 308 << ui::GetX11ErrorString(display, ret); | |
| 309 } | |
| 310 } | |
| 311 | |
| 312 XUngrabServer(display); | |
| 313 XFlush(display); | |
| 314 return ret == GrabSuccess; | |
| 315 } | |
| 316 | |
| 317 Window X11WholeScreenMoveLoop::CreateDragInputWindow(XDisplay* display) { | |
| 318 // Creates an invisible, InputOnly toplevel window. This window will receive | |
| 319 // all mouse movement for drags. It turns out that normal windows doing a | |
| 320 // grab doesn't redirect pointer motion events if the pointer isn't over the | |
| 321 // grabbing window. But InputOnly windows are able to grab everything. This | |
| 322 // is what GTK+ does, and I found a patch to KDE that did something similar. | |
| 323 unsigned long attribute_mask = CWEventMask | CWOverrideRedirect; | |
| 324 XSetWindowAttributes swa; | |
| 325 memset(&swa, 0, sizeof(swa)); | |
| 326 swa.event_mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | | |
| 327 KeyPressMask | KeyReleaseMask | StructureNotifyMask; | |
| 328 swa.override_redirect = True; | |
| 329 Window window = XCreateWindow(display, | |
| 330 DefaultRootWindow(display), | |
| 331 -100, -100, 10, 10, | |
| 332 0, CopyFromParent, InputOnly, CopyFromParent, | |
| 333 attribute_mask, &swa); | |
| 334 XMapRaised(display, window); | |
| 335 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(window); | |
| 336 return window; | |
| 337 } | |
| 338 | |
| 339 void X11WholeScreenMoveLoop::CreateDragImageWindow() { | |
| 340 Widget* widget = new Widget; | |
| 341 Widget::InitParams params(Widget::InitParams::TYPE_DRAG); | |
| 342 params.opacity = Widget::InitParams::OPAQUE_WINDOW; | |
| 343 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 344 params.accept_events = false; | |
| 345 | |
| 346 gfx::Point location = gfx::ToFlooredPoint( | |
| 347 gfx::Screen::GetNativeScreen()->GetCursorScreenPoint() - drag_offset_); | |
| 348 params.bounds = gfx::Rect(location, drag_image_.size()); | |
| 349 widget->set_focus_on_creation(false); | |
| 350 widget->set_frame_type(Widget::FRAME_TYPE_FORCE_NATIVE); | |
| 351 widget->Init(params); | |
| 352 widget->SetOpacity(kDragWidgetOpacity); | |
| 353 widget->GetNativeWindow()->SetName("DragWindow"); | |
| 354 | |
| 355 ImageView* image = new ImageView(); | |
| 356 image->SetImage(drag_image_); | |
| 357 image->SetBounds(0, 0, drag_image_.width(), drag_image_.height()); | |
| 358 widget->SetContentsView(image); | |
| 359 widget->Show(); | |
| 360 widget->GetNativeWindow()->layer()->SetFillsBoundsOpaquely(false); | |
| 361 | |
| 362 drag_widget_.reset(widget); | |
| 363 } | |
| 364 | |
| 365 bool X11WholeScreenMoveLoop::CheckIfIconValid() { | |
| 366 // Because we need a GL context per window, we do a quick check so that we | |
| 367 // don't make another context if the window would just be displaying a mostly | |
| 368 // transparent image. | |
| 369 const SkBitmap* in_bitmap = drag_image_.bitmap(); | |
| 370 SkAutoLockPixels in_lock(*in_bitmap); | |
| 371 for (int y = 0; y < in_bitmap->height(); ++y) { | |
| 372 uint32* in_row = in_bitmap->getAddr32(0, y); | |
| 373 | |
| 374 for (int x = 0; x < in_bitmap->width(); ++x) { | |
| 375 if (SkColorGetA(in_row[x]) > kMinAlpha) | |
| 376 return true; | |
| 377 } | |
| 378 } | |
| 379 | |
| 380 return false; | |
| 381 } | |
| 382 | |
| 383 } // namespace views | 183 } // namespace views |
| OLD | NEW |