diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-07 23:24:58 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-07 23:24:58 +0000 |
commit | e80c73be12cc2211d5a72a5ff85eb97366b2458f (patch) | |
tree | 5c395779776b368ed6cafdbc5c6bc929776c18a4 | |
parent | 25a3f6b52228bc68ce63c4032ed6b17cecd7b3c5 (diff) | |
download | chromium_src-e80c73be12cc2211d5a72a5ff85eb97366b2458f.zip chromium_src-e80c73be12cc2211d5a72a5ff85eb97366b2458f.tar.gz chromium_src-e80c73be12cc2211d5a72a5ff85eb97366b2458f.tar.bz2 |
Switch to using WebDragData in WebView and WebViewDelegate.
I also cleaned up some of the WebView and WebViewDelegate methods to pass
WebPoint instead of pairs of ints or gfx::Point.
With this change, I am keeping webkit/glue/webdropdata.{h,cc}, which is what
Chrome uses to pass around the equivalent data. Now, it is possible to
construct a WebDropData from a WebKit::WebDragData and to also get a
WebKit::WebDragData from a WebDropData. Hence, the conversion between
WebDropData and ChromiumDataObject (see clipboard_conversion.{h,cc}) is now
removed in favor of conversion between WebDropData and WebKit::WebDragData.
Conversion between WebKit::WebDragData and WebCore::ChromiumDataObject is very
cheap (just reference counting).
Finally, this change also brings in WebData, which is now used by the return
value of WebKitClient::loadResource. As a companion to that change, I also
changed webkit_glue::GetDataResource to return StringPiece instead of
std::string. That also saves on an unnecessary buffer copy.
R=dglazkov
Review URL: http://codereview.chromium.org/63084
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13305 0039d316-1c4b-4281-b951-d872f2087c98
37 files changed, 419 insertions, 308 deletions
@@ -19,7 +19,7 @@ deps = { "http://googletest.googlecode.com/svn/trunk@214", "src/third_party/WebKit": - "/trunk/deps/third_party/WebKit@13293", + "/trunk/deps/third_party/WebKit@13303", "src/third_party/icu38": "/trunk/deps/third_party/icu38@13083", diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index fa009e2..014737c 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -390,15 +390,16 @@ void RenderViewHost::FillPasswordForm( Send(new ViewMsg_FillPasswordForm(routing_id(), form_data)); } -void RenderViewHost::DragTargetDragEnter(const WebDropData& drop_data, - const gfx::Point& client_pt, const gfx::Point& screen_pt) { +void RenderViewHost::DragTargetDragEnter( + const WebDropData& drop_data, + const gfx::Point& client_pt, + const gfx::Point& screen_pt) { // Grant the renderer the ability to load the drop_data. RendererSecurityPolicy* policy = RendererSecurityPolicy::GetInstance(); policy->GrantRequestURL(process()->pid(), drop_data.url); - for (std::vector<std::wstring>::const_iterator - iter(drop_data.filenames.begin()); + for (std::vector<string16>::const_iterator iter(drop_data.filenames.begin()); iter != drop_data.filenames.end(); ++iter) { - FilePath path = FilePath::FromWStringHack(*iter); + FilePath path = FilePath::FromWStringHack(UTF16ToWideHack(*iter)); policy->GrantRequestURL(process()->pid(), net::FilePathToFileURL(path)); policy->GrantUploadFile(process()->pid(), path); } @@ -571,13 +572,19 @@ void RenderViewHost::ShowJavaScriptConsole() { void RenderViewHost::DragSourceEndedAt( int client_x, int client_y, int screen_x, int screen_y) { Send(new ViewMsg_DragSourceEndedOrMoved( - routing_id(), client_x, client_y, screen_x, screen_y, true)); + routing_id(), + gfx::Point(client_x, client_y), + gfx::Point(screen_x, screen_y), + true)); } void RenderViewHost::DragSourceMovedTo( int client_x, int client_y, int screen_x, int screen_y) { Send(new ViewMsg_DragSourceEndedOrMoved( - routing_id(), client_x, client_y, screen_x, screen_y, false)); + routing_id(), + gfx::Point(client_x, client_y), + gfx::Point(screen_x, screen_y), + false)); } void RenderViewHost::DragSourceSystemDragEnded() { diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index cec72e5..38184f8 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -309,11 +309,9 @@ IPC_BEGIN_MESSAGES(View) // Notifies the renderer of updates in mouse position of an in-progress // drag. if |ended| is true, then the user has ended the drag operation. - IPC_MESSAGE_ROUTED5(ViewMsg_DragSourceEndedOrMoved, - int /* client_x */, - int /* client_y */, - int /* screen_x */, - int /* screen_y */, + IPC_MESSAGE_ROUTED3(ViewMsg_DragSourceEndedOrMoved, + gfx::Point /* client_pt */, + gfx::Point /* screen_pt */, bool /* ended */) // Notifies the renderer that the system DoDragDrop call has ended. diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 99ad017..3ed10cf 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -49,6 +49,8 @@ #include "printing/units.h" #include "skia/ext/bitmap_platform_device.h" #include "skia/ext/image_operations.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" +#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" #include "webkit/default_plugin/default_plugin_shared.h" #include "webkit/glue/dom_operations.h" @@ -87,6 +89,7 @@ using base::Time; using base::TimeDelta; using webkit_glue::WebAccessibility; using WebKit::WebConsoleMessage; +using WebKit::WebDragData; using WebKit::WebScriptSource; //----------------------------------------------------------------------------- @@ -2031,8 +2034,9 @@ void RenderView::ShowContextMenu(WebView* webview, Send(new ViewHostMsg_ContextMenu(routing_id_, params)); } -void RenderView::StartDragging(WebView* webview, const WebDropData& drop_data) { - Send(new ViewHostMsg_StartDragging(routing_id_, drop_data)); +void RenderView::StartDragging(WebView* webview, + const WebDragData& drag_data) { + Send(new ViewHostMsg_StartDragging(routing_id_, WebDropData(drag_data))); } void RenderView::TakeFocus(WebView* webview, bool reverse) { @@ -2570,15 +2574,13 @@ void RenderView::OnReservePageIDRange(int size_of_range) { next_page_id_ += size_of_range + 1; } -void RenderView::OnDragSourceEndedOrMoved(int client_x, - int client_y, - int screen_x, - int screen_y, +void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point, + const gfx::Point& screen_point, bool ended) { if (ended) - webview()->DragSourceEndedAt(client_x, client_y, screen_x, screen_y); + webview()->DragSourceEndedAt(client_point, screen_point); else - webview()->DragSourceMovedTo(client_x, client_y, screen_x, screen_y); + webview()->DragSourceMovedTo(client_point, screen_point); } void RenderView::OnDragSourceSystemDragEnded() { @@ -2631,17 +2633,21 @@ void RenderView::OnFillPasswordForm( } void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data, - const gfx::Point& client_pt, const gfx::Point& screen_pt) { - bool is_drop_target = webview()->DragTargetDragEnter(drop_data, - client_pt.x(), client_pt.y(), screen_pt.x(), screen_pt.y()); + const gfx::Point& client_point, + const gfx::Point& screen_point) { + bool is_drop_target = webview()->DragTargetDragEnter( + drop_data.ToDragData(), + drop_data.identity, + client_point, + screen_point); Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target)); } -void RenderView::OnDragTargetDragOver(const gfx::Point& client_pt, - const gfx::Point& screen_pt) { - bool is_drop_target = webview()->DragTargetDragOver(client_pt.x(), - client_pt.y(), screen_pt.x(), screen_pt.y()); +void RenderView::OnDragTargetDragOver(const gfx::Point& client_point, + const gfx::Point& screen_point) { + bool is_drop_target = + webview()->DragTargetDragOver(client_point, screen_point); Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target)); } @@ -2650,10 +2656,9 @@ void RenderView::OnDragTargetDragLeave() { webview()->DragTargetDragLeave(); } -void RenderView::OnDragTargetDrop(const gfx::Point& client_pt, - const gfx::Point& screen_pt) { - webview()->DragTargetDrop(client_pt.x(), client_pt.y(), screen_pt.x(), - screen_pt.y()); +void RenderView::OnDragTargetDrop(const gfx::Point& client_point, + const gfx::Point& screen_point) { + webview()->DragTargetDrop(client_point, screen_point); } void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 3fe9dbb..6a499ad 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -67,6 +67,7 @@ struct ViewMsg_PrintPage_Params; struct ViewMsg_PrintPages_Params; struct ViewMsg_Print_Params; struct ViewMsg_UploadFile_Params; +struct WebDropData; namespace base { class WaitableEvent; @@ -77,6 +78,7 @@ struct FileUploadData; } namespace WebKit { +class WebDragData; struct WebFindOptions; } @@ -274,7 +276,7 @@ class RenderView : public RenderWidget, int edit_flags, const std::string& security_info); virtual void StartDragging(WebView* webview, - const WebDropData& drag_data); + const WebKit::WebDragData& drag_data); virtual void TakeFocus(WebView* webview, bool reverse); virtual void JSOutOfMemory(); @@ -536,8 +538,9 @@ class RenderView : public RenderWidget, void OnReservePageIDRange(int size_of_range); - void OnDragSourceEndedOrMoved( - int client_x, int client_y, int screen_x, int screen_y, bool ended); + void OnDragSourceEndedOrMoved(const gfx::Point& client_point, + const gfx::Point& screen_point, + bool ended); void OnDragSourceSystemDragEnded(); void OnInstallMissingPlugin(); void OnFileChooserResponse(const std::vector<FilePath>& file_names); diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc index c907c23..d072dce 100644 --- a/chrome/renderer/renderer_glue.cc +++ b/chrome/renderer/renderer_glue.cc @@ -171,8 +171,8 @@ void AppendToLog(const char* file, int line, const char* msg) { logging::LogMessage(file, line).stream() << msg; } -std::string GetDataResource(int resource_id) { - return ResourceBundle::GetSharedInstance().GetDataResource(resource_id); +StringPiece GetDataResource(int resource_id) { + return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); } #if defined(OS_WIN) diff --git a/chrome/test/worker/test_worker_main.cc b/chrome/test/worker/test_worker_main.cc index e14d9a4..81b3aca 100644 --- a/chrome/test/worker/test_worker_main.cc +++ b/chrome/test/worker/test_worker_main.cc @@ -66,8 +66,8 @@ string16 GetLocalizedString(int message_id) { return L""; } -std::string GetDataResource(int resource_id) { - return ""; +StringPiece GetDataResource(int resource_id) { + return StringPiece(); } void SetMediaPlayerAvailable(bool value) { diff --git a/webkit/build/WebKit/WebKit.vcproj b/webkit/build/WebKit/WebKit.vcproj index 0d7f6fd..d0abe86 100644 --- a/webkit/build/WebKit/WebKit.vcproj +++ b/webkit/build/WebKit/WebKit.vcproj @@ -156,6 +156,14 @@ > </File> <File + RelativePath="..\..\..\third_party\WebKit\WebKit\chromium\public\WebData.h" + > + </File> + <File + RelativePath="..\..\..\third_party\WebKit\WebKit\chromium\public\WebDragData.h" + > + </File> + <File RelativePath="..\..\..\third_party\WebKit\WebKit\chromium\public\WebFindOptions.h" > </File> @@ -199,6 +207,10 @@ RelativePath="..\..\..\third_party\WebKit\WebKit\chromium\public\WebURL.h" > </File> + <File + RelativePath="..\..\..\third_party\WebKit\WebKit\chromium\public\WebVector.h" + > + </File> <Filter Name="win" > @@ -244,6 +256,14 @@ > </File> <File + RelativePath="..\..\..\third_party\WebKit\WebKit\chromium\src\WebData.cpp" + > + </File> + <File + RelativePath="..\..\..\third_party\WebKit\WebKit\chromium\src\WebDragData.cpp" + > + </File> + <File RelativePath="..\..\..\third_party\WebKit\WebKit\chromium\src\WebImageSkia.cpp" > </File> diff --git a/webkit/glue/clipboard_conversion.cc b/webkit/glue/clipboard_conversion.cc deleted file mode 100644 index 28f191d..0000000 --- a/webkit/glue/clipboard_conversion.cc +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2008 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. - -#include "config.h" - -#include "webkit/glue/clipboard_conversion.h" - -#include "build/build_config.h" - -#include "ChromiumDataObject.h" -#include "ClipboardUtilitiesChromium.h" -#include "KURL.h" -#include "SharedBuffer.h" -#include <wtf/Vector.h> - -#include "webkit/glue/glue_util.h" - -namespace webkit_glue { - -WebDropData ChromiumDataObjectToWebDropData( - WebCore::ChromiumDataObject* data_object) { - WebDropData drop_data; - drop_data.url = KURLToGURL(data_object->url); - drop_data.url_title = StringToStdWString(data_object->urlTitle); - - drop_data.file_extension = StringToStdWString(data_object->fileExtension); - - for (size_t i = 0; i < data_object->filenames.size(); ++i) { - drop_data.filenames.push_back(StringToStdWString( - data_object->filenames[i])); - } - - drop_data.plain_text = StringToStdWString(data_object->plainText); - - drop_data.text_html = StringToStdWString(data_object->textHtml); - drop_data.html_base_url = KURLToGURL(data_object->htmlBaseUrl); - - drop_data.file_description_filename = StringToStdWString( - data_object->fileContentFilename); - if (data_object->fileContent) { - drop_data.file_contents.assign(data_object->fileContent->data(), - data_object->fileContent->size()); - } - - return drop_data; -} - -PassRefPtr<WebCore::ChromiumDataObject> WebDropDataToChromiumDataObject( - const WebDropData& drop_data) { - RefPtr<WebCore::ChromiumDataObject> data_object = - WebCore::ChromiumDataObject::create(); - data_object->url = GURLToKURL(drop_data.url); - data_object->urlTitle = StdWStringToString(drop_data.url_title); - - data_object->fileExtension = StdWStringToString(drop_data.file_extension); - - for (size_t i = 0; i < drop_data.filenames.size(); ++i) { - data_object->filenames.append(StdWStringToString(drop_data.filenames[i])); - } - - data_object->plainText = StdWStringToString(drop_data.plain_text); - - data_object->textHtml = StdWStringToString(drop_data.text_html); - data_object->htmlBaseUrl = GURLToKURL(drop_data.html_base_url); - - data_object->fileContentFilename = StdWStringToString( - drop_data.file_description_filename); - if (!drop_data.file_contents.empty()) { - data_object->fileContent = - WebCore::SharedBuffer::create(drop_data.file_contents.data(), - drop_data.file_contents.size()); - } - - return data_object; -} - -} // namespace webkit_glue diff --git a/webkit/glue/clipboard_conversion.h b/webkit/glue/clipboard_conversion.h deleted file mode 100644 index d6acd2f..0000000 --- a/webkit/glue/clipboard_conversion.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2008 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. -// -// This file contains helper methods for converting WebDropData objects to -// WebKit ChromiumDataObject and back. -#ifndef WEBKIT_GLUE_CLIPBOARD_CONVERSION_H_ -#define WEBKIT_GLUE_CLIPBOARD_CONVERSION_H_ - -#include "webkit/glue/webdropdata.h" - -#include <wtf/PassRefPtr.h> - -namespace WebCore { -class ChromiumDataObject; -} - -namespace webkit_glue { - -WebDropData ChromiumDataObjectToWebDropData( - WebCore::ChromiumDataObject* data_object); - -PassRefPtr<WebCore::ChromiumDataObject> WebDropDataToChromiumDataObject( - const WebDropData& drop_data); - -} // namespace webkit_glue - -#endif // WEBKIT_GLUE_CLIPBOARD_CONVERSION_H_ diff --git a/webkit/glue/devtools/debugger_agent_impl.cc b/webkit/glue/devtools/debugger_agent_impl.cc index 4edd3db..6838d5b 100644 --- a/webkit/glue/devtools/debugger_agent_impl.cc +++ b/webkit/glue/devtools/debugger_agent_impl.cc @@ -54,12 +54,12 @@ void DebuggerAgentImpl::SetDocument(Document* document) { V8Proxy::GetContext(document->frame())); v8::Context::Scope context_scope(context_); - std::string basejs = webkit_glue::GetDataResource(IDR_DEVTOOLS_BASE_JS); - v8::Script::Compile(v8::String::New(basejs.c_str()))->Run(); - std::string jsonjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_JSON_JS); - v8::Script::Compile(v8::String::New(jsonjs.c_str()))->Run(); - std::string injectjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_INJECT_JS); - v8::Script::Compile(v8::String::New(injectjs.c_str()))->Run(); + StringPiece basejs = webkit_glue::GetDataResource(IDR_DEVTOOLS_BASE_JS); + v8::Script::Compile(v8::String::New(basejs.as_string().c_str()))->Run(); + StringPiece jsonjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_JSON_JS); + v8::Script::Compile(v8::String::New(jsonjs.as_string().c_str()))->Run(); + StringPiece injectjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_INJECT_JS); + v8::Script::Compile(v8::String::New(injectjs.as_string().c_str()))->Run(); } String DebuggerAgentImpl::ExecuteUtilityFunction( diff --git a/webkit/glue/dragclient_impl.cc b/webkit/glue/dragclient_impl.cc index c3e7865..6547e27 100644 --- a/webkit/glue/dragclient_impl.cc +++ b/webkit/glue/dragclient_impl.cc @@ -20,13 +20,15 @@ MSVC_POP_WARNING(); #include "base/logging.h" #include "base/string_util.h" -#include "webkit/glue/clipboard_conversion.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" #include "webkit/glue/context_menu.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webview_delegate.h" #include "webkit/glue/webview_impl.h" +using WebKit::WebDragData; + void DragClientImpl::willPerformDragDestinationAction( WebCore::DragDestinationAction, WebCore::DragData*) { @@ -60,13 +62,10 @@ void DragClientImpl::startDrag(WebCore::DragImageRef drag_image, // Add a ref to the frame just in case a load occurs mid-drag. RefPtr<WebCore::Frame> frame_protector = frame; - RefPtr<WebCore::ChromiumDataObject> data_object = - static_cast<WebCore::ClipboardChromium*>(clipboard)->dataObject(); - DCHECK(data_object.get()); - WebDropData drop_data = webkit_glue::ChromiumDataObjectToWebDropData( - data_object.get()); + WebDragData drag_data = webkit_glue::ChromiumDataObjectToWebDragData( + static_cast<WebCore::ClipboardChromium*>(clipboard)->dataObject()); - webview_->StartDragging(drop_data); + webview_->StartDragging(drag_data); } WebCore::DragImageRef DragClientImpl::createDragImageForLink( diff --git a/webkit/glue/feed_preview.cc b/webkit/glue/feed_preview.cc index 7b2cdedb..11ddf53 100644 --- a/webkit/glue/feed_preview.cc +++ b/webkit/glue/feed_preview.cc @@ -34,7 +34,8 @@ static std::string MakeFeedPreview(const std::string& url, // The feed preview template has {{URL}} in place of where the URL should go. const std::string kUrlTemplate = "{{URL}}"; - std::string feed_template(webkit_glue::GetDataResource(IDR_FEED_PREVIEW)); + const std::string& feed_template = + webkit_glue::GetDataResource(IDR_FEED_PREVIEW).as_string(); std::string::size_type template_offset = feed_template.find(kUrlTemplate); DCHECK(template_offset != std::string::npos); // TODO(evanm): URL-escape URL! diff --git a/webkit/glue/glue.vcproj b/webkit/glue/glue.vcproj index 8ba8ddc..f86e41a 100644 --- a/webkit/glue/glue.vcproj +++ b/webkit/glue/glue.vcproj @@ -342,14 +342,6 @@ >
</File>
<File
- RelativePath=".\clipboard_conversion.cc"
- >
- </File>
- <File
- RelativePath=".\clipboard_conversion.h"
- >
- </File>
- <File
RelativePath=".\context_menu_client_impl.cc"
>
</File>
@@ -634,6 +626,10 @@ >
</File>
<File
+ RelativePath=".\webdropdata_win.cc"
+ >
+ </File>
+ <File
RelativePath=".\weberror_impl.cc"
>
</File>
diff --git a/webkit/glue/glue_util.cc b/webkit/glue/glue_util.cc index 2601970..da506ce 100644 --- a/webkit/glue/glue_util.cc +++ b/webkit/glue/glue_util.cc @@ -15,7 +15,9 @@ #include <string> +#include "ChromiumDataObject.h" #include "CString.h" +#include "IntPoint.h" #include "IntRect.h" #include "PlatformString.h" #include "KURL.h" @@ -27,6 +29,8 @@ #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "googleurl/src/gurl.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" +#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" @@ -166,4 +170,26 @@ WebCore::IntRect ToIntRect(const gfx::Rect& r) { return WebCore::IntRect(r.x(), r.y(), r.width(), r.height()); } +// Point conversions ----------------------------------------------------------- + +WebCore::IntPoint WebPointToIntPoint(const WebKit::WebPoint& point) { + return point; +} + +WebKit::WebPoint IntPointToWebPoint(const WebCore::IntPoint& point) { + return point; +} + +// DragData conversions -------------------------------------------------------- + +WebKit::WebDragData ChromiumDataObjectToWebDragData( + const PassRefPtr<WebCore::ChromiumDataObject>& data) { + return data; +} + +PassRefPtr<WebCore::ChromiumDataObject> WebDragDataToChromiumDataObject( + const WebKit::WebDragData& data) { + return data; +} + } // namespace webkit_glue diff --git a/webkit/glue/glue_util.h b/webkit/glue/glue_util.h index 5c9f90b..8f02767 100644 --- a/webkit/glue/glue_util.h +++ b/webkit/glue/glue_util.h @@ -11,7 +11,9 @@ class GURL; namespace WebCore { +class ChromiumDataObject; class CString; +class IntPoint; class IntRect; class KURL; class String; @@ -19,8 +21,14 @@ class String; namespace WebKit { class WebCString; +class WebDragData; class WebString; class WebURL; +struct WebPoint; +} + +namespace WTF { +template <typename T> class PassRefPtr; } namespace gfx { @@ -73,6 +81,16 @@ WebCore::KURL WebURLToKURL(const WebKit::WebURL& url); gfx::Rect FromIntRect(const WebCore::IntRect& r); WebCore::IntRect ToIntRect(const gfx::Rect& r); +// WebPoint <-> IntPoint +WebCore::IntPoint WebPointToIntPoint(const WebKit::WebPoint&); +WebKit::WebPoint IntPointToWebPoint(const WebCore::IntPoint&); + +// WebDragData <-> ChromiumDataObject +WebKit::WebDragData ChromiumDataObjectToWebDragData( + const WTF::PassRefPtr<WebCore::ChromiumDataObject>&); +WTF::PassRefPtr<WebCore::ChromiumDataObject> WebDragDataToChromiumDataObject( + const WebKit::WebDragData&); + } // namespace webkit_glue #endif // #ifndef WEBKIT_GLUE_GLUE_UTIL_H_ diff --git a/webkit/glue/webdropdata.cc b/webkit/glue/webdropdata.cc index bf6ef50..b48c04c 100644 --- a/webkit/glue/webdropdata.cc +++ b/webkit/glue/webdropdata.cc @@ -4,27 +4,48 @@ #include "webkit/glue/webdropdata.h" -#include "base/clipboard_util.h" -#include "googleurl/src/gurl.h" -#include <shellapi.h> -#include <shlobj.h> +#include "third_party/WebKit/WebKit/chromium/public/WebData.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebURL.h" +#include "third_party/WebKit/WebKit/chromium/public/WebVector.h" -/* static */ -void WebDropData::PopulateWebDropData(IDataObject* data_object, - WebDropData* drop_data) { - std::wstring url_str; - if (ClipboardUtil::GetUrl(data_object, &url_str, &drop_data->url_title)) { - GURL test_url(url_str); - if (test_url.is_valid()) - drop_data->url = test_url; - } - ClipboardUtil::GetFilenames(data_object, &drop_data->filenames); - ClipboardUtil::GetPlainText(data_object, &drop_data->plain_text); - std::string base_url; - ClipboardUtil::GetHtml(data_object, &drop_data->text_html, &base_url); - if (!base_url.empty()) { - drop_data->html_base_url = GURL(base_url); +using WebKit::WebData; +using WebKit::WebDragData; +using WebKit::WebString; +using WebKit::WebVector; + +WebDropData::WebDropData(const WebDragData& drag_data) + : identity(0), + url(drag_data.url()), + url_title(drag_data.urlTitle()), + file_extension(drag_data.fileExtension()), + plain_text(drag_data.plainText()), + text_html(drag_data.htmlText()), + html_base_url(drag_data.htmlBaseURL()), + file_description_filename(drag_data.fileContentFileName()) { + if (drag_data.hasFileNames()) { + WebVector<WebString> fileNames; + drag_data.fileNames(fileNames); + for (size_t i = 0; i < fileNames.size(); ++i) + filenames.push_back(fileNames[i]); } - ClipboardUtil::GetFileContents(data_object, - &drop_data->file_description_filename, &drop_data->file_contents); + WebData contents = drag_data.fileContent(); + if (!contents.isEmpty()) + file_contents.assign(contents.data(), contents.size()); +} + +WebDragData WebDropData::ToDragData() const { + WebDragData result; + result.initialize(); + result.setURL(url); + result.setURLTitle(url_title); + result.setFileExtension(file_extension); + result.setFileNames(filenames); + result.setPlainText(plain_text); + result.setHTMLText(text_html); + result.setHTMLBaseURL(html_base_url); + result.setFileContentFileName(file_description_filename); + result.setFileContent(WebData(file_contents.data(), file_contents.size())); + return result; } diff --git a/webkit/glue/webdropdata.h b/webkit/glue/webdropdata.h index f74dcaf..fe8db6a 100644 --- a/webkit/glue/webdropdata.h +++ b/webkit/glue/webdropdata.h @@ -11,42 +11,55 @@ #include <string> #include <vector> + +#include "base/string16.h" #include "googleurl/src/gurl.h" struct IDataObject; +namespace WebKit { +class WebDragData; +} + struct WebDropData { // Construct with a given drag identity. Note: identity is an int32 because // it is passed over the renderer NPAPI interface to gears. explicit WebDropData(int32 drag_identity) : identity(drag_identity) {} - int32 identity; + + // Construct from a WebDragData object. + explicit WebDropData(const WebKit::WebDragData&); // For default constructions, use drag |identity| 0. WebDropData() : identity(0) {} + int32 identity; + // User is dragging a link into the webview. GURL url; - std::wstring url_title; // The title associated with |url|. + string16 url_title; // The title associated with |url|. // File extension for dragging images from a webview to the desktop. - std::wstring file_extension; + string16 file_extension; // User is dropping one or more files on the webview. - std::vector<std::wstring> filenames; + std::vector<string16> filenames; // User is dragging plain text into the webview. - std::wstring plain_text; + string16 plain_text; // User is dragging text/html into the webview (e.g., out of Firefox). // |html_base_url| is the URL that the html fragment is taken from (used to // resolve relative links). It's ok for |html_base_url| to be empty. - std::wstring text_html; + string16 text_html; GURL html_base_url; // User is dragging data from the webview (e.g., an image). - std::wstring file_description_filename; + string16 file_description_filename; std::string file_contents; + // Convert to a WebDragData object. + WebKit::WebDragData ToDragData() const; + // Helper method for converting Window's specific IDataObject to a WebDropData // object. TODO(tc): Move this to the browser side since it's Windows // specific and no longer used in webkit. diff --git a/webkit/glue/webdropdata_win.cc b/webkit/glue/webdropdata_win.cc new file mode 100644 index 0000000..d3a67b5 --- /dev/null +++ b/webkit/glue/webdropdata_win.cc @@ -0,0 +1,32 @@ +// Copyright (c) 2006-2008 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. + +#include "webkit/glue/webdropdata.h" + +#include <windows.h> +#include <shellapi.h> +#include <shlobj.h> + +#include "base/clipboard_util.h" +#include "googleurl/src/gurl.h" + +// static +void WebDropData::PopulateWebDropData(IDataObject* data_object, + WebDropData* drop_data) { + std::wstring url_str; + if (ClipboardUtil::GetUrl(data_object, &url_str, &drop_data->url_title)) { + GURL test_url(url_str); + if (test_url.is_valid()) + drop_data->url = test_url; + } + ClipboardUtil::GetFilenames(data_object, &drop_data->filenames); + ClipboardUtil::GetPlainText(data_object, &drop_data->plain_text); + std::string base_url; + ClipboardUtil::GetHtml(data_object, &drop_data->text_html, &base_url); + if (!base_url.empty()) { + drop_data->html_base_url = GURL(base_url); + } + ClipboardUtil::GetFileContents(data_object, + &drop_data->file_description_filename, &drop_data->file_contents); +} diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index db9e238..e9f5ed8 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -18,6 +18,7 @@ #include "base/file_path.h" #include "base/gfx/native_widget_types.h" #include "base/string16.h" +#include "base/string_piece.h" class GURL; class SkBitmap; @@ -136,7 +137,7 @@ string16 GetLocalizedString(int message_id); // Returns the raw data for a resource. This resource must have been // specified as BINDATA in the relevant .rc file. -std::string GetDataResource(int resource_id); +StringPiece GetDataResource(int resource_id); #if defined(OS_WIN) // Loads and returns a cursor. diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index b9ef492..9c916b6 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -8,10 +8,10 @@ #include "base/stats_counters.h" #include "base/trace_event.h" #include "grit/webkit_resources.h" -#include "third_party/WebKit/WebKit/chromium/public/WebCString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebData.h" #include "webkit/glue/webkit_glue.h" -using WebKit::WebCString; +using WebKit::WebData; using WebKit::WebThemeEngine; namespace webkit_glue { @@ -47,7 +47,7 @@ void WebKitClientImpl::traceEventEnd(const char* name, void* id, TRACE_EVENT_END(name, id, extra); } -WebCString WebKitClientImpl::loadResource(const char* name) { +WebData WebKitClientImpl::loadResource(const char* name) { struct { const char* name; int id; @@ -68,11 +68,13 @@ WebCString WebKitClientImpl::loadResource(const char* name) { #endif }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { - if (!strcmp(name, resources[i].name)) - return webkit_glue::GetDataResource(resources[i].id); + if (!strcmp(name, resources[i].name)) { + StringPiece resource = webkit_glue::GetDataResource(resources[i].id); + return WebData(resource.data(), resource.size()); + } } NOTREACHED() << "Unknown image resource " << name; - return WebCString(); + return WebData(); } double WebKitClientImpl::currentTime() { diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h index 9fc95fa..3e7b1ab 100644 --- a/webkit/glue/webkitclient_impl.h +++ b/webkit/glue/webkitclient_impl.h @@ -25,7 +25,7 @@ class WebKitClientImpl : public WebKit::WebKitClient { virtual void incrementStatsCounter(const char* name); virtual void traceEventBegin(const char* name, void* id, const char* extra); virtual void traceEventEnd(const char* name, void* id, const char* extra); - virtual WebKit::WebCString loadResource(const char* name); + virtual WebKit::WebData loadResource(const char* name); virtual double currentTime(); virtual void setSharedTimerFiredFunction(void (*func)()); virtual void setSharedTimerFireTime(double fireTime); diff --git a/webkit/glue/webview.h b/webkit/glue/webview.h index 344dd26..35c7fe8 100644 --- a/webkit/glue/webview.h +++ b/webkit/glue/webview.h @@ -12,7 +12,11 @@ #include "base/string16.h" #include "webkit/glue/webwidget.h" -struct WebDropData; +namespace WebKit { +class WebDragData; +struct WebPoint; +} + struct WebPreferences; class GURL; class WebDevToolsAgent; @@ -174,25 +178,31 @@ class WebView : public WebWidget { // Notifies the webview that a drag has terminated. virtual void DragSourceEndedAt( - int client_x, int client_y, int screen_x, int screen_y) = 0; + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point) = 0; // Notifies the webview that a drag and drop operation is in progress, with // dropable items over the view. virtual void DragSourceMovedTo( - int client_x, int client_y, int screen_x, int screen_y) = 0; + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point) = 0; // Notfies the webview that the system drag and drop operation has ended. virtual void DragSourceSystemDragEnded() = 0; // Callback methods when a drag and drop operation is trying to drop // something on the renderer. - virtual bool DragTargetDragEnter(const WebDropData& drop_data, - int client_x, int client_y, int screen_x, int screen_y) = 0; + virtual bool DragTargetDragEnter( + const WebKit::WebDragData& drag_data, int identity, + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point) = 0; virtual bool DragTargetDragOver( - int client_x, int client_y, int screen_x, int screen_y) = 0; + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point) = 0; virtual void DragTargetDragLeave() = 0; virtual void DragTargetDrop( - int client_x, int client_y, int screen_x, int screen_y) = 0; + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point) = 0; virtual int32 GetDragIdentity() = 0; // Notifies the webview that autofill suggestions are available for a node. diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index c206ef8..4c8775a 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -42,8 +42,12 @@ namespace webkit_glue { class WebMediaPlayerDelegate; } +namespace WebKit { +class WebDragData; +struct WebPoint; +} + struct PasswordForm; -struct WebDropData; struct WebPreferences; class AutofillForm; class FilePath; @@ -601,7 +605,9 @@ class WebViewDelegate : virtual public WebWidgetDelegate { // webview: The WebView sending the delegate method. // drop_data: a WebDropData struct which should contain all the necessary // information for dragging data out of the webview. - virtual void StartDragging(WebView* webview, const WebDropData& drop_data) { } + virtual void StartDragging(WebView* webview, + const WebKit::WebDragData& drag_data) { + } // Returns the focus to the client. // reverse: Whether the focus should go to the previous (if true) or the next diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index 6860e09..408246b 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -84,9 +84,10 @@ MSVC_POP_WARNING(); #include "base/logging.h" #include "base/message_loop.h" #include "base/string_util.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" +#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" #include "webkit/glue/chrome_client_impl.h" -#include "webkit/glue/clipboard_conversion.h" #include "webkit/glue/context_menu_client_impl.h" #include "webkit/glue/dom_operations.h" #include "webkit/glue/dragclient_impl.h" @@ -114,10 +115,12 @@ MSVC_POP_WARNING(); using namespace WebCore; +using WebKit::WebDragData; using WebKit::WebInputEvent; using WebKit::WebKeyboardEvent; using WebKit::WebMouseEvent; using WebKit::WebMouseWheelEvent; +using WebKit::WebPoint; // Change the text zoom level by kTextSizeMultiplierRatio each time the user // zooms text in or out (ie., change by 20%). The min and max values limit @@ -1554,18 +1557,20 @@ void WebViewImpl::ShowJavaScriptConsole() { } void WebViewImpl::DragSourceEndedAt( - int client_x, int client_y, int screen_x, int screen_y) { - PlatformMouseEvent pme(IntPoint(client_x, client_y), - IntPoint(screen_x, screen_y), + const WebPoint& client_point, + const WebPoint& screen_point) { + PlatformMouseEvent pme(webkit_glue::WebPointToIntPoint(client_point), + webkit_glue::WebPointToIntPoint(screen_point), NoButton, MouseEventMoved, 0, false, false, false, false, 0); page_->mainFrame()->eventHandler()->dragSourceEndedAt(pme, DragOperationCopy); } void WebViewImpl::DragSourceMovedTo( - int client_x, int client_y, int screen_x, int screen_y) { - PlatformMouseEvent pme(IntPoint(client_x, client_y), - IntPoint(screen_x, screen_y), + const WebPoint& client_point, + const WebPoint& screen_point) { + PlatformMouseEvent pme(webkit_glue::WebPointToIntPoint(client_point), + webkit_glue::WebPointToIntPoint(screen_point), LeftButton, MouseEventMoved, 0, false, false, false, false, 0); page_->mainFrame()->eventHandler()->dragSourceMovedTo(pme); @@ -1577,15 +1582,22 @@ void WebViewImpl::DragSourceSystemDragEnded() { doing_drag_and_drop_ = false; } -bool WebViewImpl::DragTargetDragEnter(const WebDropData& drop_data, - int client_x, int client_y, int screen_x, int screen_y) { - DCHECK(!current_drop_data_.get()); +bool WebViewImpl::DragTargetDragEnter( + const WebDragData& web_drag_data, + int identity, + const WebPoint& client_point, + const WebPoint& screen_point) { + DCHECK(!current_drag_data_.get()); - current_drop_data_ = webkit_glue::WebDropDataToChromiumDataObject(drop_data); - drag_identity_ = drop_data.identity; + current_drag_data_ = + webkit_glue::WebDragDataToChromiumDataObject(web_drag_data); + drag_identity_ = identity; - DragData drag_data(current_drop_data_.get(), IntPoint(client_x, client_y), - IntPoint(screen_x, screen_y), kDropTargetOperation); + DragData drag_data( + current_drag_data_.get(), + webkit_glue::WebPointToIntPoint(client_point), + webkit_glue::WebPointToIntPoint(screen_point), + kDropTargetOperation); drag_target_dispatch_ = true; DragOperation effect = page_->dragController()->dragEntered(&drag_data); drag_target_dispatch_ = false; @@ -1594,11 +1606,15 @@ bool WebViewImpl::DragTargetDragEnter(const WebDropData& drop_data, } bool WebViewImpl::DragTargetDragOver( - int client_x, int client_y, int screen_x, int screen_y) { - DCHECK(current_drop_data_.get()); - - DragData drag_data(current_drop_data_.get(), IntPoint(client_x, client_y), - IntPoint(screen_x, screen_y), kDropTargetOperation); + const WebPoint& client_point, + const WebPoint& screen_point) { + DCHECK(current_drag_data_.get()); + + DragData drag_data( + current_drag_data_.get(), + webkit_glue::WebPointToIntPoint(client_point), + webkit_glue::WebPointToIntPoint(screen_point), + kDropTargetOperation); drag_target_dispatch_ = true; DragOperation effect = page_->dragController()->dragUpdated(&drag_data); drag_target_dispatch_ = false; @@ -1607,29 +1623,36 @@ bool WebViewImpl::DragTargetDragOver( } void WebViewImpl::DragTargetDragLeave() { - DCHECK(current_drop_data_.get()); + DCHECK(current_drag_data_.get()); - DragData drag_data(current_drop_data_.get(), IntPoint(), IntPoint(), - DragOperationNone); + DragData drag_data( + current_drag_data_.get(), + IntPoint(), + IntPoint(), + kDropTargetOperation); drag_target_dispatch_ = true; page_->dragController()->dragExited(&drag_data); drag_target_dispatch_ = false; - current_drop_data_ = NULL; + current_drag_data_ = NULL; drag_identity_ = 0; } void WebViewImpl::DragTargetDrop( - int client_x, int client_y, int screen_x, int screen_y) { - DCHECK(current_drop_data_.get()); - - DragData drag_data(current_drop_data_.get(), IntPoint(client_x, client_y), - IntPoint(screen_x, screen_y), kDropTargetOperation); + const WebPoint& client_point, + const WebPoint& screen_point) { + DCHECK(current_drag_data_.get()); + + DragData drag_data( + current_drag_data_.get(), + webkit_glue::WebPointToIntPoint(client_point), + webkit_glue::WebPointToIntPoint(screen_point), + kDropTargetOperation); drag_target_dispatch_ = true; page_->dragController()->performDrag(&drag_data); drag_target_dispatch_ = false; - current_drop_data_ = NULL; + current_drag_data_ = NULL; drag_identity_ = 0; } @@ -1738,11 +1761,11 @@ void WebViewImpl::DidCommitLoad(bool* is_new_navigation) { observed_new_navigation_ = false; } -void WebViewImpl::StartDragging(const WebDropData& drop_data) { +void WebViewImpl::StartDragging(const WebDragData& drag_data) { if (delegate_) { DCHECK(!doing_drag_and_drop_); doing_drag_and_drop_ = true; - delegate_->StartDragging(this, drop_data); + delegate_->StartDragging(this, drag_data); } } diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 2baf9de..e52a8d2 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -13,7 +13,6 @@ #include "base/gfx/size.h" #include "skia/ext/platform_canvas.h" #include "webkit/glue/back_forward_list_client_impl.h" -#include "webkit/glue/webdropdata.h" #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webpreferences.h" #include "webkit/glue/webview.h" @@ -44,7 +43,6 @@ class WebMouseWheelEvent; class AutocompletePopupMenuClient; class ImageResourceFetcher; class SearchableFormData; -struct WebDropData; class WebHistoryItemImpl; class WebDevToolsAgent; class WebDevToolsAgentImpl; @@ -98,17 +96,23 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { virtual void InspectElement(int x, int y); virtual void ShowJavaScriptConsole(); virtual void DragSourceEndedAt( - int client_x, int client_y, int screen_x, int screen_y); + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point); virtual void DragSourceMovedTo( - int client_x, int client_y, int screen_x, int screen_y); + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point); virtual void DragSourceSystemDragEnded(); - virtual bool DragTargetDragEnter(const WebDropData& drop_data, - int client_x, int client_y, int screen_x, int screen_y); + virtual bool DragTargetDragEnter( + const WebKit::WebDragData& drag_data, int identity, + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point); virtual bool DragTargetDragOver( - int client_x, int client_y, int screen_x, int screen_y); + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point); virtual void DragTargetDragLeave(); virtual void DragTargetDrop( - int client_x, int client_y, int screen_x, int screen_y); + const WebKit::WebPoint& client_point, + const WebKit::WebPoint& screen_point); virtual int32 GetDragIdentity(); virtual void AutofillSuggestionsForNode( int64 node_id, @@ -193,7 +197,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { } // Start a system drag and drop operation. - void StartDragging(const WebDropData& drop_data); + void StartDragging(const WebKit::WebDragData& drag_data); // ImageResourceFetcher callback. void ImageResourceDownloadDone(ImageResourceFetcher* fetcher, @@ -258,7 +262,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { WebPreferences webprefs_; // A copy of the web drop data object we received from the browser. - RefPtr<WebCore::ChromiumDataObject> current_drop_data_; + RefPtr<WebCore::ChromiumDataObject> current_drag_data_; private: // Returns true if the event was actually processed. diff --git a/webkit/tools/test_shell/drag_delegate.cc b/webkit/tools/test_shell/drag_delegate.cc index eeb5522..1759a68 100644 --- a/webkit/tools/test_shell/drag_delegate.cc +++ b/webkit/tools/test_shell/drag_delegate.cc @@ -6,8 +6,11 @@ #include <atltypes.h> +#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" #include "webkit/glue/webview.h" +using WebKit::WebPoint; + namespace { void GetCursorPositions(HWND hwnd, CPoint* client, CPoint* screen) { @@ -30,12 +33,14 @@ void TestDragDelegate::OnDragSourceDrop() { CPoint client; CPoint screen; GetCursorPositions(source_hwnd_, &client, &screen); - webview_->DragSourceEndedAt(client.x, client.y, screen.x, screen.y); + webview_->DragSourceEndedAt(WebPoint(client.x, client.y), + WebPoint(screen.x, screen.y)); } void TestDragDelegate::OnDragSourceMove() { CPoint client; CPoint screen; GetCursorPositions(source_hwnd_, &client, &screen); - webview_->DragSourceMovedTo(client.x, client.y, screen.x, screen.y); + webview_->DragSourceMovedTo(WebPoint(client.x, client.y), + WebPoint(screen.x, screen.y)); } diff --git a/webkit/tools/test_shell/drop_delegate.cc b/webkit/tools/test_shell/drop_delegate.cc index 77d6679..fed2514 100644 --- a/webkit/tools/test_shell/drop_delegate.cc +++ b/webkit/tools/test_shell/drop_delegate.cc @@ -4,10 +4,15 @@ #include "webkit/tools/test_shell/drop_delegate.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" +#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webview.h" +using WebKit::WebPoint; + // BaseDropTarget methods ---------------------------------------------------- + DWORD TestDropDelegate::OnDragEnter(IDataObject* data_object, DWORD key_state, POINT cursor_position, @@ -17,8 +22,10 @@ DWORD TestDropDelegate::OnDragEnter(IDataObject* data_object, POINT client_pt = cursor_position; ScreenToClient(GetHWND(), &client_pt); - bool valid = webview_->DragTargetDragEnter(drop_data, client_pt.x, - client_pt.y, cursor_position.x, cursor_position.y); + bool valid = webview_->DragTargetDragEnter( + drop_data.ToDragData(), drop_data.identity, + WebPoint(client_pt.x, client_pt.y), + WebPoint(cursor_position.x, cursor_position.y)); return valid ? DROPEFFECT_COPY : DROPEFFECT_NONE; } @@ -28,8 +35,9 @@ DWORD TestDropDelegate::OnDragOver(IDataObject* data_object, DWORD effect) { POINT client_pt = cursor_position; ScreenToClient(GetHWND(), &client_pt); - bool valid = webview_->DragTargetDragOver(client_pt.x, - client_pt.y, cursor_position.x, cursor_position.y); + bool valid = webview_->DragTargetDragOver( + WebPoint(client_pt.x, client_pt.y), + WebPoint(cursor_position.x, cursor_position.y)); return valid ? DROPEFFECT_COPY : DROPEFFECT_NONE; } @@ -43,8 +51,9 @@ DWORD TestDropDelegate::OnDrop(IDataObject* data_object, DWORD effect) { POINT client_pt = cursor_position; ScreenToClient(GetHWND(), &client_pt); - webview_->DragTargetDrop(client_pt.x, client_pt.y, - cursor_position.x, cursor_position.y); + webview_->DragTargetDrop( + WebPoint(client_pt.x, client_pt.y), + WebPoint(cursor_position.x, cursor_position.y)); // webkit win port always returns DROPEFFECT_NONE return DROPEFFECT_NONE; diff --git a/webkit/tools/test_shell/event_sending_controller.cc b/webkit/tools/test_shell/event_sending_controller.cc index d0849ba..5808bd3 100644 --- a/webkit/tools/test_shell/event_sending_controller.cc +++ b/webkit/tools/test_shell/event_sending_controller.cc @@ -28,7 +28,8 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "base/time.h" -#include "webkit/glue/webdropdata.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" +#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" #include "webkit/glue/webview.h" #include "webkit/tools/test_shell/test_shell.h" @@ -43,9 +44,11 @@ using WebKit::WebInputEventFactory; using base::Time; using base::TimeTicks; +using WebKit::WebDragData; using WebKit::WebInputEvent; using WebKit::WebKeyboardEvent; using WebKit::WebMouseEvent; +using WebKit::WebPoint; TestShell* EventSendingController::shell_ = NULL; gfx::Point EventSendingController::last_mouse_pos_; @@ -56,7 +59,7 @@ int EventSendingController::last_button_number_ = -1; namespace { -static scoped_ptr<WebDropData> drag_data_object; +static WebDragData current_drag_data; static bool replaying_saved_events = false; static std::queue<WebMouseEvent> mouse_event_queue; @@ -179,8 +182,8 @@ EventSendingController::EventSendingController(TestShell* shell) void EventSendingController::Reset() { // The test should have finished a drag and the mouse button state. - DCHECK(!drag_data_object.get()); - drag_data_object.reset(); + DCHECK(current_drag_data.isNull()); + current_drag_data.reset(); pressed_button_ = WebMouseEvent::ButtonNone; dragMode.Set(true); #if defined(OS_WIN) @@ -198,16 +201,15 @@ void EventSendingController::Reset() { last_button_number_ = -1; } -/* static */ WebView* EventSendingController::webview() { +// static +WebView* EventSendingController::webview() { return shell_->webView(); } -/* static */ void EventSendingController::DoDragDrop(const WebDropData& data_obj) { - WebDropData* drop_data_copy = new WebDropData; - *drop_data_copy = data_obj; - drag_data_object.reset(drop_data_copy); - - webview()->DragTargetDragEnter(data_obj, 0, 0, 0, 0); +// static +void EventSendingController::DoDragDrop(const WebDragData& drag_data) { + current_drag_data = drag_data; + webview()->DragTargetDragEnter(drag_data, 0, WebPoint(), WebPoint()); // Finish processing events. ReplaySavedEvents(); @@ -234,6 +236,7 @@ int EventSendingController::GetButtonNumberFromSingleArg( return button_code; } + // // Implemented javascript methods. // @@ -302,17 +305,20 @@ void EventSendingController::mouseUp( pressed_button_ = WebMouseEvent::ButtonNone; // If we're in a drag operation, complete it. - if (drag_data_object.get()) { - bool valid = webview()->DragTargetDragOver(e.x, e.y, e.globalX, - e.globalY); + if (!current_drag_data.isNull()) { + WebPoint client_point(e.x, e.y); + WebPoint screen_point(e.globalX, e.globalY); + + bool valid = webview()->DragTargetDragOver(client_point, screen_point); if (valid) { - webview()->DragSourceEndedAt(e.x, e.y, e.globalX, e.globalY); - webview()->DragTargetDrop(e.x, e.y, e.globalX, e.globalY); + webview()->DragSourceEndedAt(client_point, screen_point); + webview()->DragTargetDrop(client_point, screen_point); } else { - webview()->DragSourceEndedAt(e.x, e.y, e.globalX, e.globalY); + webview()->DragSourceEndedAt(client_point, screen_point); webview()->DragTargetDragLeave(); } - drag_data_object.reset(); + + current_drag_data.reset(); } } @@ -337,12 +343,17 @@ void EventSendingController::mouseMoveTo( } } -/* static */ void EventSendingController::DoMouseMove(const WebMouseEvent& e) { +// static +void EventSendingController::DoMouseMove(const WebMouseEvent& e) { webview()->HandleInputEvent(&e); - if (pressed_button_ != WebMouseEvent::ButtonNone && drag_data_object.get()) { - webview()->DragSourceMovedTo(e.x, e.y, e.globalX, e.globalY); - webview()->DragTargetDragOver(e.x, e.y, e.globalX, e.globalY); + if (pressed_button_ != WebMouseEvent::ButtonNone && + !current_drag_data.isNull()) { + WebPoint client_point(e.x, e.y); + WebPoint screen_point(e.globalX, e.globalY); + + webview()->DragSourceMovedTo(client_point, screen_point); + webview()->DragTargetDragOver(client_point, screen_point); } } diff --git a/webkit/tools/test_shell/event_sending_controller.h b/webkit/tools/test_shell/event_sending_controller.h index d6d62d5..7123692 100644 --- a/webkit/tools/test_shell/event_sending_controller.h +++ b/webkit/tools/test_shell/event_sending_controller.h @@ -24,9 +24,9 @@ class TestShell; class WebView; -struct WebDropData; namespace WebKit { +class WebDragData; class WebMouseEvent; } @@ -40,7 +40,7 @@ class EventSendingController : public CppBoundClass { void Reset(); // Simulate drag&drop system call. - static void DoDragDrop(const WebDropData& drag_data); + static void DoDragDrop(const WebKit::WebDragData& drag_data); // JS callback methods. void mouseDown(const CppArgumentList& args, CppVariant* result); diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc index 1041bdd..40cd1c1 100644 --- a/webkit/tools/test_shell/test_shell_gtk.cc +++ b/webkit/tools/test_shell/test_shell_gtk.cc @@ -651,7 +651,7 @@ string16 GetLocalizedString(int message_id) { res.length() / 2); } -std::string GetDataResource(int resource_id) { +StringPiece GetDataResource(int resource_id) { switch (resource_id) { case IDR_FEED_PREVIEW: // It is necessary to return a feed preview template that contains @@ -667,7 +667,7 @@ std::string GetDataResource(int resource_id) { resource_id = IDR_TEXTAREA_RESIZER_TESTSHELL; break; } - return TestShell::NetResourceProvider(resource_id).as_string(); + return TestShell::NetResourceProvider(resource_id); } bool GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm index c62dab7..de558dd 100644 --- a/webkit/tools/test_shell/test_shell_mac.mm +++ b/webkit/tools/test_shell/test_shell_mac.mm @@ -649,7 +649,7 @@ string16 GetLocalizedString(int message_id) { res.length() / 2); } -std::string GetDataResource(int resource_id) { +StringPiece GetDataResource(int resource_id) { switch (resource_id) { case IDR_BROKENIMAGE: { // Use webkit's broken image icon (16x16) @@ -673,7 +673,7 @@ std::string GetDataResource(int resource_id) { // a {{URL}} substring where the feed URL should go; see the code // that computes feed previews in feed_preview.cc:MakeFeedPreview. // This fixes issue #932714. - return std::string("Feed preview for {{URL}}"); + return "Feed preview for {{URL}}"; case IDR_TEXTAREA_RESIZER: { // Use webkit's text area resizer image. static std::string resize_corner_data; @@ -693,13 +693,13 @@ std::string GetDataResource(int resource_id) { case IDR_SEARCH_CANCEL_PRESSED: case IDR_SEARCH_MAGNIFIER: case IDR_SEARCH_MAGNIFIER_RESULTS: - return TestShell::NetResourceProvider(resource_id).as_string(); + return TestShell::NetResourceProvider(resource_id); default: break; } - return std::string(); + return StringPiece(); } bool GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index ac3dcfc..6bba743 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -6,7 +6,7 @@ #define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_ #include "base/string_util.h" -#include "third_party/WebKit/WebKit/chromium/public/WebCString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebData.h" #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" @@ -83,7 +83,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { virtual void prefetchHostName(const WebKit::WebString&) { } - virtual WebKit::WebCString loadResource(const char* name) { + virtual WebKit::WebData loadResource(const char* name) { if (!strcmp(name, "deleteButton")) { // Create a red 30x30 square. const char red_square[] = @@ -98,7 +98,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d" "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60" "\x82"; - return WebKit::WebCString(red_square, arraysize(red_square)); + return WebKit::WebData(red_square, arraysize(red_square)); } return webkit_glue::WebKitClientImpl::loadResource(name); } diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc index fdd2fe9..c118ceb 100644 --- a/webkit/tools/test_shell/test_shell_win.cc +++ b/webkit/tools/test_shell/test_shell_win.cc @@ -697,7 +697,7 @@ string16 GetLocalizedString(int message_id) { } // TODO(tc): Convert this to using resources from test_shell.rc. -std::string GetDataResource(int resource_id) { +StringPiece GetDataResource(int resource_id) { switch (resource_id) { case IDR_BROKENIMAGE: { // Use webkit's broken image icon (16x16) @@ -718,7 +718,7 @@ std::string GetDataResource(int resource_id) { // a {{URL}} substring where the feed URL should go; see the code // that computes feed previews in feed_preview.cc:MakeFeedPreview. // This fixes issue #932714. - return std::string("Feed preview for {{URL}}"); + return "Feed preview for {{URL}}"; case IDR_TEXTAREA_RESIZER: { // Use webkit's text area resizer image. static std::string resize_corner_data; @@ -738,13 +738,13 @@ std::string GetDataResource(int resource_id) { case IDR_SEARCH_CANCEL_PRESSED: case IDR_SEARCH_MAGNIFIER: case IDR_SEARCH_MAGNIFIER_RESULTS: - return NetResourceProvider(resource_id).as_string(); + return NetResourceProvider(resource_id); default: break; } - return std::string(); + return StringPiece(); } HCURSOR LoadCursor(int cursor_id) { diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index fe33461..af7a662 100755 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -17,8 +17,10 @@ #include "base/string_util.h" #include "base/trace_event.h" #include "net/base/net_errors.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "webkit/glue/webdatasource.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/weberror.h" @@ -40,7 +42,9 @@ #include "webkit/tools/test_shell/drop_delegate.h" #endif +using WebKit::WebDragData; using WebKit::WebScreenInfo; +using WebKit::WebString; namespace { @@ -69,8 +73,8 @@ std::wstring UrlSuitableForTestResult(const std::wstring& url) { // Adds a file called "DRTFakeFile" to |data_object| (CF_HDROP). Use to fake // dragging a file. -void AddDRTFakeFileToDataObject(WebDropData* drop_data) { - drop_data->filenames.push_back(L"DRTFakeFile"); +void AddDRTFakeFileToDataObject(WebDragData* drag_data) { + drag_data->appendFileName(WebString::fromUTF8("DRTFakeFile")); } // Get a debugging string from a WebNavigationType. @@ -480,17 +484,17 @@ void TestWebViewDelegate::SetStatusbarText(WebView* webview, } void TestWebViewDelegate::StartDragging(WebView* webview, - const WebDropData& drop_data) { + const WebDragData& drag_data) { if (WebKit::layoutTestMode()) { - WebDropData mutable_drop_data = drop_data; + WebDragData mutable_drag_data = drag_data; if (shell_->layout_test_controller()->ShouldAddFileToPasteboard()) { // Add a file called DRTFakeFile to the drag&drop clipboard. - AddDRTFakeFileToDataObject(&mutable_drop_data); + AddDRTFakeFileToDataObject(&mutable_drag_data); } // When running a test, we need to fake a drag drop operation otherwise // Windows waits for real mouse events to know when the drag is over. - EventSendingController::DoDragDrop(mutable_drop_data); + EventSendingController::DoDragDrop(mutable_drag_data); } else { // TODO(tc): Drag and drop is disabled in the test shell because we need // to be able to convert from WebDragData to an IDataObject. diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 5481376..94e1f83 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -107,7 +107,7 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, unsigned int line_no, const std::wstring& source_id); virtual void StartDragging(WebView* webview, - const WebDropData& drop_data); + const WebKit::WebDragData& drag_data); virtual void ShowContextMenu(WebView* webview, ContextNode node, int x, diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index dd24b99..6727436 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -4113,6 +4113,8 @@ '../third_party/WebKit/WebKit/chromium/public/WebCommon.h', '../third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h', '../third_party/WebKit/WebKit/chromium/public/WebCString.h', + '../third_party/WebKit/WebKit/chromium/public/WebData.h', + '../third_party/WebKit/WebKit/chromium/public/WebDragData.h', '../third_party/WebKit/WebKit/chromium/public/WebFindOptions.h', '../third_party/WebKit/WebKit/chromium/public/WebImage.h', '../third_party/WebKit/WebKit/chromium/public/WebInputEvent.h', @@ -4126,6 +4128,7 @@ '../third_party/WebKit/WebKit/chromium/public/WebSize.h', '../third_party/WebKit/WebKit/chromium/public/WebString.h', '../third_party/WebKit/WebKit/chromium/public/WebURL.h', + '../third_party/WebKit/WebKit/chromium/public/WebVector.h', '../third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h', '../third_party/WebKit/WebKit/chromium/public/win/WebSandboxSupport.h', '../third_party/WebKit/WebKit/chromium/public/win/WebScreenInfoFactory.h', @@ -4139,6 +4142,8 @@ '../third_party/WebKit/WebKit/chromium/src/mac/WebScreenInfoFactory.mm', '../third_party/WebKit/WebKit/chromium/src/WebCache.cpp', '../third_party/WebKit/WebKit/chromium/src/WebCString.cpp', + '../third_party/WebKit/WebKit/chromium/src/WebData.cpp', + '../third_party/WebKit/WebKit/chromium/src/WebDragData.cpp', '../third_party/WebKit/WebKit/chromium/src/WebImageSkia.cpp', '../third_party/WebKit/WebKit/chromium/src/WebInputEvent.cpp', '../third_party/WebKit/WebKit/chromium/src/WebKit.cpp', @@ -4299,8 +4304,6 @@ 'glue/chrome_client_impl.cc', 'glue/chrome_client_impl.h', 'glue/chromium_bridge_impl.cc', - 'glue/clipboard_conversion.cc', - 'glue/clipboard_conversion.h', 'glue/context_menu.h', 'glue/context_menu_client_impl.cc', 'glue/context_menu_client_impl.h', @@ -4387,6 +4390,7 @@ 'glue/webdevtoolsclient_impl.cc', 'glue/webdevtoolsclient_impl.h', 'glue/webdropdata.cc', + 'glue/webdropdata_win.cc', 'glue/webdropdata.h', 'glue/weberror.h', 'glue/weberror_impl.cc', @@ -4476,7 +4480,6 @@ 'glue/plugins/mozilla_extensions.cc', 'glue/plugins/webplugin_delegate_impl.cc', 'glue/glue_accessibility.cc', - 'glue/webdropdata.cc', 'pending/AccessibleBase.cpp', 'pending/AccessibleDocument.cpp', ], |