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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 @Override | 104 @Override |
102 public void onContentChanged(Tab tab) { | 105 public void onContentChanged(Tab tab) { |
103 mTabView.removeOnAttachStateChangeListener(mAttachedStateListener); | 106 mTabView.removeOnAttachStateChangeListener(mAttachedStateListener); |
104 mTabView = tab.getView(); | 107 mTabView = tab.getView(); |
105 mTabView.addOnAttachStateChangeListener(mAttachedStateListener); | 108 mTabView.addOnAttachStateChangeListener(mAttachedStateListener); |
106 } | 109 } |
107 | 110 |
108 @Override | 111 @Override |
109 public void onReparentingFinished(Tab tab) { | 112 public void onReparentingFinished(Tab tab) { |
110 setParentView((ViewGroup) tab.getActivity().findViewById(R.id.bottom _container)); | 113 setParentView((ViewGroup) tab.getActivity().findViewById(R.id.bottom _container)); |
114 Activity activity = tab.getActivity(); | |
115 if (activity != null && activity instanceof ChromeActivity) { | |
gone
2017/04/27 18:48:58
instanceof already includes an implicit null check
ramyasharma
2017/04/28 06:35:59
Thanks Done.
| |
116 mSnackbarManager = ((ChromeActivity) activity).getSnackbarManage r(); | |
117 } else { | |
118 mSnackbarManager = null; | |
119 } | |
111 } | 120 } |
112 }; | 121 }; |
113 | 122 |
114 /** | 123 /** |
115 * Adds/removes the {@link InfoBarContainer} when the tab's view is attached /detached. This is | 124 * Adds/removes the {@link InfoBarContainer} when the tab's view is attached /detached. This is |
116 * mostly to ensure the infobars are not shown in tab switcher overview mode . | 125 * mostly to ensure the infobars are not shown in tab switcher overview mode . |
117 */ | 126 */ |
118 private final OnAttachStateChangeListener mAttachedStateListener = | 127 private final OnAttachStateChangeListener mAttachedStateListener = |
119 new OnAttachStateChangeListener() { | 128 new OnAttachStateChangeListener() { |
120 @Override | 129 @Override |
(...skipping 23 matching lines...) Expand all Loading... | |
144 | 153 |
145 /** The view that {@link Tab#getView()} returns. */ | 154 /** The view that {@link Tab#getView()} returns. */ |
146 private View mTabView; | 155 private View mTabView; |
147 | 156 |
148 /** Whether or not another View is occupying the same space as this one. */ | 157 /** Whether or not another View is occupying the same space as this one. */ |
149 private boolean mIsObscured; | 158 private boolean mIsObscured; |
150 | 159 |
151 private final ObserverList<InfoBarContainerObserver> mObservers = | 160 private final ObserverList<InfoBarContainerObserver> mObservers = |
152 new ObserverList<InfoBarContainerObserver>(); | 161 new ObserverList<InfoBarContainerObserver>(); |
153 | 162 |
163 /** The snackbar manager instance used by the activity that hosts this infob ar. */ | |
164 private SnackbarManager mSnackbarManager; | |
165 | |
154 public InfoBarContainer(Context context, final ViewGroup parentView, Tab tab ) { | 166 public InfoBarContainer(Context context, final ViewGroup parentView, Tab tab ) { |
155 super(context, null); | 167 super(context, null); |
156 tab.addObserver(mTabObserver); | 168 tab.addObserver(mTabObserver); |
157 mTabView = tab.getView(); | 169 mTabView = tab.getView(); |
158 | 170 |
171 Activity activity = tab.getActivity(); | |
172 if (activity != null && activity instanceof ChromeActivity) { | |
gone
2017/04/27 18:48:58
don't duplicate this logic; make a new private fun
ramyasharma
2017/04/28 06:35:59
Done. Thanks.
| |
173 mSnackbarManager = ((ChromeActivity) activity).getSnackbarManager(); | |
174 } | |
175 | |
159 // TODO(newt): move this workaround into the infobar views if/when they' re scrollable. | 176 // 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. | 177 // Workaround for http://crbug.com/407149. See explanation in onMeasure( ) below. |
161 setVerticalScrollBarEnabled(false); | 178 setVerticalScrollBarEnabled(false); |
162 | 179 |
163 FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( | 180 FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( |
164 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BO TTOM); | 181 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BO TTOM); |
165 int topMarginDp = DeviceFormFactor.isTablet(context) | 182 int topMarginDp = DeviceFormFactor.isTablet(context) |
166 ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP; | 183 ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP; |
167 lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics ().density); | 184 lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics ().density); |
168 setLayoutParams(lp); | 185 setLayoutParams(lp); |
169 | 186 |
170 mParentView = parentView; | 187 mParentView = parentView; |
171 | 188 |
172 mLayout = new InfoBarContainerLayout(context); | 189 mLayout = new InfoBarContainerLayout(context); |
173 addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, | 190 addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
174 LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); | 191 LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); |
175 | 192 |
176 // Chromium's InfoBarContainer may add an InfoBar immediately during thi s initialization | 193 // 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. | 194 // call, so make sure everything in the InfoBarContainer is completely r eady beforehand. |
178 mNativeInfoBarContainer = nativeInit(); | 195 mNativeInfoBarContainer = nativeInit(); |
179 } | 196 } |
180 | 197 |
198 public SnackbarManager getSnackbarManager() { | |
199 return mSnackbarManager; | |
200 } | |
201 | |
181 /** | 202 /** |
182 * Adds an {@link InfoBarContainerObserver}. | 203 * Adds an {@link InfoBarContainerObserver}. |
183 * @param observer The {@link InfoBarContainerObserver} to add. | 204 * @param observer The {@link InfoBarContainerObserver} to add. |
184 */ | 205 */ |
185 public void addObserver(InfoBarContainerObserver observer) { | 206 public void addObserver(InfoBarContainerObserver observer) { |
186 mObservers.addObserver(observer); | 207 mObservers.addObserver(observer); |
187 } | 208 } |
188 | 209 |
189 /** | 210 /** |
190 * Removes a {@link InfoBarContainerObserver}. | 211 * Removes a {@link InfoBarContainerObserver}. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 } | 412 } |
392 | 413 |
393 super.onLayout(changed, l, t, r, b); | 414 super.onLayout(changed, l, t, r, b); |
394 } | 415 } |
395 | 416 |
396 private native long nativeInit(); | 417 private native long nativeInit(); |
397 private native void nativeSetWebContents( | 418 private native void nativeSetWebContents( |
398 long nativeInfoBarContainerAndroid, WebContents webContents); | 419 long nativeInfoBarContainerAndroid, WebContents webContents); |
399 private native void nativeDestroy(long nativeInfoBarContainerAndroid); | 420 private native void nativeDestroy(long nativeInfoBarContainerAndroid); |
400 } | 421 } |
OLD | NEW |