diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-06-18 14:10:49 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2015-06-18 13:53:24 +0000 |
commit | 813fbf95af77a531c57a8c497345ad2c61d475b3 (patch) | |
tree | 821b2c8de8365f21b6c9ba17a236fb3006a1d506 /chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc | |
parent | af6588f8d723931a298c995fa97259bb7f7deb55 (diff) | |
download | qtwebengine-chromium-813fbf95af77a531c57a8c497345ad2c61d475b3.tar.gz |
BASELINE: Update chromium to 44.0.2403.47
Change-Id: Ie056fedba95cf5e5c76b30c4b2c80fca4764aa2f
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc')
-rw-r--r-- | chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc | 140 |
1 files changed, 109 insertions, 31 deletions
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc index 64433279ad5..5a76cbf7a46 100644 --- a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc +++ b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc @@ -9,6 +9,7 @@ #include "base/event_types.h" #include "base/lazy_instance.h" #include "base/message_loop/message_loop.h" +#include "base/metrics/histogram_macros.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/aura/client/capture_client.h" #include "ui/aura/window.h" @@ -21,6 +22,7 @@ #include "ui/base/x/x11_foreign_window_manager.h" #include "ui/base/x/x11_util.h" #include "ui/events/event.h" +#include "ui/events/event_utils.h" #include "ui/events/platform/platform_event_source.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/screen.h" @@ -75,6 +77,39 @@ const char* kAtomsToCache[] = { NULL }; +int XGetModifiers() { + XDisplay* display = gfx::GetXDisplay(); + + XID root, child; + int root_x, root_y, win_x, win_y; + unsigned int mask; + XQueryPointer(display, + DefaultRootWindow(display), + &root, + &child, + &root_x, + &root_y, + &win_x, + &win_y, + &mask); + int modifiers = ui::EF_NONE; + if (mask & ShiftMask) + modifiers |= ui::EF_SHIFT_DOWN; + if (mask & ControlMask) + modifiers |= ui::EF_CONTROL_DOWN; + if (mask & Mod1Mask) + modifiers |= ui::EF_ALT_DOWN; + if (mask & Mod4Mask) + modifiers |= ui::EF_COMMAND_DOWN; + if (mask & Button1Mask) + modifiers |= ui::EF_LEFT_MOUSE_BUTTON; + if (mask & Button2Mask) + modifiers |= ui::EF_MIDDLE_MOUSE_BUTTON; + if (mask & Button3Mask) + modifiers |= ui::EF_RIGHT_MOUSE_BUTTON; + return modifiers; +} + // The time to wait for the target to respond after the user has released the // mouse button before ending the move loop. const int kEndMoveLoopTimeoutMs = 1000; @@ -138,6 +173,8 @@ class DesktopDragDropClientAuraX11::X11DragContext // action list. int GetDragOperation() const; + DesktopDragDropClientAuraX11* source_client() { return source_client_; } + private: // Masks the X11 atom |xdnd_operation|'s views representation onto // |drag_operation|. @@ -204,24 +241,24 @@ DesktopDragDropClientAuraX11::X11DragContext::X11DragContext( drag_drop_client_(NULL), waiting_to_handle_position_(false), suggested_action_(None) { - bool get_types = ((event.data.l[1] & 1) != 0); + if (!source_client_) { + bool get_types = ((event.data.l[1] & 1) != 0); - if (get_types) { - if (!ui::GetAtomArrayProperty(source_window_, - "XdndTypeList", - &unfetched_targets_)) { - return; - } - } else { - // data.l[2,3,4] contain the first three types. Unused slots can be None. - for (int i = 0; i < 3; ++i) { - if (event.data.l[2+i] != None) { - unfetched_targets_.push_back(event.data.l[2+i]); + if (get_types) { + if (!ui::GetAtomArrayProperty(source_window_, + "XdndTypeList", + &unfetched_targets_)) { + return; + } + } else { + // data.l[2,3,4] contain the first three types. Unused slots can be None. + for (int i = 0; i < 3; ++i) { + if (event.data.l[2+i] != None) { + unfetched_targets_.push_back(event.data.l[2+i]); + } } } - } - if (!source_client_) { // The window doesn't have a DesktopDragDropClientAuraX11, that means it's // created by some other process. Listen for messages on it. ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); @@ -237,7 +274,6 @@ DesktopDragDropClientAuraX11::X11DragContext::X11DragContext( // that we can shortcut the X11 server and ask the owning SelectionOwner // for the data it's offering. fetched_targets_ = source_client_->GetFormatMap(); - unfetched_targets_.clear(); } ReadActions(); @@ -376,9 +412,11 @@ DesktopDragDropClientAuraX11::DesktopDragDropClientAuraX11( Display* xdisplay, ::Window xwindow) : root_window_(root_window), + cursor_manager_(cursor_manager), xdisplay_(xdisplay), xwindow_(xwindow), atom_cache_(xdisplay_, kAtomsToCache), + current_modifier_state_(ui::EF_NONE), target_window_(NULL), waiting_on_status_(false), status_received_since_enter_(false), @@ -387,9 +425,6 @@ DesktopDragDropClientAuraX11::DesktopDragDropClientAuraX11( source_state_(SOURCE_STATE_OTHER), drag_operation_(0), negotiated_operation_(ui::DragDropTypes::DRAG_NONE), - grab_cursor_(cursor_manager->GetInitializedCursor(ui::kCursorGrabbing)), - copy_grab_cursor_(cursor_manager->GetInitializedCursor(ui::kCursorCopy)), - move_grab_cursor_(cursor_manager->GetInitializedCursor(ui::kCursorMove)), weak_ptr_factory_(this) { // Some tests change the DesktopDragDropClientAuraX11 associated with an // |xwindow|. @@ -403,11 +438,12 @@ DesktopDragDropClientAuraX11::DesktopDragDropClientAuraX11( } DesktopDragDropClientAuraX11::~DesktopDragDropClientAuraX11() { - g_live_client_map.Get().erase(xwindow_); - // Make sure that all observers are unregistered from source and target - // windows. This may be necessary when the parent native widget gets destroyed - // while a drag operation is in progress. + // This is necessary when the parent native widget gets destroyed while a drag + // operation is in progress. + move_loop_->EndMoveLoop(); NotifyDragLeave(); + + g_live_client_map.Get().erase(xwindow_); } // static @@ -508,17 +544,19 @@ void DesktopDragDropClientAuraX11::OnXdndStatus( return; } + int cursor_type = ui::kCursorNull; switch (negotiated_operation_) { case ui::DragDropTypes::DRAG_COPY: - move_loop_->UpdateCursor(copy_grab_cursor_); + cursor_type = ui::kCursorCopy; break; case ui::DragDropTypes::DRAG_MOVE: - move_loop_->UpdateCursor(move_grab_cursor_); + cursor_type = ui::kCursorMove; break; default: - move_loop_->UpdateCursor(grab_cursor_); + cursor_type = ui::kCursorGrabbing; break; } + move_loop_->UpdateCursor(cursor_manager_->GetInitializedCursor(cursor_type)); // 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 @@ -572,6 +610,17 @@ void DesktopDragDropClientAuraX11::OnXdndDrop( target_window_location_, target_window_root_location_, target_current_context_->GetDragOperation()); + if (target_current_context_->source_client()) { + event.set_flags(target_current_context_->source_client() + ->current_modifier_state()); + } else { + event.set_flags(XGetModifiers()); + } + + if (!IsDragDropInProgress()) { + UMA_HISTOGRAM_COUNTS("Event.DragDrop.ExternalOriginDrop", 1); + } + drag_operation = delegate->OnPerformDrop(event); } @@ -605,9 +654,12 @@ int DesktopDragDropClientAuraX11::StartDragAndDrop( const ui::OSExchangeData& data, aura::Window* root_window, aura::Window* source_window, - const gfx::Point& root_location, + const gfx::Point& screen_location, int operation, ui::DragDropTypes::DragEventSource source) { + UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Start", source, + ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); + source_current_window_ = None; DCHECK(!g_current_drag_drop_client); g_current_drag_drop_client = this; @@ -656,9 +708,18 @@ 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. - move_loop_->RunMoveLoop(source_window, grab_cursor_); + move_loop_->RunMoveLoop( + source_window, + cursor_manager_->GetInitializedCursor(ui::kCursorGrabbing)); if (alive) { + if (negotiated_operation_ == ui::DragDropTypes::DRAG_NONE) { + UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source, + ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); + } else { + UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Drop", source, + ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); + } drag_widget_.reset(); source_provider_ = NULL; @@ -669,6 +730,8 @@ int DesktopDragDropClientAuraX11::StartDragAndDrop( return negotiated_operation_; } + UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source, + ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); return ui::DragDropTypes::DRAG_NONE; } @@ -695,8 +758,10 @@ void DesktopDragDropClientAuraX11::OnWindowDestroyed(aura::Window* window) { target_window_ = NULL; } -void DesktopDragDropClientAuraX11::OnMouseMovement(XMotionEvent* event) { - gfx::Point screen_point(event->x_root, event->y_root); +void DesktopDragDropClientAuraX11::OnMouseMovement( + const gfx::Point& screen_point, + int flags, + base::TimeDelta event_time) { if (drag_widget_.get()) { drag_widget_->SetBounds( gfx::Rect(screen_point - drag_widget_offset_, @@ -704,8 +769,15 @@ void DesktopDragDropClientAuraX11::OnMouseMovement(XMotionEvent* event) { drag_widget_->StackAtTop(); } + const int kModifiers = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | + ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | + ui::EF_LEFT_MOUSE_BUTTON | + ui::EF_MIDDLE_MOUSE_BUTTON | + ui::EF_RIGHT_MOUSE_BUTTON; + current_modifier_state_ = flags & kModifiers; + repeat_mouse_move_timer_.Stop(); - ProcessMouseMove(screen_point, event->time); + ProcessMouseMove(screen_point, event_time.InMilliseconds()); } void DesktopDragDropClientAuraX11::OnMouseReleased() { @@ -765,7 +837,7 @@ void DesktopDragDropClientAuraX11::OnMoveLoopEnded() { scoped_ptr<X11MoveLoop> DesktopDragDropClientAuraX11::CreateMoveLoop( X11MoveLoopDelegate* delegate) { - return scoped_ptr<X11MoveLoop>(new X11WholeScreenMoveLoop(this)); + return make_scoped_ptr(new X11WholeScreenMoveLoop(this)); } XID DesktopDragDropClientAuraX11::FindWindowFor( @@ -925,6 +997,12 @@ void DesktopDragDropClientAuraX11::DragTranslate( location, root_location, drag_op)); + if (target_current_context_->source_client()) { + (*event)->set_flags( + target_current_context_->source_client()->current_modifier_state()); + } else { + (*event)->set_flags(XGetModifiers()); + } if (target_window_changed) (*delegate)->OnDragEntered(*event->get()); } |