| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (!overlay_) | 205 if (!overlay_) |
| 205 return; | 206 return; |
| 206 // To force |overlay_| to the topmost in the z-order, remove it, then add it | 207 // To force |overlay_| to the topmost in the z-order, remove it, then add it |
| 207 // back. | 208 // back. |
| 208 // See comments in SetOverlay() for why shadow view is removed. | 209 // See comments in SetOverlay() for why shadow view is removed. |
| 209 bool removed_shadow = false; | 210 bool removed_shadow = false; |
| 210 if (shadow_view_.get()) { | 211 if (shadow_view_.get()) { |
| 211 RemoveChildView(shadow_view_.get()); | 212 RemoveChildView(shadow_view_.get()); |
| 212 removed_shadow = true; | 213 removed_shadow = true; |
| 213 } | 214 } |
| 215 // TODO(jamescook): This can be done more efficiently with ReorderChildView(). |
| 214 RemoveChildView(overlay_); | 216 RemoveChildView(overlay_); |
| 215 AddChildView(overlay_); | 217 AddChildView(overlay_); |
| 216 if (removed_shadow) // Add back shadow view if it was removed. | 218 if (removed_shadow) // Add back shadow view if it was removed. |
| 217 AddChildView(shadow_view_.get()); | 219 AddChildView(shadow_view_.get()); |
| 218 Layout(); | 220 Layout(); |
| 219 } | 221 } |
| 220 | 222 |
| 221 void ContentsContainer::SetActiveTopMargin(int margin) { | 223 void ContentsContainer::SetWebViewsTopMargins(int active_top_margin, |
| 222 if (active_top_margin_ == margin) | 224 int overlay_top_margin) { |
| 225 if (active_top_margin_ == active_top_margin && |
| 226 overlay_top_margin_ == overlay_top_margin) |
| 223 return; | 227 return; |
| 224 | 228 active_top_margin_ = active_top_margin; |
| 225 active_top_margin_ = margin; | 229 overlay_top_margin_ = overlay_top_margin; |
| 226 // Make sure we layout next time around. We need this in case our bounds | 230 // Make sure we layout next time around. We need this in case our bounds |
| 227 // haven't changed. | 231 // haven't changed. |
| 228 InvalidateLayout(); | 232 InvalidateLayout(); |
| 229 } | 233 } |
| 230 | 234 |
| 231 gfx::Rect ContentsContainer::GetOverlayBounds() const { | 235 gfx::Rect ContentsContainer::GetOverlayBounds() const { |
| 232 gfx::Point screen_loc; | 236 gfx::Point screen_loc; |
| 233 ConvertPointToScreen(this, &screen_loc); | 237 ConvertPointToScreen(this, &screen_loc); |
| 234 return gfx::Rect(screen_loc, size()); | 238 return gfx::Rect(screen_loc, size()); |
| 235 } | 239 } |
| 236 | 240 |
| 237 bool ContentsContainer::IsOverlayFullHeight( | 241 bool ContentsContainer::IsOverlayFullHeight( |
| 238 int overlay_height, | 242 int overlay_height, |
| 239 InstantSizeUnits overlay_height_units) const { | 243 InstantSizeUnits overlay_height_units) const { |
| 240 int height_in_pixels = OverlayHeightInPixels(height(), overlay_height, | 244 int height_in_pixels = OverlayHeightInPixels(height(), overlay_height, |
| 241 overlay_height_units); | 245 overlay_height_units); |
| 242 return height_in_pixels == height(); | 246 return height_in_pixels == height(); |
| 243 } | 247 } |
| 244 | 248 |
| 245 void ContentsContainer::Layout() { | 249 void ContentsContainer::Layout() { |
| 246 int content_y = active_top_margin_; | 250 int content_y = active_top_margin_; |
| 247 int content_height = std::max(0, height() - content_y); | 251 int content_height = std::max(0, height() - content_y); |
| 248 | 252 |
| 249 active_->SetBounds(0, content_y, width(), content_height); | 253 active_->SetBounds(0, content_y, width(), content_height); |
| 250 | 254 |
| 251 if (overlay_) { | 255 if (overlay_) { |
| 252 overlay_->SetBounds(0, 0, width(), | 256 int overlay_height_pixels = |
| 253 OverlayHeightInPixels(height(), overlay_height_, | 257 OverlayHeightInPixels(height(), overlay_height_, overlay_height_units_); |
| 254 overlay_height_units_)); | 258 overlay_->SetBounds(0, overlay_top_margin_, width(), overlay_height_pixels); |
| 255 if (draw_drop_shadow_) { | 259 if (draw_drop_shadow_) { |
| 256 #if !defined(OS_WIN) | 260 #if !defined(OS_WIN) |
| 257 DCHECK(shadow_view_.get() && shadow_view_->parent()); | 261 DCHECK(shadow_view_.get() && shadow_view_->parent()); |
| 258 shadow_view_->SetBounds(0, overlay_->bounds().height(), width(), | 262 shadow_view_->SetBounds(0, overlay_->bounds().bottom(), width(), |
| 259 shadow_view_->GetPreferredSize().height()); | 263 shadow_view_->GetPreferredSize().height()); |
| 260 #endif // !defined(OS_WIN) | 264 #endif // !defined(OS_WIN) |
| 261 } | 265 } |
| 262 } | 266 } |
| 263 | 267 |
| 264 // Need to invoke views::View in case any views whose bounds didn't change | 268 // Need to invoke views::View in case any views whose bounds didn't change |
| 265 // still need a layout. | 269 // still need a layout. |
| 266 views::View::Layout(); | 270 views::View::Layout(); |
| 267 } | 271 } |
| 268 | 272 |
| 269 std::string ContentsContainer::GetClassName() const { | 273 std::string ContentsContainer::GetClassName() const { |
| 270 return kViewClassName; | 274 return kViewClassName; |
| 271 } | 275 } |
| 272 | 276 |
| 273 void ContentsContainer::Observe(int type, | 277 void ContentsContainer::Observe(int type, |
| 274 const content::NotificationSource& source, | 278 const content::NotificationSource& source, |
| 275 const content::NotificationDetails& details) { | 279 const content::NotificationDetails& details) { |
| 276 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | 280 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, |
| 277 type); | 281 type); |
| 278 // Remove shadow view if it's not needed. | 282 // Remove shadow view if it's not needed. |
| 279 if (overlay_ && !draw_drop_shadow_) { | 283 if (overlay_ && !draw_drop_shadow_) { |
| 280 DCHECK(overlay_web_contents_); | 284 DCHECK(overlay_web_contents_); |
| 281 DCHECK_EQ(overlay_web_contents_->GetRenderViewHost(), | 285 DCHECK_EQ(overlay_web_contents_->GetRenderViewHost(), |
| 282 (content::Source<content::RenderWidgetHost>(source)).ptr()); | 286 (content::Source<content::RenderWidgetHost>(source)).ptr()); |
| 283 shadow_view_.reset(); | 287 shadow_view_.reset(); |
| 284 } | 288 } |
| 285 } | 289 } |
| OLD | NEW |