Bug 1106800 - Rename Selection Handle Names, r=margaret

--HG--
rename : mobile/android/base/resources/drawable/handle_start_level.xml => mobile/android/base/resources/drawable/handle_anchor_level.xml
rename : mobile/android/base/resources/drawable/handle_end_level.xml => mobile/android/base/resources/drawable/handle_focus_level.xml
This commit is contained in:
Mark Capella 2014-12-30 16:42:17 -05:00
parent a4a993c60f
commit 6103040147
7 changed files with 72 additions and 52 deletions

View File

@ -1586,9 +1586,9 @@ public abstract class GeckoApp
mPromptService = new PromptService(this);
mTextSelection = new TextSelection((TextSelectionHandle) findViewById(R.id.start_handle),
(TextSelectionHandle) findViewById(R.id.middle_handle),
(TextSelectionHandle) findViewById(R.id.end_handle),
mTextSelection = new TextSelection((TextSelectionHandle) findViewById(R.id.anchor_handle),
(TextSelectionHandle) findViewById(R.id.caret_handle),
(TextSelectionHandle) findViewById(R.id.focus_handle),
EventDispatcher.getInstance(),
this);

View File

@ -36,10 +36,10 @@ import android.view.View;
class TextSelection extends Layer implements GeckoEventListener {
private static final String LOGTAG = "GeckoTextSelection";
private final TextSelectionHandle mStartHandle;
private final TextSelectionHandle mMiddleHandle;
private final TextSelectionHandle mEndHandle;
private final EventDispatcher mEventDispatcher;
private final TextSelectionHandle anchorHandle;
private final TextSelectionHandle caretHandle;
private final TextSelectionHandle focusHandle;
private final EventDispatcher eventDispatcher;
private final DrawListener mDrawListener;
private boolean mDraggingHandles;
@ -68,15 +68,15 @@ class TextSelection extends Layer implements GeckoEventListener {
};
private ActionModeTimerTask mActionModeTimerTask;
TextSelection(TextSelectionHandle startHandle,
TextSelectionHandle middleHandle,
TextSelectionHandle endHandle,
TextSelection(TextSelectionHandle anchorHandle,
TextSelectionHandle caretHandle,
TextSelectionHandle focusHandle,
EventDispatcher eventDispatcher,
GeckoApp activity) {
mStartHandle = startHandle;
mMiddleHandle = middleHandle;
mEndHandle = endHandle;
mEventDispatcher = eventDispatcher;
this.anchorHandle = anchorHandle;
this.caretHandle = caretHandle;
this.focusHandle = focusHandle;
this.eventDispatcher = eventDispatcher;
mDrawListener = new DrawListener() {
@Override
@ -88,7 +88,7 @@ class TextSelection extends Layer implements GeckoEventListener {
};
// Only register listeners if we have valid start/middle/end handles
if (mStartHandle == null || mMiddleHandle == null || mEndHandle == null) {
if (anchorHandle == null || caretHandle == null || focusHandle == null) {
Log.e(LOGTAG, "Failed to initialize text selection because at least one handle is null");
} else {
EventDispatcher.getInstance().registerGeckoThreadListener(this,
@ -111,12 +111,12 @@ class TextSelection extends Layer implements GeckoEventListener {
private TextSelectionHandle getHandle(String name) {
switch (TextSelectionHandle.HandleType.valueOf(name)) {
case START:
return mStartHandle;
case MIDDLE:
return mMiddleHandle;
case END:
return mEndHandle;
case ANCHOR:
return anchorHandle;
case CARET:
return caretHandle;
case FOCUS:
return focusHandle;
default:
throw new IllegalArgumentException("TextSelectionHandle is invalid type.");
@ -169,9 +169,9 @@ class TextSelection extends Layer implements GeckoEventListener {
mActionModeTimerTask = new ActionModeTimerTask();
mActionModeTimer.schedule(mActionModeTimerTask, 250);
mStartHandle.setVisibility(View.GONE);
mMiddleHandle.setVisibility(View.GONE);
mEndHandle.setVisibility(View.GONE);
anchorHandle.setVisibility(View.GONE);
caretHandle.setVisibility(View.GONE);
focusHandle.setVisibility(View.GONE);
} else if (event.equals("TextSelection:PositionHandles")) {
final boolean rtl = message.getBoolean("rtl");
final JSONArray positions = message.getJSONArray("positions");
@ -204,7 +204,7 @@ class TextSelection extends Layer implements GeckoEventListener {
return;
}
final Context context = mStartHandle.getContext();
final Context context = anchorHandle.getContext();
if (context instanceof ActionModeCompat.Presenter) {
final ActionModeCompat.Presenter presenter = (ActionModeCompat.Presenter) context;
mCallback = new TextSelectionActionModeCallback(items);
@ -213,7 +213,7 @@ class TextSelection extends Layer implements GeckoEventListener {
}
private void endActionMode() {
Context context = mStartHandle.getContext();
Context context = anchorHandle.getContext();
if (context instanceof ActionModeCompat.Presenter) {
final ActionModeCompat.Presenter presenter = (ActionModeCompat.Presenter) context;
presenter.endActionModeCompat();
@ -242,9 +242,9 @@ class TextSelection extends Layer implements GeckoEventListener {
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
mStartHandle.repositionWithViewport(viewLeft, viewTop, viewZoom);
mMiddleHandle.repositionWithViewport(viewLeft, viewTop, viewZoom);
mEndHandle.repositionWithViewport(viewLeft, viewTop, viewZoom);
anchorHandle.repositionWithViewport(viewLeft, viewTop, viewZoom);
caretHandle.repositionWithViewport(viewLeft, viewTop, viewZoom);
focusHandle.repositionWithViewport(viewLeft, viewTop, viewZoom);
}
});
}
@ -280,7 +280,7 @@ class TextSelection extends Layer implements GeckoEventListener {
final int actionEnum = obj.optBoolean("showAsAction") ? GeckoMenuItem.SHOW_AS_ACTION_ALWAYS : GeckoMenuItem.SHOW_AS_ACTION_NEVER;
menuitem.setShowAsAction(actionEnum, R.attr.menuItemActionModeStyle);
BitmapUtils.getDrawable(mStartHandle.getContext(), obj.optString("icon"), new BitmapLoader() {
BitmapUtils.getDrawable(anchorHandle.getContext(), obj.optString("icon"), new BitmapLoader() {
@Override
public void onBitmapFound(Drawable d) {
if (d != null) {

View File

@ -19,10 +19,30 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
/**
* Text selection handles enable a user to change position of selected text in
* Gecko's DOM structure.
*
* A text "Selection" or nsISelection object, has start and end positions,
* referred to as Anchor and Focus objects.
*
* If the Anchor and Focus objects are at the same point, it represents a text
* selection Caret, commonly diplayed as a blinking, vertical |.
*
* Anchor and Focus objects each represent a DOM node, and character offset
* from the start of the node. The Anchor always refers to the start of the
* Selection, and the Focus refers to its end.
*
* In LTR languages such as English, the Anchor is to the left of the Focus.
* In RTL languages such as Hebrew, the Anchor is to the right of the Focus.
*
* For multi-line Selections, in both LTR and RTL languages, the Anchor starts
* above the Focus.
*/
class TextSelectionHandle extends ImageView implements View.OnTouchListener {
private static final String LOGTAG = "GeckoTextSelectionHandle";
public enum HandleType { START, MIDDLE, END };
public enum HandleType { ANCHOR, CARET, FOCUS };
private final HandleType mHandleType;
private final int mWidth;
@ -51,11 +71,11 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
int handleType = a.getInt(R.styleable.TextSelectionHandle_handleType, 0x01);
if (handleType == 0x01)
mHandleType = HandleType.START;
mHandleType = HandleType.ANCHOR;
else if (handleType == 0x02)
mHandleType = HandleType.MIDDLE;
mHandleType = HandleType.CARET;
else
mHandleType = HandleType.END;
mHandleType = HandleType.FOCUS;
mGeckoPoint = new PointF(0.0f, 0.0f);
@ -132,7 +152,7 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
// will tell us the position of the caret, so we set the handle
// position then. This allows us to lock the handle to wherever the
// caret appears.
if (mHandleType != HandleType.MIDDLE) {
if (mHandleType != HandleType.CARET) {
setLayoutPosition();
}
}
@ -166,9 +186,9 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
}
private float adjustLeftForHandle() {
if (mHandleType == HandleType.START) {
if (mHandleType == HandleType.ANCHOR) {
return mIsRTL ? mShadow : mWidth - mShadow;
} else if (mHandleType == HandleType.MIDDLE) {
} else if (mHandleType == HandleType.CARET) {
return mWidth / 2;
} else {
return mIsRTL ? mWidth - mShadow : mShadow;

View File

@ -6,24 +6,24 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<org.mozilla.gecko.TextSelectionHandle android:id="@+id/start_handle"
<org.mozilla.gecko.TextSelectionHandle android:id="@+id/anchor_handle"
android:layout_width="@dimen/text_selection_handle_width"
android:layout_height="@dimen/text_selection_handle_height"
android:src="@drawable/handle_start_level"
android:src="@drawable/handle_anchor_level"
android:visibility="gone"
gecko:handleType="start"/>
<org.mozilla.gecko.TextSelectionHandle android:id="@+id/middle_handle"
<org.mozilla.gecko.TextSelectionHandle android:id="@+id/caret_handle"
android:layout_width="@dimen/text_selection_handle_width"
android:layout_height="@dimen/text_selection_handle_height"
android:src="@drawable/handle_middle"
android:visibility="gone"
gecko:handleType="middle"/>
<org.mozilla.gecko.TextSelectionHandle android:id="@+id/end_handle"
<org.mozilla.gecko.TextSelectionHandle android:id="@+id/focus_handle"
android:layout_width="@dimen/text_selection_handle_width"
android:layout_height="@dimen/text_selection_handle_height"
android:src="@drawable/handle_end_level"
android:src="@drawable/handle_focus_level"
android:visibility="gone"
gecko:handleType="end"/>
</merge>

View File

@ -8,9 +8,9 @@
const PHONE_NUMBER_CONTAINERS = "td,div";
var SelectionHandler = {
HANDLE_TYPE_START: "START",
HANDLE_TYPE_MIDDLE: "MIDDLE",
HANDLE_TYPE_END: "END",
HANDLE_TYPE_ANCHOR: "ANCHOR",
HANDLE_TYPE_CARET: "CARET",
HANDLE_TYPE_FOCUS: "FOCUS",
TYPE_NONE: 0,
TYPE_CURSOR: 1,
@ -133,7 +133,7 @@ var SelectionHandler = {
let data = JSON.parse(aData);
if (this._activeType == this.TYPE_SELECTION) {
this._startDraggingHandles();
this._moveSelection(data.handleType == this.HANDLE_TYPE_START, data.x, data.y);
this._moveSelection(data.handleType == this.HANDLE_TYPE_ANCHOR, data.x, data.y);
} else if (this._activeType == this.TYPE_CURSOR) {
this._startDraggingHandles();
@ -152,7 +152,7 @@ var SelectionHandler = {
this._startDraggingHandles();
// Check to see if the handles should be reversed.
let isStartHandle = JSON.parse(aData).handleType == this.HANDLE_TYPE_START;
let isStartHandle = JSON.parse(aData).handleType == this.HANDLE_TYPE_ANCHOR;
try {
let selectionReversed = this._updateCacheForSelection(isStartHandle);
if (selectionReversed) {
@ -345,7 +345,7 @@ var SelectionHandler = {
this._positionHandles(positions);
Messaging.sendRequest({
type: "TextSelection:ShowHandles",
handles: [this.HANDLE_TYPE_START, this.HANDLE_TYPE_END]
handles: [this.HANDLE_TYPE_ANCHOR, this.HANDLE_TYPE_FOCUS]
});
this._updateMenu();
return true;
@ -724,7 +724,7 @@ var SelectionHandler = {
this._positionHandles();
Messaging.sendRequest({
type: "TextSelection:ShowHandles",
handles: [this.HANDLE_TYPE_MIDDLE]
handles: [this.HANDLE_TYPE_CARET]
});
this._updateMenu();
@ -1097,7 +1097,7 @@ var SelectionHandler = {
// divide by the pixel ratio
let x = cursor.left / window.devicePixelRatio;
let y = (cursor.top + cursor.height) / window.devicePixelRatio;
return [{ handle: this.HANDLE_TYPE_MIDDLE,
return [{ handle: this.HANDLE_TYPE_CARET,
left: x + scroll.X,
top: y + scroll.Y,
hidden: checkHidden(x, y) }];
@ -1111,11 +1111,11 @@ var SelectionHandler = {
// this because the top-level page may have scrolled since selection started.
let offset = this._getViewOffset();
return [{ handle: this.HANDLE_TYPE_START,
return [{ handle: this.HANDLE_TYPE_ANCHOR,
left: sx + offset.x + scroll.X,
top: sy + offset.y + scroll.Y,
hidden: checkHidden(sx, sy) },
{ handle: this.HANDLE_TYPE_END,
{ handle: this.HANDLE_TYPE_FOCUS,
left: ex + offset.x + scroll.X,
top: ey + offset.y + scroll.Y,
hidden: checkHidden(ex, ey) }];