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

Side by Side Diff: ui/views/mus/drop_target_mus.cc

Issue 2611773002: Removes code using mus client lib (Closed)
Patch Set: dont run on linux Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « ui/views/mus/drop_target_mus.h ('k') | ui/views/mus/input_method_mus.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/drop_target_mus.h"
6
7 #include <map>
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 #include "base/memory/ptr_util.h"
13 #include "services/ui/public/interfaces/window_tree_constants.mojom.h"
14 #include "ui/aura/client/drag_drop_client.h"
15 #include "ui/aura/client/drag_drop_delegate.h"
16 #include "ui/aura/mus/os_exchange_data_provider_mus.h"
17 #include "ui/aura/window.h"
18 #include "ui/aura/window_tree_host.h"
19 #include "ui/base/dragdrop/drag_drop_types.h"
20 #include "ui/base/dragdrop/drop_target_event.h"
21
22 namespace views {
23
24 static_assert(ui::DragDropTypes::DRAG_NONE == ui::mojom::kDropEffectNone,
25 "Drag constants must be the same");
26 static_assert(ui::DragDropTypes::DRAG_MOVE == ui::mojom::kDropEffectMove,
27 "Drag constants must be the same");
28 static_assert(ui::DragDropTypes::DRAG_COPY == ui::mojom::kDropEffectCopy,
29 "Drag constants must be the same");
30 static_assert(ui::DragDropTypes::DRAG_LINK == ui::mojom::kDropEffectLink,
31 "Drag constants must be the same");
32
33 DropTargetMus::DropTargetMus(aura::Window* root_window)
34 : root_window_(root_window), target_window_(nullptr) {}
35
36 DropTargetMus::~DropTargetMus() {}
37
38 void DropTargetMus::Translate(uint32_t key_state,
39 const gfx::Point& screen_location,
40 uint32_t effect,
41 std::unique_ptr<ui::DropTargetEvent>* event,
42 aura::client::DragDropDelegate** delegate) {
43 gfx::Point location = screen_location;
44 gfx::Point root_location = location;
45 root_window_->GetHost()->ConvertScreenInPixelsToDIP(&root_location);
46 aura::Window* target_window =
47 root_window_->GetEventHandlerForPoint(root_location);
48 bool target_window_changed = false;
49 if (target_window != target_window_) {
50 if (target_window_)
51 NotifyDragExited();
52 target_window_ = target_window;
53 if (target_window_)
54 target_window_->AddObserver(this);
55 target_window_changed = true;
56 }
57 *delegate = nullptr;
58 if (!target_window_)
59 return;
60 *delegate = aura::client::GetDragDropDelegate(target_window_);
61 if (!*delegate)
62 return;
63
64 location = root_location;
65 aura::Window::ConvertPointToTarget(root_window_, target_window_, &location);
66 *event = base::MakeUnique<ui::DropTargetEvent>(
67 *(os_exchange_data_.get()), location, root_location, effect);
68 (*event)->set_flags(key_state);
69 if (target_window_changed)
70 (*delegate)->OnDragEntered(*event->get());
71 }
72
73 void DropTargetMus::NotifyDragExited() {
74 if (!target_window_)
75 return;
76
77 aura::client::DragDropDelegate* delegate =
78 aura::client::GetDragDropDelegate(target_window_);
79 if (delegate)
80 delegate->OnDragExited();
81
82 target_window_->RemoveObserver(this);
83 target_window_ = nullptr;
84 }
85
86 void DropTargetMus::OnDragDropStart(
87 std::map<std::string, std::vector<uint8_t>> mime_data) {
88 // We store the mime data here because we need to access it during each phase
89 // of the drag, but we also don't move the data cross-process multiple times.
90 os_exchange_data_ = base::MakeUnique<ui::OSExchangeData>(
91 base::MakeUnique<aura::OSExchangeDataProviderMus>(std::move(mime_data)));
92 }
93
94 uint32_t DropTargetMus::OnDragEnter(uint32_t key_state,
95 const gfx::Point& position,
96 uint32_t effect_bitmask) {
97 std::unique_ptr<ui::DropTargetEvent> event;
98 aura::client::DragDropDelegate* delegate = nullptr;
99 // Translate will call OnDragEntered.
100 Translate(key_state, position, effect_bitmask, &event, &delegate);
101 return ui::mojom::kDropEffectNone;
102 }
103
104 uint32_t DropTargetMus::OnDragOver(uint32_t key_state,
105 const gfx::Point& position,
106 uint32_t effect) {
107 int drag_operation = ui::DragDropTypes::DRAG_NONE;
108 std::unique_ptr<ui::DropTargetEvent> event;
109 aura::client::DragDropDelegate* delegate = nullptr;
110
111 Translate(key_state, position, effect, &event, &delegate);
112 if (delegate)
113 drag_operation = delegate->OnDragUpdated(*event);
114 return drag_operation;
115 }
116
117 void DropTargetMus::OnDragLeave() {
118 NotifyDragExited();
119 }
120
121 uint32_t DropTargetMus::OnCompleteDrop(uint32_t key_state,
122 const gfx::Point& position,
123 uint32_t effect) {
124 int drag_operation = ui::DragDropTypes::DRAG_NONE;
125 std::unique_ptr<ui::DropTargetEvent> event;
126 aura::client::DragDropDelegate* delegate = nullptr;
127 Translate(key_state, position, effect, &event, &delegate);
128 if (delegate)
129 drag_operation = delegate->OnPerformDrop(*event);
130 if (target_window_) {
131 target_window_->RemoveObserver(this);
132 target_window_ = nullptr;
133 }
134
135 return drag_operation;
136 }
137
138 void DropTargetMus::OnDragDropDone() {
139 os_exchange_data_.reset();
140 }
141
142 void DropTargetMus::OnWindowDestroyed(aura::Window* window) {
143 DCHECK_EQ(window, target_window_);
144 target_window_ = nullptr;
145 }
146
147 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/drop_target_mus.h ('k') | ui/views/mus/input_method_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698