diff --git a/mobile/android/base/TextSelection.java b/mobile/android/base/TextSelection.java index 59dfcff9f59..8a4a2c68924 100644 --- a/mobile/android/base/TextSelection.java +++ b/mobile/android/base/TextSelection.java @@ -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) { } }