Chromium Code Reviews| 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 int InfoBarContainer::VerticalOverlap() const { | |
| 37 int temp_total_height; | |
| 38 return GetVerticalOverlap(&temp_total_height); | |
| 39 } | |
| 40 | |
| 36 void InfoBarContainer::ChangeTabContents(TabContents* contents) { | 41 void InfoBarContainer::ChangeTabContents(TabContents* contents) { |
| 37 registrar_.RemoveAll(); | 42 registrar_.RemoveAll(); |
| 38 | 43 |
| 39 while (!infobars_.empty()) { | 44 while (!infobars_.empty()) { |
| 40 InfoBarView* infobar = *infobars_.begin(); | 45 InfoBarView* infobar = *infobars_.begin(); |
| 41 // NULL the container pointer first so OnInfoBarAnimated() won't get called; | 46 // 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. | 47 // we'll manually trigger this once for the whole set of changes below. |
| 43 infobar->set_container(NULL); | 48 infobar->set_container(NULL); |
| 44 RemoveInfoBar(infobar); | 49 RemoveInfoBar(infobar); |
| 45 } | 50 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 73 | 78 |
| 74 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { | 79 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { |
| 75 tab_contents_->RemoveInfoBar(delegate); | 80 tab_contents_->RemoveInfoBar(delegate); |
| 76 } | 81 } |
| 77 | 82 |
| 78 void InfoBarContainer::RemoveInfoBar(InfoBarView* infobar) { | 83 void InfoBarContainer::RemoveInfoBar(InfoBarView* infobar) { |
| 79 RemoveChildView(infobar); | 84 RemoveChildView(infobar); |
| 80 infobars_.erase(infobar); | 85 infobars_.erase(infobar); |
| 81 } | 86 } |
| 82 | 87 |
| 83 void InfoBarContainer::PaintInfoBarArrows(gfx::Canvas* canvas, | |
| 84 View* outer_view, | |
| 85 int arrow_center_x) { | |
| 86 for (int i = 0; i < child_count(); ++i) { | |
| 87 InfoBarView* infobar = static_cast<InfoBarView*>(GetChildViewAt(i)); | |
| 88 infobar->PaintArrow(canvas, outer_view, arrow_center_x); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 gfx::Size InfoBarContainer::GetPreferredSize() { | 88 gfx::Size InfoBarContainer::GetPreferredSize() { |
| 93 // We do not have a preferred width (we will expand to fit the available width | 89 // 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 | 90 // of the delegate). Our preferred height is the sum of the preferred heights |
|
Peter Kasting
2011/03/08 23:21:31
Nit: I'd move this second sentence to the declarat
Sheridan Rawlins
2011/03/09 00:18:26
Done.
| |
| 95 // of the InfoBars contained within us. | 91 // of the InfoBars contained within us plus the vertical_overlap. |
| 96 int height = 0; | 92 int total_height; |
| 97 for (int i = 0; i < child_count(); ++i) | 93 GetVerticalOverlap(&total_height); |
| 98 height += GetChildViewAt(i)->GetPreferredSize().height(); | 94 return gfx::Size(0, total_height); |
| 99 return gfx::Size(0, height); | |
| 100 } | 95 } |
| 101 | 96 |
| 102 void InfoBarContainer::Layout() { | 97 void InfoBarContainer::Layout() { |
| 103 int top = 0; | 98 int total_height; |
| 99 int top = GetVerticalOverlap(&total_height); | |
| 100 | |
| 104 for (int i = 0; i < child_count(); ++i) { | 101 for (int i = 0; i < child_count(); ++i) { |
| 105 View* child = GetChildViewAt(i); | 102 View* child = GetChildViewAt(i); |
| 106 gfx::Size ps = child->GetPreferredSize(); | 103 gfx::Size ps = child->GetPreferredSize(); |
| 107 child->SetBounds(0, top, width(), ps.height()); | 104 int overlapped_top = top - |
|
Peter Kasting
2011/03/08 23:21:31
Nit: Just use "top -=" here and "top +=" below, an
Sheridan Rawlins
2011/03/09 00:18:26
Done.
| |
| 108 top += ps.height(); | 105 static_cast<InfoBarView*>(child)->VerticalOverlap(); |
| 106 child->SetBounds(0, overlapped_top, width(), ps.height()); | |
| 107 top = overlapped_top + ps.height(); | |
| 109 } | 108 } |
| 110 } | 109 } |
| 111 | 110 |
| 112 AccessibilityTypes::Role InfoBarContainer::GetAccessibleRole() { | 111 AccessibilityTypes::Role InfoBarContainer::GetAccessibleRole() { |
| 113 return AccessibilityTypes::ROLE_GROUPING; | 112 return AccessibilityTypes::ROLE_GROUPING; |
| 114 } | 113 } |
| 115 | 114 |
| 116 void InfoBarContainer::Observe(NotificationType type, | 115 void InfoBarContainer::Observe(NotificationType type, |
| 117 const NotificationSource& source, | 116 const NotificationSource& source, |
| 118 const NotificationDetails& details) { | 117 const NotificationDetails& details) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 133 AddInfoBar(infobar_pair->second->CreateInfoBar(), false, WANT_CALLBACK); | 132 AddInfoBar(infobar_pair->second->CreateInfoBar(), false, WANT_CALLBACK); |
| 134 break; | 133 break; |
| 135 } | 134 } |
| 136 | 135 |
| 137 default: | 136 default: |
| 138 NOTREACHED(); | 137 NOTREACHED(); |
| 139 break; | 138 break; |
| 140 } | 139 } |
| 141 } | 140 } |
| 142 | 141 |
| 142 int InfoBarContainer::GetVerticalOverlap(int* total_height) const { | |
| 143 int minimum_top = 0; | |
|
Peter Kasting
2011/03/08 23:21:31
I do not find this algorithm at all comprehensible
Sheridan Rawlins
2011/03/09 00:18:26
I think we're going to have to agree to disagree h
| |
| 144 int top = 0; | |
| 145 | |
| 146 for (int i = 0; i < child_count(); ++i) { | |
| 147 View* child = const_cast<View*>(GetChildViewAt(i)); | |
| 148 gfx::Size ps = child->GetPreferredSize(); | |
| 149 int overlapped_top = top - | |
| 150 static_cast<const InfoBarView*>(child)->VerticalOverlap(); | |
| 151 minimum_top = std::min(minimum_top, overlapped_top); | |
| 152 top = overlapped_top + ps.height(); | |
| 153 } | |
| 154 | |
| 155 DCHECK(total_height); | |
|
Peter Kasting
2011/03/08 23:21:31
Your API comments say this can be NULL. Either ma
Sheridan Rawlins
2011/03/09 00:18:26
Done.
| |
| 156 *total_height = top - minimum_top; | |
| 157 return -minimum_top; | |
| 158 } | |
| 159 | |
| 143 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate, | 160 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate, |
| 144 bool use_animation) { | 161 bool use_animation) { |
| 145 // Search for the infobar associated with |delegate|. We cannot search for | 162 // Search for the infobar associated with |delegate|. We cannot search for |
| 146 // |delegate| in |tab_contents_|, because an InfoBar remains alive until its | 163 // |delegate| in |tab_contents_|, because an InfoBar remains alive until its |
| 147 // close animation completes, while the delegate is removed from the tab | 164 // close animation completes, while the delegate is removed from the tab |
| 148 // immediately. | 165 // immediately. |
| 149 for (InfoBars::iterator i(infobars_.begin()); i != infobars_.end(); ++i) { | 166 for (InfoBars::iterator i(infobars_.begin()); i != infobars_.end(); ++i) { |
| 150 InfoBarView* infobar = *i; | 167 InfoBarView* infobar = *i; |
| 151 if (infobar->delegate() == delegate) { | 168 if (infobar->delegate() == delegate) { |
| 152 // We merely need hide the infobar; it will call back to RemoveInfoBar() | 169 // We merely need hide the infobar; it will call back to RemoveInfoBar() |
| 153 // itself once it's hidden. | 170 // itself once it's hidden. |
| 154 infobar->Hide(use_animation); | 171 infobar->Hide(use_animation); |
| 155 break; | 172 break; |
| 156 } | 173 } |
| 157 } | 174 } |
| 158 } | 175 } |
| 159 | 176 |
| 160 void InfoBarContainer::AddInfoBar(InfoBar* infobar, | 177 void InfoBarContainer::AddInfoBar(InfoBar* infobar, |
| 161 bool animate, | 178 bool animate, |
| 162 CallbackStatus callback_status) { | 179 CallbackStatus callback_status) { |
| 163 InfoBarView* infobar_view = static_cast<InfoBarView*>(infobar); | 180 InfoBarView* infobar_view = static_cast<InfoBarView*>(infobar); |
| 164 infobars_.insert(infobar_view); | 181 infobars_.insert(infobar_view); |
| 165 AddChildView(infobar_view); | 182 AddChildView(infobar_view); |
| 166 if (callback_status == WANT_CALLBACK) | 183 if (callback_status == WANT_CALLBACK) |
| 167 infobar_view->set_container(this); | 184 infobar_view->set_container(this); |
| 168 infobar_view->Show(animate); | 185 infobar_view->Show(animate); |
| 169 if (callback_status == NO_CALLBACK) | 186 if (callback_status == NO_CALLBACK) |
| 170 infobar_view->set_container(this); | 187 infobar_view->set_container(this); |
| 171 } | 188 } |
| OLD | NEW |