| 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" | |
| 14 #include "ui/base/x/x11_util.h" | 13 #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 int foreign_window_manager_id = | 272 ui::XWindowEventManager::GetInstance()->SelectEvents(requestor, |
| 273 ui::XForeignWindowManager::GetInstance()->RequestEvents( | 273 PropertyChangeMask); |
| 274 requestor, PropertyChangeMask); | 274 incremental_transfers_.push_back(IncrementalTransfer( |
| 275 incremental_transfers_.push_back( | 275 requestor, target, property, it->second, 0, timeout)); |
| 276 IncrementalTransfer(requestor, | |
| 277 target, | |
| 278 property, | |
| 279 it->second, | |
| 280 0, | |
| 281 timeout, | |
| 282 foreign_window_manager_id)); | |
| 283 | 276 |
| 284 // Start a timer to abort the data transfer in case that the selection | 277 // Start a timer to abort the data transfer in case that the selection |
| 285 // requestor does not support the INCR property or gets destroyed during | 278 // requestor does not support the INCR property or gets destroyed during |
| 286 // the data transfer. | 279 // the data transfer. |
| 287 if (!incremental_transfer_abort_timer_.IsRunning()) { | 280 if (!incremental_transfer_abort_timer_.IsRunning()) { |
| 288 incremental_transfer_abort_timer_.Start( | 281 incremental_transfer_abort_timer_.Start( |
| 289 FROM_HERE, | 282 FROM_HERE, |
| 290 base::TimeDelta::FromMilliseconds(kTimerPeriodMs), | 283 base::TimeDelta::FromMilliseconds(kTimerPeriodMs), |
| 291 this, | 284 this, |
| 292 &SelectionOwner::AbortStaleIncrementalTransfers); | 285 &SelectionOwner::AbortStaleIncrementalTransfers); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 base::TimeTicks now = base::TimeTicks::Now(); | 331 base::TimeTicks now = base::TimeTicks::Now(); |
| 339 for (int i = static_cast<int>(incremental_transfers_.size()) - 1; | 332 for (int i = static_cast<int>(incremental_transfers_.size()) - 1; |
| 340 i >= 0; --i) { | 333 i >= 0; --i) { |
| 341 if (incremental_transfers_[i].timeout <= now) | 334 if (incremental_transfers_[i].timeout <= now) |
| 342 CompleteIncrementalTransfer(incremental_transfers_.begin() + i); | 335 CompleteIncrementalTransfer(incremental_transfers_.begin() + i); |
| 343 } | 336 } |
| 344 } | 337 } |
| 345 | 338 |
| 346 void SelectionOwner::CompleteIncrementalTransfer( | 339 void SelectionOwner::CompleteIncrementalTransfer( |
| 347 std::vector<IncrementalTransfer>::iterator it) { | 340 std::vector<IncrementalTransfer>::iterator it) { |
| 348 ui::XForeignWindowManager::GetInstance()->CancelRequest( | 341 ui::XWindowEventManager::GetInstance()->DeselectEvents(it->window, |
| 349 it->foreign_window_manager_id); | 342 PropertyChangeMask); |
| 350 incremental_transfers_.erase(it); | 343 incremental_transfers_.erase(it); |
| 351 | 344 |
| 352 if (incremental_transfers_.empty()) | 345 if (incremental_transfers_.empty()) |
| 353 incremental_transfer_abort_timer_.Stop(); | 346 incremental_transfer_abort_timer_.Stop(); |
| 354 } | 347 } |
| 355 | 348 |
| 356 std::vector<SelectionOwner::IncrementalTransfer>::iterator | 349 std::vector<SelectionOwner::IncrementalTransfer>::iterator |
| 357 SelectionOwner::FindIncrementalTransferForEvent(const XEvent& event) { | 350 SelectionOwner::FindIncrementalTransferForEvent(const XEvent& event) { |
| 358 for (std::vector<IncrementalTransfer>::iterator it = | 351 for (std::vector<IncrementalTransfer>::iterator it = |
| 359 incremental_transfers_.begin(); | 352 incremental_transfers_.begin(); |
| 360 it != incremental_transfers_.end(); | 353 it != incremental_transfers_.end(); |
| 361 ++it) { | 354 ++it) { |
| 362 if (it->window == event.xproperty.window && | 355 if (it->window == event.xproperty.window && |
| 363 it->property == event.xproperty.atom) { | 356 it->property == event.xproperty.atom) { |
| 364 return it; | 357 return it; |
| 365 } | 358 } |
| 366 } | 359 } |
| 367 return incremental_transfers_.end(); | 360 return incremental_transfers_.end(); |
| 368 } | 361 } |
| 369 | 362 |
| 370 SelectionOwner::IncrementalTransfer::IncrementalTransfer( | 363 SelectionOwner::IncrementalTransfer::IncrementalTransfer( |
| 371 XID window, | 364 XID window, |
| 372 XAtom target, | 365 XAtom target, |
| 373 XAtom property, | 366 XAtom property, |
| 374 const scoped_refptr<base::RefCountedMemory>& data, | 367 const scoped_refptr<base::RefCountedMemory>& data, |
| 375 int offset, | 368 int offset, |
| 376 base::TimeTicks timeout, | 369 base::TimeTicks timeout) |
| 377 int foreign_window_manager_id) | |
| 378 : window(window), | 370 : window(window), |
| 379 target(target), | 371 target(target), |
| 380 property(property), | 372 property(property), |
| 381 data(data), | 373 data(data), |
| 382 offset(offset), | 374 offset(offset), |
| 383 timeout(timeout), | 375 timeout(timeout) {} |
| 384 foreign_window_manager_id(foreign_window_manager_id) { | |
| 385 } | |
| 386 | 376 |
| 387 SelectionOwner::IncrementalTransfer::IncrementalTransfer( | 377 SelectionOwner::IncrementalTransfer::IncrementalTransfer( |
| 388 const IncrementalTransfer& other) = default; | 378 const IncrementalTransfer& other) = default; |
| 389 | 379 |
| 390 SelectionOwner::IncrementalTransfer::~IncrementalTransfer() { | 380 SelectionOwner::IncrementalTransfer::~IncrementalTransfer() { |
| 391 } | 381 } |
| 392 | 382 |
| 393 } // namespace ui | 383 } // namespace ui |
| OLD | NEW |