Make context menu work on links and images.
authorAntonio Gomes <a1.gomes@samsung.com>
Thu, 10 Sep 2015 14:05:00 +0000 (10:05 -0400)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Context menu were not being shown in response to long
press gestures on links and images.

These are the two cases context menu are shown:

1) user does a long press on selectable text and input fields:
context menu is only shown when user lift its finger up.
While finger is still down, user sees a magnifier glass with
zoomed in content, and can select different content as long
as it has not lifted up its finger yet.

2) user does a long press on a link and image:
context menu is shown right after the long press event gets triggered.

However, (2) was not triggering any context menu creation.
Problem was that EWebView::ShowContextMenu was calling
SelectionControllerEfl::HandleLongPress, and it was simply
calling a LOG for links and images cases.

Patch adds return value to SelectionControllerEfl::HandleLongPress to
work as an indicator that the context menu should be shown immediatly
or if it should be shown when users' finger is lifted up.

Original beta/m42 patches:
- http://165.213.202.130/gerrit/#/c/86940/ , reviewed by
Janusz Majnert, arno renevier.
- http://165.213.202.130/gerrit/#/c/86943/ , reviewed by
Jaesik Chang, arno renevier.
- http://165.213.202.130/gerrit/#/c/87569/ , reviewed by
Janusz Majnert, arno renevier.

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=6663

Reviewed by: a.renevier, sns.park

Change-Id: I6f9873582c1b3eccd1e5f084b177538b59093502
Signed-off-by: Antonio Gomes <a1.gomes@samsung.com>
tizen_src/chromium_impl/content/browser/selection/selection_controller_efl.cc
tizen_src/chromium_impl/content/browser/selection/selection_controller_efl.h
tizen_src/ewk/efl_integration/context_menu_controller_efl.cc
tizen_src/ewk/efl_integration/context_menu_controller_efl.h
tizen_src/ewk/efl_integration/eweb_view.cc

index 8de7261..0a8ef0b 100644 (file)
@@ -570,7 +570,7 @@ void SelectionControllerEfl::HandlePostponedGesture(int x, int y, ui::EventType
   }
 }
 
