2012-01-05 16:14:23 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import org.mozilla.gecko.gfx.DisplayPortMetrics;
|
2012-11-07 08:47:08 -08:00
|
|
|
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2012-08-01 14:56:26 -07:00
|
|
|
import android.content.res.Resources;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.graphics.Point;
|
|
|
|
import android.graphics.PointF;
|
|
|
|
import android.graphics.Rect;
|
|
|
|
import android.hardware.Sensor;
|
|
|
|
import android.hardware.SensorEvent;
|
|
|
|
import android.hardware.SensorManager;
|
|
|
|
import android.location.Address;
|
|
|
|
import android.location.Location;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.SystemClock;
|
2012-01-24 16:31:33 -08:00
|
|
|
import android.util.DisplayMetrics;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.util.Log;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.MotionEvent;
|
2012-07-15 13:20:43 -07:00
|
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
/* We're not allowed to hold on to most events given to us
|
|
|
|
* so we save the parts of the events we want to use in GeckoEvent.
|
|
|
|
* Fields have different meanings depending on the event type.
|
|
|
|
*/
|
|
|
|
|
2012-03-22 10:35:19 -07:00
|
|
|
/* This class is referenced by Robocop via reflection; use care when
|
|
|
|
* modifying the signature.
|
|
|
|
*/
|
2012-07-17 17:54:54 -07:00
|
|
|
public class GeckoEvent {
|
2011-11-18 10:28:17 -08:00
|
|
|
private static final String LOGTAG = "GeckoEvent";
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
private static final int INVALID = -1;
|
|
|
|
private static final int NATIVE_POKE = 0;
|
|
|
|
private static final int KEY_EVENT = 1;
|
|
|
|
private static final int MOTION_EVENT = 2;
|
2012-03-13 16:57:51 -07:00
|
|
|
private static final int SENSOR_EVENT = 3;
|
2012-03-20 16:59:24 -07:00
|
|
|
private static final int UNUSED1_EVENT = 4;
|
|
|
|
private static final int LOCATION_EVENT = 5;
|
|
|
|
private static final int IME_EVENT = 6;
|
|
|
|
private static final int DRAW = 7;
|
|
|
|
private static final int SIZE_CHANGED = 8;
|
|
|
|
private static final int ACTIVITY_STOPPING = 9;
|
|
|
|
private static final int ACTIVITY_PAUSING = 10;
|
|
|
|
private static final int ACTIVITY_SHUTDOWN = 11;
|
|
|
|
private static final int LOAD_URI = 12;
|
|
|
|
private static final int SURFACE_CREATED = 13;
|
|
|
|
private static final int SURFACE_DESTROYED = 14;
|
|
|
|
private static final int GECKO_EVENT_SYNC = 15;
|
|
|
|
private static final int ACTIVITY_START = 17;
|
|
|
|
private static final int BROADCAST = 19;
|
|
|
|
private static final int VIEWPORT = 20;
|
|
|
|
private static final int VISITED = 21;
|
|
|
|
private static final int NETWORK_CHANGED = 22;
|
2012-03-20 23:36:17 -07:00
|
|
|
private static final int UNUSED3_EVENT = 23;
|
2012-03-20 16:59:24 -07:00
|
|
|
private static final int ACTIVITY_RESUMING = 24;
|
|
|
|
private static final int SCREENSHOT = 25;
|
2012-03-20 23:36:17 -07:00
|
|
|
private static final int UNUSED2_EVENT = 26;
|
2012-03-20 16:59:24 -07:00
|
|
|
private static final int SCREENORIENTATION_CHANGED = 27;
|
2012-03-28 15:00:32 -07:00
|
|
|
private static final int COMPOSITOR_PAUSE = 28;
|
2012-04-24 12:13:36 -07:00
|
|
|
private static final int COMPOSITOR_RESUME = 29;
|
|
|
|
private static final int PAINT_LISTEN_START_EVENT = 30;
|
2012-10-02 13:18:21 -07:00
|
|
|
private static final int NATIVE_GESTURE_EVENT = 31;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-09-12 17:48:29 -07:00
|
|
|
/**
|
|
|
|
* These DOM_KEY_LOCATION constants mirror the DOM KeyboardEvent's constants.
|
|
|
|
* @see https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent#Key_location_constants
|
|
|
|
*/
|
|
|
|
private static final int DOM_KEY_LOCATION_STANDARD = 0;
|
|
|
|
private static final int DOM_KEY_LOCATION_LEFT = 1;
|
|
|
|
private static final int DOM_KEY_LOCATION_RIGHT = 2;
|
|
|
|
private static final int DOM_KEY_LOCATION_NUMPAD = 3;
|
|
|
|
private static final int DOM_KEY_LOCATION_MOBILE = 4;
|
|
|
|
private static final int DOM_KEY_LOCATION_JOYSTICK = 5;
|
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
public static final int IME_SYNCHRONIZE = 0;
|
|
|
|
public static final int IME_REPLACE_TEXT = 1;
|
|
|
|
public static final int IME_SET_SELECTION = 2;
|
|
|
|
public static final int IME_ADD_COMPOSITION_RANGE = 3;
|
|
|
|
public static final int IME_UPDATE_COMPOSITION = 4;
|
|
|
|
public static final int IME_REMOVE_COMPOSITION = 5;
|
2012-11-13 14:27:19 -08:00
|
|
|
public static final int IME_ACKNOWLEDGE_FOCUS = 6;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public static final int IME_RANGE_CARETPOSITION = 1;
|
|
|
|
public static final int IME_RANGE_RAWINPUT = 2;
|
|
|
|
public static final int IME_RANGE_SELECTEDRAWTEXT = 3;
|
|
|
|
public static final int IME_RANGE_CONVERTEDTEXT = 4;
|
|
|
|
public static final int IME_RANGE_SELECTEDCONVERTEDTEXT = 5;
|
|
|
|
|
|
|
|
public static final int IME_RANGE_UNDERLINE = 1;
|
|
|
|
public static final int IME_RANGE_FORECOLOR = 2;
|
|
|
|
public static final int IME_RANGE_BACKCOLOR = 4;
|
|
|
|
|
2012-10-02 13:18:21 -07:00
|
|
|
public static final int ACTION_MAGNIFY_START = 11;
|
|
|
|
public static final int ACTION_MAGNIFY = 12;
|
|
|
|
public static final int ACTION_MAGNIFY_END = 13;
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
final public int mType;
|
2011-11-18 10:28:17 -08:00
|
|
|
public int mAction;
|
|
|
|
public long mTime;
|
2012-01-24 16:31:33 -08:00
|
|
|
public Point[] mPoints;
|
|
|
|
public int[] mPointIndicies;
|
|
|
|
public int mPointerIndex; // index of the point that has changed
|
|
|
|
public float[] mOrientations;
|
|
|
|
public float[] mPressures;
|
|
|
|
public Point[] mPointRadii;
|
2011-11-18 10:28:17 -08:00
|
|
|
public Rect mRect;
|
|
|
|
public double mX, mY, mZ;
|
|
|
|
|
|
|
|
public int mMetaState, mFlags;
|
|
|
|
public int mKeyCode, mUnicodeChar;
|
2012-04-19 13:55:33 -07:00
|
|
|
public int mRepeatCount;
|
2012-11-01 13:11:02 -07:00
|
|
|
public int mCount;
|
|
|
|
public int mStart, mEnd;
|
2011-11-18 10:28:17 -08:00
|
|
|
public String mCharacters, mCharactersExtra;
|
|
|
|
public int mRangeType, mRangeStyles;
|
|
|
|
public int mRangeForeColor, mRangeBackColor;
|
|
|
|
public Location mLocation;
|
|
|
|
public Address mAddress;
|
2012-09-12 17:48:29 -07:00
|
|
|
public int mDomKeyLocation;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-17 10:40:39 -08:00
|
|
|
public double mBandwidth;
|
|
|
|
public boolean mCanBeMetered;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public int mNativeWindow;
|
2012-02-18 15:32:50 -08:00
|
|
|
|
2012-03-20 06:09:45 -07:00
|
|
|
public short mScreenOrientation;
|
|
|
|
|
2012-06-14 09:08:51 -07:00
|
|
|
public ByteBuffer mBuffer;
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
private GeckoEvent(int evType) {
|
|
|
|
mType = evType;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
public static GeckoEvent createPauseEvent(boolean isApplicationInBackground) {
|
2012-02-15 12:34:31 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(ACTIVITY_PAUSING);
|
2012-04-03 11:58:01 -07:00
|
|
|
event.mFlags = isApplicationInBackground ? 0 : 1;
|
2012-02-15 12:34:31 -08:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
public static GeckoEvent createResumeEvent(boolean isApplicationInBackground) {
|
2012-02-15 12:34:31 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(ACTIVITY_RESUMING);
|
2012-04-03 11:58:01 -07:00
|
|
|
event.mFlags = isApplicationInBackground ? 0 : 1;
|
2012-02-15 12:34:31 -08:00
|
|
|
return event;
|
2012-02-08 23:18:27 -08:00
|
|
|
}
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
public static GeckoEvent createStoppingEvent(boolean isApplicationInBackground) {
|
2012-02-15 12:34:31 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(ACTIVITY_STOPPING);
|
2012-04-03 11:58:01 -07:00
|
|
|
event.mFlags = isApplicationInBackground ? 0 : 1;
|
2012-02-15 12:34:31 -08:00
|
|
|
return event;
|
2012-02-08 23:18:27 -08:00
|
|
|
}
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
public static GeckoEvent createStartEvent(boolean isApplicationInBackground) {
|
2012-02-15 12:34:31 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(ACTIVITY_START);
|
2012-04-03 11:58:01 -07:00
|
|
|
event.mFlags = isApplicationInBackground ? 0 : 1;
|
2012-02-15 12:34:31 -08:00
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
public static GeckoEvent createShutdownEvent() {
|
|
|
|
return new GeckoEvent(ACTIVITY_SHUTDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createSyncEvent() {
|
|
|
|
return new GeckoEvent(GECKO_EVENT_SYNC);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createKeyEvent(KeyEvent k) {
|
|
|
|
GeckoEvent event = new GeckoEvent(KEY_EVENT);
|
|
|
|
event.initKeyEvent(k);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2012-03-28 15:00:32 -07:00
|
|
|
public static GeckoEvent createCompositorPauseEvent() {
|
|
|
|
return new GeckoEvent(COMPOSITOR_PAUSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createCompositorResumeEvent() {
|
|
|
|
return new GeckoEvent(COMPOSITOR_RESUME);
|
|
|
|
}
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
private void initKeyEvent(KeyEvent k) {
|
2011-11-18 10:28:17 -08:00
|
|
|
mAction = k.getAction();
|
|
|
|
mTime = k.getEventTime();
|
|
|
|
mMetaState = k.getMetaState();
|
|
|
|
mFlags = k.getFlags();
|
|
|
|
mKeyCode = k.getKeyCode();
|
|
|
|
mUnicodeChar = k.getUnicodeChar();
|
2012-04-19 13:55:33 -07:00
|
|
|
mRepeatCount = k.getRepeatCount();
|
2011-11-18 10:28:17 -08:00
|
|
|
mCharacters = k.getCharacters();
|
2012-09-12 17:48:29 -07:00
|
|
|
mDomKeyLocation = isJoystickButton(mKeyCode) ? DOM_KEY_LOCATION_JOYSTICK : DOM_KEY_LOCATION_MOBILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method tests if a key is one of the described in:
|
|
|
|
* https://bugzilla.mozilla.org/show_bug.cgi?id=756504#c0
|
|
|
|
* @param keyCode int with the key code (Android key constant from KeyEvent)
|
|
|
|
* @return true if the key is one of the listed above, false otherwise.
|
|
|
|
*/
|
|
|
|
private static boolean isJoystickButton(int keyCode) {
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_DPAD_CENTER:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_DOWN:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_UP:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
if (Build.VERSION.SDK_INT >= 12) {
|
|
|
|
return KeyEvent.isGamepadButton(keyCode);
|
|
|
|
}
|
|
|
|
return GeckoEvent.isGamepadButton(keyCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is a replacement for the the KeyEvent.isGamepadButton method to be
|
|
|
|
* compatible with Build.VERSION.SDK_INT < 12. This is an implementantion of the
|
|
|
|
* same method isGamepadButton available after SDK 12.
|
|
|
|
* @param keyCode int with the key code (Android key constant from KeyEvent).
|
|
|
|
* @return True if the keycode is a gamepad button, such as {@link #KEYCODE_BUTTON_A}.
|
|
|
|
*/
|
|
|
|
private static boolean isGamepadButton(int keyCode) {
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_A:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_B:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_C:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_X:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_Y:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_Z:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_L1:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_R1:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_L2:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_R2:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_THUMBL:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_THUMBR:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_START:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_SELECT:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_MODE:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_1:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_2:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_3:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_4:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_5:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_6:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_7:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_8:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_9:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_10:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_11:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_12:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_13:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_14:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_15:
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_16:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-10-02 13:18:21 -07:00
|
|
|
public static GeckoEvent createNativeGestureEvent(int action, PointF pt, double size) {
|
2012-11-12 16:07:41 -08:00
|
|
|
try {
|
|
|
|
GeckoEvent event = new GeckoEvent(NATIVE_GESTURE_EVENT);
|
|
|
|
event.mAction = action;
|
|
|
|
event.mCount = 1;
|
|
|
|
event.mPoints = new Point[1];
|
2012-10-02 13:18:21 -07:00
|
|
|
|
2012-11-12 16:07:41 -08:00
|
|
|
PointF geckoPoint = new PointF(pt.x, pt.y);
|
|
|
|
geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);
|
2012-10-31 09:39:44 -07:00
|
|
|
|
2012-11-12 16:07:41 -08:00
|
|
|
if (geckoPoint == null) {
|
|
|
|
// This could happen if Gecko isn't ready yet.
|
|
|
|
return null;
|
|
|
|
}
|
2012-10-31 09:39:44 -07:00
|
|
|
|
2012-11-12 16:07:41 -08:00
|
|
|
event.mPoints[0] = new Point(Math.round(geckoPoint.x), Math.round(geckoPoint.y));
|
2012-10-02 13:18:21 -07:00
|
|
|
|
2012-11-12 16:07:41 -08:00
|
|
|
event.mX = size;
|
|
|
|
event.mTime = System.currentTimeMillis();
|
|
|
|
return event;
|
|
|
|
} catch (Exception e) {
|
|
|
|
// This can happen if Gecko isn't ready yet
|
|
|
|
return null;
|
|
|
|
}
|
2012-10-02 13:18:21 -07:00
|
|
|
}
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
public static GeckoEvent createMotionEvent(MotionEvent m) {
|
|
|
|
GeckoEvent event = new GeckoEvent(MOTION_EVENT);
|
|
|
|
event.initMotionEvent(m);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initMotionEvent(MotionEvent m) {
|
2011-11-18 10:28:17 -08:00
|
|
|
mAction = m.getAction();
|
2012-01-24 16:31:33 -08:00
|
|
|
mTime = (System.currentTimeMillis() - SystemClock.elapsedRealtime()) + m.getEventTime();
|
2011-11-18 10:28:17 -08:00
|
|
|
mMetaState = m.getMetaState();
|
2012-01-24 16:31:33 -08:00
|
|
|
|
|
|
|
switch (mAction & MotionEvent.ACTION_MASK) {
|
|
|
|
case MotionEvent.ACTION_CANCEL:
|
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
|
case MotionEvent.ACTION_POINTER_UP:
|
|
|
|
case MotionEvent.ACTION_POINTER_DOWN:
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
2012-06-15 15:34:22 -07:00
|
|
|
case MotionEvent.ACTION_MOVE:
|
|
|
|
case MotionEvent.ACTION_HOVER_ENTER:
|
|
|
|
case MotionEvent.ACTION_HOVER_MOVE:
|
|
|
|
case MotionEvent.ACTION_HOVER_EXIT: {
|
2012-01-24 16:31:33 -08:00
|
|
|
mCount = m.getPointerCount();
|
|
|
|
mPoints = new Point[mCount];
|
|
|
|
mPointIndicies = new int[mCount];
|
|
|
|
mOrientations = new float[mCount];
|
|
|
|
mPressures = new float[mCount];
|
|
|
|
mPointRadii = new Point[mCount];
|
|
|
|
mPointerIndex = (mAction & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
|
|
|
for (int i = 0; i < mCount; i++) {
|
|
|
|
addMotionPoint(i, i, m);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
mCount = 0;
|
|
|
|
mPointerIndex = -1;
|
|
|
|
mPoints = new Point[mCount];
|
|
|
|
mPointIndicies = new int[mCount];
|
|
|
|
mOrientations = new float[mCount];
|
|
|
|
mPressures = new float[mCount];
|
|
|
|
mPointRadii = new Point[mCount];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addMotionPoint(int index, int eventIndex, MotionEvent event) {
|
2012-02-07 17:06:47 -08:00
|
|
|
try {
|
|
|
|
PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
|
2012-08-20 12:43:53 -07:00
|
|
|
geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);
|
2012-02-07 17:06:47 -08:00
|
|
|
|
|
|
|
mPoints[index] = new Point(Math.round(geckoPoint.x), Math.round(geckoPoint.y));
|
|
|
|
mPointIndicies[index] = event.getPointerId(eventIndex);
|
|
|
|
// getToolMajor, getToolMinor and getOrientation are API Level 9 features
|
|
|
|
if (Build.VERSION.SDK_INT >= 9) {
|
|
|
|
double radians = event.getOrientation(eventIndex);
|
|
|
|
mOrientations[index] = (float) Math.toDegrees(radians);
|
|
|
|
// w3c touchevents spec does not allow orientations == 90
|
|
|
|
// this shifts it to -90, which will be shifted to zero below
|
|
|
|
if (mOrientations[index] == 90)
|
|
|
|
mOrientations[index] = -90;
|
|
|
|
|
|
|
|
// w3c touchevent radius are given by an orientation between 0 and 90
|
|
|
|
// the radius is found by removing the orientation and measuring the x and y
|
|
|
|
// radius of the resulting ellipse
|
|
|
|
// for android orientations >= 0 and < 90, the major axis should correspond to
|
|
|
|
// just reporting the y radius as the major one, and x as minor
|
|
|
|
// however, for a radius < 0, we have to shift the orientation by adding 90, and
|
|
|
|
// reverse which radius is major and minor
|
|
|
|
if (mOrientations[index] < 0) {
|
|
|
|
mOrientations[index] += 90;
|
|
|
|
mPointRadii[index] = new Point((int)event.getToolMajor(eventIndex)/2,
|
|
|
|
(int)event.getToolMinor(eventIndex)/2);
|
|
|
|
} else {
|
|
|
|
mPointRadii[index] = new Point((int)event.getToolMinor(eventIndex)/2,
|
|
|
|
(int)event.getToolMajor(eventIndex)/2);
|
|
|
|
}
|
2012-01-24 16:31:33 -08:00
|
|
|
} else {
|
2012-02-07 17:06:47 -08:00
|
|
|
float size = event.getSize(eventIndex);
|
2012-08-01 14:56:26 -07:00
|
|
|
Resources resources = GeckoApp.mAppContext.getResources();
|
|
|
|
DisplayMetrics displaymetrics = resources.getDisplayMetrics();
|
2012-02-07 17:06:47 -08:00
|
|
|
size = size*Math.min(displaymetrics.heightPixels, displaymetrics.widthPixels);
|
|
|
|
mPointRadii[index] = new Point((int)size,(int)size);
|
|
|
|
mOrientations[index] = 0;
|
2012-01-24 16:31:33 -08:00
|
|
|
}
|
2012-02-07 17:06:47 -08:00
|
|
|
mPressures[index] = event.getPressure(eventIndex);
|
2012-11-12 16:07:41 -08:00
|
|
|
} catch (Exception ex) {
|
2012-02-07 17:06:47 -08:00
|
|
|
Log.e(LOGTAG, "Error creating motion point " + index, ex);
|
|
|
|
mPointRadii[index] = new Point(0, 0);
|
|
|
|
mPoints[index] = new Point(0, 0);
|
2012-01-24 16:31:33 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-03-20 23:36:17 -07:00
|
|
|
private static int HalSensorAccuracyFor(int androidAccuracy) {
|
|
|
|
switch (androidAccuracy) {
|
|
|
|
case SensorManager.SENSOR_STATUS_UNRELIABLE:
|
|
|
|
return GeckoHalDefines.SENSOR_ACCURACY_UNRELIABLE;
|
|
|
|
case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
|
|
|
|
return GeckoHalDefines.SENSOR_ACCURACY_LOW;
|
|
|
|
case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
|
|
|
|
return GeckoHalDefines.SENSOR_ACCURACY_MED;
|
|
|
|
case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
|
|
|
|
return GeckoHalDefines.SENSOR_ACCURACY_HIGH;
|
|
|
|
}
|
|
|
|
return GeckoHalDefines.SENSOR_ACCURACY_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
public static GeckoEvent createSensorEvent(SensorEvent s) {
|
2012-02-05 11:54:25 -08:00
|
|
|
int sensor_type = s.sensor.getType();
|
2012-03-13 16:57:51 -07:00
|
|
|
GeckoEvent event = null;
|
|
|
|
|
2012-02-05 11:54:25 -08:00
|
|
|
switch(sensor_type) {
|
2012-03-13 16:57:51 -07:00
|
|
|
|
2012-02-05 11:54:25 -08:00
|
|
|
case Sensor.TYPE_ACCELEROMETER:
|
2012-03-13 16:57:51 -07:00
|
|
|
event = new GeckoEvent(SENSOR_EVENT);
|
|
|
|
event.mFlags = GeckoHalDefines.SENSOR_ACCELERATION;
|
2012-03-20 23:36:17 -07:00
|
|
|
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
2012-03-13 10:00:02 -07:00
|
|
|
event.mX = s.values[0];
|
|
|
|
event.mY = s.values[1];
|
|
|
|
event.mZ = s.values[2];
|
|
|
|
break;
|
2012-03-13 16:57:51 -07:00
|
|
|
|
|
|
|
case 10 /* Requires API Level 9, so just use the raw value - Sensor.TYPE_LINEAR_ACCELEROMETER*/ :
|
|
|
|
event = new GeckoEvent(SENSOR_EVENT);
|
|
|
|
event.mFlags = GeckoHalDefines.SENSOR_LINEAR_ACCELERATION;
|
2012-03-20 23:36:17 -07:00
|
|
|
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
2012-02-08 23:18:27 -08:00
|
|
|
event.mX = s.values[0];
|
|
|
|
event.mY = s.values[1];
|
|
|
|
event.mZ = s.values[2];
|
2012-02-05 11:54:25 -08:00
|
|
|
break;
|
2012-03-13 16:57:51 -07:00
|
|
|
|
2012-02-05 11:54:25 -08:00
|
|
|
case Sensor.TYPE_ORIENTATION:
|
2012-03-13 16:57:51 -07:00
|
|
|
event = new GeckoEvent(SENSOR_EVENT);
|
|
|
|
event.mFlags = GeckoHalDefines.SENSOR_ORIENTATION;
|
2012-03-20 23:36:17 -07:00
|
|
|
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
2012-03-13 16:57:51 -07:00
|
|
|
event.mX = s.values[0];
|
|
|
|
event.mY = s.values[1];
|
|
|
|
event.mZ = s.values[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Sensor.TYPE_GYROSCOPE:
|
|
|
|
event = new GeckoEvent(SENSOR_EVENT);
|
|
|
|
event.mFlags = GeckoHalDefines.SENSOR_GYROSCOPE;
|
2012-03-20 23:36:17 -07:00
|
|
|
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
2012-03-13 16:57:51 -07:00
|
|
|
event.mX = Math.toDegrees(s.values[0]);
|
|
|
|
event.mY = Math.toDegrees(s.values[1]);
|
|
|
|
event.mZ = Math.toDegrees(s.values[2]);
|
2012-02-05 11:54:25 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Sensor.TYPE_PROXIMITY:
|
2012-03-20 23:36:17 -07:00
|
|
|
event = new GeckoEvent(SENSOR_EVENT);
|
|
|
|
event.mFlags = GeckoHalDefines.SENSOR_PROXIMITY;
|
2012-05-02 09:43:45 -07:00
|
|
|
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
2012-03-20 23:36:17 -07:00
|
|
|
event.mX = s.values[0];
|
2012-05-02 09:43:45 -07:00
|
|
|
event.mY = 0;
|
|
|
|
event.mZ = s.sensor.getMaximumRange();
|
2012-02-05 11:54:25 -08:00
|
|
|
break;
|
2012-05-02 09:43:45 -07:00
|
|
|
|
|
|
|
case Sensor.TYPE_LIGHT:
|
|
|
|
event = new GeckoEvent(SENSOR_EVENT);
|
|
|
|
event.mFlags = GeckoHalDefines.SENSOR_LIGHT;
|
|
|
|
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
|
|
|
|
event.mX = s.values[0];
|
|
|
|
break;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-02-08 23:18:27 -08:00
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-03-08 22:16:25 -08:00
|
|
|
public static GeckoEvent createLocationEvent(Location l) {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(LOCATION_EVENT);
|
|
|
|
event.mLocation = l;
|
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
public static GeckoEvent createIMEEvent(int action) {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(IME_EVENT);
|
2012-11-01 13:11:02 -07:00
|
|
|
event.mAction = action;
|
2012-02-08 23:18:27 -08:00
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
public static GeckoEvent createIMEReplaceEvent(int start, int end,
|
|
|
|
String text) {
|
2012-10-31 14:35:31 -07:00
|
|
|
GeckoEvent event = new GeckoEvent(IME_EVENT);
|
2012-11-01 13:11:02 -07:00
|
|
|
event.mAction = IME_REPLACE_TEXT;
|
|
|
|
event.mStart = start;
|
|
|
|
event.mEnd = end;
|
Backout 533faa3c50ed, 718abc1bd4ad, af2d5272c06b, ad5554e1345d, c9ef1b41b829, d3a825311d11, 0a51bcb3eb9e, a01a327e8ec4, 973b0ed30b8b, 39851bbcfaa1 & a92d2d2a3b0e (bug 805162), d4884aab5ce6, 06fcbaf40cb4, daccc3fe7c70, 881eb2a2906e, 76232441ae06, 01ae34fa1b3f & 5f405fc4e323 (bug 783092), a03d8d4db1c2, 49beb3801192, 174634554a97, 0bd27e755a83, 19e8f151ca67, a6604e038bc0, ed3b8237e76e & 082cf8d72554 (bug 785945) for bustage or conflicting with backout of said bustage on a CLOSED TREE
2012-10-31 17:16:35 -07:00
|
|
|
event.mCharacters = text;
|
2012-10-31 14:35:31 -07:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
public static GeckoEvent createIMESelectEvent(int start, int end) {
|
|
|
|
GeckoEvent event = new GeckoEvent(IME_EVENT);
|
|
|
|
event.mAction = IME_SET_SELECTION;
|
|
|
|
event.mStart = start;
|
|
|
|
event.mEnd = end;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createIMECompositionEvent(int start, int end) {
|
|
|
|
GeckoEvent event = new GeckoEvent(IME_EVENT);
|
|
|
|
event.mAction = IME_UPDATE_COMPOSITION;
|
|
|
|
event.mStart = start;
|
|
|
|
event.mEnd = end;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createIMERangeEvent(int start,
|
|
|
|
int end, int rangeType,
|
|
|
|
int rangeStyles,
|
|
|
|
int rangeForeColor,
|
|
|
|
int rangeBackColor) {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(IME_EVENT);
|
2012-11-01 13:11:02 -07:00
|
|
|
event.mAction = IME_ADD_COMPOSITION_RANGE;
|
|
|
|
event.mStart = start;
|
|
|
|
event.mEnd = end;
|
|
|
|
event.mRangeType = rangeType;
|
|
|
|
event.mRangeStyles = rangeStyles;
|
|
|
|
event.mRangeForeColor = rangeForeColor;
|
|
|
|
event.mRangeBackColor = rangeBackColor;
|
2012-02-08 23:18:27 -08:00
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
public static GeckoEvent createDrawEvent(Rect rect) {
|
|
|
|
GeckoEvent event = new GeckoEvent(DRAW);
|
|
|
|
event.mRect = rect;
|
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-24 07:51:41 -08:00
|
|
|
public static GeckoEvent createSizeChangedEvent(int w, int h, int screenw, int screenh) {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(SIZE_CHANGED);
|
2012-02-24 07:51:41 -08:00
|
|
|
event.mPoints = new Point[2];
|
2012-02-08 23:18:27 -08:00
|
|
|
event.mPoints[0] = new Point(w, h);
|
|
|
|
event.mPoints[1] = new Point(screenw, screenh);
|
|
|
|
return event;
|
2012-01-06 03:22:38 -08:00
|
|
|
}
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
public static GeckoEvent createBroadcastEvent(String subject, String data) {
|
|
|
|
GeckoEvent event = new GeckoEvent(BROADCAST);
|
|
|
|
event.mCharacters = subject;
|
|
|
|
event.mCharactersExtra = data;
|
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-11-07 08:47:08 -08:00
|
|
|
public static GeckoEvent createViewportEvent(ImmutableViewportMetrics metrics, DisplayPortMetrics displayPort) {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(VIEWPORT);
|
|
|
|
event.mCharacters = "Viewport:Change";
|
2012-02-28 13:13:20 -08:00
|
|
|
StringBuffer sb = new StringBuffer(256);
|
2012-11-07 08:47:08 -08:00
|
|
|
sb.append("{ \"x\" : ").append(metrics.viewportRectLeft)
|
|
|
|
.append(", \"y\" : ").append(metrics.viewportRectTop)
|
|
|
|
.append(", \"zoom\" : ").append(metrics.zoomFactor)
|
2012-03-26 10:15:49 -07:00
|
|
|
.append(", \"displayPort\" :").append(displayPort.toJSON())
|
2012-02-28 13:13:20 -08:00
|
|
|
.append('}');
|
|
|
|
event.mCharactersExtra = sb.toString();
|
2012-02-08 23:18:27 -08:00
|
|
|
return event;
|
2011-12-22 03:35:32 -08:00
|
|
|
}
|
|
|
|
|
2012-04-13 19:45:25 -07:00
|
|
|
public static GeckoEvent createURILoadEvent(String uri) {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(LOAD_URI);
|
|
|
|
event.mCharacters = uri;
|
2012-04-13 19:45:25 -07:00
|
|
|
event.mCharactersExtra = "";
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createWebappLoadEvent(String uri) {
|
|
|
|
GeckoEvent event = new GeckoEvent(LOAD_URI);
|
|
|
|
event.mCharacters = uri;
|
|
|
|
event.mCharactersExtra = "-webapp";
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createBookmarkLoadEvent(String uri) {
|
|
|
|
GeckoEvent event = new GeckoEvent(LOAD_URI);
|
|
|
|
event.mCharacters = uri;
|
|
|
|
event.mCharactersExtra = "-bookmark";
|
2012-02-08 23:18:27 -08:00
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
public static GeckoEvent createVisitedEvent(String data) {
|
|
|
|
GeckoEvent event = new GeckoEvent(VISITED);
|
|
|
|
event.mCharacters = data;
|
|
|
|
return event;
|
2012-01-05 16:14:23 -08:00
|
|
|
}
|
2012-01-17 10:40:39 -08:00
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
public static GeckoEvent createNetworkEvent(double bandwidth, boolean canBeMetered) {
|
|
|
|
GeckoEvent event = new GeckoEvent(NETWORK_CHANGED);
|
|
|
|
event.mBandwidth = bandwidth;
|
|
|
|
event.mCanBeMetered = canBeMetered;
|
|
|
|
return event;
|
2012-01-17 10:40:39 -08:00
|
|
|
}
|
2012-02-17 10:52:26 -08:00
|
|
|
|
2012-06-14 09:08:51 -07:00
|
|
|
public static GeckoEvent createScreenshotEvent(int tabId, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int bw, int bh, int token, ByteBuffer buffer) {
|
2012-02-17 10:52:26 -08:00
|
|
|
GeckoEvent event = new GeckoEvent(SCREENSHOT);
|
2012-06-14 09:08:51 -07:00
|
|
|
event.mPoints = new Point[5];
|
2012-04-24 12:13:36 -07:00
|
|
|
event.mPoints[0] = new Point(sx, sy);
|
|
|
|
event.mPoints[1] = new Point(sw, sh);
|
|
|
|
event.mPoints[2] = new Point(dx, dy);
|
|
|
|
event.mPoints[3] = new Point(dw, dh);
|
2012-06-14 09:08:51 -07:00
|
|
|
event.mPoints[4] = new Point(bw, bh);
|
2012-02-17 10:52:26 -08:00
|
|
|
event.mMetaState = tabId;
|
2012-04-24 12:13:36 -07:00
|
|
|
event.mFlags = token;
|
2012-06-14 09:08:51 -07:00
|
|
|
event.mBuffer = buffer;
|
2012-02-17 10:52:26 -08:00
|
|
|
return event;
|
|
|
|
}
|
2012-03-13 16:57:09 -07:00
|
|
|
|
2012-03-20 06:09:45 -07:00
|
|
|
public static GeckoEvent createScreenOrientationEvent(short aScreenOrientation) {
|
|
|
|
GeckoEvent event = new GeckoEvent(SCREENORIENTATION_CHANGED);
|
|
|
|
event.mScreenOrientation = aScreenOrientation;
|
|
|
|
return event;
|
|
|
|
}
|
2012-04-24 12:13:36 -07:00
|
|
|
|
|
|
|
public static GeckoEvent createStartPaintListentingEvent(int tabId) {
|
|
|
|
GeckoEvent event = new GeckoEvent(PAINT_LISTEN_START_EVENT);
|
|
|
|
event.mMetaState = tabId;
|
|
|
|
return event;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|