| 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 #include "ios/chrome/browser/infobars/infobar_controller.h" | 5 #include "ios/chrome/browser/infobars/infobar_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" | 10 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" |
| 11 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
| 12 @interface InfoBarController () { | 16 @interface InfoBarController () { |
| 13 base::scoped_nsobject<UIView<InfoBarViewProtocol>> _infoBarView; | 17 UIView<InfoBarViewProtocol>* _infoBarView; |
| 14 } | 18 } |
| 15 @end | 19 @end |
| 16 | 20 |
| 17 @implementation InfoBarController | 21 @implementation InfoBarController |
| 18 @synthesize delegate = _delegate; | 22 @synthesize delegate = _delegate; |
| 19 | 23 |
| 20 - (instancetype)initWithDelegate:(InfoBarViewDelegate*)delegate { | 24 - (instancetype)initWithDelegate:(InfoBarViewDelegate*)delegate { |
| 21 self = [super init]; | 25 self = [super init]; |
| 22 if (self) { | 26 if (self) { |
| 23 DCHECK(delegate); | 27 DCHECK(delegate); |
| 24 _delegate = delegate; | 28 _delegate = delegate; |
| 25 } | 29 } |
| 26 return self; | 30 return self; |
| 27 } | 31 } |
| 28 | 32 |
| 29 - (instancetype)init { | 33 - (instancetype)init { |
| 30 NOTREACHED(); | 34 NOTREACHED(); |
| 31 return nil; | 35 return nil; |
| 32 } | 36 } |
| 33 | 37 |
| 34 - (void)dealloc { | 38 - (void)dealloc { |
| 35 [_infoBarView removeFromSuperview]; | 39 [_infoBarView removeFromSuperview]; |
| 36 [super dealloc]; | |
| 37 } | 40 } |
| 38 | 41 |
| 39 - (int)barHeight { | 42 - (int)barHeight { |
| 40 return CGRectGetHeight([_infoBarView frame]); | 43 return CGRectGetHeight([_infoBarView frame]); |
| 41 } | 44 } |
| 42 | 45 |
| 43 - (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate | 46 - (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate |
| 44 frame:(CGRect)bounds { | 47 frame:(CGRect)bounds { |
| 45 DCHECK(!_infoBarView); | 48 DCHECK(!_infoBarView); |
| 46 _infoBarView = [self viewForDelegate:delegate frame:bounds]; | 49 _infoBarView = [self viewForDelegate:delegate frame:bounds]; |
| 47 } | 50 } |
| 48 | 51 |
| 49 - (base::scoped_nsobject<UIView<InfoBarViewProtocol>>) | 52 - (UIView<InfoBarViewProtocol>*)viewForDelegate: |
| 50 viewForDelegate:(infobars::InfoBarDelegate*)delegate | 53 (infobars::InfoBarDelegate*)delegate |
| 51 frame:(CGRect)bounds { | 54 frame:(CGRect)bounds { |
| 52 // Must be overriden in subclasses. | 55 // Must be overriden in subclasses. |
| 53 NOTREACHED(); | 56 NOTREACHED(); |
| 54 return _infoBarView; | 57 return _infoBarView; |
| 55 } | 58 } |
| 56 | 59 |
| 57 - (void)onHeightsRecalculated:(int)newHeight { | 60 - (void)onHeightsRecalculated:(int)newHeight { |
| 58 [_infoBarView setVisibleHeight:newHeight]; | 61 [_infoBarView setVisibleHeight:newHeight]; |
| 59 } | 62 } |
| 60 | 63 |
| 61 - (UIView<InfoBarViewProtocol>*)view { | 64 - (UIView<InfoBarViewProtocol>*)view { |
| 62 return _infoBarView; | 65 return _infoBarView; |
| 63 } | 66 } |
| 64 | 67 |
| 65 - (void)removeView { | 68 - (void)removeView { |
| 66 [_infoBarView removeFromSuperview]; | 69 [_infoBarView removeFromSuperview]; |
| 67 } | 70 } |
| 68 | 71 |
| 69 - (void)detachView { | 72 - (void)detachView { |
| 70 [_infoBarView resetDelegate]; | 73 [_infoBarView resetDelegate]; |
| 71 _delegate = nullptr; | 74 _delegate = nullptr; |
| 72 } | 75 } |
| 73 | 76 |
| 74 @end | 77 @end |
| OLD | NEW |