[epiphany] Add context menu entries for media elements
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Add context menu entries for media elements
- Date: Wed, 27 Aug 2014 09:53:49 +0000 (UTC)
commit 4c5b4c9fa65c46377c2cd51ca6790fe3ef77bbc6
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Tue Aug 26 13:44:29 2014 +0200
Add context menu entries for media elements
https://bugzilla.gnome.org/show_bug.cgi?id=735259
src/ephy-window.c | 123 ++++++++++++++++++++++++++++++++++++++++++++------
src/popup-commands.c | 96 +++++++++++++++++++++++++-------------
src/popup-commands.h | 12 +++++
3 files changed, 184 insertions(+), 47 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 1926f7a..df1b129 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -238,6 +238,28 @@ static const GtkActionEntry ephy_popups_entries [] = {
NULL, G_CALLBACK (popup_cmd_save_image_as) },
{ "SetImageAsBackground", NULL, N_("Set as _Wallpaper"), NULL,
NULL, G_CALLBACK (popup_cmd_set_image_as_background) },
+
+ /* Video. */
+
+ { "OpenVideoInNewWindow", NULL, N_("Open Video in New _Window"), NULL, NULL,
+ G_CALLBACK (popup_cmd_media_in_new_window) },
+ { "OpenVideoInNewTab", NULL, N_("Open Video in New _Tab"), NULL, NULL,
+ G_CALLBACK (popup_cmd_media_in_new_tab) },
+ { "SaveVideoAs", NULL, N_("_Save Video As…"), NULL,
+ NULL, G_CALLBACK (popup_cmd_save_media_as) },
+ { "CopyVideoLocation", NULL, N_("_Copy Video Address"), NULL,
+ NULL, G_CALLBACK (popup_cmd_copy_media_location) },
+
+ /* Audio. */
+
+ { "OpenAudioInNewWindow", NULL, N_("Open Audio in New _Window"), NULL, NULL,
+ G_CALLBACK (popup_cmd_media_in_new_window) },
+ { "OpenAudioInNewTab", NULL, N_("Open Audio in New _Tab"), NULL, NULL,
+ G_CALLBACK (popup_cmd_media_in_new_tab) },
+ { "SaveAudioAs", NULL, N_("_Save Audio As…"), NULL,
+ NULL, G_CALLBACK (popup_cmd_save_media_as) },
+ { "CopyAudioLocation", NULL, N_("_Copy Audio Address"), NULL,
+ NULL, G_CALLBACK (popup_cmd_copy_media_location) },
};
static const struct
@@ -1551,6 +1573,17 @@ add_action_to_context_menu (WebKitContextMenu *context_menu,
webkit_context_menu_append (context_menu, webkit_context_menu_item_new (action));
}
+static void
+add_item_to_context_menu (WebKitContextMenu *context_menu,
+ WebKitContextMenuItem *item)
+{
+ if (!item)
+ return;
+
+ webkit_context_menu_append (context_menu, item);
+ g_object_unref (item);
+}
+
/* FIXME: Add webkit_context_menu_find() ? */
static WebKitContextMenuItem *
find_item_in_context_menu (WebKitContextMenu *context_menu,
@@ -1609,11 +1642,19 @@ populate_context_menu (WebKitWebView *web_view,
EphyWindowPrivate *priv = window->priv;
WebKitContextMenuItem *input_methods_item = NULL;
WebKitContextMenuItem *unicode_item = NULL;
+ WebKitContextMenuItem *play_pause_item = NULL;
+ WebKitContextMenuItem *mute_item = NULL;
+ WebKitContextMenuItem *toggle_controls_item = NULL;
+ WebKitContextMenuItem *toggle_loop_item = NULL;
+ WebKitContextMenuItem *fullscreen_item = NULL;
GList *spelling_guess_items = NULL;
EphyEmbedEvent *embed_event;
gboolean is_document = FALSE;
gboolean app_mode;
gboolean is_image;
+ gboolean is_media = FALSE;
+ gboolean is_video = FALSE;
+ gboolean is_audio = FALSE;
is_image = webkit_hit_test_result_context_is_image (hit_test_result);
@@ -1623,6 +1664,36 @@ populate_context_menu (WebKitWebView *web_view,
spelling_guess_items = find_spelling_guess_context_menu_items (context_menu);
}
+ if (webkit_hit_test_result_context_is_media (hit_test_result))
+ {
+ WebKitContextMenuItem *item;
+
+ is_media = TRUE;
+ play_pause_item = find_item_in_context_menu (context_menu,
WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY);
+ if (!play_pause_item)
+ play_pause_item = find_item_in_context_menu (context_menu,
WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PAUSE);
+ mute_item = find_item_in_context_menu (context_menu, WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE);
+ toggle_controls_item = find_item_in_context_menu (context_menu,
WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS);
+ toggle_loop_item = find_item_in_context_menu (context_menu,
WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_LOOP);
+ fullscreen_item = find_item_in_context_menu (context_menu,
WEBKIT_CONTEXT_MENU_ACTION_ENTER_VIDEO_FULLSCREEN);
+
+ item = find_item_in_context_menu (context_menu,
WEBKIT_CONTEXT_MENU_ACTION_COPY_VIDEO_LINK_TO_CLIPBOARD);
+ if (item)
+ {
+ is_video = TRUE;
+ g_object_unref (item);
+ }
+ else
+ {
+ item = find_item_in_context_menu (context_menu,
WEBKIT_CONTEXT_MENU_ACTION_COPY_AUDIO_LINK_TO_CLIPBOARD);
+ if (item)
+ {
+ is_audio = TRUE;
+ g_object_unref (item);
+ }
+ }
+ }
+
webkit_context_menu_remove_all (context_menu);
embed_event = ephy_embed_event_new ((GdkEventButton *)event, hit_test_result);
@@ -1713,17 +1784,8 @@ populate_context_menu (WebKitWebView *web_view,
if (input_methods_item || unicode_item)
webkit_context_menu_append (context_menu,
webkit_context_menu_item_new_separator ());
- if (input_methods_item)
- {
- webkit_context_menu_append (context_menu, input_methods_item);
- g_object_unref (input_methods_item);
- }
-
- if (unicode_item)
- {
- webkit_context_menu_append (context_menu, unicode_item);
- g_object_unref (unicode_item);
- }
+ add_item_to_context_menu (context_menu, input_methods_item);
+ add_item_to_context_menu (context_menu, unicode_item);
}
else
{
@@ -1731,7 +1793,7 @@ populate_context_menu (WebKitWebView *web_view,
update_edit_actions_sensitivity (window, TRUE);
- if (!is_image)
+ if (!is_image && !is_media)
{
add_action_to_context_menu (context_menu,
priv->toolbar_action_group, "NavigationBack");
@@ -1746,7 +1808,7 @@ populate_context_menu (WebKitWebView *web_view,
add_action_to_context_menu (context_menu,
priv->action_group, "EditCopy");
- if (!app_mode && !is_image)
+ if (!app_mode && !is_image && !is_media)
{
webkit_context_menu_append (context_menu,
webkit_context_menu_item_new_separator ());
@@ -1769,7 +1831,40 @@ populate_context_menu (WebKitWebView *web_view,
priv->popups_action_group, "SetImageAsBackground");
}
- if (is_document)
+ if (is_media)
+ {
+ add_item_to_context_menu (context_menu, play_pause_item);
+ add_item_to_context_menu (context_menu, mute_item);
+ add_item_to_context_menu (context_menu, toggle_controls_item);
+ add_item_to_context_menu (context_menu, toggle_loop_item);
+ add_item_to_context_menu (context_menu, fullscreen_item);
+ webkit_context_menu_append (context_menu,
+ webkit_context_menu_item_new_separator ());
+ if (is_video)
+ {
+ add_action_to_context_menu (context_menu, priv->popups_action_group,
+ "OpenVideoInNewWindow");
+ add_action_to_context_menu (context_menu, priv->popups_action_group,
+ "OpenVideoInNewTab");
+ add_action_to_context_menu (context_menu, priv->popups_action_group,
+ "SaveVideoAs");
+ add_action_to_context_menu (context_menu, priv->popups_action_group,
+ "CopyVideoLocation");
+ }
+ else if (is_audio)
+ {
+ add_action_to_context_menu (context_menu, priv->popups_action_group,
+ "OpenAudioInNewWindow");
+ add_action_to_context_menu (context_menu, priv->popups_action_group,
+ "OpenAudioInNewTab");
+ add_action_to_context_menu (context_menu, priv->popups_action_group,
+ "SaveAudioAs");
+ add_action_to_context_menu (context_menu, priv->popups_action_group,
+ "CopyAudioLocation");
+ }
+ }
+
+ if (is_document && !is_image && !is_media)
{
webkit_context_menu_append (context_menu,
webkit_context_menu_item_new_separator ());
diff --git a/src/popup-commands.c b/src/popup-commands.c
index bcc55bb..8faaa66 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -38,9 +38,9 @@
#include <string.h>
#include <webkit2/webkit2.h>
-void
-popup_cmd_link_in_new_window (GtkAction *action,
- EphyWindow *window)
+static void
+popup_cmd_view_in_new_window (EphyWindow *window,
+ const char *property_name)
{
EphyWindow *new_window;
EphyEmbedEvent *event;
@@ -48,14 +48,13 @@ popup_cmd_link_in_new_window (GtkAction *action,
EphyEmbed *new_embed;
GValue value = { 0, };
- embed = ephy_embed_container_get_active_child
- (EPHY_EMBED_CONTAINER (window));
+ embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
event = ephy_window_get_context_event (window);
g_return_if_fail (event != NULL);
new_window = ephy_window_new ();
- ephy_embed_event_get_property (event, "link-uri", &value);
+ ephy_embed_event_get_property (event, property_name, &value);
new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
new_window, embed,
@@ -66,28 +65,17 @@ popup_cmd_link_in_new_window (GtkAction *action,
}
void
-popup_cmd_link_in_new_tab (GtkAction *action,
- EphyWindow *window)
+popup_cmd_link_in_new_window (GtkAction *action,
+ EphyWindow *window)
{
- EphyEmbedEvent *event;
- EphyEmbed *embed;
- EphyEmbed *new_embed;
- GValue value = { 0, };
-
- embed = ephy_embed_container_get_active_child
- (EPHY_EMBED_CONTAINER (window));
-
- event = ephy_window_get_context_event (window);
- g_return_if_fail (event != NULL);
-
- ephy_embed_event_get_property (event, "link-uri", &value);
+ popup_cmd_view_in_new_window (window, "link-uri");
+}
- new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
- window, embed,
- EPHY_NEW_TAB_APPEND_AFTER);
- ephy_web_view_load_url (ephy_embed_get_web_view (new_embed),
- g_value_get_string (&value));
- g_value_unset (&value);
+void
+popup_cmd_media_in_new_window (GtkAction *action,
+ EphyWindow *window)
+{
+ popup_cmd_view_in_new_window (window, "media-uri");
}
void
@@ -236,6 +224,7 @@ popup_cmd_download_link_as (GtkAction *action,
{
save_property_url (_("Save Link As"), window, "link-uri");
}
+
void
popup_cmd_save_image_as (GtkAction *action,
EphyWindow *window)
@@ -243,6 +232,13 @@ popup_cmd_save_image_as (GtkAction *action,
save_property_url (_("Save Image As"), window, "image-uri");
}
+void
+popup_cmd_save_media_as (GtkAction *action,
+ EphyWindow *window)
+{
+ save_property_url (_("Save Media As"), window, "media-uri");
+}
+
static void
background_download_completed (EphyDownload *download,
GtkWidget *window)
@@ -293,24 +289,38 @@ popup_cmd_set_image_as_background (GtkAction *action,
g_free (dest_uri);
}
-void
-popup_cmd_copy_image_location (GtkAction *action,
- EphyWindow *window)
+static void
+popup_cmd_copy_location (EphyWindow *window,
+ const char *property_name)
{
EphyEmbedEvent *event;
const char *location;
GValue value = { 0, };
event = ephy_window_get_context_event (window);
- ephy_embed_event_get_property (event, "image-uri", &value);
+ ephy_embed_event_get_property (event, property_name, &value);
location = g_value_get_string (&value);
popup_cmd_copy_to_clipboard (window, location);
g_value_unset (&value);
}
void
-popup_cmd_view_image_in_new_tab (GtkAction *action,
- EphyWindow *window)
+popup_cmd_copy_image_location (GtkAction *action,
+ EphyWindow *window)
+{
+ popup_cmd_copy_location (window, "image-uri");
+}
+
+void
+popup_cmd_copy_media_location (GtkAction *action,
+ EphyWindow *window)
+{
+ popup_cmd_copy_location (window, "media-uri");
+}
+
+static void
+popup_cmd_view_in_new_tab (EphyWindow *window,
+ const char *property_name)
{
EphyEmbedEvent *event;
GValue value = { 0, };
@@ -323,7 +333,7 @@ popup_cmd_view_image_in_new_tab (GtkAction *action,
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
g_return_if_fail (embed != NULL);
- ephy_embed_event_get_property (event, "image-uri", &value);
+ ephy_embed_event_get_property (event, property_name, &value);
new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
window, embed,
@@ -333,3 +343,23 @@ popup_cmd_view_image_in_new_tab (GtkAction *action,
g_value_unset (&value);
}
+void
+popup_cmd_link_in_new_tab (GtkAction *action,
+ EphyWindow *window)
+{
+ popup_cmd_view_in_new_tab (window, "link-uri");
+}
+
+void
+popup_cmd_view_image_in_new_tab (GtkAction *action,
+ EphyWindow *window)
+{
+ popup_cmd_view_in_new_tab (window, "image-uri");
+}
+
+void
+popup_cmd_media_in_new_tab (GtkAction *action,
+ EphyWindow *window)
+{
+ popup_cmd_view_in_new_tab (window, "media-uri");
+}
diff --git a/src/popup-commands.h b/src/popup-commands.h
index 1d9097a..9e40e73 100644
--- a/src/popup-commands.h
+++ b/src/popup-commands.h
@@ -62,6 +62,18 @@ void popup_cmd_download_link (GtkAction *action,
void popup_cmd_save_image_as (GtkAction *action,
EphyWindow *window);
+void popup_cmd_media_in_new_window (GtkAction *action,
+ EphyWindow *window);
+
+void popup_cmd_media_in_new_tab (GtkAction *action,
+ EphyWindow *window);
+
+void popup_cmd_copy_media_location (GtkAction *action,
+ EphyWindow *window);
+
+void popup_cmd_save_media_as (GtkAction *action,
+ EphyWindow *window);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]