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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 // Write an extra flavor that signifies WebKit was the last to modify the | 129 // Write an extra flavor that signifies WebKit was the last to modify the |
130 // pasteboard. This flavor has no data. | 130 // pasteboard. This flavor has no data. |
131 void Clipboard::WriteWebSmartPaste() { | 131 void Clipboard::WriteWebSmartPaste() { |
132 NSPasteboard* pb = GetPasteboard(); | 132 NSPasteboard* pb = GetPasteboard(); |
133 NSString* format = base::SysUTF8ToNSString(GetWebKitSmartPasteFormatType()); | 133 NSString* format = base::SysUTF8ToNSString(GetWebKitSmartPasteFormatType()); |
134 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; | 134 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; |
135 [pb setData:nil forType:format]; | 135 [pb setData:nil forType:format]; |
136 } | 136 } |
137 | 137 |
138 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { | 138 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, |
| 139 Clipboard::Buffer buffer) const { |
| 140 DCHECK_EQ(buffer, BUFFER_STANDARD); |
139 NSString* format_ns = base::SysUTF8ToNSString(format); | 141 NSString* format_ns = base::SysUTF8ToNSString(format); |
140 | 142 |
141 NSPasteboard* pb = GetPasteboard(); | 143 NSPasteboard* pb = GetPasteboard(); |
142 NSArray* types = [pb types]; | 144 NSArray* types = [pb types]; |
143 | 145 |
144 return [types containsObject:format_ns]; | 146 return [types containsObject:format_ns]; |
145 } | 147 } |
146 | 148 |
147 void Clipboard::ReadText(string16* result) const { | 149 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { |
| 150 DCHECK_EQ(buffer, BUFFER_STANDARD); |
148 NSPasteboard* pb = GetPasteboard(); | 151 NSPasteboard* pb = GetPasteboard(); |
149 NSString* contents = [pb stringForType:NSStringPboardType]; | 152 NSString* contents = [pb stringForType:NSStringPboardType]; |
150 | 153 |
151 UTF8ToUTF16([contents UTF8String], | 154 UTF8ToUTF16([contents UTF8String], |
152 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], | 155 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], |
153 result); | 156 result); |
154 } | 157 } |
155 | 158 |
156 void Clipboard::ReadAsciiText(std::string* result) const { | 159 void Clipboard::ReadAsciiText(Clipboard::Buffer buffer, |
| 160 std::string* result) const { |
| 161 DCHECK_EQ(buffer, BUFFER_STANDARD); |
157 NSPasteboard* pb = GetPasteboard(); | 162 NSPasteboard* pb = GetPasteboard(); |
158 NSString* contents = [pb stringForType:NSStringPboardType]; | 163 NSString* contents = [pb stringForType:NSStringPboardType]; |
159 | 164 |
160 if (!contents) | 165 if (!contents) |
161 result->clear(); | 166 result->clear(); |
162 else | 167 else |
163 result->assign([contents UTF8String]); | 168 result->assign([contents UTF8String]); |
164 } | 169 } |
165 | 170 |
166 void Clipboard::ReadHTML(string16* markup, std::string* src_url) const { | 171 void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, |
| 172 std::string* src_url) const { |
| 173 DCHECK_EQ(buffer, BUFFER_STANDARD); |
167 if (markup) { | 174 if (markup) { |
168 NSPasteboard* pb = GetPasteboard(); | 175 NSPasteboard* pb = GetPasteboard(); |
169 NSArray *supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, | 176 NSArray *supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, |
170 NSStringPboardType, | 177 NSStringPboardType, |
171 nil]; | 178 nil]; |
172 NSString *bestType = [pb availableTypeFromArray:supportedTypes]; | 179 NSString *bestType = [pb availableTypeFromArray:supportedTypes]; |
173 NSString* contents = [pb stringForType:bestType]; | 180 NSString* contents = [pb stringForType:bestType]; |
174 UTF8ToUTF16([contents UTF8String], | 181 UTF8ToUTF16([contents UTF8String], |
175 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], | 182 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], |
176 markup); | 183 markup); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 static const std::string type = base::SysNSStringToUTF8(NSHTMLPboardType); | 282 static const std::string type = base::SysNSStringToUTF8(NSHTMLPboardType); |
276 return type; | 283 return type; |
277 } | 284 } |
278 | 285 |
279 // static | 286 // static |
280 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { | 287 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { |
281 static const std::string type = | 288 static const std::string type = |
282 base::SysNSStringToUTF8(kWebSmartPastePboardType); | 289 base::SysNSStringToUTF8(kWebSmartPastePboardType); |
283 return type; | 290 return type; |
284 } | 291 } |
OLD | NEW |