diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-16 22:22:33 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-16 22:22:33 +0000 |
commit | d4f4facfc38f90790483adf8cba3d8377005c0b5 (patch) | |
tree | 0d1108a61e7c286118563cdc1fd9d838401dbe7b /webkit/tools | |
parent | 8761a8aeb94b9afc88931d41f9200bc8002e223a (diff) | |
download | chromium_src-d4f4facfc38f90790483adf8cba3d8377005c0b5.zip chromium_src-d4f4facfc38f90790483adf8cba3d8377005c0b5.tar.gz chromium_src-d4f4facfc38f90790483adf8cba3d8377005c0b5.tar.bz2 |
Update WebClipboard/WebDropData glue to use new getter/setters for WebDragData.
This change will help us implement the HTML spec for DataTransferItemList correctly.
BUG=112255
TEST=manual + WebKit layout tests
Review URL: https://chromiumcodereview.appspot.com/9318003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122370 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools')
-rw-r--r-- | webkit/tools/test_shell/mock_webclipboard_impl.cc | 73 | ||||
-rw-r--r-- | webkit/tools/test_shell/mock_webclipboard_impl.h | 9 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 9 |
3 files changed, 61 insertions, 30 deletions
diff --git a/webkit/tools/test_shell/mock_webclipboard_impl.cc b/webkit/tools/test_shell/mock_webclipboard_impl.cc index 4f67c707..f36e232 100644 --- a/webkit/tools/test_shell/mock_webclipboard_impl.cc +++ b/webkit/tools/test_shell/mock_webclipboard_impl.cc @@ -9,11 +9,12 @@ #include "base/logging.h" #include "base/stl_util.h" #include "base/string_util.h" -#include "net/base/escape.h" +#include "base/utf_string_conversions.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCommon.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" +#include "ui/base/clipboard/clipboard.h" #include "webkit/glue/webclipboard_impl.h" #include "webkit/glue/webkit_glue.h" #include "webkit/support/webkit_support_gfx.h" @@ -78,10 +79,11 @@ WebVector<WebString> MockWebClipboardImpl::readAvailableTypes( if (!m_image.isNull()) { results.push_back(WebString("image/png")); } - for (size_t i = 0; i < m_customData.size(); ++i) { - CHECK(std::find(results.begin(), results.end(), m_customData[i].type) == + for (std::map<string16, string16>::const_iterator it = m_customData.begin(); + it != m_customData.end(); ++it) { + CHECK(std::find(results.begin(), results.end(), it->first) == results.end()); - results.push_back(m_customData[i].type); + results.push_back(it->first); } return results; } @@ -135,58 +137,79 @@ WebKit::WebData MockWebClipboardImpl::readImage( WebKit::WebString MockWebClipboardImpl::readCustomData( WebKit::WebClipboard::Buffer buffer, const WebKit::WebString& type) { - for (size_t i = 0; i < m_customData.size(); ++i) { - if (m_customData[i].type == type) { - return m_customData[i].data; - } - } + std::map<string16, string16>::const_iterator it = m_customData.find(type); + if (it != m_customData.end()) + return it->second; return WebKit::WebString(); } void MockWebClipboardImpl::writeHTML( const WebKit::WebString& htmlText, const WebKit::WebURL& url, const WebKit::WebString& plainText, bool writeSmartPaste) { + clear(); + m_htmlText = htmlText; m_plainText = plainText; - m_image.reset(); - m_customData = WebVector<WebDragData::CustomData>(); m_writeSmartPaste = writeSmartPaste; } void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) { - m_htmlText = WebKit::WebString(); + clear(); + m_plainText = plain_text; - m_image.reset(); - m_customData = WebVector<WebDragData::CustomData>(); - m_writeSmartPaste = false; } void MockWebClipboardImpl::writeURL( const WebKit::WebURL& url, const WebKit::WebString& title) { + clear(); + m_htmlText = WebString::fromUTF8( webkit_glue::WebClipboardImpl::URLToMarkup(url, title)); m_plainText = url.spec().utf16(); - m_image.reset(); - m_customData = WebVector<WebDragData::CustomData>(); - m_writeSmartPaste = false; } void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, const WebKit::WebURL& url, const WebKit::WebString& title) { if (!image.isNull()) { + clear(); + + m_plainText = m_htmlText; m_htmlText = WebString::fromUTF8( webkit_glue::WebClipboardImpl::URLToImageMarkup(url, title)); - m_plainText = m_htmlText; m_image = image; - m_customData = WebVector<WebDragData::CustomData>(); - m_writeSmartPaste = false; } } -void MockWebClipboardImpl::writeDataObject(const WebKit::WebDragData& data) { - m_htmlText = data.htmlText(); - m_plainText = data.plainText(); +void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { + clear(); + + const WebVector<WebDragData::Item>& itemList = data.items(); + for (size_t i = 0; i < itemList.size(); ++i) { + const WebDragData::Item& item = itemList[i]; + switch (item.storageType) { + case WebDragData::Item::StorageTypeString: { + if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { + m_plainText = item.stringData; + continue; + } + if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { + m_htmlText = item.stringData; + continue; + } + m_customData.insert(std::make_pair(item.stringType, item.stringData)); + continue; + } + case WebDragData::Item::StorageTypeFilename: + case WebDragData::Item::StorageTypeBinaryData: + NOTREACHED(); // Currently unused by the clipboard implementation. + } + } +} + +void MockWebClipboardImpl::clear() { + m_plainText = WebString(); + m_htmlText = WebString(); m_image.reset(); - m_customData = data.customData(); + m_customData.clear(); m_writeSmartPaste = false; } diff --git a/webkit/tools/test_shell/mock_webclipboard_impl.h b/webkit/tools/test_shell/mock_webclipboard_impl.h index 8133089..997596d 100644 --- a/webkit/tools/test_shell/mock_webclipboard_impl.h +++ b/webkit/tools/test_shell/mock_webclipboard_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -10,6 +10,9 @@ #ifndef WEBKIT_TOOLS_TEST_SHELL_MOCK_WEBCLIPBOARD_IMPL_H_ #define WEBKIT_TOOLS_TEST_SHELL_MOCK_WEBCLIPBOARD_IMPL_H_ +#include <map> + +#include "base/string16.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebClipboard.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" @@ -45,10 +48,12 @@ class MockWebClipboardImpl : public WebKit::WebClipboard { virtual void writeDataObject(const WebKit::WebDragData& data); private: + void clear(); + WebKit::WebString m_plainText; WebKit::WebString m_htmlText; WebKit::WebImage m_image; - WebKit::WebVector<WebKit::WebDragData::CustomData> m_customData; + std::map<string16, string16> m_customData; bool m_writeSmartPaste; }; diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 01c2b68..5baf744 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -158,10 +158,13 @@ std::string DescriptionSuitableForTestResult(const std::string& url) { return url.substr(pos + 1); } -// Adds a file called "DRTFakeFile" to |data_object| (CF_HDROP). Use to fake -// dragging a file. +// Adds a file called "DRTFakeFile" to |data_object|. Use to fake dragging a +// file. void AddDRTFakeFileToDataObject(WebDragData* drag_data) { - drag_data->appendToFilenames(WebString::fromUTF8("DRTFakeFile")); + WebDragData::Item item; + item.storageType = WebDragData::Item::StorageTypeFilename; + item.filenameData = WebString::fromUTF8("DRTFakeFile"); + drag_data->addItem(item); } // Get a debugging string from a WebNavigationType. |