Commit 178d2dd9 authored by alp@webkit.org's avatar alp@webkit.org

2008-02-03 Christian Dywan <christian@imendio.com>

        Reviewed by Alp Toker.

        http://bugs.webkit.org/show_bug.cgi?id=17046
        [GTK] Context menu fixes and customisation suport

        Provide standard GTK+ context menu items where appropriate.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@29958 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5545fd33
2008-02-03 Christian Dywan <christian@imendio.com>
Reviewed by Alp Toker.
http://bugs.webkit.org/show_bug.cgi?id=17046
[GTK] Context menu fixes and customisation suport
Provide standard GTK+ context menu items where appropriate.
Note that this change makes direct use of WebKit from WebCore which is
against WebKit/GTK+ guidelines. The ContextMenu abstraction should be
fixed at some point.
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):
* platform/ContextMenu.cpp:
(WebCore::createAndAppendInputMethodsSubMenu):
(WebCore::):
(WebCore::insertControlCharacter):
(WebCore::createAndAppendUnicodeSubMenu):
(WebCore::ContextMenu::populate):
(ContextMenu::checkOrEnableIfNeeded):
* platform/ContextMenuItem.h:
(WebCore::):
* platform/LocalizedStrings.h:
* platform/gtk/ContextMenuItemGtk.cpp:
(WebCore::gtkStockIDFromContextMenuAction):
* platform/gtk/LocalizedStringsGtk.cpp:
(WebCore::gtkStockLabel):
(WebCore::contextMenuItemTagCopy):
(WebCore::contextMenuItemTagDelete):
(WebCore::contextMenuItemTagSelectAll):
(WebCore::contextMenuItemTagUnicode):
(WebCore::contextMenuItemTagInputMethods):
(WebCore::contextMenuItemTagGoBack):
(WebCore::contextMenuItemTagGoForward):
(WebCore::contextMenuItemTagStop):
(WebCore::contextMenuItemTagCut):
(WebCore::contextMenuItemTagPaste):
(WebCore::contextMenuItemTagBold):
(WebCore::contextMenuItemTagItalic):
(WebCore::contextMenuItemTagUnderline):
2008-02-03 Oliver Hunt <oliver@apple.com>
Reviewed by Maciej.
......@@ -181,6 +181,14 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
case ContextMenuItemTagPaste:
frame->editor()->paste();
break;
#if PLATFORM(GTK)
case ContextMenuItemTagDelete:
frame->editor()->performDelete();
break;
case ContextMenuItemTagSelectAll:
frame->editor()->command("SelectAll").execute();
break;
#endif
case ContextMenuItemTagSpellingGuess:
ASSERT(frame->selectedText().length());
if (frame->editor()->shouldInsertText(item->title(), frame->selectionController()->toRange().get(),
......
This diff is collapsed.
......@@ -70,6 +70,12 @@ namespace WebCore {
ContextMenuItemTagReload,
ContextMenuItemTagCut,
ContextMenuItemTagPaste,
#if PLATFORM(GTK)
ContextMenuItemTagDelete,
ContextMenuItemTagSelectAll,
ContextMenuItemTagInputMethods,
ContextMenuItemTagUnicode,
#endif
ContextMenuItemTagSpellingGuess,
ContextMenuItemTagNoGuessesFound,
ContextMenuItemTagIgnoreSpelling,
......
......@@ -51,6 +51,12 @@ namespace WebCore {
String contextMenuItemTagReload();
String contextMenuItemTagCut();
String contextMenuItemTagPaste();
#if PLATFORM(GTK)
String contextMenuItemTagDelete();
String contextMenuItemTagSelectAll();
String contextMenuItemTagInputMethods();
String contextMenuItemTagUnicode();
#endif
String contextMenuItemTagNoGuessesFound();
String contextMenuItemTagIgnoreSpelling();
String contextMenuItemTagLearnSpelling();
......
......@@ -54,6 +54,12 @@ static const char* gtkStockIDFromContextMenuAction(const ContextMenuAction& acti
return GTK_STOCK_CUT;
case ContextMenuItemTagPaste:
return GTK_STOCK_PASTE;
case ContextMenuItemTagDelete:
return GTK_STOCK_DELETE;
#if GTK_CHECK_VERSION(2, 10, 0)
case ContextMenuItemTagSelectAll:
return GTK_STOCK_SELECT_ALL;
#endif
case ContextMenuItemTagSpellingGuess:
return GTK_STOCK_INFO;
case ContextMenuItemTagIgnoreSpelling:
......@@ -64,6 +70,8 @@ static const char* gtkStockIDFromContextMenuAction(const ContextMenuAction& acti
return GTK_STOCK_MISSING_IMAGE;
case ContextMenuItemTagSearchInSpotlight:
return GTK_STOCK_FIND;
case ContextMenuItemTagSearchWeb:
return GTK_STOCK_FIND;
case ContextMenuItemTagOpenWithDefaultApplication:
return GTK_STOCK_OPEN;
case ContextMenuItemPDFZoomIn:
......
......@@ -2,6 +2,7 @@
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
* Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
* Copyright (C) 2007 Holger Hans Peter Freyther
* Copyright (C) 2008 Christian Dywan <christian@imendio.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -31,11 +32,19 @@
#include "LocalizedStrings.h"
#include "PlatformString.h"
#include <gtk/gtk.h>
#include <glib/gi18n.h>
namespace WebCore {
static const char* gtkStockLabel(const char* stockID)
{
GtkStockItem item;
if (!gtk_stock_lookup(stockID, &item))
return stockID;
return item.label;
}
String submitButtonDefaultLabel()
{
return String::fromUTF8(_("Submit"));
......@@ -103,22 +112,52 @@ String contextMenuItemTagOpenFrameInNewWindow()
String contextMenuItemTagCopy()
{
return String::fromUTF8(_("_Copy"));
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_COPY));
return stockLabel;
}
String contextMenuItemTagDelete()
{
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_DELETE));
return stockLabel;
}
String contextMenuItemTagSelectAll()
{
#if GLIB_CHECK_VERSION(2,10,0)
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_SELECT_ALL));
#else
static String stockLabel = String::fromUTF8(_("Select _All"));
#endif
return stockLabel;
}
String contextMenuItemTagUnicode()
{
return String::fromUTF8(_("_Insert Unicode Control Character"));
}
String contextMenuItemTagInputMethods()
{
return String::fromUTF8(_("Input _Methods"));
}
String contextMenuItemTagGoBack()
{
return String::fromUTF8(_("_Back"));
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_GO_BACK));
return stockLabel;
}
String contextMenuItemTagGoForward()
{
return String::fromUTF8(_("_Forward"));
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_GO_FORWARD));
return stockLabel;
}
String contextMenuItemTagStop()
{
return String::fromUTF8(_("_Stop"));
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_STOP));
return stockLabel;
}
String contextMenuItemTagReload()
......@@ -128,12 +167,14 @@ String contextMenuItemTagReload()
String contextMenuItemTagCut()
{
return String::fromUTF8(_("Cu_t"));
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_CUT));
return stockLabel;
}
String contextMenuItemTagPaste()
{
return String::fromUTF8(_("_Paste"));
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_PASTE));
return stockLabel;
}
String contextMenuItemTagNoGuessesFound()
......@@ -203,17 +244,20 @@ String contextMenuItemTagFontMenu()
String contextMenuItemTagBold()
{
return String::fromUTF8(_("_Bold"));
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_BOLD));
return stockLabel;
}
String contextMenuItemTagItalic()
{
return String::fromUTF8(_("_Italic"));
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_ITALIC));
return stockLabel;
}
String contextMenuItemTagUnderline()
{
return String::fromUTF8(_("_Underline"));
static String stockLabel = String::fromUTF8(gtkStockLabel(GTK_STOCK_UNDERLINE));
return stockLabel;
}
String contextMenuItemTagOutline()
......@@ -221,26 +265,6 @@ String contextMenuItemTagOutline()
return String::fromUTF8(_("_Outline"));
}
String contextMenuItemTagWritingDirectionMenu()
{
return String::fromUTF8(_("_Writing Direction"));
}
String contextMenuItemTagDefaultDirection()
{
return String::fromUTF8(_("_Default"));
}
String contextMenuItemTagLeftToRight()
{
return String::fromUTF8(_("_Left to Right"));
}
String contextMenuItemTagRightToLeft()
{
return String::fromUTF8(_("_Right to Left"));
}
String contextMenuItemTagInspectElement()
{
return String::fromUTF8(_("Inspect _Element"));
......
2008-02-03 Christian Dywan <christian@imendio.com>
Reviewed by Alp Toker.
http://bugs.webkit.org/show_bug.cgi?id=17046
[GTK] Context menu fixes and customisation suport
* webkit/webkitwebview.cpp:
2008-01-31 Alp Toker <alp@atoker.com>
Reviewed by Mark Rowe.
......
/*
* Copyright (C) 2007 Holger Hans Peter Freyther
* Copyright (C) 2007 Christian Dywan <christian@twotoasts.de>
* Copyright (C) 2007, 2008 Christian Dywan <christian@imendio.com>
* Copyright (C) 2007 Xan Lopez <xan@gnome.org>
* Copyright (C) 2007 Alp Toker <alp@atoker.com>
* Copyright (C) 2008 Jan Alonzo <jmalonzo@unpluggable.com>
......@@ -71,6 +71,7 @@ enum {
LOAD_FINISHED,
TITLE_CHANGED,
HOVERING_OVER_LINK,
POPULATE_POPUP,
STATUS_BAR_TEXT_CHANGED,
ICOND_LOADED,
SELECTION_CHANGED,
......@@ -119,16 +120,24 @@ static gboolean webkit_web_view_forward_context_menu_event(WebKitWebView* webVie
if (!coreMenu)
return FALSE;
if (!coreMenu->platformDescription())
GtkMenu* menu = GTK_MENU(coreMenu->platformDescription());
if (!menu)
return FALSE;
g_signal_emit(webView, webkit_web_view_signals[POPULATE_POPUP], 0, menu);
WebKitWebViewPrivate* pageData = WEBKIT_WEB_VIEW_GET_PRIVATE(webView);
pageData->lastPopupXPosition = event.globalX();
pageData->lastPopupYPosition = event.globalY();
gtk_menu_popup(GTK_MENU(coreMenu->platformDescription()), NULL, NULL,
reinterpret_cast<GtkMenuPositionFunc>(webkit_web_view_context_menu_position_func), pageData,
event.button() + 1, gtk_get_current_event_time());
GList* items = gtk_container_get_children(GTK_CONTAINER(menu));
bool empty = !g_list_nth(items, 0);
g_list_free(items);
if (empty)
return FALSE;
WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView);
priv->lastPopupXPosition = event.globalX();
priv->lastPopupYPosition = event.globalY();
gtk_menu_popup(menu, NULL, NULL,
reinterpret_cast<GtkMenuPositionFunc>(webkit_web_view_context_menu_position_func),
priv, event.button() + 1, gtk_get_current_event_time());
return TRUE;
}
......@@ -750,6 +759,25 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
G_TYPE_STRING,
G_TYPE_STRING);
/**
* WebKitWebView::populate-popup:
* @web_view: the object on which the signal is emitted
* @menu: the context menu
*
* When a context menu is about to be displayed this signal is emitted.
*
* Add menu items to #menu to extend the context menu.
*/
webkit_web_view_signals[POPULATE_POPUP] = g_signal_new("populate-popup",
G_TYPE_FROM_CLASS(webViewClass),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
0,
NULL,
NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GTK_TYPE_MENU);
webkit_web_view_signals[STATUS_BAR_TEXT_CHANGED] = g_signal_new("status-bar-text-changed",
G_TYPE_FROM_CLASS(webViewClass),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
......
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