This source file includes following definitions.
- allowAutomaticShowing
- hideAndDisallowAutomaticShowing
- isShowing
- hide
- cancelFadeOutAnimation
- updatePosition
- beforeStartUpdatingPosition
- selectBetweenCoordinates
- isSelectionStartDragged
- isDragging
- onTouchModeChanged
- onDetached
- setStartHandlePosition
- setEndHandlePosition
- beginHandleFadeIn
- setHandleVisibility
- onSelectionChanged
- showHandles
- getStartHandleViewForTest
- getEndHandleViewForTest
- createHandlesIfNeeded
- showHandlesIfNeeded
package org.chromium.content.browser.input;
import android.view.View;
import com.google.common.annotations.VisibleForTesting;
import org.chromium.content.browser.PositionObserver;
public abstract class SelectionHandleController extends CursorController {
private static final int TEXT_DIRECTION_DEFAULT = 0;
private static final int TEXT_DIRECTION_LTR = 1;
private static final int TEXT_DIRECTION_RTL = 2;
private HandleView mStartHandle, mEndHandle;
private boolean mAllowAutomaticShowing = true;
private boolean mIsShowing;
private View mParent;
private int mFixedHandleX;
private int mFixedHandleY;
private PositionObserver mPositionObserver;
public SelectionHandleController(View parent, PositionObserver positionObserver) {
mParent = parent;
mPositionObserver = positionObserver;
}
public void allowAutomaticShowing() {
mAllowAutomaticShowing = true;
}
public void hideAndDisallowAutomaticShowing() {
hide();
mAllowAutomaticShowing = false;
}
@Override
public boolean isShowing() {
return mIsShowing;
}
@Override
public void hide() {
if (mIsShowing) {
if (mStartHandle != null) mStartHandle.hide();
if (mEndHandle != null) mEndHandle.hide();
mIsShowing = false;
}
}
void cancelFadeOutAnimation() {
hide();
}
@Override
public void updatePosition(HandleView handle, int x, int y) {
selectBetweenCoordinates(mFixedHandleX, mFixedHandleY, x, y);
}
@Override
public void beforeStartUpdatingPosition(HandleView handle) {
HandleView fixedHandle = (handle == mStartHandle) ? mEndHandle : mStartHandle;
mFixedHandleX = fixedHandle.getAdjustedPositionX();
mFixedHandleY = fixedHandle.getLineAdjustedPositionY();
}
protected abstract void selectBetweenCoordinates(int x1, int y1, int x2, int y2);
boolean isSelectionStartDragged() {
return mStartHandle != null && mStartHandle.isDragging();
}
public boolean isDragging() {
return (mStartHandle != null && mStartHandle.isDragging()) ||
(mEndHandle != null && mEndHandle.isDragging());
}
@Override
public void onTouchModeChanged(boolean isInTouchMode) {
if (!isInTouchMode) {
hide();
}
}
@Override
public void onDetached() {}
public void setStartHandlePosition(float x, float y) {
mStartHandle.positionAt((int) x, (int) y);
}
public void setEndHandlePosition(float x, float y) {
mEndHandle.positionAt((int) x, (int) y);
}
public void beginHandleFadeIn() {
mStartHandle.beginFadeIn();
mEndHandle.beginFadeIn();
}
public void setHandleVisibility(int visibility) {
mStartHandle.setVisibility(visibility);
mEndHandle.setVisibility(visibility);
}
public void onSelectionChanged(int startDir, int endDir) {
if (mAllowAutomaticShowing) {
showHandles(startDir, endDir);
}
}
public void showHandles(int startDir, int endDir) {
createHandlesIfNeeded(startDir, endDir);
showHandlesIfNeeded();
}
@VisibleForTesting
public HandleView getStartHandleViewForTest() {
return mStartHandle;
}
@VisibleForTesting
public HandleView getEndHandleViewForTest() {
return mEndHandle;
}
private void createHandlesIfNeeded(int startDir, int endDir) {
if (mStartHandle == null) {
mStartHandle = new HandleView(this,
startDir == TEXT_DIRECTION_RTL ? HandleView.RIGHT : HandleView.LEFT, mParent,
mPositionObserver);
}
if (mEndHandle == null) {
mEndHandle = new HandleView(this,
endDir == TEXT_DIRECTION_RTL ? HandleView.LEFT : HandleView.RIGHT, mParent,
mPositionObserver);
}
}
private void showHandlesIfNeeded() {
if (!mIsShowing) {
mIsShowing = true;
mStartHandle.show();
mEndHandle.show();
setHandleVisibility(HandleView.VISIBLE);
}
}
}