Bug 1291373 - [geckoview] part 4, Remove GeckoEvent and AndroidGeckoEvent r=jchen

This commit is contained in:
Randall Barker 2016-08-08 17:15:41 -07:00
Родитель 9a3fae864f
Коммит 983cc6b2d1
44 изменённых файлов: 10 добавлений и 1883 удалений

Просмотреть файл

@ -15,6 +15,8 @@
#include "mozilla/Services.h"
#include "nsIMobileMessageDatabaseService.h"
#include "nsIObserverService.h"
#include "nsThreadUtils.h"
#include "AndroidJavaWrappers.h"
using namespace mozilla::dom;
using namespace mozilla::dom::mobilemessage;

Просмотреть файл

@ -8,7 +8,6 @@ import java.lang.IllegalArgumentException;
import java.util.HashMap;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.db.BrowserContract.FormHistory;
import org.mozilla.gecko.db.BrowserContract.DeletedFormHistory;
import org.mozilla.gecko.db.BrowserContract;

Просмотреть файл

@ -9,7 +9,6 @@ import java.util.HashMap;
import org.mozilla.gecko.CrashHandler;
import org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoMessageReceiver;
import org.mozilla.gecko.NSSBridge;
import org.mozilla.gecko.db.BrowserContract.DeletedPasswords;

Просмотреть файл

@ -39,7 +39,6 @@ import org.json.JSONObject;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.annotation.WrapForJNI;

Просмотреть файл

@ -9,7 +9,6 @@ import org.mozilla.gecko.AdjustConstants;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.json.JSONException;
import org.json.JSONObject;

Просмотреть файл

@ -7,7 +7,6 @@ package org.mozilla.gecko.dlc;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.dlc.catalog.DownloadContent;
import org.mozilla.gecko.dlc.catalog.DownloadContentCatalog;
import org.mozilla.gecko.util.HardwareUtils;

Просмотреть файл

@ -9,7 +9,6 @@ import org.json.JSONObject;
import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.R;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.animation.PropertyAnimator.Property;

Просмотреть файл

@ -6,7 +6,6 @@
package org.mozilla.gecko.home;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.R;
import org.mozilla.gecko.home.HomeConfig.AuthConfig;
import org.mozilla.gecko.home.HomeConfig.PanelConfig;

Просмотреть файл

@ -15,7 +15,6 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.home.HomeConfig.PanelConfig;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.ThreadUtils;

Просмотреть файл

@ -8,7 +8,6 @@ package org.mozilla.gecko.home;
import org.mozilla.gecko.R;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.home.PanelLayout.DatasetBacked;
import org.mozilla.gecko.home.PanelLayout.FilterManager;

Просмотреть файл

@ -6,7 +6,6 @@
package org.mozilla.gecko.preferences;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;

Просмотреть файл

@ -15,7 +15,6 @@ import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.TelemetryContract.Method;

Просмотреть файл

@ -9,7 +9,6 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.R;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.util.ThreadUtils;

Просмотреть файл

@ -9,7 +9,6 @@ import java.util.List;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.R;
import android.content.Context;

Просмотреть файл

@ -7,7 +7,6 @@ package org.mozilla.gecko.tabs;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;

Просмотреть файл

@ -7,7 +7,6 @@ package org.mozilla.gecko.toolbar;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.R;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.util.EventCallback;

Просмотреть файл

@ -21,7 +21,6 @@ import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.R;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.SiteIdentity;
import org.mozilla.gecko.SiteIdentity.SecurityMode;
import org.mozilla.gecko.SiteIdentity.MixedMode;

Просмотреть файл

@ -212,7 +212,6 @@ geckoview_java_files = [
'GeckoEditable.java',
'GeckoEditableClient.java',
'GeckoEditableListener.java',
'GeckoEvent.java',
'GeckoHalDefines.java',
'GeckoInputConnection.java',
'GeckoJavaSampler.java',

Просмотреть файл

@ -6,7 +6,6 @@ package org.mozilla.gecko;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoEventListener;

Просмотреть файл

@ -270,45 +270,12 @@ public class GeckoAppShell
return sLayerView;
}
/**
* If the Gecko thread is running, immediately dispatches the event to
* Gecko.
*
* If the Gecko thread is not running, queues the event. If the queue is
* full, throws {@link IllegalStateException}.
*
* Queued events will be dispatched in order of arrival when the Gecko
* thread becomes live.
*
* This method can be called from any thread.
*
* @param e
* the event to dispatch. Cannot be null.
*/
@RobocopTarget
public static void sendEventToGecko(GeckoEvent e) {
if (e == null) {
throw new IllegalArgumentException("e cannot be null.");
}
if (GeckoThread.isRunning()) {
notifyGeckoOfEvent(e);
// Gecko will copy the event data into a normal C++ object.
// We can recycle the event now.
e.recycle();
return;
}
GeckoThread.addPendingEvent(e);
}
/**
* Sends an asynchronous request to Gecko.
*
* The response data will be passed to {@link GeckoRequest#onResponse(NativeJSObject)} if the
* request succeeds; otherwise, {@link GeckoRequest#onError()} will fire.
*
* This method follows the same queuing conditions as {@link #sendEventToGecko(GeckoEvent)}.
* It can be called from any thread. The GeckoRequest callbacks will be executed on the Gecko thread.
*
* @param request The request to dispatch. Cannot be null.
@ -332,9 +299,6 @@ public class GeckoAppShell
notifyObservers(request.getName(), request.getData());
}
// Tell the Gecko event loop that an event is available.
public static native void notifyGeckoOfEvent(GeckoEvent event);
// Synchronously notify a Gecko observer; must be called from Gecko thread.
@WrapForJNI(calledFrom = "gecko")
public static native void syncNotifyObservers(String topic, String data);

Просмотреть файл

@ -1,256 +0,0 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* 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/. */
package org.mozilla.gecko;
import java.nio.ByteBuffer;
import java.util.concurrent.ArrayBlockingQueue;
import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.gfx.DisplayPortMetrics;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.SystemClock;
import android.util.Log;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.MotionEvent;
import org.mozilla.gecko.annotation.JNITarget;
import org.mozilla.gecko.annotation.RobocopTarget;
/**
* 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.
*/
@JNITarget
public class GeckoEvent {
private static final String LOGTAG = "GeckoEvent";
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 final 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);
}
}
// Make sure to keep these values in sync with the enum in
// AndroidGeckoEvent in widget/android/AndroidJavaWrappers.h
@JNITarget
public enum NativeGeckoEvent {
MOTION_EVENT(2),
VIEWPORT(20),
NATIVE_GESTURE_EVENT(31),
LONG_PRESS(47);
public final int value;
private NativeGeckoEvent(int value) {
this.value = value;
}
}
public static final int ACTION_MAGNIFY_START = 11;
public static final int ACTION_MAGNIFY = 12;
public static final int ACTION_MAGNIFY_END = 13;
private final int mType;
private int mAction;
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 int[] mToolTypes;
private Point[] mPointRadii;
private double mX;
private int mMetaState;
private int mCount;
private String mCharacters;
private String mCharactersExtra;
private GeckoEvent(NativeGeckoEvent event) {
mType = event.value;
}
public static GeckoEvent createNativeGestureEvent(int action, PointF pt, double size) {
try {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.NATIVE_GESTURE_EVENT);
event.mAction = action;
event.mCount = 1;
event.mPoints = new Point[1];
PointF geckoPoint = new PointF(pt.x, pt.y);
geckoPoint = GeckoAppShell.getLayerView().convertViewPointToLayerPoint(geckoPoint);
if (geckoPoint == null) {
// This could happen if Gecko isn't ready yet.
return null;
}
event.mPoints[0] = new Point((int)Math.floor(geckoPoint.x), (int)Math.floor(geckoPoint.y));
event.mX = size;
event.mTime = System.currentTimeMillis();
return event;
} catch (Exception e) {
// This can happen if Gecko isn't ready yet
return null;
}
}
/**
* 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) {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.MOTION_EVENT);
event.initMotionEvent(m, keepInViewCoordinates);
return event;
}
/**
* Creates a GeckoEvent that contains the data from the LongPressEvent, to be
* dispatched in CSS pixels relative to gecko's scroll position.
*/
public static GeckoEvent createLongPressEvent(MotionEvent m) {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.LONG_PRESS);
event.initMotionEvent(m, false);
return event;
}
private void initMotionEvent(MotionEvent m, boolean keepInViewCoordinates) {
mAction = m.getActionMasked();
mTime = (System.currentTimeMillis() - SystemClock.elapsedRealtime()) + m.getEventTime();
mMetaState = m.getMetaState();
switch (mAction) {
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_HOVER_ENTER:
case MotionEvent.ACTION_HOVER_MOVE:
case MotionEvent.ACTION_HOVER_EXIT: {
mCount = m.getPointerCount();
mPoints = new Point[mCount];
mPointIndicies = new int[mCount];
mOrientations = new float[mCount];
mPressures = new float[mCount];
mToolTypes = new int[mCount];
mPointRadii = new Point[mCount];
mPointerIndex = m.getActionIndex();
for (int i = 0; i < mCount; i++) {
addMotionPoint(i, i, m, keepInViewCoordinates);
}
break;
}
default: {
mCount = 0;
mPointerIndex = -1;
mPoints = new Point[mCount];
mPointIndicies = new int[mCount];
mOrientations = new float[mCount];
mPressures = new float[mCount];
mToolTypes = new int[mCount];
mPointRadii = new Point[mCount];
}
}
}
private void addMotionPoint(int index, int eventIndex, MotionEvent event, boolean keepInViewCoordinates) {
try {
PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
if (!keepInViewCoordinates) {
geckoPoint = GeckoAppShell.getLayerView().convertViewPointToLayerPoint(geckoPoint);
}
mPoints[index] = new Point((int)Math.floor(geckoPoint.x), (int)Math.floor(geckoPoint.y));
mPointIndicies[index] = event.getPointerId(eventIndex);
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);
}
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;
}
mPressures[index] = event.getPressure(eventIndex);
if (Versions.feature14Plus) {
mToolTypes[index] = event.getToolType(index);
}
} catch (Exception ex) {
Log.e(LOGTAG, "Error creating motion point " + index, ex);
mPointRadii[index] = new Point(0, 0);
mPoints[index] = new Point(0, 0);
}
}
public static GeckoEvent createViewportEvent(ImmutableViewportMetrics metrics, DisplayPortMetrics displayPort) {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.VIEWPORT);
event.mCharacters = "Viewport:Change";
StringBuilder sb = new StringBuilder(256);
sb.append("{ \"x\" : ").append(metrics.viewportRectLeft)
.append(", \"y\" : ").append(metrics.viewportRectTop)
.append(", \"zoom\" : ").append(metrics.zoomFactor)
.append(", \"displayPort\" :").append(displayPort.toJSON())
.append('}');
event.mCharactersExtra = sb.toString();
return event;
}
}

