| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/infobars/infobar_container.h" | 5 #include "chrome/browser/ui/views/infobars/infobar_container.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 8 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 9 #include "chrome/browser/ui/view_ids.h" | 9 #include "chrome/browser/ui/view_ids.h" |
| 10 #include "chrome/browser/ui/views/infobars/infobar_view.h" | 10 #include "chrome/browser/ui/views/infobars/infobar_view.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 InfoBarContainer::~InfoBarContainer() { | 27 InfoBarContainer::~InfoBarContainer() { |
| 28 // Before we remove any children, we reset |delegate_|, so that no removals | 28 // Before we remove any children, we reset |delegate_|, so that no removals |
| 29 // will result in us trying to call delegate_->InfoBarContainerSizeChanged(). | 29 // will result in us trying to call delegate_->InfoBarContainerSizeChanged(). |
| 30 // This is important because at this point |delegate_| may be shutting down, | 30 // This is important because at this point |delegate_| may be shutting down, |
| 31 // and it's at best unimportant and at worst disastrous to call that. | 31 // and it's at best unimportant and at worst disastrous to call that. |
| 32 delegate_ = NULL; | 32 delegate_ = NULL; |
| 33 ChangeTabContents(NULL); | 33 ChangeTabContents(NULL); |
| 34 } | 34 } |
| 35 | 35 |
| 36 InfoBarContainer::Heights InfoBarContainer::GetHeights() const { |
| 37 int offset = 0; |
| 38 int bar_height = 0; |
| 39 for (int i = 0; i < child_count(); ++i) { |
| 40 const InfoBarView* infobar = |
| 41 static_cast<const InfoBarView*>(GetChildViewAt(i)); |
| 42 offset = std::min(offset, bar_height - infobar->preferred_tab_height()); |
| 43 bar_height += infobar->preferred_bar_height(); |
| 44 } |
| 45 return Heights(-offset, bar_height); |
| 46 } |
| 47 |
| 36 void InfoBarContainer::ChangeTabContents(TabContents* contents) { | 48 void InfoBarContainer::ChangeTabContents(TabContents* contents) { |
| 37 registrar_.RemoveAll(); | 49 registrar_.RemoveAll(); |
| 38 | 50 |
| 39 while (!infobars_.empty()) { | 51 while (!infobars_.empty()) { |
| 40 InfoBarView* infobar = *infobars_.begin(); | 52 InfoBarView* infobar = *infobars_.begin(); |
| 41 // NULL the container pointer first so OnInfoBarAnimated() won't get called; | 53 // NULL the container pointer first so OnInfoBarAnimated() won't get called; |
| 42 // we'll manually trigger this once for the whole set of changes below. | 54 // we'll manually trigger this once for the whole set of changes below. |
| 43 infobar->set_container(NULL); | 55 infobar->set_container(NULL); |
| 44 RemoveInfoBar(infobar); | 56 RemoveInfoBar(infobar); |
| 45 } | 57 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 73 | 85 |
| 74 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { | 86 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { |
| 75 tab_contents_->RemoveInfoBar(delegate); | 87 tab_contents_->RemoveInfoBar(delegate); |
| 76 } | 88 } |
| 77 | 89 |
| 78 void InfoBarContainer::RemoveInfoBar(InfoBarView* infobar) { | 90 void InfoBarContainer::RemoveInfoBar(InfoBarView* infobar) { |
| 79 RemoveChildView(infobar); | 91 RemoveChildView(infobar); |
| 80 infobars_.erase(infobar); | 92 infobars_.erase(infobar); |
| 81 } | 93 } |
| 82 | 94 |
| 83 void InfoBarContainer::PaintInfoBarArrows(gfx::Canvas* canvas, | 95 gfx::Size InfoBarContainer::GetPreferredSize() { |
| 84 View* outer_view, | 96 // We do not have a preferred width (we will expand to fit the |
| 85 int arrow_center_x) { | 97 // available width of the delegate). Our preferred height is the sum |
| 98 // of the preferred heights of the InfoBars contained within us and |
| 99 // the tab_height. |
| 100 return gfx::Size(0, GetHeights().height()); |
| 101 } |
| 102 |
| 103 void InfoBarContainer::Layout() { |
| 104 // Because multiple infobars may be animating, the tab of a |
| 105 // vertically lower bar may be "higher". Get the overall heights of |
| 106 // this InfoBarContainer before laying out. |
| 107 Heights heights = GetHeights(); |
| 108 |
| 109 int top = heights.tab_height(); |
| 86 for (int i = 0; i < child_count(); ++i) { | 110 for (int i = 0; i < child_count(); ++i) { |
| 87 InfoBarView* infobar = static_cast<InfoBarView*>(GetChildViewAt(i)); | 111 View* child = GetChildViewAt(i); |
| 88 infobar->PaintArrow(canvas, outer_view, arrow_center_x); | 112 InfoBarView* infobar = static_cast<InfoBarView*>(child); |
| 113 gfx::Size ps = child->GetPreferredSize(); |
| 114 child->SetBounds(0, top - infobar->preferred_tab_height(), |
| 115 width(), ps.height()); |
| 116 top += infobar->preferred_bar_height(); |
| 89 } | 117 } |
| 90 } | 118 } |
| 91 | 119 |
| 92 gfx::Size InfoBarContainer::GetPreferredSize() { | |
| 93 // We do not have a preferred width (we will expand to fit the available width | |
| 94 // of the delegate). Our preferred height is the sum of the preferred heights | |
| 95 // of the InfoBars contained within us. | |
| 96 int height = 0; | |
| 97 for (int i = 0; i < child_count(); ++i) | |
| 98 height += GetChildViewAt(i)->GetPreferredSize().height(); | |
| 99 return gfx::Size(0, height); | |
| 100 } | |
| 101 | |
| 102 void InfoBarContainer::Layout() { | |
| 103 int top = 0; | |
| 104 for (int i = 0; i < child_count(); ++i) { | |
| 105 View* child = GetChildViewAt(i); | |
| 106 gfx::Size ps = child->GetPreferredSize(); | |
| 107 child->SetBounds(0, top, width(), ps.height()); | |
| 108 top += ps.height(); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 void InfoBarContainer::GetAccessibleState(ui::AccessibleViewState* state) { | 120 void InfoBarContainer::GetAccessibleState(ui::AccessibleViewState* state) { |
| 113 state->role = ui::AccessibilityTypes::ROLE_GROUPING; | 121 state->role = ui::AccessibilityTypes::ROLE_GROUPING; |
| 114 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER); | 122 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER); |
| 115 } | 123 } |
| 116 | 124 |
| 117 void InfoBarContainer::Observe(NotificationType type, | 125 void InfoBarContainer::Observe(NotificationType type, |
| 118 const NotificationSource& source, | 126 const NotificationSource& source, |
| 119 const NotificationDetails& details) { | 127 const NotificationDetails& details) { |
| 120 switch (type.value) { | 128 switch (type.value) { |
| 121 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: | 129 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 CallbackStatus callback_status) { | 171 CallbackStatus callback_status) { |
| 164 InfoBarView* infobar_view = static_cast<InfoBarView*>(infobar); | 172 InfoBarView* infobar_view = static_cast<InfoBarView*>(infobar); |
| 165 infobars_.insert(infobar_view); | 173 infobars_.insert(infobar_view); |
| 166 AddChildView(infobar_view); | 174 AddChildView(infobar_view); |
| 167 if (callback_status == WANT_CALLBACK) | 175 if (callback_status == WANT_CALLBACK) |
| 168 infobar_view->set_container(this); | 176 infobar_view->set_container(this); |
| 169 infobar_view->Show(animate); | 177 infobar_view->Show(animate); |
| 170 if (callback_status == NO_CALLBACK) | 178 if (callback_status == NO_CALLBACK) |
| 171 infobar_view->set_container(this); | 179 infobar_view->set_container(this); |
| 172 } | 180 } |
| OLD | NEW |