Chromium Code Reviews| Index: chrome/browser/ui/views/frame/contents_container.cc |
| diff --git a/chrome/browser/ui/views/frame/contents_container.cc b/chrome/browser/ui/views/frame/contents_container.cc |
| index 7b6981fd7dc542eee988d0824e23d7693e66c229..31feb37fade5d5c920fd6bb80f24013b184f155d 100644 |
| --- a/chrome/browser/ui/views/frame/contents_container.cc |
| +++ b/chrome/browser/ui/views/frame/contents_container.cc |
| @@ -5,24 +5,55 @@ |
| #include "chrome/browser/ui/views/frame/contents_container.h" |
| #include "base/logging.h" |
| +#include "ui/views/layout/fill_layout.h" |
| using content::WebContents; |
| +class ContentsContainer::HeaderView : public views::View { |
| + public: |
| + HeaderView(); |
| + |
| + bool should_show() { return child_count() && child_at(0)->visible(); } |
|
Peter Kasting
2012/06/22 20:33:22
Nit: const
|
| + |
| + protected: |
| + // views::View overrides: |
| + virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; |
| + |
| + private: |
| + bool child_visibile_; |
|
Peter Kasting
2012/06/22 20:33:22
Nit: Maybe call this child_was_visible_ and add so
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(HeaderView); |
| +}; |
| + |
| +ContentsContainer::HeaderView::HeaderView() : child_visibile_(false) {} |
| + |
| +void ContentsContainer::HeaderView::ChildPreferredSizeChanged( |
| + views::View* child) { |
| + if (parent() && (child->visible() || child_visibile_)) |
| + parent()->Layout(); |
| + child_visibile_ = child->visible(); |
| +} |
| + |
| // static |
| const char ContentsContainer::kViewClassName[] = |
| "browser/ui/views/frame/ContentsContainer"; |
| ContentsContainer::ContentsContainer(views::View* active) |
| - : active_(active), |
| + : header_(new HeaderView()), |
| + active_(active), |
| preview_(NULL), |
| preview_web_contents_(NULL), |
| active_top_margin_(0) { |
| AddChildView(active_); |
| + header_->SetLayoutManager(new views::FillLayout); |
| + AddChildView(header_); |
| } |
| ContentsContainer::~ContentsContainer() { |
| } |
| +views::View* ContentsContainer::header() { return header_; } |
| + |
| void ContentsContainer::MakePreviewContentsActiveContents() { |
| DCHECK(preview_); |
| @@ -64,9 +95,18 @@ gfx::Rect ContentsContainer::GetPreviewBounds() { |
| } |
| void ContentsContainer::Layout() { |
| - // The active view always gets the full bounds. |
| - active_->SetBounds(0, active_top_margin_, width(), |
| - std::max(0, height() - active_top_margin_)); |
| + int content_y = active_top_margin_; |
| + int content_height = std::max(0, height() - content_y); |
| + if (header_->should_show()) { |
| + gfx::Size header_pref = header_->GetPreferredSize(); |
| + int header_height = std::min(content_height, header_pref.height()); |
| + content_height -= header_height; |
| + header_->SetBounds(0, content_y, width(), header_height); |
| + content_y += header_height; |
| + } else { |
| + header_->SetBoundsRect(gfx::Rect()); |
| + } |
| + active_->SetBounds(0, content_y, width(), content_height); |
| if (preview_) |
| preview_->SetBounds(0, 0, width(), height()); |