Просмотреть файл

@ -318,7 +318,7 @@ public class GeckoNetworkManager extends BroadcastReceiver implements NativeEven
private static native void onStatusChanged(String status);
/**
* Send current network state and connection type as a GeckoEvent, to whomever is listening.
* Send current network state and connection type to whomever is listening.
*/
private void sendNetworkStateToListeners(final Context context) {
if (currentConnectionType != previousConnectionType ||

Просмотреть файл

@ -346,12 +346,6 @@ public class GeckoThread extends Thread {
// Mark as handled.
QUEUED_CALLS.set(i, null);
if (call.method == null) {
final GeckoEvent e = (GeckoEvent) call.target;
GeckoAppShell.notifyGeckoOfEvent(e);
e.recycle();
continue;
}
invokeMethod(call.method, call.target, call.args);
}
if (lastSkipped < 0) {
@ -534,18 +528,6 @@ public class GeckoThread extends Thread {
Looper.myQueue().removeIdleHandler(idleHandler);
}
public static void addPendingEvent(final GeckoEvent e) {
synchronized (QUEUED_CALLS) {
if (isRunning()) {
// We may just have switched to running state.
GeckoAppShell.notifyGeckoOfEvent(e);
e.recycle();
} else {
QUEUED_CALLS.add(new QueuedCall(null, e, null, State.RUNNING));
}
}
}
@WrapForJNI(calledFrom = "gecko")
private static boolean pumpMessageLoop(final Message msg) {
final Handler geckoHandler = ThreadUtils.sGeckoHandler;

Просмотреть файл

@ -8,7 +8,6 @@ package org.mozilla.gecko.gfx;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.gfx.LayerView.DrawListener;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
@ -404,23 +403,6 @@ class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
return mDisplayPort;
}
@WrapForJNI(calledFrom = "gecko")
DisplayPortMetrics getDisplayPort(boolean pageSizeUpdate, boolean isBrowserContentDisplayed, int tabId, ImmutableViewportMetrics metrics) {
Tabs tabs = Tabs.getInstance();
if (isBrowserContentDisplayed && tabs.isSelectedTabId(tabId)) {
// for foreground tabs, send the viewport update unless the document
// displayed is different from the content document. In that case, just
// calculate the display port.
return handleViewportMessage(metrics, pageSizeUpdate ? ViewportMessageType.PAGE_SIZE : ViewportMessageType.UPDATE);
} else {
// for background tabs, request a new display port calculation, so that
// when we do switch to that tab, we have the correct display port and
// don't need to draw twice (once to allow the first-paint viewport to
// get to java, and again once java figures out the display port).
return DisplayPortCalculator.calculate(metrics, null);
}
}
@WrapForJNI(calledFrom = "gecko")
void contentDocumentChanged() {
mContentDocumentIsDisplayed = false;

Просмотреть файл

@ -16,7 +16,6 @@ import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAccessibility;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.mozglue.JNIObject;
import org.mozilla.gecko.Tab;
@ -65,8 +64,6 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
private Listener mListener;
private PointF mInitialTouchPoint;
private float mSurfaceTranslation;
/* This should only be modified on the Java UI thread. */
@ -219,34 +216,6 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
(int)event.getToolMinor() / 2);
}
private boolean sendEventToGecko(MotionEvent event) {
if (!mLayerClient.isGeckoReady()) {
return false;
}
int action = event.getActionMasked();
PointF point = new PointF(event.getX(), event.getY());
if (action == MotionEvent.ACTION_DOWN) {
mInitialTouchPoint = point;
}
if (mInitialTouchPoint != null && action == MotionEvent.ACTION_MOVE) {
Point p = getEventRadius(event);
if (PointUtils.subtract(point, mInitialTouchPoint).length() <
Math.max(PanZoomController.CLICK_THRESHOLD, Math.min(Math.min(p.x, p.y), PanZoomController.PAN_THRESHOLD))) {
// Don't send the touchmove event if if the users finger hasn't moved far.
// Necessary for Google Maps to work correctly. See bug 771099.
return true;
} else {
mInitialTouchPoint = null;
}
}
GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event, false));
return true;
}
public void showSurface() {
// Fix this if TextureView support is turned back on above
mSurfaceView.setVisibility(View.VISIBLE);
@ -301,7 +270,7 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
if (mPanZoomController != null && mPanZoomController.onTouchEvent(event)) {
return true;
}
return sendEventToGecko(event);
return false;
}
@Override
@ -323,7 +292,7 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
return true;
}
return sendEventToGecko(event);
return false;
}
@Override
@ -797,17 +766,10 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
@Override
public void setOverScrollMode(int overscrollMode) {
super.setOverScrollMode(overscrollMode);
if (mPanZoomController != null) {
mPanZoomController.setOverScrollMode(overscrollMode);
}
}
@Override
public int getOverScrollMode() {
if (mPanZoomController != null) {
return mPanZoomController.getOverScrollMode();
}
return super.getOverScrollMode();
}

Просмотреть файл

