1// Copyright (c) 2011 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.
4
5#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
6
7#include "chrome/browser/ui/view_ids.h"
8#include "chrome/browser/ui/views/infobars/infobar_view.h"
9#include "grit/generated_resources.h"
10#include "ui/base/accessibility/accessible_view_state.h"
11#include "ui/base/l10n/l10n_util.h"
12
13InfoBarContainerView::InfoBarContainerView(Delegate* delegate)
14    : InfoBarContainer(delegate) {
15  SetID(VIEW_ID_INFO_BAR_CONTAINER);
16}
17
18InfoBarContainerView::~InfoBarContainerView() {
19  RemoveAllInfoBarsForDestruction();
20}
21
22gfx::Size InfoBarContainerView::GetPreferredSize() {
23  // We do not have a preferred width (we will expand to fit the available width
24  // of the delegate).
25  int total_height;
26  GetVerticalOverlap(&total_height);
27  return gfx::Size(0, total_height);
28}
29
30void InfoBarContainerView::Layout() {
31  int top = GetVerticalOverlap(NULL);
32
33  for (int i = 0; i < child_count(); ++i) {
34    InfoBarView* child = static_cast<InfoBarView*>(GetChildViewAt(i));
35    top -= child->arrow_height();
36    int child_height = child->total_height();
37    child->SetBounds(0, top, width(), child_height);
38    top += child_height;
39  }
40}
41
42void InfoBarContainerView::GetAccessibleState(ui::AccessibleViewState* state) {
43  state->role = ui::AccessibilityTypes::ROLE_GROUPING;
44  state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER);
45}
46
47void InfoBarContainerView::PlatformSpecificAddInfoBar(InfoBar* infobar) {
48  AddChildView(static_cast<InfoBarView*>(infobar));
49}
50
51void InfoBarContainerView::PlatformSpecificRemoveInfoBar(InfoBar* infobar) {
52  RemoveChildView(static_cast<InfoBarView*>(infobar));
53}
54