[epiphany/wip/exalm/tabs: 92/92] Update
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/tabs: 92/92] Update
- Date: Wed, 27 Jan 2021 09:26:49 +0000 (UTC)
commit 19e6d73af751fa2092bf82b98396fd5b9eb185be
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Jan 27 14:25:14 2021 +0500
Update
src/ephy-shell.c | 17 ++++-----
src/ephy-tab-view.c | 9 +++++
src/ephy-tab-view.h | 2 ++
src/ephy-window.c | 4 +--
src/webextension/api/tabs.c | 10 +++---
src/webextension/ephy-web-extension-manager.c | 32 ++++++++---------
tests/ephy-shell-test.c | 51 ++++++++++++---------------
7 files changed, 63 insertions(+), 62 deletions(-)
---
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 0bd94cf87..ae19357d9 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -1555,16 +1555,16 @@ ephy_shell_get_web_view (EphyShell *shell,
{
GList *windows;
GtkWindow *window;
- GtkWidget *notebook;
+ EphyTabView *tab_view;
windows = gtk_application_get_windows (GTK_APPLICATION (shell));
for (GList *list = windows; list && list->data; list = list->next) {
window = GTK_WINDOW (list->data);
- notebook = ephy_window_get_notebook (EPHY_WINDOW (window));
+ tab_view = ephy_window_get_tab_view (EPHY_WINDOW (window));
- for (int i = 0; i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); i++) {
- GtkWidget *page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i);
+ for (int i = 0; i < ephy_tab_view_get_n_pages (tab_view); i++) {
+ GtkWidget *page = ephy_tab_view_get_nth_page (tab_view, i);
EphyWebView *web_view = ephy_embed_get_web_view (EPHY_EMBED (page));
if (ephy_web_view_get_uid (web_view) == id)
@@ -1579,18 +1579,15 @@ EphyWebView *
ephy_shell_get_active_web_view (EphyShell *shell)
{
GtkWindow *window;
- GtkWidget *notebook;
+ EphyTabView *tab_view;
GtkWidget *page;
- gint page_num;
window = gtk_application_get_active_window (GTK_APPLICATION (shell));
if (!window)
return NULL;
- notebook = ephy_window_get_notebook (EPHY_WINDOW (window));
-
- page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
- page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), page_num);
+ tab_view = ephy_window_get_tab_view (EPHY_WINDOW (window));
+ page = ephy_tab_view_get_selected_page (tab_view);
return ephy_embed_get_web_view (EPHY_EMBED (page));
}
diff --git a/src/ephy-tab-view.c b/src/ephy-tab-view.c
index 96a33b476..acd23cf0d 100644
--- a/src/ephy-tab-view.c
+++ b/src/ephy-tab-view.c
@@ -267,6 +267,15 @@ ephy_tab_view_get_selected_index (EphyTabView *self)
return hdy_tab_view_get_page_position (self->tab_view, page);
}
+gint
+ephy_tab_view_get_page_index (EphyTabView *self,
+ GtkWidget *widget)
+{
+ HdyTabPage *page = hdy_tab_view_get_page (self->tab_view, widget);
+
+ return hdy_tab_view_get_page_position (self->tab_view, page);
+}
+
GtkWidget *
ephy_tab_view_get_nth_page (EphyTabView *self,
gint index)
diff --git a/src/ephy-tab-view.h b/src/ephy-tab-view.h
index f8b2cec2a..a04607ef6 100644
--- a/src/ephy-tab-view.h
+++ b/src/ephy-tab-view.h
@@ -49,6 +49,8 @@ void ephy_tab_view_foreach (EphyTabView *self,
gint ephy_tab_view_get_n_pages (EphyTabView *self);
gint ephy_tab_view_get_selected_index (EphyTabView *self);
+gint ephy_tab_view_get_page_index (EphyTabView *self,
+ GtkWidget *widget);
GtkWidget *ephy_tab_view_get_nth_page (EphyTabView *self,
gint index);
diff --git a/src/ephy-window.c b/src/ephy-window.c
index fd2690880..3498f03ea 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2715,12 +2715,12 @@ tab_view_page_attached_cb (HdyTabView *tab_view,
GtkWidget *content = hdy_tab_page_get_child (page);
EphyEmbed *embed;
- LOG ("page-attached tab view %p embed %p position %d\n", tab_view, embed, position);
-
g_assert (EPHY_IS_EMBED (content));
embed = EPHY_EMBED (content);
+ LOG ("page-attached tab view %p embed %p position %d\n", tab_view, embed, position);
+
g_signal_connect_object (ephy_embed_get_web_view (embed), "download-only-load",
G_CALLBACK (download_only_load_cb), window, G_CONNECT_AFTER);
diff --git a/src/webextension/api/tabs.c b/src/webextension/api/tabs.c
index 162724508..d54126704 100644
--- a/src/webextension/api/tabs.c
+++ b/src/webextension/api/tabs.c
@@ -46,7 +46,7 @@ tabs_handler_query (EphyWebExtension *self,
g_autoptr (JsonNode) root = NULL;
EphyShell *shell = ephy_shell_get_default ();
GtkWindow *window;
- GtkWidget *notebook;
+ EphyTabView *tab_view;
gboolean current_window = TRUE;
gboolean active = TRUE;
@@ -66,18 +66,18 @@ tabs_handler_query (EphyWebExtension *self,
if (current_window) {
window = gtk_application_get_active_window (GTK_APPLICATION (shell));
- notebook = ephy_window_get_notebook (EPHY_WINDOW (window));
+ tab_view = ephy_window_get_tab_view (EPHY_WINDOW (window));
json_builder_begin_array (builder);
if (active) {
- GtkWidget *page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), gtk_notebook_get_current_page
(GTK_NOTEBOOK (notebook)));
+ GtkWidget *page = ephy_tab_view_get_selected_page (tab_view);
EphyWebView *tmp_webview = ephy_embed_get_web_view (EPHY_EMBED (page));
add_web_view_to_json (builder, tmp_webview);
} else {
- for (int i = 0; i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); i++) {
- GtkWidget *page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i);
+ for (int i = 0; i < ephy_tab_view_get_n_pages (tab_view); i++) {
+ GtkWidget *page = ephy_tab_view_get_nth_page (tab_view, i);
EphyWebView *tmp_webview = ephy_embed_get_web_view (EPHY_EMBED (page));
add_web_view_to_json (builder, tmp_webview);
diff --git a/src/webextension/ephy-web-extension-manager.c b/src/webextension/ephy-web-extension-manager.c
index 4208c50d2..c88351bf9 100644
--- a/src/webextension/ephy-web-extension-manager.c
+++ b/src/webextension/ephy-web-extension-manager.c
@@ -288,9 +288,8 @@ ephy_web_extension_manager_update_location_entry (EphyWebExtensionManager *self,
{
GtkWidget *title_widget;
EphyLocationEntry *lentry;
- GtkWidget *notebook = ephy_window_get_notebook (EPHY_WINDOW (window));
- int current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
- GtkWidget *page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), current_page);
+ EphyTabView *tab_view = ephy_window_get_tab_view (EPHY_WINDOW (window));
+ GtkWidget *page = ephy_tab_view_get_selected_page (tab_view);
EphyWebView *web_view;
if (!page)
@@ -557,14 +556,15 @@ ephy_web_extension_manager_add_web_extension_to_webview (EphyWebExtensionManager
}
static void
-page_added_cb (GtkNotebook *notebook,
- GtkWidget *child,
- guint page_num,
- gpointer user_data)
+page_attached_cb (EphyTabView *tab_view,
+ HdyTabPage *page,
+ gint position,
+ gpointer user_data)
{
EphyWebExtension *web_extension = EPHY_WEB_EXTENSION (user_data);
+ GtkWidget *child = hdy_tab_page_get_child (page);
EphyWebView *web_view = ephy_embed_get_web_view (EPHY_EMBED (child));
- EphyWindow *window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (notebook)));
+ EphyWindow *window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab_view)));
EphyWebExtensionManager *self = ephy_shell_get_web_extension_manager (ephy_shell_get_default ());
@@ -752,14 +752,14 @@ ephy_web_extension_manager_add_web_extension_to_window (EphyWebExtensionManager
EphyWebExtension *web_extension,
EphyWindow *window)
{
- GtkWidget *notebook = ephy_window_get_notebook (EPHY_WINDOW (window));
+ EphyTabView *tab_view = ephy_window_get_tab_view (EPHY_WINDOW (window));
if (!ephy_web_extension_manager_is_active (self, web_extension))
return;
/* Add page actions and add content script */
- for (int i = 0; i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); i++) {
- GtkWidget *page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i);
+ for (int i = 0; i < ephy_tab_view_get_n_pages (tab_view); i++) {
+ GtkWidget *page = ephy_tab_view_get_nth_page (tab_view, i);
EphyWebView *web_view = ephy_embed_get_web_view (EPHY_EMBED (page));
ephy_web_extension_manager_add_web_extension_to_webview (self, web_extension, window, web_view);
@@ -772,7 +772,7 @@ ephy_web_extension_manager_add_web_extension_to_window (EphyWebExtensionManager
}
ephy_web_extension_manager_update_location_entry (self, window);
- g_signal_connect_object (notebook, "page-added", G_CALLBACK (page_added_cb), web_extension, 0);
+ g_signal_connect_object (tab_view, "page-attached", G_CALLBACK (page_attached_cb), web_extension, 0);
}
static gboolean
@@ -809,14 +809,14 @@ ephy_web_extension_manager_remove_web_extension_from_window (EphyWebExtensionMan
EphyWebExtension *web_extension,
EphyWindow *window)
{
- GtkWidget *notebook = ephy_window_get_notebook (EPHY_WINDOW (window));
+ EphyTabView *tab_view = ephy_window_get_tab_view (EPHY_WINDOW (window));
GtkWidget *browser_action_widget;
if (ephy_web_extension_manager_is_active (self, web_extension))
return;
- for (int i = 0; i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); i++) {
- GtkWidget *page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i);
+ for (int i = 0; i < ephy_tab_view_get_n_pages (tab_view); i++) {
+ GtkWidget *page = ephy_tab_view_get_nth_page (tab_view, i);
EphyWebView *web_view = ephy_embed_get_web_view (EPHY_EMBED (page));
ephy_web_extension_manager_remove_web_extension_from_webview (self, web_extension, window, web_view);
@@ -829,7 +829,7 @@ ephy_web_extension_manager_remove_web_extension_from_window (EphyWebExtensionMan
ephy_web_extension_manager_update_location_entry (self, window);
- g_signal_handlers_disconnect_by_data (notebook, web_extension);
+ g_signal_handlers_disconnect_by_data (tab_view, web_extension);
}
gboolean
diff --git a/tests/ephy-shell-test.c b/tests/ephy-shell-test.c
index c47035da9..6d3255cad 100644
--- a/tests/ephy-shell-test.c
+++ b/tests/ephy-shell-test.c
@@ -168,19 +168,12 @@ test_ephy_shell_tab_load (void)
gtk_widget_destroy (window);
}
-static int
-get_notebook_page_num (GtkWidget *notebook,
- EphyEmbed *embed)
-{
- return gtk_notebook_page_num (GTK_NOTEBOOK (notebook), GTK_WIDGET (embed));
-}
-
static void
test_ephy_shell_tab_append (void)
{
EphyShell *ephy_shell;
GtkWidget *window;
- GtkWidget *notebook;
+ EphyTabView *tab_view;
EphyEmbed *embed1;
EphyEmbed *embed2;
@@ -190,37 +183,37 @@ test_ephy_shell_tab_append (void)
ephy_shell = ephy_shell_get_default ();
window = GTK_WIDGET (ephy_window_new ());
- notebook = ephy_window_get_notebook (EPHY_WINDOW (window));
+ tab_view = ephy_window_get_tab_view (EPHY_WINDOW (window));
embed1 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), NULL,
EPHY_NEW_TAB_DONT_SHOW_WINDOW);
- g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed1), ==, 0);
embed2 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed1,
EPHY_NEW_TAB_DONT_SHOW_WINDOW);
- g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
- g_assert_cmpint (get_notebook_page_num (notebook, embed2), ==, 1);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed1), ==, 0);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed2), ==, 1);
embed3 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed1,
EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_APPEND_AFTER);
- g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
- g_assert_cmpint (get_notebook_page_num (notebook, embed3), ==, 1);
- g_assert_cmpint (get_notebook_page_num (notebook, embed2), ==, 2);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed1), ==, 0);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed3), ==, 1);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed2), ==, 2);
embed4 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed1,
EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_APPEND_LAST);
- g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
- g_assert_cmpint (get_notebook_page_num (notebook, embed3), ==, 1);
- g_assert_cmpint (get_notebook_page_num (notebook, embed2), ==, 2);
- g_assert_cmpint (get_notebook_page_num (notebook, embed4), ==, 3);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed1), ==, 0);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed3), ==, 1);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed2), ==, 2);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed4), ==, 3);
embed5 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), embed3,
EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_APPEND_AFTER);
- g_assert_cmpint (get_notebook_page_num (notebook, embed1), ==, 0);
- g_assert_cmpint (get_notebook_page_num (notebook, embed3), ==, 1);
- g_assert_cmpint (get_notebook_page_num (notebook, embed5), ==, 2);
- g_assert_cmpint (get_notebook_page_num (notebook, embed2), ==, 3);
- g_assert_cmpint (get_notebook_page_num (notebook, embed4), ==, 4);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed1), ==, 0);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed3), ==, 1);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed5), ==, 2);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed2), ==, 3);
+ g_assert_cmpint (ephy_tab_view_get_page_index (tab_view, embed4), ==, 4);
gtk_widget_destroy (window);
}
@@ -231,7 +224,7 @@ test_ephy_shell_tab_from_external (void)
{
EphyShell *ephy_shell;
GtkWidget *window;
- GtkWidget *notebook;
+ EphyTabView *tab_view;
GMainLoop *loop;
EphyEmbed *embed;
@@ -247,7 +240,7 @@ test_ephy_shell_tab_from_external (void)
embed = ephy_shell_new_tab (ephy_shell, NULL, NULL, "about:epiphany",
EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_OPEN_PAGE);
window = gtk_widget_get_toplevel (GTK_WIDGET (embed));
- notebook = ephy_window_get_notebook (EPHY_WINDOW (window));
+ tab_view = ephy_window_get_tab_view (EPHY_WINDOW (window));
/* This embed should be used in load-from-external. */
embed2 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), NULL, NULL,
@@ -268,7 +261,7 @@ test_ephy_shell_tab_from_external (void)
/* This one should fail, because the active embed is not @embed2. */
ephy_test_utils_check_ephy_embed_address (embed2, "ephy-about:overview");
- g_assert_cmpint (gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)), ==, 0);
+ g_assert_cmpint (ephy_tab_view_get_selected_index (tab_view), ==, 0);
loop = ephy_test_utils_setup_ensure_web_views_are_loaded ();
@@ -281,11 +274,11 @@ test_ephy_shell_tab_from_external (void)
ephy_test_utils_check_ephy_embed_address (embed2, "ephy-about:overview");
ephy_test_utils_check_ephy_embed_address (embed4, "ephy-about:applications");
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 1);
+ ephy_tab_view_select_nth_page (tab_view, 1);
/* This should work */
ephy_test_utils_check_ephy_embed_address (embed2, "ephy-about:overview");
- g_assert_cmpint (gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)), ==, 1);
+ g_assert_cmpint (ephy_tab_view_get_selected_index (tab_view), ==, 1);
loop = ephy_test_utils_setup_wait_until_load_is_committed (ephy_embed_get_web_view (embed2));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]