Mozilla-DOM
view release on metacpan or search on metacpan
examples/BrowserObjects.pm view on Meta::CPAN
# This example demonstrates the History, Location, and Navigator
# browser objects (Window and Document being two others familiar
# from JavaScript). It also shows Screen, though I don't think
# that's really considered a "browser object".
#
# $CVSHeader: Mozilla-DOM/examples/BrowserObjects.pm,v 1.3 2007-06-06 21:46:56 slanning Exp $
package BrowserObjects;
use strict;
use warnings;
use Cwd 'getcwd';
use Glib qw(TRUE FALSE);
use Gtk2;
use Gtk2::MozEmbed '0.04';
use Mozilla::DOM '0.13'; # for History, Location, Navigator, Screen
use Glib::Object::Subclass Gtk2::Window::;
# Will set these to zero after they're displayed once,
# since their output is always the same.
my $shownavigator = 1;
my $showscreen = 1;
sub INIT_INSTANCE {
my $self = shift;
my $embed = Gtk2::MozEmbed->new();
# This handler dumps information on the browser objects.
$embed->signal_connect(net_stop => \&net_stop_cb);
# This one demonstrates History's `Back' method
# when you double click anywhere.
$embed->signal_connect(dom_mouse_dbl_click => \&dom_mouse_dbl_click_cb);
# An extra feature in this demo is allowing popup windows.
# (This also comes from pumzilla in Gtk2::MozEmbed.)
# Try commenting this out, then clicking on the link;
# nothing will happen.
$embed->signal_connect(new_window => sub {
my ($embed, $chrome) = @_;
my $newwin = BrowserObjects->new();
$newwin->set_default_size(600, 400);
$newwin->show_all();
# As usual, return the embedded widget, not the window
return $newwin->{_embed};
});
$self->add($embed);
my $cwd = getcwd();
$embed->load_url("file://$cwd/index2.html");
$self->{_embed} = $embed;
}
sub net_stop_cb {
my $embed = shift;
my $browser = $embed->get_nsIWebBrowser;
my $window = $browser->GetContentDOMWindow;
my $iid = Mozilla::DOM::WindowInternal->GetIID;
my $windowinternal = $window->QueryInterface($iid);
show_location($windowinternal);
show_history($windowinternal);
show_navigator($windowinternal) if $shownavigator;
show_screen($windowinternal) if $showscreen;
print "=========\n";
}
sub dom_mouse_dbl_click_cb {
my ($embed, $event) = @_;
my $browser = $embed->get_nsIWebBrowser;
my $window = $browser->GetContentDOMWindow;
my $iid = Mozilla::DOM::WindowInternal->GetIID;
my $windowinternal = $window->QueryInterface($iid);
my $history = $windowinternal->GetHistory;
$history->Back();
return FALSE;
}
## Helper functions
sub show_location {
my $windowinternal = shift;
my $location = $windowinternal->GetLocation;
( run in 0.880 second using v1.01-cache-2.11-cpan-364913b4093 )