Skip to content

Commit

Permalink
Feature/MontFerret#221 mouse events (MontFerret#237)
Browse files Browse the repository at this point in the history
* Initial work

* Added MoveMouseByXY and ScrollByXY

* Fixed liniting issues
  • Loading branch information
ziflex authored and Владимир Фетисов committed Apr 10, 2019
1 parent 5320e5d commit 7e530d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
24 changes: 23 additions & 1 deletion pkg/drivers/cdp/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (doc *HTMLDocument) SelectBySelector(ctx context.Context, selector values.S
return nil, core.TypeError(types.Array, res.Type())
}

func (doc *HTMLDocument) HoverBySelector(ctx context.Context, selector values.String) error {
func (doc *HTMLDocument) MoveMouseBySelector(ctx context.Context, selector values.String) error {
err := doc.ScrollBySelector(ctx, selector)

if err != nil {
Expand Down Expand Up @@ -519,6 +519,13 @@ func (doc *HTMLDocument) HoverBySelector(ctx context.Context, selector values.St
)
}

func (doc *HTMLDocument) MoveMouseByXY(ctx context.Context, x, y values.Float) error {
return doc.client.Input.DispatchMouseEvent(
ctx,
input.NewDispatchMouseEventArgs("mouseMoved", float64(x), float64(y)),
)
}

func (doc *HTMLDocument) WaitForSelector(ctx context.Context, selector values.String) error {
task := events.NewEvalWaitTask(
doc.client,
Expand Down Expand Up @@ -863,6 +870,21 @@ func (doc *HTMLDocument) ScrollBySelector(ctx context.Context, selector values.S
return err
}

func (doc *HTMLDocument) ScrollByXY(ctx context.Context, x, y values.Float) error {
_, err := eval.Eval(ctx, doc.client, fmt.Sprintf(`
window.scrollBy({
top: %s,
left: %s,
behavior: 'instant'
});
`,
eval.ParamFloat(float64(x)),
eval.ParamFloat(float64(y)),
), false, false)

return err
}

func (doc *HTMLDocument) handlePageLoad(ctx context.Context, _ interface{}) {
doc.Lock()
defer doc.Unlock()
Expand Down
16 changes: 12 additions & 4 deletions pkg/drivers/http/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ func (doc *HTMLDocument) SelectBySelector(_ context.Context, _ values.String, _
return nil, core.ErrNotSupported
}

func (doc *HTMLDocument) HoverBySelector(_ context.Context, _ values.String) error {
return core.ErrNotSupported
}

func (doc *HTMLDocument) PrintToPDF(_ context.Context, _ drivers.PDFParams) (values.Binary, error) {
return nil, core.ErrNotSupported
}
Expand All @@ -213,6 +209,18 @@ func (doc *HTMLDocument) ScrollBySelector(_ context.Context, _ values.String) er
return core.ErrNotSupported
}

func (doc *HTMLDocument) ScrollByXY(_ context.Context, _, _ values.Float) error {
return core.ErrNotSupported
}

func (doc *HTMLDocument) MoveMouseBySelector(_ context.Context, _ values.String) error {
return core.ErrNotSupported
}

func (doc *HTMLDocument) MoveMouseByXY(_ context.Context, _, _ values.Float) error {
return core.ErrNotSupported
}

func (doc *HTMLDocument) WaitForNavigation(_ context.Context) error {
return core.ErrNotSupported
}
Expand Down

0 comments on commit 7e530d0

Please sign in to comment.