Bug 1266369 - FloatingToolbarTextSelection: Add an offset to the content rect to avoid overlap. r=ahunt
MozReview-Commit-ID: HNkTOAS7toJ
--- a/mobile/android/base/java/org/mozilla/gecko/text/FloatingToolbarTextSelection.java
+++ b/mobile/android/base/java/org/mozilla/gecko/text/FloatingToolbarTextSelection.java
@@ -4,16 +4,17 @@
package org.mozilla.gecko.text;
import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
+import android.util.TypedValue;
import android.view.ActionMode;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.Telemetry;
@@ -28,29 +29,37 @@ import ch.boye.httpclientandroidlib.util
/**
* Floating toolbar for text selection actions. Only on Android 6+.
*/
@TargetApi(Build.VERSION_CODES.M)
public class FloatingToolbarTextSelection implements TextSelection, GeckoEventListener {
private static final String LOGTAG = "GeckoFloatTextSelection";
+ // This is an additional offset we add to the height of the selection. This will avoid that the
+ // floating toolbar overlays the bottom handle(s).
+ private static final int HANDLES_OFFSET_DP = 20;
+
private final Activity activity;
private final LayerView layerView;
private final int[] locationInWindow;
+ private final float handlesOffset;
private ActionMode actionMode;
private FloatingActionModeCallback actionModeCallback;
private String selectionID;
/* package-private */ Rect contentRect;
public FloatingToolbarTextSelection(Activity activity, LayerView layerView) {
this.activity = activity;
this.layerView = layerView;
this.locationInWindow = new int[2];
+
+ this.handlesOffset = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
+ HANDLES_OFFSET_DP, activity.getResources().getDisplayMetrics());
}
@Override
public boolean dismiss() {
if (finishActionMode()) {
endTextSelection();
return true;
}
@@ -182,14 +191,14 @@ public class FloatingToolbarTextSelectio
final float zoomFactor = layerView.getZoomFactor();
layerView.getLocationInWindow(locationInWindow);
contentRect = new Rect(
(int) (x * zoomFactor + locationInWindow[0]),
(int) (y * zoomFactor + locationInWindow[1] + layerView.getSurfaceTranslation()),
(int) ((x + width) * zoomFactor + locationInWindow[0]),
- (int) ((y + height) * zoomFactor + locationInWindow[1] + layerView.getSurfaceTranslation()));
+ (int) ((y + height) * zoomFactor + locationInWindow[1] + layerView.getSurfaceTranslation() + handlesOffset));
} catch (JSONException e) {
Log.w(LOGTAG, "Could not calculate content rect", e);
}
}
}