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 #include "StringHash.h" 35 36 #include <support/Locker.h> 37 #include <app/Clipboard.h> 38 #include <Message.h> 39 #include <String.h> 40 #include <wtf/HashTable.h> 41 42 43 namespace WebCore { 44 45 ClipboardHaiku::ClipboardHaiku(ClipboardAccessPolicy policy, bool forDragging) 46 : Clipboard(policy, forDragging) 47 { 48 } 49 50 void ClipboardHaiku::clearData(const String& type) 51 { 52 if (be_clipboard->Lock()) { 53 BMessage* data = be_clipboard->Data(); 54 55 if (data) { 56 data->RemoveName(BString(type).String()); 57 be_clipboard->Commit(); 58 } 59 60 be_clipboard->Unlock(); 61 } 62 } 63 64 void ClipboardHaiku::clearAllData() 65 { 66 if (be_clipboard->Lock()) { 67 be_clipboard->Clear(); 68 be_clipboard->Commit(); 69 be_clipboard->Unlock(); 70 } 71 } 72 73 String ClipboardHaiku::getData(const String& type, bool& success) const 74 { 75 BString result; 76 success = false; 77 78 if (be_clipboard->Lock()) { 79 BMessage* data = be_clipboard->Data(); 80 81 if (data) 82 if (data->FindString(BString(type).String(), &result) == B_OK) 83 success = true; 84 85 be_clipboard->Unlock(); 86 } 87 88 return result; 89 } 90 91 bool ClipboardHaiku::setData(const String& type, const String& data) 92 { 93 bool result = false; 94 95 if (be_clipboard->Lock()) { 96 BMessage* bdata = be_clipboard->Data(); 97 98 if (bdata) { 99 bdata->RemoveName(BString(type).String()); 100 101 if (bdata->AddString(BString(type).String(), BString(data)) == B_OK) 102 result = true; 103 } 104 105 be_clipboard->Commit(); 106 be_clipboard->Unlock(); 107 } 108 109 return result; 110 } 111 112 // Extensions beyond IE's API. 113 HashSet<String> ClipboardHaiku::types() const 114 { 115 HashSet<String> result; 116 117 if (be_clipboard->Lock()) { 118 BMessage* data = be_clipboard->Data(); 119 120 if (data) { 121 char* name; 122 uint32 type; 123 int32 count; 124 125 for (int32 i = 0; data->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i++) 126 result.add(name); 127 } 128 129 be_clipboard->Unlock(); 130 } 131 132 return result; 133 } 134 135 PassRefPtr<FileList> ClipboardHaiku::files() const 136 { 137 notImplemented(); 138 return 0; 139 } 140 141 IntPoint ClipboardHaiku::dragLocation() const 142 { 143 notImplemented(); 144 return IntPoint(0, 0); 145 } 146 147 CachedImage* ClipboardHaiku::dragImage() const 148 { 149 notImplemented(); 150 return 0; 151 } 152 153 void ClipboardHaiku::setDragImage(CachedImage*, const IntPoint&) 154 { 155 notImplemented(); 156 } 157 158 Node* ClipboardHaiku::dragImageElement() 159 { 160 notImplemented(); 161 return 0; 162 } 163 164 void ClipboardHaiku::setDragImageElement(Node*, const IntPoint&) 165 { 166 notImplemented(); 167 } 168 169 DragImageRef ClipboardHaiku::createDragImage(IntPoint& dragLocation) const 170 { 171 notImplemented(); 172 return 0; 173 } 174 175 void ClipboardHaiku::declareAndWriteDragImage(Element*, const KURL&, const String&, Frame*) 176 { 177 notImplemented(); 178 } 179 180 void ClipboardHaiku::writeURL(const KURL&, const String&, Frame*) 181 { 182 notImplemented(); 183 } 184 185 void ClipboardHaiku::writeRange(Range*, Frame*) 186 { 187 notImplemented(); 188 } 189 190 void ClipboardHaiku::writePlainText(const String&) 191 { 192 notImplemented(); 193 } 194 195 bool ClipboardHaiku::hasData() 196 { 197 bool result = false; 198 199 if (be_clipboard->Lock()) { 200 BMessage* data = be_clipboard->Data(); 201 202 if (data) 203 result = !data->IsEmpty(); 204 205 be_clipboard->Unlock(); 206 } 207 208 return result; 209 } 210 211 } // namespace WebCore 212 213