Enable sound effect when tapping on a link
authorArnaud Renevier <a.renevier@samsung.com>
Fri, 10 Apr 2015 22:25:51 +0000 (15:25 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Previously, we were handling tap event in browser process. So, we had to
send a hit test request to the render process, which replied with a hit
test result.

In order to avoid that, we perform that hit test in the render process,
in RenderViewObserver::DidHandleGestureEvent method. If we tap on a
link, we ask the browser process to play a link effect sound.

Change-Id: I74710c8eff2f60bca831b1545832348c332ee269
Signed-off-by: Arnaud Renevier <a.renevier@samsung.com>
tizen_src/ewk/efl_integration/browser/web_view_browser_message_filter.cc
tizen_src/ewk/efl_integration/common/render_messages_ewk.h
tizen_src/ewk/efl_integration/private/ewk_settings_private.h
tizen_src/ewk/efl_integration/public/ewk_settings.cc
tizen_src/ewk/efl_integration/renderer/render_view_observer_efl.cc
tizen_src/ewk/efl_integration/renderer/render_view_observer_efl.h
tizen_src/ewk/efl_integration/tizen_webview/public/tw_settings.h

index 285b7eb..f0c1c32 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "browser/web_view_browser_message_filter.h"
 
+#include "browser/sound_effect.h"
 #include "common/web_contents_utils.h"
 #include "common/render_messages_ewk.h"
 #include "common/error_params.h"
@@ -83,6 +84,11 @@ class WebViewBrowserMessageFilterPrivate
       web_view_->InvokePlainTextGetCallback(content_text, plain_text_get_callback_id);
   }
 
