OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "content/public/browser/notification_service.h" | 7 #include "content/public/browser/notification_service.h" |
8 #include "content/public/browser/notification_types.h" | 8 #include "content/public/browser/notification_types.h" |
9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 }; | 77 }; |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 ContentsContainer::ContentsContainer(views::WebView* active) | 81 ContentsContainer::ContentsContainer(views::WebView* active) |
82 : active_(active), | 82 : active_(active), |
83 overlay_(NULL), | 83 overlay_(NULL), |
84 overlay_web_contents_(NULL), | 84 overlay_web_contents_(NULL), |
85 draw_drop_shadow_(false), | 85 draw_drop_shadow_(false), |
86 active_top_margin_(0), | 86 active_top_margin_(0), |
| 87 overlay_top_margin_(0), |
87 overlay_height_(100), | 88 overlay_height_(100), |
88 overlay_height_units_(INSTANT_SIZE_PERCENT) { | 89 overlay_height_units_(INSTANT_SIZE_PERCENT) { |
89 AddChildView(active_); | 90 AddChildView(active_); |
90 } | 91 } |
91 | 92 |
92 ContentsContainer::~ContentsContainer() { | 93 ContentsContainer::~ContentsContainer() { |
93 } | 94 } |
94 | 95 |
95 void ContentsContainer::MakeOverlayContentsActiveContents() { | 96 void ContentsContainer::MakeOverlayContentsActiveContents() { |
96 DCHECK(overlay_); | 97 DCHECK(overlay_); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (!overlay_) | 202 if (!overlay_) |
202 return; | 203 return; |
203 // To force |overlay_| to the topmost in the z-order, remove it, then add it | 204 // To force |overlay_| to the topmost in the z-order, remove it, then add it |
204 // back. | 205 // back. |
205 // See comments in SetOverlay() for why shadow view is removed. | 206 // See comments in SetOverlay() for why shadow view is removed. |
206 bool removed_shadow = false; | 207 bool removed_shadow = false; |
207 if (shadow_view_.get()) { | 208 if (shadow_view_.get()) { |
208 RemoveChildView(shadow_view_.get()); | 209 RemoveChildView(shadow_view_.get()); |
209 removed_shadow = true; | 210 removed_shadow = true; |
210 } | 211 } |
| 212 // TODO(jamescook): This can be done more efficiently with ReorderChildView(). |
211 RemoveChildView(overlay_); | 213 RemoveChildView(overlay_); |
212 AddChildView(overlay_); | 214 AddChildView(overlay_); |
213 if (removed_shadow) // Add back shadow view if it was removed. | 215 if (removed_shadow) // Add back shadow view if it was removed. |
214 AddChildView(shadow_view_.get()); | 216 AddChildView(shadow_view_.get()); |
215 Layout(); | 217 Layout(); |
216 } | 218 } |
217 | 219 |
218 void ContentsContainer::SetActiveTopMargin(int margin) { | 220 void ContentsContainer::SetWebViewsTopMargins(int active_top_margin, |
219 if (active_top_margin_ == margin) | 221 int overlay_top_margin) { |
| 222 if (active_top_margin_ == active_top_margin && |
| 223 overlay_top_margin_ == overlay_top_margin) |
220 return; | 224 return; |
221 | 225 active_top_margin_ = active_top_margin; |
222 active_top_margin_ = margin; | 226 overlay_top_margin_ = overlay_top_margin; |
223 // Make sure we layout next time around. We need this in case our bounds | 227 // Make sure we layout next time around. We need this in case our bounds |
224 // haven't changed. | 228 // haven't changed. |
225 InvalidateLayout(); | 229 InvalidateLayout(); |
226 } | 230 } |
227 | 231 |
228 gfx::Rect ContentsContainer::GetOverlayBounds() const { | 232 gfx::Rect ContentsContainer::GetOverlayBounds() const { |
229 gfx::Point screen_loc; | 233 gfx::Point screen_loc; |
230 ConvertPointToScreen(this, &screen_loc); | 234 ConvertPointToScreen(this, &screen_loc); |
231 return gfx::Rect(screen_loc, size()); | 235 return gfx::Rect(screen_loc, size()); |
232 } | 236 } |
233 | 237 |
234 bool ContentsContainer::IsOverlayFullHeight( | 238 bool ContentsContainer::IsOverlayFullHeight( |
235 int overlay_height, | 239 int overlay_height, |
236 InstantSizeUnits overlay_height_units) const { | 240 InstantSizeUnits overlay_height_units) const { |
237 int height_in_pixels = OverlayHeightInPixels(height(), overlay_height, | 241 int height_in_pixels = OverlayHeightInPixels(height(), overlay_height, |
238 overlay_height_units); | 242 overlay_height_units); |
239 return height_in_pixels == height(); | 243 return height_in_pixels == height(); |
240 } | 244 } |
241 | 245 |
242 void ContentsContainer::Layout() { | 246 void ContentsContainer::Layout() { |
243 int content_y = active_top_margin_; | 247 int content_y = active_top_margin_; |
244 int content_height = std::max(0, height() - content_y); | 248 int content_height = std::max(0, height() - content_y); |
245 | 249 |
246 active_->SetBounds(0, content_y, width(), content_height); | 250 active_->SetBounds(0, content_y, width(), content_height); |
247 | 251 |
248 if (overlay_) { | 252 if (overlay_) { |
249 overlay_->SetBounds(0, 0, width(), | 253 int overlay_height_pixels = |
250 OverlayHeightInPixels(height(), overlay_height_, | 254 OverlayHeightInPixels(height(), overlay_height_, overlay_height_units_); |
251 overlay_height_units_)); | 255 overlay_->SetBounds(0, overlay_top_margin_, width(), overlay_height_pixels); |
252 if (draw_drop_shadow_) { | 256 if (draw_drop_shadow_) { |
253 #if !defined(OS_WIN) | 257 #if !defined(OS_WIN) |
254 DCHECK(shadow_view_.get() && shadow_view_->parent()); | 258 DCHECK(shadow_view_.get() && shadow_view_->parent()); |
255 shadow_view_->SetBounds(0, overlay_->bounds().height(), width(), | 259 shadow_view_->SetBounds(0, overlay_->bounds().bottom(), width(), |
256 shadow_view_->GetPreferredSize().height()); | 260 shadow_view_->GetPreferredSize().height()); |
257 #endif // !defined(OS_WIN) | 261 #endif // !defined(OS_WIN) |
258 } | 262 } |
259 } | 263 } |
260 | 264 |
261 // Need to invoke views::View in case any views whose bounds didn't change | 265 // Need to invoke views::View in case any views whose bounds didn't change |
262 // still need a layout. | 266 // still need a layout. |
263 views::View::Layout(); | 267 views::View::Layout(); |
264 } | 268 } |
265 | 269 |
266 std::string ContentsContainer::GetClassName() const { | 270 std::string ContentsContainer::GetClassName() const { |
267 return kViewClassName; | 271 return kViewClassName; |
268 } | 272 } |
269 | 273 |
270 void ContentsContainer::Observe(int type, | 274 void ContentsContainer::Observe(int type, |
271 const content::NotificationSource& source, | 275 const content::NotificationSource& source, |
272 const content::NotificationDetails& details) { | 276 const content::NotificationDetails& details) { |
273 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | 277 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, |
274 type); | 278 type); |
275 // Remove shadow view if it's not needed. | 279 // Remove shadow view if it's not needed. |
276 if (overlay_ && !draw_drop_shadow_) | 280 if (overlay_ && !draw_drop_shadow_) |
277 shadow_view_.reset(); | 281 shadow_view_.reset(); |
278 } | 282 } |
OLD | NEW |