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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
################################################################################
# _____ _
# |_ _| |_ ___
# | | | ' \/ -_)
# |_| |_||_\___|
# _ _ ____ _ _
# / \ _ __ ___| |_(_) ___ __ _ | _ \ _ __ ___ (_) ___ ___| |_
# / _ \ | '__/ __| __| |/ __/ _` | | |_) | '__/ _ \| |/ _ \/ __| __|
# / ___ \| | | (__| |_| | (_| (_| | | __/| | | (_) | | __/ (__| |_
# /_/ \_\_| \___|\__|_|\___\__,_| |_| |_| \___// |\___|\___|\__|
# |__/
# The Arctica Modular Remote Computing Framework
#
################################################################################
#
# Copyright (C) 2015-2016 The Arctica Project
# http://http://arctica-project.org/
#
# This code is dual licensed: strictly GPL-2 or AGPL-3+
#
# GPL-2
# -----
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
#
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# AGPL-3+
# -------
# This programm is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This programm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Copyright (C) 2015-2016 Guangzhou Nianguan Electronics Technology Co.Ltd.
# <opensource@gznianguan.com>
# Copyright (C) 2015-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
################################################################################
package Arctica::Browser::Overlay::WebView;
use strict;
use Gtk3;
use Glib 'TRUE', 'FALSE';
use Gtk3::WebKit;
use Data::Dumper;
# Be very selective about what (if any) gets exported by default:
our @EXPORT = qw();
# And be mindful of what we let the caller request, too:
our @EXPORT_OK = qw( );
sub new {
my $class_name = $_[0];
my $related_toolbar = $_[1];
my $self = {
isArctica => 1,
aobject_name => "browser_webview",
};
bless($self, $class_name);
if ($related_toolbar) {
if ($related_toolbar->{'aobject_name'} eq "browser_toolbar") {
$self->{'toolbar'} = $related_toolbar;
$related_toolbar->{'webview'} = $self;
} else {
die("Thats not a toolbar you're trying to pass of as one, is it?");
}
} else {
$related_toolbar = FALSE;
}
$self->_gen_webview_main;
return $self;
}
sub return_webview {
my $self = $_[0];
if ($self->{'_gtk'}{'webview'}{'main_container'}) {
return $self->{'_gtk'}{'webview'}{'main_container'};
} else {
die("Can't return a webview that does not exist, can we?");
}
}
sub _gen_webview_main {
my $self = $_[0];
$self->{'_gtk'}{'webview'}{'main_container'} = Gtk3::Overlay->new();
$self->{'_gtk'}{'webview'}{'thewebview'} = Gtk3::WebKit::WebView->new();
$self->{'_gtk'}{'webview'}{'thewebview'}->load_uri("http://duckduckgo.com/");#
$self->{'_gtk'}{'webview'}{'scroller'} = Gtk3::ScrolledWindow->new();
$self->{'_gtk'}{'webview'}{'scroller'}->add($self->{'_gtk'}{'webview'}{'thewebview'});
$self->{'_gtk'}{'webview'}{'main_container'}->add($self->{'_gtk'}{'webview'}{'scroller'});
$self->{'_gtk'}{'webview'}{'bottom_overlay_text'} = Gtk3::Label->new();
$self->{'_gtk'}{'webview'}{'bottom_overlay_text'}->set_halign('start');
$self->{'_gtk'}{'webview'}{'bottom_overlay_text'}->set_valign('end');
$self->{'_gtk'}{'webview'}{'main_container'}->add_overlay($self->{'_gtk'}{'webview'}{'bottom_overlay_text'});
$self->{'_gtk'}{'webview'}{'thewebview'}->signal_connect( 'hovering-over-link' => sub {$self->_sigfunc_webview_hover_over_link($_[2]);}, undef );
$self->{'_gtk'}{'webview'}{'thewebview'}->signal_connect( 'notify::load-status' => sub {$self->_sigfunc_webview_notify_load_status;}, undef );
$self->{'_gtk'}{'webview'}{'thewebview'}->signal_connect( 'notify::progress' => sub {$self->_sigfunc_webview_notify_progress;}, undef );
# $self->{'_gtk'}{'webview'}{'thewebview'}->signal_connect( 'notify::title' => sub {} , undef );
}
sub ext_sigfunc {
my $self = $_[0];
my $func = $_[1];
my $func_data = $_[2];
# print "WEBVIEW SIGFUNC:\t$_[1]\n";
# print Dumper($_[2]);
if ($func eq "reload") {
$self->{'_gtk'}{'webview'}{'thewebview'}->reload();
} elsif ($func eq "stop") {
$self->{'_gtk'}{'webview'}{'thewebview'}->stop_loading();
} elsif ($func eq "load_uri") {
$self->{'_gtk'}{'webview'}{'thewebview'}->load_uri($func_data);
} elsif ($func eq "history_back") {
$self->{'_gtk'}{'webview'}{'thewebview'}->go_back;
} elsif ($func eq "history_forward") {
$self->{'_gtk'}{'webview'}{'thewebview'}->go_forward;
}
}
sub _sigfunc_webview_notify_load_status {
my $self = $_[0];
my $status = $self->{'_gtk'}{'webview'}{'thewebview'}->get('load_status');
if ($status eq 'committed') {
my $uri = $self->{'_gtk'}{'webview'}{'thewebview'}->get_uri();
# if ($uri) {print "URI:\t$uri\n";}
$self->{'toolbar'}->ext_sigfunc('load_committed',$uri)
} elsif ($status eq 'finished') {
my $uri = $self->{'_gtk'}{'webview'}{'thewebview'}->get_uri();
$self->{'toolbar'}->ext_sigfunc('load_finished',$uri)
} else {
# print "WTF LS:\t$status\n";
}
}
sub _sigfunc_webview_notify_progress {
my $self = $_[0];
my $progress = $self->{'_gtk'}{'webview'}{'thewebview'}->get('progress');
if ($progress) {
$self->{'toolbar'}->ext_sigfunc('load_progress',sprintf("%.2f", $progress));
}
}
sub _sigfunc_webview_hover_over_link {
my $self = $_[0];
my $link = $_[1];
if ($link) {
$self->{'_gtk'}{'webview'}{'bottom_overlay_text'}->set_text($link);
} else {
$self->{'_gtk'}{'webview'}{'bottom_overlay_text'}->set_text('');
}
}
1;
|