-void SelectionControllerEfl::HandleLongPressEvent(
+bool SelectionControllerEfl::HandleLongPressEvent(
     const gfx::Point& touch_point,
     const content::ContextMenuParams& params) {
 
@@ -578,19 +578,28 @@ void SelectionControllerEfl::HandleLongPressEvent(
     SetSelectionStatus(true);
     SetSelectionEditable(true);
     HandleLongPressEventPrivate(touch_point);
+    return true;
   } else if (params.link_url.is_empty()
       && params.src_url.is_empty()
       && params.is_text_node) {
     SetSelectionStatus(true);
     SetSelectionEditable(false);
     HandleLongPressEventPrivate(touch_point);
-    DVLOG(1) << __PRETTY_FUNCTION__ << ":: link, !image, !media, text";
+    DVLOG(1) << __PRETTY_FUNCTION__ << ":: !link, !image, !media, text";
+    return true;
   } else if (!params.src_url.is_empty() && params.has_image_contents) {
     DVLOG(1) << __PRETTY_FUNCTION__ << ":: IMAGE";
+    long_mouse_press_ = false;
+    return false;
   } else if (!params.link_url.is_empty()) {
-    ClearSelectionViaEWebView();
     DVLOG(1) << __PRETTY_FUNCTION__ << ":: LINK";
+    long_mouse_press_ = false;
+    return false;
   }
+  // Default return is true, because if 'params' did not
+  // fall through any of the switch cases above, no further
+  // action should be taken by the callee.
+  return true;
 }
 
 void SelectionControllerEfl::HandleLongPressEventPrivate(const gfx::Point& touch_point) {
index 95b47aa..3428a71 100644 (file)
@@ -51,7 +51,7 @@ class CONTENT_EXPORT SelectionControllerEfl {
   ~SelectionControllerEfl();
 
   // Functions that handle long press, long press move and release
-  void HandleLongPressEvent(const gfx::Point& touch_point,
+  bool HandleLongPressEvent(const gfx::Point& touch_point,
       const content::ContextMenuParams& params);
   void HandleLongPressMoveEvent(const gfx::Point& touch_point);
   void HandleLongPressEndEvent();
index f15c0a1..ce6e967 100644 (file)
@@ -75,12 +75,12 @@ bool ContextMenuControllerEfl::PopulateAndShowContextMenu(const ContextMenuParam
   return ShowContextMenu();
 }
 
-void ContextMenuControllerEfl::AddItemToPropsedList(ContextMenuOptionType item,
-                                                    ContextMenuOption option,
-                                                    std::string title,
-                                                    std::string image_url,
-                                                    std::string link_url,
-                                                    std::string icon_path) {
+void ContextMenuControllerEfl::AddItemToProposedList(ContextMenuOptionType item,
+                                                     ContextMenuOption option,
+                                                     const std::string& title,
+                                                     const std::string& image_url,
+                                                     const std::string& link_url,
+                                                     const std::string& icon_path) {
   ContextMenuItemEfl* new_menu_item = new ContextMenuItemEfl(
       item, option, title, image_url, link_url, icon_path);
   _Ewk_Context_Menu_Item* new_item = new _Ewk_Context_Menu_Item(new_menu_item);
@@ -89,18 +89,18 @@ void ContextMenuControllerEfl::AddItemToPropsedList(ContextMenuOptionType item,
 
 void ContextMenuControllerEfl::GetProposedContextMenu() {
   if (!params_.link_url.is_empty()) {
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION,
         MENU_ITEM_OPEN_LINK_IN_NEW_WINDOW,
         std::string(dgettext("WebKit",
             "IDS_WEBVIEW_OPT_OPEN_LINK_IN_NEW_TAB_ABB")),
         params_.link_url.spec(),
         params_.link_url.spec());
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION,
         MENU_ITEM_COPY_LINK_TO_CLIPBOARD,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_COPY_LINK_URL_ABB")),
         std::string(),
         params_.link_url.spec());
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION,
         MENU_ITEM_DOWNLOAD_LINK_TO_DISK,
         std::string(dgettext("WebKit", "IDS_BR_BODY_SAVE_LINK")),
         std::string(),
@@ -108,48 +108,48 @@ void ContextMenuControllerEfl::GetProposedContextMenu() {
   }
 #if !defined(WAYLAND_BRINGUP)
   if (params_.is_editable && ClipboardHelperEfl::NumberOfItems() > 0) {
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_PASTE,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_PASTE,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_PASTE")));
   }
 #else
   NOTIMPLEMENTED();
 #endif
   if (!params_.selection_text.empty() && params_.is_editable) {
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_CUT,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_CUT,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_CUT_ABB")));
   }
   if (!params_.selection_text.empty()) {
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_COPY,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_COPY,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_COPY")));
     if (!params_.is_editable) {
-      AddItemToPropsedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_SEARCH_WEB,
+      AddItemToProposedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_SEARCH_WEB,
           std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_WEB_SEARCH")));
 #if !defined(OS_TIZEN_MOBILE)
-      AddItemToPropsedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_SEARCH_IN_SPOTLIGHT,
+      AddItemToProposedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_SEARCH_IN_SPOTLIGHT,
           std::string());
 #endif
     }
   }
 
  if (params_.has_image_contents && !params_.src_url.is_empty()) {
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION,
         MENU_ITEM_OPEN_IMAGE_IN_NEW_WINDOW,
         std::string(dgettext("WebKit",
             "IDS_WEBVIEW_OPT_OPEN_IMAGE_IN_NEW_TAB_ABB")),
         params_.src_url.spec(),
         params_.src_url.spec());
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION,
         MENU_ITEM_DOWNLOAD_IMAGE_TO_DISK,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_SAVE_IMAGE_ABB")),
         params_.src_url.spec(),
         params_.src_url.spec());
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION,
         MENU_ITEM_COPY_IMAGE_TO_CLIPBOARD,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_COPY_IMAGE")),
         params_.src_url.spec(),
         params_.src_url.spec());
   } else if (!params_.link_url.is_empty()) {
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION,
         MENU_ITEM_TEXT_SELECTION_MODE,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_SELECTION_MODE_ABB")),
         params_.link_url.spec(),
@@ -159,20 +159,20 @@ void ContextMenuControllerEfl::GetProposedContextMenu() {
   RenderWidgetHostViewEfl* rwhv = static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
   if (!params_.selection_text.empty()
       || (params_.is_editable && (rwhv && !rwhv->IsLastAvailableTextEmpty()))) {
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_SELECT_WORD,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_SELECT_WORD,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_SELECT_ABB")));
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_SELECT_ALL,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_SELECT_ALL,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_SELECT_ALL_ABB")));
   }
 #if !defined(EWK_BRINGUP)
   if (params_.is_draggable) {
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_DRAG,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_DRAG,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_DRAG_AND_DROP")));
   }
 #endif
 #if !defined(WAYLAND_BRINGUP)
   if (params_.is_editable && ClipboardHelperEfl::NumberOfItems() > 0) {
-    AddItemToPropsedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_CLIPBOARD,
+    AddItemToProposedList(MENU_ITEM_TYPE_ACTION, MENU_ITEM_CLIPBOARD,
         std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_CLIPBOARD")));
   }
 #else
index 8ff63a9..9daaa92 100644 (file)
@@ -197,12 +197,12 @@ class ContextMenuControllerEfl
   void GetProposedContextMenu();
   bool CreateContextMenu();
   bool ShowContextMenu();
-  void AddItemToPropsedList(ContextMenuOptionType item,
-                            ContextMenuOption option,
-                            std::string title,
-                            std::string image_url = std::string(),
-                            std::string link_url = std::string(),
-                            std::string icon_path = std::string());
+  void AddItemToProposedList(ContextMenuOptionType item,
+                             ContextMenuOption option,
+                             const std::string& title,
+                             const std::string& image_url = std::string(),
+                             const std::string& link_url = std::string(),
+                             const std::string& icon_path = std::string());
   void HideSelectionHandle();
   void ShowSelectionHandleAndContextMenu();
   virtual void OnDownloadUpdated(content::DownloadItem* download) override;
index 5582900..da57d64 100644 (file)
@@ -1125,10 +1125,12 @@ void EWebView::ShowContextMenu(const content::ContextMenuParams& params) {
   context_menu_position_ = gfx::Point(convertedParams.x, convertedParams.y);
 
   if (GetSelectionController()) {
-    if (GetSelectionController()->GetLongPressed()) {
-      GetSelectionController()->HandleLongPressEvent(convertedPoint, convertedParams);
-    } else {
-      if(!context_menu_->PopulateAndShowContextMenu(convertedParams)) {
+    bool handled = false;
+    if (GetSelectionController()->GetLongPressed())
+      handled = GetSelectionController()->HandleLongPressEvent(convertedPoint, convertedParams);
+
+    if (!handled) {
+      if (!context_menu_->PopulateAndShowContextMenu(convertedParams)) {
         context_menu_.reset();
         GetSelectionController()->HideHandles();
       }