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

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: Cast stroke width. 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 void InfoBarContainer::LayoutHelper(bool set_bounds,
Peter Kasting 2011/03/07 20:14:30 Nit: Function definition order should match declar
Sheridan Rawlins 2011/03/08 01:38:19 Done.
37 int* vertical_overlap,
38 int* height) const {
39 int minimum_top = 0;
40 int top = 0;
41
42 if (set_bounds) {
Peter Kasting 2011/03/07 22:23:07 This recursive method works correctly, but it has
Sheridan Rawlins 2011/03/08 01:38:19 Slightly different but in the same spirit. Done.
43 // Because multiple infobars may be animating, the tab of a
44 // vertically lower InfoBarView may be "higher", and the first
45 // InfoBarView may start "lower" than 0. Call once recursively to
46 // set the top to the overlap amount before laying out.
47 LayoutHelper(false, &top, height);
48 }
49
50 for (int i = 0; i < child_count(); ++i) {
51 View* child = const_cast<View*>(GetChildViewAt(i));
52 gfx::Size ps = child->GetPreferredSize();
53 int overlapped_top = top -
54 static_cast<InfoBarView*>(child)->vertical_overlap();
55 minimum_top = std::min(minimum_top, overlapped_top);
56 if (set_bounds)
57 child->SetBounds(0, overlapped_top, width(), ps.height());
58 top = overlapped_top + ps.height();
59 }
60
61 DCHECK(vertical_overlap);
62 DCHECK(height);
63 *vertical_overlap = -minimum_top;
64 *height = top - minimum_top;
65 }
66
67 int InfoBarContainer::vertical_overlap() const {
68 int vertical_overlap;
69 int height;
70 LayoutHelper(false, &vertical_overlap, &height);
71 return vertical_overlap;
72 }
73
36 void InfoBarContainer::ChangeTabContents(TabContents* contents) { 74 void InfoBarContainer::ChangeTabContents(TabContents* contents) {
37 registrar_.RemoveAll(); 75 registrar_.RemoveAll();
38 76
39 while (!infobars_.empty()) { 77 while (!infobars_.empty()) {
40 InfoBarView* infobar = *infobars_.begin(); 78 InfoBarView* infobar = *infobars_.begin();
41 // NULL the container pointer first so OnInfoBarAnimated() won't get called; 79 // 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. 80 // we'll manually trigger this once for the whole set of changes below.
43 infobar->set_container(NULL); 81 infobar->set_container(NULL);
44 RemoveInfoBar(infobar); 82 RemoveInfoBar(infobar);
45 } 83 }
(...skipping 27 matching lines...) Expand all
73 111
74 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { 112 void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) {
75 tab_contents_->RemoveInfoBar(delegate); 113 tab_contents_->RemoveInfoBar(delegate);
76 } 114 }
77 115
78 void InfoBarContainer::RemoveInfoBar(InfoBarView* infobar) { 116 void InfoBarContainer::RemoveInfoBar(InfoBarView* infobar) {
79 RemoveChildView(infobar); 117 RemoveChildView(infobar);
80 infobars_.erase(infobar); 118 infobars_.erase(infobar);
81 } 119 }
82 120
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() { 121 gfx::Size InfoBarContainer::GetPreferredSize() {
93 // We do not have a preferred width (we will expand to fit the available width 122 // We do not have a preferred width (we will expand to fit the
94 // of the delegate). Our preferred height is the sum of the preferred heights 123 // available width of the delegate). Our preferred height is the sum
Peter Kasting 2011/03/07 20:14:30 Nit: Why did you rewrap these lines? They were fi
Sheridan Rawlins 2011/03/08 01:38:19 After adding text, I hit M-q. Emacs' c-fill-parag
95 // of the InfoBars contained within us. 124 // of the preferred heights of the InfoBars contained within us and
96 int height = 0; 125 // the tab_height.
97 for (int i = 0; i < child_count(); ++i) 126 int vertical_overlap;
98 height += GetChildViewAt(i)->GetPreferredSize().height(); 127 int height;
128 LayoutHelper(false, &vertical_overlap, &height);
99 return gfx::Size(0, height); 129 return gfx::Size(0, height);
100 } 130 }
101 131
102 void InfoBarContainer::Layout() { 132 void InfoBarContainer::Layout() {
103 int top = 0; 133 int vertical_overlap;
104 for (int i = 0; i < child_count(); ++i) { 134 int height;
105 View* child = GetChildViewAt(i); 135 LayoutHelper(true, &vertical_overlap, &height);
106 gfx::Size ps = child->GetPreferredSize();
107 child->SetBounds(0, top, width(), ps.height());
108 top += ps.height();
109 }
110 } 136 }
111 137
112 AccessibilityTypes::Role InfoBarContainer::GetAccessibleRole() { 138 AccessibilityTypes::Role InfoBarContainer::GetAccessibleRole() {
113 return AccessibilityTypes::ROLE_GROUPING; 139 return AccessibilityTypes::ROLE_GROUPING;
114 } 140 }
115 141
116 void InfoBarContainer::Observe(NotificationType type, 142 void InfoBarContainer::Observe(NotificationType type,
117 const NotificationSource& source, 143 const NotificationSource& source,
118 const NotificationDetails& details) { 144 const NotificationDetails& details) {
119 switch (type.value) { 145 switch (type.value) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 CallbackStatus callback_status) { 188 CallbackStatus callback_status) {
163 InfoBarView* infobar_view = static_cast<InfoBarView*>(infobar); 189 InfoBarView* infobar_view = static_cast<InfoBarView*>(infobar);
164 infobars_.insert(infobar_view); 190 infobars_.insert(infobar_view);
165 AddChildView(infobar_view); 191 AddChildView(infobar_view);
166 if (callback_status == WANT_CALLBACK) 192 if (callback_status == WANT_CALLBACK)
167 infobar_view->set_container(this); 193 infobar_view->set_container(this);
168 infobar_view->Show(animate); 194 infobar_view->Show(animate);
169 if (callback_status == NO_CALLBACK) 195 if (callback_status == NO_CALLBACK)
170 infobar_view->set_container(this); 196 infobar_view->set_container(this);
171 } 197 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698