blob: d887c1ed725e0c696d1297544419823e3b75a832 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/clipboard/clipboard_data.h"
#include <memory>
#include <ostream>
#include "base/notreached.h"
#include "skia/ext/skia_utils_base.h"
#include "ui/base/clipboard/clipboard_data_endpoint.h"
#include "ui/gfx/skia_util.h"
namespace ui {
ClipboardData::ClipboardData() : web_smart_paste_(false), format_(0) {}
ClipboardData::ClipboardData(const ClipboardData& other) {
format_ = other.format_;
text_ = other.text_;
markup_data_ = other.markup_data_;
url_ = other.url_;
rtf_data_ = other.rtf_data_;
bitmap_ = other.bitmap();
bookmark_title_ = other.bookmark_title_;
bookmark_url_ = other.bookmark_url_;
custom_data_format_ = other.custom_data_format_;
custom_data_data_ = other.custom_data_data_;
web_smart_paste_ = other.web_smart_paste_;
src_ = other.src_ ? std::make_unique<ClipboardDataEndpoint>(*other.src_.get())
: nullptr;
}
ClipboardData::~ClipboardData() = default;
ClipboardData::ClipboardData(ClipboardData&&) = default;
bool ClipboardData::operator==(const ClipboardData& that) const {
return format_ == that.format() && text_ == that.text() &&
markup_data_ == that.markup_data() && url_ == that.url() &&
rtf_data_ == that.rtf_data() &&
bookmark_title_ == that.bookmark_title() &&
bookmark_url_ == that.bookmark_url() &&
custom_data_format_ == that.custom_data_format() &&
custom_data_data_ == that.custom_data_data() &&
web_smart_paste_ == that.web_smart_paste() &&
gfx::BitmapsAreEqual(bitmap_, that.bitmap()) &&
(src_.get() ? (that.source() && *src_.get() == *that.source())
: !that.source());
}
bool ClipboardData::operator!=(const ClipboardData& that) const {
return !(*this == that);
}
void ClipboardData::SetBitmapData(const SkBitmap& bitmap) {
if (!skia::SkBitmapToN32OpaqueOrPremul(bitmap, &bitmap_)) {
NOTREACHED() << "Unable to convert bitmap for clipboard";
return;
}
format_ |= static_cast<int>(ClipboardInternalFormat::kBitmap);
}
void ClipboardData::SetCustomData(const std::string& data_format,
const std::string& data_data) {
if (data_data.size() == 0) {
custom_data_data_.clear();
custom_data_format_.clear();
return;
}
custom_data_data_ = data_data;
custom_data_format_ = data_format;
format_ |= static_cast<int>(ClipboardInternalFormat::kCustom);
}
} // namespace ui
|