mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 795045 - Part 1: Cleanup for TextSelection/TextSelectionHandle. r=wesj
This commit is contained in:
parent
79fef6eac8
commit
9c1661ae3b
@ -1720,7 +1720,8 @@ abstract public class GeckoApp
|
||||
mTextSelection = new TextSelection((TextSelectionHandle) findViewById(R.id.start_handle),
|
||||
(TextSelectionHandle) findViewById(R.id.middle_handle),
|
||||
(TextSelectionHandle) findViewById(R.id.end_handle),
|
||||
GeckoAppShell.getEventDispatcher());
|
||||
GeckoAppShell.getEventDispatcher(),
|
||||
this);
|
||||
|
||||
PrefsHelper.getPref("app.update.autodownload", new PrefsHelper.PrefHandlerBase() {
|
||||
@Override public void prefValue(String pref, String value) {
|
||||
|
@ -12,6 +12,7 @@ import org.mozilla.gecko.util.FloatUtils;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.util.Log;
|
||||
@ -29,14 +30,18 @@ class TextSelection extends Layer implements GeckoEventListener {
|
||||
private float mViewTop;
|
||||
private float mViewZoom;
|
||||
|
||||
private GeckoApp mActivity;
|
||||
|
||||
TextSelection(TextSelectionHandle startHandle,
|
||||
TextSelectionHandle middleHandle,
|
||||
TextSelectionHandle endHandle,
|
||||
EventDispatcher eventDispatcher) {
|
||||
EventDispatcher eventDispatcher,
|
||||
GeckoApp activity) {
|
||||
mStartHandle = startHandle;
|
||||
mMiddleHandle = middleHandle;
|
||||
mEndHandle = endHandle;
|
||||
mEventDispatcher = eventDispatcher;
|
||||
mActivity = activity;
|
||||
|
||||
// Only register listeners if we have valid start/middle/end handles
|
||||
if (mStartHandle == null || mMiddleHandle == null || mEndHandle == null) {
|
||||
@ -64,68 +69,53 @@ class TextSelection extends Layer implements GeckoEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void handleMessage(String event, JSONObject message) {
|
||||
try {
|
||||
if (event.equals("TextSelection:ShowHandles")) {
|
||||
final JSONArray handles = message.getJSONArray("handles");
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
for (int i=0; i < handles.length(); i++) {
|
||||
String handle = handles.getString(i);
|
||||
getHandle(handle).setVisibility(View.VISIBLE);
|
||||
}
|
||||
public void handleMessage(final String event, final JSONObject message) {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
if (event.equals("TextSelection:ShowHandles")) {
|
||||
final JSONArray handles = message.getJSONArray("handles");
|
||||
for (int i=0; i < handles.length(); i++) {
|
||||
String handle = handles.getString(i);
|
||||
getHandle(handle).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mViewLeft = 0.0f;
|
||||
mViewTop = 0.0f;
|
||||
mViewZoom = 0.0f;
|
||||
LayerView layerView = GeckoApp.mAppContext.getLayerView();
|
||||
if (layerView != null) {
|
||||
layerView.addLayer(TextSelection.this);
|
||||
}
|
||||
} catch(Exception e) {}
|
||||
mViewLeft = 0.0f;
|
||||
mViewTop = 0.0f;
|
||||
mViewZoom = 0.0f;
|
||||
LayerView layerView = mActivity.getLayerView();
|
||||
if (layerView != null) {
|
||||
layerView.addLayer(TextSelection.this);
|
||||
}
|
||||
} else if (event.equals("TextSelection:HideHandles")) {
|
||||
final JSONArray handles = message.getJSONArray("handles");
|
||||
LayerView layerView = mActivity.getLayerView();
|
||||
if (layerView != null) {
|
||||
layerView.removeLayer(TextSelection.this);
|
||||
}
|
||||
|
||||
for (int i=0; i < handles.length(); i++) {
|
||||
String handle = handles.getString(i);
|
||||
getHandle(handle).setVisibility(View.GONE);
|
||||
}
|
||||
} else if (event.equals("TextSelection:PositionHandles")) {
|
||||
final boolean rtl = message.getBoolean("rtl");
|
||||
final JSONArray positions = message.getJSONArray("positions");
|
||||
for (int i=0; i < positions.length(); i++) {
|
||||
JSONObject position = positions.getJSONObject(i);
|
||||
int left = position.getInt("left");
|
||||
int top = position.getInt("top");
|
||||
|
||||
TextSelectionHandle handle = getHandle(position.getString("handle"));
|
||||
handle.setVisibility(position.getBoolean("hidden") ? View.GONE : View.VISIBLE);
|
||||
handle.positionFromGecko(left, top, rtl);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (event.equals("TextSelection:HideHandles")) {
|
||||
final JSONArray handles = message.getJSONArray("handles");
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
LayerView layerView = GeckoApp.mAppContext.getLayerView();
|
||||
if (layerView != null) {
|
||||
layerView.removeLayer(TextSelection.this);
|
||||
}
|
||||
|
||||
for (int i=0; i < handles.length(); i++) {
|
||||
String handle = handles.getString(i);
|
||||
getHandle(handle).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
});
|
||||
} else if (event.equals("TextSelection:PositionHandles")) {
|
||||
final boolean rtl = message.getBoolean("rtl");
|
||||
final JSONArray positions = message.getJSONArray("positions");
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
for (int i=0; i < positions.length(); i++) {
|
||||
JSONObject position = positions.getJSONObject(i);
|
||||
int left = position.getInt("left");
|
||||
int top = position.getInt("top");
|
||||
|
||||
TextSelectionHandle handle = getHandle(position.getString("handle"));
|
||||
handle.setVisibility(position.getBoolean("hidden") ? View.GONE : View.VISIBLE);
|
||||
handle.positionFromGecko(left, top, rtl);
|
||||
}
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOGTAG, "JSON exception", e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -142,7 +132,7 @@ class TextSelection extends Layer implements GeckoEventListener {
|
||||
mViewTop = context.viewport.top;
|
||||
mViewZoom = context.zoomFactor;
|
||||
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
mStartHandle.repositionWithViewport(context.viewport.left, context.viewport.top, context.zoomFactor);
|
||||
mMiddleHandle.repositionWithViewport(context.viewport.left, context.viewport.top, context.zoomFactor);
|
||||
|
@ -41,9 +41,12 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
|
||||
private static final int IMAGE_LEVEL_LTR = 0;
|
||||
private static final int IMAGE_LEVEL_RTL = 1;
|
||||
|
||||
private GeckoApp mActivity;
|
||||
|
||||
TextSelectionHandle(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setOnTouchListener(this);
|
||||
mActivity = (GeckoApp) context;
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextSelectionHandle);
|
||||
int handleType = a.getInt(R.styleable.TextSelectionHandle_handleType, 0x01);
|
||||
@ -96,7 +99,7 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
|
||||
mLeft = mLeft + newX - mTouchStartX;
|
||||
mTop = mTop + newY - mTouchStartY;
|
||||
|
||||
LayerView layerView = GeckoApp.mAppContext.getLayerView();
|
||||
LayerView layerView = mActivity.getLayerView();
|
||||
if (layerView == null) {
|
||||
Log.e(LOGTAG, "Can't move selection because layerView is null");
|
||||
return;
|
||||
@ -121,7 +124,7 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
|
||||
}
|
||||
|
||||
void positionFromGecko(int left, int top, boolean rtl) {
|
||||
LayerView layerView = GeckoApp.mAppContext.getLayerView();
|
||||
LayerView layerView = mActivity.getLayerView();
|
||||
if (layerView == null) {
|
||||
Log.e(LOGTAG, "Can't position handle because layerView is null");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user