infobar_container_view.cc revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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 "base/message_loop.h"
8#include "chrome/browser/ui/view_ids.h"
9#include "chrome/browser/ui/views/infobars/infobar_view.h"
10#include "grit/generated_resources.h"
11#include "ui/base/accessibility/accessible_view_state.h"
12#include "ui/base/l10n/l10n_util.h"
13
14// static
15const char InfoBarContainerView::kViewClassName[] = "InfoBarContainerView";
16
17InfoBarContainerView::InfoBarContainerView(Delegate* delegate)
18    : InfoBarContainer(delegate) {
19  set_id(VIEW_ID_INFO_BAR_CONTAINER);
20}
21
22InfoBarContainerView::~InfoBarContainerView() {
23  RemoveAllInfoBarsForDestruction();
24}
25
26gfx::Size InfoBarContainerView::GetPreferredSize() {
27  // We do not have a preferred width (we will expand to fit the available width
28  // of the delegate).
29  int total_height;
30  GetVerticalOverlap(&total_height);
31  return gfx::Size(0, total_height);
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::AccessibleViewState* state) {
51  state->role = ui::AccessibilityTypes::ROLE_GROUPING;
52  state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER);
53}
54
55void InfoBarContainerView::PlatformSpecificAddInfoBar(InfoBar* infobar,
56                                                      size_t position) {
57  AddChildViewAt(static_cast<InfoBarView*>(infobar),
58                 static_cast<int>(position));
59}
60
61void InfoBarContainerView::PlatformSpecificRemoveInfoBar(InfoBar* infobar) {
62  RemoveChildView(static_cast<InfoBarView*>(infobar));
63  base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar);
64}
65