Chromium Code Reviews| 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 "base/memory/ptr_util.h" | |
| 12 #include "ui/base/x/selection_utils.h" | 13 #include "ui/base/x/selection_utils.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/base/x/x11_window_event_manager.h" |
| 15 #include "ui/events/platform/x11/x11_event_source.h" | 16 #include "ui/events/platform/x11/x11_event_source.h" |
| 16 | 17 |
| 17 namespace ui { | 18 namespace ui { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const char kAtomPair[] = "ATOM_PAIR"; | 22 const char kAtomPair[] = "ATOM_PAIR"; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 PropModeReplace, | 263 PropModeReplace, |
| 263 reinterpret_cast<unsigned char*>(&length), | 264 reinterpret_cast<unsigned char*>(&length), |
| 264 1); | 265 1); |
| 265 | 266 |
| 266 // Wait for the selection requestor to indicate that it has processed | 267 // Wait for the selection requestor to indicate that it has processed |
| 267 // the selection result before sending the first chunk of data. The | 268 // the selection result before sending the first chunk of data. The |
| 268 // selection requestor indicates this by deleting |property|. | 269 // selection requestor indicates this by deleting |property|. |
| 269 base::TimeTicks timeout = | 270 base::TimeTicks timeout = |
| 270 base::TimeTicks::Now() + | 271 base::TimeTicks::Now() + |
| 271 base::TimeDelta::FromMilliseconds(kIncrementalTransferTimeoutMs); | 272 base::TimeDelta::FromMilliseconds(kIncrementalTransferTimeoutMs); |
| 272 requestor_events_.reset( | |
| 273 new ui::XScopedEventSelector(requestor, PropertyChangeMask)); | |
| 274 incremental_transfers_.push_back(IncrementalTransfer( | 273 incremental_transfers_.push_back(IncrementalTransfer( |
| 275 requestor, target, property, it->second, 0, timeout)); | 274 requestor, target, property, |
| 275 base::MakeUnique<XScopedEventSelector>(requestor, PropertyChangeMask), | |
|
Daniel Erat
2017/02/21 18:09:28
nit, just to check: is this what clang-format sugg
pkotwicz
2017/02/22 03:06:30
Run "git cl format" on this CL does not result in
| |
| 276 it->second, 0, timeout)); | |
| 276 | 277 |
| 277 // Start a timer to abort the data transfer in case that the selection | 278 // 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 | 279 // requestor does not support the INCR property or gets destroyed during |
| 279 // the data transfer. | 280 // the data transfer. |
| 280 if (!incremental_transfer_abort_timer_.IsRunning()) { | 281 if (!incremental_transfer_abort_timer_.IsRunning()) { |
| 281 incremental_transfer_abort_timer_.Start( | 282 incremental_transfer_abort_timer_.Start( |
| 282 FROM_HERE, | 283 FROM_HERE, |
| 283 base::TimeDelta::FromMilliseconds(kTimerPeriodMs), | 284 base::TimeDelta::FromMilliseconds(kTimerPeriodMs), |
| 284 this, | 285 this, |
| 285 &SelectionOwner::AbortStaleIncrementalTransfers); | 286 &SelectionOwner::AbortStaleIncrementalTransfers); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 base::TimeTicks now = base::TimeTicks::Now(); | 332 base::TimeTicks now = base::TimeTicks::Now(); |
| 332 for (int i = static_cast<int>(incremental_transfers_.size()) - 1; | 333 for (int i = static_cast<int>(incremental_transfers_.size()) - 1; |
| 333 i >= 0; --i) { | 334 i >= 0; --i) { |
| 334 if (incremental_transfers_[i].timeout <= now) | 335 if (incremental_transfers_[i].timeout <= now) |
| 335 CompleteIncrementalTransfer(incremental_transfers_.begin() + i); | 336 CompleteIncrementalTransfer(incremental_transfers_.begin() + i); |
| 336 } | 337 } |
| 337 } | 338 } |
| 338 | 339 |
| 339 void SelectionOwner::CompleteIncrementalTransfer( | 340 void SelectionOwner::CompleteIncrementalTransfer( |
| 340 std::vector<IncrementalTransfer>::iterator it) { | 341 std::vector<IncrementalTransfer>::iterator it) { |
| 341 requestor_events_.reset(); | |
| 342 | |
| 343 incremental_transfers_.erase(it); | 342 incremental_transfers_.erase(it); |
| 344 | 343 |
| 345 if (incremental_transfers_.empty()) | 344 if (incremental_transfers_.empty()) |
| 346 incremental_transfer_abort_timer_.Stop(); | 345 incremental_transfer_abort_timer_.Stop(); |
| 347 } | 346 } |
| 348 | 347 |
| 349 std::vector<SelectionOwner::IncrementalTransfer>::iterator | 348 std::vector<SelectionOwner::IncrementalTransfer>::iterator |
| 350 SelectionOwner::FindIncrementalTransferForEvent(const XEvent& event) { | 349 SelectionOwner::FindIncrementalTransferForEvent(const XEvent& event) { |
| 351 for (std::vector<IncrementalTransfer>::iterator it = | 350 for (std::vector<IncrementalTransfer>::iterator it = |
| 352 incremental_transfers_.begin(); | 351 incremental_transfers_.begin(); |
| 353 it != incremental_transfers_.end(); | 352 it != incremental_transfers_.end(); |
| 354 ++it) { | 353 ++it) { |
| 355 if (it->window == event.xproperty.window && | 354 if (it->window == event.xproperty.window && |
| 356 it->property == event.xproperty.atom) { | 355 it->property == event.xproperty.atom) { |
| 357 return it; | 356 return it; |
| 358 } | 357 } |
| 359 } | 358 } |
| 360 return incremental_transfers_.end(); | 359 return incremental_transfers_.end(); |
| 361 } | 360 } |
| 362 | 361 |
| 363 SelectionOwner::IncrementalTransfer::IncrementalTransfer( | 362 SelectionOwner::IncrementalTransfer::IncrementalTransfer( |
| 364 XID window, | 363 XID window, |
| 365 XAtom target, | 364 XAtom target, |
| 366 XAtom property, | 365 XAtom property, |
| 366 std::unique_ptr<XScopedEventSelector> event_selector, | |
| 367 const scoped_refptr<base::RefCountedMemory>& data, | 367 const scoped_refptr<base::RefCountedMemory>& data, |
| 368 int offset, | 368 int offset, |
| 369 base::TimeTicks timeout) | 369 base::TimeTicks timeout) |
| 370 : window(window), | 370 : window(window), |
| 371 target(target), | 371 target(target), |
| 372 property(property), | 372 property(property), |
| 373 event_selector(std::move(event_selector)), | |
| 373 data(data), | 374 data(data), |
| 374 offset(offset), | 375 offset(offset), |
| 375 timeout(timeout) {} | 376 timeout(timeout) {} |
| 376 | 377 |
| 377 SelectionOwner::IncrementalTransfer::IncrementalTransfer( | 378 SelectionOwner::IncrementalTransfer::IncrementalTransfer( |
| 378 const IncrementalTransfer& other) = default; | 379 IncrementalTransfer&& other) = default; |
| 380 | |
| 381 SelectionOwner::IncrementalTransfer& SelectionOwner::IncrementalTransfer:: | |
| 382 operator=(IncrementalTransfer&&) = default; | |
| 379 | 383 |
| 380 SelectionOwner::IncrementalTransfer::~IncrementalTransfer() { | 384 SelectionOwner::IncrementalTransfer::~IncrementalTransfer() { |
| 381 } | 385 } |
| 382 | 386 |
| 383 } // namespace ui | 387 } // namespace ui |
| OLD | NEW |