Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions WWW-WebKit/Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.11 2017-07-25 11:11:00 CET
* Make window size configurable by using attributes
* Croak if an object is dragged out of the window/screen

0.10 2016-12-13 16:45:00 CET
* Fix compatibility with libwebkitgtk-3_0-0 version > 2.4.8

Expand Down
52 changes: 41 additions & 11 deletions WWW-WebKit/lib/WWW/WebKit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use XSLoader;
use English '-no_match_vars';
use POSIX qw<F_SETFD F_GETFD FD_CLOEXEC>;

our $VERSION = '0.10';
our $VERSION = '0.11';

use constant DOM_TYPE_ELEMENT => 1;
use constant ORDERED_NODE_SNAPSHOT_TYPE => 7;
Expand Down Expand Up @@ -78,6 +78,18 @@ has scrolled_view => (
}
);

has window_width => (
is => 'ro',
isa => 'Int',
default => 1600,
);

has window_height => (
is => 'ro',
isa => 'Int',
default => 1200,
);

has window => (
is => 'ro',
isa => 'Gtk3::Window',
Expand All @@ -91,7 +103,7 @@ has window => (

my $win = Gtk3::Window->new;
$win->set_title($self->window_title);
$win->set_default_size(1600, 1200);
$win->set_default_size($self->window_width, $self->window_height);
$win->add($sw);

return $win;
Expand Down Expand Up @@ -315,7 +327,8 @@ sub setup_xvfb {

open STDERR, '>', '/dev/null' or die "Cant' open STDERR: $!";

system ("Xvfb -nolisten tcp -terminate -screen 0 1600x1200x24 -displayfd $writefd &");
my $screen_dimensions = join 'x', $self->window_width, $self->window_height, 24;
system ("Xvfb -nolisten tcp -terminate -screen 0 $screen_dimensions -displayfd $writefd &");

open STDERR, '>&', $stderr or die "Can't open STDERR: $!";

Expand Down Expand Up @@ -1065,21 +1078,23 @@ sub wait_for_condition {
return $result;
}

=head3 native_drag_and_drop_to_position($source, $target_x, $target_y, $options)
=head3 native_drag_and_drop_to_position($source_locator, $target_x, $target_y, $options)

Drag and drop $source to position ($target_x and $target_y).
Drag source element and drop it to position $target_x, $target_y.

=cut

sub native_drag_and_drop_to_position {
my ($self, $source, $target_x, $target_y, $options) = @_;
my ($self, $source_locator, $target_x, $target_y, $options) = @_;
$self->check_window_bounds($target_x, $target_y, "target");

my $steps = $options->{steps} // 5;
my $step_delay = $options->{step_delay} // 150; # ms
$self->event_send_delay($options->{event_send_delay}) if $options->{event_send_delay};

$source = $self->resolve_locator($source);
my $source = $self->resolve_locator($source_locator);
my ($source_x, $source_y) = $self->get_center_screen_position($source);
$self->check_window_bounds($source_x, $source_y, "source '$source_locator'");

my ($delta_x, $delta_y) = ($target_x - $source_x, $target_y - $source_y);
my ($step_x, $step_y) = (int($delta_x / $steps), int($delta_y / $steps));
Expand All @@ -1105,9 +1120,9 @@ sub native_drag_and_drop_to_position {
$self->process_page_load;
}

=head3 native_drag_and_drop_to_object($source, $target, $options)
=head3 native_drag_and_drop_to_object($source_locator, $target_locator, $options)

Drag and drop $source to $target.
Drag source element and drop it into target element.

=cut

Expand All @@ -1124,16 +1139,18 @@ sub native_drag_and_drop_to_object {
my $source = $self->resolve_locator($source_locator)
or croak "did not find element $source_locator";
my ($x, $y) = $self->get_center_screen_position($source);
$self->check_window_bounds($x, $y, "source '$source_locator'");

$self->pause($step_delay);
$self->move_mouse_abs($x, $y);
$self->pause($step_delay);
$self->press_mouse_button(1);
$self->pause($step_delay);

foreach (0 .. $steps - 1) {
my ($target_x, $target_y) = $self->get_center_screen_position($target);
my ($target_x, $target_y) = $self->get_center_screen_position($target);
$self->check_window_bounds($target_x, $target_y, "target '$target_locator'");

foreach (0 .. $steps - 1) {
my $delta_x = $target_x - $x;
my $delta_y = $target_y - $y;
my $step_x = int($delta_x / ($steps - $_));
Expand All @@ -1157,6 +1174,19 @@ sub native_drag_and_drop_to_object {
$self->process_page_load;
}

sub check_window_bounds {
my ($self, $x, $y, $obj_description) = @_;

my ($max_x, $max_y) = ($self->window_width, $self->window_height);
if ($x > $max_x or $y > $max_y) {
croak
"$obj_description out of bounds (position: $x, $y - window bounds: $max_x x $max_y). "
. "Raise window_width/window_height!"
}

return 1;
}

sub move_mouse_abs {
my ($self, $x, $y) = @_;

Expand Down