OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/clipboard.h" | 5 #include "base/clipboard.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 [pb setData:nil forType:GetWebKitSmartPasteFormatType()]; | 133 [pb setData:nil forType:GetWebKitSmartPasteFormatType()]; |
134 } | 134 } |
135 | 135 |
136 bool Clipboard::IsFormatAvailable(NSString* format) const { | 136 bool Clipboard::IsFormatAvailable(NSString* format) const { |
137 NSPasteboard* pb = GetPasteboard(); | 137 NSPasteboard* pb = GetPasteboard(); |
138 NSArray* types = [pb types]; | 138 NSArray* types = [pb types]; |
139 | 139 |
140 return [types containsObject:format]; | 140 return [types containsObject:format]; |
141 } | 141 } |
142 | 142 |
143 void Clipboard::ReadText(std::wstring* result) const { | 143 void Clipboard::ReadText(string16* result) const { |
144 NSPasteboard* pb = GetPasteboard(); | 144 NSPasteboard* pb = GetPasteboard(); |
145 NSString* contents = [pb stringForType:NSStringPboardType]; | 145 NSString* contents = [pb stringForType:NSStringPboardType]; |
146 | 146 |
147 UTF8ToWide([contents UTF8String], | 147 UTF8ToUTF16([contents UTF8String], |
148 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], | 148 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], |
149 result); | 149 result); |
150 } | 150 } |
151 | 151 |
152 void Clipboard::ReadAsciiText(std::string* result) const { | 152 void Clipboard::ReadAsciiText(std::string* result) const { |
153 NSPasteboard* pb = GetPasteboard(); | 153 NSPasteboard* pb = GetPasteboard(); |
154 NSString* contents = [pb stringForType:NSStringPboardType]; | 154 NSString* contents = [pb stringForType:NSStringPboardType]; |
155 | 155 |
156 if (!contents) | 156 if (!contents) |
157 result->clear(); | 157 result->clear(); |
158 else | 158 else |
159 result->assign([contents UTF8String]); | 159 result->assign([contents UTF8String]); |
160 } | 160 } |
161 | 161 |
162 void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const { | 162 void Clipboard::ReadHTML(string16* markup, std::string* src_url) const { |
163 if (markup) { | 163 if (markup) { |
164 NSPasteboard* pb = GetPasteboard(); | 164 NSPasteboard* pb = GetPasteboard(); |
165 NSArray *supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, | 165 NSArray *supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, |
166 NSStringPboardType, | 166 NSStringPboardType, |
167 nil]; | 167 nil]; |
168 NSString *bestType = [pb availableTypeFromArray:supportedTypes]; | 168 NSString *bestType = [pb availableTypeFromArray:supportedTypes]; |
169 NSString* contents = [pb stringForType:bestType]; | 169 NSString* contents = [pb stringForType:bestType]; |
170 UTF8ToWide([contents UTF8String], | 170 UTF8ToUTF16([contents UTF8String], |
171 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], | 171 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], |
172 markup); | 172 markup); |
173 } | 173 } |
174 | 174 |
175 // TODO(avi): src_url? | 175 // TODO(avi): src_url? |
176 if (src_url) | 176 if (src_url) |
177 src_url->clear(); | 177 src_url->clear(); |
178 } | 178 } |
179 | 179 |
180 void Clipboard::ReadBookmark(std::wstring* title, std::string* url) const { | 180 void Clipboard::ReadBookmark(string16* title, std::string* url) const { |
181 NSPasteboard* pb = GetPasteboard(); | 181 NSPasteboard* pb = GetPasteboard(); |
182 | 182 |
183 if (title) { | 183 if (title) { |
184 NSString* contents = [pb stringForType:kUTTypeURLName]; | 184 NSString* contents = [pb stringForType:kUTTypeURLName]; |
185 UTF8ToWide([contents UTF8String], | 185 UTF8ToUTF16([contents UTF8String], |
186 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], | 186 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], |
187 title); | 187 title); |
188 } | 188 } |
189 | 189 |
190 if (url) { | 190 if (url) { |
191 NSString* url_string = [[NSURL URLFromPasteboard:pb] absoluteString]; | 191 NSString* url_string = [[NSURL URLFromPasteboard:pb] absoluteString]; |
192 if (!url_string) | 192 if (!url_string) |
193 url->clear(); | 193 url->clear(); |
194 else | 194 else |
195 url->assign([url_string UTF8String]); | 195 url->assign([url_string UTF8String]); |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 void Clipboard::ReadFile(std::wstring* file) const { | 199 void Clipboard::ReadFile(FilePath* file) const { |
200 if (!file) { | 200 if (!file) { |
201 NOTREACHED(); | 201 NOTREACHED(); |
202 return; | 202 return; |
203 } | 203 } |
204 | 204 |
205 file->clear(); | 205 file->clear(); |
206 std::vector<std::wstring> files; | 206 std::vector<string16> files; |
207 ReadFiles(&files); | 207 ReadFiles(&files); |
208 | 208 |
209 // Take the first file, if available. | 209 // Take the first file, if available. |
210 if (!files.empty()) | 210 if (!files.empty()) |
211 file->assign(files[0]); | 211 file->assign(files[0]); |
212 } | 212 } |
213 | 213 |
214 void Clipboard::ReadFiles(std::vector<std::wstring>* files) const { | 214 void Clipboard::ReadFiles(std::vector<string16>* files) const { |
215 if (!files) { | 215 if (!files) { |
216 NOTREACHED(); | 216 NOTREACHED(); |
217 return; | 217 return; |
218 } | 218 } |
219 | 219 |
220 files->clear(); | 220 files->clear(); |
221 | 221 |
222 NSPasteboard* pb = GetPasteboard(); | 222 NSPasteboard* pb = GetPasteboard(); |
223 NSArray* fileList = [pb propertyListForType:NSFilenamesPboardType]; | 223 NSArray* fileList = [pb propertyListForType:NSFilenamesPboardType]; |
224 | 224 |
225 for (unsigned int i = 0; i < [fileList count]; ++i) { | 225 for (unsigned int i = 0; i < [fileList count]; ++i) { |
226 std::wstring file = UTF8ToWide([[fileList objectAtIndex:i] UTF8String]); | 226 string16 file = UTF8ToUTF16([[fileList objectAtIndex:i] UTF8String]); |
227 files->push_back(file); | 227 files->push_back(file); |
228 } | 228 } |
229 } | 229 } |
230 | 230 |
231 // static | 231 // static |
232 Clipboard::FormatType Clipboard::GetUrlFormatType() { | 232 Clipboard::FormatType Clipboard::GetUrlFormatType() { |
233 return NSURLPboardType; | 233 return NSURLPboardType; |
234 } | 234 } |
235 | 235 |
236 // static | 236 // static |
(...skipping 23 matching lines...) Expand all Loading... |
260 | 260 |
261 // static | 261 // static |
262 Clipboard::FormatType Clipboard::GetHtmlFormatType() { | 262 Clipboard::FormatType Clipboard::GetHtmlFormatType() { |
263 return NSHTMLPboardType; | 263 return NSHTMLPboardType; |
264 } | 264 } |
265 | 265 |
266 // static | 266 // static |
267 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { | 267 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { |
268 return kWebSmartPastePboardType; | 268 return kWebSmartPastePboardType; |
269 } | 269 } |
OLD | NEW |