Commit 96451e35 authored by Daichi Hirono's avatar Daichi Hirono Committed by Commit Bot

Clears clipboard when null DataSource is passed to SetSelection

Previously SetSelection did DCHECK for null DataSrouce, which was wrong.
According to Wayland document, we should clears the clipboard when null
DataSource is passed.

Bug; 789831
Test: exo_unittests

Change-Id: I9bff52cb4259b2d02faeb6a6e32353d0e3da4f2c
Reviewed-on: https://chromium-review.googlesource.com/798815
Commit-Queue: Daichi Hirono <hirono@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520775}
parent 8f0e7748
...@@ -62,14 +62,17 @@ Surface* Seat::GetFocusedSurface() { ...@@ -62,14 +62,17 @@ Surface* Seat::GetFocusedSurface() {
} }
void Seat::SetSelection(DataSource* source) { void Seat::SetSelection(DataSource* source) {
DCHECK(source); if (!source) {
ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
// selection_source_ is Cancelled() and reset() in OnClipboardDataChanged().
return;
}
if (selection_source_) { if (selection_source_) {
if (selection_source_->get() == source) if (selection_source_->get() == source)
return; return;
selection_source_->get()->Cancelled(); selection_source_->get()->Cancelled();
} }
selection_source_ = std::make_unique<ScopedDataSource>(source, this); selection_source_ = std::make_unique<ScopedDataSource>(source, this);
// Unretained is safe as Seat always outlives DataSource. // Unretained is safe as Seat always outlives DataSource.
......
...@@ -227,5 +227,26 @@ TEST_F(SeatTest, SetSelection_SourceDestroyedAfterSetSelection) { ...@@ -227,5 +227,26 @@ TEST_F(SeatTest, SetSelection_SourceDestroyedAfterSetSelection) {
EXPECT_FALSE(delegate1.cancelled()); EXPECT_FALSE(delegate1.cancelled());
} }
TEST_F(SeatTest, SetSelection_NullSource) {
Seat seat;
TestDataSourceDelegate delegate;
DataSource source(&delegate);
source.Offer("text/plain;charset=utf-8");
seat.SetSelection(&source);
RunReadingTask();
// Should clear the clipboard.
seat.SetSelection(nullptr);
ASSERT_TRUE(delegate.cancelled());
std::string clipboard;
ui::Clipboard::GetForCurrentThread()->ReadAsciiText(
ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard);
EXPECT_EQ(clipboard, "");
}
} // namespace } // namespace
} // namespace exo } // namespace exo
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment