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