[EFL][WK2] Support sub menu in ewk context menus
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 May 2013 13:46:33 +0000 (13:46 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 May 2013 13:46:33 +0000 (13:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=114729

Patch by Michał Pakuła vel Rutka <m.pakula@samsung.com> on 2013-05-17
Reviewed by Christophe Dumez.

Added submenu support in EwkContextMenu and an API function to receive
Ewk_Context_Menu from submenu context menu item. A test case was added
for new API function.
EwkContextMenu is now an EwkObject allowing multiple instances of submenu
to be used in different submenu type context menu items.

* UIProcess/API/efl/ewk_context_menu_item.cpp:
(EwkContextMenuItem::EwkContextMenuItem):
(ewk_context_menu_item_new):
(ewk_context_menu_item_parent_menu_get):
(ewk_context_menu_item_submenu_get):
* UIProcess/API/efl/ewk_context_menu_item.h:
* UIProcess/API/efl/ewk_context_menu_item_private.h:
(EwkContextMenuItem::create):
(EwkContextMenuItem::parentMenu):
(EwkContextMenuItem::subMenu):
(EwkContextMenuItem):
* UIProcess/API/efl/ewk_context_menu_private.h:
(EwkContextMenu::ewkView):
(EwkContextMenu):
* UIProcess/API/efl/tests/test_ewk2_context_menu.cpp:
(showContextMenu):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150254 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/efl/ewk_context_menu_item.cpp
Source/WebKit2/UIProcess/API/efl/ewk_context_menu_item.h
Source/WebKit2/UIProcess/API/efl/ewk_context_menu_item_private.h
Source/WebKit2/UIProcess/API/efl/ewk_context_menu_private.h
Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context_menu.cpp

index c3394c5..b24a872 100644 (file)
@@ -1,3 +1,33 @@
+2013-05-17  Michał Pakuła vel Rutka  <m.pakula@samsung.com>
+
+        [EFL][WK2] Support sub menu in ewk context menus
+        https://bugs.webkit.org/show_bug.cgi?id=114729
+
+        Reviewed by Christophe Dumez.
+
+        Added submenu support in EwkContextMenu and an API function to receive
+        Ewk_Context_Menu from submenu context menu item. A test case was added
+        for new API function.
+        EwkContextMenu is now an EwkObject allowing multiple instances of submenu
+        to be used in different submenu type context menu items.
+
+        * UIProcess/API/efl/ewk_context_menu_item.cpp:
+        (EwkContextMenuItem::EwkContextMenuItem):
+        (ewk_context_menu_item_new):
+        (ewk_context_menu_item_parent_menu_get):
+        (ewk_context_menu_item_submenu_get):
+        * UIProcess/API/efl/ewk_context_menu_item.h:
+        * UIProcess/API/efl/ewk_context_menu_item_private.h:
+        (EwkContextMenuItem::create):
+        (EwkContextMenuItem::parentMenu):
+        (EwkContextMenuItem::subMenu):
+        (EwkContextMenuItem):
+        * UIProcess/API/efl/ewk_context_menu_private.h:
+        (EwkContextMenu::ewkView):
+        (EwkContextMenu):
+        * UIProcess/API/efl/tests/test_ewk2_context_menu.cpp:
+        (showContextMenu):
+
 2013-05-17  Zoltan Arvai  <zarvai@inf.u-szeged.hu>, Ádám Kallai  <kadam@inf.u-szeged.hu>
 
         [Qt] Unreviewed build fix.
index 780850b..62afd69 100644 (file)
@@ -27,6 +27,7 @@
 #include "ewk_context_menu_item.h"
 
 #include "ewk_context_menu_item_private.h"
+#include "ewk_context_menu_private.h"
 #include "ewk_private.h"
 #include <WebKit2/WKContextMenuItemTypes.h>
 #include <wtf/text/CString.h>
@@ -35,18 +36,21 @@ using namespace WebKit;
 
 static Ewk_Context_Menu_Item_Action getEwkActionFromWKTag(WKContextMenuItemTag action);
 
-EwkContextMenuItem::EwkContextMenuItem(WKContextMenuItemRef item, EwkContextMenu* parentMenu)
+EwkContextMenuItem::EwkContextMenuItem(WKContextMenuItemRef item, PassRefPtr<EwkContextMenu> parentMenu)
     : m_type(static_cast<Ewk_Context_Menu_Item_Type>(WKContextMenuItemGetType(item)))
     , m_action(getEwkActionFromWKTag((WKContextMenuItemGetTag(item))))
     , m_title(WKEinaSharedString(AdoptWK, WKContextMenuItemCopyTitle(item)))
     , m_isChecked(WKContextMenuItemGetChecked(item))
     , m_isEnabled(WKContextMenuItemGetEnabled(item))
     , m_parentMenu(parentMenu)
-    , m_subMenu(0)
 {
+    if (WKContextMenuItemGetType(item) == kWKContextMenuItemTypeSubmenu) {
+        WKRetainPtr<WKArrayRef> menuItems = adoptWK(WKContextMenuCopySubmenuItems(item));
+        m_subMenu = EwkContextMenu::create(parentMenu->ewkView(), menuItems.get());
+    }
 }
 
-EwkContextMenuItem::EwkContextMenuItem(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, EwkContextMenu* subMenu, EwkContextMenu* parentMenu)
+EwkContextMenuItem::EwkContextMenuItem(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, PassRefPtr<EwkContextMenu> subMenu, PassRefPtr<EwkContextMenu> parentMenu)
     : m_type(type)
     , m_action(action)
     , m_title(title)
@@ -59,7 +63,7 @@ EwkContextMenuItem::EwkContextMenuItem(Ewk_Context_Menu_Item_Type type, Ewk_Cont
 
 Ewk_Context_Menu_Item* ewk_context_menu_item_new(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled)
 {
-    return Ewk_Context_Menu_Item::create(type, action, title, checked, enabled, 0).leakPtr();
+    return Ewk_Context_Menu_Item::create(type, action, title, checked, enabled).leakPtr();
 }
 
 Ewk_Context_Menu_Item* ewk_context_menu_item_new_with_submenu(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, Ewk_Context_Menu* subMenu)
@@ -153,7 +157,14 @@ Ewk_Context_Menu* ewk_context_menu_item_parent_menu_get(const Ewk_Context_Menu_I
 {
     EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
 
-    return const_cast<Ewk_Context_Menu_Item*>(item)->parentMenu();
+    return item->parentMenu();
+}
+
+Ewk_Context_Menu* ewk_context_menu_item_submenu_get(const Ewk_Context_Menu_Item* item)
+{
+    EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
+
+    return item->subMenu();
 }
 
 static Ewk_Context_Menu_Item_Action getEwkActionFromWKTag(WKContextMenuItemTag action)
index 208e0ad..b014cbc 100644 (file)
@@ -268,6 +268,15 @@ EAPI Eina_Bool ewk_context_menu_item_enabled_set(Ewk_Context_Menu_Item *o, Eina_
  */
 EAPI Ewk_Context_Menu *ewk_context_menu_item_parent_menu_get(const Ewk_Context_Menu_Item *o);
 
+/**
+ * Gets the submenu for the item.
+ *
+ * @param o item to get the submenu
+ *
+ * @return the pointer to submenu on success or @c NULL on failure
+ */
+EAPI Ewk_Context_Menu *ewk_context_menu_item_submenu_get(const Ewk_Context_Menu_Item *o);
+
 #ifdef __cplusplus
 }
 #endif
index e9c446e..3287d10 100644 (file)
@@ -32,6 +32,8 @@
 #include "ewk_context_menu_item.h"
 #include "ewk_context_menu_private.h"
 #include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
 
 /**
  * \struct  Ewk_Context_Menu_Item
  */
 class EwkContextMenuItem {
 public:
-    static PassOwnPtr<EwkContextMenuItem> create(WKContextMenuItemRef item, EwkContextMenu* parentMenu = 0)
+    static PassOwnPtr<EwkContextMenuItem> create(WKContextMenuItemRef item, PassRefPtr<EwkContextMenu> parentMenu = 0)
     {
         return adoptPtr(new EwkContextMenuItem(item, parentMenu));
     }
 
-    static PassOwnPtr<EwkContextMenuItem> create(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, EwkContextMenu* subMenu, EwkContextMenu* parentMenu = 0)
+    static PassOwnPtr<EwkContextMenuItem> create(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, PassRefPtr<EwkContextMenu> subMenu = 0, PassRefPtr<EwkContextMenu> parentMenu = 0)
     {
         return adoptPtr(new EwkContextMenuItem(type, action, title, checked, enabled, subMenu, parentMenu));
     }
@@ -64,12 +66,14 @@ public:
     bool enabled() const { return m_isEnabled; }
     void setEnabled(bool enabled) { m_isEnabled = enabled; }
 
-    EwkContextMenu* parentMenu() const { return m_parentMenu; }
+    EwkContextMenu* parentMenu() const { return m_parentMenu.get(); }
     void setParentMenu(EwkContextMenu* parentMenu) { m_parentMenu = parentMenu; }
 
+    EwkContextMenu* subMenu() const { return m_subMenu.get(); }
+
 private:
-    EwkContextMenuItem(WKContextMenuItemRef, EwkContextMenu* parentMenu);
-    EwkContextMenuItem(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, EwkContextMenu* subMenu, EwkContextMenu* parentMenu);
+    EwkContextMenuItem(WKContextMenuItemRef, PassRefPtr<EwkContextMenu> parentMenu);
+    EwkContextMenuItem(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, PassRefPtr<EwkContextMenu> subMenu, PassRefPtr<EwkContextMenu> parentMenu);
 
     Ewk_Context_Menu_Item_Type m_type;
     Ewk_Context_Menu_Item_Action m_action;
@@ -79,8 +83,8 @@ private:
     bool m_isChecked;
     bool m_isEnabled;
 
-    EwkContextMenu* m_parentMenu;
-    EwkContextMenu* m_subMenu;
+    RefPtr<EwkContextMenu> m_parentMenu;
+    RefPtr<EwkContextMenu> m_subMenu;
 };
 
 #endif // ewk_context_menu_item_private_h
index 8fc3d2e..49b5f97 100644 (file)
@@ -61,6 +61,8 @@ public:
     const Eina_List* items() const { return m_contextMenuItems; }
     void contextMenuItemSelected(WKContextMenuItemRef item);
 
+    EwkView* ewkView() const { return m_viewImpl; }
+
 private:
     EwkContextMenu();
     EwkContextMenu(Eina_List* items);
index 7306eb4..ba2c8de 100644 (file)
@@ -73,6 +73,9 @@ static Eina_Bool showContextMenu(Ewk_View_Smart_Data* smartData, Evas_Coord x, E
     // When context menu item is added to menu using ewk_context_menu_item_append, it should have parent menu.
     EXPECT_EQ(contextMenu, ewk_context_menu_item_parent_menu_get(newItem));
 
+    // When context menu item was created using ewk_context_menu_item_new, submenu should be 0.
+    EXPECT_EQ(0, ewk_context_menu_item_submenu_get(newItem));
+
     Eina_List* subMenuItemList = 0;
     Ewk_Context_Menu_Item* subMenuItem1 = ewk_context_menu_item_new(EWK_ACTION_TYPE, EWK_CONTEXT_MENU_ITEM_TAG_OTHER, "New SubMenu Item 1", false, true);
     Ewk_Context_Menu_Item* subMenuItem2 = ewk_context_menu_item_new(EWK_ACTION_TYPE, EWK_CONTEXT_MENU_ITEM_TAG_OTHER, "New SubMenu Item 2", false, true);
@@ -90,6 +93,9 @@ static Eina_Bool showContextMenu(Ewk_View_Smart_Data* smartData, Evas_Coord x, E
     EXPECT_EQ(0, ewk_context_menu_item_parent_menu_get(newItem));
     ewk_context_menu_item_append(contextMenu, newItem2);
 
+    // Context menu received from ewk_context_menu_item_submenu_get should be the same as one used to create sub menu.
+    EXPECT_EQ(subMenu, ewk_context_menu_item_submenu_get(newItem2));
+
     // When context menu item is created using ewk_context_menu_item_new_with_submenu and added using ewk_context_menu_item_append it should have parent menu.
     EXPECT_EQ(contextMenu, ewk_context_menu_item_parent_menu_get(newItem));