Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Unified Diff: ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc

Issue 262893002: Removes grab input window and extra grab and ungrab in X11WholeScreenMoveLoop Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removes grab input window and extra grab and ungrab in X11WholeScreenMoveLoop (no more changes in T… Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 d3e52f787192b6ec1a11eebd26d7e8843e204637..531718207b0c9a54287c03d7ad6f5154552531a2 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,11 @@ 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;
+
const int kMinXdndVersion = 5;
const int kWillAcceptDrop = 1;
@@ -80,6 +88,25 @@ static base::LazyInstance<
std::map< ::Window, views::DesktopDragDropClientAuraX11*> >::Leaky
g_live_client_map = LAZY_INSTANCE_INITIALIZER;
+// Checks to see if |drag_image| is an image that has any visible regions
+// (defined as having a pixel with alpha > 32). If so, returns true.
+bool CheckIfIconValid(const gfx::ImageSkia& drag_image) {
+ // Because we need a GL context per window, we do a quick check 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;
+}
+
} // namespace
namespace views {
@@ -363,6 +390,7 @@ DesktopDragDropClientAuraX11::DesktopDragDropClientAuraX11(
grab_cursor_(cursor_manager->GetInitializedCursor(ui::kCursorGrabbing)),
copy_grab_cursor_(cursor_manager->GetInitializedCursor(ui::kCursorCopy)),
move_grab_cursor_(cursor_manager->GetInitializedCursor(ui::kCursorMove)),
+ null_drag_widget_bounds_(-100, -100, 1, 1),
weak_ptr_factory_(this) {
// Some tests change the DesktopDragDropClientAuraX11 associated with an
// |xwindow|.
@@ -477,17 +505,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
@@ -610,15 +628,21 @@ int DesktopDragDropClientAuraX11::StartDragAndDrop(
base::WeakPtr<DesktopDragDropClientAuraX11> alive(
weak_ptr_factory_.GetWeakPtr());
+ SetDragImage(source_provider_->GetDragImage(),
+ source_provider_->GetDragImageOffset());
+ CreateDragImageWindow();
+ // Capture drag widget to continue receiving events even if the drag source
+ // gets destroyed during the drag such as when we drag an item out of a menu
+ // and the menu closes.
+ drag_widget_->GetNativeWindow()->SetCapture();
+
// 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.
- move_loop_.SetDragImage(source_provider_->GetDragImage(),
- source_provider_->GetDragImageOffset());
- move_loop_.RunMoveLoop(source_window, grab_cursor_);
+ move_loop_.RunMoveLoop();
if (alive) {
- move_loop_.SetDragImage(gfx::ImageSkia(), gfx::Vector2dF());
+ SetDragImage(gfx::ImageSkia(), gfx::Vector2dF());
source_provider_ = NULL;
g_current_drag_drop_client = NULL;
@@ -702,6 +726,7 @@ void DesktopDragDropClientAuraX11::OnMouseReleased() {
}
void DesktopDragDropClientAuraX11::OnMoveLoopEnded() {
+ drag_widget_.reset();
if (source_current_window_ != None) {
SendXdndLeave(source_current_window_);
source_current_window_ = None;
@@ -779,6 +804,17 @@ void DesktopDragDropClientAuraX11::ProcessMouseMove(
if (source_state_ != SOURCE_STATE_OTHER)
return;
+ if (drag_widget_.get()) {
+ if (drag_image_.isNull()) {
+ drag_widget_->SetBounds(null_drag_widget_bounds_);
+ } else {
+ drag_widget_->SetBounds(gfx::Rect(
+ gfx::ToFlooredPoint(screen_point - drag_offset_),
+ drag_image_.size()));
+ }
+ drag_widget_->StackAtTop();
+ }
+
// Find the current window the cursor is over.
::Window dest_window = FindWindowFor(screen_point);
@@ -911,6 +947,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 new cursor if a grab is active.
+ XChangeActivePointerGrab(
+ xdisplay_,
+ ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
+ cursor.platform(),
+ CurrentTime);
+}
+
void DesktopDragDropClientAuraX11::CompleteXdndPosition(
::Window source_window,
const gfx::Point& screen_point) {
@@ -1028,4 +1085,53 @@ void DesktopDragDropClientAuraX11::SendXdndDrop(::Window dest_window) {
SendXClientEvent(dest_window, &xev);
}
+void DesktopDragDropClientAuraX11::SetDragImage(const gfx::ImageSkia& image,
+ const 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::TRANSLUCENT_WINDOW;
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ params.accept_events = false;
+
+ if (!drag_image_.isNull() && !CheckIfIconValid(drag_image_)) {
+ // Show drag widget off screen if the image is mostly transparent.
+ drag_image_ = gfx::ImageSkia();
+ drag_offset_ = gfx::Vector2dF();
+ }
+
+ if (drag_image_.isNull()) {
+ params.bounds = null_drag_widget_bounds_;
+ } else {
+ params.bounds = gfx::Rect(
+ gfx::ToFlooredPoint(
+ gfx::Screen::GetNativeScreen()->GetCursorScreenPoint() -
+ drag_offset_),
+ 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");
+
+ if (!drag_image_.isNull()) {
+ 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);
+ drag_widget_.reset(widget);
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698