Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: ui/base/x/selection_utils.cc

Issue 2924343002: Move ui::GetAtom to gfx::GetAtom (Closed)
Patch Set: fix CrOs build Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/x/selection_requestor_unittest.cc ('k') | ui/base/x/x11_menu_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_utils.h" 5 #include "ui/base/x/selection_utils.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
11 11
12 #include "base/i18n/icu_string_conversions.h" 12 #include "base/i18n/icu_string_conversions.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "ui/base/clipboard/clipboard.h" 17 #include "ui/base/clipboard/clipboard.h"
18 #include "ui/base/x/x11_util.h" 18 #include "ui/gfx/x/x11_atom_cache.h"
19 19
20 namespace ui { 20 namespace ui {
21 21
22 const char kString[] = "STRING"; 22 const char kString[] = "STRING";
23 const char kText[] = "TEXT"; 23 const char kText[] = "TEXT";
24 const char kTextPlain[] = "text/plain"; 24 const char kTextPlain[] = "text/plain";
25 const char kTextPlainUtf8[] = "text/plain;charset=utf-8"; 25 const char kTextPlainUtf8[] = "text/plain;charset=utf-8";
26 const char kUtf8String[] = "UTF8_STRING"; 26 const char kUtf8String[] = "UTF8_STRING";
27 27
28 std::vector<::Atom> GetTextAtomsFrom() { 28 std::vector<::Atom> GetTextAtomsFrom() {
29 std::vector< ::Atom> atoms; 29 std::vector< ::Atom> atoms;
30 atoms.push_back(GetAtom(kUtf8String)); 30 atoms.push_back(gfx::GetAtom(kUtf8String));
31 atoms.push_back(GetAtom(kString)); 31 atoms.push_back(gfx::GetAtom(kString));
32 atoms.push_back(GetAtom(kText)); 32 atoms.push_back(gfx::GetAtom(kText));
33 atoms.push_back(GetAtom(kTextPlain)); 33 atoms.push_back(gfx::GetAtom(kTextPlain));
34 atoms.push_back(GetAtom(kTextPlainUtf8)); 34 atoms.push_back(gfx::GetAtom(kTextPlainUtf8));
35 return atoms; 35 return atoms;
36 } 36 }
37 37
38 std::vector<::Atom> GetURLAtomsFrom() { 38 std::vector<::Atom> GetURLAtomsFrom() {
39 std::vector< ::Atom> atoms; 39 std::vector< ::Atom> atoms;
40 atoms.push_back(GetAtom(Clipboard::kMimeTypeURIList)); 40 atoms.push_back(gfx::GetAtom(Clipboard::kMimeTypeURIList));
41 atoms.push_back(GetAtom(Clipboard::kMimeTypeMozillaURL)); 41 atoms.push_back(gfx::GetAtom(Clipboard::kMimeTypeMozillaURL));
42 return atoms; 42 return atoms;
43 } 43 }
44 44
45 std::vector<::Atom> GetURIListAtomsFrom() { 45 std::vector<::Atom> GetURIListAtomsFrom() {
46 std::vector< ::Atom> atoms; 46 std::vector< ::Atom> atoms;
47 atoms.push_back(GetAtom(Clipboard::kMimeTypeURIList)); 47 atoms.push_back(gfx::GetAtom(Clipboard::kMimeTypeURIList));
48 return atoms; 48 return atoms;
49 } 49 }
50 50
51 void GetAtomIntersection(const std::vector< ::Atom>& desired, 51 void GetAtomIntersection(const std::vector< ::Atom>& desired,
52 const std::vector< ::Atom>& offered, 52 const std::vector< ::Atom>& offered,
53 std::vector< ::Atom>* output) { 53 std::vector< ::Atom>* output) {
54 for (std::vector< ::Atom>::const_iterator it = desired.begin(); 54 for (std::vector< ::Atom>::const_iterator it = desired.begin();
55 it != desired.end(); ++it) { 55 it != desired.end(); ++it) {
56 std::vector< ::Atom>::const_iterator jt = 56 std::vector< ::Atom>::const_iterator jt =
57 std::find(offered.begin(), offered.end(), *it); 57 std::find(offered.begin(), offered.end(), *it);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 const unsigned char* SelectionData::GetData() const { 175 const unsigned char* SelectionData::GetData() const {
176 return memory_.get() ? memory_->front() : NULL; 176 return memory_.get() ? memory_->front() : NULL;
177 } 177 }
178 178
179 size_t SelectionData::GetSize() const { 179 size_t SelectionData::GetSize() const {
180 return memory_.get() ? memory_->size() : 0; 180 return memory_.get() ? memory_->size() : 0;
181 } 181 }
182 182
183 std::string SelectionData::GetText() const { 183 std::string SelectionData::GetText() const {
184 if (type_ == GetAtom(kUtf8String) || type_ == GetAtom(kText) || 184 if (type_ == gfx::GetAtom(kUtf8String) || type_ == gfx::GetAtom(kText) ||
185 type_ == GetAtom(kTextPlainUtf8)) { 185 type_ == gfx::GetAtom(kTextPlainUtf8)) {
186 return RefCountedMemoryToString(memory_); 186 return RefCountedMemoryToString(memory_);
187 } else if (type_ == GetAtom(kString) || type_ == GetAtom(kTextPlain)) { 187 } else if (type_ == gfx::GetAtom(kString) ||
188 type_ == gfx::GetAtom(kTextPlain)) {
188 std::string result; 189 std::string result;
189 base::ConvertToUtf8AndNormalize(RefCountedMemoryToString(memory_), 190 base::ConvertToUtf8AndNormalize(RefCountedMemoryToString(memory_),
190 base::kCodepageLatin1, 191 base::kCodepageLatin1,
191 &result); 192 &result);
192 return result; 193 return result;
193 } else { 194 } else {
194 // BTW, I looked at COMPOUND_TEXT, and there's no way we're going to 195 // BTW, I looked at COMPOUND_TEXT, and there's no way we're going to
195 // support that. Yuck. 196 // support that. Yuck.
196 NOTREACHED(); 197 NOTREACHED();
197 return std::string(); 198 return std::string();
198 } 199 }
199 } 200 }
200 201
201 base::string16 SelectionData::GetHtml() const { 202 base::string16 SelectionData::GetHtml() const {
202 base::string16 markup; 203 base::string16 markup;
203 204
204 if (type_ == GetAtom(Clipboard::kMimeTypeHTML)) { 205 if (type_ == gfx::GetAtom(Clipboard::kMimeTypeHTML)) {
205 const unsigned char* data = GetData(); 206 const unsigned char* data = GetData();
206 size_t size = GetSize(); 207 size_t size = GetSize();
207 208
208 // If the data starts with 0xFEFF, i.e., Byte Order Mark, assume it is 209 // If the data starts with 0xFEFF, i.e., Byte Order Mark, assume it is
209 // UTF-16, otherwise assume UTF-8. 210 // UTF-16, otherwise assume UTF-8.
210 if (size >= 2 && 211 if (size >= 2 &&
211 reinterpret_cast<const uint16_t*>(data)[0] == 0xFEFF) { 212 reinterpret_cast<const uint16_t*>(data)[0] == 0xFEFF) {
212 markup.assign(reinterpret_cast<const uint16_t*>(data) + 1, 213 markup.assign(reinterpret_cast<const uint16_t*>(data) + 1,
213 (size / 2) - 1); 214 (size / 2) - 1);
214 } else { 215 } else {
(...skipping 13 matching lines...) Expand all
228 229
229 void SelectionData::AssignTo(std::string* result) const { 230 void SelectionData::AssignTo(std::string* result) const {
230 *result = RefCountedMemoryToString(memory_); 231 *result = RefCountedMemoryToString(memory_);
231 } 232 }
232 233
233 void SelectionData::AssignTo(base::string16* result) const { 234 void SelectionData::AssignTo(base::string16* result) const {
234 *result = RefCountedMemoryToString16(memory_); 235 *result = RefCountedMemoryToString16(memory_);
235 } 236 }
236 237
237 } // namespace ui 238 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/selection_requestor_unittest.cc ('k') | ui/base/x/x11_menu_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698