summaryrefslogtreecommitdiff
path: root/core/java/android/view/InsetsSource.java
diff options
context:
space:
mode:
authorTiger Huang <tigerhuang@google.com>2020-03-13 17:06:35 +0800
committerTiger Huang <tigerhuang@google.com>2020-03-13 17:15:09 +0800
commita24aab56869e14e2301ac8b6fc54d08c0ef4bb27 (patch)
treec28ea41775c2183701367bd34c0a4a355fedf0d5 /core/java/android/view/InsetsSource.java
parent98955a625c159ec46ebb9eb7cd521fc5e73bb031 (diff)
Let insets sources can produce insets on 0-width or 0-height windows
Window Manager allows the client to add 0-width or 0-height windows. These windows can get insets in the legacy insets mode even they only intersect with the insets source window on the edges. This CL make this behavior compatible with the legacy insets mode. Fix: 150696052 Test: atest InsetsSourceTest Change-Id: I9ed76bb615a0133ad55e1f93b22fbc03ae5cb437
Diffstat (limited to 'core/java/android/view/InsetsSource.java')
-rw-r--r--core/java/android/view/InsetsSource.java26
1 files changed, 24 insertions, 2 deletions
diff --git a/core/java/android/view/InsetsSource.java b/core/java/android/view/InsetsSource.java
index 719f649cb5a2..294faaf0b5c8 100644
--- a/core/java/android/view/InsetsSource.java
+++ b/core/java/android/view/InsetsSource.java
@@ -18,6 +18,7 @@ package android.view;
import static android.view.InsetsState.ITYPE_IME;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Insets;
import android.graphics.Rect;
@@ -114,7 +115,7 @@ public class InsetsSource implements Parcelable {
if (!ignoreVisibility && !mVisible) {
return Insets.NONE;
}
- if (!mTmpFrame.setIntersect(frame, relativeFrame)) {
+ if (!getIntersection(frame, relativeFrame, mTmpFrame)) {
return Insets.NONE;
}
@@ -144,12 +145,33 @@ public class InsetsSource implements Parcelable {
}
}
+ /**
+ * Outputs the intersection of two rectangles. The shared edges will also be counted in the
+ * intersection.
+ *
+ * @param a The first rectangle being intersected with.
+ * @param b The second rectangle being intersected with.
+ * @param out The rectangle which represents the intersection.
+ * @return {@code true} if there is any intersection.
+ */
+ private static boolean getIntersection(@NonNull Rect a, @NonNull Rect b, @NonNull Rect out) {
+ if (a.left <= b.right && b.left <= a.right && a.top <= b.bottom && b.top <= a.bottom) {
+ out.left = Math.max(a.left, b.left);
+ out.top = Math.max(a.top, b.top);
+ out.right = Math.min(a.right, b.right);
+ out.bottom = Math.min(a.bottom, b.bottom);
+ return true;
+ }
+ out.setEmpty();
+ return false;
+ }
+
public void dump(String prefix, PrintWriter pw) {
pw.print(prefix);
pw.print("InsetsSource type="); pw.print(InsetsState.typeToString(mType));
pw.print(" frame="); pw.print(mFrame.toShortString());
if (mVisibleFrame != null) {
- pw.print(" visibleFrmae="); pw.print(mVisibleFrame.toShortString());
+ pw.print(" visibleFrame="); pw.print(mVisibleFrame.toShortString());
}
pw.print(" visible="); pw.print(mVisible);
pw.println();