Merge "Update mInsetsHint regardless of the nullity of mControl" into udc-qpr-dev
This commit is contained in:
@@ -81,6 +81,7 @@ class InsetsSourceProvider {
|
||||
private boolean mIsLeashReadyForDispatching;
|
||||
private final Rect mSourceFrame = new Rect();
|
||||
private final Rect mLastSourceFrame = new Rect();
|
||||
private final Rect mLastContainerBounds = new Rect();
|
||||
private @NonNull Insets mInsetsHint = Insets.NONE;
|
||||
private @Flags int mFlagsFromFrameProvider;
|
||||
private @Flags int mFlagsFromServer;
|
||||
@@ -278,11 +279,31 @@ class InsetsSourceProvider {
|
||||
// visible. (i.e. No surface, pending insets that were given during layout, etc..)
|
||||
if (mServerVisible) {
|
||||
mSource.setFrame(mSourceFrame);
|
||||
updateInsetsHint();
|
||||
} else {
|
||||
mSource.setFrame(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// To be called when mSourceFrame or the window container bounds is changed.
|
||||
private void updateInsetsHint() {
|
||||
if (!mControllable || !mServerVisible) {
|
||||
return;
|
||||
}
|
||||
final Rect bounds = mWindowContainer.getBounds();
|
||||
if (mSourceFrame.equals(mLastSourceFrame) && bounds.equals(mLastContainerBounds)) {
|
||||
return;
|
||||
}
|
||||
mLastSourceFrame.set(mSourceFrame);
|
||||
mLastContainerBounds.set(bounds);
|
||||
mInsetsHint = mSource.calculateInsets(bounds, true /* ignoreVisibility */);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Insets getInsetsHint() {
|
||||
return mInsetsHint;
|
||||
}
|
||||
|
||||
/** @return A new source computed by the specified window frame in the given display frames. */
|
||||
InsetsSource createSimulatedSource(DisplayFrames displayFrames, Rect frame) {
|
||||
final InsetsSource source = new InsetsSource(mSource);
|
||||
@@ -338,15 +359,9 @@ class InsetsSourceProvider {
|
||||
mSetLeashPositionConsumer.accept(t);
|
||||
}
|
||||
}
|
||||
if (mServerVisible && !mLastSourceFrame.equals(mSource.getFrame())) {
|
||||
final Insets insetsHint = mSource.calculateInsets(
|
||||
mWindowContainer.getBounds(), true /* ignoreVisibility */);
|
||||
if (!insetsHint.equals(mControl.getInsetsHint())) {
|
||||
changed = true;
|
||||
mControl.setInsetsHint(insetsHint);
|
||||
mInsetsHint = insetsHint;
|
||||
}
|
||||
mLastSourceFrame.set(mSource.getFrame());
|
||||
if (!mControl.getInsetsHint().equals(mInsetsHint)) {
|
||||
mControl.setInsetsHint(mInsetsHint);
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
mStateController.notifyControlChanged(mControlTarget);
|
||||
@@ -587,6 +602,11 @@ class InsetsSourceProvider {
|
||||
pw.print(prefix + "mControl=");
|
||||
mControl.dump("", pw);
|
||||
}
|
||||
if (mControllable) {
|
||||
pw.print(prefix + "mInsetsHint=");
|
||||
pw.print(mInsetsHint);
|
||||
pw.println();
|
||||
}
|
||||
pw.print(prefix);
|
||||
pw.print("mIsLeashReadyForDispatching="); pw.print(mIsLeashReadyForDispatching);
|
||||
pw.println();
|
||||
|
||||
@@ -62,28 +62,31 @@ public class InsetsSourceProviderTest extends WindowTestsBase {
|
||||
@Test
|
||||
public void testPostLayout() {
|
||||
final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
|
||||
statusBar.setBounds(0, 0, 500, 1000);
|
||||
statusBar.getFrame().set(0, 0, 500, 100);
|
||||
statusBar.mHasSurface = true;
|
||||
mProvider.setWindowContainer(statusBar, null, null);
|
||||
mProvider.updateSourceFrame(statusBar.getFrame());
|
||||
mProvider.onPostLayout();
|
||||
assertEquals(new Rect(0, 0, 500, 100), mProvider.getSource().getFrame());
|
||||
assertEquals(Insets.of(0, 100, 0, 0),
|
||||
mProvider.getSource().calculateInsets(new Rect(0, 0, 500, 500),
|
||||
false /* ignoreVisibility */));
|
||||
assertEquals(Insets.of(0, 100, 0, 0),
|
||||
mProvider.getSource().calculateVisibleInsets(new Rect(0, 0, 500, 500)));
|
||||
assertEquals(Insets.of(0, 100, 0, 0), mProvider.getInsetsHint());
|
||||
|
||||
// Change the bounds and call onPostLayout. Make sure the insets hint gets updated.
|
||||
statusBar.setBounds(0, 10, 500, 1000);
|
||||
mProvider.onPostLayout();
|
||||
assertEquals(Insets.of(0, 90, 0, 0), mProvider.getInsetsHint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostLayout_invisible() {
|
||||
final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
|
||||
statusBar.setBounds(0, 0, 500, 1000);
|
||||
statusBar.getFrame().set(0, 0, 500, 100);
|
||||
mProvider.setWindowContainer(statusBar, null, null);
|
||||
mProvider.updateSourceFrame(statusBar.getFrame());
|
||||
mProvider.onPostLayout();
|
||||
assertEquals(Insets.NONE, mProvider.getSource().calculateInsets(new Rect(0, 0, 500, 500),
|
||||
false /* ignoreVisibility */));
|
||||
assertTrue(mProvider.getSource().getFrame().isEmpty());
|
||||
assertEquals(Insets.NONE, mProvider.getInsetsHint());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,6 +162,36 @@ public class InsetsSourceProviderTest extends WindowTestsBase {
|
||||
assertNull(mProvider.getControl(target));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSourceFrame() {
|
||||
final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
|
||||
mProvider.setWindowContainer(statusBar, null, null);
|
||||
statusBar.setBounds(0, 0, 500, 1000);
|
||||
|
||||
mProvider.setServerVisible(true);
|
||||
statusBar.getFrame().set(0, 0, 500, 100);
|
||||
mProvider.updateSourceFrame(statusBar.getFrame());
|
||||
assertEquals(statusBar.getFrame(), mProvider.getSource().getFrame());
|
||||
assertEquals(Insets.of(0, 100, 0, 0), mProvider.getInsetsHint());
|
||||
|
||||
// Only change the source frame but not the visibility.
|
||||
statusBar.getFrame().set(0, 0, 500, 90);
|
||||
mProvider.updateSourceFrame(statusBar.getFrame());
|
||||
assertEquals(statusBar.getFrame(), mProvider.getSource().getFrame());
|
||||
assertEquals(Insets.of(0, 90, 0, 0), mProvider.getInsetsHint());
|
||||
|
||||
mProvider.setServerVisible(false);
|
||||
statusBar.getFrame().set(0, 0, 500, 80);
|
||||
mProvider.updateSourceFrame(statusBar.getFrame());
|
||||
assertTrue(mProvider.getSource().getFrame().isEmpty());
|
||||
assertEquals(Insets.of(0, 90, 0, 0), mProvider.getInsetsHint());
|
||||
|
||||
// Only change the visibility but not the frame.
|
||||
mProvider.setServerVisible(true);
|
||||
assertEquals(statusBar.getFrame(), mProvider.getSource().getFrame());
|
||||
assertEquals(Insets.of(0, 80, 0, 0), mProvider.getInsetsHint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSourceFrameForIme() {
|
||||
final WindowState inputMethod = createWindow(null, TYPE_INPUT_METHOD, "inputMethod");
|
||||
@@ -184,7 +217,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsetsModified() {
|
||||
public void testSetRequestedVisibleTypes() {
|
||||
final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
|
||||
final WindowState target = createWindow(null, TYPE_APPLICATION, "target");
|
||||
statusBar.getFrame().set(0, 0, 500, 100);
|
||||
@@ -196,7 +229,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsetsModified_noControl() {
|
||||
public void testSetRequestedVisibleTypes_noControl() {
|
||||
final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
|
||||
final WindowState target = createWindow(null, TYPE_APPLICATION, "target");
|
||||
statusBar.getFrame().set(0, 0, 500, 100);
|
||||
|
||||
Reference in New Issue
Block a user