+  void OnPlayLinkEffect() {
+    DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+    sound_effect::playLinkEffect();
+  }
+
   void OnWebAppIconUrlGet(const std::string &icon_url, int callback_id) {
     DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     if (web_view_)
@@ -177,6 +183,7 @@ void WebViewBrowserMessageFilter::OverrideThreadForMessage(
     case EwkViewMsg_DidFailLoadWithError::ID:
     case EwkViewHostMsg_HitTestAsyncReply::ID:
     case EwkHostMsg_PlainTextGetContents::ID:
+    case EwkHostMsg_PlayLinkEffect::ID:
     case EwkHostMsg_WebAppIconUrlGet::ID:
     case EwkHostMsg_WebAppIconUrlsGet::ID:
     case EwkHostMsg_WebAppCapableGet::ID:
@@ -198,6 +205,8 @@ bool WebViewBrowserMessageFilter::OnMessageReceived(
         WebViewBrowserMessageFilterPrivate::OnReceivedDidFailLoadWithError)
     IPC_MESSAGE_FORWARD(EwkHostMsg_PlainTextGetContents, private_,
         WebViewBrowserMessageFilterPrivate::OnPlainTextGetContents)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_PlayLinkEffect, private_,
+        WebViewBrowserMessageFilterPrivate::OnPlayLinkEffect)
     IPC_MESSAGE_FORWARD(EwkHostMsg_WebAppIconUrlGet, private_,
         WebViewBrowserMessageFilterPrivate::OnWebAppIconUrlGet)
     IPC_MESSAGE_FORWARD(EwkHostMsg_WebAppIconUrlsGet, private_,
index ebec84e..f2752e2 100644 (file)
@@ -35,6 +35,7 @@ IPC_STRUCT_TRAITS_END()
 
 IPC_STRUCT_TRAITS_BEGIN(tizen_webview::Settings)
   IPC_STRUCT_TRAITS_MEMBER(javascript_can_open_windows)
+  IPC_STRUCT_TRAITS_MEMBER(link_effect_enabled)
 IPC_STRUCT_TRAITS_END()
 
 IPC_STRUCT_TRAITS_BEGIN(ErrorParams)
@@ -229,6 +230,8 @@ IPC_MESSAGE_ROUTED1(EwkViewMsg_SelectionTextStyleState,
 
 IPC_MESSAGE_ROUTED1(EflViewMsg_UpdateSettings, tizen_webview::Settings)
 
+IPC_MESSAGE_ROUTED0(EwkHostMsg_PlayLinkEffect)
+
 IPC_MESSAGE_ROUTED2(EwkHostMsg_PlainTextGetContents,
                     std::string, /* contentText */
                     int /* callback id */)
index 2cb0930..c421642 100644 (file)
@@ -31,7 +31,6 @@ class Ewk_Settings {
         , m_useKeyPadWithoutUserAction(true)
         , m_textStyleState(true)
         , m_autoFitting(false)
-        , m_linkEffectEnabled(true)
         , m_detectContentsAutomatically(true)
         , m_evas_object(evas_object)
 #if defined(OS_TIZEN_TV)
@@ -82,8 +81,6 @@ class Ewk_Settings {
     void setTextStyleStateState(bool enable) { m_textStyleState = enable; }
     bool autoFitting() const {return m_autoFitting; }
     void setAutoFitting(bool enable) {m_autoFitting = enable; }
-    bool linkEffectEnabled() const { return m_linkEffectEnabled; }
-    void setLinkEffectEnabled(bool flag) { m_linkEffectEnabled = flag; }
     void setSpdyEnabled(bool flag);
     void setDetectContentsAutomatically(bool enable) { m_detectContentsAutomatically = enable; }
     bool detectContentsAutomatically() const { return m_detectContentsAutomatically; }
@@ -135,7 +132,6 @@ class Ewk_Settings {
     bool m_useKeyPadWithoutUserAction;
     bool m_textStyleState;
     bool m_autoFitting;
-    bool m_linkEffectEnabled;
     bool m_detectContentsAutomatically;
 
     Evas_Object* m_evas_object;
index 317a3c6..9d97c27 100644 (file)
@@ -288,15 +288,16 @@ Eina_Bool ewk_settings_link_magnifier_enabled_get(const Ewk_Settings *settings)
 
 Eina_Bool ewk_settings_link_effect_enabled_set(Ewk_Settings* settings, Eina_Bool linkEffectEnabled)
 {
-    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
-    settings->setLinkEffectEnabled(linkEffectEnabled);
-    return true;
+  EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
+  settings->getWebViewSettings().link_effect_enabled = linkEffectEnabled;
+  ewkUpdateWebkitPreferences(settings->getEvasObject());
+  return true;
 }
 
 Eina_Bool ewk_settings_link_effect_enabled_get(const Ewk_Settings* settings)
 {
-    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
-    return settings->linkEffectEnabled();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
+  return settings->getWebViewSettings().link_effect_enabled ? true : false;
 }
 
 Eina_Bool ewk_settings_uses_encoding_detector_set(Ewk_Settings* settings, Eina_Bool use)
index d01cd7c..46aadf8 100644 (file)
@@ -28,6 +28,7 @@
 #include "third_party/WebKit/public/web/WebFormElement.h"
 #include "third_party/WebKit/public/web/WebFrame.h"
 #include "third_party/WebKit/public/web/WebHitTestResult.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
 #include "third_party/WebKit/public/web/WebLocalFrame.h"
 #include "third_party/WebKit/public/web/WebPageSerializer.h"
 #include "third_party/WebKit/public/web/WebView.h"
@@ -149,6 +150,7 @@ RenderViewObserverEfl::RenderViewObserverEfl(
   : content::RenderViewObserver(render_view),
     cached_min_page_scale_factor_(-1.0),
     cached_max_page_scale_factor_(-1.0),
+    link_effect_enabled_(true),
     renderer_client_(render_client)
 {
 }
@@ -563,6 +565,12 @@ void RenderViewObserverEfl::OnWebAppCapableGet(int callback_id) {
   Send(new EwkHostMsg_WebAppCapableGet(render_view()->GetRoutingID(), capable, callback_id));
 }
 
+void RenderViewObserverEfl::DidHandleGestureEvent(const blink::WebGestureEvent& event)
+{
+  if (event.type == blink::WebInputEvent::GestureTap)
+    HandleTap(event);
+}
+
 void RenderViewObserverEfl::OnSetBrowserFont()
 {
 #if !defined(EWK_BRINGUP)
@@ -599,4 +607,19 @@ void RenderViewObserverEfl::OnUpdateSettings(const tizen_webview::Settings& sett
   if (renderer_client_) {
     static_cast<ContentRendererClientEfl*>(renderer_client_)->SetWebViewSettings(settings);
   }
+  link_effect_enabled_ = settings.link_effect_enabled;
+}
+
+void RenderViewObserverEfl::HandleTap(const blink::WebGestureEvent& event)
+{
+  if (link_effect_enabled_) {
+    const blink::WebHitTestResult web_hit_test_result =
+        render_view()->GetWebView()->hitTestResultAt(
+            blink::WebPoint(event.x, event.y));
+
+    if (!web_hit_test_result.absoluteLinkURL().isEmpty()) {
+      // we are on a link
+      Send(new EwkHostMsg_PlayLinkEffect(render_view()->GetRoutingID()));
+    }
+  }
 }
index 087317e..8db0c43 100644 (file)
@@ -36,6 +36,10 @@ namespace tizen_webview {
 class Settings;
 }
 
+namespace blink {
+class WebGestureEvent;
+}
+
 class EwkViewMsg_LoadData_Params;
 class Hit_Test_Params;
 
@@ -60,6 +64,8 @@ class RenderViewObserverEfl: public content::RenderViewObserver {
   //So using this notification to update minimum and maximum page scale factor values
   virtual void DidUpdateLayout() override;
 
+  void DidHandleGestureEvent(const blink::WebGestureEvent& event) override;
+
  private:
   void OnSetContentSecurityPolicy(const std::string& policy, Ewk_CSP_Header_Type header_type);
   void OnScale(double scale_factor, int x, int y);
@@ -82,6 +88,8 @@ class RenderViewObserverEfl: public content::RenderViewObserver {
   void OnResumeScheduledTasks();
   void OnUpdateSettings(const tizen_webview::Settings& settings);
 
+  void HandleTap(const blink::WebGestureEvent& event);
+
   // This function sets CSS "view-mode" media feature value.
   void OnSetViewMode(blink::WebViewMode view_mode);
 
@@ -90,6 +98,8 @@ class RenderViewObserverEfl: public content::RenderViewObserver {
   gfx::Size last_sent_contents_size_;
   base::OneShotTimer<RenderViewObserverEfl> check_contents_size_timer_;
 
+  bool link_effect_enabled_;
+
   content::ContentRendererClient* renderer_client_;
 };
 
index 3fbf98d..754656c 100644 (file)
@@ -7,8 +7,12 @@
 
 namespace tizen_webview {
 struct Settings {
-  Settings() : javascript_can_open_windows(false) {}
+  Settings() 
+    : javascript_can_open_windows(false),
+      link_effect_enabled(true) {}
+
   bool javascript_can_open_windows;
+  bool link_effect_enabled;
 };
 
 } // namespace tizen_webview