Commit 220028ed authored by Stephane Zermatten's avatar Stephane Zermatten Committed by Commit Bot

[Autofill Assistant] Resize overlay to match visible page view.

Before this change the touch event filter would always cover the whole
screen and rely on drawing and event filtering to make the bottom and
top controls accessible. This doesn't work with Talkback, which sees
an overlay and thinks that controls are not accessible.

With this change, the touch event filter is resized dynamically to only
covers the webpage, except when the controls are being animated. With
this solution, the touch event filter still needs to be aware of the
exact height of the bars while they're being animated, but otherwise the
visual viewport height matches the filter height.

Bug: 806868
Change-Id: Ic67232ebdbc8eb98069568e6408b185597e69147
Reviewed-on: https://chromium-review.googlesource.com/c/1352165Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Commit-Queue: Stephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611719}
parent d2d10bf3
...@@ -18,6 +18,7 @@ import android.view.GestureDetector; ...@@ -18,6 +18,7 @@ import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener; import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -124,6 +125,20 @@ public class TouchEventFilter ...@@ -124,6 +125,20 @@ public class TouchEventFilter
*/ */
private int mOffsetY; private int mOffsetY;
/**
* Current top margin of this view.
*
* <p>Margins are set when the top or bottom controller are fully shown. When they're shown
* partially, during a scroll, margins are always 0. The drawing takes care of adapting.
*
* <p>TODO(crbug.com/806868): Better integrate this filter with the view layout to make it
* automatic.
*/
private int mMarginTop;
/** Current bottom margin of this view. */
private int mMarginBottom;
public TouchEventFilter(Context context) { public TouchEventFilter(Context context) {
this(context, null, 0); this(context, null, 0);
} }
...@@ -178,6 +193,7 @@ public class TouchEventFilter ...@@ -178,6 +193,7 @@ public class TouchEventFilter
mFullscreenManager.addListener(this); mFullscreenManager.addListener(this);
mGestureListenerManager = GestureListenerManager.fromWebContents(webContents); mGestureListenerManager = GestureListenerManager.fromWebContents(webContents);
mGestureListenerManager.addListener(this); mGestureListenerManager.addListener(this);
maybeUpdateVerticalMargins();
} }
public void deInit() { public void deInit() {
...@@ -364,6 +380,7 @@ public class TouchEventFilter ...@@ -364,6 +380,7 @@ public class TouchEventFilter
@Override @Override
public void onControlsOffsetChanged(float topOffset, float bottomOffset, boolean needsAnimate) { public void onControlsOffsetChanged(float topOffset, float bottomOffset, boolean needsAnimate) {
maybeUpdateVerticalMargins();
invalidate(); invalidate();
} }
...@@ -441,26 +458,64 @@ public class TouchEventFilter ...@@ -441,26 +458,64 @@ public class TouchEventFilter
return false; return false;
} }
/** Top position within the view of the visual viewport. */ /** Gets the top position, within this view, of the visual viewport. */
private int getVisualViewportTop() { private int getVisualViewportTop() {
if (mFullscreenManager == null) { return getTopBarHeight() - mMarginTop;
return 0;
}
return (int) mFullscreenManager.getContentOffset();
} }
/** Bottom position within the view of the visual viewport. */ /** Gets the bottom position, within this view, of the visual viewport. */
private int getVisualViewportBottom() { private int getVisualViewportBottom() {
int bottomBarHeight = 0; return getHeight() - (getBottomBarHeight() - mMarginBottom);
if (mFullscreenManager != null) {
bottomBarHeight = (int) (mFullscreenManager.getBottomControlsHeight()
- mFullscreenManager.getBottomControlOffset());
}
return getHeight() - bottomBarHeight;
} }
/** Height of the visual viewport. */ /** Gets the height of the visual viewport. */
private int getVisualViewportHeight() { private int getVisualViewportHeight() {
return getVisualViewportBottom() - getVisualViewportTop(); return getVisualViewportBottom() - getVisualViewportTop();
} }
/** Gets the current height of the bottom bar. */
private int getBottomBarHeight() {
if (mFullscreenManager == null) return 0;
return (int) (mFullscreenManager.getBottomControlsHeight()
- mFullscreenManager.getBottomControlOffset());
}
/** Gets the current height of the top bar. */
private int getTopBarHeight() {
if (mFullscreenManager == null) return 0;
return (int) mFullscreenManager.getContentOffset();
}
/**
* Updates the vertical margins of the view.
*
* <p>When the controls are fully visible, the view covers has just the right margins to cover
* only the web page.
*
* <p>When the controls are fully invisible, the view covers everything, which matches the web
* page.
*
* <p>When the controls are partially visible, when animating, the view covers everything,
* including parts of the controls. Drawing takes care of making this look good.
*/
private void maybeUpdateVerticalMargins() {
if (mFullscreenManager == null) return;
if (mFullscreenManager.areBrowserControlsFullyVisible()) {
setVerticalMargins(getTopBarHeight(), getBottomBarHeight());
} else {
setVerticalMargins(0, 0);
}
}
/** Sets top and bottom margin of the view, if necessary */
private void setVerticalMargins(int top, int bottom) {
if (top == mMarginTop && bottom == mMarginBottom) return;
mMarginTop = top;
mMarginBottom = bottom;
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) getLayoutParams();
params.setMargins(/* left= */ 0, /* top= */ top, /* right= */ 0, /* bottom= */ bottom);
setLayoutParams(params);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment