Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java b/chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f0bf2e17379857ace2be692d1e681c6280e0c522 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser; |
| + |
| +import android.annotation.TargetApi; |
| +import android.content.Context; |
| +import android.graphics.Rect; |
| +import android.os.Build; |
| +import android.util.AttributeSet; |
| +import android.view.WindowInsets; |
| +import android.widget.FrameLayout; |
| + |
| +/** |
| + * The purpose of this view is to consume the insets (OSK resizes, status bar). |
| + * It stores the value of the insets in ContentViewCore so that size of things |
| + * like the OSK can be known. |
| + */ |
| +public class InsetConsumerView extends FrameLayout { |
|
Ted C
2016/03/12 00:01:44
if we go sibling child route,
can this just be a
ymalik
2016/03/14 22:19:01
Yes. Done.
|
| + |
| + private Rect mWindowInsets; |
|
Ted C
2016/03/12 00:01:44
make this final
ymalik
2016/03/14 22:19:01
Done.
|
| + |
| + /** |
| + * Creates an {@link InsetConsumerView}. |
| + * |
| + * @param context The Context to create this {@link InsetConsumerView} in. |
| + */ |
| + public InsetConsumerView(Context context) { |
| + super(context); |
| + mWindowInsets = new Rect(); |
|
Ted C
2016/03/12 00:01:44
also if we go with the sibling child route,
add
s
ymalik
2016/03/14 22:19:01
Done.
|
| + } |
| + |
| + /** |
| + * Creates an {@link InsetConsumerView}. |
| + * |
| + * @param context The Context to create this {@link InsetConsumerView} in. |
| + * @param attrs The AttributeSet used to create this |
| + * {@link InsetConsumerView}. |
| + */ |
| + public InsetConsumerView(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + mWindowInsets = new Rect(); |
| + } |
| + |
| + /** |
| + * Returns the left {@link WindowInsets} in pixels. |
| + * |
| + * @return The left system window inset. |
| + */ |
| + public int getSystemWindowInsetsLeft() { |
| + return mWindowInsets.left; |
| + } |
| + |
| + /** |
| + * Returns the top {@link WindowInsets} in pixels. |
| + * |
| + * @return The top system window inset. |
| + */ |
| + public int getSystemWindowInsetsTop() { |
| + return mWindowInsets.top; |
| + } |
| + |
| + /** |
| + * Returns the right {@link WindowInsets} in pixels. |
| + * |
| + * @return The right system window inset. |
| + */ |
| + public int getSystemWindowInsetsRight() { |
| + return mWindowInsets.right; |
| + } |
| + |
| + /** |
| + * Returns the bottom {@link WindowInsets} in pixels. |
| + * |
| + * @return The bottom system window inset. |
| + */ |
| + public int getSystemWindowInsetsBottom() { |
| + return mWindowInsets.bottom; |
| + } |
| + |
| + @SuppressWarnings("deprecation") |
| + @Override |
| + protected boolean fitSystemWindows(Rect insets) { |
| + // For Lollipop and above, onApplyWindowInsets will set the insets. |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
| + mWindowInsets.set(insets.left, insets.top, insets.right, insets.bottom); |
| + } |
| + return super.fitSystemWindows(insets); |
|
Ted C
2016/03/12 00:01:44
if you return false here, then adding it at positi
ymalik
2016/03/14 22:19:01
Done.
|
| + } |
| + |
| + @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| + @Override |
| + public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
|
Ted C
2016/03/12 00:01:44
As for fixing this, you want to do something like
ymalik
2016/03/14 22:19:01
Done. Thanks for the snippet :)!
|
| + mWindowInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), |
| + insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); |
| + return super.onApplyWindowInsets(insets); |
| + } |
| +} |