OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/layout/fill_layout.h" |
8 | 9 |
9 using content::WebContents; | 10 using content::WebContents; |
10 | 11 |
| 12 class ContentsContainer::HeaderView : public views::View { |
| 13 public: |
| 14 HeaderView(); |
| 15 |
| 16 bool should_show() { return child_count() && child_at(0)->visible(); } |
| 17 |
| 18 protected: |
| 19 // views::View overrides: |
| 20 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; |
| 21 |
| 22 private: |
| 23 bool child_visibile_; |
| 24 |
| 25 DISALLOW_COPY_AND_ASSIGN(HeaderView); |
| 26 }; |
| 27 |
| 28 ContentsContainer::HeaderView::HeaderView() : child_visibile_(false) {} |
| 29 |
| 30 void ContentsContainer::HeaderView::ChildPreferredSizeChanged( |
| 31 views::View* child) { |
| 32 if (parent() && (child->visible() || child_visibile_)) |
| 33 parent()->Layout(); |
| 34 child_visibile_ = child->visible(); |
| 35 } |
| 36 |
11 // static | 37 // static |
12 const char ContentsContainer::kViewClassName[] = | 38 const char ContentsContainer::kViewClassName[] = |
13 "browser/ui/views/frame/ContentsContainer"; | 39 "browser/ui/views/frame/ContentsContainer"; |
14 | 40 |
15 ContentsContainer::ContentsContainer(views::View* active) | 41 ContentsContainer::ContentsContainer(views::View* active) |
16 : active_(active), | 42 : header_(new HeaderView()), |
| 43 active_(active), |
17 preview_(NULL), | 44 preview_(NULL), |
18 preview_web_contents_(NULL), | 45 preview_web_contents_(NULL), |
19 active_top_margin_(0) { | 46 active_top_margin_(0) { |
20 AddChildView(active_); | 47 AddChildView(active_); |
| 48 header_->SetLayoutManager(new views::FillLayout); |
| 49 AddChildView(header_); |
21 } | 50 } |
22 | 51 |
23 ContentsContainer::~ContentsContainer() { | 52 ContentsContainer::~ContentsContainer() { |
24 } | 53 } |
25 | 54 |
| 55 views::View* ContentsContainer::header() { return header_; } |
| 56 |
26 void ContentsContainer::MakePreviewContentsActiveContents() { | 57 void ContentsContainer::MakePreviewContentsActiveContents() { |
27 DCHECK(preview_); | 58 DCHECK(preview_); |
28 | 59 |
29 active_ = preview_; | 60 active_ = preview_; |
30 preview_ = NULL; | 61 preview_ = NULL; |
31 preview_web_contents_ = NULL; | 62 preview_web_contents_ = NULL; |
32 Layout(); | 63 Layout(); |
33 } | 64 } |
34 | 65 |
35 void ContentsContainer::SetPreview(views::View* preview, | 66 void ContentsContainer::SetPreview(views::View* preview, |
(...skipping 21 matching lines...) Expand all Loading... |
57 InvalidateLayout(); | 88 InvalidateLayout(); |
58 } | 89 } |
59 | 90 |
60 gfx::Rect ContentsContainer::GetPreviewBounds() { | 91 gfx::Rect ContentsContainer::GetPreviewBounds() { |
61 gfx::Point screen_loc; | 92 gfx::Point screen_loc; |
62 ConvertPointToScreen(this, &screen_loc); | 93 ConvertPointToScreen(this, &screen_loc); |
63 return gfx::Rect(screen_loc, size()); | 94 return gfx::Rect(screen_loc, size()); |
64 } | 95 } |
65 | 96 |
66 void ContentsContainer::Layout() { | 97 void ContentsContainer::Layout() { |
67 // The active view always gets the full bounds. | 98 int content_y = active_top_margin_; |
68 active_->SetBounds(0, active_top_margin_, width(), | 99 int content_height = std::max(0, height() - content_y); |
69 std::max(0, height() - active_top_margin_)); | 100 if (header_->should_show()) { |
| 101 gfx::Size header_pref = header_->GetPreferredSize(); |
| 102 int header_height = std::min(content_height, header_pref.height()); |
| 103 content_height -= header_height; |
| 104 header_->SetBounds(0, content_y, width(), header_height); |
| 105 content_y += header_height; |
| 106 } else { |
| 107 header_->SetBoundsRect(gfx::Rect()); |
| 108 } |
| 109 active_->SetBounds(0, content_y, width(), content_height); |
70 | 110 |
71 if (preview_) | 111 if (preview_) |
72 preview_->SetBounds(0, 0, width(), height()); | 112 preview_->SetBounds(0, 0, width(), height()); |
73 | 113 |
74 // Need to invoke views::View in case any views whose bounds didn't change | 114 // Need to invoke views::View in case any views whose bounds didn't change |
75 // still need a layout. | 115 // still need a layout. |
76 views::View::Layout(); | 116 views::View::Layout(); |
77 } | 117 } |
78 | 118 |
79 std::string ContentsContainer::GetClassName() const { | 119 std::string ContentsContainer::GetClassName() const { |
80 return kViewClassName; | 120 return kViewClassName; |
81 } | 121 } |
OLD | NEW |