OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/views/mus/drag_drop_client_mus.h" | |
6 | |
7 #include <map> | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/run_loop.h" | |
13 #include "services/ui/public/cpp/window.h" | |
14 #include "ui/aura/window.h" | |
15 #include "ui/views/mus/os_exchange_data_provider_mus.h" | |
16 | |
17 namespace views { | |
18 namespace { | |
19 | |
20 DragDropClientMus* g_current_dragging_client = nullptr; | |
sky
2016/09/23 16:14:08
My understanding from the style guide is that this
| |
21 | |
22 void OnMoveLoopEnd(bool* out_success, | |
23 uint32_t* out_action, | |
24 base::Closure quit_closure, | |
25 bool in_success, | |
26 uint32_t in_action) { | |
27 *out_success = in_success; | |
28 *out_action = in_action; | |
29 quit_closure.Run(); | |
30 } | |
31 | |
32 } // namespace | |
33 | |
34 // TODO(erg): Do we need to observe? | |
35 | |
36 DragDropClientMus::DragDropClientMus( | |
37 aura::Window* aura_window, | |
38 ui::Window* ui_window) | |
39 : aura_window_(aura_window), | |
40 ui_window_(ui_window) {} | |
41 | |
42 DragDropClientMus::~DragDropClientMus() {} | |
43 | |
44 int DragDropClientMus::StartDragAndDrop( | |
45 const ui::OSExchangeData& data, | |
46 aura::Window* root_window, | |
47 aura::Window* source_window, | |
48 const gfx::Point& screen_location, | |
49 int drag_operations, | |
50 ui::DragDropTypes::DragEventSource source) { | |
51 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
| |
52 | |
53 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.
| |
54 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); | |
55 base::RunLoop run_loop; | |
56 | |
57 std::map<std::string, std::vector<uint8_t>> drag_data = | |
58 static_cast<const OSExchangeDataProviderMus&>(data.provider()).GetData(); | |
59 | |
60 // TODO(erg): Right now, I'm passing the cursor_location, but maybe I want to | |
61 // pass OSExchangeData::GetDragImageOffset() instead? | |
62 | |
63 // TODO(erg): We don't have access to the pointer event at this level, and | |
64 // we'll have to do work to thread the actual events down to this | |
65 // layer. There are two callers to View::DoDrag(), which is the input to this | |
66 // code path: | |
67 // - view.cc:View::ProcessMouseDragged(), which can translate to Pointer. | |
68 // - root_view.cc:PosteEventDispatchHandler::OnGestureEvent() which can't. | |
69 // | |
70 // Getting the Gesture events translated to PointerEvents so that we can | |
71 // thread them to here is going to be...fun. | |
72 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,
| |
73 | |
74 bool success = false; | |
75 gfx::Point cursor_location = screen_location; | |
76 uint32_t action_taken = ui::mojom::kDropEffectNone; | |
77 g_current_dragging_client = this; | |
78 ui_window_->PerformDragDrop( | |
79 drag_pointer, drag_data, drag_operations, cursor_location, | |
80 *data.provider().GetDragImage().bitmap(), | |
81 base::Bind(OnMoveLoopEnd, &success, &action_taken, | |
82 run_loop.QuitClosure())); | |
83 | |
84 run_loop.Run(); | |
85 g_current_dragging_client = nullptr; | |
86 | |
87 return action_taken; | |
88 } | |
89 | |
90 void DragDropClientMus::DragUpdate(aura::Window* target, | |
91 const ui::LocatedEvent& event) { | |
92 // 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
| |
93 NOTREACHED(); | |
94 } | |
95 | |
96 void DragDropClientMus::Drop(aura::Window* target, | |
97 const ui::LocatedEvent& event) { | |
98 // Part of a fat interface for mac. | |
99 NOTREACHED(); | |
100 } | |
101 | |
102 void DragDropClientMus::DragCancel() { | |
103 ui_window_->CancelDragDrop(); | |
104 } | |
105 | |
106 bool DragDropClientMus::IsDragDropInProgress() { | |
107 return !!g_current_dragging_client; | |
108 } | |
109 | |
110 } // namespace views | |
111 | |
OLD | NEW |