From: Murugappan Nataraj Date: Tue, 15 Apr 2014 11:56:31 +0000 (+0530) Subject: Implement WebContentsViewEfl::RenderViewSwappedIn() X-Git-Tag: submit/tizen/20201118.160233~2046 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21dabcb2fd2b1e90420e4076a69c1614b1da6a6c;p=platform%2Fframework%2Fweb%2Fchromium-efl.git Implement WebContentsViewEfl::RenderViewSwappedIn() Borrowed the implementation from GTK+ port, 2 new files and 1 new function were added. Implementation provided to update drag destination. This commit is part of EFL port P0 API implementation. Change-Id: Ie9b7a05e8f93bf0a59cd474b0c32c6c5423079c6 Conflicts: impl/browser/web_contents/web_contents_view_efl.cc impl/browser/web_contents/web_contents_view_efl.h --- diff --git a/tizen_src/impl/browser/web_contents/web_contents_view_efl.cc b/tizen_src/impl/browser/web_contents/web_contents_view_efl.cc index 33257b8..092eb94 100644 --- a/tizen_src/impl/browser/web_contents/web_contents_view_efl.cc +++ b/tizen_src/impl/browser/web_contents/web_contents_view_efl.cc @@ -18,13 +18,15 @@ WebContentsView* CreateWebContentsView( WebContentsImpl* web_contents, WebContentsViewDelegate* delegate, RenderViewHostDelegateView** render_view_host_delegate_view) { - WebContentsViewEfl* view = new WebContentsViewEfl(web_contents); + WebContentsViewEfl* view = new WebContentsViewEfl(web_contents, delegate); *render_view_host_delegate_view = view; return view; } -WebContentsViewEfl::WebContentsViewEfl(WebContents* contents) - : web_contents_(contents) { +WebContentsViewEfl::WebContentsViewEfl(WebContents* contents, + WebContentsViewDelegate* delegate) + : delegate_(delegate), + web_contents_(contents) { } //////////////////////////////////////////////////////////////////////////////// @@ -32,7 +34,10 @@ WebContentsViewEfl::WebContentsViewEfl(WebContents* contents) void WebContentsViewEfl::CreateView(const gfx::Size& initial_size, gfx::NativeView context) { - NOTIMPLEMENTED(); + requested_size_ = initial_size; + + if (delegate_) + drag_dest_delegate_ = delegate_->GetDragDestDelegate(); } RenderWidgetHostViewBase* WebContentsViewEfl::CreateViewForWidget( @@ -64,12 +69,43 @@ void WebContentsViewEfl::SetPageTitle(const base::string16& title) { delegate->web_view()->SmartCallback().call(base::UTF16ToUTF8(title).c_str()); } +void WebContentsViewEfl::UpdateDragDest(RenderViewHost* host) { + // Drag-and-drop is entirely managed by BrowserPluginGuest for guest + // processes in a largely platform independent way. WebDragDestEfl + // will result in spurious messages being sent to the guest process which + // will violate assumptions. + if (host->GetProcess() && host->GetProcess()->IsIsolatedGuest()) { + DCHECK(!drag_dest_); + return; + } + + // If supporting RenderWidgetHostViewEfl::GetNativeView(), following lines + // will be enabled similar to GTK+ port + RenderWidgetHostViewEfl* view = static_cast( + web_contents_->GetRenderWidgetHostView()); + + // If the host is already used by the drag_dest_, there's no point in deleting + // the old one to create an identical copy. + + /*if (drag_dest_.get() && drag_dest_->widget() == content_view) + return;*/ + + // Clear the currently connected drag drop signals by deleting the old + // drag_dest_ before creating the new one. + drag_dest_.reset(); + // Create the new drag_dest_. + drag_dest_.reset(new WebDragDestEfl(web_contents_, view)); + + if (delegate_) + drag_dest_->set_delegate(delegate_->GetDragDestDelegate()); +} + void WebContentsViewEfl::RenderViewCreated(RenderViewHost* host) { NOTIMPLEMENTED(); } void WebContentsViewEfl::RenderViewSwappedIn(RenderViewHost* host) { - NOTIMPLEMENTED(); + UpdateDragDest(host); } void WebContentsViewEfl::SetOverscrollControllerEnabled(bool enabled) { diff --git a/tizen_src/impl/browser/web_contents/web_contents_view_efl.h b/tizen_src/impl/browser/web_contents/web_contents_view_efl.h index 753f575..ba2a476 100644 --- a/tizen_src/impl/browser/web_contents/web_contents_view_efl.h +++ b/tizen_src/impl/browser/web_contents/web_contents_view_efl.h @@ -5,6 +5,7 @@ #ifndef WEB_CONTENTS_VIEW_EFL #define WEB_CONTENTS_VIEW_EFL +#include "browser/web_contents/web_drag_dest_efl.h" #include "content/browser/renderer_host/render_view_host_delegate_view.h" #include "content/browser/web_contents/web_contents_view.h" @@ -17,7 +18,8 @@ class WebContentsViewEfl : public content::WebContentsView , public content::RenderViewHostDelegateView { public: - WebContentsViewEfl(WebContents* contents); + WebContentsViewEfl(WebContents* contents, + WebContentsViewDelegate* delegate = NULL); // content::WebContentsView implementation. virtual void CreateView( @@ -56,6 +58,20 @@ class WebContentsViewEfl virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE; virtual void CancelContextMenu(int request_id) OVERRIDE; + void UpdateDragDest(RenderViewHost* host); + + // Our optional views wrapper. + scoped_ptr delegate_; + + WebDragDestDelegate* drag_dest_delegate_; + + // The size we want the view to be. + gfx::Size requested_size_; + + // The helper object that handles drag destination related interactions with + // EFL. + scoped_ptr drag_dest_; + WebContents* web_contents_; }; diff --git a/tizen_src/impl/browser/web_contents/web_drag_dest_efl.cc b/tizen_src/impl/browser/web_contents/web_drag_dest_efl.cc new file mode 100644 index 0000000..5014c39 --- /dev/null +++ b/tizen_src/impl/browser/web_contents/web_drag_dest_efl.cc @@ -0,0 +1,124 @@ +// 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. + +#include "web_drag_dest_efl.h" + +#include +#include "base/bind.h" +#include "base/files/file_path.h" +#include "base/message_loop/message_loop.h" +#include "base/strings/utf_string_conversions.h" +#include "content/browser/web_contents/web_contents_impl.h" +#include "content/public/browser/web_contents_delegate.h" +#include "content/public/browser/web_drag_dest_delegate.h" +#include "content/public/common/url_constants.h" +#include "net/base/net_util.h" +#include "third_party/WebKit/public/web/WebInputEvent.h" +#include "ui/base/clipboard/custom_data_helper.h" + +#include "browser/renderer_host/render_widget_host_view_efl.h" + +using blink::WebDragOperation; +using blink::WebDragOperationNone; +using blink::WebDragOperationCopy; + +namespace content { + +#ifdef OS_TIZEN_TV +static void drag_state_enter_cb(void *data, Evas_Object *obj) { + WebDragDestEfl *webdragdestefl = (WebDragDestEfl *)data; + + webdragdestefl->drop_data_.reset(new DropData); + + if (webdragdestefl->delegate()) + webdragdestefl->delegate()->DragInitialize(webdragdestefl->web_contents()); +} + +static void drag_state_leave_cb(void *data, Evas_Object *obj) { + WebDragDestEfl *webdragdestefl = (WebDragDestEfl *)data; + + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&WebDragDestEfl::DragLeave, webdragdestefl->method_factory_.GetWeakPtr())); +} + +static void drag_Pos(void *data, Evas_Object *obj, Evas_Coord x, Evas_Coord y, Elm_Xdnd_Action action) { + WebDragDestEfl *webdragdestefl = (WebDragDestEfl *)data; + + gfx::Rect rect = webdragdestefl->render_widget_host_view()->GetBoundsInRootWindow(); + gfx::Point point = gfx::Point(rect.x(), rect.y()); + + webdragdestefl->GetRenderViewHost()->DragTargetDragOver( + point, + point, + WebDragOperationCopy, + blink::WebInputEvent::ControlKey); + + if (webdragdestefl->delegate()) + webdragdestefl->delegate()->OnDragOver(); +} + +static Eina_Bool drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *drop) { + WebDragDestEfl *webdragdestefl = (WebDragDestEfl *)data; + webdragdestefl->drop_data_->text = base::NullableString16(base::UTF8ToUTF16(std::string(reinterpret_cast(drop->data))), + false); + + gfx::Rect rect = webdragdestefl->render_widget_host_view()->GetBoundsInRootWindow(); + gfx::Point point = gfx::Point(rect.x(), rect.y()); + + webdragdestefl->GetRenderViewHost()->DragTargetDragEnter( + *webdragdestefl->drop_data_.get(), + point, + point, + WebDragOperationCopy, + blink::WebInputEvent::ControlKey); + + if (webdragdestefl->delegate()) + webdragdestefl->delegate()->OnDragEnter(); + + // Efl port need to check this, GTK+ port has drag data received & drag drop two callbacks + webdragdestefl->method_factory_.InvalidateWeakPtrs(); + + webdragdestefl->GetRenderViewHost()-> + DragTargetDrop(point, point, blink::WebInputEvent::ControlKey); + + if (webdragdestefl->delegate()) + webdragdestefl->delegate()->OnDrop(); + + return EINA_TRUE; +} +#endif // OS_TIZEN_TV + +WebDragDestEfl::WebDragDestEfl(WebContents* web_contents, RenderWidgetHostViewEfl *rwhvefl) + : method_factory_(this), + rwhvefl_(rwhvefl), + web_contents_(web_contents) { +#ifdef OS_TIZEN_TV + elm_drop_target_add(rwhvefl_->eweb_view()->evas_object(), ELM_SEL_FORMAT_TEXT, + drag_state_enter_cb, this, + drag_state_leave_cb, this, + drag_Pos, this, + drag_drop_cb, this); +#endif +} + +WebDragDestEfl::~WebDragDestEfl() { +#ifdef OS_TIZEN_TV + elm_drop_target_del(rwhvefl_->eweb_view()->evas_object()); +#endif +} + +void WebDragDestEfl::DragLeave() { + GetRenderViewHost()->DragTargetDragLeave(); + if (delegate()) + delegate()->OnDragLeave(); + + drop_data_.reset(); +} + +RenderViewHostImpl* WebDragDestEfl::GetRenderViewHost() const { + return static_cast(web_contents_->GetRenderViewHost()); +} + +} // namespace content diff --git a/tizen_src/impl/browser/web_contents/web_drag_dest_efl.h b/tizen_src/impl/browser/web_contents/web_drag_dest_efl.h new file mode 100644 index 0000000..95c46dd --- /dev/null +++ b/tizen_src/impl/browser/web_contents/web_drag_dest_efl.h @@ -0,0 +1,70 @@ +// 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. + +#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_DEST_EFL_H_ +#define CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_DEST_EFL_H_ + +#include "base/gtest_prod_util.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "content/browser/renderer_host/render_view_host_impl.h" +#include "content/common/content_export.h" +#include "content/public/common/drop_data.h" +#include "third_party/WebKit/public/web/WebDragOperation.h" + +#include +#include +#include +#include +#include + +namespace content { + +class RenderViewHostImpl; +class WebContents; +class WebDragDestDelegate; +class RenderWidgetHostViewEfl; + +#define EFL_CONTENT_EXPORT __attribute__((visibility("default"))) + +class EFL_CONTENT_EXPORT WebDragDestEfl { + public: + WebDragDestEfl(WebContents* web_contents, RenderWidgetHostViewEfl* rwhvefl); + ~WebDragDestEfl(); + + // Informs the renderer when a system drag has left the render view. + // See OnDragLeave(). + void DragLeave(); + + WebDragDestDelegate* delegate() const { return delegate_; } + void set_delegate(WebDragDestDelegate* delegate) { delegate_ = delegate; } + + RenderViewHostImpl* GetRenderViewHost() const; + + RenderWidgetHostViewEfl* render_widget_host_view() { return rwhvefl_; } + + WebContents* web_contents() { return web_contents_; } + + // EFL port - public variables for now, need to add get methods to make private, + // faced build errors with scoped_ptr, base::WeakPtrFactory methods. + + // The data for the current drag, or NULL if |context_| is NULL. + scoped_ptr drop_data_; + + base::WeakPtrFactory method_factory_; + + private: + // A delegate that can receive drag information about drag events. + WebDragDestDelegate* delegate_; + + // The render view. + RenderWidgetHostViewEfl *rwhvefl_; + + WebContents* web_contents_; + + DISALLOW_COPY_AND_ASSIGN(WebDragDestEfl); +}; +} // namespace content + +#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_DEST_EFL_H_ diff --git a/tizen_src/impl/chromium-efl.gyp b/tizen_src/impl/chromium-efl.gyp index 4111b48..9b280cd 100644 --- a/tizen_src/impl/chromium-efl.gyp +++ b/tizen_src/impl/chromium-efl.gyp @@ -109,6 +109,8 @@ 'browser/vibration/vibration_provider_client.h', 'browser/web_contents/web_contents_view_efl.cc', 'browser/web_contents/web_contents_view_efl.h', + 'browser/web_contents/web_drag_dest_efl.cc', + 'browser/web_contents/web_drag_dest_efl.h', 'browser_context_efl.cc', 'browser_context_efl.h', 'cache_params_efl.h',