Index: ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc |
diff --git a/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc b/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc |
index 4771962cfcf92aa00594488a497d59914b3f93ac..c32cf0f81dad9c6e2007e740f4e54a18a9b70cc8 100644 |
--- a/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc |
+++ b/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc |
@@ -19,8 +19,11 @@ |
#include "ui/base/x/x11_util.h" |
#include "ui/events/event.h" |
#include "ui/events/platform/platform_event_source.h" |
+#include "ui/gfx/screen.h" |
+#include "ui/views/controls/image_view.h" |
#include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
#include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" |
+#include "ui/views/widget/widget.h" |
#include "ui/wm/public/drag_drop_client.h" |
#include "ui/wm/public/drag_drop_delegate.h" |
@@ -29,6 +32,29 @@ using ui::OSExchangeData; |
namespace { |
+// The minimum alpha before we declare a pixel transparent when searching in |
+// our source image. |
+const uint32 kMinAlpha = 32; |
+const unsigned char kDragWidgetOpacity = 0xc0; |
+ |
+bool CheckIfIconValid(const gfx::ImageSkia& drag_image) { |
+ // Because we need a GL context per window, we do a quick check so that we |
+ // don't make another context if the window would just be displaying a mostly |
+ // transparent image. |
+ const SkBitmap* in_bitmap = drag_image.bitmap(); |
+ SkAutoLockPixels in_lock(*in_bitmap); |
+ for (int y = 0; y < in_bitmap->height(); ++y) { |
+ uint32* in_row = in_bitmap->getAddr32(0, y); |
+ |
+ for (int x = 0; x < in_bitmap->width(); ++x) { |
+ if (SkColorGetA(in_row[x]) > kMinAlpha) |
+ return true; |
+ } |
+ } |
+ |
+ return false; |
+} |
+ |
const int kMinXdndVersion = 5; |
const int kWillAcceptDrop = 1; |
@@ -497,17 +523,7 @@ void DesktopDragDropClientAuraX11::OnXdndStatus( |
return; |
} |
- switch (negotiated_operation_) { |
- case ui::DragDropTypes::DRAG_COPY: |
- move_loop_.UpdateCursor(copy_grab_cursor_); |
- break; |
- case ui::DragDropTypes::DRAG_MOVE: |
- move_loop_.UpdateCursor(move_grab_cursor_); |
- break; |
- default: |
- move_loop_.UpdateCursor(grab_cursor_); |
- break; |
- } |
+ UpdateCursor(); |
// Note: event.data.[2,3] specify a rectangle. It is a request by the other |
// window to not send further XdndPosition messages while the cursor is |
@@ -625,12 +641,14 @@ int DesktopDragDropClientAuraX11::StartDragAndDrop( |
// Windows has a specific method, DoDragDrop(), which performs the entire |
// drag. We have to emulate this, so we spin off a nested runloop which will |
// track all cursor movement and reroute events to a specific handler. |
pkotwicz
2014/05/08 00:03:49
Nits:
- The comment above should be right above th
varkha
2014/05/09 19:01:01
Done.
|
- move_loop_.SetDragImage(source_provider_->GetDragImage(), |
- source_provider_->GetDragImageOffset()); |
- move_loop_.RunMoveLoop(source_window, grab_cursor_); |
+ SetDragImage(source_provider_->GetDragImage(), |
+ source_provider_->GetDragImageOffset()); |
+ if (!drag_image_.isNull() && CheckIfIconValid(drag_image_)) |
+ CreateDragImageWindow(); |
pkotwicz
2014/05/08 00:03:49
We may need to move |grab_input_window_| to this c
varkha
2014/05/09 19:01:01
We talked about this offline. I've set up the drag
|
+ move_loop_.RunMoveLoop(grab_cursor_); |
if (alive) { |
- move_loop_.SetDragImage(gfx::ImageSkia(), gfx::Vector2dF()); |
+ SetDragImage(gfx::ImageSkia(), gfx::Vector2dF()); |
source_provider_ = NULL; |
g_current_drag_drop_client = NULL; |
@@ -672,6 +690,12 @@ void DesktopDragDropClientAuraX11::OnMouseMovement(XMotionEvent* event) { |
if (source_state_ != SOURCE_STATE_OTHER) |
return; |
+ if (drag_widget_.get()) { |
+ gfx::Point location = gfx::ToFlooredPoint(screen_point - drag_offset_); |
+ drag_widget_->SetBounds(gfx::Rect(location, drag_image_.size())); |
+ drag_widget_->StackAtTop(); |
+ } |
+ |
// Find the current window the cursor is over. |
::Window mouse_window = None; |
::Window dest_window = None; |
@@ -736,6 +760,7 @@ void DesktopDragDropClientAuraX11::OnMouseReleased() { |
} |
void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { |
+ drag_widget_.reset(); |
if (source_current_window_ != None) { |
SendXdndLeave(source_current_window_); |
source_current_window_ = None; |
@@ -849,6 +874,27 @@ ui::SelectionFormatMap DesktopDragDropClientAuraX11::GetFormatMap() const { |
ui::SelectionFormatMap(); |
} |
+void DesktopDragDropClientAuraX11::UpdateCursor() { |
+ gfx::NativeCursor cursor = grab_cursor_; |
+ switch (negotiated_operation_) { |
+ case ui::DragDropTypes::DRAG_COPY: |
+ cursor = copy_grab_cursor_; |
+ break; |
+ case ui::DragDropTypes::DRAG_MOVE: |
+ cursor = move_grab_cursor_; |
+ break; |
+ default: |
+ break; |
+ } |
+ |
+ // Update the pointer with the updated cursor if a grab is active. |
pkotwicz
2014/05/08 00:03:49
Nit: updated -> new
varkha
2014/05/09 19:01:01
Done.
|
+ XChangeActivePointerGrab( |
+ xdisplay_, |
+ ButtonPressMask | ButtonReleaseMask | PointerMotionMask, |
+ cursor.platform(), |
+ CurrentTime); |
+} |
+ |
void DesktopDragDropClientAuraX11::CompleteXdndPosition( |
::Window source_window, |
const gfx::Point& screen_point) { |
@@ -996,4 +1042,39 @@ void DesktopDragDropClientAuraX11::SendXClientEvent(::Window xid, |
XSendEvent(xdisplay_, xid, False, 0, xev); |
} |
+void DesktopDragDropClientAuraX11::SetDragImage(const gfx::ImageSkia& image, |
+ gfx::Vector2dF offset) { |
+ drag_image_ = image; |
+ drag_offset_ = offset; |
+ // Reset the Y offset, so that the drag-image is always just below the cursor, |
+ // so that it is possible to see where the cursor is going. |
+ drag_offset_.set_y(0.f); |
+} |
+ |
+void DesktopDragDropClientAuraX11::CreateDragImageWindow() { |
+ Widget* widget = new Widget; |
+ Widget::InitParams params(Widget::InitParams::TYPE_DRAG); |
+ params.opacity = Widget::InitParams::OPAQUE_WINDOW; |
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
+ params.accept_events = false; |
+ |
+ gfx::Point location = gfx::ToFlooredPoint( |
+ gfx::Screen::GetNativeScreen()->GetCursorScreenPoint() - drag_offset_); |
+ params.bounds = gfx::Rect(location, drag_image_.size()); |
+ widget->set_focus_on_creation(false); |
+ widget->set_frame_type(Widget::FRAME_TYPE_FORCE_NATIVE); |
+ widget->Init(params); |
+ widget->SetOpacity(kDragWidgetOpacity); |
+ widget->GetNativeWindow()->SetName("DragWindow"); |
+ |
+ ImageView* image = new ImageView(); |
+ image->SetImage(drag_image_); |
+ image->SetBounds(0, 0, drag_image_.width(), drag_image_.height()); |
+ widget->SetContentsView(image); |
+ widget->Show(); |
+ widget->GetNativeWindow()->layer()->SetFillsBoundsOpaquely(false); |
+ widget->GetNativeWindow()->SetCapture(); |
+ drag_widget_.reset(widget); |
+} |
+ |
} // namespace views |