PassRefPtr<DocumentFragment> fragmentFromHTML(Document* doc, IDataObject* data) { if (!doc || !data) return 0; STGMEDIUM store; String html; String srcURL; if (SUCCEEDED(data->GetData(htmlFormat(), &store))) { //MS HTML Format parsing char* data = (char*)GlobalLock(store.hGlobal); SIZE_T dataSize = ::GlobalSize(store.hGlobal); String cf_html(UTF8Encoding().decode(data, dataSize)); GlobalUnlock(store.hGlobal); ReleaseStgMedium(&store); if (PassRefPtr<DocumentFragment> fragment = fragmentFromCF_HTML(doc, cf_html)) return fragment; } if (SUCCEEDED(data->GetData(texthtmlFormat(), &store))) { //raw html UChar* data = (UChar*)GlobalLock(store.hGlobal); html = String(data); GlobalUnlock(store.hGlobal); ReleaseStgMedium(&store); return createFragmentFromMarkup(doc, html, srcURL); } return 0; }
static String getFullCFHTML(IDataObject* data, bool& success) { STGMEDIUM store; if (SUCCEEDED(data->GetData(htmlFormat(), &store))) { // MS HTML Format parsing char* data = static_cast<char*>(GlobalLock(store.hGlobal)); SIZE_T dataSize = ::GlobalSize(store.hGlobal); String cfhtml(UTF8Encoding().decode(data, dataSize)); GlobalUnlock(store.hGlobal); ReleaseStgMedium(&store); success = true; return cfhtml; } success = false; return String(); }
void Clipboard::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame) { // Order is important here for Explorer's sake if (!m_pasteboard->writableDataObject()) return; m_pasteboard->writeURLToWritableDataObject(url, title); m_pasteboard->writeImageToDataObject(element, url); AtomicString imageURL = element->getAttribute(HTMLNames::srcAttr); if (imageURL.isEmpty()) return; KURL fullURL = frame->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(imageURL)); if (fullURL.isEmpty()) return; STGMEDIUM medium = {0}; medium.tymed = TYMED_HGLOBAL; // Put img tag on the clipboard referencing the image Vector<char> data; markupToCFHTML(createMarkup(element, IncludeNode, 0, ResolveAllURLs), "", data); medium.hGlobal = createGlobalData(data); if (medium.hGlobal && FAILED(m_pasteboard->writableDataObject()->SetData(htmlFormat(), &medium, TRUE))) ::GlobalFree(medium.hGlobal); }
bool containsHTML(IDataObject* data) { return SUCCEEDED(data->QueryGetData(texthtmlFormat())) || SUCCEEDED(data->QueryGetData(htmlFormat())); }