Skip to content

Commit 3fd4a38

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Implement cropping of windows based on system UI elements." into jb-dev
2 parents e3320e6 + 3556c9a commit 3fd4a38

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

core/java/android/view/View.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16820,6 +16820,12 @@ public void setPooled(boolean isPooled) {
1682016820
*/
1682116821
boolean mUse32BitDrawingCache;
1682216822

16823+
/**
16824+
* Describes the parts of the window that are currently completely
16825+
* obscured by system UI elements.
16826+
*/
16827+
final Rect mSystemInsets = new Rect();
16828+
1682316829
/**
1682416830
* For windows that are full-screen but using insets to layout inside
1682516831
* of the screen decorations, these are the current insets for the

core/java/android/view/ViewRootImpl.java

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ public final class ViewRootImpl implements ViewParent,
262262
final Rect mPendingVisibleInsets = new Rect();
263263
final Rect mPendingContentInsets = new Rect();
264264
final Rect mPendingSystemInsets = new Rect();
265+
final Rect mActiveRect = new Rect();
265266
final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets
266267
= new ViewTreeObserver.InternalInsetsInfo();
267268

@@ -271,7 +272,8 @@ public final class ViewRootImpl implements ViewParent,
271272
final Configuration mPendingConfiguration = new Configuration();
272273

273274
class ResizedInfo {
274-
Rect coveredInsets;
275+
Rect systemInsets;
276+
Rect contentInsets;
275277
Rect visibleInsets;
276278
Configuration newConfig;
277279
}
@@ -567,6 +569,7 @@ public void setView(View view, WindowManager.LayoutParams attrs, View panelParen
567569
if (mTranslator != null) {
568570
mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets);
569571
}
572+
mPendingSystemInsets.set(0, 0, 0, 0);
570573
mPendingContentInsets.set(mAttachInfo.mContentInsets);
571574
mPendingVisibleInsets.set(0, 0, 0, 0);
572575
if (DEBUG_LAYOUT) Log.v(TAG, "Added window " + mWindow);
@@ -1222,6 +1225,7 @@ private void performTraversals() {
12221225
getRunQueue().executeActions(attachInfo.mHandler);
12231226

12241227
boolean insetsChanged = false;
1228+
boolean activeRectChanged = false;
12251229

12261230
boolean layoutRequested = mLayoutRequested && !mStopped;
12271231
if (layoutRequested) {
@@ -1233,7 +1237,12 @@ private void performTraversals() {
12331237
// to opposite of the added touch mode.
12341238
mAttachInfo.mInTouchMode = !mAddedTouchMode;
12351239
ensureTouchModeLocally(mAddedTouchMode);
1240+
activeRectChanged = true;
12361241
} else {
1242+
if (!mPendingSystemInsets.equals(mAttachInfo.mSystemInsets)) {
1243+
mAttachInfo.mSystemInsets.set(mPendingSystemInsets);
1244+
activeRectChanged = true;
1245+
}
12371246
if (!mPendingContentInsets.equals(mAttachInfo.mContentInsets)) {
12381247
insetsChanged = true;
12391248
}
@@ -1386,7 +1395,11 @@ private void performTraversals() {
13861395
updateConfiguration(mPendingConfiguration, !mFirst);
13871396
mPendingConfiguration.seq = 0;
13881397
}
1389-
1398+
1399+
if (!mPendingSystemInsets.equals(mAttachInfo.mSystemInsets)) {
1400+
activeRectChanged = true;
1401+
mAttachInfo.mSystemInsets.set(mPendingSystemInsets);
1402+
}
13901403
contentInsetsChanged = !mPendingContentInsets.equals(
13911404
mAttachInfo.mContentInsets);
13921405
visibleInsetsChanged = !mPendingVisibleInsets.equals(
@@ -1489,6 +1502,7 @@ private void performTraversals() {
14891502
// before actually drawing them, so it can display then
14901503
// all at once.
14911504
newSurface = true;
1505+
activeRectChanged = true;
14921506
mFullRedrawNeeded = true;
14931507
mPreviousTransparentRegion.setEmpty();
14941508

@@ -1553,8 +1567,11 @@ private void performTraversals() {
15531567
// !!FIXME!! This next section handles the case where we did not get the
15541568
// window size we asked for. We should avoid this by getting a maximum size from
15551569
// the window session beforehand.
1556-
mWidth = frame.width();
1557-
mHeight = frame.height();
1570+
if (mWidth != frame.width() || mHeight != frame.height()) {
1571+
activeRectChanged = true;
1572+
mWidth = frame.width();
1573+
mHeight = frame.height();
1574+
}
15581575

15591576
if (mSurfaceHolder != null) {
15601577
// The app owns the surface; tell it about what is going on.
@@ -1670,6 +1687,14 @@ private void performTraversals() {
16701687
}
16711688
}
16721689

1690+
if (activeRectChanged && mSurface.isValid()) {
1691+
mActiveRect.set(attachInfo.mSystemInsets.left, attachInfo.mSystemInsets.top,
1692+
mWidth - attachInfo.mSystemInsets.right,
1693+
mHeight - attachInfo.mSystemInsets.bottom);
1694+
//Log.i(TAG, "Active rect " + mWindowAttributes.getTitle() + ": " + mActiveRect);
1695+
mSurface.setActiveRect(mActiveRect);
1696+
}
1697+
16731698
final boolean didLayout = layoutRequested && !mStopped;
16741699
boolean triggerGlobalLayoutListener = didLayout
16751700
|| attachInfo.mRecomputeGlobalAttributes;
@@ -2784,7 +2809,8 @@ public void handleMessage(Message msg) {
27842809
ResizedInfo ri = (ResizedInfo)msg.obj;
27852810

27862811
if (mWinFrame.width() == msg.arg1 && mWinFrame.height() == msg.arg2
2787-
&& mPendingContentInsets.equals(ri.coveredInsets)
2812+
&& mPendingSystemInsets.equals(ri.systemInsets)
2813+
&& mPendingContentInsets.equals(ri.contentInsets)
27882814
&& mPendingVisibleInsets.equals(ri.visibleInsets)
27892815
&& ((ResizedInfo)msg.obj).newConfig == null) {
27902816
break;
@@ -2800,7 +2826,8 @@ public void handleMessage(Message msg) {
28002826
mWinFrame.right = msg.arg1;
28012827
mWinFrame.top = 0;
28022828
mWinFrame.bottom = msg.arg2;
2803-
mPendingContentInsets.set(((ResizedInfo)msg.obj).coveredInsets);
2829+
mPendingSystemInsets.set(((ResizedInfo)msg.obj).systemInsets);
2830+
mPendingContentInsets.set(((ResizedInfo)msg.obj).contentInsets);
28042831
mPendingVisibleInsets.set(((ResizedInfo)msg.obj).visibleInsets);
28052832
if (msg.what == MSG_RESIZED_REPORT) {
28062833
mReportNextDraw = true;
@@ -4009,23 +4036,25 @@ public void dispatchFinishInputConnection(InputConnection connection) {
40094036
mHandler.sendMessage(msg);
40104037
}
40114038

4012-
public void dispatchResized(int w, int h, Rect coveredInsets,
4039+
public void dispatchResized(int w, int h, Rect systemInsets, Rect contentInsets,
40134040
Rect visibleInsets, boolean reportDraw, Configuration newConfig) {
40144041
if (DEBUG_LAYOUT) Log.v(TAG, "Resizing " + this + ": w=" + w
4015-
+ " h=" + h + " coveredInsets=" + coveredInsets.toShortString()
4042+
+ " h=" + h + " systemInsets=" + systemInsets.toShortString()
4043+
+ " contentInsets=" + contentInsets.toShortString()
40164044
+ " visibleInsets=" + visibleInsets.toShortString()
40174045
+ " reportDraw=" + reportDraw);
40184046
Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT :MSG_RESIZED);
40194047
if (mTranslator != null) {
4020-
mTranslator.translateRectInScreenToAppWindow(coveredInsets);
4048+
mTranslator.translateRectInScreenToAppWindow(contentInsets);
40214049
mTranslator.translateRectInScreenToAppWindow(visibleInsets);
40224050
w *= mTranslator.applicationInvertedScale;
40234051
h *= mTranslator.applicationInvertedScale;
40244052
}
40254053
msg.arg1 = w;
40264054
msg.arg2 = h;
40274055
ResizedInfo ri = new ResizedInfo();
4028-
ri.coveredInsets = new Rect(coveredInsets);
4056+
ri.systemInsets = new Rect(systemInsets);
4057+
ri.contentInsets = new Rect(contentInsets);
40294058
ri.visibleInsets = new Rect(visibleInsets);
40304059
ri.newConfig = newConfig;
40314060
msg.obj = ri;
@@ -4676,8 +4705,8 @@ public void resized(int w, int h, Rect systemInsets, Rect contentInsets,
46764705
Rect visibleInsets, boolean reportDraw, Configuration newConfig) {
46774706
final ViewRootImpl viewAncestor = mViewAncestor.get();
46784707
if (viewAncestor != null) {
4679-
viewAncestor.dispatchResized(w, h, contentInsets, visibleInsets, reportDraw,
4680-
newConfig);
4708+
viewAncestor.dispatchResized(w, h, systemInsets, contentInsets,
4709+
visibleInsets, reportDraw, newConfig);
46814710
}
46824711
}
46834712

0 commit comments

Comments
 (0)