OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "ios/chrome/browser/infobars/infobar_container_ios.h" | 5 #include "ios/chrome/browser/infobars/infobar_container_ios.h" |
6 | 6 |
7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 11 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
12 #include "ios/chrome/browser/infobars/infobar.h" | 12 #include "ios/chrome/browser/infobars/infobar.h" |
13 #include "ios/chrome/browser/infobars/infobar_container_view.h" | 13 #include "ios/chrome/browser/infobars/infobar_container_view.h" |
14 | 14 |
15 InfoBarContainerIOS::InfoBarContainerIOS( | 15 InfoBarContainerIOS::InfoBarContainerIOS( |
16 infobars::InfoBarContainer::Delegate* delegate) | 16 infobars::InfoBarContainer::Delegate* delegate) |
17 : InfoBarContainer(delegate), delegate_(delegate) { | 17 : InfoBarContainer(delegate), delegate_(delegate) { |
18 DCHECK(delegate); | 18 DCHECK(delegate); |
19 container_view_.reset([[InfoBarContainerView alloc] init]); | 19 container_view_.reset([[InfoBarContainerView alloc] init]); |
20 [container_view_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 20 [container_view_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
21 UIViewAutoresizingFlexibleTopMargin]; | 21 UIViewAutoresizingFlexibleTopMargin]; |
22 } | 22 } |
23 | 23 |
24 InfoBarContainerIOS::~InfoBarContainerIOS() { | 24 InfoBarContainerIOS::~InfoBarContainerIOS() { |
| 25 delegate_ = nullptr; |
25 RemoveAllInfoBarsForDestruction(); | 26 RemoveAllInfoBarsForDestruction(); |
26 } | 27 } |
27 | 28 |
28 InfoBarContainerView* InfoBarContainerIOS::view() { | 29 InfoBarContainerView* InfoBarContainerIOS::view() { |
29 return container_view_; | 30 return container_view_; |
30 } | 31 } |
31 | 32 |
32 void InfoBarContainerIOS::PlatformSpecificAddInfoBar(infobars::InfoBar* infobar, | 33 void InfoBarContainerIOS::PlatformSpecificAddInfoBar(infobars::InfoBar* infobar, |
33 size_t position) { | 34 size_t position) { |
34 InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar); | 35 InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar); |
35 [container_view_ addInfoBar:infobar_ios position:position]; | 36 [container_view_ addInfoBar:infobar_ios position:position]; |
36 } | 37 } |
37 | 38 |
38 void InfoBarContainerIOS::PlatformSpecificRemoveInfoBar( | 39 void InfoBarContainerIOS::PlatformSpecificRemoveInfoBar( |
39 infobars::InfoBar* infobar) { | 40 infobars::InfoBar* infobar) { |
40 InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar); | 41 InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar); |
41 infobar_ios->RemoveView(); | 42 infobar_ios->RemoveView(); |
42 // If total_height() is 0, then the infobar was removed after an animation. In | 43 // If total_height() is 0, then the infobar was removed after an animation. In |
43 // this case, signal the delegate that the state changed. | 44 // this case, signal the delegate that the state changed. |
44 // Otherwise, the infobar is being replaced by another one. Do not call the | 45 // Otherwise, the infobar is being replaced by another one. Do not call the |
45 // delegate in this case, as the delegate will be updated when the new infobar | 46 // delegate in this case, as the delegate will be updated when the new infobar |
46 // is added. | 47 // is added. |
47 if (infobar->total_height() == 0) | 48 if (infobar->total_height() == 0 && delegate_) |
48 delegate_->InfoBarContainerStateChanged(false); | 49 delegate_->InfoBarContainerStateChanged(false); |
49 | 50 |
50 // TODO(rohitrao, jif): [Merge 239355] Upstream InfoBarContainer deletes the | 51 // TODO(rohitrao, jif): [Merge 239355] Upstream InfoBarContainer deletes the |
51 // infobar. Avoid deleting it here. | 52 // infobar. Avoid deleting it here. |
52 // crbug.com/327290 | 53 // crbug.com/327290 |
53 // base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar_ios); | 54 // base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar_ios); |
54 } | 55 } |
55 | 56 |
56 void InfoBarContainerIOS::PlatformSpecificInfoBarStateChanged( | 57 void InfoBarContainerIOS::PlatformSpecificInfoBarStateChanged( |
57 bool is_animating) { | 58 bool is_animating) { |
58 [container_view_ setUserInteractionEnabled:!is_animating]; | 59 [container_view_ setUserInteractionEnabled:!is_animating]; |
59 [container_view_ setNeedsLayout]; | 60 [container_view_ setNeedsLayout]; |
60 } | 61 } |
61 | 62 |
62 void InfoBarContainerIOS::SuspendInfobars() { | 63 void InfoBarContainerIOS::SuspendInfobars() { |
63 ios::GetChromeBrowserProvider()->SetUIViewAlphaWithAnimation(container_view_, | 64 ios::GetChromeBrowserProvider()->SetUIViewAlphaWithAnimation(container_view_, |
64 0); | 65 0); |
65 } | 66 } |
66 | 67 |
67 void InfoBarContainerIOS::RestoreInfobars() { | 68 void InfoBarContainerIOS::RestoreInfobars() { |
68 ios::GetChromeBrowserProvider()->SetUIViewAlphaWithAnimation(container_view_, | 69 ios::GetChromeBrowserProvider()->SetUIViewAlphaWithAnimation(container_view_, |
69 1); | 70 1); |
70 } | 71 } |
OLD | NEW |