https://bugs.webkit.org/show_bug.cgi?id=77125
This change supports the unification of the data store backing ChromiumDataObject and
DataTransferItemListChromium. ChromiumDataObject will represent dragging and clipboard data
as a list of data nodes to make it more straightforward to implement the HTML spec for
DataTransferItemList. Thus, we extend the abstraction to the webkit glue layer to
simplify the serialization/deserialization between platform-specific data and WebDragData.
The other setter/getter methods are deprecated and will be removed once the dependencies in
Chromium code are gone.
Reviewed by Darin Fisher.
* public/platform/WebDragData.h:
(WebKit):
(WebDragData):
* src/WebDragData.cpp:
(WebKit::WebDragData::items):
(WebKit):
(WebKit::WebDragData::setItems):
(WebKit::WebDragData::addItem):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107846
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2012-02-01 Daniel Cheng <dcheng@chromium.org>
+
+ [chromium] Add setter/getter to expose drag data as a list of items
+ https://bugs.webkit.org/show_bug.cgi?id=77125
+
+ This change supports the unification of the data store backing ChromiumDataObject and
+ DataTransferItemListChromium. ChromiumDataObject will represent dragging and clipboard data
+ as a list of data nodes to make it more straightforward to implement the HTML spec for
+ DataTransferItemList. Thus, we extend the abstraction to the webkit glue layer to
+ simplify the serialization/deserialization between platform-specific data and WebDragData.
+ The other setter/getter methods are deprecated and will be removed once the dependencies in
+ Chromium code are gone.
+
+ Reviewed by Darin Fisher.
+
+ * public/platform/WebDragData.h:
+ (WebKit):
+ (WebDragData):
+ * src/WebDragData.cpp:
+ (WebKit::WebDragData::items):
+ (WebKit):
+ (WebKit::WebDragData::setItems):
+ (WebKit::WebDragData::addItem):
+
2012-02-15 Sadrul Habib Chowdhury <sadrul@chromium.org>
Notify ChromeClient when touch-event handlers are installed/removed.
#define WebDragData_h
#include "WebCommon.h"
+#include "WebData.h"
#include "WebString.h"
+#include "WebURL.h"
#if WEBKIT_IMPLEMENTATION
namespace WebCore { class ChromiumDataObject; }
namespace WebKit {
-class WebData;
class WebDragDataPrivate;
-class WebURL;
template <typename T> class WebVector;
// Holds data that may be exchanged through a drag-n-drop operation. It is
// inexpensive to copy a WebDragData object.
class WebDragData {
public:
+ struct Item {
+ enum StorageType {
+ // String data with an associated MIME type. Depending on the MIME type, there may be
+ // optional metadata attributes as well.
+ StorageTypeString,
+ // Stores the name of one file being dragged into the renderer.
+ StorageTypeFilename,
+ // An image being dragged out of the renderer. Contains a buffer holding the image data
+ // as well as the suggested name for saving the image to.
+ StorageTypeBinaryData,
+ };
+
+ StorageType storageType;
+
+ // Only valid when storageType == StorageTypeString.
+ WebString stringType;
+ WebString stringData;
+
+ // Only valid when storageType == StorageTypeFilename.
+ WebString filenameData;
+
+ // Only valid when storageType == StorageTypeBinaryData.
+ WebData binaryData;
+
+ // Title associated with a link when stringType == "text/uri-list".
+ // Filename when storageType == StorageTypeBinaryData.
+ WebString title;
+
+ // Only valid when stringType == "text/html".
+ WebURL baseURL;
+ };
+
~WebDragData() { reset(); }
WebDragData() : m_private(0) { }
bool isNull() const { return !m_private; }
+ WebVector<Item> items() const;
+ void setItems(const WebVector<Item>&);
+
WEBKIT_EXPORT WebString url() const;
WEBKIT_EXPORT void setURL(const WebURL&);
};
WEBKIT_EXPORT WebVector<CustomData> customData() const;
WEBKIT_EXPORT void setCustomData(const WebVector<CustomData>&);
+ void addItem(const Item&);
#if WEBKIT_IMPLEMENTATION
WebDragData(const WTF::PassRefPtr<WebCore::ChromiumDataObject>&);
assign(p);
}
+WebVector<WebDragData::Item> WebDragData::items() const
+{
+ Vector<Item> itemList;
+ const HashSet<String>& types = m_private->types();
+ if (types.contains(mimeTypeTextPlain)) {
+ Item item;
+ item.storageType = Item::StorageTypeString;
+ item.stringType = String(mimeTypeTextPlain);
+ bool ignored;
+ item.stringData = m_private->getData(mimeTypeTextPlain, ignored);
+ itemList.append(item);
+ }
+ if (types.contains(mimeTypeTextURIList)) {
+ Item item;
+ item.storageType = Item::StorageTypeString;
+ item.stringType = String(mimeTypeTextURIList);
+ bool ignored;
+ item.stringData = m_private->getData(mimeTypeURL, ignored);
+ item.title = m_private->urlTitle();
+ itemList.append(item);
+ }
+ if (types.contains(mimeTypeTextHTML)) {
+ Item item;
+ item.storageType = Item::StorageTypeString;
+ item.stringType = String(mimeTypeTextHTML);
+ bool ignored;
+ item.stringData = m_private->getData(mimeTypeTextHTML, ignored);
+ item.baseURL = m_private->htmlBaseUrl();
+ itemList.append(item);
+ }
+ if (types.contains(mimeTypeDownloadURL)) {
+ Item item;
+ item.storageType = Item::StorageTypeString;
+ item.stringType = String(mimeTypeDownloadURL);
+ bool ignored;
+ item.stringData = m_private->getData(mimeTypeDownloadURL, ignored);
+ itemList.append(item);
+ }
+ const HashMap<String, String>& customData = m_private->customData();
+ for (HashMap<String, String>::const_iterator it = customData.begin(); it != customData.end(); ++it) {
+ Item item;
+ item.storageType = Item::StorageTypeString;
+ item.stringType = it->first;
+ item.stringData = it->second;
+ itemList.append(item);
+ }
+ if (m_private->fileContent()) {
+ Item item;
+ item.storageType = Item::StorageTypeBinaryData;
+ item.binaryData = m_private->fileContent();
+ item.title = m_private->fileContentFilename();
+ }
+ // We don't handle filenames here, since they are never used for dragging out.
+ return itemList;
+}
+
+void WebDragData::setItems(const WebVector<Item>& itemList)
+{
+ m_private->clearAll();
+ for (size_t i = 0; i < itemList.size(); ++i)
+ addItem(itemList[i]);
+}
+
+void WebDragData::addItem(const Item& item)
+{
+ switch (item.storageType) {
+ case Item::StorageTypeString:
+ m_private->setData(item.stringType, item.stringData);
+ if (String(item.stringType) == mimeTypeTextURIList)
+ m_private->setUrlTitle(item.title);
+ else if (String(item.stringType) == mimeTypeTextHTML)
+ m_private->setHtmlBaseUrl(item.baseURL);
+ return;
+ case Item::StorageTypeFilename:
+ m_private->addFilename(item.filenameData);
+ return;
+ case Item::StorageTypeBinaryData:
+ // This should never happen when dragging in.
+ ASSERT_NOT_REACHED();
+ }
+}
+
WebString WebDragData::url() const
{
ASSERT(!isNull());