Index: ui/views/mus/drag_drop_client_mus.cc |
diff --git a/ui/views/mus/drag_drop_client_mus.cc b/ui/views/mus/drag_drop_client_mus.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..83bf55251be018f71b5cb0d20d0883ad195c0767 |
--- /dev/null |
+++ b/ui/views/mus/drag_drop_client_mus.cc |
@@ -0,0 +1,111 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/views/mus/drag_drop_client_mus.h" |
+ |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/message_loop/message_loop.h" |
+#include "base/run_loop.h" |
+#include "services/ui/public/cpp/window.h" |
+#include "ui/aura/window.h" |
+#include "ui/views/mus/os_exchange_data_provider_mus.h" |
+ |
+namespace views { |
+namespace { |
+ |
+DragDropClientMus* g_current_dragging_client = nullptr; |
sky
2016/09/23 16:14:08
My understanding from the style guide is that this
|
+ |
+void OnMoveLoopEnd(bool* out_success, |
+ uint32_t* out_action, |
+ base::Closure quit_closure, |
+ bool in_success, |
+ uint32_t in_action) { |
+ *out_success = in_success; |
+ *out_action = in_action; |
+ quit_closure.Run(); |
+} |
+ |
+} // namespace |
+ |
+// TODO(erg): Do we need to observe? |
+ |
+DragDropClientMus::DragDropClientMus( |
+ aura::Window* aura_window, |
+ ui::Window* ui_window) |
+ : aura_window_(aura_window), |
+ ui_window_(ui_window) {} |
+ |
+DragDropClientMus::~DragDropClientMus() {} |
+ |
+int DragDropClientMus::StartDragAndDrop( |
+ const ui::OSExchangeData& data, |
+ aura::Window* root_window, |
+ aura::Window* source_window, |
+ const gfx::Point& screen_location, |
+ int drag_operations, |
+ ui::DragDropTypes::DragEventSource source) { |
+ aura_window_->ReleaseCapture(); |
sky
2016/09/23 16:14:08
Please comment why this is necessary.
Elliot Glaysher
2016/09/23 21:40:48
Deleted; it wasn't necessary anymore now that ther
|
+ |
+ base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
sadrul
2016/09/23 16:22:36
Can this be just MessageLoop? Because mus apps do
Elliot Glaysher
2016/09/23 21:40:48
Done.
|
+ base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
+ base::RunLoop run_loop; |
+ |
+ std::map<std::string, std::vector<uint8_t>> drag_data = |
+ static_cast<const OSExchangeDataProviderMus&>(data.provider()).GetData(); |
+ |
+ // TODO(erg): Right now, I'm passing the cursor_location, but maybe I want to |
+ // pass OSExchangeData::GetDragImageOffset() instead? |
+ |
+ // TODO(erg): We don't have access to the pointer event at this level, and |
+ // we'll have to do work to thread the actual events down to this |
+ // layer. There are two callers to View::DoDrag(), which is the input to this |
+ // code path: |
+ // - view.cc:View::ProcessMouseDragged(), which can translate to Pointer. |
+ // - root_view.cc:PosteEventDispatchHandler::OnGestureEvent() which can't. |
+ // |
+ // Getting the Gesture events translated to PointerEvents so that we can |
+ // thread them to here is going to be...fun. |
+ int32_t drag_pointer = ui::PointerEvent::kMousePointerId; |
Elliot Glaysher
2016/09/22 20:23:20
This is the one final issue with this patch. At th
sadrul
2016/09/23 16:22:36
Does it matter what pointer id you use on the clie
sky
2016/09/23 17:56:27
On the mus side we know we are waiting on a respon
Elliot Glaysher
2016/09/23 21:40:48
At this point, mus will no longer have the event w
sky
2016/09/26 02:12:59
Can you move crating the RunLoop until after calli
Elliot Glaysher
2016/09/26 20:57:29
Done, with a few additional changes. (For example,
|
+ |
+ bool success = false; |
+ gfx::Point cursor_location = screen_location; |
+ uint32_t action_taken = ui::mojom::kDropEffectNone; |
+ g_current_dragging_client = this; |
+ ui_window_->PerformDragDrop( |
+ drag_pointer, drag_data, drag_operations, cursor_location, |
+ *data.provider().GetDragImage().bitmap(), |
+ base::Bind(OnMoveLoopEnd, &success, &action_taken, |
+ run_loop.QuitClosure())); |
+ |
+ run_loop.Run(); |
+ g_current_dragging_client = nullptr; |
+ |
+ return action_taken; |
+} |
+ |
+void DragDropClientMus::DragUpdate(aura::Window* target, |
+ const ui::LocatedEvent& event) { |
+ // Part of a fat interface for mac. |
sky
2016/09/23 16:14:08
I'm not clear on what this comment means. Maybe yo
|
+ NOTREACHED(); |
+} |
+ |
+void DragDropClientMus::Drop(aura::Window* target, |
+ const ui::LocatedEvent& event) { |
+ // Part of a fat interface for mac. |
+ NOTREACHED(); |
+} |
+ |
+void DragDropClientMus::DragCancel() { |
+ ui_window_->CancelDragDrop(); |
+} |
+ |
+bool DragDropClientMus::IsDragDropInProgress() { |
+ return !!g_current_dragging_client; |
+} |
+ |
+} // namespace views |
+ |