EV-WebKit

 view release on metacpan or  search on metacpan

lib/EV/WebKit/Element.pm  view on Meta::CPAN

    $el->clear($cb);

On an C<< <input> >> or C<< <textarea> >>, empties C<value> and dispatches
an C<input> event. On a contenteditable element, empties C<textContent>
instead and dispatches an C<input> event. On anything else, C<$err> is set
to an error mentioning "not editable".

=head2 focus

    $el->focus($cb);

Calls the node's C<focus()>.

=head2 submit

    $el->submit($cb);

Calls the native C<submit()> of the element's owning C<< <form> >>, or of
the element itself if it has no C<form> (e.g. calling C<submit> directly on
a C<< <form> >> element). This bypasses any C<onsubmit> handler and may
navigate the page. Resolves successfully even if there was nothing to
submit (a silent no-op).

=head2 select_option

    $el->select_option($value, $cb);   # $cb->($selected_value, $err)

Selects an C<< <option> >> of a C<< <select> >> by its C<value>, falling back
to matching the visible label when no value matches -- so an option whose
C<value> differs from what the page displays, such as
C<< <option value="b">Beta</option> >>, is still reachable by the text the
user sees. (An option with no C<value> attribute at all takes its value from
its own text, so it already matches on the first pass.) Fires C<input> and C<change> so page code bound to
those actually runs; assigning C<el.value> alone updates the DOM and leaves
application state stale. Errors if the element is not a C<< <select> >>, or if
no option matches.

=head2 check / uncheck

    $el->check($cb);          # ensure checked
    $el->check(0, $cb);       # ensure UNchecked
    $el->uncheck($cb);        # the same thing, spelled out

Sets a checkbox or radio to a definite state and resolves with that state.
Deliberately not C<click>: clicking B<toggles>, so calling it twice "to be
sure" silently undoes itself. These are idempotent -- already in the requested
state means no change and, like a real browser, B<no> C<change> event. Errors
if the element is not a checkbox or radio.

The single-argument form is read as a B<callback> if it is a code reference and
as the B<state> otherwise -- evaluated for truth, so a decoded-JSON boolean
works as well as a plain C<1> or C<0>. C<uncheck> has no state argument, so a
non-coderef there is a mistyped callback and croaks.

=head2 hover

    $el->hover($cb);

Dispatches the pointer/mouse sequence an entering cursor produces:
C<pointerover>/C<mouseover> (which bubble), then C<pointerenter>/C<mouseenter>
(which do not), then C<mousemove>, positioned at the element's centre. Menus
and tooltips listen for various of these, so dispatching only C<mouseover>
leaves a menu that opens on C<mouseenter> shut. These are synthetic events:
C<isTrusted> is false, so a page that checks it is not fooled.

=head2 box

    $el->box($cb);   # $cb->($box, $err)

The element's geometry as a hashref: C<x>, C<y>, C<width>, C<height>, C<top>,
C<left>, C<bottom>, C<right> -- viewport-relative, exactly as
C<getBoundingClientRect> gives them, which is what you want when comparing
against a screenshot -- plus C<page_x> and C<page_y>, the same origin with the
scroll offset added, for absolute document coordinates.

C<$box> is C<undef> for an element that is not rendered (C<display:none>, or
detached from the document). Such an element has an all-zero rect in every
browser, and returning that as a box would be a plausible-looking lie a caller
could divide by; ask L</is_visible> if that is the question.

For an element inside a frame the rect is relative to B<that frame's> viewport,
not the top-level one, since that is the only coordinate space the element's
own document has. Offsetting it into page coordinates would need the frame's
position, which is the parent document's to know.

=head2 frame_id

    my $id = $el->frame_id;

The id of the frame this handle is B<bound> to, or C<undef> if it is not bound
to one. Synchronous; the id itself is opaque and lives only as long as the frame
does.

Note what C<undef> does B<not> mean. Only the C<< frame => { url => ... } >>
form binds a handle to a frame; a handle reached through the selector form
(C<< frame => '#f' >>) is inside an iframe but reports C<undef>, exactly as a
main-frame handle does. So this tells you how the handle will be operated on,
not where the element lives -- it is not a test for "is this inside an iframe".
See L<EV::WebKit/"Addressing an iframe">.

=head2 scroll_into_view

    $el->scroll_into_view($cb);

Scrolls the element to the centre of the viewport. Worth doing before reading
around it: C<click> works on an off-screen element, but a page that reacts to
scroll position (lazy images, infinite scroll, sticky headers) will not have
done that work yet.

=head1 SEE ALSO

L<EV::WebKit>

=head1 AUTHOR

vividsnow

=head1 LICENSE

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.



( run in 1.212 second using v1.01-cache-2.11-cpan-60884a8df76 )