Changeset 63734 in webkit
- Timestamp:
- Jul 20, 2010 1:43:44 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r63732 r63734 1 2010-07-20 Tony Chang <tony@chromium.org> 2 3 Reviewed by Kent Tamura. 4 5 clean up style in ClipboardWin and PasteboardWin 6 https://bugs.webkit.org/show_bug.cgi?id=42609 7 8 No new tests since this is just a style cleanup. 9 10 * platform/win/ClipboardUtilitiesWin.cpp: 11 (WebCore::createGlobalData): 12 (WebCore::markupToCFHTML): 13 (WebCore::getURL): 14 (WebCore::getPlainText): 15 (WebCore::getTextHTML): 16 (WebCore::fragmentFromFilenames): 17 (WebCore::containsFilenames): 18 (WebCore::fragmentFromCFHTML): 19 (WebCore::fragmentFromHTML): 20 * platform/win/ClipboardUtilitiesWin.h: 21 * platform/win/ClipboardWin.cpp: 22 (WebCore::pathRemoveBadFSCharacters): 23 (WebCore::createGlobalHDropContent): 24 (WebCore::createGlobalUrlFileDescriptor): 25 (WebCore::writeURL): 26 (WebCore::ClipboardWin::clearData): 27 (WebCore::ClipboardWin::clearAllData): 28 (WebCore::ClipboardWin::getData): 29 (WebCore::ClipboardWin::types): 30 (WebCore::ClipboardWin::declareAndWriteDragImage): 31 (WebCore::ClipboardWin::writeRange): 32 * platform/win/ClipboardWin.h: 33 (WebCore::ClipboardWin::create): 34 (WebCore::ClipboardWin::dataObject): 35 * platform/win/PasteboardWin.cpp: 36 (WebCore::PasteboardOwnerWndProc): 37 (WebCore::Pasteboard::writeSelection): 38 (WebCore::Pasteboard::writeURL): 39 (WebCore::Pasteboard::plainText): 40 (WebCore::Pasteboard::documentFragment): 41 1 42 2010-07-20 Yury Semikhatsky <yurys@chromium.org> 2 43 -
trunk/WebCore/platform/win/ClipboardUtilitiesWin.cpp
r60957 r63734 33 33 #include "markup.h" 34 34 #include <CoreFoundation/CoreFoundation.h> 35 #include <shlwapi.h> 36 #include <wininet.h> // for INTERNET_MAX_URL_LENGTH 35 37 #include <wtf/RetainPtr.h> 36 38 #include <wtf/text/CString.h> 37 #include <shlwapi.h>38 #include <wininet.h> // for INTERNET_MAX_URL_LENGTH39 39 40 40 namespace WebCore { … … 98 98 } 99 99 100 // Firefox text/html100 // Firefox text/html 101 101 static FORMATETC* texthtmlFormat() 102 102 { … … 110 110 String mutableURL(url.string()); 111 111 String mutableTitle(title); 112 SIZE_T size = mutableURL.length() + mutableTitle.length() + 2; 112 SIZE_T size = mutableURL.length() + mutableTitle.length() + 2; // +1 for "\n" and +1 for null terminator 113 113 HGLOBAL cbData = ::GlobalAlloc(GPTR, size * sizeof(UChar)); 114 114 … … 156 156 157 157 // Documentation for the CF_HTML format is available at http://msdn.microsoft.com/workshop/networking/clipboard/htmlclipboard.asp 158 void markupToCF _HTML(const String& markup, const String& srcURL, Vector<char>& result)158 void markupToCFHTML(const String& markup, const String& srcURL, Vector<char>& result) 159 159 { 160 160 if (markup.isEmpty()) … … 257 257 } 258 258 259 // MSIE HTML Format259 // MSIE HTML Format 260 260 FORMATETC* htmlFormat() 261 261 { … … 295 295 String url; 296 296 success = false; 297 if (getWebLocData(dataObject, url, title)) { 298 success = true; 299 return url; 300 } else if (SUCCEEDED(dataObject->GetData(urlWFormat(), &store))) { 301 //URL using unicode 297 if (getWebLocData(dataObject, url, title)) 298 success = true; 299 else if (SUCCEEDED(dataObject->GetData(urlWFormat(), &store))) { 300 // URL using Unicode 302 301 UChar* data = (UChar*)GlobalLock(store.hGlobal); 303 302 url = extractURL(String(data), title); … … 306 305 success = true; 307 306 } else if (SUCCEEDED(dataObject->GetData(urlFormat(), &store))) { 308 // URL using ascii307 // URL using ASCII 309 308 char* data = (char*)GlobalLock(store.hGlobal); 310 309 url = extractURL(String(data), title); … … 350 349 success = false; 351 350 if (SUCCEEDED(dataObject->GetData(plainTextWFormat(), &store))) { 352 // unicode text351 // Unicode text 353 352 UChar* data = (UChar*)GlobalLock(store.hGlobal); 354 353 text = String(data); … … 357 356 success = true; 358 357 } else if (SUCCEEDED(dataObject->GetData(plainTextFormat(), &store))) { 359 // asciitext358 // ASCII text 360 359 char* data = (char*)GlobalLock(store.hGlobal); 361 360 text = String(data); … … 373 372 } 374 373 374 String getTextHTML(IDataObject* data, bool& success) 375 { 376 STGMEDIUM store; 377 String html; 378 success = false; 379 if (SUCCEEDED(data->GetData(texthtmlFormat(), &store))) { 380 UChar* data = static_cast<UChar*>(GlobalLock(store.hGlobal)); 381 html = String(data); 382 GlobalUnlock(store.hGlobal); 383 ReleaseStgMedium(&store); 384 success = true; 385 } 386 return html; 387 } 388 375 389 PassRefPtr<DocumentFragment> fragmentFromFilenames(Document*, const IDataObject*) 376 390 { 377 // FIXME: We should be able to create fragments from files391 // FIXME: We should be able to create fragments from files 378 392 return 0; 379 393 } … … 381 395 bool containsFilenames(const IDataObject*) 382 396 { 383 // FIXME: We'll want to update this once we can produce fragments from files397 // FIXME: We'll want to update this once we can produce fragments from files 384 398 return false; 385 399 } 386 400 387 // Convert a String containing CF_HTML formatted text to a DocumentFragment388 PassRefPtr<DocumentFragment> fragmentFromCF _HTML(Document* doc, const String& cf_html)401 // Convert a String containing CF_HTML formatted text to a DocumentFragment 402 PassRefPtr<DocumentFragment> fragmentFromCFHTML(Document* doc, const String& cfhtml) 389 403 { 390 404 // obtain baseURL if present 391 405 String srcURLStr("sourceURL:"); 392 406 String srcURL; 393 unsigned lineStart = cf _html.find(srcURLStr, 0, false);407 unsigned lineStart = cfhtml.find(srcURLStr, 0, false); 394 408 if (lineStart != -1) { 395 unsigned srcEnd = cf _html.find("\n", lineStart, false);409 unsigned srcEnd = cfhtml.find("\n", lineStart, false); 396 410 unsigned srcStart = lineStart+srcURLStr.length(); 397 String rawSrcURL = cf _html.substring(srcStart, srcEnd-srcStart);411 String rawSrcURL = cfhtml.substring(srcStart, srcEnd-srcStart); 398 412 replaceNBSPWithSpace(rawSrcURL); 399 413 srcURL = rawSrcURL.stripWhiteSpace(); … … 401 415 402 416 // find the markup between "<!--StartFragment -->" and "<!--EndFragment -->", accounting for browser quirks 403 unsigned markupStart = cf _html.find("<html", 0, false);404 unsigned tagStart = cf _html.find("startfragment", markupStart, false);405 unsigned fragmentStart = cf _html.find('>', tagStart) + 1;406 unsigned tagEnd = cf _html.find("endfragment", fragmentStart, false);407 unsigned fragmentEnd = cf _html.reverseFind('<', tagEnd);408 String markup = cf _html.substring(fragmentStart, fragmentEnd - fragmentStart).stripWhiteSpace();417 unsigned markupStart = cfhtml.find("<html", 0, false); 418 unsigned tagStart = cfhtml.find("startfragment", markupStart, false); 419 unsigned fragmentStart = cfhtml.find('>', tagStart) + 1; 420 unsigned tagEnd = cfhtml.find("endfragment", fragmentStart, false); 421 unsigned fragmentEnd = cfhtml.reverseFind('<', tagEnd); 422 String markup = cfhtml.substring(fragmentStart, fragmentEnd - fragmentStart).stripWhiteSpace(); 409 423 410 424 return createFragmentFromMarkup(doc, markup, srcURL, FragmentScriptingNotAllowed); … … 421 435 String srcURL; 422 436 if (SUCCEEDED(data->GetData(htmlFormat(), &store))) { 423 // MS HTML Format parsing437 // MS HTML Format parsing 424 438 char* data = (char*)GlobalLock(store.hGlobal); 425 439 SIZE_T dataSize = ::GlobalSize(store.hGlobal); 426 String cf _html(UTF8Encoding().decode(data, dataSize));440 String cfhtml(UTF8Encoding().decode(data, dataSize)); 427 441 GlobalUnlock(store.hGlobal); 428 442 ReleaseStgMedium(&store); 429 if (PassRefPtr<DocumentFragment> fragment = fragmentFromCF _HTML(doc, cf_html))443 if (PassRefPtr<DocumentFragment> fragment = fragmentFromCFHTML(doc, cfhtml)) 430 444 return fragment; 431 445 } 432 if (SUCCEEDED(data->GetData(texthtmlFormat(), &store))) { 433 //raw html 434 UChar* data = (UChar*)GlobalLock(store.hGlobal); 435 html = String(data); 436 GlobalUnlock(store.hGlobal); 437 ReleaseStgMedium(&store); 446 bool success = false; 447 html = getTextHTML(data, success); 448 if (success) 438 449 return createFragmentFromMarkup(doc, html, srcURL, FragmentScriptingNotAllowed); 439 }440 450 441 451 return 0; -
trunk/WebCore/platform/win/ClipboardUtilitiesWin.h
r60957 r63734 50 50 FORMATETC* smartPasteFormat(); 51 51 52 void markupToCF _HTML(const String& markup, const String& srcURL, Vector<char>& result);52 void markupToCFHTML(const String& markup, const String& srcURL, Vector<char>& result); 53 53 54 54 void replaceNewlinesWithWindowsStyleNewlines(String&); … … 60 60 PassRefPtr<DocumentFragment> fragmentFromFilenames(Document*, const IDataObject*); 61 61 PassRefPtr<DocumentFragment> fragmentFromHTML(Document*, IDataObject*); 62 PassRefPtr<DocumentFragment> fragmentFromCF _HTML(Document*, const String& cf_html);62 PassRefPtr<DocumentFragment> fragmentFromCFHTML(Document*, const String& cfhtml); 63 63 64 64 String getURL(IDataObject*, DragData::FilenameConversionPolicy, bool& success, String* title = 0); 65 65 String getPlainText(IDataObject*, bool& success); 66 String getTextHTML(IDataObject*, bool& success); 66 67 67 68 } // namespace WebCore 68 69 69 70 #endif // ClipboardUtilitiesWin_h 70 -
trunk/WebCore/platform/win/ClipboardWin.cpp
r60957 r63734 106 106 while (readFrom < length) { 107 107 UINT type = PathGetCharType(psz[readFrom]); 108 if ( psz[readFrom] == 0 || type & (GCT_LFNCHAR | GCT_SHORTCHAR)) {108 if (!psz[readFrom] || type & (GCT_LFNCHAR | GCT_SHORTCHAR)) 109 109 psz[writeTo++] = psz[readFrom]; 110 }111 110 112 111 readFrom++; … … 216 215 static HGLOBAL createGlobalHDropContent(const KURL& url, String& fileName, SharedBuffer* data) 217 216 { 218 if (fileName.isEmpty() || !data 217 if (fileName.isEmpty() || !data) 219 218 return 0; 220 219 … … 291 290 fgd->fgd[0].dwFlags = FD_FILESIZE; 292 291 int fileSize = ::WideCharToMultiByte(CP_ACP, 0, url.characters(), url.length(), 0, 0, 0, 0); 293 fileSize += strlen(szShellDotUrlTemplate) - 2; 292 fileSize += strlen(szShellDotUrlTemplate) - 2; // -2 is for getting rid of %s in the template string 294 293 fgd->fgd[0].nFileSizeLow = fileSize; 295 294 estimatedSize = fileSize; … … 438 437 if (withHTML) { 439 438 Vector<char> cfhtmlData; 440 markupToCF _HTML(urlToMarkup(url, title), "", cfhtmlData);439 markupToCFHTML(urlToMarkup(url, title), "", cfhtmlData); 441 440 medium.hGlobal = createGlobalData(cfhtmlData); 442 441 if (medium.hGlobal && FAILED(data->SetData(htmlFormat(), &medium, TRUE))) … … 459 458 void ClipboardWin::clearData(const String& type) 460 459 { 461 // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941>460 // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941> 462 461 ASSERT(isForDragging()); 463 462 if (policy() != ClipboardWritable || !m_writableDataObject) … … 479 478 void ClipboardWin::clearAllData() 480 479 { 481 // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941>480 // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941> 482 481 ASSERT(isForDragging()); 483 482 if (policy() != ClipboardWritable) … … 492 491 { 493 492 success = false; 494 if (policy() != ClipboardReadable || !m_dataObject) {493 if (policy() != ClipboardReadable || !m_dataObject) 495 494 return ""; 496 }497 495 498 496 ClipboardDataType dataType = clipboardTypeFromMIMEType(type); 499 497 if (dataType == ClipboardDataTypeText) 500 498 return getPlainText(m_dataObject.get(), success); 501 else if (dataType == ClipboardDataTypeURL)499 if (dataType == ClipboardDataTypeURL) 502 500 return getURL(m_dataObject.get(), DragData::DoNotConvertFilenames, success); 503 501 … … 569 567 570 568 // IEnumFORMATETC::Next returns S_FALSE if there are no more items. 571 while (itr->Next(1, &data, 0) == S_OK) {569 while (itr->Next(1, &data, 0) == S_OK) 572 570 addMimeTypesForFormat(results, data); 573 }574 571 575 572 return results; … … 721 718 // Put img tag on the clipboard referencing the image 722 719 Vector<char> data; 723 markupToCF _HTML(imageToMarkup(fullURL), "", data);720 markupToCFHTML(imageToMarkup(fullURL), "", data); 724 721 medium.hGlobal = createGlobalData(data); 725 722 if (medium.hGlobal && FAILED(m_writableDataObject->SetData(htmlFormat(), &medium, TRUE))) … … 758 755 759 756 Vector<char> data; 760 markupToCF _HTML(createMarkup(selectedRange, 0, AnnotateForInterchange),757 markupToCFHTML(createMarkup(selectedRange, 0, AnnotateForInterchange), 761 758 selectedRange->startContainer(ec)->document()->url().string(), data); 762 759 medium.hGlobal = createGlobalData(data); -
trunk/WebCore/platform/win/ClipboardWin.h
r54368 r63734 27 27 #define ClipboardWin_h 28 28 29 #include "COMPtr.h" 29 30 #include "CachedResourceClient.h" 30 31 #include "Clipboard.h" 31 #include "COMPtr.h"32 32 33 33 struct IDataObject; … … 35 35 namespace WebCore { 36 36 37 38 39 37 class CachedImage; 38 class IntPoint; 39 class WCDataObject; 40 40 41 // State available during IE's events for drag and drop and copy/paste 42 class ClipboardWin : public Clipboard, public CachedResourceClient { 43 public: 44 static PassRefPtr<ClipboardWin> create(bool isForDragging, IDataObject* dataObject, ClipboardAccessPolicy policy) 45 { 46 return adoptRef(new ClipboardWin(isForDragging, dataObject, policy)); 47 } 48 static PassRefPtr<ClipboardWin> create(bool isForDragging, WCDataObject* dataObject, ClipboardAccessPolicy policy) 49 { 50 return adoptRef(new ClipboardWin(isForDragging, dataObject, policy)); 51 } 52 ~ClipboardWin(); 53 54 void clearData(const String& type); 55 void clearAllData(); 56 String getData(const String& type, bool& success) const; 57 bool setData(const String& type, const String& data); 58 59 // extensions beyond IE's API 60 virtual HashSet<String> types() const; 61 virtual PassRefPtr<FileList> files() const; 62 63 void setDragImage(CachedImage*, const IntPoint&); 64 void setDragImageElement(Node*, const IntPoint&); 41 // State available during IE's events for drag and drop and copy/paste 42 class ClipboardWin : public Clipboard, public CachedResourceClient { 43 public: 44 static PassRefPtr<ClipboardWin> create(bool isForDragging, IDataObject* dataObject, ClipboardAccessPolicy policy) 45 { 46 return adoptRef(new ClipboardWin(isForDragging, dataObject, policy)); 47 } 48 static PassRefPtr<ClipboardWin> create(bool isForDragging, WCDataObject* dataObject, ClipboardAccessPolicy policy) 49 { 50 return adoptRef(new ClipboardWin(isForDragging, dataObject, policy)); 51 } 52 ~ClipboardWin(); 65 53 66 virtual DragImageRef createDragImage(IntPoint& dragLoc) const; 67 virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*); 68 virtual void writeURL(const KURL&, const String&, Frame*); 69 virtual void writeRange(Range*, Frame*); 70 virtual void writePlainText(const String&); 54 void clearData(const String& type); 55 void clearAllData(); 56 String getData(const String& type, bool& success) const; 57 bool setData(const String& type, const String& data); 71 58 72 virtual bool hasData(); 59 // extensions beyond IE's API 60 virtual HashSet<String> types() const; 61 virtual PassRefPtr<FileList> files() const; 73 62 74 COMPtr<IDataObject> dataObject() { return m_dataObject; } 63 void setDragImage(CachedImage*, const IntPoint&); 64 void setDragImageElement(Node*, const IntPoint&); 75 65 76 void setExternalDataObject(IDataObject *dataObject); 66 virtual DragImageRef createDragImage(IntPoint& dragLoc) const; 67 virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*); 68 virtual void writeURL(const KURL&, const String&, Frame*); 69 virtual void writeRange(Range*, Frame*); 70 virtual void writePlainText(const String&); 77 71 78 private: 79 ClipboardWin(bool isForDragging, IDataObject*, ClipboardAccessPolicy); 80 ClipboardWin(bool isForDragging, WCDataObject*, ClipboardAccessPolicy); 72 virtual bool hasData(); 81 73 82 void resetFromClipboard(); 83 void setDragImage(CachedImage*, Node*, const IntPoint&); 74 COMPtr<IDataObject> dataObject() { return m_dataObject; } 84 75 85 COMPtr<IDataObject> m_dataObject; 86 COMPtr<WCDataObject> m_writableDataObject; 87 Frame* m_frame; 88 }; 76 void setExternalDataObject(IDataObject *dataObject); 77 78 private: 79 ClipboardWin(bool isForDragging, IDataObject*, ClipboardAccessPolicy); 80 ClipboardWin(bool isForDragging, WCDataObject*, ClipboardAccessPolicy); 81 82 void resetFromClipboard(); 83 void setDragImage(CachedImage*, Node*, const IntPoint&); 84 85 COMPtr<IDataObject> m_dataObject; 86 COMPtr<WCDataObject> m_writableDataObject; 87 Frame* m_frame; 88 }; 89 89 90 90 } // namespace WebCore -
trunk/WebCore/platform/win/PasteboardWin.cpp
r56825 r63734 55 55 LONG_PTR longPtr = GetWindowLongPtr(hWnd, 0); 56 56 57 switch (message) {57 switch (message) { 58 58 case WM_RENDERFORMAT: 59 59 // This message comes when SetClipboardData was sent a null data handle … … 118 118 ExceptionCode ec = 0; 119 119 Vector<char> data; 120 markupToCF _HTML(createMarkup(selectedRange, 0, AnnotateForInterchange),120 markupToCFHTML(createMarkup(selectedRange, 0, AnnotateForInterchange), 121 121 selectedRange->startContainer(ec)->document()->url().string(), data); 122 122 HGLOBAL cbData = createGlobalData(data); … … 140 140 if (canSmartCopyOrDelete) { 141 141 if (::OpenClipboard(m_owner)) { 142 ::SetClipboardData(WebSmartPasteFormat, NULL);142 ::SetClipboardData(WebSmartPasteFormat, 0); 143 143 ::CloseClipboard(); 144 144 } … … 186 186 if (::OpenClipboard(m_owner)) { 187 187 Vector<char> data; 188 markupToCF _HTML(urlToMarkup(url, title), "", data);188 markupToCFHTML(urlToMarkup(url, title), "", data); 189 189 HGLOBAL cbData = createGlobalData(data); 190 190 if (!::SetClipboardData(HTMLClipboardFormat, cbData)) … … 261 261 ::CloseClipboard(); 262 262 return fromClipboard; 263 } else264 263 } 264 ::CloseClipboard(); 265 265 } 266 266 … … 273 273 ::CloseClipboard(); 274 274 return fromClipboard; 275 } else276 275 } 276 ::CloseClipboard(); 277 277 } 278 278 … … 289 289 if (cbData) { 290 290 SIZE_T dataSize = ::GlobalSize(cbData); 291 String cf _html(UTF8Encoding().decode((char*)::GlobalLock(cbData), dataSize));291 String cfhtml(UTF8Encoding().decode((char*)::GlobalLock(cbData), dataSize)); 292 292 ::GlobalUnlock(cbData); 293 293 ::CloseClipboard(); 294 294 295 PassRefPtr<DocumentFragment> fragment = fragmentFromCF _HTML(frame->document(), cf_html);295 PassRefPtr<DocumentFragment> fragment = fragmentFromCFHTML(frame->document(), cfhtml); 296 296 if (fragment) 297 297 return fragment; … … 307 307 UChar* buffer = (UChar*)GlobalLock(cbData); 308 308 String str(buffer); 309 ::GlobalUnlock( cbData);309 ::GlobalUnlock(cbData); 310 310 ::CloseClipboard(); 311 311 RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), str); … … 324 324 char* buffer = (char*)GlobalLock(cbData); 325 325 String str(buffer); 326 ::GlobalUnlock( cbData);326 ::GlobalUnlock(cbData); 327 327 ::CloseClipboard(); 328 328 RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), str);
Note: See TracChangeset
for help on using the changeset viewer.