mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1817924 - Use Window manager coordinate for text selection menu on Android 11+. r=geckoview-reviewers,owlish
When using split window, the position of selection context menu is strange position. When on Android 11+, it has independent window manager per split window, `onGetContentRect` of `ActionMode.Callback2` seems to use this coordinates, instead of screen coordinate. So we should consider this situation. Also, our CI has no Android 11+ and no way to set split window, so I cannot add unit test for it. Differential Revision: https://phabricator.services.mozilla.com/D170472
This commit is contained in:
parent
59858d2342
commit
86ff1beda0
@ -13,8 +13,10 @@ import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Build;
|
||||
import android.os.TransactionTooLargeException;
|
||||
import android.text.TextUtils;
|
||||
@ -467,7 +469,12 @@ public class BasicSelectionActionDelegate
|
||||
return;
|
||||
}
|
||||
|
||||
mSelection.screenRect.roundOut(outRect);
|
||||
// outRect has to convert to current window coordinate.
|
||||
final Matrix matrix = new Matrix();
|
||||
mSession.getScreenToWindowManagerOffsetMatrix(matrix);
|
||||
final RectF transformedRect = new RectF();
|
||||
matrix.mapRect(transformedRect, mSelection.screenRect);
|
||||
transformedRect.roundOut(outRect);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
|
@ -31,6 +31,7 @@ import android.view.PointerIcon;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.ViewStructure;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.CursorAnchorInfo;
|
||||
import android.view.inputmethod.ExtractedText;
|
||||
import android.view.inputmethod.ExtractedTextRequest;
|
||||
@ -5587,6 +5588,30 @@ public class GeckoSession {
|
||||
matrix.postTranslate(mLeft, mTop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a matrix for transforming from screen coordinates to Android's current window coordinates.
|
||||
*
|
||||
* @param matrix Matrix to be replaced by the transformation matrix.
|
||||
* @see
|
||||
* https://developer.android.com/guide/topics/large-screens/multi-window-support#window_metrics
|
||||
*/
|
||||
@UiThread
|
||||
/* package */ void getScreenToWindowManagerOffsetMatrix(@NonNull final Matrix matrix) {
|
||||
ThreadUtils.assertOnUiThread();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
final WindowManager wm =
|
||||
(WindowManager)
|
||||
GeckoAppShell.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
||||
final Rect currentWindowRect = wm.getCurrentWindowMetrics().getBounds();
|
||||
matrix.postTranslate(-currentWindowRect.left, -currentWindowRect.top);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(m_kato): Bug 1678531
|
||||
// How to get window coordinate on Android 7-10 that supports split window?
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bounds of the client area in client coordinates. The returned top-left coordinates are
|
||||
* always (0, 0). Use the matrix from {@link #getClientToSurfaceMatrix(Matrix)} or {@link
|
||||
|
Loading…
Reference in New Issue
Block a user