Skip to content

Commit

Permalink
[java] make the action movement methods specify the button number
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed May 27, 2022
1 parent 190a8fb commit d0a0df9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
5 changes: 2 additions & 3 deletions java/src/org/openqa/selenium/interactions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import static org.openqa.selenium.interactions.PointerInput.MouseButton.LEFT;
import static org.openqa.selenium.interactions.PointerInput.MouseButton.RIGHT;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -420,9 +422,6 @@ public Actions moveToElement(WebElement target, int xOffset, int yOffset) {
action.addAction(new MoveToOffsetAction(jsonMouse, (Locatable) target, xOffset, yOffset));
}

// Of course, this is the offset from the centre of the element. We have no idea what the width
// and height are once we execute this method.
LOG.info("When using the W3C Action commands, offsets are from the element's in-view center point");
return moveInTicks(target, xOffset, yOffset);
}

Expand Down
32 changes: 29 additions & 3 deletions java/src/org/openqa/selenium/interactions/PointerInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,32 @@ public Interaction createPointerDown(int button) {
return new PointerPress(this, PointerPress.Direction.DOWN, button);
}

/**
* @deprecated always use the method with the button
*/
@Deprecated
public Interaction createPointerDown(PointerEventProperties eventProperties) {
return new PointerPress(this, PointerPress.Direction.DOWN, eventProperties);
return createPointerDown(0, eventProperties);
}

public Interaction createPointerDown(int button, PointerEventProperties eventProperties) {
return new PointerPress(this, PointerPress.Direction.DOWN, button, eventProperties);
}

public Interaction createPointerUp(int button) {
return new PointerPress(this, PointerPress.Direction.UP, button);
}

/**
* @deprecated always use the method with the button
*/
@Deprecated
public Interaction createPointerUp(PointerEventProperties eventProperties) {
return new PointerPress(this, PointerPress.Direction.UP, eventProperties);
return createPointerUp(0, eventProperties);
}

public Interaction createPointerUp(int button, PointerEventProperties eventProperties) {
return new PointerPress(this, PointerPress.Direction.UP, button, eventProperties);
}

private static class PointerPress extends Interaction implements Encodable {
Expand All @@ -110,9 +126,17 @@ public PointerPress(InputSource source, Direction direction, int button) {
this.eventProperties = new PointerEventProperties();
}

/**
* @deprecated always use the constructor with the button
*/
@Deprecated
public PointerPress(InputSource source, Direction direction, PointerEventProperties eventProperties) {
this(source, direction, 0, eventProperties);
}

public PointerPress(InputSource source, Direction direction, int button, PointerEventProperties eventProperties) {
super(source);
this.button = 0;
this.button = button;
this.eventProperties = Require.nonNull("pointer event properties", eventProperties);
this.direction = Require.nonNull("Direction of press", direction);
}
Expand Down Expand Up @@ -212,6 +236,8 @@ public enum MouseButton {
LEFT(0),
MIDDLE(1),
RIGHT(2),
BACK(3),
FORWARD(4),
;

private final int button;
Expand Down

0 comments on commit d0a0df9

Please sign in to comment.