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;
|
2013-11-21 14:44:00 -08:00
|
|
|
import org.mozilla.gecko.mozglue.JNITarget;
|
2013-11-12 10:41:00 -08:00
|
|
|
import org.mozilla.gecko.mozglue.generatorannotations.GeneratorOptions;
|
|
|
|
import org.mozilla.gecko.mozglue.generatorannotations.WrapEntireClassForJNI;
|
2013-12-06 11:43:11 -08:00
|
|
|
import org.mozilla.gecko.mozglue.RobocopTarget;
|
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;
|
2014-02-28 12:25:30 -08:00
|
|
|
import android.util.SparseArray;
|
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;
|
2014-02-28 12:25:30 -08:00
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
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.
|
|
|
|
*/
|
|
|
|
|
2013-04-08 13:21:52 -07:00
|
|
|
/* This class is referenced by Robocop via reflection; use care when
|
2012-03-22 10:35:19 -07:00
|
|
|
* modifying the signature.
|
|
|
|
*/
|
2013-11-21 14:44:00 -08:00
|
|
|
@JNITarget
|
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";
|
|
|
|
|
2014-02-28 12:25:30 -08:00
|
|
|
private static final int EVENT_FACTORY_SIZE = 5;
|
|
|
|
|
|
|
|
// Maybe we're probably better to just make mType non final, and just store GeckoEvents in here...
|
|
|
|
private static SparseArray<ArrayBlockingQueue<GeckoEvent>> mEvents = new SparseArray<ArrayBlockingQueue<GeckoEvent>>();
|
|
|
|
|
|
|
|
public static GeckoEvent get(NativeGeckoEvent type) {
|
|
|
|
synchronized (mEvents) {
|
|
|
|
ArrayBlockingQueue<GeckoEvent> events = mEvents.get(type.value);
|
|
|
|
if (events != null && events.size() > 0) {
|
|
|
|
return events.poll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new GeckoEvent(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void recycle() {
|
|
|
|
synchronized (mEvents) {
|
|
|
|
ArrayBlockingQueue<GeckoEvent> events = mEvents.get(mType);
|
|
|
|
if (events == null) {
|
|
|
|
events = new ArrayBlockingQueue<GeckoEvent>(EVENT_FACTORY_SIZE);
|
|
|
|
mEvents.put(mType, events);
|
|
|
|
}
|
|
|
|
|
|
|
|
events.offer(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 15:45:07 -07:00
|
|
|
// Make sure to keep these values in sync with the enum in
|
2013-12-10 10:41:34 -08:00
|
|
|
// AndroidGeckoEvent in widget/android/AndroidJavaWrappers.h
|
2013-11-21 14:44:00 -08:00
|
|
|
@JNITarget
|
2013-04-08 13:21:52 -07:00
|
|
|
private enum NativeGeckoEvent {
|
|
|
|
NATIVE_POKE(0),
|
|
|
|
KEY_EVENT(1),
|
|
|
|
MOTION_EVENT(2),
|
|
|
|
SENSOR_EVENT(3),
|
|
|
|
LOCATION_EVENT(5),
|
|
|
|
IME_EVENT(6),
|
|
|
|
DRAW(7),
|
|
|
|
SIZE_CHANGED(8),
|
|
|
|
APP_BACKGROUNDING(9),
|
|
|
|
APP_FOREGROUNDING(10),
|
|
|
|
LOAD_URI(12),
|
|
|
|
NOOP(15),
|
|
|
|
BROADCAST(19),
|
|
|
|
VIEWPORT(20),
|
|
|
|
VISITED(21),
|
|
|
|
NETWORK_CHANGED(22),
|
|
|
|
THUMBNAIL(25),
|
|
|
|
SCREENORIENTATION_CHANGED(27),
|
|
|
|
COMPOSITOR_CREATE(28),
|
|
|
|
COMPOSITOR_PAUSE(29),
|
|
|
|
COMPOSITOR_RESUME(30),
|
|
|
|
NATIVE_GESTURE_EVENT(31),
|
2013-06-15 14:40:27 -07:00
|
|
|
IME_KEY_EVENT(32),
|
2013-06-17 14:09:09 -07:00
|
|
|
CALL_OBSERVER(33),
|
2013-06-19 10:55:35 -07:00
|
|
|
REMOVE_OBSERVER(34),
|
|
|
|
LOW_MEMORY(35),
|
2013-08-15 12:03:47 -07:00
|
|
|
NETWORK_LINK_CHANGE(36),
|
2013-09-04 06:58:23 -07:00
|
|
|
TELEMETRY_HISTOGRAM_ADD(37),
|
|
|
|
PREFERENCES_OBSERVE(39),
|
|
|
|
PREFERENCES_GET(40),
|
2013-12-10 10:41:34 -08:00
|
|
|
PREFERENCES_REMOVE_OBSERVERS(41),
|
|
|
|
TELEMETRY_UI_SESSION_START(42),
|
|
|
|
TELEMETRY_UI_SESSION_STOP(43),
|
2014-04-22 07:53:48 -07:00
|
|
|
TELEMETRY_UI_EVENT(44),
|
|
|
|
GAMEPAD_ADDREMOVE(45),
|
|
|
|
GAMEPAD_DATA(46);
|
2013-04-08 13:21:52 -07:00
|
|
|
|
|
|
|
public final int value;
|
|
|
|
|
|
|
|
private NativeGeckoEvent(int value) {
|
|
|
|
this.value = value;
|
2013-12-10 10:41:34 -08:00
|
|
|
}
|
2013-04-08 13:21:52 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-09-12 17:48:29 -07:00
|
|
|
/**
|
2013-04-08 13:21:52 -07:00
|
|
|
* The DomKeyLocation enum encapsulates the DOM KeyboardEvent's constants.
|
2012-09-12 17:48:29 -07:00
|
|
|
* @see https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent#Key_location_constants
|
|
|
|
*/
|
2013-11-12 10:41:00 -08:00
|
|
|
@GeneratorOptions(generatedClassName = "JavaDomKeyLocation")
|
|
|
|
@WrapEntireClassForJNI
|
2013-04-08 13:21:52 -07:00
|
|
|
public enum DomKeyLocation {
|
|
|
|
DOM_KEY_LOCATION_STANDARD(0),
|
|
|
|
DOM_KEY_LOCATION_LEFT(1),
|
|
|
|
DOM_KEY_LOCATION_RIGHT(2),
|
|
|
|
DOM_KEY_LOCATION_NUMPAD(3),
|
|
|
|
DOM_KEY_LOCATION_MOBILE(4),
|
|
|
|
DOM_KEY_LOCATION_JOYSTICK(5);
|
|
|
|
|
|
|
|
public final int value;
|
|
|
|
|
|
|
|
private DomKeyLocation(int value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encapsulation of common IME actions.
|
2013-11-21 14:44:00 -08:00
|
|
|
@JNITarget
|
2013-04-08 13:21:52 -07:00
|
|
|
public enum ImeAction {
|
|
|
|
IME_SYNCHRONIZE(0),
|
|
|
|
IME_REPLACE_TEXT(1),
|
|
|
|
IME_SET_SELECTION(2),
|
|
|
|
IME_ADD_COMPOSITION_RANGE(3),
|
|
|
|
IME_UPDATE_COMPOSITION(4),
|
|
|
|
IME_REMOVE_COMPOSITION(5),
|
|
|
|
IME_ACKNOWLEDGE_FOCUS(6);
|
|
|
|
|
|
|
|
public final int value;
|
|
|
|
|
|
|
|
private ImeAction(int value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
|
2012-12-06 11:35:59 -08:00
|
|
|
public static final int IME_RANGE_LINE_NONE = 0;
|
|
|
|
public static final int IME_RANGE_LINE_DOTTED = 1;
|
|
|
|
public static final int IME_RANGE_LINE_DASHED = 2;
|
|
|
|
public static final int IME_RANGE_LINE_SOLID = 3;
|
|
|
|
public static final int IME_RANGE_LINE_DOUBLE = 4;
|
|
|
|
public static final int IME_RANGE_LINE_WAVY = 5;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
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-12-06 11:35:59 -08:00
|
|
|
public static final int IME_RANGE_LINECOLOR = 8;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
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;
|
|
|
|
|
2014-04-22 07:53:48 -07:00
|
|
|
public static final int ACTION_GAMEPAD_ADDED = 1;
|
|
|
|
public static final int ACTION_GAMEPAD_REMOVED = 2;
|
|
|
|
|
|
|
|
public static final int ACTION_GAMEPAD_BUTTON = 1;
|
|
|
|
public static final int ACTION_GAMEPAD_AXES = 2;
|
|
|
|
|
2013-03-10 15:43:53 -07:00
|
|
|
private final int mType;
|
|
|
|
private int mAction;
|
|
|
|
private boolean mAckNeeded;
|
|
|
|
private long mTime;
|
|
|
|
private Point[] mPoints;
|
|
|
|
private int[] mPointIndicies;
|
|
|
|
private int mPointerIndex; // index of the point that has changed
|
|
|
|
private float[] mOrientations;
|
|
|
|
private float[] mPressures;
|
|
|
|
private Point[] mPointRadii;
|
|
|
|
private Rect mRect;
|
|
|
|
private double mX;
|
|
|
|
private double mY;
|
|
|
|
private double mZ;
|
|
|
|
|
|
|
|
private int mMetaState;
|
|
|
|
private int mFlags;
|
|
|
|
private int mKeyCode;
|
2014-05-24 19:09:00 -07:00
|
|
|
private int mScanCode;
|
2013-03-10 15:43:53 -07:00
|
|
|
private int mUnicodeChar;
|
2013-03-29 07:54:01 -07:00
|
|
|
private int mBaseUnicodeChar; // mUnicodeChar without meta states applied
|
2013-12-10 08:14:54 -08:00
|
|
|
private int mDOMPrintableKeyValue;
|
2013-03-10 15:43:53 -07:00
|
|
|
private int mRepeatCount;
|
|
|
|
private int mCount;
|
|
|
|
private int mStart;
|
|
|
|
private int mEnd;
|
|
|
|
private String mCharacters;
|
|
|
|
private String mCharactersExtra;
|
2013-06-15 14:40:27 -07:00
|
|
|
private String mData;
|
2013-03-10 15:43:53 -07:00
|
|
|
private int mRangeType;
|
|
|
|
private int mRangeStyles;
|
|
|
|
private int mRangeLineStyle;
|
|
|
|
private boolean mRangeBoldLine;
|
|
|
|
private int mRangeForeColor;
|
|
|
|
private int mRangeBackColor;
|
|
|
|
private int mRangeLineColor;
|
|
|
|
private Location mLocation;
|
|
|
|
private Address mAddress;
|
2013-04-08 13:21:52 -07:00
|
|
|
private DomKeyLocation mDomKeyLocation;
|
2013-03-10 15:43:53 -07:00
|
|
|
|
2014-03-05 01:42:42 -08:00
|
|
|
private int mConnectionType;
|
2013-07-11 08:39:36 -07:00
|
|
|
private boolean mIsWifi;
|
|
|
|
private int mDHCPGateway;
|
2013-03-10 15:43:53 -07:00
|
|
|
|
|
|
|
private int mNativeWindow;
|
|
|
|
|
|
|
|
private short mScreenOrientation;
|
|
|
|
|
|
|
|
private ByteBuffer mBuffer;
|
2012-06-14 09:08:51 -07:00
|
|
|
|
2013-03-20 15:45:07 -07:00
|
|
|
private int mWidth;
|
|
|
|
private int mHeight;
|
|
|
|
|
2014-04-22 07:53:48 -07:00
|
|
|
private int mID;
|
|
|
|
private int mGamepadButton;
|
|
|
|
private boolean mGamepadButtonPressed;
|
|
|
|
private float mGamepadButtonValue;
|
|
|
|
private float[] mGamepadValues;
|
|
|
|
|
2013-09-04 06:58:23 -07:00
|
|
|
private String[] mPrefNames;
|
|
|
|
|
2013-04-08 13:21:52 -07:00
|
|
|
private GeckoEvent(NativeGeckoEvent event) {
|
|
|
|
mType = event.value;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-03-26 11:05:10 -07:00
|
|
|
public static GeckoEvent createAppBackgroundingEvent() {
|
2014-02-28 12:25:30 -08:00
|
|
|
return GeckoEvent.get(NativeGeckoEvent.APP_BACKGROUNDING);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-03-26 11:05:10 -07:00
|
|
|
public static GeckoEvent createAppForegroundingEvent() {
|
2014-02-28 12:25:30 -08:00
|
|
|
return GeckoEvent.get(NativeGeckoEvent.APP_FOREGROUNDING);
|
2012-02-08 23:18:27 -08:00
|
|
|
}
|
|
|
|
|
2013-03-10 15:43:30 -07:00
|
|
|
public static GeckoEvent createNoOpEvent() {
|
2014-02-28 12:25:30 -08:00
|
|
|
return GeckoEvent.get(NativeGeckoEvent.NOOP);
|
2012-02-08 23:18:27 -08:00
|
|
|
}
|
|
|
|
|
2013-03-19 15:26:33 -07:00
|
|
|
public static GeckoEvent createKeyEvent(KeyEvent k, int metaState) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.KEY_EVENT);
|
2013-03-19 15:26:33 -07:00
|
|
|
event.initKeyEvent(k, metaState);
|
2012-02-08 23:18:27 -08:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-03-20 15:45:07 -07:00
|
|
|
public static GeckoEvent createCompositorCreateEvent(int width, int height) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.COMPOSITOR_CREATE);
|
2013-03-20 15:45:07 -07:00
|
|
|
event.mWidth = width;
|
|
|
|
event.mHeight = height;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2012-03-28 15:00:32 -07:00
|
|
|
public static GeckoEvent createCompositorPauseEvent() {
|
2014-02-28 12:25:30 -08:00
|
|
|
return GeckoEvent.get(NativeGeckoEvent.COMPOSITOR_PAUSE);
|
2012-03-28 15:00:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createCompositorResumeEvent() {
|
2014-02-28 12:25:30 -08:00
|
|
|
return GeckoEvent.get(NativeGeckoEvent.COMPOSITOR_RESUME);
|
2012-03-28 15:00:32 -07:00
|
|
|
}
|
|
|
|
|
2013-03-19 15:26:33 -07:00
|
|
|
private void initKeyEvent(KeyEvent k, int metaState) {
|
2011-11-18 10:28:17 -08:00
|
|
|
mAction = k.getAction();
|
|
|
|
mTime = k.getEventTime();
|
2013-03-19 15:26:33 -07:00
|
|
|
// Normally we expect k.getMetaState() to reflect the current meta-state; however,
|
|
|
|
// some software-generated key events may not have k.getMetaState() set, e.g. key
|
|
|
|
// events from Swype. Therefore, it's necessary to combine the key's meta-states
|
|
|
|
// with the meta-states that we keep separately in KeyListener
|
|
|
|
mMetaState = k.getMetaState() | metaState;
|
2011-11-18 10:28:17 -08:00
|
|
|
mFlags = k.getFlags();
|
|
|
|
mKeyCode = k.getKeyCode();
|
2014-05-24 19:09:00 -07:00
|
|
|
mScanCode = k.getScanCode();
|
2013-03-29 07:54:01 -07:00
|
|
|
mUnicodeChar = k.getUnicodeChar(mMetaState);
|
|
|
|
// e.g. for Ctrl+A, Android returns 0 for mUnicodeChar,
|
|
|
|
// but Gecko expects 'a', so we return that in mBaseUnicodeChar
|
|
|
|
mBaseUnicodeChar = k.getUnicodeChar(0);
|
2012-04-19 13:55:33 -07:00
|
|
|
mRepeatCount = k.getRepeatCount();
|
2011-11-18 10:28:17 -08:00
|
|
|
mCharacters = k.getCharacters();
|
2013-12-10 08:14:54 -08:00
|
|
|
if (mUnicodeChar >= ' ') {
|
|
|
|
mDOMPrintableKeyValue = mUnicodeChar;
|
|
|
|
} else {
|
|
|
|
int unmodifiedMetaState =
|
|
|
|
mMetaState & ~(KeyEvent.META_ALT_MASK |
|
|
|
|
KeyEvent.META_CTRL_MASK |
|
|
|
|
KeyEvent.META_META_MASK);
|
|
|
|
if (unmodifiedMetaState != mMetaState) {
|
|
|
|
mDOMPrintableKeyValue = k.getUnicodeChar(unmodifiedMetaState);
|
|
|
|
}
|
|
|
|
}
|
2013-04-08 13:21:52 -07:00
|
|
|
mDomKeyLocation = isJoystickButton(mKeyCode) ? DomKeyLocation.DOM_KEY_LOCATION_JOYSTICK
|
|
|
|
: DomKeyLocation.DOM_KEY_LOCATION_MOBILE;
|
2012-09-12 17:48:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.NATIVE_GESTURE_EVENT);
|
2012-11-12 16:07:41 -08:00
|
|
|
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);
|
2013-06-06 11:05:32 -07:00
|
|
|
geckoPoint = GeckoAppShell.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
|
|
|
}
|
|
|
|
|
2013-04-26 10:24:28 -07:00
|
|
|
/**
|
|
|
|
* Creates a GeckoEvent that contains the data from the MotionEvent.
|
|
|
|
* The keepInViewCoordinates parameter can be set to false to convert from the Java
|
|
|
|
* coordinate system (device pixels relative to the LayerView) to a coordinate system
|
|
|
|
* relative to gecko's coordinate system (CSS pixels relative to gecko scroll position).
|
|
|
|
*/
|
|
|
|
public static GeckoEvent createMotionEvent(MotionEvent m, boolean keepInViewCoordinates) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.MOTION_EVENT);
|
2013-04-26 10:24:28 -07:00
|
|
|
event.initMotionEvent(m, keepInViewCoordinates);
|
2012-02-08 23:18:27 -08:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-04-26 10:24:28 -07:00
|
|
|
private void initMotionEvent(MotionEvent m, boolean keepInViewCoordinates) {
|
2013-04-17 14:39:11 -07:00
|
|
|
mAction = m.getActionMasked();
|
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
|
|
|
|
2013-04-17 14:39:11 -07:00
|
|
|
switch (mAction) {
|
2012-01-24 16:31:33 -08:00
|
|
|
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];
|
2013-04-17 14:39:11 -07:00
|
|
|
mPointerIndex = m.getActionIndex();
|
2012-01-24 16:31:33 -08:00
|
|
|
for (int i = 0; i < mCount; i++) {
|
2013-04-26 10:24:28 -07:00
|
|
|
addMotionPoint(i, i, m, keepInViewCoordinates);
|
2012-01-24 16:31:33 -08:00
|
|
|
}
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-26 10:24:28 -07:00
|
|
|
private void addMotionPoint(int index, int eventIndex, MotionEvent event, boolean keepInViewCoordinates) {
|
2012-02-07 17:06:47 -08:00
|
|
|
try {
|
|
|
|
PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
|
2013-04-26 10:24:28 -07:00
|
|
|
if (!keepInViewCoordinates) {
|
2013-05-24 09:21:01 -07:00
|
|
|
geckoPoint = GeckoAppShell.getLayerView().convertViewPointToLayerPoint(geckoPoint);
|
2013-04-26 10:24:28 -07:00
|
|
|
}
|
2013-04-08 13:21:52 -07:00
|
|
|
|
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;
|
2013-04-08 13:21:52 -07:00
|
|
|
|
2012-02-07 17:06:47 -08:00
|
|
|
// 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);
|
2013-05-24 09:21:01 -07:00
|
|
|
Resources resources = GeckoAppShell.getContext().getResources();
|
2012-08-01 14:56:26 -07:00
|
|
|
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
|
|
|
}
|
2013-07-04 06:02:29 -07:00
|
|
|
if (!keepInViewCoordinates) {
|
|
|
|
// If we are converting to gecko CSS pixels, then we should adjust the
|
|
|
|
// radii as well
|
|
|
|
float zoom = GeckoAppShell.getLayerView().getViewportMetrics().zoomFactor;
|
|
|
|
mPointRadii[index].x /= zoom;
|
|
|
|
mPointRadii[index].y /= zoom;
|
|
|
|
}
|
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:
|
2014-02-28 12:25:30 -08:00
|
|
|
event = GeckoEvent.get(NativeGeckoEvent.SENSOR_EVENT);
|
2012-03-13 16:57:51 -07:00
|
|
|
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*/ :
|
2014-02-28 12:25:30 -08:00
|
|
|
event = GeckoEvent.get(NativeGeckoEvent.SENSOR_EVENT);
|
2012-03-13 16:57:51 -07:00
|
|
|
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:
|
2014-02-28 12:25:30 -08:00
|
|
|
event = GeckoEvent.get(NativeGeckoEvent.SENSOR_EVENT);
|
2012-03-13 16:57:51 -07:00
|
|
|
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:
|
2014-02-28 12:25:30 -08:00
|
|
|
event = GeckoEvent.get(NativeGeckoEvent.SENSOR_EVENT);
|
2012-03-13 16:57:51 -07:00
|
|
|
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:
|
2014-02-28 12:25:30 -08:00
|
|
|
event = GeckoEvent.get(NativeGeckoEvent.SENSOR_EVENT);
|
2012-03-20 23:36:17 -07:00
|
|
|
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:
|
2014-02-28 12:25:30 -08:00
|
|
|
event = GeckoEvent.get(NativeGeckoEvent.SENSOR_EVENT);
|
2012-05-02 09:43:45 -07:00
|
|
|
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) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.LOCATION_EVENT);
|
2012-02-08 23:18:27 -08:00
|
|
|
event.mLocation = l;
|
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-04-08 13:21:52 -07:00
|
|
|
public static GeckoEvent createIMEEvent(ImeAction action) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.IME_EVENT);
|
2013-04-08 13:21:52 -07:00
|
|
|
event.mAction = action.value;
|
2012-02-08 23:18:27 -08:00
|
|
|
return event;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-03-29 07:54:01 -07:00
|
|
|
public static GeckoEvent createIMEKeyEvent(KeyEvent k) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.IME_KEY_EVENT);
|
2013-03-29 07:54:01 -07:00
|
|
|
event.initKeyEvent(k, 0);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2012-11-01 13:11:02 -07:00
|
|
|
public static GeckoEvent createIMEReplaceEvent(int start, int end,
|
|
|
|
String text) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.IME_EVENT);
|
2013-04-08 13:21:52 -07:00
|
|
|
event.mAction = ImeAction.IME_REPLACE_TEXT.value;
|
2012-11-01 13:11:02 -07:00
|
|
|
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) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.IME_EVENT);
|
2013-04-08 13:21:52 -07:00
|
|
|
event.mAction = ImeAction.IME_SET_SELECTION.value;
|
2012-11-01 13:11:02 -07:00
|
|
|
event.mStart = start;
|
|
|
|
event.mEnd = end;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createIMECompositionEvent(int start, int end) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.IME_EVENT);
|
2013-04-08 13:21:52 -07:00
|
|
|
event.mAction = ImeAction.IME_UPDATE_COMPOSITION.value;
|
2012-11-01 13:11:02 -07:00
|
|
|
event.mStart = start;
|
|
|
|
event.mEnd = end;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createIMERangeEvent(int start,
|
|
|
|
int end, int rangeType,
|
|
|
|
int rangeStyles,
|
2012-12-06 11:35:59 -08:00
|
|
|
int rangeLineStyle,
|
|
|
|
boolean rangeBoldLine,
|
2012-11-01 13:11:02 -07:00
|
|
|
int rangeForeColor,
|
2012-12-06 11:35:59 -08:00
|
|
|
int rangeBackColor,
|
|
|
|
int rangeLineColor) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.IME_EVENT);
|
2013-04-08 13:21:52 -07:00
|
|
|
event.mAction = ImeAction.IME_ADD_COMPOSITION_RANGE.value;
|
2012-11-01 13:11:02 -07:00
|
|
|
event.mStart = start;
|
|
|
|
event.mEnd = end;
|
|
|
|
event.mRangeType = rangeType;
|
|
|
|
event.mRangeStyles = rangeStyles;
|
2012-12-06 11:35:59 -08:00
|
|
|
event.mRangeLineStyle = rangeLineStyle;
|
|
|
|
event.mRangeBoldLine = rangeBoldLine;
|
2012-11-01 13:11:02 -07:00
|
|
|
event.mRangeForeColor = rangeForeColor;
|
|
|
|
event.mRangeBackColor = rangeBackColor;
|
2012-12-06 11:35:59 -08:00
|
|
|
event.mRangeLineColor = rangeLineColor;
|
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) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.DRAW);
|
2012-02-08 23:18:27 -08:00
|
|
|
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) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.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
|
|
|
}
|
|
|
|
|
2013-12-06 11:43:11 -08:00
|
|
|
@RobocopTarget
|
2012-02-08 23:18:27 -08:00
|
|
|
public static GeckoEvent createBroadcastEvent(String subject, String data) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.BROADCAST);
|
2012-02-08 23:18:27 -08:00
|
|
|
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) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.VIEWPORT);
|
2012-02-08 23:18:27 -08:00
|
|
|
event.mCharacters = "Viewport:Change";
|
2013-07-02 05:12:17 -07:00
|
|
|
StringBuilder sb = new StringBuilder(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)
|
2013-04-25 10:47:08 -07:00
|
|
|
.append(", \"fixedMarginLeft\" : ").append(metrics.marginLeft)
|
|
|
|
.append(", \"fixedMarginTop\" : ").append(metrics.marginTop)
|
|
|
|
.append(", \"fixedMarginRight\" : ").append(metrics.marginRight)
|
|
|
|
.append(", \"fixedMarginBottom\" : ").append(metrics.marginBottom)
|
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) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.LOAD_URI);
|
2012-02-08 23:18:27 -08:00
|
|
|
event.mCharacters = uri;
|
2012-04-13 19:45:25 -07:00
|
|
|
event.mCharactersExtra = "";
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createWebappLoadEvent(String uri) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.LOAD_URI);
|
2012-04-13 19:45:25 -07:00
|
|
|
event.mCharacters = uri;
|
|
|
|
event.mCharactersExtra = "-webapp";
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createBookmarkLoadEvent(String uri) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.LOAD_URI);
|
2012-04-13 19:45:25 -07:00
|
|
|
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) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.VISITED);
|
2012-02-08 23:18:27 -08:00
|
|
|
event.mCharacters = data;
|
|
|
|
return event;
|
2012-01-05 16:14:23 -08:00
|
|
|
}
|
2012-01-17 10:40:39 -08:00
|
|
|
|
2014-03-05 01:42:42 -08:00
|
|
|
public static GeckoEvent createNetworkEvent(int connectionType, boolean isWifi, int DHCPGateway) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.NETWORK_CHANGED);
|
2014-03-05 01:42:42 -08:00
|
|
|
event.mConnectionType = connectionType;
|
2013-07-11 08:39:36 -07:00
|
|
|
event.mIsWifi = isWifi;
|
|
|
|
event.mDHCPGateway = DHCPGateway;
|
2012-02-08 23:18:27 -08:00
|
|
|
return event;
|
2012-01-17 10:40:39 -08:00
|
|
|
}
|
2012-02-17 10:52:26 -08:00
|
|
|
|
2012-12-15 07:43:52 -08:00
|
|
|
public static GeckoEvent createThumbnailEvent(int tabId, int bufw, int bufh, ByteBuffer buffer) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.THUMBNAIL);
|
2012-12-15 07:43:52 -08:00
|
|
|
event.mPoints = new Point[1];
|
|
|
|
event.mPoints[0] = new Point(bufw, bufh);
|
2012-02-17 10:52:26 -08:00
|
|
|
event.mMetaState = tabId;
|
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) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.SCREENORIENTATION_CHANGED);
|
2012-03-20 06:09:45 -07:00
|
|
|
event.mScreenOrientation = aScreenOrientation;
|
|
|
|
return event;
|
|
|
|
}
|
2013-03-10 15:43:30 -07:00
|
|
|
|
2013-06-15 14:40:27 -07:00
|
|
|
public static GeckoEvent createCallObserverEvent(String observerKey, String topic, String data) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.CALL_OBSERVER);
|
2013-06-15 14:40:27 -07:00
|
|
|
event.mCharacters = observerKey;
|
|
|
|
event.mCharactersExtra = topic;
|
|
|
|
event.mData = data;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-06-19 10:55:35 -07:00
|
|
|
public static GeckoEvent createRemoveObserverEvent(String observerKey) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.REMOVE_OBSERVER);
|
2013-06-19 10:55:35 -07:00
|
|
|
event.mCharacters = observerKey;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-12-06 11:43:11 -08:00
|
|
|
@RobocopTarget
|
2013-09-04 06:58:23 -07:00
|
|
|
public static GeckoEvent createPreferencesObserveEvent(int requestId, String[] prefNames) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.PREFERENCES_OBSERVE);
|
2013-09-04 06:58:23 -07:00
|
|
|
event.mCount = requestId;
|
|
|
|
event.mPrefNames = prefNames;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-12-06 11:43:11 -08:00
|
|
|
@RobocopTarget
|
2013-09-04 06:58:23 -07:00
|
|
|
public static GeckoEvent createPreferencesGetEvent(int requestId, String[] prefNames) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.PREFERENCES_GET);
|
2013-09-04 06:58:23 -07:00
|
|
|
event.mCount = requestId;
|
|
|
|
event.mPrefNames = prefNames;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-12-06 11:43:11 -08:00
|
|
|
@RobocopTarget
|
2013-09-04 06:58:23 -07:00
|
|
|
public static GeckoEvent createPreferencesRemoveObserversEvent(int requestId) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.PREFERENCES_REMOVE_OBSERVERS);
|
2013-09-04 06:58:23 -07:00
|
|
|
event.mCount = requestId;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-06-17 14:09:09 -07:00
|
|
|
public static GeckoEvent createLowMemoryEvent(int level) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.LOW_MEMORY);
|
2013-06-17 14:09:09 -07:00
|
|
|
event.mMetaState = level;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createNetworkLinkChangeEvent(String status) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.NETWORK_LINK_CHANGE);
|
2013-06-17 14:09:09 -07:00
|
|
|
event.mCharacters = status;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-08-15 12:03:47 -07:00
|
|
|
public static GeckoEvent createTelemetryHistogramAddEvent(String histogram,
|
|
|
|
int value) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.TELEMETRY_HISTOGRAM_ADD);
|
2013-08-15 12:03:47 -07:00
|
|
|
event.mCharacters = histogram;
|
|
|
|
event.mCount = value;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-12-10 10:41:34 -08:00
|
|
|
public static GeckoEvent createTelemetryUISessionStartEvent(String session, long timestamp) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.TELEMETRY_UI_SESSION_START);
|
2013-12-10 10:41:34 -08:00
|
|
|
event.mCharacters = session;
|
|
|
|
event.mTime = timestamp;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createTelemetryUISessionStopEvent(String session, String reason, long timestamp) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.TELEMETRY_UI_SESSION_STOP);
|
2013-12-10 10:41:34 -08:00
|
|
|
event.mCharacters = session;
|
|
|
|
event.mCharactersExtra = reason;
|
|
|
|
event.mTime = timestamp;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createTelemetryUIEvent(String action, String method, long timestamp, String extras) {
|
2014-02-28 12:25:30 -08:00
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.TELEMETRY_UI_EVENT);
|
2013-12-10 10:41:34 -08:00
|
|
|
event.mData = action;
|
|
|
|
event.mCharacters = method;
|
|
|
|
event.mCharactersExtra = extras;
|
|
|
|
event.mTime = timestamp;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2014-04-22 07:53:48 -07:00
|
|
|
public static GeckoEvent createGamepadAddRemoveEvent(int id, boolean added) {
|
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.GAMEPAD_ADDREMOVE);
|
|
|
|
event.mID = id;
|
|
|
|
event.mAction = added ? ACTION_GAMEPAD_ADDED : ACTION_GAMEPAD_REMOVED;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int boolArrayToBitfield(boolean[] array) {
|
|
|
|
int bits = 0;
|
|
|
|
for (int i = 0; i < array.length; i++) {
|
|
|
|
if (array[i]) {
|
|
|
|
bits |= 1<<i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createGamepadButtonEvent(int id,
|
|
|
|
int which,
|
|
|
|
boolean pressed,
|
|
|
|
float value) {
|
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.GAMEPAD_DATA);
|
|
|
|
event.mID = id;
|
|
|
|
event.mAction = ACTION_GAMEPAD_BUTTON;
|
|
|
|
event.mGamepadButton = which;
|
|
|
|
event.mGamepadButtonPressed = pressed;
|
|
|
|
event.mGamepadButtonValue = value;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GeckoEvent createGamepadAxisEvent(int id, boolean[] valid,
|
|
|
|
float[] values) {
|
|
|
|
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.GAMEPAD_DATA);
|
|
|
|
event.mID = id;
|
|
|
|
event.mAction = ACTION_GAMEPAD_AXES;
|
|
|
|
event.mFlags = boolArrayToBitfield(valid);
|
|
|
|
event.mCount = values.length;
|
|
|
|
event.mGamepadValues = values;
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-03-10 15:43:30 -07:00
|
|
|
public void setAckNeeded(boolean ackNeeded) {
|
|
|
|
mAckNeeded = ackNeeded;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|