| 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_utils.h" | 5 #include "ui/base/x/selection_utils.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/i18n/icu_string_conversions.h" | 9 #include "base/i18n/icu_string_conversions.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 std::vector< ::Atom>* output) { | 48 std::vector< ::Atom>* output) { |
| 49 for (std::vector< ::Atom>::const_iterator it = desired.begin(); | 49 for (std::vector< ::Atom>::const_iterator it = desired.begin(); |
| 50 it != desired.end(); ++it) { | 50 it != desired.end(); ++it) { |
| 51 std::vector< ::Atom>::const_iterator jt = | 51 std::vector< ::Atom>::const_iterator jt = |
| 52 std::find(offered.begin(), offered.end(), *it); | 52 std::find(offered.begin(), offered.end(), *it); |
| 53 if (jt != offered.end()) | 53 if (jt != offered.end()) |
| 54 output->push_back(*it); | 54 output->push_back(*it); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 void AddString16ToVector(const string16& str, | 58 void AddString16ToVector(const base::string16& str, |
| 59 std::vector<unsigned char>* bytes) { | 59 std::vector<unsigned char>* bytes) { |
| 60 const unsigned char* front = | 60 const unsigned char* front = |
| 61 reinterpret_cast<const unsigned char*>(str.data()); | 61 reinterpret_cast<const unsigned char*>(str.data()); |
| 62 bytes->insert(bytes->end(), front, front + (str.size() * 2)); | 62 bytes->insert(bytes->end(), front, front + (str.size() * 2)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 std::string RefCountedMemoryToString( | 65 std::string RefCountedMemoryToString( |
| 66 const scoped_refptr<base::RefCountedMemory>& memory) { | 66 const scoped_refptr<base::RefCountedMemory>& memory) { |
| 67 if (!memory.get()) { | 67 if (!memory.get()) { |
| 68 NOTREACHED(); | 68 NOTREACHED(); |
| 69 return std::string(); | 69 return std::string(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 size_t size = memory->size(); | 72 size_t size = memory->size(); |
| 73 if (!size) | 73 if (!size) |
| 74 return std::string(); | 74 return std::string(); |
| 75 | 75 |
| 76 const unsigned char* front = memory->front(); | 76 const unsigned char* front = memory->front(); |
| 77 return std::string(reinterpret_cast<const char*>(front), size); | 77 return std::string(reinterpret_cast<const char*>(front), size); |
| 78 } | 78 } |
| 79 | 79 |
| 80 string16 RefCountedMemoryToString16( | 80 base::string16 RefCountedMemoryToString16( |
| 81 const scoped_refptr<base::RefCountedMemory>& memory) { | 81 const scoped_refptr<base::RefCountedMemory>& memory) { |
| 82 if (!memory.get()) { | 82 if (!memory.get()) { |
| 83 NOTREACHED(); | 83 NOTREACHED(); |
| 84 return string16(); | 84 return base::string16(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 size_t size = memory->size(); | 87 size_t size = memory->size(); |
| 88 if (!size) | 88 if (!size) |
| 89 return string16(); | 89 return base::string16(); |
| 90 | 90 |
| 91 const unsigned char* front = memory->front(); | 91 const unsigned char* front = memory->front(); |
| 92 return string16(reinterpret_cast<const base::char16*>(front), size / 2); | 92 return base::string16(reinterpret_cast<const base::char16*>(front), size / 2); |
| 93 } | 93 } |
| 94 | 94 |
| 95 /////////////////////////////////////////////////////////////////////////////// | 95 /////////////////////////////////////////////////////////////////////////////// |
| 96 | 96 |
| 97 SelectionFormatMap::SelectionFormatMap() {} | 97 SelectionFormatMap::SelectionFormatMap() {} |
| 98 | 98 |
| 99 SelectionFormatMap::~SelectionFormatMap() {} | 99 SelectionFormatMap::~SelectionFormatMap() {} |
| 100 | 100 |
| 101 void SelectionFormatMap::Insert( | 101 void SelectionFormatMap::Insert( |
| 102 ::Atom atom, | 102 ::Atom atom, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 &result); | 184 &result); |
| 185 return result; | 185 return result; |
| 186 } else { | 186 } else { |
| 187 // BTW, I looked at COMPOUND_TEXT, and there's no way we're going to | 187 // BTW, I looked at COMPOUND_TEXT, and there's no way we're going to |
| 188 // support that. Yuck. | 188 // support that. Yuck. |
| 189 NOTREACHED(); | 189 NOTREACHED(); |
| 190 return std::string(); | 190 return std::string(); |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 | 193 |
| 194 string16 SelectionData::GetHtml() const { | 194 base::string16 SelectionData::GetHtml() const { |
| 195 string16 markup; | 195 base::string16 markup; |
| 196 | 196 |
| 197 if (type_ == atom_cache_.GetAtom(Clipboard::kMimeTypeHTML)) { | 197 if (type_ == atom_cache_.GetAtom(Clipboard::kMimeTypeHTML)) { |
| 198 const unsigned char* data = GetData(); | 198 const unsigned char* data = GetData(); |
| 199 size_t size = GetSize(); | 199 size_t size = GetSize(); |
| 200 | 200 |
| 201 // If the data starts with 0xFEFF, i.e., Byte Order Mark, assume it is | 201 // If the data starts with 0xFEFF, i.e., Byte Order Mark, assume it is |
| 202 // UTF-16, otherwise assume UTF-8. | 202 // UTF-16, otherwise assume UTF-8. |
| 203 if (size >= 2 && | 203 if (size >= 2 && |
| 204 reinterpret_cast<const uint16_t*>(data)[0] == 0xFEFF) { | 204 reinterpret_cast<const uint16_t*>(data)[0] == 0xFEFF) { |
| 205 markup.assign(reinterpret_cast<const uint16_t*>(data) + 1, | 205 markup.assign(reinterpret_cast<const uint16_t*>(data) + 1, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 216 } else { | 216 } else { |
| 217 NOTREACHED(); | 217 NOTREACHED(); |
| 218 return markup; | 218 return markup; |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 void SelectionData::AssignTo(std::string* result) const { | 222 void SelectionData::AssignTo(std::string* result) const { |
| 223 *result = RefCountedMemoryToString(memory_); | 223 *result = RefCountedMemoryToString(memory_); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void SelectionData::AssignTo(string16* result) const { | 226 void SelectionData::AssignTo(base::string16* result) const { |
| 227 *result = RefCountedMemoryToString16(memory_); | 227 *result = RefCountedMemoryToString16(memory_); |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace ui | 230 } // namespace ui |
| OLD | NEW |