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..e93854cce8f175772a74b6329afa701519e777fc |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java |
| @@ -0,0 +1,84 @@ |
| +// 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.SuppressLint; |
| +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; |
| + } |
| + |
| + @Deprecated |
|
aelias_OOO_until_Jul13
2016/01/28 05:04:55
It's not conventional to mark something like this
ymalik
2016/02/11 01:06:22
Makes sense. Thanks!
|
| + @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(new Rect(insets)); |
|
aelias_OOO_until_Jul13
2016/01/28 05:04:55
I don't see any reason to use 'new' here instead o
ymalik
2016/02/11 01:06:22
See comment below.
|
| + } |
| + } |
| + return super.fitSystemWindows(insets); |
| + } |
| + |
| + @SuppressLint("NewApi") |
|
aelias_OOO_until_Jul13
2016/01/28 05:04:55
I think the correct annotation is @TargetApi(Build
ymalik
2016/02/11 01:06:22
Done. Thanks!
|
| + @Override |
| + public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| + if (mTabModelSelector != null && mTabModelSelector.getCurrentTab() != null) { |
| + ContentViewCore cvc = mTabModelSelector.getCurrentTab().getContentViewCore(); |
| + if (cvc != null) { |
| + cvc.setWindowInsets(new WindowInsets(insets)); |
|
aelias_OOO_until_Jul13
2016/01/28 05:04:55
Likewise, I don't see any reason to use 'new' here
ymalik
2016/02/11 01:06:22
You're right, there is no need for new in this cas
|
| + } |
| + } |
| + return super.onApplyWindowInsets(insets); |
| + } |
| +} |