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 508fff9f24523528d3bd8804b09a49af50f3bfda..86f5a44a7e2abcc7f740b0bcc6d35d69d6586609 100644 |
| --- a/chrome/browser/ui/views/frame/contents_container.cc |
| +++ b/chrome/browser/ui/views/frame/contents_container.cc |
| @@ -18,7 +18,9 @@ ContentsContainer::ContentsContainer(views::WebView* active) |
| overlay_(NULL), |
| preview_(NULL), |
| preview_web_contents_(NULL), |
| - active_top_margin_(0) { |
| + active_top_margin_(0), |
| + preview_height_(100), |
| + preview_height_units_(INSTANT_SIZE_PERCENT) { |
| AddChildView(active_); |
| } |
| @@ -62,9 +64,12 @@ void ContentsContainer::SetPreview(views::WebView* preview, |
| RemoveChildView(preview_); |
| preview_ = preview; |
| preview_web_contents_ = preview_web_contents; |
| - if (preview_) |
| + if (preview_) { |
| AddChildView(preview_); |
| - |
| + } else { |
| + preview_height_ = 100; |
| + preview_height_units_ = INSTANT_SIZE_PERCENT; |
| + } |
| Layout(); |
| } |
| @@ -94,14 +99,37 @@ void ContentsContainer::Layout() { |
| if (overlay_) |
| overlay_->SetBounds(0, 0, width(), height()); |
| - if (preview_) |
| - preview_->SetBounds(0, 0, width(), height()); |
| + if (preview_) { |
| + const int capped_height = std::min(height(), PreviewHeightInPixels()); |
|
sky
2012/09/19 00:23:18
Shouldn't PreviewHeightInPixels cap for us?
Jered
2012/09/19 18:52:09
Done.
|
| + preview_->SetBounds(0, 0, width(), capped_height); |
| + } |
| // Need to invoke views::View in case any views whose bounds didn't change |
| // still need a layout. |
| views::View::Layout(); |
| } |
| +void ContentsContainer::SetPreviewHeight(int height, InstantSizeUnits units) { |
| + int old_height = PreviewHeightInPixels(); |
| + preview_height_ = height; |
| + preview_height_units_ = units; |
| + // Only re-layout if the height changed. |
| + if (preview_ && old_height != PreviewHeightInPixels()) |
| + Layout(); |
| +} |
| + |
| +int ContentsContainer::PreviewHeightInPixels() const { |
| + switch (preview_height_units_) { |
| + case INSTANT_SIZE_PERCENT: |
| + return (height() * preview_height_) / 100; |
| + |
| + case INSTANT_SIZE_PIXELS: |
| + return preview_height_; |
| + } |
| + NOTREACHED() << "unknown units: " << preview_height_units_; |
| + return 0; |
| +} |
| + |
| std::string ContentsContainer::GetClassName() const { |
| return kViewClassName; |
| } |