Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / ios / chrome / browser / infobars / infobar_controller.mm
blobc2c4875beaed4f9d3259985b6ff6b9abfc41707e
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
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/infobars/infobar_controller.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h"
11 @interface InfoBarController () {
12   base::scoped_nsobject<UIView<InfoBarViewProtocol>> _infoBarView;
14 @end
16 @implementation InfoBarController
17 @synthesize delegate = _delegate;
19 - (instancetype)initWithDelegate:(InfoBarViewDelegate*)delegate {
20   self = [super init];
21   if (self) {
22     DCHECK(delegate);
23     _delegate = delegate;
24   }
25   return self;
28 - (instancetype)init {
29   NOTREACHED();
30   return nil;
33 - (void)dealloc {
34   [_infoBarView removeFromSuperview];
35   [super dealloc];
38 - (int)barHeight {
39   return CGRectGetHeight([_infoBarView frame]);
42 - (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate
43                     frame:(CGRect)bounds {
44   DCHECK(!_infoBarView);
45   _infoBarView = [self viewForDelegate:delegate frame:bounds];
48 - (base::scoped_nsobject<UIView<InfoBarViewProtocol>>)
49     viewForDelegate:(infobars::InfoBarDelegate*)delegate
50               frame:(CGRect)bounds {
51   // Must be overriden in subclasses.
52   NOTREACHED();
53   return _infoBarView;
56 - (void)onHeightsRecalculated:(int)newHeight {
57   [_infoBarView setVisibleHeight:newHeight];
60 - (UIView<InfoBarViewProtocol>*)view {
61   return _infoBarView;
64 - (void)removeView {
65   [_infoBarView removeFromSuperview];
68 - (void)detachView {
69   [_infoBarView resetDelegate];
70   _delegate = nullptr;
73 @end