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; |
18 import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item; | 20 import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item; |
| 21 import org.chromium.chrome.browser.snackbar.SnackbarManager; |
19 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 22 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
20 import org.chromium.chrome.browser.tab.Tab; | 23 import org.chromium.chrome.browser.tab.Tab; |
21 import org.chromium.chrome.browser.tab.TabObserver; | 24 import org.chromium.chrome.browser.tab.TabObserver; |
22 import org.chromium.content.browser.ContentViewCore; | 25 import org.chromium.content.browser.ContentViewCore; |
23 import org.chromium.content_public.browser.WebContents; | 26 import org.chromium.content_public.browser.WebContents; |
24 import org.chromium.ui.UiUtils; | 27 import org.chromium.ui.UiUtils; |
25 import org.chromium.ui.base.DeviceFormFactor; | 28 import org.chromium.ui.base.DeviceFormFactor; |
26 | 29 |
27 import java.util.ArrayList; | 30 import java.util.ArrayList; |
28 | 31 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 @Override | 111 @Override |
109 public void onContentChanged(Tab tab) { | 112 public void onContentChanged(Tab tab) { |
110 mTabView.removeOnAttachStateChangeListener(mAttachedStateListener); | 113 mTabView.removeOnAttachStateChangeListener(mAttachedStateListener); |
111 mTabView = tab.getView(); | 114 mTabView = tab.getView(); |
112 mTabView.addOnAttachStateChangeListener(mAttachedStateListener); | 115 mTabView.addOnAttachStateChangeListener(mAttachedStateListener); |
113 } | 116 } |
114 | 117 |
115 @Override | 118 @Override |
116 public void onReparentingFinished(Tab tab) { | 119 public void onReparentingFinished(Tab tab) { |
117 setParentView((ViewGroup) tab.getActivity().findViewById(R.id.bottom
_container)); | 120 setParentView((ViewGroup) tab.getActivity().findViewById(R.id.bottom
_container)); |
| 121 setSnackbarManagerFromTab(tab); |
118 } | 122 } |
119 }; | 123 }; |
120 | 124 |
| 125 private void setSnackbarManagerFromTab(Tab tab) { |
| 126 Activity activity = tab.getActivity(); |
| 127 if (activity != null) { |
| 128 mSnackbarManager = ((ChromeActivity) activity).getSnackbarManager(); |
| 129 } else { |
| 130 mSnackbarManager = null; |
| 131 } |
| 132 } |
| 133 |
121 /** | 134 /** |
122 * Adds/removes the {@link InfoBarContainer} when the tab's view is attached
/detached. This is | 135 * Adds/removes the {@link InfoBarContainer} when the tab's view is attached
/detached. This is |
123 * mostly to ensure the infobars are not shown in tab switcher overview mode
. | 136 * mostly to ensure the infobars are not shown in tab switcher overview mode
. |
124 */ | 137 */ |
125 private final OnAttachStateChangeListener mAttachedStateListener = | 138 private final OnAttachStateChangeListener mAttachedStateListener = |
126 new OnAttachStateChangeListener() { | 139 new OnAttachStateChangeListener() { |
127 @Override | 140 @Override |
128 public void onViewDetachedFromWindow(View v) { | 141 public void onViewDetachedFromWindow(View v) { |
129 removeFromParentView(); | 142 removeFromParentView(); |
130 } | 143 } |
(...skipping 23 matching lines...) Expand all Loading... |
154 | 167 |
155 /** The view that {@link Tab#getView()} returns. */ | 168 /** The view that {@link Tab#getView()} returns. */ |
156 private View mTabView; | 169 private View mTabView; |
157 | 170 |
158 /** Whether or not another View is occupying the same space as this one. */ | 171 /** Whether or not another View is occupying the same space as this one. */ |
159 private boolean mIsObscured; | 172 private boolean mIsObscured; |
160 | 173 |
161 private final ObserverList<InfoBarContainerObserver> mObservers = | 174 private final ObserverList<InfoBarContainerObserver> mObservers = |
162 new ObserverList<InfoBarContainerObserver>(); | 175 new ObserverList<InfoBarContainerObserver>(); |
163 | 176 |
| 177 /** The snackbar manager instance used by the activity that hosts this infob
ar. */ |
| 178 private SnackbarManager mSnackbarManager; |
| 179 |
164 public InfoBarContainer(Context context, final ViewGroup parentView, Tab tab
) { | 180 public InfoBarContainer(Context context, final ViewGroup parentView, Tab tab
) { |
165 super(context, null); | 181 super(context, null); |
166 tab.addObserver(mTabObserver); | 182 tab.addObserver(mTabObserver); |
167 mTabView = tab.getView(); | 183 mTabView = tab.getView(); |
| 184 setSnackbarManagerFromTab(tab); |
168 | 185 |
169 // TODO(newt): move this workaround into the infobar views if/when they'
re scrollable. | 186 // TODO(newt): move this workaround into the infobar views if/when they'
re scrollable. |
170 // Workaround for http://crbug.com/407149. See explanation in onMeasure(
) below. | 187 // Workaround for http://crbug.com/407149. See explanation in onMeasure(
) below. |
171 setVerticalScrollBarEnabled(false); | 188 setVerticalScrollBarEnabled(false); |
172 | 189 |
173 FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( | 190 FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( |
174 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BO
TTOM); | 191 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BO
TTOM); |
175 int topMarginDp = DeviceFormFactor.isTablet(context) | 192 int topMarginDp = DeviceFormFactor.isTablet(context) |
176 ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP; | 193 ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP; |
177 lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics
().density); | 194 lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics
().density); |
178 setLayoutParams(lp); | 195 setLayoutParams(lp); |
179 | 196 |
180 mParentView = parentView; | 197 mParentView = parentView; |
181 | 198 |
182 mLayout = new InfoBarContainerLayout(context); | 199 mLayout = new InfoBarContainerLayout(context); |
183 addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, | 200 addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
184 LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); | 201 LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); |
185 | 202 |
186 mIPHSupport = new IPHInfoBarSupport(context); | 203 mIPHSupport = new IPHInfoBarSupport(context); |
187 mLayout.addAnimationListener(mIPHSupport); | 204 mLayout.addAnimationListener(mIPHSupport); |
188 addObserver(mIPHSupport); | 205 addObserver(mIPHSupport); |
189 | 206 |
190 // Chromium's InfoBarContainer may add an InfoBar immediately during thi
s initialization | 207 // Chromium's InfoBarContainer may add an InfoBar immediately during thi
s initialization |
191 // call, so make sure everything in the InfoBarContainer is completely r
eady beforehand. | 208 // call, so make sure everything in the InfoBarContainer is completely r
eady beforehand. |
192 mNativeInfoBarContainer = nativeInit(); | 209 mNativeInfoBarContainer = nativeInit(); |
193 } | 210 } |
194 | 211 |
| 212 public SnackbarManager getSnackbarManager() { |
| 213 return mSnackbarManager; |
| 214 } |
| 215 |
195 /** | 216 /** |
196 * Adds an {@link InfoBarContainerObserver}. | 217 * Adds an {@link InfoBarContainerObserver}. |
197 * @param observer The {@link InfoBarContainerObserver} to add. | 218 * @param observer The {@link InfoBarContainerObserver} to add. |
198 */ | 219 */ |
199 public void addObserver(InfoBarContainerObserver observer) { | 220 public void addObserver(InfoBarContainerObserver observer) { |
200 mObservers.addObserver(observer); | 221 mObservers.addObserver(observer); |
201 } | 222 } |
202 | 223 |
203 /** | 224 /** |
204 * Removes a {@link InfoBarContainerObserver}. | 225 * Removes a {@link InfoBarContainerObserver}. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 428 } |
408 | 429 |
409 super.onLayout(changed, l, t, r, b); | 430 super.onLayout(changed, l, t, r, b); |
410 } | 431 } |
411 | 432 |
412 private native long nativeInit(); | 433 private native long nativeInit(); |
413 private native void nativeSetWebContents( | 434 private native void nativeSetWebContents( |
414 long nativeInfoBarContainerAndroid, WebContents webContents); | 435 long nativeInfoBarContainerAndroid, WebContents webContents); |
415 private native void nativeDestroy(long nativeInfoBarContainerAndroid); | 436 private native void nativeDestroy(long nativeInfoBarContainerAndroid); |
416 } | 437 } |
OLD | NEW |