OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.infobar; | 5 package org.chromium.chrome.browser.infobar; |
6 | 6 |
7 import android.app.Activity; | |
7 import android.content.Context; | 8 import android.content.Context; |
8 import android.view.Gravity; | 9 import android.view.Gravity; |
9 import android.view.View; | 10 import android.view.View; |
10 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
11 import android.widget.FrameLayout; | 12 import android.widget.FrameLayout; |
12 | 13 |
13 import org.chromium.base.ObserverList; | 14 import org.chromium.base.ObserverList; |
14 import org.chromium.base.VisibleForTesting; | 15 import org.chromium.base.VisibleForTesting; |
15 import org.chromium.base.annotations.CalledByNative; | 16 import org.chromium.base.annotations.CalledByNative; |
16 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
18 import org.chromium.chrome.browser.ChromeActivity; | |
17 import org.chromium.chrome.browser.banners.SwipableOverlayView; | 19 import org.chromium.chrome.browser.banners.SwipableOverlayView; |
20 import org.chromium.chrome.browser.snackbar.SnackbarManager; | |
18 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 21 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
19 import org.chromium.chrome.browser.tab.Tab; | 22 import org.chromium.chrome.browser.tab.Tab; |
20 import org.chromium.chrome.browser.tab.TabObserver; | 23 import org.chromium.chrome.browser.tab.TabObserver; |
21 import org.chromium.content.browser.ContentViewCore; | 24 import org.chromium.content.browser.ContentViewCore; |
22 import org.chromium.content_public.browser.WebContents; | 25 import org.chromium.content_public.browser.WebContents; |
23 import org.chromium.ui.UiUtils; | 26 import org.chromium.ui.UiUtils; |
24 import org.chromium.ui.base.DeviceFormFactor; | 27 import org.chromium.ui.base.DeviceFormFactor; |
25 | 28 |
26 import java.util.ArrayList; | 29 import java.util.ArrayList; |
27 | 30 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 147 |
145 /** The view that {@link Tab#getView()} returns. */ | 148 /** The view that {@link Tab#getView()} returns. */ |
146 private View mTabView; | 149 private View mTabView; |
147 | 150 |
148 /** Whether or not another View is occupying the same space as this one. */ | 151 /** Whether or not another View is occupying the same space as this one. */ |
149 private boolean mIsObscured; | 152 private boolean mIsObscured; |
150 | 153 |
151 private final ObserverList<InfoBarContainerObserver> mObservers = | 154 private final ObserverList<InfoBarContainerObserver> mObservers = |
152 new ObserverList<InfoBarContainerObserver>(); | 155 new ObserverList<InfoBarContainerObserver>(); |
153 | 156 |
157 /** The snackbar manager instance used by the activity that hosts this infob ar. */ | |
158 private SnackbarManager mSnackbarManager; | |
159 | |
154 public InfoBarContainer(Context context, final ViewGroup parentView, Tab tab ) { | 160 public InfoBarContainer(Context context, final ViewGroup parentView, Tab tab ) { |
155 super(context, null); | 161 super(context, null); |
156 tab.addObserver(mTabObserver); | 162 tab.addObserver(mTabObserver); |
157 mTabView = tab.getView(); | 163 mTabView = tab.getView(); |
158 | 164 |
165 Activity activity = tab.getActivity(); | |
166 if (activity != null && activity instanceof ChromeActivity) { | |
167 mSnackbarManager = ((ChromeActivity) activity).getSnackbarManager(); | |
168 } | |
gone
2017/04/26 17:27:02
This won't work if the tab is sent to another Acti
ramyasharma
2017/04/27 08:03:11
Thanks done. How can I test re-parenting from the
gone
2017/04/27 18:48:57
Re-parenting currently moves a tab from a CustomTa
| |
169 | |
159 // TODO(newt): move this workaround into the infobar views if/when they' re scrollable. | 170 // TODO(newt): move this workaround into the infobar views if/when they' re scrollable. |
160 // Workaround for http://crbug.com/407149. See explanation in onMeasure( ) below. | 171 // Workaround for http://crbug.com/407149. See explanation in onMeasure( ) below. |
161 setVerticalScrollBarEnabled(false); | 172 setVerticalScrollBarEnabled(false); |
162 | 173 |
163 FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( | 174 FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( |
164 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BO TTOM); | 175 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BO TTOM); |
165 int topMarginDp = DeviceFormFactor.isTablet(context) | 176 int topMarginDp = DeviceFormFactor.isTablet(context) |
166 ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP; | 177 ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP; |
167 lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics ().density); | 178 lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics ().density); |
168 setLayoutParams(lp); | 179 setLayoutParams(lp); |
169 | 180 |
170 mParentView = parentView; | 181 mParentView = parentView; |
171 | 182 |
172 mLayout = new InfoBarContainerLayout(context); | 183 mLayout = new InfoBarContainerLayout(context); |
173 addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, | 184 addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
174 LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); | 185 LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); |
175 | 186 |
176 // Chromium's InfoBarContainer may add an InfoBar immediately during thi s initialization | 187 // Chromium's InfoBarContainer may add an InfoBar immediately during thi s initialization |
177 // call, so make sure everything in the InfoBarContainer is completely r eady beforehand. | 188 // call, so make sure everything in the InfoBarContainer is completely r eady beforehand. |
178 mNativeInfoBarContainer = nativeInit(); | 189 mNativeInfoBarContainer = nativeInit(); |
179 } | 190 } |
180 | 191 |
192 public SnackbarManager getSnackbarManager() { | |
193 return mSnackbarManager; | |
194 } | |
195 | |
181 /** | 196 /** |
182 * Adds an {@link InfoBarContainerObserver}. | 197 * Adds an {@link InfoBarContainerObserver}. |
183 * @param observer The {@link InfoBarContainerObserver} to add. | 198 * @param observer The {@link InfoBarContainerObserver} to add. |
184 */ | 199 */ |
185 public void addObserver(InfoBarContainerObserver observer) { | 200 public void addObserver(InfoBarContainerObserver observer) { |
186 mObservers.addObserver(observer); | 201 mObservers.addObserver(observer); |
187 } | 202 } |
188 | 203 |
189 /** | 204 /** |
190 * Removes a {@link InfoBarContainerObserver}. | 205 * Removes a {@link InfoBarContainerObserver}. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 } | 406 } |
392 | 407 |
393 super.onLayout(changed, l, t, r, b); | 408 super.onLayout(changed, l, t, r, b); |
394 } | 409 } |
395 | 410 |
396 private native long nativeInit(); | 411 private native long nativeInit(); |
397 private native void nativeSetWebContents( | 412 private native void nativeSetWebContents( |
398 long nativeInfoBarContainerAndroid, WebContents webContents); | 413 long nativeInfoBarContainerAndroid, WebContents webContents); |
399 private native void nativeDestroy(long nativeInfoBarContainerAndroid); | 414 private native void nativeDestroy(long nativeInfoBarContainerAndroid); |
400 } | 415 } |
OLD | NEW |