diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-09-26 23:35:02 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-09-26 23:35:02 (EDT) |
commit | 0817a7c9910561dd127e89635c08f838f046d303 (patch) | |
tree | 0c6f5ad72681c977da2b191dc4ea644cfe962a76 /src | |
parent | 8a0c2f1baeb46a0d7e6dec536ef28e4bbf270a7d (diff) | |
download | marquee-0817a7c9910561dd127e89635c08f838f046d303.zip marquee-0817a7c9910561dd127e89635c08f838f046d303.tar.gz marquee-0817a7c9910561dd127e89635c08f838f046d303.tar.bz2 |
MqTabBody: Populate menu items for media contexts
Diffstat (limited to 'src')
-rw-r--r-- | src/tab-body.c | 129 |
1 files changed, 95 insertions, 34 deletions
diff --git a/src/tab-body.c b/src/tab-body.c index 192ce73..17f8c3a 100644 --- a/src/tab-body.c +++ b/src/tab-body.c @@ -74,6 +74,50 @@ menu_open_image_win_activate_cb(GtkAction __attribute__((unused)) *action, g_print("Open Image in New Window\n"); } +static void +menu_open_video_activate_cb(GtkAction __attribute__((unused)) *action, + MqTabBody *body) +{ + webkit_web_view_load_uri(body->web_view, + webkit_hit_test_result_get_media_uri(body->hit_test_result)); +} + +static void +menu_open_video_tab_activate_cb(GtkAction __attribute__((unused)) *action, + MqTabBody *body) +{ + g_print("Open Video in New Tab\n"); +} + +static void +menu_open_video_win_activate_cb(GtkAction __attribute__((unused)) *action, + MqTabBody *body) +{ + g_print("Open Video in New Window\n"); +} + +static void +menu_open_audio_activate_cb(GtkAction __attribute__((unused)) *action, + MqTabBody *body) +{ + webkit_web_view_load_uri(body->web_view, + webkit_hit_test_result_get_media_uri(body->hit_test_result)); +} + +static void +menu_open_audio_tab_activate_cb(GtkAction __attribute__((unused)) *action, + MqTabBody *body) +{ + g_print("Open Audio in New Tab\n"); +} + +static void +menu_open_audio_win_activate_cb(GtkAction __attribute__((unused)) *action, + MqTabBody *body) +{ + g_print("Open Audio in New Window\n"); +} + #define ITEM_DECLS \ GtkAction *action; \ WebKitContextMenuItem *menu_item; @@ -136,6 +180,35 @@ context_menu_image_cb(WebKitContextMenu *context_menu, MqTabBody *body) } static void +context_menu_media_cb(WebKitContextMenu *context_menu, GList *media_ctrl_items, + GList *media_toggle_items, gboolean is_video, MqTabBody *body) +{ + ITEM_DECLS + + /* Play/Pause, Mute */ + RESTORE_ITEMS(media_ctrl_items); + /* Toggle Media Controls, Toggle Media Loop Playback, Switch Video to + * Fullscreen */ + RESTORE_ITEMS(media_toggle_items); + NEW_SEPARATOR_ITEM(); /* --- */ + if (is_video) { + /* Copy Video Link Location */ + NEW_STOCK_ITEM(COPY_VIDEO_LINK_TO_CLIPBOARD); + NEW_CUSTOM_ITEM(open_video, "Open Video"); + NEW_CUSTOM_ITEM(open_video_tab, "Open Video in New Tab"); + NEW_CUSTOM_ITEM(open_video_win, "Open Video in New Window"); + NEW_STOCK_ITEM(DOWNLOAD_VIDEO_TO_DISK); /* Download Video */ + } else { + /* Copy Audio Link Location */ + NEW_STOCK_ITEM(COPY_AUDIO_LINK_TO_CLIPBOARD); + NEW_CUSTOM_ITEM(open_audio, "Open Audio"); + NEW_CUSTOM_ITEM(open_audio_tab, "Open Audio in New Tab"); + NEW_CUSTOM_ITEM(open_audio_win, "Open Audio in New Window"); + NEW_STOCK_ITEM(DOWNLOAD_AUDIO_TO_DISK); /* Download Audio */ + } +} + +static void context_menu_document_cb(WebKitContextMenu *context_menu, GList *nav_items, MqTabBody *body) { @@ -164,6 +237,8 @@ context_menu_cb(WebKitWebView __attribute__((unused)) *web_view, GList *nav_items; GList *input_items; GList *spell_items; + GList *media_ctrl_items; + GList *media_toggle_items; gboolean is_selection; gboolean is_video; WebKitContextMenuAction stock_action; @@ -176,9 +251,11 @@ context_menu_cb(WebKitWebView __attribute__((unused)) *web_view, * that aren't easy to reproduce (e.g. the Unicode menu and spelling * guesses). */ items = webkit_context_menu_get_items(context_menu); - nav_items = NULL; - input_items = NULL; - spell_items = NULL; + nav_items = NULL; + input_items = NULL; + spell_items = NULL; + media_ctrl_items = NULL; + media_toggle_items = NULL; is_selection = FALSE; is_video = FALSE; for (; items; items = items->next) { @@ -217,15 +294,24 @@ context_menu_cb(WebKitWebView __attribute__((unused)) *web_view, case WKCMA(DOWNLOAD_AUDIO_TO_DISK): is_video = FALSE; break; + case WKCMA(TOGGLE_MEDIA_CONTROLS): + case WKCMA(TOGGLE_MEDIA_LOOP): + case WKCMA(ENTER_VIDEO_FULLSCREEN): + PRESERVE_ITEM(media_toggle_items); + break; case WKCMA(MEDIA_PLAY): case WKCMA(MEDIA_PAUSE): + case WKCMA(MEDIA_MUTE): + PRESERVE_ITEM(media_ctrl_items); break; } #pragma GCC diagnostic pop } - nav_items = g_list_reverse(nav_items); - input_items = g_list_reverse(input_items); - spell_items = g_list_reverse(spell_items); + nav_items = g_list_reverse(nav_items); + input_items = g_list_reverse(input_items); + spell_items = g_list_reverse(spell_items); + media_ctrl_items = g_list_reverse(media_ctrl_items); + media_toggle_items = g_list_reverse(media_toggle_items); webkit_context_menu_remove_all(context_menu); @@ -250,34 +336,9 @@ context_menu_cb(WebKitWebView __attribute__((unused)) *web_view, context_handled = TRUE; } if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA) { - if (is_video) { - /* Play / Pause (preserved) - * Mute (stock) - * Toggle Media Controls (stock?) - * Toggle Media Loop Playback (stock?) - * Switch Video to Fullscreen (stock) - * --- - * Copy Video Link Location (stock) - * Open Video - * Open Video in New Tab - * Open Video in New Window - * Download Video (stock) */ - g_print(" video"); - context_handled = TRUE; - } else { - /* Play / Pause (preserved) - * Mute (stock) - * Toggle Media Controls (stock?) - * Toggle Media Loop Playback (stock?) - * --- - * Copy Audio Link Location (stock) - * Open Audio - * Open Audio in New Tab - * Open Audio in New Window - * Download Audio (stock) */ - g_print(" audio"); - context_handled = TRUE; - } + context_menu_media_cb(context_menu, media_ctrl_items, + media_toggle_items, is_video, body); + context_handled = TRUE; } if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) { /* Cut (stock) |