2012-07-20 00:16:44 +04: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/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-07-26 18:13:48 +04:00
|
|
|
import org.mozilla.gecko.gfx.Layer;
|
|
|
|
import org.mozilla.gecko.gfx.Layer.RenderContext;
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 21:42:05 +04:00
|
|
|
import org.mozilla.gecko.gfx.LayerController;
|
2012-07-28 04:53:54 +04:00
|
|
|
|
2012-07-20 00:16:44 +04:00
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2012-07-28 04:53:54 +04:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.View;
|
|
|
|
|
2012-07-26 18:13:48 +04:00
|
|
|
class TextSelection extends Layer implements GeckoEventListener {
|
2012-07-20 00:16:44 +04:00
|
|
|
private static final String LOGTAG = "GeckoTextSelection";
|
|
|
|
|
|
|
|
private final TextSelectionHandle mStartHandle;
|
|
|
|
private final TextSelectionHandle mEndHandle;
|
|
|
|
|
2012-07-26 18:13:48 +04:00
|
|
|
private float mViewLeft;
|
|
|
|
private float mViewTop;
|
|
|
|
private float mViewZoom;
|
|
|
|
|
2012-07-20 00:16:44 +04:00
|
|
|
TextSelection(TextSelectionHandle startHandle, TextSelectionHandle endHandle) {
|
|
|
|
mStartHandle = startHandle;
|
|
|
|
mEndHandle = endHandle;
|
|
|
|
|
2012-07-24 02:41:55 +04:00
|
|
|
// Only register listeners if we have valid start/end handles
|
|
|
|
if (mStartHandle == null || mEndHandle == null) {
|
|
|
|
Log.e(LOGTAG, "Failed to initialize text selection because at least one handle is null");
|
|
|
|
} else {
|
|
|
|
GeckoAppShell.registerGeckoEventListener("TextSelection:ShowHandles", this);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("TextSelection:HideHandles", this);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("TextSelection:PositionHandles", this);
|
|
|
|
}
|
2012-07-20 00:16:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void destroy() {
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("TextSelection:ShowHandles", this);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("TextSelection:HideHandles", this);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("TextSelection:PositionHandles", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
try {
|
|
|
|
if (event.equals("TextSelection:ShowHandles")) {
|
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mStartHandle.setVisibility(View.VISIBLE);
|
|
|
|
mEndHandle.setVisibility(View.VISIBLE);
|
2012-07-26 18:13:48 +04:00
|
|
|
|
|
|
|
mViewLeft = 0.0f;
|
|
|
|
mViewTop = 0.0f;
|
|
|
|
mViewZoom = 0.0f;
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 21:42:05 +04:00
|
|
|
LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
|
|
|
if (layerController != null) {
|
|
|
|
layerController.getView().addLayer(TextSelection.this);
|
2012-07-26 18:13:48 +04:00
|
|
|
}
|
2012-07-20 00:16:44 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (event.equals("TextSelection:HideHandles")) {
|
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 21:42:05 +04:00
|
|
|
LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
|
|
|
if (layerController != null) {
|
|
|
|
layerController.getView().removeLayer(TextSelection.this);
|
2012-07-26 18:13:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-20 00:16:44 +04:00
|
|
|
mStartHandle.setVisibility(View.GONE);
|
|
|
|
mEndHandle.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (event.equals("TextSelection:PositionHandles")) {
|
|
|
|
final int startLeft = message.getInt("startLeft");
|
|
|
|
final int startTop = message.getInt("startTop");
|
|
|
|
final int endLeft = message.getInt("endLeft");
|
|
|
|
final int endTop = message.getInt("endTop");
|
|
|
|
|
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mStartHandle.positionFromGecko(startLeft, startTop);
|
|
|
|
mEndHandle.positionFromGecko(endLeft, endTop);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 18:13:48 +04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void draw(final RenderContext context) {
|
|
|
|
// cache the relevant values from the context and bail out if they are the same. we do this
|
|
|
|
// because this draw function gets called a lot (once per compositor frame) and we want to
|
|
|
|
// avoid doing a lot of extra work in cases where it's not needed.
|
|
|
|
if (FloatUtils.fuzzyEquals(mViewLeft, context.viewport.left)
|
|
|
|
&& FloatUtils.fuzzyEquals(mViewTop, context.viewport.top)
|
|
|
|
&& FloatUtils.fuzzyEquals(mViewZoom, context.zoomFactor)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mViewLeft = context.viewport.left;
|
|
|
|
mViewTop = context.viewport.top;
|
|
|
|
mViewZoom = context.zoomFactor;
|
|
|
|
|
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mStartHandle.repositionWithViewport(context.viewport.left, context.viewport.top, context.zoomFactor);
|
|
|
|
mEndHandle.repositionWithViewport(context.viewport.left, context.viewport.top, context.zoomFactor);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-07-20 00:16:44 +04:00
|
|
|
}
|