summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-09-26 18:26:40 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-09-26 18:26:40 (EDT)
commit3aa86a78fdcf00f9b62cf9b843febb78c81e575c (patch)
tree38b24708ce4a97201f0264e2fc419d7e329540a8 /src
parenteb82c6d9de299ec879b7853486feb372b2906a19 (diff)
downloadmarquee-3aa86a78fdcf00f9b62cf9b843febb78c81e575c.zip
marquee-3aa86a78fdcf00f9b62cf9b843febb78c81e575c.tar.gz
marquee-3aa86a78fdcf00f9b62cf9b843febb78c81e575c.tar.bz2
MqTabBody: Populate menu items for some contexts
Diffstat (limited to 'src')
-rw-r--r--src/tab-body.c168
-rw-r--r--src/tab-body.h7
2 files changed, 167 insertions, 8 deletions
diff --git a/src/tab-body.c b/src/tab-body.c
index c5266b2..ad2e2ac 100644
--- a/src/tab-body.c
+++ b/src/tab-body.c
@@ -27,9 +27,127 @@
#include "tab-body.h"
#include "tab.h"
+static void
+menu_open_link_activate_cb(GtkAction __attribute__((unused)) *action,
+ MqTabBody *body)
+{
+ webkit_web_view_load_uri(body->web_view,
+ webkit_hit_test_result_get_link_uri(body->hit_test_result));
+}
+
+static void
+menu_open_link_tab_activate_cb(GtkAction __attribute__((unused)) *action,
+ MqTabBody *body)
+{
+ g_print("Open Link in New Tab\n");
+}
+
+static void
+menu_open_link_win_activate_cb(GtkAction __attribute__((unused)) *action,
+ MqTabBody *body)
+{
+ g_print("Open Link in New Window\n");
+}
+
+static void
+menu_open_image_activate_cb(GtkAction __attribute__((unused)) *action,
+ MqTabBody *body)
+{
+ webkit_web_view_load_uri(body->web_view,
+ webkit_hit_test_result_get_image_uri(body->hit_test_result));
+}
+
+static void
+menu_open_image_tab_activate_cb(GtkAction __attribute__((unused)) *action,
+ MqTabBody *body)
+{
+ g_print("Open Image in New Tab\n");
+}
+
+static void
+menu_open_image_win_activate_cb(GtkAction __attribute__((unused)) *action,
+ MqTabBody *body)
+{
+ g_print("Open Image in New Window\n");
+}
+
+#define ITEM_BEGIN_DECLS \
+ GtkAction *action; \
+ WebKitContextMenuItem *menu_item; \
+ /* Don't blame me; blame WebKitGTK+ for using GtkAction. */ \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+#define ITEM_BEGIN_DECLS_NO_CUSTOM \
+ WebKitContextMenuItem *menu_item;
+ _Pragma("GCC diagnostic push")
+#define ITEM_END_DECLS \
+ _Pragma("GCC diagnostic pop")
+#define NEW_CUSTOM_ITEM(NAME, LABEL) \
+ do { \
+ action = gtk_action_new(#NAME, (LABEL), NULL, NULL); \
+ g_signal_connect(action, "activate", \
+ G_CALLBACK(menu_##NAME##_activate_cb), body); \
+ menu_item = webkit_context_menu_item_new(action); \
+ webkit_context_menu_append(context_menu, menu_item); \
+ } while (0)
+#define NEW_STOCK_ITEM(STOCK) \
+ do { \
+ menu_item = webkit_context_menu_item_new_from_stock_action( \
+ WEBKIT_CONTEXT_MENU_ACTION_##STOCK); \
+ webkit_context_menu_append(context_menu, menu_item); \
+ } while (0)
+
+static void
+context_menu_link_cb(WebKitContextMenu *context_menu, MqTabBody *body)
+{
+ ITEM_BEGIN_DECLS
+
+ NEW_CUSTOM_ITEM(open_link, "Open Link");
+ NEW_CUSTOM_ITEM(open_link_tab, "Open Link in New Tab");
+ NEW_CUSTOM_ITEM(open_link_win, "Open Link in New Window");
+ NEW_STOCK_ITEM(DOWNLOAD_LINK_TO_DISK); /* Download Linked File */
+ NEW_STOCK_ITEM(COPY_LINK_TO_CLIPBOARD); /* Copy Link Location */
+
+ ITEM_END_DECLS
+}
+
+static void
+context_menu_image_cb(WebKitContextMenu *context_menu, MqTabBody *body)
+{
+ ITEM_BEGIN_DECLS
+
+ NEW_CUSTOM_ITEM(open_image, "Open Image");
+ NEW_CUSTOM_ITEM(open_image_tab, "Open Image in New Tab");
+ NEW_CUSTOM_ITEM(open_image_win, "Open Image in New Window");
+ NEW_STOCK_ITEM(DOWNLOAD_IMAGE_TO_DISK); /* Save Image As */
+ NEW_STOCK_ITEM(COPY_IMAGE_TO_CLIPBOARD); /* Copy Image */
+ NEW_STOCK_ITEM(COPY_IMAGE_URL_TO_CLIPBOARD); /* Copy Image Address */
+
+ ITEM_END_DECLS
+}
+
+static void
+context_menu_document_cb(WebKitContextMenu *context_menu, MqTabBody *body)
+{
+ ITEM_BEGIN_DECLS_NO_CUSTOM
+
+ NEW_STOCK_ITEM(GO_BACK); /* Back */
+ NEW_STOCK_ITEM(GO_FORWARD); /* Forward */
+ NEW_STOCK_ITEM(STOP); /* Stop */
+ NEW_STOCK_ITEM(RELOAD); /* Reload */
+ NEW_STOCK_ITEM(NO_ACTION); /* --- */
+ NEW_STOCK_ITEM(SELECT_ALL); /* Select All */
+ NEW_STOCK_ITEM(NO_ACTION); /* --- */
+ /* View Page Source */
+
+ ITEM_END_DECLS
+}
+
static gboolean
-context_menu_cb(WebKitWebView *web_view, WebKitContextMenu *context_menu,
- GdkEvent *event, WebKitHitTestResult *hit_test_result, MqTabBody *body)
+context_menu_cb(WebKitWebView __attribute__((unused)) *web_view,
+ WebKitContextMenu *context_menu,
+ GdkEvent __attribute__((unused)) *event,
+ WebKitHitTestResult *hit_test_result, MqTabBody *body)
{
GList *items;
GList *input_items;
@@ -88,28 +206,63 @@ context_menu_cb(WebKitWebView *web_view, WebKitContextMenu *context_menu,
#pragma GCC diagnostic pop
}
+ webkit_context_menu_remove_all(context_menu);
+
context = webkit_hit_test_result_get_context(hit_test_result);
+ if (body->hit_test_result) {
+ g_object_unref(body->hit_test_result);
+ }
+ body->hit_test_result = hit_test_result;
+ g_object_ref(body->hit_test_result);
context_handled = FALSE;
g_print("Context menu, hit test:");
if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
- g_print(" link");
+ context_menu_link_cb(context_menu, body);
context_handled = TRUE;
}
if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE) {
- g_print(" image");
+ context_menu_image_cb(context_menu, body);
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;
}
}
if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) {
+ /* Cut (stock)
+ * Copy (stock)
+ * Paste (stock)
+ * Delete (stock)
+ * ---
+ * Select All (stock)
+ * Insert Unicode Character (preserved) */
g_print(" editable");
context_handled = TRUE;
}
@@ -118,10 +271,14 @@ context_menu_cb(WebKitWebView *web_view, WebKitContextMenu *context_menu,
if (is_selection) {
g_print(" selection");
} else {
- g_print(" document");
+ context_menu_document_cb(context_menu, body);
}
}
g_print("\n");
+ if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT) {
+ /* ---
+ * Inspect Element (stock) */
+ }
return FALSE;
}
@@ -144,6 +301,7 @@ mq_tab_body_new(MqTab *tab, gchar *uri)
/* FIXME: This doesn't seem to be working. */
gtk_widget_grab_focus(body->container);
+ body->hit_test_result = NULL;
g_signal_connect(body->web_view, "context-menu",
G_CALLBACK(context_menu_cb), body);
diff --git a/src/tab-body.h b/src/tab-body.h
index 332cfeb..446228d 100644
--- a/src/tab-body.h
+++ b/src/tab-body.h
@@ -30,9 +30,10 @@ typedef struct MqTabBody MqTabBody;
#include "tab.h"
struct MqTabBody {
- MqTab *tab;
- GtkWidget *container;
- WebKitWebView *web_view;
+ MqTab *tab;
+ GtkWidget *container;
+ WebKitWebView *web_view;
+ WebKitHitTestResult *hit_test_result;
};
MqTabBody *