| 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..ee78dd8588dd98a0e84dc7db54c7f4067c4f2a6e
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java
|
| @@ -0,0 +1,87 @@
|
| +// 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;
|
| +
|
| +import org.chromium.chrome.browser.tabmodel.TabModelSelector;
|
| +import org.chromium.content.browser.ContentViewCore;
|
| +
|
| +/**
|
| + * 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 TabModelSelector mTabModelSelector;
|
| +
|
| + /**
|
| + * Creates an {@link InsetConsumerView}.
|
| + *
|
| + * @param context The Context to create this {@link InsetConsumerView} in.
|
| + */
|
| + public InsetConsumerView(Context context) {
|
| + super(context);
|
| + }
|
| +
|
| + /**
|
| + * 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);
|
| + }
|
| +
|
| + /**
|
| + * Sets the {@link TabModelSelector} that will be queried for information
|
| + * about the state of the system.
|
| + *
|
| + * @param tabModelSelector A {@link TabModelSelector} that represents the
|
| + * state of the system.
|
| + */
|
| + public void setTabModelSelector(TabModelSelector tabModelSelector) {
|
| + mTabModelSelector = tabModelSelector;
|
| + }
|
| +
|
| + @SuppressWarnings("deprecation")
|
| + @Override
|
| + protected boolean fitSystemWindows(Rect insets) {
|
| + // For Lollipop and above, onApplyWindowInsets will set the insets on
|
| + // ContentViewCore.
|
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
|
| + && mTabModelSelector != null && mTabModelSelector.getCurrentTab() != null) {
|
| + ContentViewCore cvc = mTabModelSelector.getCurrentTab().getContentViewCore();
|
| + if (cvc != null) {
|
| + cvc.setWindowInsets(insets.left, insets.top, insets.right, insets.bottom);
|
| + }
|
| + }
|
| + return super.fitSystemWindows(insets);
|
| + }
|
| +
|
| + @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
| + @Override
|
| + public WindowInsets onApplyWindowInsets(WindowInsets insets) {
|
| + if (mTabModelSelector != null && mTabModelSelector.getCurrentTab() != null) {
|
| + ContentViewCore cvc = mTabModelSelector.getCurrentTab().getContentViewCore();
|
| + if (cvc != null) {
|
| + cvc.setWindowInsets(insets.getSystemWindowInsetLeft(),
|
| + insets.getSystemWindowInsetTop(),
|
| + insets.getSystemWindowInsetRight(),
|
| + insets.getSystemWindowInsetBottom());
|
| + }
|
| + }
|
| + return super.onApplyWindowInsets(insets);
|
| + }
|
| +}
|
|
|