summaryrefslogtreecommitdiffstats
path: root/ios/chrome/browser/infobars/infobar_controller.mm
blob: c2c4875beaed4f9d3259985b6ff6b9abfc41707e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ios/chrome/browser/infobars/infobar_controller.h"

#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h"

@interface InfoBarController () {
  base::scoped_nsobject<UIView<InfoBarViewProtocol>> _infoBarView;
}
@end

@implementation InfoBarController
@synthesize delegate = _delegate;

- (instancetype)initWithDelegate:(InfoBarViewDelegate*)delegate {
  self = [super init];
  if (self) {
    DCHECK(delegate);
    _delegate = delegate;
  }
  return self;
}

- (instancetype)init {
  NOTREACHED();
  return nil;
}

- (void)dealloc {
  [_infoBarView removeFromSuperview];
  [super dealloc];
}

- (int)barHeight {
  return CGRectGetHeight([_infoBarView frame]);
}

- (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate
                    frame:(CGRect)bounds {
  DCHECK(!_infoBarView);
  _infoBarView = [self viewForDelegate:delegate frame:bounds];
}

- (base::scoped_nsobject<UIView<InfoBarViewProtocol>>)
    viewForDelegate:(infobars::InfoBarDelegate*)delegate
              frame:(CGRect)bounds {
  // Must be overriden in subclasses.
  NOTREACHED();
  return _infoBarView;
}

- (void)onHeightsRecalculated:(int)newHeight {
  [_infoBarView setVisibleHeight:newHeight];
}

- (UIView<InfoBarViewProtocol>*)view {
  return _infoBarView;
}

- (void)removeView {
  [_infoBarView removeFromSuperview];
}

- (void)detachView {
  [_infoBarView resetDelegate];
  _delegate = nullptr;
}

@end