Changeset 57522 in webkit
- Timestamp:
- Apr 13, 2010 10:46:46 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r57521 r57522 1 2010-04-13 Stephan Aßmus <superstippi@gmx.de> 2 3 Reviewed by David Levin. 4 5 [Haiku] Use the system clipboard instead of a private clipboard. 6 Fix various problems in the previous implementation. 7 8 https://bugs.webkit.org/show_bug.cgi?id=37421 9 10 No new tests needed. 11 12 * platform/haiku/PasteboardHaiku.cpp: 13 (WebCore::Pasteboard::~Pasteboard): 14 (WebCore::Pasteboard::generalPasteboard): 15 - Don't leak the pasteboard at program exit. 16 (WebCore::AutoClipboardLocker::AutoClipboardLocker): 17 (WebCore::AutoClipboardLocker::~AutoClipboardLocker): 18 (WebCore::AutoClipboardLocker::isLocked): 19 - helper class for locking a BClipboard. 20 (WebCore::Pasteboard::writeSelection): 21 - Use AddData(B_MIME_TYPE) as required by clipboard protocol. 22 - Make sure we don't end up with unwanted UTF-8 characters for 23 regular line breaks. 24 (WebCore::Pasteboard::writePlainText): 25 - Use AddData(B_MIME_TYPE) as required by clipboard protocol. 26 (WebCore::Pasteboard::plainText): 27 - Use FindData(B_MIME_TYPE) as required by clipboard protocol. 28 (WebCore::Pasteboard::documentFragment): 29 - Implemented. 30 (WebCore::Pasteboard::writeURL): 31 - Needs to use AddData(B_MIME_TYPE) instead of AddString(). 32 (WebCore::Pasteboard::clear): 33 1 34 2010-04-13 Stephan Aßmus <superstippi@gmx.de> 2 35 -
trunk/WebCore/platform/haiku/PasteboardHaiku.cpp
r48710 r57522 2 2 * Copyright (C) 2006 Zack Rusin <zack@kde.org> 3 3 * Copyright (C) 2007 Ryan Leavengood <leavengood@gmail.com> 4 * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de> 4 5 * 5 6 * Redistribution and use in source and binary forms, with or without … … 22 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 24 * (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 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26 */ 26 27 … … 33 34 #include "KURL.h" 34 35 #include "NotImplemented.h" 36 #include "TextResourceDecoder.h" 35 37 #include "markup.h" 36 38 #include <support/Locker.h> … … 38 40 #include <Message.h> 39 41 #include <String.h> 42 #include <wtf/text/CString.h> 40 43 41 44 … … 46 49 } 47 50 51 Pasteboard::~Pasteboard() 52 { 53 } 54 48 55 Pasteboard* Pasteboard::generalPasteboard() 49 56 { 50 static Pasteboard* pasteboard = new Pasteboard(); 51 return pasteboard; 52 } 57 static Pasteboard pasteboard; 58 return &pasteboard; 59 } 60 61 // BClipboard unfortunately does not derive from BLocker, so we cannot use BAutolock. 62 class AutoClipboardLocker { 63 public: 64 AutoClipboardLocker(BClipboard* clipboard) 65 : m_clipboard(clipboard) 66 , m_isLocked(clipboard && clipboard->Lock()) 67 { 68 } 69 70 ~AutoClipboardLocker() 71 { 72 if (m_isLocked) 73 m_clipboard->Unlock(); 74 } 75 76 bool isLocked() const 77 { 78 return m_isLocked; 79 } 80 81 private: 82 BClipboard* m_clipboard; 83 bool m_isLocked; 84 }; 53 85 54 86 void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) 55 87 { 56 BClipboard clipboard("WebKit"); 57 if (!clipboard.Lock()) 58 return; 59 60 clipboard.Clear(); 61 BMessage* data = clipboard.Data(); 62 if (!data) 63 return; 64 65 data->AddString("text/plain", BString(frame->selectedText())); 66 clipboard.Commit(); 67 68 clipboard.Unlock(); 88 AutoClipboardLocker locker(be_clipboard); 89 if (!locker.isLocked()) 90 return; 91 92 be_clipboard->Clear(); 93 BMessage* data = be_clipboard->Data(); 94 if (!data) 95 return; 96 97 BString string(frame->selectedText()); 98 99 // Replace unwanted representation of blank lines 100 const char* utf8BlankLine = "\302\240\n"; 101 string.ReplaceAll(utf8BlankLine, "\n"); 102 103 data->AddData("text/plain", B_MIME_TYPE, string.String(), string.Length()); 104 105 BString markupString(createMarkup(selectedRange, 0, AnnotateForInterchange)); 106 data->AddData("text/html", B_MIME_TYPE, markupString.String(), markupString.Length()); 107 108 be_clipboard->Commit(); 69 109 } 70 110 71 111 void Pasteboard::writePlainText(const String& text) 72 112 { 73 BClipboard clipboard("WebKit"); 74 if (!clipboard.Lock()) 75 return; 76 77 clipboard.Clear(); 78 BMessage* data = clipboard.Data(); 79 if (!data) 80 return; 81 82 data->AddString("text/plain", BString(text)); 83 clipboard.Commit(); 84 85 clipboard.Unlock(); 113 AutoClipboardLocker locker(be_clipboard); 114 if (!locker.isLocked()) 115 return; 116 117 be_clipboard->Clear(); 118 BMessage* data = be_clipboard->Data(); 119 if (!data) 120 return; 121 122 BString string(text); 123 data->AddData("text/plain", B_MIME_TYPE, string.String(), string.Length()); 124 be_clipboard->Commit(); 86 125 } 87 126 … … 94 133 String Pasteboard::plainText(Frame* frame) 95 134 { 96 BClipboard clipboard("WebKit");97 if (! clipboard.Lock())135 AutoClipboardLocker locker(be_clipboard); 136 if (!locker.isLocked()) 98 137 return String(); 99 138 100 BMessage* data = clipboard.Data();139 BMessage* data = be_clipboard->Data(); 101 140 if (!data) 102 141 return String(); 103 142 143 const char* buffer = 0; 144 ssize_t bufferLength; 104 145 BString string; 105 data->FindString("text/plain", &string); 106 107 clipboard.Unlock(); 146 if (data->FindData("text/plain", B_MIME_TYPE, reinterpret_cast<const void**>(&buffer), &bufferLength) == B_OK) 147 string.Append(buffer, bufferLength); 108 148 109 149 return string; … … 113 153 bool allowPlainText, bool& chosePlainText) 114 154 { 155 chosePlainText = false; 156 157 AutoClipboardLocker locker(be_clipboard); 158 if (!locker.isLocked()) 159 return 0; 160 161 BMessage* data = be_clipboard->Data(); 162 if (!data) 163 return 0; 164 165 const char* buffer = 0; 166 ssize_t bufferLength; 167 if (data->FindData("text/html", B_MIME_TYPE, reinterpret_cast<const void**>(&buffer), &bufferLength) == B_OK) { 168 RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/plain", "UTF-8", true); 169 String html = decoder->decode(buffer, bufferLength); 170 html += decoder->flush(); 171 172 if (!html.isEmpty()) { 173 RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, "", FragmentScriptingNotAllowed); 174 if (fragment) 175 return fragment.release(); 176 } 177 } 178 179 if (!allowPlainText) 180 return 0; 181 182 if (data->FindData("text/plain", B_MIME_TYPE, reinterpret_cast<const void**>(&buffer), &bufferLength) == B_OK) { 183 BString plainText(buffer, bufferLength); 184 185 chosePlainText = true; 186 RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), plainText); 187 if (fragment) 188 return fragment.release(); 189 } 190 191 return 0; 192 } 193 194 void Pasteboard::writeURL(const KURL& url, const String&, Frame*) 195 { 196 AutoClipboardLocker locker(be_clipboard); 197 if (!locker.isLocked()) 198 return; 199 200 be_clipboard->Clear(); 201 202 BMessage* data = be_clipboard->Data(); 203 if (!data) 204 return; 205 206 BString string(url.string()); 207 data->AddData("text/plain", B_MIME_TYPE, string.String(), string.Length()); 208 be_clipboard->Commit(); 209 } 210 211 void Pasteboard::writeImage(Node*, const KURL&, const String&) 212 { 115 213 notImplemented(); 116 return 0;117 }118 119 void Pasteboard::writeURL(const KURL& url, const String&, Frame*)120 {121 BClipboard clipboard("WebKit");122 if (!clipboard.Lock())123 return;124 125 clipboard.Clear();126 127 BMessage* data = clipboard.Data();128 if (!data)129 return;130 131 data->AddString("text/plain", url.string());132 clipboard.Commit();133 134 clipboard.Unlock();135 }136 137 void Pasteboard::writeImage(Node*, const KURL&, const String&)138 {139 notImplemented();140 214 } 141 215 142 216 void Pasteboard::clear() 143 217 { 144 BClipboard clipboard("WebKit"); 145 if (!clipboard.Lock()) 146 return; 147 148 clipboard.Clear(); 149 clipboard.Commit(); 150 151 clipboard.Unlock(); 218 AutoClipboardLocker locker(be_clipboard); 219 if (!locker.isLocked()) 220 return; 221 222 be_clipboard->Clear(); 223 be_clipboard->Commit(); 152 224 } 153 225
Note: See TracChangeset
for help on using the changeset viewer.