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

Side by Side Diff: Source/WebCore/platform/mac/PlatformPasteboardMac.mm

Issue 13713003: Remove all of WebCore/platform/mac which is not mentioned in WebCore.gypi. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added back a couple needed headers Created 7 years, 8 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #import "config.h"
27 #import "Color.h"
28 #import "KURL.h"
29 #import "PlatformPasteboard.h"
30
31 namespace WebCore {
32
33 PlatformPasteboard::PlatformPasteboard(const String& pasteboardName)
34 : m_pasteboard([NSPasteboard pasteboardWithName:pasteboardName])
35 {
36 ASSERT(pasteboardName);
37 }
38
39 void PlatformPasteboard::getTypes(Vector<String>& types)
40 {
41 NSArray *pasteboardTypes = [m_pasteboard.get() types];
42
43 for (NSUInteger i = 0; i < [pasteboardTypes count]; i++)
44 types.append([pasteboardTypes objectAtIndex:i]);
45 }
46
47 PassRefPtr<SharedBuffer> PlatformPasteboard::bufferForType(const String& pastebo ardType)
48 {
49 NSData *data = [m_pasteboard.get() dataForType:pasteboardType];
50 if (!data)
51 return 0;
52 return SharedBuffer::wrapNSData([[data copy] autorelease]);
53 }
54
55 void PlatformPasteboard::getPathnamesForType(Vector<String>& pathnames, const St ring& pasteboardType)
56 {
57 NSArray* paths = [m_pasteboard.get() propertyListForType:pasteboardType];
58 if ([paths isKindOfClass:[NSString class]]) {
59 pathnames.append((NSString *)paths);
60 return;
61 }
62 for (NSUInteger i = 0; i < [paths count]; i++)
63 pathnames.append([paths objectAtIndex:i]);
64 }
65
66 String PlatformPasteboard::stringForType(const String& pasteboardType)
67 {
68 if (pasteboardType == String(NSURLPboardType))
69 return [[NSURL URLFromPasteboard:m_pasteboard.get()] absoluteString];
70
71 return [m_pasteboard.get() stringForType:pasteboardType];
72 }
73
74 int PlatformPasteboard::changeCount() const
75 {
76 return [m_pasteboard.get() changeCount];
77 }
78
79 String PlatformPasteboard::uniqueName()
80 {
81 return [[NSPasteboard pasteboardWithUniqueName] name];
82 }
83
84 Color PlatformPasteboard::color()
85 {
86 NSColor *color = [NSColor colorFromPasteboard:m_pasteboard.get()];
87
88 // The color may not be in an RGB colorspace. This commonly occurs when a co lor is
89 // dragged from the NSColorPanel grayscale picker.
90 if ([[color colorSpace] colorSpaceModel] != NSRGBColorSpaceModel)
91 color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
92
93 return makeRGBA((int)([color redComponent] * 255.0 + 0.5), (int)([color gree nComponent] * 255.0 + 0.5),
94 (int)([color blueComponent] * 255.0 + 0.5), (int)([color alp haComponent] * 255.0 + 0.5));
95 }
96
97 KURL PlatformPasteboard::url()
98 {
99 return [NSURL URLFromPasteboard:m_pasteboard.get()];
100 }
101
102 void PlatformPasteboard::copy(const String& fromPasteboard)
103 {
104 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:fromPasteboard];
105 NSArray* types = [pasteboard types];
106
107 [m_pasteboard.get() addTypes:types owner:nil];
108 for (NSUInteger i = 0; i < [types count]; i++) {
109 NSString* type = [types objectAtIndex:i];
110 [m_pasteboard.get() setData:[pasteboard dataForType:type] forType:type];
111 }
112 }
113
114 void PlatformPasteboard::addTypes(const Vector<String>& pasteboardTypes)
115 {
116 RetainPtr<NSMutableArray> types(AdoptNS, [[NSMutableArray alloc] init]);
117 for (size_t i = 0; i < pasteboardTypes.size(); ++i)
118 [types.get() addObject:pasteboardTypes[i]];
119
120 [m_pasteboard.get() addTypes:types.get() owner:nil];
121 }
122
123 void PlatformPasteboard::setTypes(const Vector<String>& pasteboardTypes)
124 {
125 if (pasteboardTypes.isEmpty()) {
126 [m_pasteboard.get() declareTypes:nil owner:nil];
127 return;
128 }
129
130 RetainPtr<NSMutableArray> types(AdoptNS, [[NSMutableArray alloc] init]);
131 for (size_t i = 0; i < pasteboardTypes.size(); ++i)
132 [types.get() addObject:pasteboardTypes[i]];
133
134 [m_pasteboard.get() declareTypes:types.get() owner:nil];
135 }
136
137 void PlatformPasteboard::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType)
138 {
139 [m_pasteboard.get() setData:buffer ? [buffer->createNSData() autorelease] : nil forType:pasteboardType];
140 }
141
142 void PlatformPasteboard::setPathnamesForType(const Vector<String>& pathnames, co nst String& pasteboardType)
143 {
144 RetainPtr<NSMutableArray> paths(AdoptNS, [[NSMutableArray alloc] init]);
145 for (size_t i = 0; i < pathnames.size(); ++i)
146 [paths.get() addObject: [NSArray arrayWithObject:pathnames[i]]];
147 [m_pasteboard.get() setPropertyList:paths.get() forType:pasteboardType];
148 }
149
150 void PlatformPasteboard::setStringForType(const String& string, const String& pa steboardType)
151 {
152 if (pasteboardType == String(NSURLPboardType))
153 [[NSURL URLWithString:string] writeToPasteboard:m_pasteboard.get()];
154 else
155 [m_pasteboard.get() setString:string forType:pasteboardType];
156 }
157
158 }
OLDNEW
« no previous file with comments | « Source/WebCore/platform/mac/PlatformEventFactoryMac.mm ('k') | Source/WebCore/platform/mac/PlatformScreenMac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698