1 /* 2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.glass.ui.ios; 27 28 import javafx.scene.input.KeyCode; 29 import javafx.scene.input.MouseButton; 30 import javafx.scene.paint.Color; 31 32 import com.sun.glass.ui.Application; 33 import com.sun.glass.ui.GlassRobot; 34 35 /** 36 * iOS platform implementation class of test automation Robot. 37 */ 38 final class IosRobot extends GlassRobot { 39 40 private long ptr = 0; 41 42 // init and create native robot object 43 private native long _init(); 44 45 @Override public void create() { 46 Application.checkEventThread(); 47 ptr = _init(); 48 } 49 50 // release native robot object 51 private native void _destroy(long ptr); 52 @Override public void destroy() { 53 Application.checkEventThread(); 54 _destroy(ptr); 55 ptr = 0; 56 } 57 58 // synthesize key press 59 private native void _keyPress(long ptr, int code); 60 @Override public void keyPress(KeyCode code) { 61 Application.checkEventThread(); 62 if (ptr == 0) { 63 return; 64 } 65 _keyPress(ptr, code.getCode()); 66 } 67 68 // synthesize key release 69 private native void _keyRelease(long ptr, int code); 70 @Override public void keyRelease(KeyCode code) { 71 Application.checkEventThread(); 72 if (ptr == 0) { 73 return; 74 } 75 _keyRelease(ptr, code.getCode()); 76 } 77 78 // synthesize mouse motion 79 private native void _mouseMove(long ptr, int x, int y); 80 @Override public void mouseMove(double x, double y) { 81 Application.checkEventThread(); 82 if (ptr == 0) { 83 return; 84 } 85 _mouseMove(ptr, (int) x, (int) y); 86 } 87 88 // synthesize mouse press of buttons 89 private native void _mousePress(long ptr, int buttons); 90 @Override 91 public void mousePress(MouseButton... buttons) { 92 Application.checkEventThread(); 93 if (ptr == 0) { 94 return; 95 } 96 _mousePress(ptr, GlassRobot.convertToRobotMouseButton(buttons)); 97 } 98 99 // synthesize mouse release of buttons 100 private native void _mouseRelease(long ptr, int buttons); 101 @Override 102 public void mouseRelease(MouseButton... buttons) { 103 Application.checkEventThread(); 104 if (ptr == 0) { 105 return; 106 } 107 _mouseRelease(ptr, GlassRobot.convertToRobotMouseButton(buttons)); 108 } 109 110 private native void _mouseWheel(long ptr, int wheelAmt); 111 @Override public void mouseWheel(int wheelAmt) { 112 Application.checkEventThread(); 113 if (ptr == 0) { 114 return; 115 } 116 _mouseWheel(ptr, wheelAmt); 117 } 118 119 // get x-coordinate of mouse location 120 private native int _getMouseX(long ptr); 121 @Override public double getMouseX() { 122 Application.checkEventThread(); 123 if (ptr == 0) { 124 return 0; 125 } 126 return _getMouseX(ptr); 127 } 128 129 // get x-coordinate of mouse location 130 private native int _getMouseY(long ptr); 131 @Override public double getMouseY() { 132 Application.checkEventThread(); 133 if (ptr == 0) { 134 return 0; 135 } 136 return _getMouseY(ptr); 137 } 138 139 private native int _getPixelColor(long ptr, int x, int y); 140 @Override public Color getPixelColor(double x, double y) { 141 Application.checkEventThread(); 142 if (ptr == 0) { 143 return GlassRobot.convertFromIntArgb(0); 144 } 145 return GlassRobot.convertFromIntArgb(_getPixelColor(ptr, (int) x, (int) y)); 146 } 147 148 private native void _getScreenCapture(long ptr, int x, int y, int width, int height, int[] data); 149 @Override 150 public void getScreenCapture(int x, int y, int width, int height, int[] data, boolean scaleToFit) { 151 Application.checkEventThread(); 152 if (ptr == 0) { 153 return; 154 } 155 _getScreenCapture(ptr, x, y, width, height, data); 156 } 157 158 } 159