This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d32f1e3
commit 24bdecf
Showing
6 changed files
with
505 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.mozilla.servo; | ||
|
||
import android.view.Surface; | ||
|
||
import org.mozilla.geckoview.GeckoDisplay; | ||
import org.mozilla.geckoview.GeckoSession; | ||
|
||
public class ServoDisplay extends GeckoDisplay { | ||
|
||
private final ServoSession mServoSession; | ||
|
||
public ServoDisplay(final GeckoSession session) { | ||
super(session); | ||
mServoSession = (ServoSession) session; | ||
} | ||
|
||
@Override | ||
public void surfaceChanged(final Surface surface, final int width, final int height) { | ||
mServoSession.onSurfaceReady(surface, width, height); | ||
} | ||
|
||
@Override | ||
public void surfaceDestroyed() { | ||
// FIXME | ||
} | ||
|
||
@Override | ||
public void screenOriginChanged(final int left, final int top) { | ||
// FIXME | ||
} | ||
|
||
@Override | ||
public boolean shouldPinOnScreen() { | ||
// FIXME | ||
return false; | ||
} | ||
|
||
} |
202 changes: 202 additions & 0 deletions
202
app/src/common/shared/org/mozilla/servo/ServoPanZoomController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
package org.mozilla.servo; | ||
|
||
import android.view.MotionEvent; | ||
import android.graphics.Rect; | ||
import android.util.Pair; | ||
import android.view.InputDevice; | ||
|
||
import org.mozilla.gecko.gfx.PanZoomController; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ServoPanZoomController extends PanZoomController { | ||
|
||
private static final int EVENT_SOURCE_SCROLL = 0; | ||
private static final int EVENT_SOURCE_MOTION = 1; | ||
private final Rect mTempRect = new Rect(); | ||
private boolean mAttached; | ||
private float mPointerScrollFactor = 64.0f; | ||
private long mLastDownTime; | ||
private boolean mIsScrolling = false; | ||
private final ServoSession mSession; | ||
|
||
ServoPanZoomController(ServoSession session) { | ||
super(null); | ||
mSession = session; | ||
enableEventQueue(); | ||
setAttached(true); // FIXME | ||
} | ||
|
||
private ArrayList<Pair<Integer, MotionEvent>> mQueuedEvents; | ||
|
||
private boolean handleMotionEvent( | ||
int action, int actionIndex, long time, int metaState, | ||
int pointerId[], float x[], float y[], float orientation[], float pressure[], | ||
float toolMajor[], float toolMinor[]) { | ||
|
||
if (action == MotionEvent.ACTION_UP) { | ||
mSession.click((int)x[0], (int)y[0]); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private boolean handleScrollEvent(long _time, int _metaState, float x, float y, float hScroll, float vScroll) { | ||
if (!mIsScrolling) { | ||
mSession.scrollStart((int)hScroll, (int)vScroll, (int)x, (int)y); | ||
} else { | ||
mSession.scroll((int)hScroll, (int)vScroll, (int)x, (int)y); | ||
} | ||
mIsScrolling = true; | ||
return true; | ||
} | ||
|
||
private boolean handleMotionEvent(MotionEvent event) { | ||
if (!mAttached) { | ||
mQueuedEvents.add(new Pair(EVENT_SOURCE_MOTION, event)); | ||
return false; | ||
} | ||
|
||
final int action = event.getActionMasked(); | ||
final int count = event.getPointerCount(); | ||
|
||
if (action == MotionEvent.ACTION_DOWN) { | ||
mLastDownTime = event.getDownTime(); | ||
} else if (mLastDownTime != event.getDownTime()) { | ||
return false; | ||
} | ||
|
||
final int[] pointerId = new int[count]; | ||
final float[] x = new float[count]; | ||
final float[] y = new float[count]; | ||
final float[] orientation = new float[count]; | ||
final float[] pressure = new float[count]; | ||
final float[] toolMajor = new float[count]; | ||
final float[] toolMinor = new float[count]; | ||
|
||
final MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords(); | ||
|
||
for (int i = 0; i < count; i++) { | ||
pointerId[i] = event.getPointerId(i); | ||
event.getPointerCoords(i, coords); | ||
x[i] = coords.x; | ||
y[i] = coords.y; | ||
orientation[i] = coords.orientation; | ||
pressure[i] = coords.pressure; | ||
toolMajor[i] = coords.toolMajor; | ||
toolMinor[i] = coords.toolMinor; | ||
} | ||
|
||
return handleMotionEvent(action, event.getActionIndex(), event.getEventTime(), | ||
event.getMetaState(), pointerId, x, y, orientation, pressure, | ||
toolMajor, toolMinor); | ||
} | ||
|
||
private boolean handleScrollEvent(MotionEvent event) { | ||
if (!mAttached) { | ||
mQueuedEvents.add(new Pair(EVENT_SOURCE_SCROLL, event)); | ||
return false; | ||
} | ||
|
||
final int count = event.getPointerCount(); | ||
|
||
if (count <= 0) { | ||
return false; | ||
} | ||
|
||
final MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords(); | ||
event.getPointerCoords(0, coords); | ||
|
||
// Translate surface origin to client origin for scroll events. | ||
mSession.getSurfaceBounds(mTempRect); | ||
final float x = coords.x - mTempRect.left; | ||
final float y = coords.y - mTempRect.top; | ||
|
||
final float hScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL) * mPointerScrollFactor; | ||
final float vScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL) * mPointerScrollFactor; | ||
|
||
return handleScrollEvent(event.getEventTime(), event.getMetaState(), x, y, | ||
hScroll, vScroll); | ||
} | ||
|
||
@Override | ||
public boolean onTouchEvent(final MotionEvent event) { | ||
return handleMotionEvent(event); | ||
} | ||
|
||
@Override | ||
public boolean onMotionEvent(MotionEvent event) { | ||
final int action = event.getActionMasked(); | ||
if (action == MotionEvent.ACTION_SCROLL) { | ||
if (event.getDownTime() >= mLastDownTime) { | ||
mLastDownTime = event.getDownTime(); | ||
} else if ((InputDevice.getDevice(event.getDeviceId()).getSources() & | ||
InputDevice.SOURCE_TOUCHPAD) == InputDevice.SOURCE_TOUCHPAD) { | ||
return false; | ||
} | ||
return handleScrollEvent(event); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void setScrollFactor(final float factor) { | ||
mPointerScrollFactor = factor; | ||
} | ||
|
||
@Override | ||
public float getScrollFactor() { | ||
return mPointerScrollFactor; | ||
} | ||
|
||
@Override | ||
public boolean onMouseEvent(final MotionEvent event) { | ||
if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) { | ||
// FIXME | ||
return false; | ||
} | ||
return handleMotionEvent(event); | ||
} | ||
|
||
@Override | ||
public void setIsLongpressEnabled(boolean isLongpressEnabled) { | ||
// FIXME | ||
} | ||
|
||
private void enableEventQueue() { | ||
if (mQueuedEvents != null) { | ||
throw new IllegalStateException("Already have an event queue"); | ||
} | ||
mQueuedEvents = new ArrayList(); | ||
} | ||
|
||
private void flushEventQueue() { | ||
if (mQueuedEvents == null) { | ||
return; | ||
} | ||
|
||
ArrayList<Pair<Integer, MotionEvent>> events = mQueuedEvents; | ||
mQueuedEvents = null; | ||
for (Pair<Integer, MotionEvent> pair : events) { | ||
switch (pair.first) { | ||
case EVENT_SOURCE_MOTION: | ||
handleMotionEvent(pair.second); | ||
break; | ||
case EVENT_SOURCE_SCROLL: | ||
handleScrollEvent(pair.second); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private void setAttached(final boolean attached) { | ||
if (attached) { | ||
mAttached = true; | ||
flushEventQueue(); | ||
} else if (mAttached) { | ||
mAttached = false; | ||
enableEventQueue(); | ||
} | ||
} | ||
} |
Oops, something went wrong.