| 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_(-1) { |
| 22 AddChildView(active_); | 23 AddChildView(active_); |
| 23 } | 24 } |
| 24 | 25 |
| 25 ContentsContainer::~ContentsContainer() { | 26 ContentsContainer::~ContentsContainer() { |
| 26 } | 27 } |
| 27 | 28 |
| 28 void ContentsContainer::SetActive(views::WebView* active) { | 29 void ContentsContainer::SetActive(views::WebView* active) { |
| 29 if (active_) | 30 if (active_) |
| 30 RemoveChildView(active_); | 31 RemoveChildView(active_); |
| 31 active_ = active; | 32 active_ = active; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // haven't changed. | 78 // haven't changed. |
| 78 InvalidateLayout(); | 79 InvalidateLayout(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 gfx::Rect ContentsContainer::GetPreviewBounds() { | 82 gfx::Rect ContentsContainer::GetPreviewBounds() { |
| 82 gfx::Point screen_loc; | 83 gfx::Point screen_loc; |
| 83 ConvertPointToScreen(this, &screen_loc); | 84 ConvertPointToScreen(this, &screen_loc); |
| 84 return gfx::Rect(screen_loc, size()); | 85 return gfx::Rect(screen_loc, size()); |
| 85 } | 86 } |
| 86 | 87 |
| 88 void ContentsContainer::SetPreviewHeight(int value, bool is_percent) { |
| 89 preview_height_ = is_percent ? (value * height()) / 100 : value; |
| 90 |
| 91 Layout(); |
| 92 } |
| 93 |
| 87 void ContentsContainer::Layout() { | 94 void ContentsContainer::Layout() { |
| 88 int content_y = active_top_margin_; | 95 int content_y = active_top_margin_; |
| 89 int content_height = std::max(0, height() - content_y); | 96 int content_height = std::max(0, height() - content_y); |
| 90 | 97 |
| 91 if (active_) | 98 if (active_) |
| 92 active_->SetBounds(0, content_y, width(), content_height); | 99 active_->SetBounds(0, content_y, width(), content_height); |
| 93 | 100 |
| 94 if (overlay_) | 101 if (overlay_) |
| 95 overlay_->SetBounds(0, 0, width(), height()); | 102 overlay_->SetBounds(0, 0, width(), height()); |
| 96 | 103 |
| 97 if (preview_) | 104 if (preview_) |
| 98 preview_->SetBounds(0, 0, width(), height()); | 105 preview_->SetBounds(0, 0, width(), |
| 106 (preview_height_ < 0 || preview_height_ > height() ? |
| 107 height() : preview_height_)); |
| 99 | 108 |
| 100 // Need to invoke views::View in case any views whose bounds didn't change | 109 // Need to invoke views::View in case any views whose bounds didn't change |
| 101 // still need a layout. | 110 // still need a layout. |
| 102 views::View::Layout(); | 111 views::View::Layout(); |
| 103 } | 112 } |
| 104 | 113 |
| 105 std::string ContentsContainer::GetClassName() const { | 114 std::string ContentsContainer::GetClassName() const { |
| 106 return kViewClassName; | 115 return kViewClassName; |
| 107 } | 116 } |
| OLD | NEW |