Commit 086b246f authored by carlosgc@webkit.org's avatar carlosgc@webkit.org

[GTK] Don't use the C API internally in WebKitContextMenu

https://bugs.webkit.org/show_bug.cgi?id=96770

Reviewed by Gustavo Noronha Silva.

Using the C++ classes directly instead of the C API wrappers we
avoid a lot of toImpl/toAPI casts, string conversions and
allocations. The code is also a lot simpler and easier to read.

* UIProcess/API/gtk/WebKitContextMenu.cpp:
(webkitContextMenuCreate):
* UIProcess/API/gtk/WebKitContextMenuItem.cpp:
(webkitContextMenuItemCreate):
* UIProcess/API/gtk/WebKitContextMenuItemPrivate.h:
* UIProcess/API/gtk/WebKitContextMenuPrivate.h:
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkitWebViewPopulateContextMenu):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@131606 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 93c5cf65
2012-10-17 Carlos Garcia Campos <cgarcia@igalia.com>
[GTK] Don't use the C API internally in WebKitContextMenu
https://bugs.webkit.org/show_bug.cgi?id=96770
Reviewed by Gustavo Noronha Silva.
Using the C++ classes directly instead of the C API wrappers we
avoid a lot of toImpl/toAPI casts, string conversions and
allocations. The code is also a lot simpler and easier to read.
* UIProcess/API/gtk/WebKitContextMenu.cpp:
(webkitContextMenuCreate):
* UIProcess/API/gtk/WebKitContextMenuItem.cpp:
(webkitContextMenuItemCreate):
* UIProcess/API/gtk/WebKitContextMenuItemPrivate.h:
* UIProcess/API/gtk/WebKitContextMenuPrivate.h:
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkitWebViewPopulateContextMenu):
2012-10-17 Carlos Garcia Campos <cgarcia@igalia.com>
[GTK] Don't use the C API internally in WebKitBackForwardList
......
......@@ -20,10 +20,11 @@
#include "config.h"
#include "WebKitContextMenu.h"
#include "ImmutableArray.h"
#include "WebContextMenuItem.h"
#include "WebKitContextMenuItemPrivate.h"
#include "WebKitContextMenuPrivate.h"
using namespace WebKit;
using namespace WebCore;
struct _WebKitContextMenuPrivate {
......@@ -64,12 +65,12 @@ void webkitContextMenuPopulate(WebKitContextMenu* menu, Vector<ContextMenuItem>&
}
}
WebKitContextMenu* webkitContextMenuCreate(WKArrayRef wkItems)
WebKitContextMenu* webkitContextMenuCreate(ImmutableArray* items)
{
WebKitContextMenu* menu = webkit_context_menu_new();
for (size_t i = 0; i < WKArrayGetSize(wkItems); ++i) {
WKContextMenuItemRef wkItem = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(wkItems, i));
webkit_context_menu_prepend(menu, webkitContextMenuItemCreate(wkItem));
for (size_t i = 0; i < items->size(); ++i) {
WebContextMenuItem* item = static_cast<WebContextMenuItem*>(items->at(i));
webkit_context_menu_prepend(menu, webkitContextMenuItemCreate(item));
}
menu->priv->items = g_list_reverse(menu->priv->items);
......
......@@ -34,7 +34,6 @@
#include <wtf/gobject/GOwnPtr.h>
#include <wtf/gobject/GRefPtr.h>
using namespace WebKit;
using namespace WebCore;
struct _WebKitContextMenuItemPrivate {
......@@ -91,10 +90,10 @@ static void webkitContextMenuItemSetSubMenu(WebKitContextMenuItem* item, GRefPtr
webkitContextMenuSetParentItem(subMenu.get(), item);
}
WebKitContextMenuItem* webkitContextMenuItemCreate(WKContextMenuItemRef wkItem)
WebKitContextMenuItem* webkitContextMenuItemCreate(WebContextMenuItem* webItem)
{
WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL));
WebContextMenuItemData* itemData = toImpl(wkItem)->data();
WebContextMenuItemData* itemData = webItem->data();
item->priv->menuItem = WTF::adoptPtr(new ContextMenuItem(itemData->type(), itemData->action(), itemData->title(), itemData->enabled(), itemData->checked()));
const Vector<WebContextMenuItemData>& subMenu = itemData->submenu();
if (!subMenu.size())
......@@ -104,7 +103,7 @@ WebKitContextMenuItem* webkitContextMenuItemCreate(WKContextMenuItemRef wkItem)
subMenuItems->reserveCapacity(subMenu.size());
for (size_t i = 0; i < subMenu.size(); ++i)
subMenuItems->append(WebContextMenuItem::create(subMenu[i]).get());
webkitContextMenuItemSetSubMenu(item, adoptGRef(webkitContextMenuCreate(toAPI(subMenuItems.get()))));
webkitContextMenuItemSetSubMenu(item, adoptGRef(webkitContextMenuCreate(subMenuItems.get())));
return item;
}
......
......@@ -23,7 +23,9 @@
#include "WebKitContextMenuItem.h"
#include "WebKitPrivate.h"
WebKitContextMenuItem* webkitContextMenuItemCreate(WKContextMenuItemRef);
using namespace WebKit;
WebKitContextMenuItem* webkitContextMenuItemCreate(WebContextMenuItem*);
GtkMenuItem* webkitContextMenuItemRelease(WebKitContextMenuItem*);
void webkitContextMenuItemSetSubMenuFromGtkMenu(WebKitContextMenuItem*, GtkMenu*);
......
......@@ -23,7 +23,9 @@
#include "WebKitContextMenu.h"
#include "WebKitPrivate.h"
WebKitContextMenu* webkitContextMenuCreate(WKArrayRef wkItems);
using namespace WebKit;
WebKitContextMenu* webkitContextMenuCreate(ImmutableArray* items);
void webkitContextMenuPopulate(WebKitContextMenu*, Vector<WebCore::ContextMenuItem>&);
void webkitContextMenuSetParentItem(WebKitContextMenu*, WebKitContextMenuItem*);
WebKitContextMenuItem* webkitContextMenuGetParentItem(WebKitContextMenu*);
......
......@@ -1577,7 +1577,7 @@ void webkitWebViewPopulateContextMenu(WebKitWebView* webView, ImmutableArray* pr
WebContextMenuProxyGtk* contextMenuProxy = webkitWebViewBaseGetActiveContextMenuProxy(webViewBase);
ASSERT(contextMenuProxy);
GRefPtr<WebKitContextMenu> contextMenu = adoptGRef(webkitContextMenuCreate(toAPI(proposedMenu)));
GRefPtr<WebKitContextMenu> contextMenu = adoptGRef(webkitContextMenuCreate(proposedMenu));
if (webHitTestResult->isContentEditable())
webkitWebViewCreateAndAppendInputMethodsMenuItem(webView, contextMenu.get());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment