[M108 Migration] Migrate WebView focus related patches 07/287607/4
authorayush.k123 <ayush.k123@samsung.com>
Wed, 1 Feb 2023 07:14:15 +0000 (12:44 +0530)
committerBot Blink <blinkbot@samsung.com>
Thu, 2 Feb 2023 04:48:50 +0000 (04:48 +0000)
This patch migrates WebView's focus related patches.

References: https://review.tizen.org/gerrit/c/279552/

Change-Id: I42047923805973b8ac3a9b8290b13771953c0d3e
Signed-off-by: Ayush Kumar <ayush.k123@samsung.com>
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_offscreen_helper_efl.cc
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_offscreen_helper_efl.h
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/eweb_view_callbacks.h

index 97a72d5..e19a136 100644 (file)
@@ -533,6 +533,13 @@ bool RWHVAuraOffscreenHelperEfl::HasFocus() {
   return evas_object_focus_get(content_image_);
 }
 
+void RWHVAuraOffscreenHelperEfl::SetFocusInOutCallbacks(
+    const OnFocusCallback& on_focus_in,
+    const OnFocusCallback& on_focus_out) {
+  on_focus_in_callback_ = on_focus_in;
+  on_focus_out_callback_ = on_focus_out;
+}
+
 void RWHVAuraOffscreenHelperEfl::OnFocusIn(void* data,
                                            Evas* evas,
                                            Evas_Object* obj,
@@ -540,6 +547,9 @@ void RWHVAuraOffscreenHelperEfl::OnFocusIn(void* data,
   RWHVAuraOffscreenHelperEfl* thiz =
       static_cast<RWHVAuraOffscreenHelperEfl*>(data);
   thiz->FocusRWHVA();
+
+  if (!thiz->on_focus_in_callback_.is_null())
+    thiz->on_focus_in_callback_.Run();
 }
 
 void RWHVAuraOffscreenHelperEfl::OnFocusOut(void* data,
@@ -556,6 +566,9 @@ void RWHVAuraOffscreenHelperEfl::OnFocusOut(void* data,
       aura::client::GetFocusClient(window_host->window())->GetFocusedWindow();
   if (focused_window)
     focused_window->LostFocus();
+
+  if (!thiz->on_focus_out_callback_.is_null())
+    thiz->on_focus_out_callback_.Run();
 }
 
 void RWHVAuraOffscreenHelperEfl::OnHostFocusIn(void* data,
index 5bba8fb..da6c449 100644 (file)
@@ -52,6 +52,9 @@ class WebContentsDelegate;
 
 class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl {
  public:
+
+  using OnFocusCallback = base::RepeatingCallback<void(void)>;
+
   RWHVAuraOffscreenHelperEfl(RenderWidgetHostViewAura* rwhva,
                              WebContents* web_contents);
   ~RWHVAuraOffscreenHelperEfl();
@@ -121,6 +124,9 @@ class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl {
   gfx::NativeView GetNativeView();
   WebContents* GetWebContents() { return web_contents_; }
 
+  void SetFocusInOutCallbacks(const OnFocusCallback& on_focus_in,
+                              const OnFocusCallback& on_focus_out);
+
  private:
   static void OnParentViewResize(void* data, Evas*, Evas_Object*, void*);
   static void EvasObjectImagePixelsGetCallback(void*, Evas_Object*);
@@ -195,6 +201,9 @@ class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl {
   std::unique_ptr<base::OneShotTimer> snapshot_timer_;
   base::IDMap<std::unique_ptr<ScreenshotCapturedCallback>>
       screen_capture_cb_map_;
+
+  OnFocusCallback on_focus_in_callback_;
+  OnFocusCallback on_focus_out_callback_;
 };
 
 }  // namespace content
index f966854..363fc93 100644 (file)
@@ -8,6 +8,7 @@
 #include <Eina.h>
 #include <Elementary.h>
 
+#include "base/bind.h"
 #include "base/command_line.h"
 #include "base/files/file_path.h"
 #include "base/json/json_string_value_serializer.h"
@@ -164,6 +165,16 @@ RenderWidgetHostViewEfl* EWebView::rwhv() const {
 }
 #endif
 
+void EWebView::OnViewFocusIn(void* data, Evas*, Evas_Object*, void*) {
+  auto view = static_cast<EWebView*>(data);
+  view->SetFocus(EINA_TRUE);
+}
+
+void EWebView::OnViewFocusOut(void* data, Evas*, Evas_Object*, void*) {
+  auto view = static_cast<EWebView*>(data);
+  view->SetFocus(EINA_FALSE);
+}
+
 EWebView::EWebView(Ewk_Context* context, Evas_Object* object)
     : context_(context),
       evas_object_(object),
@@ -179,7 +190,14 @@ EWebView::EWebView(Ewk_Context* context, Evas_Object* object)
       page_scale_factor_(1.0),
       x_delta_(0.0),
       y_delta_(0.0),
-      is_initialized_(false) {}
+      is_initialized_(false) {
+ if (evas_object_) {
+    evas_object_event_callback_add(evas_object_, EVAS_CALLBACK_FOCUS_IN,
+                                   OnViewFocusIn, this);
+    evas_object_event_callback_add(evas_object_, EVAS_CALLBACK_FOCUS_OUT,
+                                   OnViewFocusOut, this);
+  }
+}
 
 void EWebView::Initialize() {
   if (is_initialized_) {
@@ -294,6 +312,13 @@ EWebView::~EWebView() {
   if (context_->GetImpl()->browser_context()->IsOffTheRecord())
     Ewk_Context::Delete(context_.get());
   gin_native_bridge_dispatcher_host_.reset();
+
+  if (evas_object_) {
+    evas_object_event_callback_del(evas_object_, EVAS_CALLBACK_FOCUS_IN,
+                                   OnViewFocusIn);
+    evas_object_event_callback_del(evas_object_, EVAS_CALLBACK_FOCUS_OUT,
+                                   OnViewFocusOut);
+  }
 }
 
 void EWebView::ReleasePopupMenuList() {
@@ -1581,15 +1606,23 @@ void EWebView::UpdateHitTestData(const Hit_Test_Params& params) {
 
 void EWebView::OnCopyFromBackingStore(bool success, const SkBitmap& bitmap) {}
 
+void EWebView::OnFocusIn() {
+  SmartCallback<EWebViewCallbacks::FocusIn>().call();
+}
+
+void EWebView::OnFocusOut() {
+  SmartCallback<EWebViewCallbacks::FocusOut>().call();
+}
+
 void EWebView::RenderViewCreated(RenderViewHost* render_view_host) {
   SendDelayedMessages(render_view_host);
   UpdateWebkitPreferencesEfl(render_view_host);
-#if !defined(USE_AURA)
-  RenderWidgetHostViewEfl* view = static_cast<RenderWidgetHostViewEfl*>(
-      render_view_host->GetWidget()->GetView());
-  if (view)
-    view->SetEvasHandler(evas_event_handler_);
-#endif
+  if (rwhva()) {
+    rwhva()->offscreen_helper()->SetFocusInOutCallbacks(
+        base::BindRepeating(&EWebView::OnFocusIn, base::Unretained(this)),
+        base::BindRepeating(&EWebView::OnFocusOut, base::Unretained(this)));
+  }
+
   if (render_view_host) {
     WebContents* content = WebContents::FromRenderViewHost(render_view_host);
     if (content) {
index 29c9703..111407f 100755 (executable)
@@ -341,6 +341,9 @@ class EWebView {
   // from render
   void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
 
+  void OnFocusIn();
+  void OnFocusOut();
+
   void RenderViewCreated(content::RenderViewHost* render_view_host);
 
   /**
@@ -582,6 +585,9 @@ class EWebView {
 
   void ChangeScroll(int& x, int& y);
 
+  static void OnViewFocusIn(void* data, Evas*, Evas_Object*, void*);
+  static void OnViewFocusOut(void* data, Evas*, Evas_Object*, void*);
+
   scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
   scoped_refptr<Ewk_Context> context_;
   scoped_refptr<Ewk_Context> old_context_;
index 16bcd36..0a17d74 100644 (file)
@@ -142,7 +142,9 @@ enum CallbackType {
 #endif  // IS_TIZEN
   URIChanged,
   DidNotAllowScript,
-  NotificationPermissionReply
+  NotificationPermissionReply,
+  FocusIn,
+  FocusOut
 };
 
 template <CallbackType>
@@ -297,6 +299,8 @@ DECLARE_EWK_VIEW_CALLBACK(DidNotAllowScript, "did,not,allow,script", void);
 DECLARE_EWK_VIEW_CALLBACK(NotificationPermissionReply,
                           "notification,permission,reply",
                           Ewk_Notification_Permission*);
+DECLARE_EWK_VIEW_CALLBACK(FocusOut, "webview,focus,out", void);
+DECLARE_EWK_VIEW_CALLBACK(FocusIn, "webview,focus,in", void);
 }
 
 #endif