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