| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/frame/contents_container.h" | 5 #include "chrome/browser/ui/views/frame/contents_container.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/views/controls/webview/webview.h" | 8 #include "ui/views/controls/webview/webview.h" |
| 9 | 9 |
| 10 using content::WebContents; | 10 using content::WebContents; |
| 11 | 11 |
| 12 // static | 12 // static |
| 13 const char ContentsContainer::kViewClassName[] = | 13 const char ContentsContainer::kViewClassName[] = |
| 14 "browser/ui/views/frame/ContentsContainer"; | 14 "browser/ui/views/frame/ContentsContainer"; |
| 15 | 15 |
| 16 ContentsContainer::ContentsContainer(views::WebView* active) | 16 ContentsContainer::ContentsContainer(views::WebView* active) |
| 17 : active_(active), | 17 : active_(active), |
| 18 overlay_(NULL), | 18 overlay_(NULL), |
| 19 preview_(NULL), | 19 preview_(NULL), |
| 20 preview_web_contents_(NULL), | 20 preview_web_contents_(NULL), |
| 21 active_top_margin_(0) { | 21 active_top_margin_(0), |
| 22 preview_height_(100), |
| 23 preview_height_units_(INSTANT_SIZE_PERCENT) { |
| 22 AddChildView(active_); | 24 AddChildView(active_); |
| 23 } | 25 } |
| 24 | 26 |
| 25 ContentsContainer::~ContentsContainer() { | 27 ContentsContainer::~ContentsContainer() { |
| 26 } | 28 } |
| 27 | 29 |
| 28 void ContentsContainer::SetActive(views::WebView* active) { | 30 void ContentsContainer::SetActive(views::WebView* active) { |
| 29 if (active_) | 31 if (active_) |
| 30 RemoveChildView(active_); | 32 RemoveChildView(active_); |
| 31 active_ = active; | 33 active_ = active; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 47 void ContentsContainer::MakePreviewContentsActiveContents() { | 49 void ContentsContainer::MakePreviewContentsActiveContents() { |
| 48 DCHECK(preview_); | 50 DCHECK(preview_); |
| 49 | 51 |
| 50 active_ = preview_; | 52 active_ = preview_; |
| 51 preview_ = NULL; | 53 preview_ = NULL; |
| 52 preview_web_contents_ = NULL; | 54 preview_web_contents_ = NULL; |
| 53 Layout(); | 55 Layout(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void ContentsContainer::SetPreview(views::WebView* preview, | 58 void ContentsContainer::SetPreview(views::WebView* preview, |
| 57 WebContents* preview_web_contents) { | 59 WebContents* preview_web_contents, |
| 58 if (preview == preview_) | 60 int height, |
| 61 InstantSizeUnits units) { |
| 62 const int old_height = PreviewHeightInPixels(); |
| 63 preview_height_ = height; |
| 64 preview_height_units_ = units; |
| 65 if (preview == preview_ && preview_web_contents_ == preview_web_contents && |
| 66 old_height == PreviewHeightInPixels()) |
| 59 return; | 67 return; |
| 60 | 68 if (preview_ != preview) { |
| 61 if (preview_) | 69 if (preview_) |
| 62 RemoveChildView(preview_); | 70 RemoveChildView(preview_); |
| 63 preview_ = preview; | 71 preview_ = preview; |
| 72 if (preview_) |
| 73 AddChildView(preview_); |
| 74 } |
| 64 preview_web_contents_ = preview_web_contents; | 75 preview_web_contents_ = preview_web_contents; |
| 65 if (preview_) | |
| 66 AddChildView(preview_); | |
| 67 | |
| 68 Layout(); | 76 Layout(); |
| 69 } | 77 } |
| 70 | 78 |
| 71 void ContentsContainer::SetActiveTopMargin(int margin) { | 79 void ContentsContainer::SetActiveTopMargin(int margin) { |
| 72 if (active_top_margin_ == margin) | 80 if (active_top_margin_ == margin) |
| 73 return; | 81 return; |
| 74 | 82 |
| 75 active_top_margin_ = margin; | 83 active_top_margin_ = margin; |
| 76 // Make sure we layout next time around. We need this in case our bounds | 84 // Make sure we layout next time around. We need this in case our bounds |
| 77 // haven't changed. | 85 // haven't changed. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 int content_y = active_top_margin_; | 96 int content_y = active_top_margin_; |
| 89 int content_height = std::max(0, height() - content_y); | 97 int content_height = std::max(0, height() - content_y); |
| 90 | 98 |
| 91 if (active_) | 99 if (active_) |
| 92 active_->SetBounds(0, content_y, width(), content_height); | 100 active_->SetBounds(0, content_y, width(), content_height); |
| 93 | 101 |
| 94 if (overlay_) | 102 if (overlay_) |
| 95 overlay_->SetBounds(0, 0, width(), height()); | 103 overlay_->SetBounds(0, 0, width(), height()); |
| 96 | 104 |
| 97 if (preview_) | 105 if (preview_) |
| 98 preview_->SetBounds(0, 0, width(), height()); | 106 preview_->SetBounds(0, 0, width(), PreviewHeightInPixels()); |
| 99 | 107 |
| 100 // Need to invoke views::View in case any views whose bounds didn't change | 108 // Need to invoke views::View in case any views whose bounds didn't change |
| 101 // still need a layout. | 109 // still need a layout. |
| 102 views::View::Layout(); | 110 views::View::Layout(); |
| 103 } | 111 } |
| 104 | 112 |
| 113 int ContentsContainer::PreviewHeightInPixels() const { |
| 114 switch (preview_height_units_) { |
| 115 case INSTANT_SIZE_PERCENT: |
| 116 return std::min(height(), (height() * preview_height_) / 100); |
| 117 |
| 118 case INSTANT_SIZE_PIXELS: |
| 119 return std::min(height(), preview_height_); |
| 120 } |
| 121 NOTREACHED() << "unknown units: " << preview_height_units_; |
| 122 return 0; |
| 123 } |
| 124 |
| 105 std::string ContentsContainer::GetClassName() const { | 125 std::string ContentsContainer::GetClassName() const { |
| 106 return kViewClassName; | 126 return kViewClassName; |
| 107 } | 127 } |
| OLD | NEW |