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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc

Issue 2313033002: Refactor X11ForeignWindowManager (Reland) (Closed)
Patch Set: Rename to XWindowEventmanager Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" 5 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h"
6 6
7 #include <X11/Xatom.h> 7 #include <X11/Xatom.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "base/event_types.h" 11 #include "base/event_types.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "ui/aura/client/capture_client.h" 18 #include "ui/aura/client/capture_client.h"
19 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
20 #include "ui/aura/window_tree_host.h" 20 #include "ui/aura/window_tree_host.h"
21 #include "ui/base/clipboard/clipboard.h" 21 #include "ui/base/clipboard/clipboard.h"
22 #include "ui/base/dragdrop/drop_target_event.h" 22 #include "ui/base/dragdrop/drop_target_event.h"
23 #include "ui/base/dragdrop/os_exchange_data.h" 23 #include "ui/base/dragdrop/os_exchange_data.h"
24 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" 24 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h"
25 #include "ui/base/x/selection_utils.h" 25 #include "ui/base/x/selection_utils.h"
26 #include "ui/base/x/x11_foreign_window_manager.h"
27 #include "ui/base/x/x11_util.h" 26 #include "ui/base/x/x11_util.h"
27 #include "ui/base/x/x11_window_event_manager.h"
28 #include "ui/display/screen.h" 28 #include "ui/display/screen.h"
29 #include "ui/events/event.h" 29 #include "ui/events/event.h"
30 #include "ui/events/event_utils.h" 30 #include "ui/events/event_utils.h"
31 #include "ui/events/platform/platform_event_source.h" 31 #include "ui/events/platform/platform_event_source.h"
32 #include "ui/gfx/image/image_skia.h" 32 #include "ui/gfx/image/image_skia.h"
33 #include "ui/views/controls/image_view.h" 33 #include "ui/views/controls/image_view.h"
34 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" 34 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
35 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" 35 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
36 #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h" 36 #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h"
37 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 190
191 // The atom cache owned by our parent. 191 // The atom cache owned by our parent.
192 ui::X11AtomCache* atom_cache_; 192 ui::X11AtomCache* atom_cache_;
193 193
194 // The XID of our chrome local aura window handling our events. 194 // The XID of our chrome local aura window handling our events.
195 ::Window local_window_; 195 ::Window local_window_;
196 196
197 // The XID of the window that's initiated the drag. 197 // The XID of the window that's initiated the drag.
198 unsigned long source_window_; 198 unsigned long source_window_;
199 199
200 // Events that we have selected on |source_window_|.
201 std::unique_ptr<ui::XWindowEventManager::ScopedEventSelector>
202 source_window_events_;
203
200 // The DesktopDragDropClientAuraX11 for |source_window_| if |source_window_| 204 // The DesktopDragDropClientAuraX11 for |source_window_| if |source_window_|
201 // belongs to a Chrome window. 205 // belongs to a Chrome window.
202 DesktopDragDropClientAuraX11* source_client_; 206 DesktopDragDropClientAuraX11* source_client_;
203 207
204 // Used to unselect PropertyChangeMask on |source_window_| if |source_window_|
205 // does not belong to a Chrome window when X11DragContext is destroyed.
206 int foreign_window_manager_source_window_id_;
207
208 // The client we inform once we're done with requesting data. 208 // The client we inform once we're done with requesting data.
209 DesktopDragDropClientAuraX11* drag_drop_client_; 209 DesktopDragDropClientAuraX11* drag_drop_client_;
210 210
211 // Whether we're blocking the handling of an XdndPosition message by waiting 211 // Whether we're blocking the handling of an XdndPosition message by waiting
212 // for |unfetched_targets_| to be fetched. 212 // for |unfetched_targets_| to be fetched.
213 bool waiting_to_handle_position_; 213 bool waiting_to_handle_position_;
214 214
215 // Where the cursor is on screen. 215 // Where the cursor is on screen.
216 gfx::Point screen_point_; 216 gfx::Point screen_point_;
217 217
(...skipping 16 matching lines...) Expand all
234 234
235 DesktopDragDropClientAuraX11::X11DragContext::X11DragContext( 235 DesktopDragDropClientAuraX11::X11DragContext::X11DragContext(
236 ui::X11AtomCache* atom_cache, 236 ui::X11AtomCache* atom_cache,
237 ::Window local_window, 237 ::Window local_window,
238 const XClientMessageEvent& event) 238 const XClientMessageEvent& event)
239 : atom_cache_(atom_cache), 239 : atom_cache_(atom_cache),
240 local_window_(local_window), 240 local_window_(local_window),
241 source_window_(event.data.l[0]), 241 source_window_(event.data.l[0]),
242 source_client_( 242 source_client_(
243 DesktopDragDropClientAuraX11::GetForWindow(source_window_)), 243 DesktopDragDropClientAuraX11::GetForWindow(source_window_)),
244 foreign_window_manager_source_window_id_(0),
245 drag_drop_client_(NULL), 244 drag_drop_client_(NULL),
246 waiting_to_handle_position_(false), 245 waiting_to_handle_position_(false),
247 suggested_action_(None) { 246 suggested_action_(None) {
248 if (!source_client_) { 247 if (!source_client_) {
249 bool get_types = ((event.data.l[1] & 1) != 0); 248 bool get_types = ((event.data.l[1] & 1) != 0);
250 249
251 if (get_types) { 250 if (get_types) {
252 if (!ui::GetAtomArrayProperty(source_window_, 251 if (!ui::GetAtomArrayProperty(source_window_,
253 "XdndTypeList", 252 "XdndTypeList",
254 &unfetched_targets_)) { 253 &unfetched_targets_)) {
255 return; 254 return;
256 } 255 }
257 } else { 256 } else {
258 // data.l[2,3,4] contain the first three types. Unused slots can be None. 257 // data.l[2,3,4] contain the first three types. Unused slots can be None.
259 for (int i = 0; i < 3; ++i) { 258 for (int i = 0; i < 3; ++i) {
260 if (event.data.l[2+i] != None) { 259 if (event.data.l[2+i] != None) {
261 unfetched_targets_.push_back(event.data.l[2+i]); 260 unfetched_targets_.push_back(event.data.l[2+i]);
262 } 261 }
263 } 262 }
264 } 263 }
265 264
266 // The window doesn't have a DesktopDragDropClientAuraX11, that means it's 265 // The window doesn't have a DesktopDragDropClientAuraX11, that means it's
267 // created by some other process. Listen for messages on it. 266 // created by some other process. Listen for messages on it.
268 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); 267 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
269 foreign_window_manager_source_window_id_ = 268 source_window_events_.reset(
270 ui::XForeignWindowManager::GetInstance()->RequestEvents( 269 new ui::XWindowEventManager::ScopedEventSelector(source_window_,
271 source_window_, PropertyChangeMask); 270 PropertyChangeMask));
272 271
273 // We must perform a full sync here because we could be racing 272 // We must perform a full sync here because we could be racing
274 // |source_window_|. 273 // |source_window_|.
275 XSync(gfx::GetXDisplay(), False); 274 XSync(gfx::GetXDisplay(), False);
276 } else { 275 } else {
277 // This drag originates from an aura window within our process. This means 276 // This drag originates from an aura window within our process. This means
278 // that we can shortcut the X11 server and ask the owning SelectionOwner 277 // that we can shortcut the X11 server and ask the owning SelectionOwner
279 // for the data it's offering. 278 // for the data it's offering.
280 fetched_targets_ = source_client_->GetFormatMap(); 279 fetched_targets_ = source_client_->GetFormatMap();
281 } 280 }
282 281
283 ReadActions(); 282 ReadActions();
284 } 283 }
285 284
286 DesktopDragDropClientAuraX11::X11DragContext::~X11DragContext() { 285 DesktopDragDropClientAuraX11::X11DragContext::~X11DragContext() {
287 if (!source_client_) { 286 if (!source_client_) {
288 // Unsubscribe from message events. 287 // Unsubscribe from message events.
289 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); 288 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
290 ui::XForeignWindowManager::GetInstance()->CancelRequest(
291 foreign_window_manager_source_window_id_);
292 } 289 }
293 } 290 }
294 291
295 void DesktopDragDropClientAuraX11::X11DragContext::OnStartXdndPositionMessage( 292 void DesktopDragDropClientAuraX11::X11DragContext::OnStartXdndPositionMessage(
296 DesktopDragDropClientAuraX11* client, 293 DesktopDragDropClientAuraX11* client,
297 ::Atom suggested_action, 294 ::Atom suggested_action,
298 ::Window source_window, 295 ::Window source_window,
299 const gfx::Point& screen_point) { 296 const gfx::Point& screen_point) {
300 DCHECK_EQ(source_window_, source_window); 297 DCHECK_EQ(source_window_, source_window);
301 suggested_action_ = suggested_action; 298 suggested_action_ = suggested_action;
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 for (int x = 0; x < in_bitmap->width(); ++x) { 1227 for (int x = 0; x < in_bitmap->width(); ++x) {
1231 if (SkColorGetA(in_row[x]) > kMinAlpha) 1228 if (SkColorGetA(in_row[x]) > kMinAlpha)
1232 return true; 1229 return true;
1233 } 1230 }
1234 } 1231 }
1235 1232
1236 return false; 1233 return false;
1237 } 1234 }
1238 1235
1239 } // namespace views 1236 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698