[EFL][WK2] Add an API for getting context menu item's parent menu
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Apr 2013 15:34:18 +0000 (15:34 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Apr 2013 15:34:18 +0000 (15:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=107510

Patch by Michał Pakuła vel Rutka <m.pakula@samsung.com> on 2013-04-16
Reviewed by Kenneth Rohde Christiansen.

Added parent menu support and API for Ewk_Context_Menu_Item, to
allow selecting context menus using Elementary widgets.
Context menu unit test updated with new function.

* UIProcess/API/efl/ewk_context_menu.cpp:
(EwkContextMenu::EwkContextMenu):
* UIProcess/API/efl/ewk_context_menu_item.cpp:
(EwkContextMenuItem::EwkContextMenuItem):
(ewk_context_menu_item_parent_menu_get):
* UIProcess/API/efl/ewk_context_menu_item.h:
* UIProcess/API/efl/ewk_context_menu_item_private.h:
(EwkContextMenuItem::create):
(EwkContextMenuItem::parentMenu):
(EwkContextMenuItem::setParentMenu):
(EwkContextMenuItem):
* UIProcess/API/efl/tests/test_ewk2_context_menu.cpp:
(showContextMenu):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/efl/ewk_context_menu.cpp
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/tests/test_ewk2_context_menu.cpp

index 4e9495a..7254104 100644 (file)
@@ -1,3 +1,28 @@
+2013-04-16  Michał Pakuła vel Rutka  <m.pakula@samsung.com>
+
+        [EFL][WK2] Add an API for getting context menu item's parent menu
+        https://bugs.webkit.org/show_bug.cgi?id=107510
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Added parent menu support and API for Ewk_Context_Menu_Item, to
+        allow selecting context menus using Elementary widgets.
+        Context menu unit test updated with new function. 
+
+        * UIProcess/API/efl/ewk_context_menu.cpp:
+        (EwkContextMenu::EwkContextMenu):
+        * UIProcess/API/efl/ewk_context_menu_item.cpp:
+        (EwkContextMenuItem::EwkContextMenuItem):
+        (ewk_context_menu_item_parent_menu_get):
+        * UIProcess/API/efl/ewk_context_menu_item.h:
+        * UIProcess/API/efl/ewk_context_menu_item_private.h:
+        (EwkContextMenuItem::create):
+        (EwkContextMenuItem::parentMenu):
+        (EwkContextMenuItem::setParentMenu):
+        (EwkContextMenuItem):
+        * UIProcess/API/efl/tests/test_ewk2_context_menu.cpp:
+        (showContextMenu):
+
 2013-04-16  Andreas Kling  <akling@apple.com>
 
         Fix release builds with !LOG_DISABLED.
index a54cbba..a480ad5 100644 (file)
@@ -45,7 +45,7 @@ EwkContextMenu::EwkContextMenu(EwkView* view, WKArrayRef items)
 {
     size_t size = WKArrayGetSize(items);
     for (size_t i = 0; i < size; ++i)
-        m_contextMenuItems = eina_list_append(m_contextMenuItems, Ewk_Context_Menu_Item::create(static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(items, i))).leakPtr());
+        m_contextMenuItems = eina_list_append(m_contextMenuItems, Ewk_Context_Menu_Item::create(static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(items, i)), this).leakPtr());
 }
 
 EwkContextMenu::EwkContextMenu()
@@ -60,8 +60,12 @@ EwkContextMenu::EwkContextMenu(Eina_List* items)
 {
     Eina_List* l;
     void* data;
-    EINA_LIST_FOREACH(items, l, data)
-        m_contextMenuItems = eina_list_append(m_contextMenuItems, static_cast<EwkContextMenuItem*>(data));
+    EINA_LIST_FOREACH(items, l, data) {
+        if (EwkContextMenuItem* item = static_cast<EwkContextMenuItem*>(data)) {
+            item->setParentMenu(this);
+            m_contextMenuItems = eina_list_append(m_contextMenuItems, item);
+        }
+    }
 }
 
 EwkContextMenu::~EwkContextMenu()
index edb9f46..9b85ba9 100644 (file)
@@ -35,24 +35,24 @@ using namespace WebKit;
 
 static Ewk_Context_Menu_Item_Action getEwkActionFromWKTag(WKContextMenuItemTag action);
 
