Skip to content

Commit

Permalink
Move offsetPosition to closer to where it's used
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed May 15, 2024
1 parent 4a64fbf commit b2a362a
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions common/element_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,6 @@ func (h *ElementHandle) defaultTimeout() time.Duration {
return h.frame.manager.timeoutSettings.timeout()
}

func (h *ElementHandle) offsetPosition(apiCtx context.Context, offset *Position) (*Position, error) {
fn := `
(node, injected) => {
return injected.getElementBorderWidth(node);
}
`
opts := evalOptions{
forceCallable: true,
returnByValue: true,
}
result, err := h.evalWithScript(apiCtx, opts, fn)
if err != nil {
return nil, err
}

var border struct{ Top, Left float64 }
if err := convert(result, &border); err != nil {
return nil, fmt.Errorf("converting result (%v of type %t) to border: %w", result, result, err)
}

box := h.BoundingBox()
if box == nil || (border.Left == 0 && border.Top == 0) {
return nil, errorFromDOMError("error:notvisible")
}

// Make point relative to the padding box to align with offsetX/offsetY.
return &Position{
X: box.X + border.Left + offset.X,
Y: box.Y + border.Top + offset.Y,
}, nil
}

// AsElement returns this element handle.
func (h *ElementHandle) AsElement() *ElementHandle {
return h
Expand Down Expand Up @@ -1485,6 +1453,38 @@ func (h *ElementHandle) scrollRectIntoViewIfNeeded(apiCtx context.Context, rect
return err //nolint:wrapcheck
}

func (h *ElementHandle) offsetPosition(apiCtx context.Context, offset *Position) (*Position, error) {
fn := `
(node, injected) => {
return injected.getElementBorderWidth(node);
}
`
opts := evalOptions{
forceCallable: true,
returnByValue: true,
}
result, err := h.evalWithScript(apiCtx, opts, fn)
if err != nil {
return nil, err
}

var border struct{ Top, Left float64 }
if err := convert(result, &border); err != nil {
return nil, fmt.Errorf("converting result (%v of type %t) to border: %w", result, result, err)
}

box := h.BoundingBox()
if box == nil || (border.Left == 0 && border.Top == 0) {
return nil, errorFromDOMError("error:notvisible")
}

// Make point relative to the padding box to align with offsetX/offsetY.
return &Position{
X: box.X + border.Left + offset.X,
Y: box.Y + border.Top + offset.Y,
}, nil
}

func (h *ElementHandle) clickablePoint() (*Position, error) {
var (
quads []dom.Quad
Expand Down

0 comments on commit b2a362a

Please sign in to comment.