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