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

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

Issue 18308004: Update CrOS to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura/window.cc ('k') | no next file » | 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 <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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 void AddString16ToVector(const string16& str, 61 void AddString16ToVector(const string16& str,
62 std::vector<unsigned char>* bytes) { 62 std::vector<unsigned char>* bytes) {
63 const unsigned char* front = 63 const unsigned char* front =
64 reinterpret_cast<const unsigned char*>(str.data()); 64 reinterpret_cast<const unsigned char*>(str.data());
65 bytes->insert(bytes->end(), front, front + (str.size() * 2)); 65 bytes->insert(bytes->end(), front, front + (str.size() * 2));
66 } 66 }
67 67
68 std::string RefCountedMemoryToString( 68 std::string RefCountedMemoryToString(
69 const scoped_refptr<base::RefCountedMemory>& memory) { 69 const scoped_refptr<base::RefCountedMemory>& memory) {
70 if (!memory) { 70 if (!memory.get()) {
71 NOTREACHED(); 71 NOTREACHED();
72 return std::string(); 72 return std::string();
73 } 73 }
74 74
75 size_t size = memory->size(); 75 size_t size = memory->size();
76 if (!size) 76 if (!size)
77 return std::string(); 77 return std::string();
78 78
79 const unsigned char* front = memory->front(); 79 const unsigned char* front = memory->front();
80 return std::string(reinterpret_cast<const char*>(front), size); 80 return std::string(reinterpret_cast<const char*>(front), size);
81 } 81 }
82 82
83 string16 RefCountedMemoryToString16( 83 string16 RefCountedMemoryToString16(
84 const scoped_refptr<base::RefCountedMemory>& memory) { 84 const scoped_refptr<base::RefCountedMemory>& memory) {
85 if (!memory) { 85 if (!memory.get()) {
86 NOTREACHED(); 86 NOTREACHED();
87 return string16(); 87 return string16();
88 } 88 }
89 89
90 size_t size = memory->size(); 90 size_t size = memory->size();
91 if (!size) 91 if (!size)
92 return string16(); 92 return string16();
93 93
94 const unsigned char* front = memory->front(); 94 const unsigned char* front = memory->front();
95 return string16(reinterpret_cast<const base::char16*>(front), size / 2); 95 return string16(reinterpret_cast<const base::char16*>(front), size / 2);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 161
162 bool SelectionData::IsValid() const { 162 bool SelectionData::IsValid() const {
163 return type_ != None; 163 return type_ != None;
164 } 164 }
165 165
166 ::Atom SelectionData::GetType() const { 166 ::Atom SelectionData::GetType() const {
167 return type_; 167 return type_;
168 } 168 }
169 169
170 const unsigned char* SelectionData::GetData() const { 170 const unsigned char* SelectionData::GetData() const {
171 return memory_ ? memory_->front() : NULL; 171 return memory_.get() ? memory_->front() : NULL;
172 } 172 }
173 173
174 size_t SelectionData::GetSize() const { 174 size_t SelectionData::GetSize() const {
175 return memory_ ? memory_->size() : 0; 175 return memory_.get() ? memory_->size() : 0;
176 } 176 }
177 177
178 std::string SelectionData::GetText() const { 178 std::string SelectionData::GetText() const {
179 if (type_ == atom_cache_.GetAtom(kUtf8String) || 179 if (type_ == atom_cache_.GetAtom(kUtf8String) ||
180 type_ == atom_cache_.GetAtom(kText)) { 180 type_ == atom_cache_.GetAtom(kText)) {
181 return RefCountedMemoryToString(memory_); 181 return RefCountedMemoryToString(memory_);
182 } else if (type_ == atom_cache_.GetAtom(kString)) { 182 } else if (type_ == atom_cache_.GetAtom(kString)) {
183 std::string result; 183 std::string result;
184 base::ConvertToUtf8AndNormalize(RefCountedMemoryToString(memory_), 184 base::ConvertToUtf8AndNormalize(RefCountedMemoryToString(memory_),
185 base::kCodepageLatin1, 185 base::kCodepageLatin1,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 223
224 void SelectionData::AssignTo(std::string* result) const { 224 void SelectionData::AssignTo(std::string* result) const {
225 *result = RefCountedMemoryToString(memory_); 225 *result = RefCountedMemoryToString(memory_);
226 } 226 }
227 227
228 void SelectionData::AssignTo(string16* result) const { 228 void SelectionData::AssignTo(string16* result) const {
229 *result = RefCountedMemoryToString16(memory_); 229 *result = RefCountedMemoryToString16(memory_);
230 } 230 }
231 231
232 } // namespace ui 232 } // namespace ui
OLDNEW
« no previous file with comments | « ui/aura/window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698