Bug 1416310 - 1. Remove getMatrixForLayerRectToViewRect; r?rbarker
Patch gets rid of `LayerView.getMatrixForLayerRectToViewRect`, and just
uses `LayerView.getZoomFactor` directly when calculating the matrix in
GeckoInputConnection. This also lets us avoid the `isCompositorReady`
call on a non-UI thread. To get the correct offset, we need the screen
bounds from Gecko, so it's passed to Java as the first element in the
rect array. Using bounds from Gecko lets us avoid having to deal with
things like the dynamic toolbar animator ourselves.
MozReview-Commit-ID: 6I61SZGyQyO
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
@@ -360,40 +360,39 @@ class GeckoInputConnection
mCursorAnchorInfoBuilder.reset();
// Calculate Gecko logical coords to screen coords
final GeckoView view = getView();
if (view == null) {
return;
}
- Matrix matrix = view.getMatrixForLayerRectToViewRect();
- if (matrix == null) {
- if (DEBUG) {
- Log.d(LOGTAG, "Cannot get Matrix to convert from Gecko coords to layer view coords");
- }
- return;
- }
+ // First aRects element is the widget bounds in device units.
+ final float zoom = view.getZoomFactor();
+ final Matrix matrix = new Matrix();
+ matrix.postScale(zoom, zoom);
+ matrix.postTranslate(aRects[0].left, aRects[0].top);
mCursorAnchorInfoBuilder.setMatrix(matrix);
final Editable content = getEditable();
if (content == null) {
return;
}
int composingStart = getComposingSpanStart(content);
int composingEnd = getComposingSpanEnd(content);
if (composingStart < 0 || composingEnd < 0) {
if (DEBUG) {
Log.d(LOGTAG, "No composition for updates");
}
return;
}
- for (int i = 0; i < aRects.length; i++) {
- mCursorAnchorInfoBuilder.addCharacterBounds(i,
+ // Subsequent aRects elements are character bounds in CSS units.
+ for (int i = 1; i < aRects.length; i++) {
+ mCursorAnchorInfoBuilder.addCharacterBounds(i - 1,
aRects[i].left,
aRects[i].top,
aRects[i].right,
aRects[i].bottom,
CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION);
}
mCursorAnchorInfoBuilder.setComposingText(0, content.subSequence(composingStart, composingEnd));
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
@@ -382,24 +382,9 @@ class GeckoLayerClient implements LayerV
public void surfaceChanged() {
IntSize viewportSize = mToolbarAnimator.getViewportSize();
setViewportSize(viewportSize.width, viewportSize.height);
}
ImmutableViewportMetrics getViewportMetrics() {
return mViewportMetrics;
}
-
- Matrix getMatrixForLayerRectToViewRect() {
- ImmutableViewportMetrics viewportMetrics = mViewportMetrics;
- PointF origin = viewportMetrics.getOrigin();
- float zoom = viewportMetrics.zoomFactor;
- ImmutableViewportMetrics geckoViewport = mViewportMetrics;
- PointF geckoOrigin = geckoViewport.getOrigin();
- float geckoZoom = geckoViewport.zoomFactor;
-
- Matrix matrix = new Matrix();
- matrix.postTranslate(geckoOrigin.x / geckoZoom, geckoOrigin.y / geckoZoom);
- matrix.postScale(zoom, zoom);
- matrix.postTranslate(-origin.x, -origin.y);
- return matrix;
- }
}
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
@@ -278,20 +278,16 @@ public class LayerView extends FrameLayo
public PanZoomController getPanZoomController() { return mPanZoomController; }
public DynamicToolbarAnimator getDynamicToolbarAnimator() { return mToolbarAnimator; }
public ImmutableViewportMetrics getViewportMetrics() {
return mLayerClient.getViewportMetrics();
}
- public Matrix getMatrixForLayerRectToViewRect() {
- return mLayerClient.getMatrixForLayerRectToViewRect();
- }
-
public void setSurfaceBackgroundColor(int newColor) {
}
public interface GetPixelsResult {
public void onPixelsResult(int width, int height, IntBuffer pixels);
}
@RobocopTarget
--- a/widget/android/GeckoEditableSupport.cpp
+++ b/widget/android/GeckoEditableSupport.cpp
@@ -531,29 +531,36 @@ ConvertAndroidColor(uint32_t aArgb)
return NS_RGBA((aArgb & 0x00ff0000) >> 16,
(aArgb & 0x0000ff00) >> 8,
(aArgb & 0x000000ff),
(aArgb & 0xff000000) >> 24);
}
static jni::ObjectArray::LocalRef
ConvertRectArrayToJavaRectFArray(const nsTArray<LayoutDeviceIntRect>& aRects,
- const LayoutDeviceIntPoint& aOffset,
+ const LayoutDeviceIntRect& aWidgetBounds,
const CSSToLayoutDeviceScale aScale)
{
const size_t length = aRects.Length();
- auto rects = jni::ObjectArray::New<sdk::RectF>(length);
+ auto rects = jni::ObjectArray::New<sdk::RectF>(length + 1);
+
+ // First element is the widget bounds in device units.
+ auto widgetRect = sdk::RectF::New(aWidgetBounds.x, aWidgetBounds.y,
+ aWidgetBounds.x + aWidgetBounds.width,
+ aWidgetBounds.y + aWidgetBounds.height);
+ rects->SetElement(0, widgetRect);
for (size_t i = 0; i < length; i++) {
- LayoutDeviceIntRect tmp = aRects[i] + aOffset;
+ LayoutDeviceIntRect tmp = aRects[i];
+ // Subsequent elements are character bounds in CSS units.
auto rect = sdk::RectF::New(tmp.x / aScale.scale, tmp.y / aScale.scale,
(tmp.x + tmp.width) / aScale.scale,
(tmp.y + tmp.height) / aScale.scale);
- rects->SetElement(i, rect);
+ rects->SetElement(i + 1, rect);
}
return rects;
}
namespace mozilla {
namespace widget {
NS_IMPL_ISUPPORTS(GeckoEditableSupport,
@@ -910,17 +917,17 @@ GeckoEditableSupport::UpdateCompositionR
nsEventStatus status = nsEventStatus_eIgnore;
uint32_t offset = composition->NativeOffsetOfStartComposition();
WidgetQueryContentEvent textRects(true, eQueryTextRectArray, widget);
textRects.InitForQueryTextRectArray(offset, composition->String().Length());
widget->DispatchEvent(&textRects, status);
auto rects = ConvertRectArrayToJavaRectFArray(
textRects.mReply.mRectArray,
- widget->WidgetToScreenOffset(),
+ widget->GetScreenBounds(),
widget->GetDefaultScale());
mEditable->UpdateCompositionRects(rects);
}
void
GeckoEditableSupport::OnImeSynchronize()
{