infobar_container_view.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu// Copyright (c) 2011 The Chromium Authors. All rights reserved.
218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu// Use of this source code is governed by a BSD-style license that can be
318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu// found in the LICENSE file.
418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu#include "chrome/browser/ui/view_ids.h"
818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu#include "chrome/browser/ui/views/infobars/infobar_view.h"
918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu#include "grit/generated_resources.h"
1018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu#include "ui/accessibility/ax_view_state.h"
1118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu#include "ui/base/l10n/l10n_util.h"
1218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
1318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu// static
1418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhuconst char InfoBarContainerView::kViewClassName[] = "InfoBarContainerView";
1518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
1618b892c723e812a7e111f102d2b0c0782b116bb6Guang ZhuInfoBarContainerView::InfoBarContainerView(Delegate* delegate)
1718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu    : InfoBarContainer(delegate) {
1818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  set_id(VIEW_ID_INFO_BAR_CONTAINER);
1918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu}
2018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
2118b892c723e812a7e111f102d2b0c0782b116bb6Guang ZhuInfoBarContainerView::~InfoBarContainerView() {
2218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  RemoveAllInfoBarsForDestruction();
2318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu}
2418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
2518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhugfx::Size InfoBarContainerView::GetPreferredSize() {
2618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  int total_height;
2718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  GetVerticalOverlap(&total_height);
2818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  gfx::Size size(0, total_height);
2918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  for (int i = 0; i < child_count(); ++i)
3018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu    size.SetToMax(gfx::Size(child_at(i)->GetPreferredSize().width(), 0));
3118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  return size;
3218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu}
3318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
3418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhuconst char* InfoBarContainerView::GetClassName() const {
3518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  return kViewClassName;
3618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu}
3718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
3818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhuvoid InfoBarContainerView::Layout() {
3918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  int top = GetVerticalOverlap(NULL);
4018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
4118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  for (int i = 0; i < child_count(); ++i) {
4218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu    InfoBarView* child = static_cast<InfoBarView*>(child_at(i));
4318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu    top -= child->arrow_height();
4418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu    int child_height = child->total_height();
4518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu    child->SetBounds(0, top, width(), child_height);
4618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu    top += child_height;
4718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  }
4818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu}
4918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
5018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhuvoid InfoBarContainerView::GetAccessibleState(ui::AXViewState* state) {
5118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  state->role = ui::AX_ROLE_GROUP;
5218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER);
5318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu}
5418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
5518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhuvoid InfoBarContainerView::PlatformSpecificAddInfoBar(InfoBar* infobar,
5618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu                                                      size_t position) {
5718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  AddChildViewAt(static_cast<InfoBarView*>(infobar),
5818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu                 static_cast<int>(position));
5918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu}
6018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
6118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhuvoid InfoBarContainerView::PlatformSpecificRemoveInfoBar(InfoBar* infobar) {
6218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu  RemoveChildView(static_cast<InfoBarView*>(infobar));
6318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu}
6418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu