Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/ui/views/frame/contents_container.cc

Issue 10915217: Hook up SetInstantPreviewHeight for ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 23 matching lines...) Expand all
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 if (preview == preview_)
59 return; 61 return;
60 62
61 if (preview_) 63 if (preview_)
62 RemoveChildView(preview_); 64 RemoveChildView(preview_);
63 preview_ = preview; 65 preview_ = preview;
64 preview_web_contents_ = preview_web_contents; 66 preview_web_contents_ = preview_web_contents;
65 if (preview_) 67 if (preview_) {
66 AddChildView(preview_); 68 AddChildView(preview_);
67 69 } else {
70 preview_height_ = 100;
71 preview_height_units_ = INSTANT_SIZE_PERCENT;
72 }
68 Layout(); 73 Layout();
69 } 74 }
70 75
71 void ContentsContainer::SetActiveTopMargin(int margin) { 76 void ContentsContainer::SetActiveTopMargin(int margin) {
72 if (active_top_margin_ == margin) 77 if (active_top_margin_ == margin)
73 return; 78 return;
74 79
75 active_top_margin_ = margin; 80 active_top_margin_ = margin;
76 // Make sure we layout next time around. We need this in case our bounds 81 // Make sure we layout next time around. We need this in case our bounds
77 // haven't changed. 82 // haven't changed.
78 InvalidateLayout(); 83 InvalidateLayout();
79 } 84 }
80 85
81 gfx::Rect ContentsContainer::GetPreviewBounds() { 86 gfx::Rect ContentsContainer::GetPreviewBounds() {
82 gfx::Point screen_loc; 87 gfx::Point screen_loc;
83 ConvertPointToScreen(this, &screen_loc); 88 ConvertPointToScreen(this, &screen_loc);
84 return gfx::Rect(screen_loc, size()); 89 return gfx::Rect(screen_loc, size());
85 } 90 }
86 91
87 void ContentsContainer::Layout() { 92 void ContentsContainer::Layout() {
88 int content_y = active_top_margin_; 93 int content_y = active_top_margin_;
89 int content_height = std::max(0, height() - content_y); 94 int content_height = std::max(0, height() - content_y);
90 95
91 if (active_) 96 if (active_)
92 active_->SetBounds(0, content_y, width(), content_height); 97 active_->SetBounds(0, content_y, width(), content_height);
93 98
94 if (overlay_) 99 if (overlay_)
95 overlay_->SetBounds(0, 0, width(), height()); 100 overlay_->SetBounds(0, 0, width(), height());
96 101
97 if (preview_) 102 if (preview_) {
98 preview_->SetBounds(0, 0, width(), height()); 103 const int capped_height = std::min(height(), PreviewHeightInPixels());
104 preview_->SetBounds(0, 0, width(), capped_height);
105 }
99 106
100 // Need to invoke views::View in case any views whose bounds didn't change 107 // Need to invoke views::View in case any views whose bounds didn't change
101 // still need a layout. 108 // still need a layout.
102 views::View::Layout(); 109 views::View::Layout();
103 } 110 }
104 111
112 void ContentsContainer::SetPreviewHeight(int height, InstantSizeUnits units) {
113 int old_height = PreviewHeightInPixels();
114 preview_height_ = height;
115 preview_height_units_ = units;
116 // Only re-layout if the height changed.
117 if (preview_ && old_height != PreviewHeightInPixels()) {
118 Layout();
119 }
sreeram 2012/09/18 22:24:24 Nit: No curlies.
Jered 2012/09/18 22:46:24 Done.
120 }
121
122 int ContentsContainer::PreviewHeightInPixels() const {
123 switch (preview_height_units_) {
124 case INSTANT_SIZE_PERCENT:
125 return (height() * preview_height_) / 100;
126
127 case INSTANT_SIZE_PIXELS:
128 return preview_height_;
129 }
130 NOTREACHED() << "unknown units: " << preview_height_units_;
131 return 0;
132 }
133
105 std::string ContentsContainer::GetClassName() const { 134 std::string ContentsContainer::GetClassName() const {
106 return kViewClassName; 135 return kViewClassName;
107 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698