@ -6,7 +6,6 @@
package org.mozilla.gecko.gfx;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.annotation.WrapForJNI;
@ -255,22 +254,6 @@ class NativePanZoomController extends JNIObject implements PanZoomController {
@Override @WrapForJNI(calledFrom = "ui") // JNIObject
protected native void disposeNative();
@Override
public void setOverScrollMode(int overscrollMode) {
// FIXME implement this
}
@Override
public int getOverScrollMode() {
// FIXME implement this
return 0;
}
@WrapForJNI(calledFrom = "ui")
private void requestContentRepaint(float x, float y, float width, float height, float resolution) {
mTarget.forceRedraw(new DisplayPortMetrics(x, y, x + width, y + height, resolution));
}
@Override
public void setOverscrollHandler(final Overscroll handler) {
mOverscroll = handler;

Просмотреть файл

@ -42,9 +42,6 @@ public interface PanZoomController {
public void abortPanning();
public void abortAnimation();
public void setOverScrollMode(int overscrollMode);
public int getOverScrollMode();
public void setOverscrollHandler(final Overscroll controller);
public void setIsLongpressEnabled(boolean isLongpressEnabled);

Просмотреть файл

@ -6,7 +6,6 @@
package org.mozilla.gecko.gfx;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.util.GeckoEventListener;

Просмотреть файл

@ -25,7 +25,6 @@ import org.mozilla.gecko.FennecNativeActions;
import org.mozilla.gecko.FennecNativeDriver;
import org.mozilla.gecko.FennecTalosAssert;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.updater.UpdateServiceHelper;

Просмотреть файл

@ -8,7 +8,6 @@ import static org.mozilla.gecko.tests.helpers.AssertionHelper.fFail;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.util.GeckoEventListener;
import org.json.JSONException;

Просмотреть файл

@ -8,7 +8,6 @@ import static org.mozilla.gecko.tests.helpers.AssertionHelper.fFail;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.util.GeckoEventListener;
import org.json.JSONException;

Просмотреть файл

@ -172,25 +172,6 @@ Java_org_mozilla_gecko_GeckoAppShell_onFullScreenPluginHidden(JNIEnv * arg0, jcl
#ifdef JNI_STUBS
typedef void (*Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent_t)(JNIEnv *, jclass, jobject);
static Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent_t f_Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent;
extern "C" NS_EXPORT void MOZ_JNICALL
Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent(JNIEnv * arg0, jclass arg1, jobject arg2) {
if (!f_Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return ;
}
f_Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent(arg0, arg1, arg2);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent", &f_Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent);
#endif
#ifdef JNI_STUBS
typedef void (*Java_org_mozilla_gecko_GeckoAppShell_syncNotifyObservers_t)(JNIEnv *, jclass, jstring, jstring);
static Java_org_mozilla_gecko_GeckoAppShell_syncNotifyObservers_t f_Java_org_mozilla_gecko_GeckoAppShell_syncNotifyObservers;
extern "C" NS_EXPORT void MOZ_JNICALL

Просмотреть файл

@ -230,8 +230,6 @@ AndroidBridge::AndroidBridge()
jInputStream = inputStream.getGlobalRef();
jClose = inputStream.getMethod("close", "()V");
jAvailable = inputStream.getMethod("available", "()I");
InitAndroidJavaWrappers(jEnv);
}
// Raw JNIEnv variants.
@ -275,19 +273,6 @@ jstring AndroidBridge::NewJavaString(AutoLocalJNIFrame* frame, const nsACString&
return NewJavaString(frame, NS_ConvertUTF8toUTF16(string));
}
void AutoGlobalWrappedJavaObject::Dispose() {
if (isNull()) {
return;
}
GetEnvForThread()->DeleteGlobalRef(wrapped_obj);
wrapped_obj = nullptr;
}
AutoGlobalWrappedJavaObject::~AutoGlobalWrappedJavaObject() {
Dispose();
}
static void
getHandlersFromStringArray(JNIEnv *aJNIEnv, jobjectArray jArr, jsize aLen,
nsIMutableArray *aHandlersArray,
@ -1233,12 +1218,6 @@ NS_IMETHODIMP nsAndroidBridge::HandleGeckoMessage(JS::HandleValue val,
return NS_OK;
}
NS_IMETHODIMP nsAndroidBridge::GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort)
{
AndroidBridge::Bridge()->GetDisplayPort(aPageSizeUpdate, aIsBrowserContentDisplayed, tabId, metrics, displayPort);
return NS_OK;
}
NS_IMETHODIMP nsAndroidBridge::ContentDocumentChanged()
{
AndroidBridge::Bridge()->ContentDocumentChanged();
@ -1437,61 +1416,6 @@ AndroidBridge::GetFrameNameJavaProfiling(uint32_t aThreadId, uint32_t aSampleId,
return true;
}
void
AndroidBridge::GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort)
{
ALOG_BRIDGE("Enter: %s", __PRETTY_FUNCTION__);
if (!mLayerClient) {
ALOG_BRIDGE("Exceptional Exit: %s", __PRETTY_FUNCTION__);
return;
}
JNIEnv* const env = jni::GetGeckoThreadEnv();
AutoLocalJNIFrame jniFrame(env, 1);
int width, height;
float x, y,
pageLeft, pageTop, pageRight, pageBottom,
cssPageLeft, cssPageTop, cssPageRight, cssPageBottom,
zoom;
metrics->GetX(&x);
metrics->GetY(&y);
metrics->GetWidth(&width);
metrics->GetHeight(&height);
metrics->GetPageLeft(&pageLeft);
metrics->GetPageTop(&pageTop);
metrics->GetPageRight(&pageRight);
metrics->GetPageBottom(&pageBottom);
metrics->GetCssPageLeft(&cssPageLeft);
metrics->GetCssPageTop(&cssPageTop);
metrics->GetCssPageRight(&cssPageRight);
metrics->GetCssPageBottom(&cssPageBottom);
metrics->GetZoom(&zoom);
auto jmetrics = ImmutableViewportMetrics::New(
pageLeft, pageTop, pageRight, pageBottom,
cssPageLeft, cssPageTop, cssPageRight, cssPageBottom,
x, y, width, height,
zoom);
DisplayPortMetrics::LocalRef displayPortMetrics = mLayerClient->GetDisplayPort(
aPageSizeUpdate, aIsBrowserContentDisplayed, tabId, jmetrics);
if (!displayPortMetrics) {
ALOG_BRIDGE("Exceptional Exit: %s", __PRETTY_FUNCTION__);
return;
}
AndroidRectF rect(env, displayPortMetrics->MPosition().Get());
float resolution = displayPortMetrics->Resolution();
*displayPort = new nsAndroidDisplayport(rect, resolution);
(*displayPort)->AddRef();
ALOG_BRIDGE("Exit: %s", __PRETTY_FUNCTION__);
}
void
AndroidBridge::ContentDocumentChanged()
{

Просмотреть файл

@ -17,7 +17,6 @@
#include "nsCOMArray.h"
#include "GeneratedJNIWrappers.h"
#include "AndroidJavaWrappers.h"
#include "nsIMutableArray.h"
#include "nsIMIMEInfo.h"
@ -35,12 +34,15 @@
#include "mozilla/gfx/Point.h"
#include "mozilla/jni/Utils.h"
#include "nsIObserver.h"
#include "nsDataHashtable.h"
#include "Units.h"
// Some debug #defines
// #define DEBUG_ANDROID_EVENTS
// #define DEBUG_ANDROID_WIDGET
class nsIObserver;
class nsPIDOMWindowOuter;
namespace base {
class Thread;
@ -50,6 +52,7 @@ typedef void* EGLSurface;
namespace mozilla {
class AutoLocalJNIFrame;
class Runnable;
namespace hal {
@ -145,7 +148,6 @@ public:
bool GetThreadNameJavaProfiling(uint32_t aThreadId, nsCString & aResult);
bool GetFrameNameJavaProfiling(uint32_t aThreadId, uint32_t aSampleId, uint32_t aFrameId, nsCString & aResult);
void GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort);
void ContentDocumentChanged();
bool IsContentDocumentDisplayed();

Просмотреть файл

@ -49,14 +49,6 @@ extern "C" {
/*
* Incoming JNI methods
*/
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent(JNIEnv *jenv, jclass jc, jobject event)
{
// poke the appshell
nsAppShell::PostEvent(AndroidGeckoEvent::MakeFromJavaObject(jenv, event));
}
NS_EXPORT jlong JNICALL
Java_org_mozilla_gecko_GeckoAppShell_runUiThreadCallback(JNIEnv* env, jclass)
{

Просмотреть файл

@ -4,587 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AndroidJavaWrappers.h"
#include "AndroidBridge.h"
#include "AndroidBridgeUtilities.h"
#include "nsIDOMKeyEvent.h"
#include "nsIWidget.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/TouchEvents.h"
using namespace mozilla;
using namespace mozilla::dom;
jclass AndroidGeckoEvent::jGeckoEventClass = 0;
jfieldID AndroidGeckoEvent::jActionField = 0;
jfieldID AndroidGeckoEvent::jTypeField = 0;
jfieldID AndroidGeckoEvent::jTimeField = 0;
jfieldID AndroidGeckoEvent::jPoints = 0;
jfieldID AndroidGeckoEvent::jPointIndicies = 0;
jfieldID AndroidGeckoEvent::jPressures = 0;
jfieldID AndroidGeckoEvent::jToolTypes = 0;
jfieldID AndroidGeckoEvent::jPointRadii = 0;
jfieldID AndroidGeckoEvent::jOrientations = 0;
jfieldID AndroidGeckoEvent::jXField = 0;
jfieldID AndroidGeckoEvent::jCharactersField = 0;
jfieldID AndroidGeckoEvent::jCharactersExtraField = 0;
jfieldID AndroidGeckoEvent::jMetaStateField = 0;
jfieldID AndroidGeckoEvent::jCountField = 0;
jfieldID AndroidGeckoEvent::jPointerIndexField = 0;
jclass AndroidPoint::jPointClass = 0;
jfieldID AndroidPoint::jXField = 0;
jfieldID AndroidPoint::jYField = 0;
jclass AndroidRect::jRectClass = 0;
jfieldID AndroidRect::jBottomField = 0;
jfieldID AndroidRect::jLeftField = 0;
jfieldID AndroidRect::jRightField = 0;
jfieldID AndroidRect::jTopField = 0;
jclass AndroidRectF::jRectClass = 0;
jfieldID AndroidRectF::jBottomField = 0;
jfieldID AndroidRectF::jLeftField = 0;
jfieldID AndroidRectF::jRightField = 0;
jfieldID AndroidRectF::jTopField = 0;
RefCountedJavaObject::~RefCountedJavaObject() {
if (mObject)
GetEnvForThread()->DeleteGlobalRef(mObject);
mObject = nullptr;
}
void
mozilla::InitAndroidJavaWrappers(JNIEnv *jEnv)
{
AndroidGeckoEvent::InitGeckoEventClass(jEnv);
AndroidPoint::InitPointClass(jEnv);
AndroidRect::InitRectClass(jEnv);
AndroidRectF::InitRectFClass(jEnv);
}
void
AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
{
AutoJNIClass geckoEvent(jEnv, "org/mozilla/gecko/GeckoEvent");
jGeckoEventClass = geckoEvent.getGlobalRef();
jActionField = geckoEvent.getField("mAction", "I");
jTypeField = geckoEvent.getField("mType", "I");
jTimeField = geckoEvent.getField("mTime", "J");
jPoints = geckoEvent.getField("mPoints", "[Landroid/graphics/Point;");
jPointIndicies = geckoEvent.getField("mPointIndicies", "[I");
jOrientations = geckoEvent.getField("mOrientations", "[F");
jPressures = geckoEvent.getField("mPressures", "[F");
jToolTypes = geckoEvent.getField("mToolTypes", "[I");
jPointRadii = geckoEvent.getField("mPointRadii", "[Landroid/graphics/Point;");
jXField = geckoEvent.getField("mX", "D");
jCharactersField = geckoEvent.getField("mCharacters", "Ljava/lang/String;");
jCharactersExtraField = geckoEvent.getField("mCharactersExtra", "Ljava/lang/String;");
jMetaStateField = geckoEvent.getField("mMetaState", "I");
jCountField = geckoEvent.getField("mCount", "I");
jPointerIndexField = geckoEvent.getField("mPointerIndex", "I");
}
void
AndroidPoint::InitPointClass(JNIEnv *jEnv)
{
AutoJNIClass point(jEnv, "android/graphics/Point");
jPointClass = point.getGlobalRef();
jXField = point.getField("x", "I");
jYField = point.getField("y", "I");
}
void
AndroidRect::InitRectClass(JNIEnv *jEnv)
{
AutoJNIClass rect(jEnv, "android/graphics/Rect");
jRectClass = rect.getGlobalRef();
jBottomField = rect.getField("bottom", "I");
jLeftField = rect.getField("left", "I");
jTopField = rect.getField("top", "I");
jRightField = rect.getField("right", "I");
}
void
AndroidRectF::InitRectFClass(JNIEnv *jEnv)
{
AutoJNIClass rect(jEnv, "android/graphics/RectF");
jRectClass = rect.getGlobalRef();
jBottomField = rect.getField("bottom", "F");
jLeftField = rect.getField("left", "F");
jTopField = rect.getField("top", "F");
jRightField = rect.getField("right", "F");
}
void
AndroidGeckoEvent::ReadPointArray(nsTArray<nsIntPoint> &points,
JNIEnv *jenv,
jfieldID field,
int32_t count)
{
jobjectArray jObjArray = (jobjectArray)jenv->GetObjectField(wrapped_obj, field);
for (int32_t i = 0; i < count; i++) {
jobject jObj = jenv->GetObjectArrayElement(jObjArray, i);
AndroidPoint jpoint(jenv, jObj);
nsIntPoint p(jpoint.X(), jpoint.Y());
points.AppendElement(p);
}
}
void
AndroidGeckoEvent::ReadIntArray(nsTArray<int> &aVals,
JNIEnv *jenv,
jfieldID field,
int32_t count)
{
jintArray jIntArray = (jintArray)jenv->GetObjectField(wrapped_obj, field);
jint *vals = jenv->GetIntArrayElements(jIntArray, nullptr);
for (int32_t i = 0; i < count; i++) {
aVals.AppendElement(vals[i]);
}
jenv->ReleaseIntArrayElements(jIntArray, vals, JNI_ABORT);
}
void
AndroidGeckoEvent::ReadFloatArray(nsTArray<float> &aVals,
JNIEnv *jenv,
jfieldID field,
int32_t count)
{
jfloatArray jFloatArray = (jfloatArray)jenv->GetObjectField(wrapped_obj, field);
jfloat *vals = jenv->GetFloatArrayElements(jFloatArray, nullptr);
for (int32_t i = 0; i < count; i++) {
aVals.AppendElement(vals[i]);
}
jenv->ReleaseFloatArrayElements(jFloatArray, vals, JNI_ABORT);
}
void
AndroidGeckoEvent::ReadStringArray(nsTArray<nsString> &array,
JNIEnv *jenv,
jfieldID field)
{
jarray jArray = (jarray)jenv->GetObjectField(wrapped_obj, field);
jsize length = jenv->GetArrayLength(jArray);
jobjectArray jStringArray = (jobjectArray)jArray;
nsString *strings = array.AppendElements(length);
for (jsize i = 0; i < length; ++i) {
jstring javastring = (jstring) jenv->GetObjectArrayElement(jStringArray, i);
ReadStringFromJString(strings[i], jenv, javastring);
}
}
void
AndroidGeckoEvent::ReadStringFromJString(nsString &aString, JNIEnv *jenv,
jstring s)
{
if (!s) {
aString.SetIsVoid(true);
return;
}
int len = jenv->GetStringLength(s);
aString.SetLength(len);
jenv->GetStringRegion(s, 0, len, reinterpret_cast<jchar*>(aString.BeginWriting()));
}
void
AndroidGeckoEvent::ReadCharactersField(JNIEnv *jenv)
{
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersField);
ReadStringFromJString(mCharacters, jenv, s);
}
void
AndroidGeckoEvent::ReadCharactersExtraField(JNIEnv *jenv)
{
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersExtraField);
ReadStringFromJString(mCharactersExtra, jenv, s);
}
void
AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
{
NS_ASSERTION(!wrapped_obj, "Init called on non-null wrapped_obj!");
wrapped_obj = jobj;
if (!jobj)
return;
mAction = jenv->GetIntField(jobj, jActionField);
mType = jenv->GetIntField(jobj, jTypeField);
switch (mType) {
case NATIVE_GESTURE_EVENT:
mTime = jenv->GetLongField(jobj, jTimeField);
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
mCount = jenv->GetIntField(jobj, jCountField);
ReadPointArray(mPoints, jenv, jPoints, mCount);
mX = jenv->GetDoubleField(jobj, jXField);
break;
case MOTION_EVENT:
case LONG_PRESS:
mTime = jenv->GetLongField(jobj, jTimeField);
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
mCount = jenv->GetIntField(jobj, jCountField);
mPointerIndex = jenv->GetIntField(jobj, jPointerIndexField);
ReadPointArray(mPointRadii, jenv, jPointRadii, mCount);
ReadFloatArray(mOrientations, jenv, jOrientations, mCount);
ReadFloatArray(mPressures, jenv, jPressures, mCount);
ReadIntArray(mToolTypes, jenv, jToolTypes, mCount);
ReadPointArray(mPoints, jenv, jPoints, mCount);
ReadIntArray(mPointIndicies, jenv, jPointIndicies, mCount);
break;
case VIEWPORT: {
ReadCharactersField(jenv);
ReadCharactersExtraField(jenv);
break;
}
default:
break;
}
#ifdef DEBUG_ANDROID_EVENTS
ALOG("AndroidGeckoEvent: %p : %d", (void*)jobj, mType);
#endif
}
void
AndroidGeckoEvent::Init(int aType)
{
mType = aType;
}
bool
AndroidGeckoEvent::CanCoalesceWith(AndroidGeckoEvent* ae)
{
if (Type() == MOTION_EVENT && ae->Type() == MOTION_EVENT) {
return Action() == AndroidMotionEvent::ACTION_MOVE
&& ae->Action() == AndroidMotionEvent::ACTION_MOVE;
} else if (Type() == APZ_INPUT_EVENT && ae->Type() == APZ_INPUT_EVENT) {
return mApzInput.mType == MultiTouchInput::MULTITOUCH_MOVE
&& ae->mApzInput.mType == MultiTouchInput::MULTITOUCH_MOVE;
}
return false;
}
mozilla::layers::ScrollableLayerGuid
AndroidGeckoEvent::ApzGuid()
{
MOZ_ASSERT(Type() == APZ_INPUT_EVENT);
return mApzGuid;
}
uint64_t
AndroidGeckoEvent::ApzInputBlockId()
{
MOZ_ASSERT(Type() == APZ_INPUT_EVENT);
return mApzInputBlockId;
}
nsEventStatus
AndroidGeckoEvent::ApzEventStatus()
{
MOZ_ASSERT(Type() == APZ_INPUT_EVENT);
return mApzEventStatus;
}
WidgetTouchEvent
AndroidGeckoEvent::MakeTouchEvent(nsIWidget* widget)
{
if (Type() == APZ_INPUT_EVENT) {
return mApzInput.ToWidgetTouchEvent(widget);
}
EventMessage type = eVoidEvent;
int startIndex = 0;
int endIndex = Count();
switch (Action()) {
case AndroidMotionEvent::ACTION_HOVER_ENTER: {
if (ToolTypes()[0] == AndroidMotionEvent::TOOL_TYPE_MOUSE) {
break;
}
}
MOZ_FALLTHROUGH;
case AndroidMotionEvent::ACTION_DOWN:
MOZ_FALLTHROUGH;
case AndroidMotionEvent::ACTION_POINTER_DOWN: {
type = eTouchStart;
break;
}
case AndroidMotionEvent::ACTION_HOVER_MOVE: {
if (ToolTypes()[0] == AndroidMotionEvent::TOOL_TYPE_MOUSE) {
break;
}
}
MOZ_FALLTHROUGH;
case AndroidMotionEvent::ACTION_MOVE: {
type = eTouchMove;
break;
}
case AndroidMotionEvent::ACTION_HOVER_EXIT: {
if (ToolTypes()[0] == AndroidMotionEvent::TOOL_TYPE_MOUSE) {
break;
}
}
MOZ_FALLTHROUGH;
case AndroidMotionEvent::ACTION_UP:
MOZ_FALLTHROUGH;
case AndroidMotionEvent::ACTION_POINTER_UP: {
type = eTouchEnd;
// for pointer-up events we only want the data from
// the one pointer that went up
startIndex = PointerIndex();
endIndex = startIndex + 1;
break;
}
case AndroidMotionEvent::ACTION_OUTSIDE:
MOZ_FALLTHROUGH;
case AndroidMotionEvent::ACTION_CANCEL: {
type = eTouchCancel;
break;
}
}
WidgetTouchEvent event(true, type, widget);
if (type == eVoidEvent) {
// An event we don't know about
return event;
}
event.mModifiers = DOMModifiers();
event.mTime = Time();
const LayoutDeviceIntPoint& offset = widget->WidgetToScreenOffset();
event.mTouches.SetCapacity(endIndex - startIndex);
for (int i = startIndex; i < endIndex; i++) {
// In this code branch, we are dispatching this event directly
// into Gecko (as opposed to going through the AsyncPanZoomController),
// and the Points() array has points in CSS pixels, which we need
// to convert.
CSSToLayoutDeviceScale scale = widget->GetDefaultScale();
auto pt = LayoutDeviceIntPoint::Truncate(
(Points()[i].x * scale.scale) - offset.x,
(Points()[i].y * scale.scale) - offset.y);
auto radius = LayoutDeviceIntPoint::Truncate(
PointRadii()[i].x * scale.scale,
PointRadii()[i].y * scale.scale);
RefPtr<Touch> t = new Touch(PointIndicies()[i],
pt,
radius,
Orientations()[i],
Pressures()[i]);
event.mTouches.AppendElement(t);
}
return event;
}
MultiTouchInput
AndroidGeckoEvent::MakeMultiTouchInput(nsIWidget* widget)
{
MultiTouchInput::MultiTouchType type = (MultiTouchInput::MultiTouchType)-1;
int startIndex = 0;
int endIndex = Count();
switch (Action()) {
case AndroidMotionEvent::ACTION_DOWN:
case AndroidMotionEvent::ACTION_POINTER_DOWN: {
type = MultiTouchInput::MULTITOUCH_START;
break;
}
case AndroidMotionEvent::ACTION_MOVE: {
type = MultiTouchInput::MULTITOUCH_MOVE;
break;
}
case AndroidMotionEvent::ACTION_UP:
case AndroidMotionEvent::ACTION_POINTER_UP: {
// for pointer-up events we only want the data from
// the one pointer that went up
startIndex = PointerIndex();
endIndex = startIndex + 1;
type = MultiTouchInput::MULTITOUCH_END;
break;
}
case AndroidMotionEvent::ACTION_OUTSIDE:
case AndroidMotionEvent::ACTION_CANCEL: {
type = MultiTouchInput::MULTITOUCH_CANCEL;
break;
}
}
MultiTouchInput event(type, Time(), TimeStamp(), 0);
event.modifiers = DOMModifiers();
if (type < 0) {
// An event we don't know about
return event;
}
const nsIntPoint& offset = widget->WidgetToScreenOffset().ToUnknownPoint();
event.mTouches.SetCapacity(endIndex - startIndex);
for (int i = startIndex; i < endIndex; i++) {
nsIntPoint point = Points()[i] - offset;
nsIntPoint radius = PointRadii()[i];
SingleTouchData data(PointIndicies()[i],
ScreenIntPoint::FromUnknownPoint(
gfx::IntPoint(point.x, point.y)),
ScreenSize::FromUnknownSize(
gfx::Size(radius.x, radius.y)),
Orientations()[i],
Pressures()[i]);
event.mTouches.AppendElement(data);
}
return event;
}
WidgetMouseEvent
AndroidGeckoEvent::MakeMouseEvent(nsIWidget* widget)
{
EventMessage msg = eVoidEvent;
if (Points().Length() > 0) {
switch (Action()) {
case AndroidMotionEvent::ACTION_HOVER_MOVE:
msg = eMouseMove;
break;
case AndroidMotionEvent::ACTION_HOVER_ENTER:
msg = eMouseEnterIntoWidget;
break;
case AndroidMotionEvent::ACTION_HOVER_EXIT:
msg = eMouseExitFromWidget;
break;
default:
break;
}
}
WidgetMouseEvent event(true, msg, widget,
WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
if (msg == eVoidEvent) {
// unknown type, or no point data. abort
return event;
}
// XXX can we synthesize different buttons?
event.button = WidgetMouseEvent::eLeftButton;
if (msg != eMouseMove) {
event.mClickCount = 1;
}
event.mModifiers = DOMModifiers();
event.mTime = Time();
// We are dispatching this event directly into Gecko (as opposed to going
// through the AsyncPanZoomController), and the Points() array has points
// in CSS pixels, which we need to convert to LayoutDevice pixels.
const LayoutDeviceIntPoint& offset = widget->WidgetToScreenOffset();
CSSToLayoutDeviceScale scale = widget->GetDefaultScale();
event.mRefPoint =
LayoutDeviceIntPoint::Truncate((Points()[0].x * scale.scale) - offset.x,
(Points()[0].y * scale.scale) - offset.y);
return event;
}
Modifiers
AndroidGeckoEvent::DOMModifiers() const
{
Modifiers result = 0;
if (mMetaState & AMETA_ALT_MASK) {
result |= MODIFIER_ALT;
}
if (mMetaState & AMETA_SHIFT_MASK) {
result |= MODIFIER_SHIFT;
}
if (mMetaState & AMETA_CTRL_MASK) {
result |= MODIFIER_CONTROL;
}
if (mMetaState & AMETA_META_MASK) {
result |= MODIFIER_META;
}
if (mMetaState & AMETA_FUNCTION_ON) {
result |= MODIFIER_FN;
}
if (mMetaState & AMETA_CAPS_LOCK_ON) {
result |= MODIFIER_CAPSLOCK;
}
if (mMetaState & AMETA_NUM_LOCK_ON) {
result |= MODIFIER_NUMLOCK;
}
if (mMetaState & AMETA_SCROLL_LOCK_ON) {
result |= MODIFIER_SCROLLLOCK;
}
return result;
}
void
AndroidPoint::Init(JNIEnv *jenv, jobject jobj)
{
if (jobj) {
mX = jenv->GetIntField(jobj, jXField);
mY = jenv->GetIntField(jobj, jYField);
} else {
mX = 0;
mY = 0;
}
}
NS_IMPL_ISUPPORTS(nsAndroidDisplayport, nsIAndroidDisplayport)
void
AndroidRect::Init(JNIEnv *jenv, jobject jobj)
{
NS_ASSERTION(wrapped_obj == nullptr, "Init called on non-null wrapped_obj!");
wrapped_obj = jobj;
if (jobj) {
mTop = jenv->GetIntField(jobj, jTopField);
mLeft = jenv->GetIntField(jobj, jLeftField);
mRight = jenv->GetIntField(jobj, jRightField);
mBottom = jenv->GetIntField(jobj, jBottomField);
} else {
mTop = 0;
mLeft = 0;
mRight = 0;
mBottom = 0;
}
}
void
AndroidRectF::Init(JNIEnv *jenv, jobject jobj)
{
NS_ASSERTION(wrapped_obj == nullptr, "Init called on non-null wrapped_obj!");
wrapped_obj = jobj;
if (jobj) {
mTop = jenv->GetFloatField(jobj, jTopField);
mLeft = jenv->GetFloatField(jobj, jLeftField);
mRight = jenv->GetFloatField(jobj, jRightField);
mBottom = jenv->GetFloatField(jobj, jBottomField);
} else {
mTop = 0;
mLeft = 0;
mRight = 0;
mBottom = 0;
}
}
nsJNIString::nsJNIString(jstring jstr, JNIEnv *jenv)
{

Просмотреть файл

@ -29,185 +29,6 @@ class nsIWidget;
namespace mozilla {
class AutoLocalJNIFrame;
void InitAndroidJavaWrappers(JNIEnv *jEnv);
class RefCountedJavaObject {
public:
RefCountedJavaObject(JNIEnv* env, jobject obj) : mRefCnt(0), mObject(env->NewGlobalRef(obj)) {}
~RefCountedJavaObject();
int32_t AddRef() { return ++mRefCnt; }
int32_t Release() {
int32_t refcnt = --mRefCnt;
if (refcnt == 0)
delete this;
return refcnt;
}
jobject GetObject() { return mObject; }
private:
int32_t mRefCnt;
jobject mObject;
};
/*
* Note: do not store global refs to any WrappedJavaObject;
* these are live only during a particular JNI method, as
* NewGlobalRef is -not- called on the jobject.
*
* If this is needed, WrappedJavaObject can be extended to
* handle it.
*/
class WrappedJavaObject {
public:
WrappedJavaObject() :
wrapped_obj(nullptr)
{ }
WrappedJavaObject(jobject jobj) : wrapped_obj(nullptr) {
Init(jobj);
}
void Init(jobject jobj) {
wrapped_obj = jobj;
}
bool isNull() const {
return wrapped_obj == nullptr;
}
jobject wrappedObject() const {
return wrapped_obj;
}
protected:
jobject wrapped_obj;
};
class AutoGlobalWrappedJavaObject : protected WrappedJavaObject{
public:
AutoGlobalWrappedJavaObject() :
wrapped_obj(nullptr)
{ }
AutoGlobalWrappedJavaObject(jobject jobj, JNIEnv* env) : wrapped_obj(nullptr) {
Init(jobj, env);
}
virtual ~AutoGlobalWrappedJavaObject();
void Dispose();
void Init(jobject jobj, JNIEnv* env) {
if (!isNull()) {
env->DeleteGlobalRef(wrapped_obj);
}
wrapped_obj = env->NewGlobalRef(jobj);
}
bool isNull() const {
return wrapped_obj == nullptr;
}
jobject wrappedObject() const {
return wrapped_obj;
}
protected:
jobject wrapped_obj;
};
class AndroidPoint : public WrappedJavaObject
{
public:
static void InitPointClass(JNIEnv *jEnv);
AndroidPoint() { }
AndroidPoint(JNIEnv *jenv, jobject jobj) {
Init(jenv, jobj);
}
void Init(JNIEnv *jenv, jobject jobj);
int X() { return mX; }
int Y() { return mY; }
protected:
int mX;
int mY;
static jclass jPointClass;
static jfieldID jXField;
static jfieldID jYField;
};
class AndroidRect : public WrappedJavaObject
{
public:
static void InitRectClass(JNIEnv *jEnv);
AndroidRect() { }
AndroidRect(JNIEnv *jenv, jobject jobj) {
Init(jenv, jobj);
}
void Init(JNIEnv *jenv, jobject jobj);
int Bottom() { return mBottom; }
int Left() { return mLeft; }
int Right() { return mRight; }
int Top() { return mTop; }
int Width() { return mRight - mLeft; }
int Height() { return mBottom - mTop; }
protected:
int mBottom;
int mLeft;
int mRight;
int mTop;
static jclass jRectClass;
static jfieldID jBottomField;
static jfieldID jLeftField;
static jfieldID jRightField;
static jfieldID jTopField;
};
class AndroidRectF : public WrappedJavaObject
{
public:
static void InitRectFClass(JNIEnv *jEnv);
AndroidRectF() { }
AndroidRectF(JNIEnv *jenv, jobject jobj) {
Init(jenv, jobj);
}
void Init(JNIEnv *jenv, jobject jobj);
float Bottom() { return mBottom; }
float Left() { return mLeft; }
float Right() { return mRight; }
float Top() { return mTop; }
float Width() { return mRight - mLeft; }
float Height() { return mBottom - mTop; }
protected:
float mBottom;
float mLeft;
float mRight;
float mTop;
static jclass jRectClass;
static jfieldID jBottomField;
static jfieldID jLeftField;
static jfieldID jRightField;
static jfieldID jTopField;
};
enum {
// These keycode masks are not defined in android/keycodes.h:
#if __ANDROID_API__ < 13
@ -345,29 +166,6 @@ enum {
AMETA_SHIFT_MASK = AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_RIGHT_ON | AMETA_SHIFT_ON,
};
class nsAndroidDisplayport final : public nsIAndroidDisplayport
{
public:
NS_DECL_ISUPPORTS
virtual nsresult GetLeft(float *aLeft) override { *aLeft = mLeft; return NS_OK; }
virtual nsresult GetTop(float *aTop) override { *aTop = mTop; return NS_OK; }
virtual nsresult GetRight(float *aRight) override { *aRight = mRight; return NS_OK; }
virtual nsresult GetBottom(float *aBottom) override { *aBottom = mBottom; return NS_OK; }
virtual nsresult GetResolution(float *aResolution) override { *aResolution = mResolution; return NS_OK; }
virtual nsresult SetLeft(float aLeft) override { mLeft = aLeft; return NS_OK; }
virtual nsresult SetTop(float aTop) override { mTop = aTop; return NS_OK; }
virtual nsresult SetRight(float aRight) override { mRight = aRight; return NS_OK; }
virtual nsresult SetBottom(float aBottom) override { mBottom = aBottom; return NS_OK; }
virtual nsresult SetResolution(float aResolution) override { mResolution = aResolution; return NS_OK; }
nsAndroidDisplayport(AndroidRectF aRect, float aResolution):
mLeft(aRect.Left()), mTop(aRect.Top()), mRight(aRect.Right()), mBottom(aRect.Bottom()), mResolution(aResolution) {}
private:
~nsAndroidDisplayport() {}
float mLeft, mTop, mRight, mBottom, mResolution;
};
class AndroidMotionEvent
{
public:
@ -403,139 +201,6 @@ public:
};
};
class AndroidGeckoEvent : public WrappedJavaObject
{
private:
AndroidGeckoEvent() {
}
void Init(JNIEnv *jenv, jobject jobj);
void Init(int aType);
public:
static void InitGeckoEventClass(JNIEnv *jEnv);
static AndroidGeckoEvent* MakeFromJavaObject(JNIEnv *jenv, jobject jobj) {
AndroidGeckoEvent *event = new AndroidGeckoEvent();
event->Init(jenv, jobj);
return event;
}
static AndroidGeckoEvent* MakeApzInputEvent(const MultiTouchInput& aInput, const mozilla::layers::ScrollableLayerGuid& aGuid, uint64_t aInputBlockId, nsEventStatus aEventStatus) {
AndroidGeckoEvent* event = new AndroidGeckoEvent();
event->Init(APZ_INPUT_EVENT);
event->mApzInput = aInput;
event->mApzGuid = aGuid;
event->mApzInputBlockId = aInputBlockId;
event->mApzEventStatus = aEventStatus;
return event;
}
bool IsInputEvent() const {
return mType == AndroidGeckoEvent::MOTION_EVENT ||
mType == AndroidGeckoEvent::NATIVE_GESTURE_EVENT ||
mType == AndroidGeckoEvent::LONG_PRESS ||
mType == AndroidGeckoEvent::APZ_INPUT_EVENT;
}
int Action() { return mAction; }
int Type() { return mType; }
int64_t Time() { return mTime; }
const nsTArray<nsIntPoint>& Points() { return mPoints; }
const nsTArray<int>& PointIndicies() { return mPointIndicies; }
const nsTArray<float>& Pressures() { return mPressures; }
const nsTArray<int>& ToolTypes() { return mToolTypes; }
const nsTArray<float>& Orientations() { return mOrientations; }
const nsTArray<nsIntPoint>& PointRadii() { return mPointRadii; }
double X() { return mX; }
nsString& Characters() { return mCharacters; }
nsString& CharactersExtra() { return mCharactersExtra; }
int MetaState() { return mMetaState; }
Modifiers DOMModifiers() const;
bool IsAltPressed() const { return (mMetaState & AMETA_ALT_MASK) != 0; }
bool IsShiftPressed() const { return (mMetaState & AMETA_SHIFT_MASK) != 0; }
bool IsCtrlPressed() const { return (mMetaState & AMETA_CTRL_MASK) != 0; }
bool IsMetaPressed() const { return (mMetaState & AMETA_META_MASK) != 0; }
int Count() { return mCount; }
int PointerIndex() { return mPointerIndex; }
int RequestId() { return mCount; } // for convenience
bool CanCoalesceWith(AndroidGeckoEvent* ae);
WidgetTouchEvent MakeTouchEvent(nsIWidget* widget);
MultiTouchInput MakeMultiTouchInput(nsIWidget* widget);
WidgetMouseEvent MakeMouseEvent(nsIWidget* widget);
mozilla::layers::ScrollableLayerGuid ApzGuid();
uint64_t ApzInputBlockId();
nsEventStatus ApzEventStatus();
protected:
int mAction;
int mType;
int64_t mTime;
nsTArray<nsIntPoint> mPoints;
nsTArray<nsIntPoint> mPointRadii;
nsTArray<int> mPointIndicies;
nsTArray<float> mOrientations;
nsTArray<float> mPressures;
nsTArray<int> mToolTypes;
int mMetaState;
int mCount;
double mX;
int mPointerIndex;
nsString mCharacters, mCharactersExtra;
MultiTouchInput mApzInput;
mozilla::layers::ScrollableLayerGuid mApzGuid;
uint64_t mApzInputBlockId;
nsEventStatus mApzEventStatus;
void ReadIntArray(nsTArray<int> &aVals,
JNIEnv *jenv,
jfieldID field,
int32_t count);
void ReadFloatArray(nsTArray<float> &aVals,
JNIEnv *jenv,
jfieldID field,
int32_t count);
void ReadPointArray(nsTArray<nsIntPoint> &mPoints,
JNIEnv *jenv,
jfieldID field,
int32_t count);
void ReadStringArray(nsTArray<nsString> &aStrings,
JNIEnv *jenv,
jfieldID field);
void ReadCharactersField(JNIEnv *jenv);
void ReadCharactersExtraField(JNIEnv *jenv);
void ReadStringFromJString(nsString &aString, JNIEnv *jenv, jstring s);
static jclass jGeckoEventClass;
static jfieldID jActionField;
static jfieldID jTypeField;
static jfieldID jTimeField;
static jfieldID jPoints;
static jfieldID jPointIndicies;
static jfieldID jOrientations;
static jfieldID jPressures;
static jfieldID jToolTypes;
static jfieldID jPointRadii;
static jfieldID jXField;
static jfieldID jCharactersField;
static jfieldID jCharactersExtraField;
static jfieldID jMetaStateField;
static jfieldID jCountField;
static jfieldID jPointerIndexField;
public:
enum {
MOTION_EVENT = 2,
NOOP = 15,
APZ_INPUT_EVENT = 17, // used internally in AndroidJNI/nsAppShell/nsWindow
VIEWPORT = 20,
NATIVE_GESTURE_EVENT = 31,
LONG_PRESS = 47,
dummy_java_enum_list_end
};
};
class nsJNIString : public nsString
{
public:

Просмотреть файл

@ -1277,14 +1277,6 @@ auto GeckoLayerClient::DeactivateProgramAndRestoreState(bool a0, int32_t a1, int
return mozilla::jni::Method<DeactivateProgramAndRestoreState_t>::Call(GeckoLayerClient::mCtx, nullptr, a0, a1, a2, a3, a4);
}
constexpr char GeckoLayerClient::GetDisplayPort_t::name[];
constexpr char GeckoLayerClient::GetDisplayPort_t::signature[];
auto GeckoLayerClient::GetDisplayPort(bool a0, bool a1, int32_t a2, mozilla::jni::Object::Param a3) const -> mozilla::jni::Object::LocalRef
{
return mozilla::jni::Method<GetDisplayPort_t>::Call(GeckoLayerClient::mCtx, nullptr, a0, a1, a2, a3);
}
constexpr char GeckoLayerClient::IsContentDocumentDisplayed_t::name[];
constexpr char GeckoLayerClient::IsContentDocumentDisplayed_t::signature[];
@ -1500,14 +1492,6 @@ auto NativePanZoomController::OnSelectionDragState(bool a0) const -> void
return mozilla::jni::Method<OnSelectionDragState_t>::Call(NativePanZoomController::mCtx, nullptr, a0);
}
constexpr char NativePanZoomController::RequestContentRepaint_t::name[];
constexpr char NativePanZoomController::RequestContentRepaint_t::signature[];
auto NativePanZoomController::RequestContentRepaint(float a0, float a1, float a2, float a3, float a4) const -> void
{
return mozilla::jni::Method<RequestContentRepaint_t>::Call(NativePanZoomController::mCtx, nullptr, a0, a1, a2, a3, a4);
}
constexpr char NativePanZoomController::SetScrollingRootContent_t::name[];
constexpr char NativePanZoomController::SetScrollingRootContent_t::signature[];

Просмотреть файл

@ -4072,29 +4072,6 @@ public:
auto DeactivateProgramAndRestoreState(bool, int32_t, int32_t, int32_t, int32_t) const -> void;
struct GetDisplayPort_t {
typedef GeckoLayerClient Owner;
typedef mozilla::jni::Object::LocalRef ReturnType;
typedef mozilla::jni::Object::Param SetterType;
typedef mozilla::jni::Args<
bool,
bool,
int32_t,
mozilla::jni::Object::Param> Args;
static constexpr char name[] = "getDisplayPort";
static constexpr char signature[] =
"(ZZILorg/mozilla/gecko/gfx/ImmutableViewportMetrics;)Lorg/mozilla/gecko/gfx/DisplayPortMetrics;";
static const bool isStatic = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
static const mozilla::jni::CallingThread callingThread =
mozilla::jni::CallingThread::GECKO;
static const mozilla::jni::DispatchTarget dispatchTarget =
mozilla::jni::DispatchTarget::CURRENT;
};
auto GetDisplayPort(bool, bool, int32_t, mozilla::jni::Object::Param) const -> mozilla::jni::Object::LocalRef;
struct IsContentDocumentDisplayed_t {
typedef GeckoLayerClient Owner;
typedef bool ReturnType;
@ -4889,30 +4866,6 @@ public:
auto OnSelectionDragState(bool) const -> void;
struct RequestContentRepaint_t {
typedef NativePanZoomController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
float,
float,
float,
float,
float> Args;
static constexpr char name[] = "requestContentRepaint";
static constexpr char signature[] =
"(FFFFF)V";
static const bool isStatic = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
static const mozilla::jni::CallingThread callingThread =
mozilla::jni::CallingThread::UI;
static const mozilla::jni::DispatchTarget dispatchTarget =
mozilla::jni::DispatchTarget::CURRENT;
};
auto RequestContentRepaint(float, float, float, float, float) const -> void;
struct SetScrollingRootContent_t {
typedef NativePanZoomController Owner;
typedef void ReturnType;

Просмотреть файл

@ -607,118 +607,6 @@ nsAppShell::ResolveURI(const nsCString& aUriStr)
return nullptr;
}
class nsAppShell::LegacyGeckoEvent : public Event
{
mozilla::UniquePtr<AndroidGeckoEvent> ae;
public:
LegacyGeckoEvent(AndroidGeckoEvent* e) : ae(e) {}
void Run() override;
void PostTo(mozilla::LinkedList<Event>& queue) override;
Event::Type ActivityType() const override
{
return ae->IsInputEvent() ? mozilla::HangMonitor::kUIActivity
: mozilla::HangMonitor::kGeneralActivity;
}
};
void
nsAppShell::PostEvent(AndroidGeckoEvent* event)
{
mozilla::MutexAutoLock lock(*sAppShellLock);
if (!sAppShell) {
return;
}
sAppShell->mEventQueue.Post(mozilla::MakeUnique<LegacyGeckoEvent>(event));
}
void
nsAppShell::LegacyGeckoEvent::Run()
{
const mozilla::UniquePtr<AndroidGeckoEvent>& curEvent = ae;
EVLOG("nsAppShell: event %p %d", (void*)curEvent.get(), curEvent->Type());
switch (curEvent->Type()) {
case AndroidGeckoEvent::VIEWPORT: {
if (curEvent->Characters().Length() == 0)
break;
nsCOMPtr<nsIObserverService> obsServ =
mozilla::services::GetObserverService();
const NS_ConvertUTF16toUTF8 topic(curEvent->Characters());
obsServ->NotifyObservers(nullptr, topic.get(), curEvent->CharactersExtra().get());
break;
}
case AndroidGeckoEvent::NOOP:
break;
default:
nsWindow::OnGlobalAndroidEvent(curEvent.get());
break;
}
EVLOG("nsAppShell: -- done event %p %d", (void*)curEvent.get(), curEvent->Type());
}
void
nsAppShell::LegacyGeckoEvent::PostTo(mozilla::LinkedList<Event>& queue)
{
{
EVLOG("nsAppShell::PostEvent %p %d", ae, ae->Type());
switch (ae->Type()) {
case AndroidGeckoEvent::VIEWPORT:
// Coalesce a previous viewport event with this one, while
// allowing coalescing to happen across native callback events.
for (Event* event = queue.getLast(); event;
event = event->getPrevious())
{
if (event->HasSameTypeAs(this) &&
static_cast<LegacyGeckoEvent*>(event)->ae->Type()
== AndroidGeckoEvent::VIEWPORT) {
// Found a previous viewport event; remove it.
delete event;
break;
}
NativeCallbackEvent callbackEvent(nullptr);
if (event->HasSameTypeAs(&callbackEvent)) {
// Allow coalescing viewport events across callback events.
continue;
}
// End of search for viewport events to coalesce.
break;
}
queue.insertBack(this);
break;
case AndroidGeckoEvent::MOTION_EVENT:
case AndroidGeckoEvent::APZ_INPUT_EVENT:
if (sAppShell->mAllowCoalescingTouches) {
Event* const event = queue.getLast();
if (event && event->HasSameTypeAs(this) && ae->CanCoalesceWith(
static_cast<LegacyGeckoEvent*>(event)->ae.get())) {
// consecutive motion-move events; drop the last one before adding the new one
EVLOG("nsAppShell: Dropping old move event at %p in favour of new move event %p", event, ae);
// Delete the event and remove from list.
delete event;
}
}
queue.insertBack(this);
break;
default:
queue.insertBack(this);
break;
}
}
}
nsresult
nsAppShell::AddObserver(const nsAString &aObserverKey, nsIObserver *aObserver)
{

Просмотреть файл

@ -21,7 +21,6 @@
#include "nsIAndroidBridge.h"
namespace mozilla {
class AndroidGeckoEvent;
bool ProcessNextEvent();
void NotifyEvent();
}
@ -57,8 +56,6 @@ public:
}
};
class LegacyGeckoEvent;
template<typename T>
class LambdaEvent : public Event
{
@ -132,8 +129,6 @@ public:
mozilla::Move(lambda)));
}
static void PostEvent(mozilla::AndroidGeckoEvent* event);
// Post a event and wait for it to finish running on the Gecko thread.
static void SyncRunEvent(Event&& event,
mozilla::UniquePtr<Event>(*eventFactory)(

Просмотреть файл

@ -32,38 +32,11 @@ interface nsIAndroidBrowserApp : nsISupports {
nsIUITelemetryObserver getUITelemetryObserver();
};
[scriptable, uuid(92ae801d-da9c-4a24-b2b6-344c4af7008b)]
interface nsIAndroidViewport : nsISupports {
readonly attribute float x;
readonly attribute float y;
readonly attribute int32_t width;
readonly attribute int32_t height;
readonly attribute float pageLeft;
readonly attribute float pageTop;
readonly attribute float pageRight;
readonly attribute float pageBottom;
readonly attribute float cssPageLeft;
readonly attribute float cssPageTop;
readonly attribute float cssPageRight;
readonly attribute float cssPageBottom;
readonly attribute float zoom;
};
[scriptable, uuid(e1bfbc07-dbae-409d-a5b5-ef57522c1f15)]
interface nsIAndroidDisplayport : nsISupports {
attribute float left;
attribute float top;
attribute float right;
attribute float bottom;
attribute float resolution;
};
[scriptable, uuid(1beb70d3-70f3-4742-98cc-a3d301b26c0c)]
interface nsIAndroidBridge : nsISupports
{
[implicit_jscontext] void handleGeckoMessage(in jsval message);
attribute nsIAndroidBrowserApp browserApp;
nsIAndroidDisplayport getDisplayPort(in boolean aPageSizeUpdate, in boolean isBrowserContentDisplayed, in int32_t tabId, in nsIAndroidViewport metrics);
void contentDocumentChanged();
boolean isContentDocumentDisplayed();
};

Просмотреть файл

@ -1836,55 +1836,6 @@ nsWindow::CreateLayerManager(int aCompositorWidth, int aCompositorHeight)
}
}
void
nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
{
nsWindow *win = TopWindow();
if (!win)
return;
switch (ae->Type()) {
case AndroidGeckoEvent::APZ_INPUT_EVENT: {
win->UserActivity();
WidgetTouchEvent touchEvent = ae->MakeTouchEvent(win);
win->ProcessUntransformedAPZEvent(&touchEvent, ae->ApzGuid(), ae->ApzInputBlockId(), ae->ApzEventStatus());
win->DispatchHitTest(touchEvent);
break;
}
case AndroidGeckoEvent::MOTION_EVENT: {
win->UserActivity();
bool preventDefaultActions = win->OnMultitouchEvent(ae);
if (!preventDefaultActions && ae->Count() < 2) {
win->OnMouseEvent(ae);
}
break;
}
// LongPress events mostly trigger contextmenu options, but can also lead to
// textSelection processing.
case AndroidGeckoEvent::LONG_PRESS: {
win->UserActivity();
nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService();
obsServ->NotifyObservers(nullptr, "before-build-contextmenu", nullptr);
// Send the contextmenu event to Gecko.
if (!win->OnContextmenuEvent(ae)) {
// If not consumed, continue as a LongTap, possibly trigger
// Gecko Text Selection Carets.
win->OnLongTapEvent(ae);
}
break;
}
case AndroidGeckoEvent::NATIVE_GESTURE_EVENT: {
win->OnNativeGestureEvent(ae);
break;
}
}
}
void
nsWindow::OnSizeChanged(const gfx::IntSize& aSize)
{
@ -1979,80 +1930,6 @@ nsWindow::GetNativeData(uint32_t aDataType)
return nullptr;
}
void
nsWindow::OnMouseEvent(AndroidGeckoEvent *ae)
{
RefPtr<nsWindow> kungFuDeathGrip(this);
WidgetMouseEvent event = ae->MakeMouseEvent(this);
if (event.mMessage == eVoidEvent) {
// invalid event type, abort
return;
}
DispatchEvent(&event);
}
bool
nsWindow::OnContextmenuEvent(AndroidGeckoEvent *ae)
{
RefPtr<nsWindow> kungFuDeathGrip(this);
CSSPoint pt;
const nsTArray<nsIntPoint>& points = ae->Points();
if (points.Length() > 0) {
pt = CSSPoint(points[0].x, points[0].y);
}
// Send the contextmenu event.
WidgetMouseEvent contextMenuEvent(true, eContextMenu, this,
WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
contextMenuEvent.mRefPoint =
RoundedToInt(pt * GetDefaultScale()) - WidgetToScreenOffset();
contextMenuEvent.mIgnoreRootScrollFrame = true;
contextMenuEvent.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
nsEventStatus contextMenuStatus;
DispatchEvent(&contextMenuEvent, contextMenuStatus);
// If the contextmenu event was consumed (preventDefault issued), we follow with a
// touchcancel event. This avoids followup touchend events passsing through and
// triggering further element behaviour such as link-clicks.
if (contextMenuStatus == nsEventStatus_eConsumeNoDefault) {
WidgetTouchEvent canceltouchEvent = ae->MakeTouchEvent(this);
canceltouchEvent.mMessage = eTouchCancel;
DispatchEvent(&canceltouchEvent);
return true;
}
return false;
}
void
nsWindow::OnLongTapEvent(AndroidGeckoEvent *ae)
{
RefPtr<nsWindow> kungFuDeathGrip(this);
CSSPoint pt;
const nsTArray<nsIntPoint>& points = ae->Points();
if (points.Length() > 0) {
pt = CSSPoint(points[0].x, points[0].y);
}
// Send the LongTap event to Gecko.
WidgetMouseEvent event(true, eMouseLongTap, this,
WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
event.button = WidgetMouseEvent::eLeftButton;
event.mRefPoint =
RoundedToInt(pt * GetDefaultScale()) - WidgetToScreenOffset();
event.mClickCount = 1;
event.mTime = ae->Time();
event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
event.mIgnoreRootScrollFrame = true;
DispatchEvent(&event);
}
void
nsWindow::DispatchHitTest(const WidgetTouchEvent& aEvent)
{
@ -2075,120 +1952,6 @@ nsWindow::DispatchHitTest(const WidgetTouchEvent& aEvent)
}
}
bool nsWindow::OnMultitouchEvent(AndroidGeckoEvent *ae)
{
RefPtr<nsWindow> kungFuDeathGrip(this);
// End any composition in progress in case the touch event listener
// modifies the input field value (see bug 856155)
RemoveIMEComposition();
// This is set to true once we have called SetPreventPanning() exactly
// once for a given sequence of touch events. It is reset on the start
// of the next sequence.
static bool sDefaultPreventedNotified = false;
static bool sLastWasDownEvent = false;
bool preventDefaultActions = false;
bool isDownEvent = false;
WidgetTouchEvent event = ae->MakeTouchEvent(this);
if (event.mMessage != eVoidEvent) {
nsEventStatus status;
DispatchEvent(&event, status);
// We check mMultipleActionsPrevented because that's what <input type=range>
// sets when someone starts dragging the thumb. It doesn't set the status
// because it doesn't want to prevent the code that gives the input focus
// from running.
preventDefaultActions = (status == nsEventStatus_eConsumeNoDefault ||
event.mFlags.mMultipleActionsPrevented);
isDownEvent = (event.mMessage == eTouchStart);
}
DispatchHitTest(event);
// if the last event we got was a down event, then by now we know for sure whether
// this block has been default-prevented or not. if we haven't already sent the
// notification for this block, do so now.
if (sLastWasDownEvent && !sDefaultPreventedNotified) {
// if this event is a down event, that means it's the start of a new block, and the
// previous block should not be default-prevented
bool defaultPrevented = isDownEvent ? false : preventDefaultActions;
if (ae->Type() == AndroidGeckoEvent::APZ_INPUT_EVENT) {
if (mAPZC) {
AndroidContentController::NotifyDefaultPrevented(
mAPZC, ae->ApzInputBlockId(), defaultPrevented);
}
} else {
GeckoAppShell::NotifyDefaultPrevented(defaultPrevented);
}
sDefaultPreventedNotified = true;
}
// now, if this event is a down event, then we might already know that it has been
// default-prevented. if so, we send the notification right away; otherwise we wait
// for the next event.
if (isDownEvent) {
if (preventDefaultActions) {
if (ae->Type() == AndroidGeckoEvent::APZ_INPUT_EVENT) {
if (mAPZC) {
AndroidContentController::NotifyDefaultPrevented(
mAPZC, ae->ApzInputBlockId(), true);
}
} else {
GeckoAppShell::NotifyDefaultPrevented(true);
}
sDefaultPreventedNotified = true;
} else {
sDefaultPreventedNotified = false;
}
}
sLastWasDownEvent = isDownEvent;
return preventDefaultActions;
}
void
nsWindow::OnNativeGestureEvent(AndroidGeckoEvent *ae)
{
LayoutDeviceIntPoint pt(ae->Points()[0].x,
ae->Points()[0].y);
double delta = ae->X();
EventMessage msg = eVoidEvent;
switch (ae->Action()) {
case AndroidMotionEvent::ACTION_MAGNIFY_START:
msg = eMagnifyGestureStart;
mStartDist = delta;
mLastDist = delta;
break;
case AndroidMotionEvent::ACTION_MAGNIFY:
msg = eMagnifyGestureUpdate;
delta -= mLastDist;
mLastDist += delta;
break;
case AndroidMotionEvent::ACTION_MAGNIFY_END:
msg = eMagnifyGesture;
delta -= mStartDist;
break;
default:
return;
}
RefPtr<nsWindow> kungFuDeathGrip(this);
WidgetSimpleGestureEvent event(true, msg, this);
event.mDirection = 0;
event.mDelta = delta;
event.mModifiers = 0;
event.mTime = ae->Time();
event.mRefPoint = pt;
DispatchEvent(&event);
}
static unsigned int ConvertAndroidKeyCodeToDOMKeyCode(int androidKeyCode)
{
// Special-case alphanumeric keycodes because they are most common.

Просмотреть файл

@ -20,7 +20,6 @@
struct ANPEvent;
namespace mozilla {
class AndroidGeckoEvent;
class TextComposition;
class WidgetTouchEvent;
@ -68,15 +67,8 @@ private:
NPZCSupport* mNPZCSupport;
public:
static void OnGlobalAndroidEvent(mozilla::AndroidGeckoEvent *ae);
static nsWindow* TopWindow();
bool OnContextmenuEvent(mozilla::AndroidGeckoEvent *ae);
void OnLongTapEvent(mozilla::AndroidGeckoEvent *ae);
bool OnMultitouchEvent(mozilla::AndroidGeckoEvent *ae);
void OnNativeGestureEvent(mozilla::AndroidGeckoEvent *ae);
void OnMouseEvent(mozilla::AndroidGeckoEvent *ae);
void OnSizeChanged(const mozilla::gfx::IntSize& aSize);
void InitEvent(mozilla::WidgetGUIEvent& event,