summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tab-body.c93
1 files changed, 83 insertions, 10 deletions
diff --git a/src/tab-body.c b/src/tab-body.c
index 8f12108..c5266b2 100644
--- a/src/tab-body.c
+++ b/src/tab-body.c
@@ -31,23 +31,96 @@ static gboolean
context_menu_cb(WebKitWebView *web_view, WebKitContextMenu *context_menu,
GdkEvent *event, WebKitHitTestResult *hit_test_result, MqTabBody *body)
{
- WebKitHitTestResultContext context;
+ GList *items;
+ GList *input_items;
+ GList *spell_items;
+ gboolean is_selection;
+ gboolean is_video;
+ WebKitContextMenuAction stock_action;
+ WebKitHitTestResultContext context;
+ gboolean context_handled;
+
+ /* Get more hints about the context, since WebKit doesn't describe
+ * context very well in hit test results. Also, preserve menu items
+ * that aren't easy to reproduce (e.g. the Unicode menu and spelling
+ * guesses). */
+ items = webkit_context_menu_get_items(context_menu);
+ input_items = NULL;
+ spell_items = NULL;
+ is_selection = FALSE;
+ is_video = FALSE;
+ for (; items; items = items->next) {
+ stock_action = webkit_context_menu_item_get_stock_action(
+ items->data);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch"
+ switch (stock_action) {
+ case WEBKIT_CONTEXT_MENU_ACTION_COPY:
+ is_selection = TRUE;
+ break;
+ case WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS:
+ case WEBKIT_CONTEXT_MENU_ACTION_UNICODE:
+ input_items = g_list_prepend(input_items,
+ items->data);
+ break;
+ case WEBKIT_CONTEXT_MENU_ACTION_SPELLING_GUESS:
+ case WEBKIT_CONTEXT_MENU_ACTION_NO_GUESSES_FOUND:
+ case WEBKIT_CONTEXT_MENU_ACTION_IGNORE_SPELLING:
+ case WEBKIT_CONTEXT_MENU_ACTION_LEARN_SPELLING:
+ case WEBKIT_CONTEXT_MENU_ACTION_IGNORE_GRAMMAR:
+ spell_items = g_list_prepend(spell_items,
+ items->data);
+ break;
+ case WEBKIT_CONTEXT_MENU_ACTION_OPEN_VIDEO_IN_NEW_WINDOW:
+ case WEBKIT_CONTEXT_MENU_ACTION_COPY_VIDEO_LINK_TO_CLIPBOARD:
+ case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK:
+ is_video = TRUE;
+ break;
+ case WEBKIT_CONTEXT_MENU_ACTION_OPEN_AUDIO_IN_NEW_WINDOW:
+ case WEBKIT_CONTEXT_MENU_ACTION_COPY_AUDIO_LINK_TO_CLIPBOARD:
+ case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK:
+ is_video = FALSE;
+ break;
+ case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY:
+ case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PAUSE:
+ break;
+ }
+#pragma GCC diagnostic pop
+ }
context = webkit_hit_test_result_get_context(hit_test_result);
+ context_handled = FALSE;
g_print("Context menu, hit test:");
- if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT)
- g_print(" document");
- if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
+ if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
g_print(" link");
- if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE)
+ context_handled = TRUE;
+ }
+ if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE) {
g_print(" image");
- if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA)
- g_print(" media");
- if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE)
+ context_handled = TRUE;
+ }
+ if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA) {
+ if (is_video) {
+ g_print(" video");
+ context_handled = TRUE;
+ } else {
+ g_print(" audio");
+ context_handled = TRUE;
+ }
+ }
+ if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) {
g_print(" editable");
- if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR)
- g_print(" scrollbar");
+ context_handled = TRUE;
+ }
+ if (!context_handled &&
+ context & WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT) {
+ if (is_selection) {
+ g_print(" selection");
+ } else {
+ g_print(" document");
+ }
+ }
g_print("\n");
return FALSE;