[epiphany/wip/exalm/cleanups] embed: Inline EphyEmbedEvent



commit 31ee8c74adec3e6bf3625939b50691c05a2809e1
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Nov 29 17:44:01 2021 +0500

    embed: Inline EphyEmbedEvent
    
    It was probably more useful when it was written, but by now it's a thin
    wrapper around WebKitHitTestResult that proxies everything to it and
    doesn't do much else. Also contains a GdkEvent and proxies its fields
    but it's unused.
    
    So just inline it instead.

 embed/ephy-embed-event.c | 171 -----------------------------------------------
 embed/ephy-embed-event.h |  48 -------------
 embed/meson.build        |   1 -
 src/ephy-window.c        |  21 ++----
 src/ephy-window.h        |   3 +-
 src/popup-commands.c     |  76 +++++++++------------
 6 files changed, 39 insertions(+), 281 deletions(-)
---
diff --git a/embed/meson.build b/embed/meson.build
index dd92a9227..28b95859c 100644
--- a/embed/meson.build
+++ b/embed/meson.build
@@ -17,7 +17,6 @@ libephyembed_sources = [
   'ephy-download.c',
   'ephy-embed.c',
   'ephy-embed-container.c',
-  'ephy-embed-event.c',
   'ephy-embed-prefs.c',
   'ephy-embed-shell.c',
   'ephy-embed-utils.c',
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 6f8ac95b8..c467618b4 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -165,7 +165,7 @@ struct _EphyWindow {
   GtkWidget *action_bar;
   EphyEmbed *active_embed;
   EphyWindowChrome chrome;
-  EphyEmbedEvent *context_event;
+  WebKitHitTestResult *context_event;
   WebKitHitTestResult *hit_test_result;
   guint idle_worker;
   EphyLocationController *location_controller;
@@ -1318,23 +1318,19 @@ idle_unref_context_event (EphyWindow *window)
 {
   LOG ("Idle unreffing context event %p", window->context_event);
 
-  if (window->context_event != NULL) {
-    g_object_unref (window->context_event);
-    window->context_event = NULL;
-  }
+  g_clear_object (&window->context_event);
 
   window->idle_worker = 0;
   return FALSE;
 }
 
 static void
-_ephy_window_set_context_event (EphyWindow     *window,
-                                EphyEmbedEvent *event)
+_ephy_window_set_context_event (EphyWindow          *window,
+                                WebKitHitTestResult *hit_test_result)
 {
   g_clear_handle_id (&window->idle_worker, g_source_remove);
 
-  g_clear_object (&window->context_event);
-  window->context_event = event != NULL ? g_object_ref (event) : NULL;
+  g_set_object (&window->context_event, hit_test_result);
 }
 
 static void
@@ -1544,7 +1540,6 @@ populate_context_menu (WebKitWebView       *web_view,
   GActionGroup *toolbar_action_group;
   GActionGroup *popup_action_group;
   GList *spelling_guess_items = NULL;
-  EphyEmbedEvent *embed_event;
   gboolean app_mode, incognito_mode;
   gboolean is_document = FALSE;
   gboolean is_image = FALSE;
@@ -1629,9 +1624,7 @@ populate_context_menu (WebKitWebView       *web_view,
 
   webkit_context_menu_remove_all (context_menu);
 
-  embed_event = ephy_embed_event_new (event, hit_test_result);
-  _ephy_window_set_context_event (window, embed_event);
-  g_object_unref (embed_event);
+  _ephy_window_set_context_event (window, hit_test_result);
 
   app_mode = ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) == 
EPHY_EMBED_SHELL_MODE_APPLICATION;
   incognito_mode = ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) == 
EPHY_EMBED_SHELL_MODE_INCOGNITO;
@@ -4098,7 +4091,7 @@ ephy_window_set_zoom (EphyWindow *window,
  *
  * Return value: (transfer none): an #EphyEmbedEvent, or %NULL
  **/
-EphyEmbedEvent *
+WebKitHitTestResult *
 ephy_window_get_context_event (EphyWindow *window)
 {
   g_assert (EPHY_IS_WINDOW (window));
diff --git a/src/ephy-window.h b/src/ephy-window.h
index 1c7a1459d..35997a3d9 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -23,7 +23,6 @@
 #include "ephy-bookmark-states.h"
 #include "ephy-bookmarks-manager.h"
 #include "ephy-embed.h"
-#include "ephy-embed-event.h"
 #include "ephy-location-controller.h"
 #include "ephy-tab-view.h"
 #include "ephy-web-view.h"
@@ -71,7 +70,7 @@ EphyWindowChrome  ephy_window_get_chrome          (EphyWindow *window);
 
 EphyLocationController  *ephy_window_get_location_controller (EphyWindow *window);
 
-EphyEmbedEvent   *ephy_window_get_context_event        (EphyWindow *window);
+WebKitHitTestResult *ephy_window_get_context_event     (EphyWindow *window);
 
 GtkWidget        *ephy_window_get_current_find_toolbar (EphyWindow *window);
 
diff --git a/src/popup-commands.c b/src/popup-commands.c
index 40ff2f4d9..4a3c5a9bb 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -48,8 +48,8 @@ view_in_destination (EphyWindow      *window,
                      const char      *property_name,
                      LinkDestination  destination)
 {
-  EphyEmbedEvent *event;
-  GValue value = { 0, };
+  WebKitHitTestResult *hit_test_result;
+  g_autofree char *value = NULL;
   EphyEmbed *embed;
   EphyEmbed *new_embed;
   EphyWebView *new_view;
@@ -57,13 +57,13 @@ view_in_destination (EphyWindow      *window,
   EphyWindow *dest_window = window;
   EphyNewTabFlags flags = 0;
 
-  event = ephy_window_get_context_event (window);
-  g_assert (event != NULL);
+  hit_test_result = ephy_window_get_context_event (window);
+  g_assert (hit_test_result != NULL);
 
   embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
   g_assert (embed != NULL);
 
-  ephy_embed_event_get_property (event, property_name, &value);
+  g_object_get (hit_test_result, property_name, &value, NULL);
   switch (destination) {
     case NEW_WINDOW:
       dest_window = ephy_window_new ();
@@ -84,8 +84,7 @@ view_in_destination (EphyWindow      *window,
   session_state = webkit_web_view_get_session_state (WEBKIT_WEB_VIEW (ephy_embed_get_web_view (embed)));
   webkit_web_view_restore_session_state (WEBKIT_WEB_VIEW (new_view), session_state);
   webkit_web_view_session_state_unref (session_state);
-  ephy_web_view_load_url (new_view, g_value_get_string (&value));
-  g_value_unset (&value);
+  ephy_web_view_load_url (new_view, value);
 }
 
 void
@@ -117,25 +116,22 @@ popup_cmd_copy_link_address (GSimpleAction *action,
                              GVariant      *parameter,
                              gpointer       user_data)
 {
-  EphyEmbedEvent *event;
+  WebKitHitTestResult *hit_test_result;
   guint context;
   const char *address;
-  GValue value = { 0, };
 
-  event = ephy_window_get_context_event (EPHY_WINDOW (user_data));
-  g_assert (event != NULL);
+  hit_test_result = ephy_window_get_context_event (EPHY_WINDOW (user_data));
+  g_assert (hit_test_result != NULL);
 
-  context = ephy_embed_event_get_context (event);
+  context = webkit_hit_test_result_get_context (hit_test_result);
 
   if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
-    ephy_embed_event_get_property (event, "link-uri", &value);
-    address = g_value_get_string (&value);
+    address = webkit_hit_test_result_get_link_uri (hit_test_result);
 
     if (g_str_has_prefix (address, "mailto:";))
       address = address + 7;
 
     popup_cmd_copy_to_clipboard (EPHY_WINDOW (user_data), address);
-    g_value_unset (&value);
   }
 }
 
@@ -205,17 +201,15 @@ save_property_url (const char *title,
                    EphyWindow *window,
                    const char *property)
 {
-  EphyEmbedEvent *event;
-  const char *location;
+  WebKitHitTestResult *hit_test_result;
+  g_autofree char *location = NULL;
   EphyDownload *download;
   SavePropertyURLData *data;
-  GValue value = G_VALUE_INIT;
 
-  event = ephy_window_get_context_event (window);
-  g_assert (event != NULL);
+  hit_test_result = ephy_window_get_context_event (window);
+  g_assert (hit_test_result != NULL);
 
-  ephy_embed_event_get_property (event, property, &value);
-  location = g_value_get_string (&value);
+  g_object_get (hit_test_result, property, &location, NULL);
   download = ephy_download_new_for_uri (location);
   data = g_new (SavePropertyURLData, 1);
   data->title = g_strdup (title);
@@ -223,8 +217,6 @@ save_property_url (const char *title,
   g_signal_connect (download, "filename-suggested",
                     G_CALLBACK (filename_suggested_cb),
                     data);
-
-  g_value_unset (&value);
 }
 
 void
@@ -268,20 +260,18 @@ popup_cmd_set_image_as_background (GSimpleAction *action,
                                    GVariant      *parameter,
                                    gpointer       user_data)
 {
-  EphyEmbedEvent *event;
+  WebKitHitTestResult *hit_test_result;
   const char *location;
   char *dest_uri, *dest, *base, *base_converted;
-  GValue value = { 0, };
   EphyDownload *download;
 
   if (ephy_is_running_inside_flatpak ())
     return;
 
-  event = ephy_window_get_context_event (EPHY_WINDOW (user_data));
-  g_assert (event != NULL);
+  hit_test_result = ephy_window_get_context_event (EPHY_WINDOW (user_data));
+  g_assert (hit_test_result != NULL);
 
-  ephy_embed_event_get_property (event, "image-uri", &value);
-  location = g_value_get_string (&value);
+  location = webkit_hit_test_result_get_image_uri (hit_test_result);
 
   download = ephy_download_new_for_uri (location);
 
@@ -298,7 +288,6 @@ popup_cmd_set_image_as_background (GSimpleAction *action,
   g_signal_connect (download, "completed",
                     G_CALLBACK (background_download_completed), user_data);
 
-  g_value_unset (&value);
   g_free (base);
   g_free (base_converted);
   g_free (dest);
@@ -309,15 +298,12 @@ static void
 popup_cmd_copy_location (EphyWindow *window,
                          const char *property_name)
 {
-  EphyEmbedEvent *event;
-  const char *location;
-  GValue value = { 0, };
+  WebKitHitTestResult *hit_test_result;
+  g_autofree char *location = NULL;
 
-  event = ephy_window_get_context_event (window);
-  ephy_embed_event_get_property (event, property_name, &value);
-  location = g_value_get_string (&value);
+  hit_test_result = ephy_window_get_context_event (window);
+  g_object_get (hit_test_result, property_name, &location, NULL);
   popup_cmd_copy_to_clipboard (window, location);
-  g_value_unset (&value);
 }
 
 void
@@ -365,15 +351,15 @@ popup_cmd_link_in_incognito_window (GSimpleAction *action,
                                     GVariant      *parameter,
                                     gpointer       user_data)
 {
-  EphyEmbedEvent *event;
-  GValue value = { 0, };
+  WebKitHitTestResult *hit_test_result;
+  const char *link_uri;
+
+  hit_test_result = ephy_window_get_context_event (EPHY_WINDOW (user_data));
+  g_assert (hit_test_result != NULL);
 
-  event = ephy_window_get_context_event (EPHY_WINDOW (user_data));
-  g_assert (event != NULL);
+  link_uri = webkit_hit_test_result_get_link_uri (hit_test_result);
 
-  ephy_embed_event_get_property (event, "link-uri", &value);
-  ephy_open_incognito_window (g_value_get_string (&value));
-  g_value_unset (&value);
+  ephy_open_incognito_window (link_uri);
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]