void EventSender::beginDragWithFiles(const CppArgumentList& arguments, CppVariant* result) { currentDragData.initialize(); Vector<string> files = arguments[0].toStringVector(); Vector<WebString> absoluteFilenames; for (size_t i = 0; i < files.size(); ++i) { WebDragData::Item item; item.storageType = WebDragData::Item::StorageTypeFilename; item.filenameData = webkit_support::GetAbsoluteWebStringFromUTF8Path(files[i]); currentDragData.addItem(item); absoluteFilenames.append(item.filenameData); } currentDragData.setFilesystemId(webkit_support::RegisterIsolatedFileSystem(absoluteFilenames)); currentDragEffectsAllowed = WebKit::WebDragOperationCopy; // Provide a drag source. webview()->dragTargetDragEnter(currentDragData, lastMousePos, lastMousePos, currentDragEffectsAllowed); // dragMode saves events and then replays them later. We don't need/want that. dragMode.set(false); // Make the rest of eventSender think a drag is in progress. pressedButton = WebMouseEvent::ButtonLeft; result->setNull(); }
WebDragData DataObject::toWebDragData() { WebDragData data; data.initialize(); data.setModifierKeyState(m_modifiers); WebVector<WebDragData::Item> itemList(length()); for (size_t i = 0; i < length(); ++i) { DataObjectItem* originalItem = item(i); WebDragData::Item item; if (originalItem->kind() == DataObjectItem::StringKind) { item.storageType = WebDragData::Item::StorageTypeString; item.stringType = originalItem->type(); item.stringData = originalItem->getAsString(); } else if (originalItem->kind() == DataObjectItem::FileKind) { if (originalItem->sharedBuffer()) { item.storageType = WebDragData::Item::StorageTypeBinaryData; item.binaryData = originalItem->sharedBuffer(); } else if (originalItem->isFilename()) { Blob* blob = originalItem->getAsFile(); if (blob->isFile()) { File* file = toFile(blob); if (file->hasBackingFile()) { item.storageType = WebDragData::Item::StorageTypeFilename; item.filenameData = file->path(); item.displayNameData = file->name(); } else if (!file->fileSystemURL().isEmpty()) { item.storageType = WebDragData::Item::StorageTypeFileSystemFile; item.fileSystemURL = file->fileSystemURL(); item.fileSystemFileSize = file->size(); } else { // FIXME: support dragging constructed Files across renderers, see // http://crbug.com/394955 item.storageType = WebDragData::Item::StorageTypeString; item.stringType = "text/plain"; item.stringData = file->name(); } } else { ASSERT_NOT_REACHED(); } } else { ASSERT_NOT_REACHED(); } } else { ASSERT_NOT_REACHED(); } item.title = originalItem->title(); item.baseURL = originalItem->baseURL(); itemList[i] = item; } data.swapItems(itemList); return data; }