OLD | NEW |
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 Loading... |
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::XScopedEventSelector> source_window_events_; |
| 202 |
200 // The DesktopDragDropClientAuraX11 for |source_window_| if |source_window_| | 203 // The DesktopDragDropClientAuraX11 for |source_window_| if |source_window_| |
201 // belongs to a Chrome window. | 204 // belongs to a Chrome window. |
202 DesktopDragDropClientAuraX11* source_client_; | 205 DesktopDragDropClientAuraX11* source_client_; |
203 | 206 |
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. | 207 // The client we inform once we're done with requesting data. |
209 DesktopDragDropClientAuraX11* drag_drop_client_; | 208 DesktopDragDropClientAuraX11* drag_drop_client_; |
210 | 209 |
211 // Whether we're blocking the handling of an XdndPosition message by waiting | 210 // Whether we're blocking the handling of an XdndPosition message by waiting |
212 // for |unfetched_targets_| to be fetched. | 211 // for |unfetched_targets_| to be fetched. |
213 bool waiting_to_handle_position_; | 212 bool waiting_to_handle_position_; |
214 | 213 |
215 // Where the cursor is on screen. | 214 // Where the cursor is on screen. |
216 gfx::Point screen_point_; | 215 gfx::Point screen_point_; |
217 | 216 |
(...skipping 16 matching lines...) Expand all Loading... |
234 | 233 |
235 DesktopDragDropClientAuraX11::X11DragContext::X11DragContext( | 234 DesktopDragDropClientAuraX11::X11DragContext::X11DragContext( |
236 ui::X11AtomCache* atom_cache, | 235 ui::X11AtomCache* atom_cache, |
237 ::Window local_window, | 236 ::Window local_window, |
238 const XClientMessageEvent& event) | 237 const XClientMessageEvent& event) |
239 : atom_cache_(atom_cache), | 238 : atom_cache_(atom_cache), |
240 local_window_(local_window), | 239 local_window_(local_window), |
241 source_window_(event.data.l[0]), | 240 source_window_(event.data.l[0]), |
242 source_client_( | 241 source_client_( |
243 DesktopDragDropClientAuraX11::GetForWindow(source_window_)), | 242 DesktopDragDropClientAuraX11::GetForWindow(source_window_)), |
244 foreign_window_manager_source_window_id_(0), | |
245 drag_drop_client_(NULL), | 243 drag_drop_client_(NULL), |
246 waiting_to_handle_position_(false), | 244 waiting_to_handle_position_(false), |
247 suggested_action_(None) { | 245 suggested_action_(None) { |
248 if (!source_client_) { | 246 if (!source_client_) { |
249 bool get_types = ((event.data.l[1] & 1) != 0); | 247 bool get_types = ((event.data.l[1] & 1) != 0); |
250 | 248 |
251 if (get_types) { | 249 if (get_types) { |
252 if (!ui::GetAtomArrayProperty(source_window_, | 250 if (!ui::GetAtomArrayProperty(source_window_, |
253 "XdndTypeList", | 251 "XdndTypeList", |
254 &unfetched_targets_)) { | 252 &unfetched_targets_)) { |
255 return; | 253 return; |
256 } | 254 } |
257 } else { | 255 } else { |
258 // data.l[2,3,4] contain the first three types. Unused slots can be None. | 256 // data.l[2,3,4] contain the first three types. Unused slots can be None. |
259 for (int i = 0; i < 3; ++i) { | 257 for (int i = 0; i < 3; ++i) { |
260 if (event.data.l[2+i] != None) { | 258 if (event.data.l[2+i] != None) { |
261 unfetched_targets_.push_back(event.data.l[2+i]); | 259 unfetched_targets_.push_back(event.data.l[2+i]); |
262 } | 260 } |
263 } | 261 } |
264 } | 262 } |
265 | 263 |
266 // The window doesn't have a DesktopDragDropClientAuraX11, that means it's | 264 // The window doesn't have a DesktopDragDropClientAuraX11, that means it's |
267 // created by some other process. Listen for messages on it. | 265 // created by some other process. Listen for messages on it. |
268 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | 266 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
269 foreign_window_manager_source_window_id_ = | 267 source_window_events_.reset( |
270 ui::XForeignWindowManager::GetInstance()->RequestEvents( | 268 new ui::XScopedEventSelector(source_window_, PropertyChangeMask)); |
271 source_window_, PropertyChangeMask); | |
272 | 269 |
273 // We must perform a full sync here because we could be racing | 270 // We must perform a full sync here because we could be racing |
274 // |source_window_|. | 271 // |source_window_|. |
275 XSync(gfx::GetXDisplay(), False); | 272 XSync(gfx::GetXDisplay(), False); |
276 } else { | 273 } else { |
277 // This drag originates from an aura window within our process. This means | 274 // 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 | 275 // that we can shortcut the X11 server and ask the owning SelectionOwner |
279 // for the data it's offering. | 276 // for the data it's offering. |
280 fetched_targets_ = source_client_->GetFormatMap(); | 277 fetched_targets_ = source_client_->GetFormatMap(); |
281 } | 278 } |
282 | 279 |
283 ReadActions(); | 280 ReadActions(); |
284 } | 281 } |
285 | 282 |
286 DesktopDragDropClientAuraX11::X11DragContext::~X11DragContext() { | 283 DesktopDragDropClientAuraX11::X11DragContext::~X11DragContext() { |
287 if (!source_client_) { | 284 if (!source_client_) { |
288 // Unsubscribe from message events. | 285 // Unsubscribe from message events. |
289 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); | 286 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
290 ui::XForeignWindowManager::GetInstance()->CancelRequest( | |
291 foreign_window_manager_source_window_id_); | |
292 } | 287 } |
293 } | 288 } |
294 | 289 |
295 void DesktopDragDropClientAuraX11::X11DragContext::OnStartXdndPositionMessage( | 290 void DesktopDragDropClientAuraX11::X11DragContext::OnStartXdndPositionMessage( |
296 DesktopDragDropClientAuraX11* client, | 291 DesktopDragDropClientAuraX11* client, |
297 ::Atom suggested_action, | 292 ::Atom suggested_action, |
298 ::Window source_window, | 293 ::Window source_window, |
299 const gfx::Point& screen_point) { | 294 const gfx::Point& screen_point) { |
300 DCHECK_EQ(source_window_, source_window); | 295 DCHECK_EQ(source_window_, source_window); |
301 suggested_action_ = suggested_action; | 296 suggested_action_ = suggested_action; |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 for (int x = 0; x < in_bitmap->width(); ++x) { | 1225 for (int x = 0; x < in_bitmap->width(); ++x) { |
1231 if (SkColorGetA(in_row[x]) > kMinAlpha) | 1226 if (SkColorGetA(in_row[x]) > kMinAlpha) |
1232 return true; | 1227 return true; |
1233 } | 1228 } |
1234 } | 1229 } |
1235 | 1230 |
1236 return false; | 1231 return false; |
1237 } | 1232 } |
1238 | 1233 |
1239 } // namespace views | 1234 } // namespace views |
OLD | NEW |