OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/base/x/selection_owner.h" | 5 #include "ui/base/x/selection_owner.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "ui/base/x/selection_utils.h" | 12 #include "ui/base/x/selection_utils.h" |
| 13 #include "ui/base/x/x11_foreign_window_manager.h" |
13 #include "ui/base/x/x11_util.h" | 14 #include "ui/base/x/x11_util.h" |
14 #include "ui/base/x/x11_window_event_manager.h" | |
15 #include "ui/events/platform/x11/x11_event_source.h" | 15 #include "ui/events/platform/x11/x11_event_source.h" |
16 | 16 |
17 namespace ui { | 17 namespace ui { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const char kAtomPair[] = "ATOM_PAIR"; | 21 const char kAtomPair[] = "ATOM_PAIR"; |
22 const char kIncr[] = "INCR"; | 22 const char kIncr[] = "INCR"; |
23 const char kMultiple[] = "MULTIPLE"; | 23 const char kMultiple[] = "MULTIPLE"; |
24 const char kSaveTargets[] = "SAVE_TARGETS"; | 24 const char kSaveTargets[] = "SAVE_TARGETS"; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 PropModeReplace, | 262 PropModeReplace, |
263 reinterpret_cast<unsigned char*>(&length), | 263 reinterpret_cast<unsigned char*>(&length), |
264 1); | 264 1); |
265 | 265 |
266 // Wait for the selection requestor to indicate that it has processed | 266 // Wait for the selection requestor to indicate that it has processed |
267 // the selection result before sending the first chunk of data. The | 267 // the selection result before sending the first chunk of data. The |
268 // selection requestor indicates this by deleting |property|. | 268 // selection requestor indicates this by deleting |property|. |
269 base::TimeTicks timeout = | 269 base::TimeTicks timeout = |
270 base::TimeTicks::Now() + | 270 base::TimeTicks::Now() + |
271 base::TimeDelta::FromMilliseconds(kIncrementalTransferTimeoutMs); | 271 base::TimeDelta::FromMilliseconds(kIncrementalTransferTimeoutMs); |
272 requestor_events_.reset( | 272 int foreign_window_manager_id = |
273 new ui::XScopedEventSelector(requestor, PropertyChangeMask)); | 273 ui::XForeignWindowManager::GetInstance()->RequestEvents( |
274 incremental_transfers_.push_back(IncrementalTransfer( | 274 requestor, PropertyChangeMask); |
275 requestor, target, property, it->second, 0, timeout)); | 275 incremental_transfers_.push_back( |
| 276 IncrementalTransfer(requestor, |
| 277 target, |
| 278 property, |
| 279 it->second, |
| 280 0, |
| 281 timeout, |
| 282 foreign_window_manager_id)); |
276 | 283 |
277 // Start a timer to abort the data transfer in case that the selection | 284 // Start a timer to abort the data transfer in case that the selection |
278 // requestor does not support the INCR property or gets destroyed during | 285 // requestor does not support the INCR property or gets destroyed during |
279 // the data transfer. | 286 // the data transfer. |
280 if (!incremental_transfer_abort_timer_.IsRunning()) { | 287 if (!incremental_transfer_abort_timer_.IsRunning()) { |
281 incremental_transfer_abort_timer_.Start( | 288 incremental_transfer_abort_timer_.Start( |
282 FROM_HERE, | 289 FROM_HERE, |
283 base::TimeDelta::FromMilliseconds(kTimerPeriodMs), | 290 base::TimeDelta::FromMilliseconds(kTimerPeriodMs), |
284 this, | 291 this, |
285 &SelectionOwner::AbortStaleIncrementalTransfers); | 292 &SelectionOwner::AbortStaleIncrementalTransfers); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 base::TimeTicks now = base::TimeTicks::Now(); | 338 base::TimeTicks now = base::TimeTicks::Now(); |
332 for (int i = static_cast<int>(incremental_transfers_.size()) - 1; | 339 for (int i = static_cast<int>(incremental_transfers_.size()) - 1; |
333 i >= 0; --i) { | 340 i >= 0; --i) { |
334 if (incremental_transfers_[i].timeout <= now) | 341 if (incremental_transfers_[i].timeout <= now) |
335 CompleteIncrementalTransfer(incremental_transfers_.begin() + i); | 342 CompleteIncrementalTransfer(incremental_transfers_.begin() + i); |
336 } | 343 } |
337 } | 344 } |
338 | 345 |
339 void SelectionOwner::CompleteIncrementalTransfer( | 346 void SelectionOwner::CompleteIncrementalTransfer( |
340 std::vector<IncrementalTransfer>::iterator it) { | 347 std::vector<IncrementalTransfer>::iterator it) { |
341 requestor_events_.reset(); | 348 ui::XForeignWindowManager::GetInstance()->CancelRequest( |
342 | 349 it->foreign_window_manager_id); |
343 incremental_transfers_.erase(it); | 350 incremental_transfers_.erase(it); |
344 | 351 |
345 if (incremental_transfers_.empty()) | 352 if (incremental_transfers_.empty()) |
346 incremental_transfer_abort_timer_.Stop(); | 353 incremental_transfer_abort_timer_.Stop(); |
347 } | 354 } |
348 | 355 |
349 std::vector<SelectionOwner::IncrementalTransfer>::iterator | 356 std::vector<SelectionOwner::IncrementalTransfer>::iterator |
350 SelectionOwner::FindIncrementalTransferForEvent(const XEvent& event) { | 357 SelectionOwner::FindIncrementalTransferForEvent(const XEvent& event) { |
351 for (std::vector<IncrementalTransfer>::iterator it = | 358 for (std::vector<IncrementalTransfer>::iterator it = |
352 incremental_transfers_.begin(); | 359 incremental_transfers_.begin(); |
353 it != incremental_transfers_.end(); | 360 it != incremental_transfers_.end(); |
354 ++it) { | 361 ++it) { |
355 if (it->window == event.xproperty.window && | 362 if (it->window == event.xproperty.window && |
356 it->property == event.xproperty.atom) { | 363 it->property == event.xproperty.atom) { |
357 return it; | 364 return it; |
358 } | 365 } |
359 } | 366 } |
360 return incremental_transfers_.end(); | 367 return incremental_transfers_.end(); |
361 } | 368 } |
362 | 369 |
363 SelectionOwner::IncrementalTransfer::IncrementalTransfer( | 370 SelectionOwner::IncrementalTransfer::IncrementalTransfer( |
364 XID window, | 371 XID window, |
365 XAtom target, | 372 XAtom target, |
366 XAtom property, | 373 XAtom property, |
367 const scoped_refptr<base::RefCountedMemory>& data, | 374 const scoped_refptr<base::RefCountedMemory>& data, |
368 int offset, | 375 int offset, |
369 base::TimeTicks timeout) | 376 base::TimeTicks timeout, |
| 377 int foreign_window_manager_id) |
370 : window(window), | 378 : window(window), |
371 target(target), | 379 target(target), |
372 property(property), | 380 property(property), |
373 data(data), | 381 data(data), |
374 offset(offset), | 382 offset(offset), |
375 timeout(timeout) {} | 383 timeout(timeout), |
| 384 foreign_window_manager_id(foreign_window_manager_id) { |
| 385 } |
376 | 386 |
377 SelectionOwner::IncrementalTransfer::IncrementalTransfer( | 387 SelectionOwner::IncrementalTransfer::IncrementalTransfer( |
378 const IncrementalTransfer& other) = default; | 388 const IncrementalTransfer& other) = default; |
379 | 389 |
380 SelectionOwner::IncrementalTransfer::~IncrementalTransfer() { | 390 SelectionOwner::IncrementalTransfer::~IncrementalTransfer() { |
381 } | 391 } |
382 | 392 |
383 } // namespace ui | 393 } // namespace ui |
OLD | NEW |