1 /* 2 * Copyright (C) 2007 Apple Inc. All rights reserved. 3 * Copyright (C) 2007 Ryan Leavengood <leavengood (at) gmail.com> 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include "config.h" 28 #include "ClipboardHaiku.h" 29 30 #include "FileList.h" 31 #include "IntPoint.h" 32 #include "NotImplemented.h" 33 #include "PlatformString.h" 34 35 #include <support/Locker.h> 36 #include <app/Clipboard.h> 37 #include <Message.h> 38 #include <String.h> 39 #include <wtf/HashTable.h> 40 #include <wtf/text/StringHash.h> 41 42 43 namespace WebCore { 44 45 PassRefPtr<Clipboard> Clipboard::create(ClipboardAccessPolicy policy, DragData*, Frame*) 46 { 47 return ClipboardHaiku::create(policy, DragAndDrop); 48 } 49 50 ClipboardHaiku::ClipboardHaiku(ClipboardAccessPolicy policy, ClipboardType clipboardType) 51 : Clipboard(policy, clipboardType) 52 { 53 } 54 55 void ClipboardHaiku::clearData(const String& type) 56 { 57 if (be_clipboard->Lock()) { 58 BMessage* data = be_clipboard->Data(); 59 60 if (data) { 61 data->RemoveName(BString(type).String()); 62 be_clipboard->Commit(); 63 } 64 65 be_clipboard->Unlock(); 66 } 67 } 68 69 void ClipboardHaiku::clearAllData() 70 { 71 if (be_clipboard->Lock()) { 72 be_clipboard->Clear(); 73 be_clipboard->Commit(); 74 be_clipboard->Unlock(); 75 } 76 } 77 78 String ClipboardHaiku::getData(const String& type, bool& success) const 79 { 80 BString result; 81 success = false; 82 83 if (be_clipboard->Lock()) { 84 BMessage* data = be_clipboard->Data(); 85 86 if (data) 87 if (data->FindString(BString(type).String(), &result) == B_OK) 88 success = true; 89 90 be_clipboard->Unlock(); 91 } 92 93 return result; 94 } 95 96 bool ClipboardHaiku::setData(const String& type, const String& data) 97 { 98 bool result = false; 99 100 if (be_clipboard->Lock()) { 101 BMessage* bdata = be_clipboard->Data(); 102 103 if (bdata) { 104 bdata->RemoveName(BString(type).String()); 105 106 if (bdata->AddString(BString(type).String(), BString(data)) == B_OK) 107 result = true; 108 } 109 110 be_clipboard->Commit(); 111 be_clipboard->Unlock(); 112 } 113 114 return result; 115 } 116 117 // Extensions beyond IE's API. 118 HashSet<String> ClipboardHaiku::types() const 119 { 120 HashSet<String> result; 121 122 if (be_clipboard->Lock()) { 123 BMessage* data = be_clipboard->Data(); 124 125 if (data) { 126 char* name; 127 uint32 type; 128 int32 count; 129 130 for (int32 i = 0; data->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i++) 131 result.add(name); 132 } 133 134 be_clipboard->Unlock(); 135 } 136 137 return result; 138 } 139 140 PassRefPtr<FileList> ClipboardHaiku::files() const 141 { 142 notImplemented(); 143 return 0; 144 } 145 146 IntPoint ClipboardHaiku::dragLocation() const 147 { 148 notImplemented(); 149 return IntPoint(0, 0); 150 } 151 152 CachedImage* ClipboardHaiku::dragImage() const 153 { 154 notImplemented(); 155 return 0; 156 } 157 158 void ClipboardHaiku::setDragImage(CachedImage*, const IntPoint&) 159 { 160 notImplemented(); 161 } 162 163 Node* ClipboardHaiku::dragImageElement() 164 { 165 notImplemented(); 166 return 0; 167 } 168 169 void ClipboardHaiku::setDragImageElement(Node*, const IntPoint&) 170 { 171 notImplemented(); 172 } 173 174 DragImageRef ClipboardHaiku::createDragImage(IntPoint& dragLocation) const 175 { 176 notImplemented(); 177 return 0; 178 } 179 180 void ClipboardHaiku::declareAndWriteDragImage(Element*, const KURL&, const String&, Frame*) 181 { 182 notImplemented(); 183 } 184 185 void ClipboardHaiku::writeURL(const KURL&, const String&, Frame*) 186 { 187 notImplemented(); 188 } 189 190 void ClipboardHaiku::writeRange(Range*, Frame*) 191 { 192 notImplemented(); 193 } 194 195 void ClipboardHaiku::writePlainText(const String&) 196 { 197 notImplemented(); 198 } 199 200 bool ClipboardHaiku::hasData() 201 { 202 bool result = false; 203 204 if (be_clipboard->Lock()) { 205 BMessage* data = be_clipboard->Data(); 206 207 if (data) 208 result = !data->IsEmpty(); 209 210 be_clipboard->Unlock(); 211 } 212 213 return result; 214 } 215 216 } // namespace WebCore 217 218