Bug 716673 - Refactor some code that sends messages to Gecko. r=pcwalton

This commit is contained in:
Kartikaya Gupta 2012-01-10 10:05:42 -05:00
Родитель 27e3a608b8
Коммит 33da0d74c0
1 изменённых файлов: 13 добавлений и 41 удалений

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

@ -1025,8 +1025,7 @@ public class PanZoomController
mLastEventTime = detector.getEventTime(); mLastEventTime = detector.getEventTime();
} }
@Override private void sendPointToGecko(String event, MotionEvent motionEvent) {
public void onLongPress(MotionEvent motionEvent) {
String json; String json;
try { try {
PointF point = new PointF(motionEvent.getX(), motionEvent.getY()); PointF point = new PointF(motionEvent.getX(), motionEvent.getY());
@ -1035,13 +1034,17 @@ public class PanZoomController
return; return;
} }
json = PointUtils.toJSON(point).toString(); json = PointUtils.toJSON(point).toString();
} catch(Exception ex) { } catch (Exception e) {
Log.w(LOGTAG, "Error building return: " + ex); Log.e(LOGTAG, "Unable to convert point to JSON for " + event, e);
return; // json would be null return;
} }
GeckoEvent e = new GeckoEvent("Gesture:LongPress", json); GeckoAppShell.sendEventToGecko(new GeckoEvent(event, json));
GeckoAppShell.sendEventToGecko(e); }
@Override
public void onLongPress(MotionEvent motionEvent) {
sendPointToGecko("Gesture:LongPress", motionEvent);
} }
public boolean getRedrawHint() { public boolean getRedrawHint() {
@ -1050,35 +1053,14 @@ public class PanZoomController
@Override @Override
public boolean onDown(MotionEvent motionEvent) { public boolean onDown(MotionEvent motionEvent) {
String json; sendPointToGecko("Gesture:ShowPress", motionEvent);
try {
PointF point = new PointF(motionEvent.getX(), motionEvent.getY());
point = mController.convertViewPointToLayerPoint(point);
json = PointUtils.toJSON(point).toString();
} catch(Exception ex) {
throw new RuntimeException(ex);
}
GeckoEvent e = new GeckoEvent("Gesture:ShowPress", json);
GeckoAppShell.sendEventToGecko(e);
return false; return false;
} }
@Override @Override
public boolean onSingleTapConfirmed(MotionEvent motionEvent) { public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
String json;
try {
PointF point = new PointF(motionEvent.getX(), motionEvent.getY());
point = mController.convertViewPointToLayerPoint(point);
json = PointUtils.toJSON(point).toString();
} catch(Exception ex) {
throw new RuntimeException(ex);
}
GeckoApp.mAppContext.mAutoCompletePopup.hide(); GeckoApp.mAppContext.mAutoCompletePopup.hide();
sendPointToGecko("Gesture:SingleTap", motionEvent);
GeckoEvent e = new GeckoEvent("Gesture:SingleTap", json);
GeckoAppShell.sendEventToGecko(e);
return true; return true;
} }
@ -1089,17 +1071,7 @@ public class PanZoomController
@Override @Override
public boolean onDoubleTap(MotionEvent motionEvent) { public boolean onDoubleTap(MotionEvent motionEvent) {
String json; sendPointToGecko("Gesture:DoubleTap", motionEvent);
try {
PointF point = new PointF(motionEvent.getX(), motionEvent.getY());
point = mController.convertViewPointToLayerPoint(point);
json = PointUtils.toJSON(point).toString();
} catch(Exception ex) {
throw new RuntimeException(ex);
}
GeckoEvent e = new GeckoEvent("Gesture:DoubleTap", json);
GeckoAppShell.sendEventToGecko(e);
return true; return true;
} }