Chromium Code Reviews| 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.content.Context; | 7 import android.content.Context; |
| 8 import android.view.Gravity; | 8 import android.view.Gravity; |
| 9 import android.view.View; | 9 import android.view.View; |
| 10 import android.view.ViewGroup; | 10 import android.view.ViewGroup; |
| 11 import android.widget.FrameLayout; | 11 import android.widget.FrameLayout; |
| 12 | 12 |
| 13 import org.chromium.base.ObserverList; | 13 import org.chromium.base.ObserverList; |
| 14 import org.chromium.base.VisibleForTesting; | 14 import org.chromium.base.VisibleForTesting; |
| 15 import org.chromium.base.annotations.CalledByNative; | 15 import org.chromium.base.annotations.CalledByNative; |
| 16 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
| 17 import org.chromium.chrome.browser.banners.SwipableOverlayView; | 17 import org.chromium.chrome.browser.banners.SwipableOverlayView; |
| 18 import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item; | |
| 18 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 19 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 19 import org.chromium.chrome.browser.tab.Tab; | 20 import org.chromium.chrome.browser.tab.Tab; |
| 20 import org.chromium.chrome.browser.tab.TabObserver; | 21 import org.chromium.chrome.browser.tab.TabObserver; |
| 21 import org.chromium.content.browser.ContentViewCore; | 22 import org.chromium.content.browser.ContentViewCore; |
| 22 import org.chromium.content_public.browser.WebContents; | 23 import org.chromium.content_public.browser.WebContents; |
| 23 import org.chromium.ui.UiUtils; | 24 import org.chromium.ui.UiUtils; |
| 24 import org.chromium.ui.base.DeviceFormFactor; | 25 import org.chromium.ui.base.DeviceFormFactor; |
| 25 | 26 |
| 26 import java.util.ArrayList; | 27 import java.util.ArrayList; |
| 27 | 28 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 50 */ | 51 */ |
| 51 public interface InfoBarAnimationListener { | 52 public interface InfoBarAnimationListener { |
| 52 public static final int ANIMATION_TYPE_SHOW = 0; | 53 public static final int ANIMATION_TYPE_SHOW = 0; |
| 53 public static final int ANIMATION_TYPE_SWAP = 1; | 54 public static final int ANIMATION_TYPE_SWAP = 1; |
| 54 public static final int ANIMATION_TYPE_HIDE = 2; | 55 public static final int ANIMATION_TYPE_HIDE = 2; |
| 55 | 56 |
| 56 /** | 57 /** |
| 57 * Notifies the subscriber when an animation is completed. | 58 * Notifies the subscriber when an animation is completed. |
| 58 */ | 59 */ |
| 59 void notifyAnimationFinished(int animationType); | 60 void notifyAnimationFinished(int animationType); |
| 61 | |
| 62 /** | |
| 63 * Notifies the subscriber when all animations are finished. | |
| 64 * @param frontInfoBar The frontmost infobar or {@code null} if none are showing. | |
| 65 */ | |
| 66 void notifyAllAnimationsFinished(Item frontInfoBar); | |
| 60 } | 67 } |
| 61 | 68 |
| 62 /** | 69 /** |
| 63 * An observer that is notified of changes to a {@link InfoBarContainer} obj ect. | 70 * An observer that is notified of changes to a {@link InfoBarContainer} obj ect. |
| 64 */ | 71 */ |
| 65 public interface InfoBarContainerObserver { | 72 public interface InfoBarContainerObserver { |
| 66 /** | 73 /** |
| 67 * Called when an {@link InfoBar} is about to be added (before the anima tion). | 74 * Called when an {@link InfoBar} is about to be added (before the anima tion). |
| 68 * @param container The notifying {@link InfoBarContainer} | 75 * @param container The notifying {@link InfoBarContainer} |
| 69 * @param infoBar An {@link InfoBar} being added | 76 * @param infoBar An {@link InfoBar} being added |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 } | 130 } |
| 124 | 131 |
| 125 @Override | 132 @Override |
| 126 public void onViewAttachedToWindow(View v) { | 133 public void onViewAttachedToWindow(View v) { |
| 127 addToParentView(); | 134 addToParentView(); |
| 128 } | 135 } |
| 129 }; | 136 }; |
| 130 | 137 |
| 131 private final InfoBarContainerLayout mLayout; | 138 private final InfoBarContainerLayout mLayout; |
| 132 | 139 |
| 140 private final IPHInfoBarSupport mIPHSupport; | |
|
gone
2017/04/18 21:05:19
javadoc?
David Trainor- moved to gerrit
2017/04/25 05:01:05
Done.
| |
| 141 | |
| 133 /** Native InfoBarContainer pointer which will be set by nativeInit(). */ | 142 /** Native InfoBarContainer pointer which will be set by nativeInit(). */ |
| 134 private final long mNativeInfoBarContainer; | 143 private final long mNativeInfoBarContainer; |
| 135 | 144 |
| 136 /** The list of all InfoBars in this container, regardless of whether they'v e been shown yet. */ | 145 /** The list of all InfoBars in this container, regardless of whether they'v e been shown yet. */ |
| 137 private final ArrayList<InfoBar> mInfoBars = new ArrayList<InfoBar>(); | 146 private final ArrayList<InfoBar> mInfoBars = new ArrayList<InfoBar>(); |
| 138 | 147 |
| 139 /** True when this container has been emptied and its native counterpart has been destroyed. */ | 148 /** True when this container has been emptied and its native counterpart has been destroyed. */ |
| 140 private boolean mDestroyed; | 149 private boolean mDestroyed; |
| 141 | 150 |
| 142 /** Parent view that contains the InfoBarContainerLayout. */ | 151 /** Parent view that contains the InfoBarContainerLayout. */ |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 166 ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP; | 175 ? TOP_MARGIN_TABLET_DP : TOP_MARGIN_PHONE_DP; |
| 167 lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics ().density); | 176 lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics ().density); |
| 168 setLayoutParams(lp); | 177 setLayoutParams(lp); |
| 169 | 178 |
| 170 mParentView = parentView; | 179 mParentView = parentView; |
| 171 | 180 |
| 172 mLayout = new InfoBarContainerLayout(context); | 181 mLayout = new InfoBarContainerLayout(context); |
| 173 addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, | 182 addView(mLayout, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
| 174 LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); | 183 LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); |
| 175 | 184 |
| 185 mIPHSupport = new IPHInfoBarSupport(context); | |
| 186 mLayout.addAnimationListener(mIPHSupport); | |
| 187 addObserver(mIPHSupport); | |
| 188 | |
| 176 // Chromium's InfoBarContainer may add an InfoBar immediately during thi s initialization | 189 // 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. | 190 // call, so make sure everything in the InfoBarContainer is completely r eady beforehand. |
| 178 mNativeInfoBarContainer = nativeInit(); | 191 mNativeInfoBarContainer = nativeInit(); |
| 179 } | 192 } |
| 180 | 193 |
| 181 /** | 194 /** |
| 182 * Adds an {@link InfoBarContainerObserver}. | 195 * Adds an {@link InfoBarContainerObserver}. |
| 183 * @param observer The {@link InfoBarContainerObserver} to add. | 196 * @param observer The {@link InfoBarContainerObserver} to add. |
| 184 */ | 197 */ |
| 185 public void addObserver(InfoBarContainerObserver observer) { | 198 public void addObserver(InfoBarContainerObserver observer) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 205 /** | 218 /** |
| 206 * Sets the parent {@link ViewGroup} that contains the {@link InfoBarContain er}. | 219 * Sets the parent {@link ViewGroup} that contains the {@link InfoBarContain er}. |
| 207 */ | 220 */ |
| 208 public void setParentView(ViewGroup parent) { | 221 public void setParentView(ViewGroup parent) { |
| 209 mParentView = parent; | 222 mParentView = parent; |
| 210 removeFromParentView(); | 223 removeFromParentView(); |
| 211 addToParentView(); | 224 addToParentView(); |
| 212 } | 225 } |
| 213 | 226 |
| 214 @VisibleForTesting | 227 @VisibleForTesting |
| 215 public void setAnimationListener(InfoBarAnimationListener listener) { | 228 public void setAnimationListener(InfoBarAnimationListener listener) { |
|
gone
2017/04/18 21:05:19
rename the function? set implies one
David Trainor- moved to gerrit
2017/04/25 05:01:05
Done.
| |
| 216 mLayout.setAnimationListener(listener); | 229 mLayout.addAnimationListener(listener); |
| 217 } | 230 } |
| 218 | 231 |
| 219 /** | 232 /** |
| 220 * Returns true if any animations are pending or in progress. | 233 * Returns true if any animations are pending or in progress. |
| 221 */ | 234 */ |
| 222 @VisibleForTesting | 235 @VisibleForTesting |
| 223 public boolean isAnimating() { | 236 public boolean isAnimating() { |
| 224 return mLayout.isAnimating(); | 237 return mLayout.isAnimating(); |
| 225 } | 238 } |
| 226 | 239 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 | 304 |
| 292 /** | 305 /** |
| 293 * @return True when this container has been emptied and its native counterp art has been | 306 * @return True when this container has been emptied and its native counterp art has been |
| 294 * destroyed. | 307 * destroyed. |
| 295 */ | 308 */ |
| 296 public boolean hasBeenDestroyed() { | 309 public boolean hasBeenDestroyed() { |
| 297 return mDestroyed; | 310 return mDestroyed; |
| 298 } | 311 } |
| 299 | 312 |
| 300 public void destroy() { | 313 public void destroy() { |
| 314 mLayout.removeAnimationListener(mIPHSupport); | |
| 315 removeObserver(mIPHSupport); | |
| 301 mDestroyed = true; | 316 mDestroyed = true; |
| 302 if (mNativeInfoBarContainer != 0) { | 317 if (mNativeInfoBarContainer != 0) { |
| 303 nativeDestroy(mNativeInfoBarContainer); | 318 nativeDestroy(mNativeInfoBarContainer); |
| 304 } | 319 } |
| 305 } | 320 } |
| 306 | 321 |
| 307 /** | 322 /** |
| 308 * @return all of the InfoBars held in this container. | 323 * @return all of the InfoBars held in this container. |
| 309 */ | 324 */ |
| 310 @VisibleForTesting | 325 @VisibleForTesting |
| (...skipping 80 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 |