infobar_container_view.cc revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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/accessibility/ax_view_state.h"
11#include "ui/base/l10n/l10n_util.h"
12
13// static
14const char InfoBarContainerView::kViewClassName[] = "InfoBarContainerView";
15
16InfoBarContainerView::InfoBarContainerView(Delegate* delegate)
17    : infobars::InfoBarContainer(delegate) {
18  set_id(VIEW_ID_INFO_BAR_CONTAINER);
19}
20
21InfoBarContainerView::~InfoBarContainerView() {
22  RemoveAllInfoBarsForDestruction();
23}
24
25gfx::Size InfoBarContainerView::GetPreferredSize() {
26  int total_height;
27  GetVerticalOverlap(&total_height);
28  gfx::Size size(0, total_height);
29  for (int i = 0; i < child_count(); ++i)
30    size.SetToMax(gfx::Size(child_at(i)->GetPreferredSize().width(), 0));
31  return size;
32}
33
34const char* InfoBarContainerView::GetClassName() const {
35  return kViewClassName;
36}
37
38void InfoBarContainerView::Layout() {
39  int top = GetVerticalOverlap(NULL);
40
41  for (int i = 0; i < child_count(); ++i) {
42    InfoBarView* child = static_cast<InfoBarView*>(child_at(i));
43    top -= child->arrow_height();
44    int child_height = child->total_height();
45    child->SetBounds(0, top, width(), child_height);
46    top += child_height;
47  }
48}
49
50void InfoBarContainerView::GetAccessibleState(ui::AXViewState* state) {
51  state->role = ui::AX_ROLE_GROUP;
52  state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER);
53}
54
55void InfoBarContainerView::PlatformSpecificAddInfoBar(
56    infobars::InfoBar* infobar,
57    size_t position) {
58  AddChildViewAt(static_cast<InfoBarView*>(infobar),
59                 static_cast<int>(position));
60}
61
62void InfoBarContainerView::PlatformSpecificRemoveInfoBar(
63    infobars::InfoBar* infobar) {
64  RemoveChildView(static_cast<InfoBarView*>(infobar));
65}
66