1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/infobars/infobar_container_ios.h"
7 #import <UIKit/UIKit.h>
9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h"
11 #include "ios/chrome/browser/infobars/infobar.h"
12 #include "ios/chrome/browser/infobars/infobar_container_view.h"
13 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
15 InfoBarContainerIOS::InfoBarContainerIOS(
16 infobars::InfoBarContainer::Delegate* delegate)
17 : InfoBarContainer(delegate), delegate_(delegate) {
19 container_view_.reset([[InfoBarContainerView alloc] init]);
20 [container_view_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
21 UIViewAutoresizingFlexibleTopMargin];
24 InfoBarContainerIOS::~InfoBarContainerIOS() {
26 RemoveAllInfoBarsForDestruction();
29 InfoBarContainerView* InfoBarContainerIOS::view() {
30 return container_view_;
33 void InfoBarContainerIOS::PlatformSpecificAddInfoBar(infobars::InfoBar* infobar,
35 InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar);
36 [container_view_ addInfoBar:infobar_ios position:position];
39 void InfoBarContainerIOS::PlatformSpecificRemoveInfoBar(
40 infobars::InfoBar* infobar) {
41 InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar);
42 infobar_ios->RemoveView();
43 // If total_height() is 0, then the infobar was removed after an animation. In
44 // this case, signal the delegate that the state changed.
45 // Otherwise, the infobar is being replaced by another one. Do not call the
46 // delegate in this case, as the delegate will be updated when the new infobar
48 if (infobar->total_height() == 0 && delegate_)
49 delegate_->InfoBarContainerStateChanged(false);
51 // TODO(rohitrao, jif): [Merge 239355] Upstream InfoBarContainer deletes the
52 // infobar. Avoid deleting it here.
54 // base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar_ios);
57 void InfoBarContainerIOS::PlatformSpecificInfoBarStateChanged(
59 [container_view_ setUserInteractionEnabled:!is_animating];
60 [container_view_ setNeedsLayout];
63 void InfoBarContainerIOS::SuspendInfobars() {
64 ios::GetChromeBrowserProvider()->SetUIViewAlphaWithAnimation(container_view_,
68 void InfoBarContainerIOS::RestoreInfobars() {
69 ios::GetChromeBrowserProvider()->SetUIViewAlphaWithAnimation(container_view_,