EV-WebKit

 view release on metacpan or  search on metacpan

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

# dispatches mouse events to one and firing them here would let a test drive
# something a person could not.
sub click {
    $_[0]->_call_js(
        'const el = window.__evwk.get(A.id, A.epoch);'
      . 'const r = el.getBoundingClientRect();'
      . 'const at = { bubbles:true, cancelable:true, composed:true, view:window,'
      . '             pointerType:"mouse", pointerId:1, isPrimary:true, button:0,'
      . '             clientX: r.left + r.width/2, clientY: r.top + r.height/2 };'
      . 'const off = el.disabled === true'
      . '         || !!(el.closest && el.closest("fieldset[disabled]") && !el.closest("legend"));'
      . 'if (!off) {'
      . '  const P = window.PointerEvent || MouseEvent;'
      . '  el.dispatchEvent(new P("pointerdown", {...at, buttons:1}));'
      . '  el.dispatchEvent(new MouseEvent("mousedown", {...at, buttons:1}));'
      . '  el.dispatchEvent(new P("pointerup",   {...at, buttons:0}));'
      . '  el.dispatchEvent(new MouseEvent("mouseup",   {...at, buttons:0}));'
      . '}'
      # click() last, and unconditionally: it is what activates a link or submits
      # a form, and on a disabled control the engine makes it the no-op it should be.
      . 'el.click();'



( run in 1.192 second using v1.01-cache-2.11-cpan-364913b4093 )