| 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 {
|
| +
|
| + private Rect mWindowInsets;
|
| +
|
| + /**
|
| + * Creates an {@link InsetConsumerView}.
|
| + *
|
| + * @param context The Context to create this {@link InsetConsumerView} in.
|
| + */
|
| + public InsetConsumerView(Context context) {
|
| + super(context);
|
| + mWindowInsets = new Rect();
|
| + }
|
| +
|
| + /**
|
| + * 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);
|
| + }
|
| +
|
| + @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
| + @Override
|
| + public WindowInsets onApplyWindowInsets(WindowInsets insets) {
|
| + mWindowInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
|
| + insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
|
| + return super.onApplyWindowInsets(insets);
|
| + }
|
| +}
|
|
|