Fix ScrollerTest for large displays.
Fixes: 151407917
When clipping, if a rectangle was completely clipped out, globalBounds
would not be clipped at all. This CL also fixes the uses of
globalBounds to understand an empty rect as being clipped out.
Test: New test
Change-Id: Icb3ba3d1e4ea03301f6bec9e82209c0cea41f343
diff --git a/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/DrawLayerTest.kt b/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/DrawLayerTest.kt
index e6d00f4..4d204ef 100644
--- a/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/DrawLayerTest.kt
+++ b/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/DrawLayerTest.kt
@@ -206,4 +206,30 @@
assertEquals(PxPosition(5.px, 10.px), layoutCoordinates.positionInRoot)
}
}
+
+ @Test
+ fun testTotalClip() {
+ activityTestRule.runOnUiThreadIR {
+ activity.setContent {
+ Padding(10.ipx) {
+ FixedSize(10.ipx, Modifier.drawLayer(clipToBounds = true)) {
+ FixedSize(
+ 10.ipx,
+ PaddingModifier(20.ipx) +
+ positioner
+ ) {
+ }
+ }
+ }
+ }
+ }
+
+ assertTrue(positionLatch.await(1, TimeUnit.SECONDS))
+ activity.runOnUiThread {
+ val bounds = layoutCoordinates.boundsInRoot
+ // should be completely clipped out
+ assertEquals(0.px, bounds.width)
+ assertEquals(0.px, bounds.height)
+ }
+ }
}
\ No newline at end of file
diff --git a/ui/ui-platform/api/0.1.0-dev09.txt b/ui/ui-platform/api/0.1.0-dev09.txt
index b405336..d7192c2 100644
--- a/ui/ui-platform/api/0.1.0-dev09.txt
+++ b/ui/ui-platform/api/0.1.0-dev09.txt
@@ -413,6 +413,7 @@
method public androidx.ui.core.ComponentNode getComponentNode();
method public androidx.ui.core.semantics.SemanticsConfiguration getConfig();
method public androidx.ui.unit.PxBounds getGlobalBounds();
+ method public androidx.ui.unit.PxPosition getGlobalPosition();
method public boolean getHasChildren();
method public int getId();
method public androidx.ui.core.semantics.SemanticsNode? getParent();
@@ -427,6 +428,7 @@
property public final java.util.List<androidx.ui.core.semantics.SemanticsNode> children;
property public final androidx.ui.core.semantics.SemanticsConfiguration config;
property public final androidx.ui.unit.PxBounds globalBounds;
+ property public final androidx.ui.unit.PxPosition globalPosition;
property public final boolean hasChildren;
property public final boolean isSemanticBoundary;
property public final androidx.ui.core.semantics.SemanticsNode? parent;
diff --git a/ui/ui-platform/api/current.txt b/ui/ui-platform/api/current.txt
index b405336..d7192c2 100644
--- a/ui/ui-platform/api/current.txt
+++ b/ui/ui-platform/api/current.txt
@@ -413,6 +413,7 @@
method public androidx.ui.core.ComponentNode getComponentNode();
method public androidx.ui.core.semantics.SemanticsConfiguration getConfig();
method public androidx.ui.unit.PxBounds getGlobalBounds();
+ method public androidx.ui.unit.PxPosition getGlobalPosition();
method public boolean getHasChildren();
method public int getId();
method public androidx.ui.core.semantics.SemanticsNode? getParent();
@@ -427,6 +428,7 @@
property public final java.util.List<androidx.ui.core.semantics.SemanticsNode> children;
property public final androidx.ui.core.semantics.SemanticsConfiguration config;
property public final androidx.ui.unit.PxBounds globalBounds;
+ property public final androidx.ui.unit.PxPosition globalPosition;
property public final boolean hasChildren;
property public final boolean isSemanticBoundary;
property public final androidx.ui.core.semantics.SemanticsNode? parent;
diff --git a/ui/ui-platform/api/public_plus_experimental_0.1.0-dev09.txt b/ui/ui-platform/api/public_plus_experimental_0.1.0-dev09.txt
index cc93e18..b3bb52d 100644
--- a/ui/ui-platform/api/public_plus_experimental_0.1.0-dev09.txt
+++ b/ui/ui-platform/api/public_plus_experimental_0.1.0-dev09.txt
@@ -415,6 +415,7 @@
method public androidx.ui.core.ComponentNode getComponentNode();
method public androidx.ui.core.semantics.SemanticsConfiguration getConfig();
method public androidx.ui.unit.PxBounds getGlobalBounds();
+ method public androidx.ui.unit.PxPosition getGlobalPosition();
method public boolean getHasChildren();
method public int getId();
method public androidx.ui.core.semantics.SemanticsNode? getParent();
@@ -429,6 +430,7 @@
property public final java.util.List<androidx.ui.core.semantics.SemanticsNode> children;
property public final androidx.ui.core.semantics.SemanticsConfiguration config;
property public final androidx.ui.unit.PxBounds globalBounds;
+ property public final androidx.ui.unit.PxPosition globalPosition;
property public final boolean hasChildren;
property public final boolean isSemanticBoundary;
property public final androidx.ui.core.semantics.SemanticsNode? parent;
diff --git a/ui/ui-platform/api/public_plus_experimental_current.txt b/ui/ui-platform/api/public_plus_experimental_current.txt
index cc93e18..b3bb52d 100644
--- a/ui/ui-platform/api/public_plus_experimental_current.txt
+++ b/ui/ui-platform/api/public_plus_experimental_current.txt
@@ -415,6 +415,7 @@
method public androidx.ui.core.ComponentNode getComponentNode();
method public androidx.ui.core.semantics.SemanticsConfiguration getConfig();
method public androidx.ui.unit.PxBounds getGlobalBounds();
+ method public androidx.ui.unit.PxPosition getGlobalPosition();
method public boolean getHasChildren();
method public int getId();
method public androidx.ui.core.semantics.SemanticsNode? getParent();
@@ -429,6 +430,7 @@
property public final java.util.List<androidx.ui.core.semantics.SemanticsNode> children;
property public final androidx.ui.core.semantics.SemanticsConfiguration config;
property public final androidx.ui.unit.PxBounds globalBounds;
+ property public final androidx.ui.unit.PxPosition globalPosition;
property public final boolean hasChildren;
property public final boolean isSemanticBoundary;
property public final androidx.ui.core.semantics.SemanticsNode? parent;
diff --git a/ui/ui-platform/api/restricted_0.1.0-dev09.txt b/ui/ui-platform/api/restricted_0.1.0-dev09.txt
index 494ff77..11d94ea 100644
--- a/ui/ui-platform/api/restricted_0.1.0-dev09.txt
+++ b/ui/ui-platform/api/restricted_0.1.0-dev09.txt
@@ -417,6 +417,7 @@
method public androidx.ui.core.ComponentNode getComponentNode();
method public androidx.ui.core.semantics.SemanticsConfiguration getConfig();
method public androidx.ui.unit.PxBounds getGlobalBounds();
+ method public androidx.ui.unit.PxPosition getGlobalPosition();
method public boolean getHasChildren();
method public int getId();
method public androidx.ui.core.semantics.SemanticsNode? getParent();
@@ -431,6 +432,7 @@
property public final java.util.List<androidx.ui.core.semantics.SemanticsNode> children;
property public final androidx.ui.core.semantics.SemanticsConfiguration config;
property public final androidx.ui.unit.PxBounds globalBounds;
+ property public final androidx.ui.unit.PxPosition globalPosition;
property public final boolean hasChildren;
property public final boolean isSemanticBoundary;
property public final androidx.ui.core.semantics.SemanticsNode? parent;
diff --git a/ui/ui-platform/api/restricted_current.txt b/ui/ui-platform/api/restricted_current.txt
index 494ff77..11d94ea 100644
--- a/ui/ui-platform/api/restricted_current.txt
+++ b/ui/ui-platform/api/restricted_current.txt
@@ -417,6 +417,7 @@
method public androidx.ui.core.ComponentNode getComponentNode();
method public androidx.ui.core.semantics.SemanticsConfiguration getConfig();
method public androidx.ui.unit.PxBounds getGlobalBounds();
+ method public androidx.ui.unit.PxPosition getGlobalPosition();
method public boolean getHasChildren();
method public int getId();
method public androidx.ui.core.semantics.SemanticsNode? getParent();
@@ -431,6 +432,7 @@
property public final java.util.List<androidx.ui.core.semantics.SemanticsNode> children;
property public final androidx.ui.core.semantics.SemanticsConfiguration config;
property public final androidx.ui.unit.PxBounds globalBounds;
+ property public final androidx.ui.unit.PxPosition globalPosition;
property public final boolean hasChildren;
property public final boolean isSemanticBoundary;
property public final androidx.ui.core.semantics.SemanticsNode? parent;
diff --git a/ui/ui-platform/src/main/java/androidx/ui/core/LayoutNodeWrapper.kt b/ui/ui-platform/src/main/java/androidx/ui/core/LayoutNodeWrapper.kt
index 6e192b0..302dc62 100644
--- a/ui/ui-platform/src/main/java/androidx/ui/core/LayoutNodeWrapper.kt
+++ b/ui/ui-platform/src/main/java/androidx/ui/core/LayoutNodeWrapper.kt
@@ -851,10 +851,11 @@
}
override fun rectInParent(bounds: RectF) {
- if (drawLayerModifier.clipToBounds ||
- (drawLayerModifier.clipToOutline && drawLayerModifier.outlineShape != null)
+ if ((drawLayerModifier.clipToBounds ||
+ (drawLayerModifier.clipToOutline && drawLayerModifier.outlineShape != null)) &&
+ !bounds.intersect(0f, 0f, size.width.value.toFloat(), size.height.value.toFloat())
) {
- bounds.intersect(0f, 0f, size.width.value.toFloat(), size.height.value.toFloat())
+ bounds.setEmpty()
}
val matrix = layer.getMatrix()
matrix.mapRect(bounds)
diff --git a/ui/ui-platform/src/main/java/androidx/ui/core/semantics/SemanticsNode.kt b/ui/ui-platform/src/main/java/androidx/ui/core/semantics/SemanticsNode.kt
index 2d28393..ab7e1f4f 100644
--- a/ui/ui-platform/src/main/java/androidx/ui/core/semantics/SemanticsNode.kt
+++ b/ui/ui-platform/src/main/java/androidx/ui/core/semantics/SemanticsNode.kt
@@ -22,12 +22,14 @@
import androidx.ui.core.findChildSemanticsComponentNodes
import androidx.ui.core.findFirstLayoutNodeInTree
import androidx.ui.core.globalBounds
+import androidx.ui.core.globalPosition
import androidx.ui.core.ifDebug
import androidx.ui.core.requireFirstLayoutNodeInTree
import androidx.ui.semantics.AccessibilityAction
import androidx.ui.semantics.SemanticsPropertyKey
import androidx.ui.unit.IntPxSize
import androidx.ui.unit.PxBounds
+import androidx.ui.unit.PxPosition
/**
* Signature for a function that is called for each [SemanticsNode].
@@ -121,6 +123,12 @@
return layoutNode.coordinates.globalBounds
}
+ val globalPosition: PxPosition
+ get() {
+ val layoutNode = componentNode.requireFirstLayoutNodeInTree()
+ return layoutNode.coordinates.globalPosition
+ }
+
// MERGING
val isSemanticBoundary: Boolean
get() = unmergedConfig.isSemanticBoundary
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/Actions.kt b/ui/ui-test/src/main/java/androidx/ui/test/Actions.kt
index c9c2c93..27a6fd3 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/Actions.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/Actions.kt
@@ -66,7 +66,7 @@
"Semantic Node has no parent layout with a Scroll SemanticsAction"
)
- val globalRect = node.globalBounds
+ val globalPosition = node.globalPosition
val layoutNode = scrollableSemanticsNode.componentNode.findLastLayoutChild { true }
?: throw AssertionError(
@@ -77,8 +77,8 @@
runOnUiThread {
scrollableSemanticsNode.config[SemanticsActions.ScrollTo].action(
- globalRect.left - position.x,
- globalRect.top - position.y
+ globalPosition.x - position.x,
+ globalPosition.y - position.y
)
}
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidSemanticsTreeInteraction.kt b/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidSemanticsTreeInteraction.kt
index 897ae29..56c0903 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidSemanticsTreeInteraction.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/android/AndroidSemanticsTreeInteraction.kt
@@ -27,8 +27,10 @@
import androidx.ui.test.SemanticsTreeInteraction
import androidx.ui.unit.PxBounds
import androidx.ui.unit.PxPosition
+import androidx.ui.unit.height
import androidx.ui.unit.px
import androidx.ui.unit.toRect
+import androidx.ui.unit.width
/**
* Android specific implementation of [SemanticsTreeInteraction].
@@ -48,6 +50,9 @@
}
override fun isInScreenBounds(rectangle: PxBounds): Boolean {
+ if (rectangle.width == 0.px && rectangle.height == 0.px) {
+ return false
+ }
val displayMetrics = SynchronizedTreeCollector.collectOwners()
.findActivity()
.resources