github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/html/mouse_xy.go (about)

     1  package html
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/MontFerret/ferret/pkg/drivers"
     7  	"github.com/MontFerret/ferret/pkg/runtime/core"
     8  	"github.com/MontFerret/ferret/pkg/runtime/values"
     9  	"github.com/MontFerret/ferret/pkg/runtime/values/types"
    10  )
    11  
    12  // MOUSE moves mouse by given coordinates.
    13  // @param {HTMLDocument} document - HTML document.
    14  // @param {Int|Float} x - X coordinate.
    15  // @param {Int|Float} y - Y coordinate.
    16  func MouseMoveXY(ctx context.Context, args ...core.Value) (core.Value, error) {
    17  	err := core.ValidateArgs(args, 3, 3)
    18  
    19  	if err != nil {
    20  		return values.None, err
    21  	}
    22  
    23  	doc, err := drivers.ToDocument(args[0])
    24  
    25  	if err != nil {
    26  		return values.None, err
    27  	}
    28  
    29  	err = core.ValidateType(args[1], types.Int, types.Float)
    30  
    31  	if err != nil {
    32  		return values.None, err
    33  	}
    34  
    35  	err = core.ValidateType(args[2], types.Int, types.Float)
    36  
    37  	if err != nil {
    38  		return values.None, err
    39  	}
    40  
    41  	x := values.ToFloat(args[0])
    42  	y := values.ToFloat(args[1])
    43  
    44  	return values.None, doc.MoveMouseByXY(ctx, x, y)
    45  }