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 #import "ios/chrome/browser/infobars/infobar_container_view.h"
7 #include "base/logging.h"
8 #include "ios/chrome/browser/infobars/infobar.h"
9 #include "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h"
10 #include "ui/base/device_form_factor.h"
12 @implementation InfoBarContainerView
14 - (void)addInfoBar:(InfoBarIOS*)infoBarIOS position:(NSInteger)position {
15 DCHECK_LE((NSUInteger)position, [[self subviews] count]);
16 CGRect containerBounds = [self bounds];
17 infoBarIOS->Layout(containerBounds);
18 UIView* view = infoBarIOS->view();
19 [self insertSubview:view atIndex:position];
22 - (CGSize)sizeThatFits:(CGSize)size {
24 if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) {
25 for (UIView* view in self.subviews) {
26 CGSize elementSize = [view sizeThatFits:size];
27 height += elementSize.height;
30 for (UIView* view in self.subviews) {
31 CGFloat elementHeight = [view sizeThatFits:size].height;
32 if (elementHeight > height)
33 height = elementHeight;
40 - (void)layoutSubviews {
41 for (UIView<InfoBarViewProtocol>* view in self.subviews) {
43 CGRect frame = view.frame;
44 frame.origin.y = CGRectGetHeight(frame) - [view visibleHeight];
45 [view setFrame:frame];
49 - (CGFloat)topmostVisibleInfoBarHeight {
50 for (UIView<InfoBarViewProtocol>* view in
51 [self.subviews reverseObjectEnumerator]) {
52 return [view sizeThatFits:self.frame.size].height;