summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-12 14:32:23 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-12 14:32:23 (EDT)
commit76e79c399f9f94f401e9021b1f8780f2d625400d (patch)
treefc5b9bbe7cbfbac54fbd73ee3e0bc290634ec90e /src
parent81c8f142f03fc304258eb671df9a92b89ecefc46 (diff)
downloadmarquee-76e79c399f9f94f401e9021b1f8780f2d625400d.zip
marquee-76e79c399f9f94f401e9021b1f8780f2d625400d.tar.gz
marquee-76e79c399f9f94f401e9021b1f8780f2d625400d.tar.bz2
MqTabChrome: Use MqFindToolbar
Diffstat (limited to 'src')
-rw-r--r--src/tab-chrome.c210
-rw-r--r--src/tab-chrome.h43
2 files changed, 24 insertions, 229 deletions
diff --git a/src/tab-chrome.c b/src/tab-chrome.c
index f4d666c..fea7259 100644
--- a/src/tab-chrome.c
+++ b/src/tab-chrome.c
@@ -27,6 +27,7 @@
#include "tab-chrome.h"
#include "tab.h"
+#include "find-toolbar.h"
static void
back_clicked_cb(GtkButton G_GNUC_UNUSED *toolbutton, MqTabChrome *chrome)
@@ -343,9 +344,7 @@ zoom_in_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqTabChrome *chrome)
static void
find_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqTabChrome *chrome)
{
- gtk_revealer_set_reveal_child(GTK_REVEALER(chrome->find_revealer),
- TRUE);
- gtk_widget_grab_focus(chrome->find_search_entry);
+ mq_find_toolbar_reveal(MQ_FIND_TOOLBAR(chrome->find_toolbar));
gtk_widget_hide(chrome->menu_popover);
}
@@ -574,178 +573,6 @@ navigation_toolbar_new(MqTabChrome *chrome, const gchar *uri)
return GTK_WIDGET(navigation_toolbar);
}
-static void
-find_search(MqTabChrome *chrome, gboolean forward)
-{
- guint32 find_options;
-
- find_options = WEBKIT_FIND_OPTIONS_WRAP_AROUND;
- if (!chrome->find_match_case) {
- find_options |= WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE;
- }
- if (!forward) {
- find_options |= WEBKIT_FIND_OPTIONS_BACKWARDS;
- }
- webkit_find_controller_search(chrome->find_controller,
- gtk_entry_get_text(GTK_ENTRY(chrome->find_search_entry)),
- find_options, G_MAXUINT);
- chrome->find_searching = TRUE;
-}
-
-static void
-find_search_finished(MqTabChrome *chrome)
-{
- chrome->find_searching = FALSE;
- webkit_find_controller_search_finish(chrome->find_controller);
-}
-
-static void
-find_close(MqTabChrome *chrome)
-{
- gtk_revealer_set_reveal_child(GTK_REVEALER(chrome->find_revealer),
- FALSE);
- gtk_label_set_text(GTK_LABEL(chrome->find_matches_label), NULL);
- find_search_finished(chrome);
-}
-
-static void
-find_search_changed_cb(GtkSearchEntry G_GNUC_UNUSED *entry, MqTabChrome *chrome)
-{
- find_search(chrome, TRUE);
-}
-
-static gboolean
-find_search_key_press_event_cb(GtkSearchEntry G_GNUC_UNUSED *entry,
- GdkEventKey *event, MqTabChrome *chrome)
-{
- switch (event->keyval) {
- case GDK_KEY_Escape:
- find_close(chrome);
- return TRUE;
- case GDK_KEY_Return:
- case GDK_KEY_KP_Enter:
- case GDK_KEY_ISO_Enter:
- find_search(chrome, !(event->state & GDK_SHIFT_MASK));
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-static void
-find_prev_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqTabChrome *chrome)
-{
- /* Calling this method before webkit_find_controller_search() or
- * webkit_find_controller_count_matches() is a programming error. */
- if (chrome->find_searching) {
- webkit_find_controller_search_previous(chrome->find_controller);
- } else {
- find_search(chrome, FALSE);
- }
-}
-
-static void
-find_next_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqTabChrome *chrome)
-{
- /* Calling this method before webkit_find_controller_search() or
- * webkit_find_controller_count_matches() is a programming error. */
- if (chrome->find_searching) {
- webkit_find_controller_search_next(chrome->find_controller);
- } else {
- find_search(chrome, TRUE);
- }
-}
-
-static void
-find_match_case_toggled_cb(GtkToggleButton *toggle_button, MqTabChrome *chrome)
-{
- chrome->find_match_case = gtk_toggle_button_get_active(toggle_button);
- find_search(chrome, TRUE);
-}
-
-static void
-find_close_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqTabChrome *chrome)
-{
- find_close(chrome);
-}
-
-static GtkWidget *
-find_toolbar_new(MqTabChrome *chrome)
-{
- GtkWidget *close_button;
- GtkWidget *prev_button;
- GtkWidget *next_button;
- GtkWidget *match_case_button;
- GtkWidget *box;
-
- /* Search entry */
- chrome->find_search_entry = gtk_search_entry_new();
- g_signal_connect(chrome->find_search_entry, "search-changed",
- G_CALLBACK(find_search_changed_cb), chrome);
- g_signal_connect(chrome->find_search_entry, "key-press-event",
- G_CALLBACK(find_search_key_press_event_cb), chrome);
-
- /* Previous button */
- prev_button = gtk_button_new_from_icon_name("go-up",
- GTK_ICON_SIZE_BUTTON);
- gtk_widget_set_tooltip_text(prev_button, "Find previous occurrence");
- gtk_widget_set_can_focus(prev_button, FALSE);
- g_signal_connect(prev_button, "clicked",
- G_CALLBACK(find_prev_clicked_cb), chrome);
-
- /* Next button */
- next_button = gtk_button_new_from_icon_name("go-down",
- GTK_ICON_SIZE_BUTTON);
- gtk_widget_set_tooltip_text(next_button, "Find next occurrence");
- gtk_widget_set_can_focus(next_button, FALSE);
- g_signal_connect(next_button, "clicked",
- G_CALLBACK(find_next_clicked_cb), chrome);
-
- /* Case sensitivity button */
- match_case_button = gtk_toggle_button_new_with_label("Match case");
- gtk_widget_set_tooltip_text(match_case_button,
- "Search with case sensitivity");
- gtk_widget_set_can_focus(match_case_button, FALSE);
- g_signal_connect(match_case_button, "toggled",
- G_CALLBACK(find_match_case_toggled_cb), chrome);
-
- /* Matches label */
- chrome->find_matches_label = gtk_label_new(NULL);
-
- /* Close button */
- close_button = gtk_button_new_from_icon_name("window-close",
- GTK_ICON_SIZE_BUTTON);
- gtk_button_set_relief(GTK_BUTTON(close_button), GTK_RELIEF_NONE);
- gtk_widget_set_tooltip_text(close_button, "Close find bar");
- gtk_widget_set_can_focus(close_button, FALSE);
- g_signal_connect(close_button, "clicked",
- G_CALLBACK(find_close_clicked_cb), chrome);
-
- /* Box */
- box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_pack_start(GTK_BOX(box), chrome->find_search_entry,
- FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(box), prev_button, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(box), next_button, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(box), match_case_button, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(box), chrome->find_matches_label,
- FALSE, FALSE, 0);
- gtk_box_pack_end(GTK_BOX(box), close_button, FALSE, FALSE, 0);
-
- /* Revealer */
- chrome->find_revealer = gtk_revealer_new();
- gtk_revealer_set_transition_type(GTK_REVEALER(chrome->find_revealer),
- GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
- gtk_container_add(GTK_CONTAINER(chrome->find_revealer), box);
-
- chrome->find_match_case = FALSE;
- chrome->find_searching = FALSE;
- chrome->find_controller = webkit_web_view_get_find_controller(
- WEBKIT_WEB_VIEW(chrome->web_view));
-
- return chrome->find_revealer;
-}
-
MqTabChrome *
mq_tab_chrome_new(MqTab *tab, const gchar *uri)
{
@@ -930,29 +757,6 @@ back_forward_list_changed_cb(
}
static void
-find_found_text_cb(WebKitFindController G_GNUC_UNUSED *find_controller,
- guint match_count, MqTabChrome *chrome)
-{
- gchar *text;
-
- if (match_count == 1) {
- text = g_strdup("1 match");
- } else {
- text = g_strdup_printf("%u matches", match_count);
- }
- gtk_label_set_text(GTK_LABEL(chrome->find_matches_label), text);
- g_free(text);
-
-}
-
-static void
-find_failed_to_find_text_cb(WebKitFindController G_GNUC_UNUSED *find_controller,
- MqTabChrome *chrome)
-{
- gtk_label_set_text(GTK_LABEL(chrome->find_matches_label), "No matches");
-}
-
-static void
connect_web_view(MqTabChrome *chrome)
{
chrome->hovered_link_uri = NULL;
@@ -972,18 +776,14 @@ connect_web_view(MqTabChrome *chrome)
g_signal_connect(webkit_web_view_get_back_forward_list(
WEBKIT_WEB_VIEW(chrome->web_view)),
"changed", G_CALLBACK(back_forward_list_changed_cb), chrome);
-
- g_signal_connect(chrome->find_controller, "found-text",
- G_CALLBACK(find_found_text_cb), chrome);
- g_signal_connect(chrome->find_controller, "failed-to-find-text",
- G_CALLBACK(find_failed_to_find_text_cb), chrome);
}
void
mq_tab_chrome_set_web_view(MqTabChrome *chrome, MqWebView *web_view)
{
chrome->web_view = web_view;
- gtk_box_pack_start(GTK_BOX(chrome->container),
- find_toolbar_new(chrome), FALSE, FALSE, 0);
+ chrome->find_toolbar = mq_find_toolbar_new(web_view);
+ gtk_box_pack_start(GTK_BOX(chrome->container), chrome->find_toolbar,
+ FALSE, FALSE, 0);
connect_web_view(chrome);
}
diff --git a/src/tab-chrome.h b/src/tab-chrome.h
index 6547f20..2393650 100644
--- a/src/tab-chrome.h
+++ b/src/tab-chrome.h
@@ -31,30 +31,25 @@ typedef struct MqTabChrome MqTabChrome;
#include "web-view.h"
struct MqTabChrome {
- MqConfig *config;
- MqTab *tab;
- GtkWidget *container;
- GtkWidget *back_forward_box;
- GtkWidget *back_button;
- GtkWidget *forward_button;
- GtkWidget *stop_icon;
- GtkWidget *reload_icon;
- GtkToolItem *stop_reload_button;
- GtkWidget *uri_entry;
- PangoAttrList *hovered_link_style;
- gchar *hovered_link_uri;
- GtkWidget *find_revealer;
- GtkWidget *find_search_entry;
- GtkWidget *find_matches_label;
- gboolean find_match_case;
- gboolean find_searching;
- MqWebView *web_view;
- WebKitFindController *find_controller;
- gboolean load_failed;
- GtkWidget *back_forward_popover;
- gint back_items;
- GtkToolItem *menu_button;
- GtkWidget *menu_popover;
+ MqConfig *config;
+ MqTab *tab;
+ GtkWidget *container;
+ GtkWidget *back_forward_box;
+ GtkWidget *back_button;
+ GtkWidget *forward_button;
+ GtkWidget *stop_icon;
+ GtkWidget *reload_icon;
+ GtkToolItem *stop_reload_button;
+ GtkWidget *uri_entry;
+ PangoAttrList *hovered_link_style;
+ gchar *hovered_link_uri;
+ MqWebView *web_view;
+ GtkWidget *find_toolbar;
+ gboolean load_failed;
+ GtkWidget *back_forward_popover;
+ gint back_items;
+ GtkToolItem *menu_button;
+ GtkWidget *menu_popover;
};
MqTabChrome *