1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/*
* Copyright (C) 2008 Nuanti Ltd.
* Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#if ENABLE(CONTEXT_MENUS)
#include "ContextMenuClientGtk.h"
#include "ContextMenu.h"
#include "ContextMenuController.h"
#include "HitTestResult.h"
#include "KURL.h"
#include "LocalizedStrings.h"
#include "NotImplemented.h"
#include "Page.h"
#include "webkitwebviewprivate.h"
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <wtf/text/CString.h>
using namespace WebCore;
namespace WebKit {
ContextMenuClient::ContextMenuClient(WebKitWebView *webView)
: m_webView(webView)
{
}
void ContextMenuClient::contextMenuDestroyed()
{
delete this;
}
static GtkWidget* inputMethodsMenuItem (WebKitWebView* webView)
{
if (gtk_major_version > 2 || (gtk_major_version == 2 && gtk_minor_version >= 10)) {
GtkSettings* settings = webView ? gtk_widget_get_settings(GTK_WIDGET(webView)) : gtk_settings_get_default();
gboolean showMenu = TRUE;
if (settings)
g_object_get(settings, "gtk-show-input-method-menu", &showMenu, NULL);
if (!showMenu)
return 0;
}
WebKitWebViewPrivate* priv = webView->priv;
ContextMenu imContextMenu;
gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(priv->imFilter.context()), GTK_MENU_SHELL(imContextMenu.platformDescription()));
ContextMenuItem menuItem(ActionType, ContextMenuItemTagInputMethods, contextMenuItemTagInputMethods(), &imContextMenu);
imContextMenu.releasePlatformDescription();
return GTK_WIDGET(menuItem.releasePlatformDescription());
}
static int getUnicodeMenuItemPosition(GtkMenu* menu)
{
GOwnPtr<GList> items(gtk_container_get_children(GTK_CONTAINER(menu)));
int unicodeMenuItemPosition = -1;
GList* iter;
int i = 0;
for (iter = items.get(), i = 0; iter; iter = g_list_next(iter), ++i) {
GtkMenuItem* item = GTK_MENU_ITEM(iter->data);
if (GTK_IS_SEPARATOR_MENU_ITEM(item))
continue;
if (String::fromUTF8(gtk_menu_item_get_label(item)) == contextMenuItemTagUnicode()) {
unicodeMenuItemPosition = i;
break;
}
}
return unicodeMenuItemPosition;
}
PlatformMenuDescription ContextMenuClient::getCustomMenuFromDefaultItems(ContextMenu* menu)
{
GtkMenu* gtkmenu = menu->releasePlatformDescription();
WebKitWebView* webView = m_webView;
HitTestResult result = core(webView)->contextMenuController()->hitTestResult();
if (result.isContentEditable()) {
GtkWidget* imContextMenu = inputMethodsMenuItem(webView);
if (!imContextMenu)
return gtkmenu;
// Place the im context menu item right before the unicode menu item
// if it's present.
int unicodeMenuItemPosition = getUnicodeMenuItemPosition(gtkmenu);
if (unicodeMenuItemPosition == -1) {
GtkWidget* separator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(gtkmenu), separator);
gtk_widget_show(separator);
}
gtk_menu_shell_insert(GTK_MENU_SHELL(gtkmenu), imContextMenu, unicodeMenuItemPosition);
gtk_widget_show(imContextMenu);
}
return gtkmenu;
}
void ContextMenuClient::contextMenuItemSelected(ContextMenuItem*, const ContextMenu*)
{
notImplemented();
}
void ContextMenuClient::downloadURL(const KURL& url)
{
WebKitNetworkRequest* networkRequest = webkit_network_request_new(url.string().utf8().data());
webkit_web_view_request_download(m_webView, networkRequest);
g_object_unref(networkRequest);
}
void ContextMenuClient::copyImageToClipboard(const HitTestResult&)
{
notImplemented();
}
void ContextMenuClient::searchWithGoogle(const Frame*)
{
notImplemented();
}
void ContextMenuClient::lookUpInDictionary(Frame*)
{
notImplemented();
}
void ContextMenuClient::speak(const String&)
{
notImplemented();
}
void ContextMenuClient::stopSpeaking()
{
notImplemented();
}
bool ContextMenuClient::isSpeaking()
{
notImplemented();
return false;
}
}
#endif // ENABLE(CONTEXT_MENUS)
|