-EwkContextMenuItem::EwkContextMenuItem(WKContextMenuItemRef item)
+EwkContextMenuItem::EwkContextMenuItem(WKContextMenuItemRef item, Ewk_Context_Menu* 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(0)
+    , m_parentMenu(parentMenu)
     , m_subMenu(0)
 {
 }
 
-EwkContextMenuItem::EwkContextMenuItem(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)
+EwkContextMenuItem::EwkContextMenuItem(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, Ewk_Context_Menu* parentMenu)
     : m_type(type)
     , m_action(action)
     , m_title(title)
     , m_isChecked(checked)
     , m_isEnabled(enabled)
-    , m_parentMenu(0)
+    , m_parentMenu(parentMenu)
     , m_subMenu(subMenu)
 {
 }
@@ -147,6 +147,13 @@ Eina_Bool ewk_context_menu_item_enabled_set(Ewk_Context_Menu_Item* item, Eina_Bo
     return true;
 }
 
+Ewk_Context_Menu* ewk_context_menu_item_parent_menu_get(const Ewk_Context_Menu_Item* item)
+{
+    EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
+
+    return const_cast<Ewk_Context_Menu_Item*>(item)->parentMenu();
+}
+
 static Ewk_Context_Menu_Item_Action getEwkActionFromWKTag(WKContextMenuItemTag action)
 {
     switch (action) {
index 11a9282..208e0ad 100644 (file)
@@ -259,6 +259,15 @@ EAPI Eina_Bool ewk_context_menu_item_enabled_get(const Ewk_Context_Menu_Item *o)
  */
 EAPI Eina_Bool ewk_context_menu_item_enabled_set(Ewk_Context_Menu_Item *o, Eina_Bool enabled);
 
+/**
+ * Gets the parent menu for the item.
+ *
+ * @param o item to get the parent
+ *
+ * @return the pointer to parent menu on success or @c NULL on failure
+ */
+EAPI Ewk_Context_Menu *ewk_context_menu_item_parent_menu_get(const Ewk_Context_Menu_Item *o);
+
 #ifdef __cplusplus
 }
 #endif
index 9f7783b..2511183 100644 (file)
  */
 class EwkContextMenuItem {
 public:
-    static PassOwnPtr<EwkContextMenuItem> create(WKContextMenuItemRef item)
+    static PassOwnPtr<EwkContextMenuItem> create(WKContextMenuItemRef item, EwkContextMenu* parentMenu = 0)
     {
-        return adoptPtr(new EwkContextMenuItem(item));
+        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)
+    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)
     {
-        return adoptPtr(new EwkContextMenuItem(type, action, title, checked, enabled, subMenu));
+        return adoptPtr(new EwkContextMenuItem(type, action, title, checked, enabled, subMenu, parentMenu));
     }
 
     Ewk_Context_Menu_Item_Action action() const { return m_action; }
@@ -63,9 +63,12 @@ public:
     bool enabled() const { return m_isEnabled; }
     void setEnabled(bool enabled) { m_isEnabled = enabled; }
 
+    EwkContextMenu* parentMenu() const { return m_parentMenu; }
+    void setParentMenu(EwkContextMenu* parentMenu) { m_parentMenu = parentMenu; }
+
 private:
-    explicit EwkContextMenuItem(WKContextMenuItemRef);
-    EwkContextMenuItem(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, EwkContextMenu* subMenu);
+    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);
 
     Ewk_Context_Menu_Item_Type m_type;
     Ewk_Context_Menu_Item_Action m_action;
index 78858af..7306eb4 100644 (file)
@@ -46,6 +46,9 @@ static Eina_Bool showContextMenu(Ewk_View_Smart_Data* smartData, Evas_Coord x, E
     Ewk_Context_Menu_Item* item = static_cast<Ewk_Context_Menu_Item*>(eina_list_nth(list, 0));
     checkBasicContextMenuItem(item, EWK_ACTION_TYPE, EWK_CONTEXT_MENU_ITEM_TAG_GO_BACK, "Go Back", false, true);
 
+    // When context menu is created by WebKit, an item should have parent menu.
+    EXPECT_EQ(contextMenu, ewk_context_menu_item_parent_menu_get(item));
+
     item = static_cast<Ewk_Context_Menu_Item*>(eina_list_nth(list, 1));
     checkBasicContextMenuItem(item, EWK_ACTION_TYPE, EWK_CONTEXT_MENU_ITEM_TAG_GO_FORWARD, "Go Forward", false, true);
     ewk_context_menu_item_enabled_set(item, false);
@@ -63,8 +66,13 @@ static Eina_Bool showContextMenu(Ewk_View_Smart_Data* smartData, Evas_Coord x, E
 
     // Makes new context menu items.
     Ewk_Context_Menu_Item* newItem = ewk_context_menu_item_new(EWK_ACTION_TYPE, EWK_CONTEXT_MENU_ITEM_TAG_OTHER, "New Custom Item", false, true);
+    // When context menu item is created using ewk_context_menu_item_new, it should not have parent menu.
+    EXPECT_EQ(0, ewk_context_menu_item_parent_menu_get(newItem));
     ewk_context_menu_item_append(contextMenu, newItem);
 
+    // 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));
+
     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);
@@ -73,9 +81,18 @@ static Eina_Bool showContextMenu(Ewk_View_Smart_Data* smartData, Evas_Coord x, E
     subMenuItemList = eina_list_append(subMenuItemList, subMenuItem2);
     subMenuItemList = eina_list_append(subMenuItemList, subMenuItem3);
     Ewk_Context_Menu* subMenu = ewk_context_menu_new_with_items(subMenuItemList);
+
+    // When context menu is created using ewk_context_menu_new_with_items, items should have parent menu.
+    EXPECT_EQ(subMenu, ewk_context_menu_item_parent_menu_get(subMenuItem1));
+
     Ewk_Context_Menu_Item* newItem2 = ewk_context_menu_item_new_with_submenu(EWK_SUBMENU_TYPE, EWK_CONTEXT_MENU_ITEM_TAG_OTHER, "New Custom Item 2", false, true, subMenu);
+    // When context menu item is created using ewk_context_menu_item_new_with_submenu, it should not have parent menu.
+    EXPECT_EQ(0, ewk_context_menu_item_parent_menu_get(newItem));
     ewk_context_menu_item_append(contextMenu, 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));
+
     Ewk_Context_Menu* subMenu2 = ewk_context_menu_new();
     Ewk_Context_Menu_Item* newItem3 = ewk_context_menu_item_new_with_submenu(EWK_SUBMENU_TYPE, EWK_CONTEXT_MENU_ITEM_TAG_OTHER, "New Custom Item 3", false, true, subMenu2);
     ewk_context_menu_item_append(contextMenu, newItem3);