Skip to content

Commit

Permalink
Set the bottom handwriting bounds offset on the Url bar to 0
Browse files Browse the repository at this point in the history
This is to stop the Url bar from intercepting stylus events meant for
the web contents.

Bug: 1427112
Change-Id: I4aa4461d8c422f5091942a9e95d408228aff85ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4365223
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Peter Conn <peconn@chromium.org>
Commit-Queue: Alex Mitra <alexmitra@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1122028}
  • Loading branch information
AlexMitraChromium authored and Chromium LUCI CQ committed Mar 25, 2023
1 parent 911d7ac commit 5748e68
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java
Expand Up @@ -336,6 +336,38 @@ public static void setActivityOptionsBackgroundActivityStartMode(
}
}

/**
* Sets the bottom handwriting bounds offset of the given view to 0.
* See https://crbug.com/1427112
* @param view The view on which to set the handwriting bounds.
*/
@OptIn(markerClass = androidx.core.os.BuildCompat.PrereleaseSdkCheck.class)
public static void clearHandwritingBoundsOffsetBottom(View view) {
// TODO(crbug.com/1427112): Replace uses of this method with direct calls once the API is
// available.
if (!BuildCompat.isAtLeastU()) return;
// Set the bottom handwriting bounds offset to 0 so that the view doesn't intercept
// stylus events meant for the web contents.
try {
// float offsetTop = this.getHandwritingBoundsOffsetTop();
float offsetTop =
(float) View.class.getMethod("getHandwritingBoundsOffsetTop").invoke(view);
// float offsetLeft = this.getHandwritingBoundsOffsetLeft();
float offsetLeft =
(float) View.class.getMethod("getHandwritingBoundsOffsetLeft").invoke(view);
// float offsetRight = this.getHandwritingBoundsOffsetRight();
float offsetRight =
(float) View.class.getMethod("getHandwritingBoundsOffsetRight").invoke(view);
// this.setHandwritingBoundsOffsets(offsetLeft, offsetTop, offsetRight, 0);
Method setHandwritingBoundsOffsets = View.class.getMethod("setHandwritingBoundsOffsets",
float.class, float.class, float.class, float.class);
setHandwritingBoundsOffsets.invoke(view, offsetLeft, offsetTop, offsetRight, 0);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException
| NullPointerException e) {
// Do nothing.
}
}

// Access this via ContextUtils.getProcessName().
@SuppressWarnings("PrivateApi")
static String getProcessName() {
Expand Down
Expand Up @@ -328,6 +328,7 @@ protected void onFocusChanged(boolean focused, int direction, Rect previouslyFoc
public void onFinishInflate() {
super.onFinishInflate();
setPrivateImeOptions(IME_OPTION_RESTRICT_STYLUS_WRITING_AREA);
ApiCompatibilityUtils.clearHandwritingBoundsOffsetBottom(this);
}

/**
Expand Down

0 comments on commit 5748e68

Please sign in to comment.