Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/ui/views/infobars/infobar_container.cc

Issue 6609047: [linux_views][Win] spoof proof redesign infobar extension with tab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: renames, don't const_cast, ditch InfoBarView::VerticalOffset. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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() {
37 return GetVerticalOverlap(NULL);
38 }
39
36 void InfoBarContainer::ChangeTabContents(TabContents* contents) { 40 void InfoBarContainer::ChangeTabContents(TabContents* contents) {
37 registrar_.RemoveAll(); 41 registrar_.RemoveAll();
38 42
39 while (!infobars_.empty()) { 43 while (!infobars_.empty()) {
40 InfoBarView* infobar = *infobars_.begin(); 44 InfoBarView* infobar = *infobars_.begin();
41 // NULL the container pointer first so OnInfoBarAnimated() won't get called; 45 // 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. 46 // we'll manually trigger this once for the whole set of changes below.
43 infobar->set_container(NULL); 47 infobar->set_container(NULL);
44 RemoveInfoBar(infobar); 48 RemoveInfoBar(infobar);
45 } 49 }
(...skipping 27 matching lines...) Expand all
73 77
74 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { 78 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) {
75 tab_contents_->RemoveInfoBar(delegate); 79 tab_contents_->RemoveInfoBar(delegate);
76 } 80 }
77 81
78 void InfoBarContainer::RemoveInfoBar(InfoBarView* infobar) { 82 void InfoBarContainer::RemoveInfoBar(InfoBarView* infobar) {
79 RemoveChildView(infobar); 83 RemoveChildView(infobar);
80 infobars_.erase(infobar); 84 infobars_.erase(infobar);
81 } 85 }
82 86
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() { 87 gfx::Size InfoBarContainer::GetPreferredSize() {
93 // We do not have a preferred width (we will expand to fit the available width 88 // 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 89 // of the delegate).
95 // of the InfoBars contained within us. 90 int total_height;
96 int height = 0; 91 GetVerticalOverlap(&total_height);
97 for (int i = 0; i < child_count(); ++i) 92 return gfx::Size(0, total_height);
98 height += GetChildViewAt(i)->GetPreferredSize().height();
99 return gfx::Size(0, height);
100 } 93 }
101 94
102 void InfoBarContainer::Layout() { 95 void InfoBarContainer::Layout() {
103 int top = 0; 96 int top = GetVerticalOverlap(NULL);
97
104 for (int i = 0; i < child_count(); ++i) { 98 for (int i = 0; i < child_count(); ++i) {
105 View* child = GetChildViewAt(i); 99 View* child = GetChildViewAt(i);
106 gfx::Size ps = child->GetPreferredSize(); 100 gfx::Size ps = child->GetPreferredSize();
101 top -= static_cast<InfoBarView*>(child)->AnimatedTabHeight();
107 child->SetBounds(0, top, width(), ps.height()); 102 child->SetBounds(0, top, width(), ps.height());
108 top += ps.height(); 103 top += ps.height();
109 } 104 }
110 } 105 }
111 106
112 AccessibilityTypes::Role InfoBarContainer::GetAccessibleRole() { 107 AccessibilityTypes::Role InfoBarContainer::GetAccessibleRole() {
113 return AccessibilityTypes::ROLE_GROUPING; 108 return AccessibilityTypes::ROLE_GROUPING;
114 } 109 }
115 110
116 void InfoBarContainer::Observe(NotificationType type, 111 void InfoBarContainer::Observe(NotificationType type,
(...skipping 16 matching lines...) Expand all
133 AddInfoBar(infobar_pair->second->CreateInfoBar(), false, WANT_CALLBACK); 128 AddInfoBar(infobar_pair->second->CreateInfoBar(), false, WANT_CALLBACK);
134 break; 129 break;
135 } 130 }
136 131
137 default: 132 default:
138 NOTREACHED(); 133 NOTREACHED();
139 break; 134 break;
140 } 135 }
141 } 136 }
142 137
138 int InfoBarContainer::GetVerticalOverlap(int* total_height) {
139 // Our |total_height| is the sum of the preferred heights of the InfoBars
140 // contained within us plus the |vertical_overlap|.
141 int vertical_overlap = 0;
142 int next_child_y = 0;
143
144 for (int i = 0; i < child_count(); ++i) {
145 View* child = GetChildViewAt(i);
146 gfx::Size ps = child->GetPreferredSize();
147 next_child_y -= static_cast<InfoBarView*>(child)->AnimatedTabHeight();
148 vertical_overlap = std::max(vertical_overlap, -next_child_y);
149 next_child_y += child->GetPreferredSize().height();
150 }
151
152 if (total_height)
153 *total_height = next_child_y + vertical_overlap;
154 return vertical_overlap;
155 }
156
143 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate, 157 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate,
144 bool use_animation) { 158 bool use_animation) {
145 // Search for the infobar associated with |delegate|. We cannot search for 159 // Search for the infobar associated with |delegate|. We cannot search for
146 // |delegate| in |tab_contents_|, because an InfoBar remains alive until its 160 // |delegate| in |tab_contents_|, because an InfoBar remains alive until its
147 // close animation completes, while the delegate is removed from the tab 161 // close animation completes, while the delegate is removed from the tab
148 // immediately. 162 // immediately.
149 for (InfoBars::iterator i(infobars_.begin()); i != infobars_.end(); ++i) { 163 for (InfoBars::iterator i(infobars_.begin()); i != infobars_.end(); ++i) {
150 InfoBarView* infobar = *i; 164 InfoBarView* infobar = *i;
151 if (infobar->delegate() == delegate) { 165 if (infobar->delegate() == delegate) {
152 // We merely need hide the infobar; it will call back to RemoveInfoBar() 166 // We merely need hide the infobar; it will call back to RemoveInfoBar()
153 // itself once it's hidden. 167 // itself once it's hidden.
154 infobar->Hide(use_animation); 168 infobar->Hide(use_animation);
155 break; 169 break;
156 } 170 }
157 } 171 }
158 } 172 }
159 173
160 void InfoBarContainer::AddInfoBar(InfoBar* infobar, 174 void InfoBarContainer::AddInfoBar(InfoBar* infobar,
161 bool animate, 175 bool animate,
162 CallbackStatus callback_status) { 176 CallbackStatus callback_status) {
163 InfoBarView* infobar_view = static_cast<InfoBarView*>(infobar); 177 InfoBarView* infobar_view = static_cast<InfoBarView*>(infobar);
164 infobars_.insert(infobar_view); 178 infobars_.insert(infobar_view);
165 AddChildView(infobar_view); 179 AddChildView(infobar_view);
166 if (callback_status == WANT_CALLBACK) 180 if (callback_status == WANT_CALLBACK)
167 infobar_view->set_container(this); 181 infobar_view->set_container(this);
168 infobar_view->Show(animate); 182 infobar_view->Show(animate);
169 if (callback_status == NO_CALLBACK) 183 if (callback_status == NO_CALLBACK)
170 infobar_view->set_container(this); 184 infobar_view->set_container(this);
171 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698