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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 RemoveChildView(shadow_view_.get()); | 212 RemoveChildView(shadow_view_.get()); |
212 removed_shadow = true; | 213 removed_shadow = true; |
213 } | 214 } |
214 RemoveChildView(overlay_); | 215 RemoveChildView(overlay_); |
215 AddChildView(overlay_); | 216 AddChildView(overlay_); |
216 if (removed_shadow) // Add back shadow view if it was removed. | 217 if (removed_shadow) // Add back shadow view if it was removed. |
217 AddChildView(shadow_view_.get()); | 218 AddChildView(shadow_view_.get()); |
218 Layout(); | 219 Layout(); |
219 } | 220 } |
220 | 221 |
221 void ContentsContainer::SetActiveTopMargin(int margin) { | 222 bool ContentsContainer::SetActiveTopMargin(int margin) { |
222 if (active_top_margin_ == margin) | 223 if (active_top_margin_ == margin) |
223 return; | 224 return false; |
224 | 225 |
225 active_top_margin_ = margin; | 226 active_top_margin_ = margin; |
226 // 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 |
227 // haven't changed. | 228 // haven't changed. |
228 InvalidateLayout(); | 229 InvalidateLayout(); |
| 230 return true; |
| 231 } |
| 232 |
| 233 bool ContentsContainer::SetOverlayTopMargin(int margin) { |
| 234 if (overlay_top_margin_ == margin) |
| 235 return false; |
| 236 overlay_top_margin_ = margin; |
| 237 // Make sure we layout next time around. We need this in case our bounds |
| 238 // haven't changed. |
| 239 InvalidateLayout(); |
| 240 return true; |
229 } | 241 } |
230 | 242 |
231 gfx::Rect ContentsContainer::GetOverlayBounds() const { | 243 gfx::Rect ContentsContainer::GetOverlayBounds() const { |
232 gfx::Point screen_loc; | 244 gfx::Point screen_loc; |
233 ConvertPointToScreen(this, &screen_loc); | 245 ConvertPointToScreen(this, &screen_loc); |
234 return gfx::Rect(screen_loc, size()); | 246 return gfx::Rect(screen_loc, size()); |
235 } | 247 } |
236 | 248 |
237 bool ContentsContainer::WillOverlayBeFullHeight( | 249 bool ContentsContainer::WillOverlayBeFullHeight( |
238 int overlay_height, | 250 int overlay_height, |
239 InstantSizeUnits overlay_height_units) const { | 251 InstantSizeUnits overlay_height_units) const { |
240 int height_in_pixels = OverlayHeightInPixels(height(), overlay_height, | 252 int height_in_pixels = OverlayHeightInPixels(height(), overlay_height, |
241 overlay_height_units); | 253 overlay_height_units); |
242 return height_in_pixels == height(); | 254 return height_in_pixels == height(); |
243 } | 255 } |
244 | 256 |
245 bool ContentsContainer::IsOverlayFullHeight() const { | 257 bool ContentsContainer::IsOverlayFullHeight() const { |
246 return overlay_ && overlay_height_ == 100 && | 258 return overlay_ && overlay_height_ == 100 && |
247 overlay_height_units_ == INSTANT_SIZE_PERCENT; | 259 overlay_height_units_ == INSTANT_SIZE_PERCENT; |
248 } | 260 } |
249 | 261 |
250 void ContentsContainer::Layout() { | 262 void ContentsContainer::Layout() { |
251 int content_y = active_top_margin_; | 263 int content_y = active_top_margin_; |
252 int content_height = std::max(0, height() - content_y); | 264 int content_height = std::max(0, height() - content_y); |
253 | 265 |
254 active_->SetBounds(0, content_y, width(), content_height); | 266 active_->SetBounds(0, content_y, width(), content_height); |
255 | 267 |
256 if (overlay_) { | 268 if (overlay_) { |
257 overlay_->SetBounds(0, 0, width(), | 269 int target_overlay_height = |
258 OverlayHeightInPixels(height(), overlay_height_, | 270 OverlayHeightInPixels(height(), overlay_height_, overlay_height_units_); |
259 overlay_height_units_)); | 271 // Ensure the overlay doesn't extend outside this container view. |
| 272 int overlay_height = |
| 273 std::min(height() - overlay_top_margin_, target_overlay_height); |
| 274 overlay_->SetBounds(0, overlay_top_margin_, |
| 275 width(), std::max(0, overlay_height)); |
260 if (draw_drop_shadow_) { | 276 if (draw_drop_shadow_) { |
261 #if !defined(OS_WIN) | 277 #if !defined(OS_WIN) |
262 DCHECK(shadow_view_.get() && shadow_view_->parent()); | 278 DCHECK(shadow_view_.get() && shadow_view_->parent()); |
263 shadow_view_->SetBounds(0, overlay_->bounds().height(), width(), | 279 shadow_view_->SetBounds(0, overlay_->bounds().bottom(), width(), |
264 shadow_view_->GetPreferredSize().height()); | 280 shadow_view_->GetPreferredSize().height()); |
265 #endif // !defined(OS_WIN) | 281 #endif // !defined(OS_WIN) |
266 } | 282 } |
267 } | 283 } |
268 | 284 |
269 // Need to invoke views::View in case any views whose bounds didn't change | 285 // Need to invoke views::View in case any views whose bounds didn't change |
270 // still need a layout. | 286 // still need a layout. |
271 views::View::Layout(); | 287 views::View::Layout(); |
272 } | 288 } |
273 | 289 |
274 std::string ContentsContainer::GetClassName() const { | 290 std::string ContentsContainer::GetClassName() const { |
275 return kViewClassName; | 291 return kViewClassName; |
276 } | 292 } |
277 | 293 |
278 void ContentsContainer::Observe(int type, | 294 void ContentsContainer::Observe(int type, |
279 const content::NotificationSource& source, | 295 const content::NotificationSource& source, |
280 const content::NotificationDetails& details) { | 296 const content::NotificationDetails& details) { |
281 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | 297 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, |
282 type); | 298 type); |
283 // Remove shadow view if it's not needed. | 299 // Remove shadow view if it's not needed. |
284 if (overlay_ && !draw_drop_shadow_) { | 300 if (overlay_ && !draw_drop_shadow_) { |
285 DCHECK(overlay_web_contents_); | 301 DCHECK(overlay_web_contents_); |
286 DCHECK_EQ(overlay_web_contents_->GetRenderViewHost(), | 302 DCHECK_EQ(overlay_web_contents_->GetRenderViewHost(), |
287 (content::Source<content::RenderWidgetHost>(source)).ptr()); | 303 (content::Source<content::RenderWidgetHost>(source)).ptr()); |
288 shadow_view_.reset(); | 304 shadow_view_.reset(); |
289 } | 305 } |
290 } | 306 } |
OLD | NEW |