Bug 799094 - Refactor handle-picking code into a reusable method. r=margaret

This commit is contained in:
Kartikaya Gupta 2012-10-18 13:41:06 -04:00
parent 65733730db
commit 86ffca961d

View File

@ -54,6 +54,16 @@ class TextSelection extends Layer implements GeckoEventListener {
unregisterEventListener("TextSelection:PositionHandles");
}
private TextSelectionHandle getHandle(String name) {
if (name.equals("START")) {
return mStartHandle;
} else if (name.equals("MIDDLE")) {
return mMiddleHandle;
} else {
return mEndHandle;
}
}
public void handleMessage(String event, JSONObject message) {
try {
if (event.equals("TextSelection:ShowHandles")) {
@ -63,13 +73,7 @@ class TextSelection extends Layer implements GeckoEventListener {
try {
for (int i=0; i < handles.length(); i++) {
String handle = handles.getString(i);
if (handle.equals("START"))
mStartHandle.setVisibility(View.VISIBLE);
else if (handle.equals("MIDDLE"))
mMiddleHandle.setVisibility(View.VISIBLE);
else
mEndHandle.setVisibility(View.VISIBLE);
getHandle(handle).setVisibility(View.VISIBLE);
}
mViewLeft = 0.0f;
@ -94,12 +98,7 @@ class TextSelection extends Layer implements GeckoEventListener {
for (int i=0; i < handles.length(); i++) {
String handle = handles.getString(i);
if (handle.equals("START"))
mStartHandle.setVisibility(View.GONE);
else if (handle.equals("MIDDLE"))
mMiddleHandle.setVisibility(View.GONE);
else
mEndHandle.setVisibility(View.GONE);
getHandle(handle).setVisibility(View.GONE);
}
} catch(Exception e) {}
@ -116,12 +115,7 @@ class TextSelection extends Layer implements GeckoEventListener {
int left = position.getInt("left");
int top = position.getInt("top");
if (handle.equals("START"))
mStartHandle.positionFromGecko(left, top);
else if (handle.equals("MIDDLE"))
mMiddleHandle.positionFromGecko(left, top);
else
mEndHandle.positionFromGecko(left, top);
getHandle(handle).positionFromGecko(left, top);
}
} catch (Exception e) { }
}