Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions java/client/src/org/openqa/selenium/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ java_library(name = 'core',
'ContextAware.java',
'HasCapabilities.java',
'JavascriptExecutor.java',
'DeviceRotation.java',
'Keys.java',
'OutputType.java',
'Proxy.java',
Expand Down Expand Up @@ -60,6 +61,7 @@ java_library(name = 'core',
'//java/client/src/org/openqa/selenium/interactions:exceptions',
'//java/client/src/org/openqa/selenium/logging:api',
'//java/client/src/org/openqa/selenium/security:security',
'//third_party/java/guava:guava',
],
visibility = [
'//java/client/src/org/openqa/selenium/interactions:interactions',
Expand Down
81 changes: 81 additions & 0 deletions java/client/src/org/openqa/selenium/DeviceRotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium;

import java.util.Map;
import com.google.common.collect.ImmutableMap;

public class DeviceRotation {
//Default orientation is portrait
private int x = 0;
private int y = 0;
private int z = 0;

public DeviceRotation(int x, int y, int z) {
this.validateParameters(x, y, z);
this.x = x;
this.y = y;
this.z = z;
}

public DeviceRotation(Map<String, Integer> map) {
if (map == null || !map.containsKey("x") || !map.containsKey("y") || !map.containsKey("z")) {
throw new IllegalArgumentException("Could not initialize DeviceRotation with map given: " + map.toString());
}
this.validateParameters(map.get("x"), map.get("y"), map.get("z"));
this.x = map.get("x");
this.y = map.get("y");
this.z = map.get("z");
}

private void validateParameters(int x, int y, int z) {
if (x < 0 || y < 0 || z < 0) {
throw new IllegalArgumentException("DeviceRotation requires positive axis values: \nx = " + x + "\ny = " + y + "\nz = " + z);
}
}

/**
* @return the x
*/
public int getX() {
return x;
}

/**
* @return the y
*/
public int getY() {
return y;
}

/**
* @return the z
*/
public int getZ() {
return z;
}

/**
* @return returns all axis mapped to an ImmutableMap
*/
public ImmutableMap<String,Integer> parameters() {
return ImmutableMap.of("x", this.x, "y", this.y, "z", this.z);
}


}
13 changes: 13 additions & 0 deletions java/client/src/org/openqa/selenium/Rotatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ public interface Rotatable {
* @return the current screen orientation of the browser
*/
ScreenOrientation getOrientation();

/**
* Changes the rotation of the browser window.
*
* @param rotation
*/
void rotate(DeviceRotation rotation);

/**
* @return DeviceOrientation describing the current screen rotation of the browser window
*/
DeviceRotation rotation();

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public interface DriverCommand {

String SET_SCREEN_ORIENTATION = "setScreenOrientation";
String GET_SCREEN_ORIENTATION = "getScreenOrientation";

String SET_SCREEN_ROTATION = "setScreenRotation";
String GET_SCREEN_ROTATION = "getScreenRotation";

String ACTION_CHAIN = "actionChain";

// These belong to the Advanced user interactions - an element is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public JsonHttpCommandCodec() {

defineCommand(GET_SCREEN_ORIENTATION, get("/session/:sessionId/orientation"));
defineCommand(SET_SCREEN_ORIENTATION, post("/session/:sessionId/orientation"));
defineCommand(GET_SCREEN_ROTATION, get("/session/:sessionId/rotation"));
defineCommand(SET_SCREEN_ROTATION, post("/session/:sessionId/rotation"));

// Interactions-related commands.
defineCommand(MOUSE_DOWN, post("/session/:sessionId/buttondown"));
Expand Down