| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/info_bar_view.h" | 5 #include "chrome/browser/views/info_bar_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/navigation_controller.h" | 8 #include "chrome/browser/navigation_controller.h" |
| 9 #include "chrome/browser/navigation_entry.h" | 9 #include "chrome/browser/navigation_entry.h" |
| 10 #include "chrome/browser/tab_contents_delegate.h" | 10 #include "chrome/browser/tab_contents_delegate.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // AddChildView adds an entry to expire_map_ for view. | 48 // AddChildView adds an entry to expire_map_ for view. |
| 49 AddChildView(view); | 49 AddChildView(view); |
| 50 if (auto_expire) | 50 if (auto_expire) |
| 51 expire_map_[view] = GetActiveID(); | 51 expire_map_[view] = GetActiveID(); |
| 52 else | 52 else |
| 53 expire_map_.erase(expire_map_.find(view)); | 53 expire_map_.erase(expire_map_.find(view)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Preferred size is equal to the max of the childrens horizontal sizes | 56 // Preferred size is equal to the max of the childrens horizontal sizes |
| 57 // and the sum of their vertical sizes. | 57 // and the sum of their vertical sizes. |
| 58 void InfoBarView::GetPreferredSize(CSize *out) { | 58 gfx::Size InfoBarView::GetPreferredSize() { |
| 59 out->cx = 0; | 59 gfx::Size prefsize; |
| 60 out->cy = 0; | |
| 61 | 60 |
| 62 // We count backwards so the most recently added view is on the top. | 61 // We count backwards so the most recently added view is on the top. |
| 63 for (int i = GetChildViewCount() - 1; i >= 0; i--) { | 62 for (int i = GetChildViewCount() - 1; i >= 0; i--) { |
| 64 View* v = GetChildViewAt(i); | 63 View* v = GetChildViewAt(i); |
| 65 if (v->IsVisible()) { | 64 if (v->IsVisible()) { |
| 66 CSize view_size; | 65 prefsize.set_width(std::max(prefsize.width(), v->width())); |
| 67 v->GetPreferredSize(&view_size); | 66 prefsize.Enlarge(0, v->GetPreferredSize().height() + kSeparatorHeight); |
| 68 out->cx = std::max(static_cast<int>(out->cx), v->width()); | |
| 69 out->cy += static_cast<int>(view_size.cy) + kSeparatorHeight; | |
| 70 } | 67 } |
| 71 } | 68 } |
| 69 |
| 70 return prefsize; |
| 72 } | 71 } |
| 73 | 72 |
| 74 void InfoBarView::Layout() { | 73 void InfoBarView::Layout() { |
| 75 int x = 0; | 74 int x = 0; |
| 76 int y = height(); | 75 int y = height(); |
| 77 | 76 |
| 78 // We lay the bars out from bottom to top. | 77 // We lay the bars out from bottom to top. |
| 79 for (int i = 0; i < GetChildViewCount(); ++i) { | 78 for (int i = 0; i < GetChildViewCount(); ++i) { |
| 80 View* v = GetChildViewAt(i); | 79 View* v = GetChildViewAt(i); |
| 81 if (!v->IsVisible()) | 80 if (!v->IsVisible()) |
| 82 continue; | 81 continue; |
| 83 | 82 |
| 84 CSize view_size; | 83 gfx::Size view_size = v->GetPreferredSize(); |
| 85 v->GetPreferredSize(&view_size); | 84 int view_width = std::max(view_size.width(), width()); |
| 86 int view_width = std::max(static_cast<int>(view_size.cx), width()); | 85 y = y - view_size.height() - kSeparatorHeight; |
| 87 y = y - view_size.cy - kSeparatorHeight; | 86 v->SetBounds(x, y, view_width, view_size.height()); |
| 88 v->SetBounds(x, | |
| 89 y, | |
| 90 view_width, | |
| 91 view_size.cy); | |
| 92 } | 87 } |
| 93 } | 88 } |
| 94 | 89 |
| 95 void InfoBarView::Paint(ChromeCanvas* canvas) { | 90 void InfoBarView::Paint(ChromeCanvas* canvas) { |
| 96 PaintBackground(canvas); | 91 PaintBackground(canvas); |
| 97 PaintBorder(canvas); | 92 PaintBorder(canvas); |
| 98 PaintSeparators(canvas); | 93 PaintSeparators(canvas); |
| 99 } | 94 } |
| 100 | 95 |
| 101 void InfoBarView::DidChangeBounds(const CRect& previous, | 96 void InfoBarView::DidChangeBounds(const CRect& previous, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 229 } |
| 235 | 230 |
| 236 if (GetChildViewCount() == 0) { | 231 if (GetChildViewCount() == 0) { |
| 237 // All our views have been removed, no need to stay visible. | 232 // All our views have been removed, no need to stay visible. |
| 238 web_contents_->view()->SetInfoBarVisible(false); | 233 web_contents_->view()->SetInfoBarVisible(false); |
| 239 } else if (web_contents_) { | 234 } else if (web_contents_) { |
| 240 // This triggers a layout. | 235 // This triggers a layout. |
| 241 web_contents_->ToolbarSizeChanged(false); | 236 web_contents_->ToolbarSizeChanged(false); |
| 242 } | 237 } |
| 243 } | 238 } |
| OLD | NEW |