-
Notifications
You must be signed in to change notification settings - Fork 0
/
volo.h
170 lines (152 loc) · 6.14 KB
/
volo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (c) 2014 Josh Rickmar.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
#ifndef _VOLO_H
#define _VOLO_H
#include <array>
#include <vector>
#include <gtk.h>
#include <webkit.h>
#include <uri_entry.h>
namespace volo {
// browser_tab represents the widgets added to the browser's notebook. Note
// that there is an additional box which holds the tab's title and close button
// that is not owned by this struct.
struct browser_tab {
gtk::unique_ptr<webkit::web_view> wv;
gtk::unique_ptr<gtk::label> tab_title;
gtk::unique_ptr<gtk::button> tab_close;
browser_tab(const char *);
};
struct search_bar {
gtk::unique_ptr<gtk::search_bar> bar;
gtk::unique_ptr<gtk::search_entry> entry;
webkit::find_controller *controller;
search_bar();
void begin_searching(webkit::web_view&);
};
// browser represents the top level widget which creates the browser. It
// contains a navigation bar with buttons to move the current visable page
// back and forward in history and a URI entry to begin loading any other
// page. Multiple webpages are managed via a GTK notebook with tabs under
// the navigation bar.
//
// A browser will show no less than one tab at all times. Removing the last
// tab will close the browser.
class browser {
private:
std::vector<browser_tab> tabs;
gtk::unique_ptr<gtk::window> window;
gtk::unique_ptr<gtk::header_bar> navbar;
gtk::unique_ptr<gtk::box> histnav;
gtk::unique_ptr<gtk::button> back;
gtk::unique_ptr<gtk::button> fwd;
gtk::unique_ptr<gtk::button> new_tab;
gtk::unique_ptr<uri_entry> nav_entry;
gtk::unique_ptr<gtk::notebook> nb;
search_bar page_search{};
// Details about the currently shown page.
std::array<gtk::connection, 8> page_signals;
struct visable_tab {
unsigned int tab_index{0};
webkit::web_view *web_view{nullptr};
WebKitBackForwardList *bfl{nullptr};
visable_tab() {}
visable_tab(unsigned int n, webkit::web_view& wv) :
tab_index{n}, web_view{&wv}, bfl{wv.get_back_forward_list()} {}
} visable_tab;
public:
// Constructors to create the toplevel browser window widget. Multiple
// URIs (a "session") to open may be specified, while the default
// constructor will open a single tab to a single blank page.
browser() : browser{std::vector<const char *>{""}} {}
browser(const std::vector<const char *>&);
// open_new_tab creates a new tab, loading the specified resource, and
// adds it to the browser, appending the page to the end of the
// notebook. The notebook index is returned and may be used to switch
// view to the newly opened tab.
int open_new_tab(const char *);
// show_window calls the show method of the browser's window widget.
void show_window();
private:
void show_webview(unsigned int, webkit::web_view&);
void switch_page(unsigned int);
void update_histnav(webkit::web_view&);
// Slots (member functions)
void on_nav_entry_activate(uri_entry&);
void on_notebook_switch_page(gtk::notebook&, gtk::widget&, unsigned int);
void on_notebook_page_added(gtk::notebook&, gtk::widget&, unsigned int);
void on_notebook_page_removed(gtk::notebook&, gtk::widget&, unsigned int);
void on_notebook_page_reordered(gtk::notebook&, gtk::widget&, unsigned int);
void on_new_tab_clicked(gtk::button&);
bool on_window_key_press_event(gtk::window&, GdkEventKey&);
void on_window_destroy(gtk::window&);
void on_tab_close_clicked(gtk::button&);
void on_back_button_clicked(gtk::button&);
void on_fwd_button_clicked(gtk::button&);
void on_back_forward_list_changed(WebKitBackForwardList&, WebKitBackForwardListItem&,
gpointer);
void on_web_view_load_changed(webkit::web_view&, WebKitLoadEvent);
void on_web_view_notify_uri(webkit::web_view&, GParamSpec&);
void on_web_view_notify_title(webkit::web_view&, GParamSpec&);
void on_page_search_changed(gtk::search_entry&);
// Slots (static functions)
static void on_nav_entry_activate(uri_entry *entry, browser *b) {
return b->on_nav_entry_activate(*entry);
}
static void on_notebook_switch_page(gtk::notebook *notebook, gtk::widget *widget,
unsigned int page_num, browser *b) {
b->on_notebook_switch_page(*notebook, *widget, page_num);
}
static void on_notebook_page_added(gtk::notebook *notebook, gtk::widget *widget,
unsigned int page_num, browser *b) {
b->on_notebook_page_added(*notebook, *widget, page_num);
}
static void on_notebook_page_removed(gtk::notebook *notebook, gtk::widget *widget,
unsigned int page_num, browser *b) {
b->on_notebook_page_removed(*notebook, *widget, page_num);
}
static void on_notebook_page_reordered(gtk::notebook *notebook, gtk::widget *child,
unsigned int page_num, browser *b) {
b->on_notebook_page_reordered(*notebook, *child, page_num);
}
static void on_new_tab_clicked(gtk::button *button, browser *b) {
b->on_new_tab_clicked(*button);
}
static bool on_window_key_press_event(gtk::window *w, GdkEventKey *ev, browser *b) {
return b->on_window_key_press_event(*w, *ev);
}
static void on_window_destroy(gtk::window *w, browser *b) {
return b->on_window_destroy(*w);
}
static void on_tab_close_clicked(gtk::button *button, browser *b) {
b->on_tab_close_clicked(*button);
}
static void on_back_button_clicked(gtk::button *button, browser *b) {
b->on_back_button_clicked(*button);
}
static void on_fwd_button_clicked(gtk::button *button, browser *b) {
b->on_fwd_button_clicked(*button);
}
static void on_back_forward_list_changed(WebKitBackForwardList *button,
WebKitBackForwardListItem *item_added, gpointer items_removed, browser *b) {
b->on_back_forward_list_changed(*button, *item_added, items_removed);
}
static void on_web_view_load_changed(webkit::web_view *web_view,
WebKitLoadEvent load_event, browser *b) {
b->on_web_view_load_changed(*web_view, load_event);
}
static void on_web_view_notify_uri(webkit::web_view *web_view,
GParamSpec *param_spec, browser *b) {
b->on_web_view_notify_uri(*web_view, *param_spec);
}
static void on_web_view_notify_title(webkit::web_view *web_view,
GParamSpec *param_spec, browser *b) {
b->on_web_view_notify_title(*web_view, *param_spec);
}
static void on_page_search_changed(gtk::search_entry *entry, browser *b) {
b->on_page_search_changed(*entry);
}
};
} // namespace volo
#endif // _VOLO_H