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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 gfx::ImageSkia drop_shadow_; | 74 gfx::ImageSkia drop_shadow_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(ShadowView); | 76 DISALLOW_COPY_AND_ASSIGN(ShadowView); |
77 }; | 77 }; |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 ContentsContainer::ContentsContainer(views::WebView* active) | 81 ContentsContainer::ContentsContainer(views::WebView* active, |
| 82 views::View* browser_view) |
82 : active_(active), | 83 : active_(active), |
| 84 browser_view_(browser_view), |
83 overlay_(NULL), | 85 overlay_(NULL), |
84 overlay_web_contents_(NULL), | 86 overlay_web_contents_(NULL), |
85 draw_drop_shadow_(false), | 87 draw_drop_shadow_(false), |
86 active_top_margin_(0), | 88 active_top_margin_(0), |
87 overlay_height_(100), | 89 overlay_height_(100), |
88 overlay_height_units_(INSTANT_SIZE_PERCENT) { | 90 overlay_height_units_(INSTANT_SIZE_PERCENT) { |
89 AddChildView(active_); | 91 AddChildView(active_); |
90 } | 92 } |
91 | 93 |
92 ContentsContainer::~ContentsContainer() { | 94 ContentsContainer::~ContentsContainer() { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 content::NotificationSource source = | 164 content::NotificationSource source = |
163 content::Source<content::RenderWidgetHost>(rvh); | 165 content::Source<content::RenderWidgetHost>(rvh); |
164 registrar_.Add(this, | 166 registrar_.Add(this, |
165 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | 167 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, |
166 source); | 168 source); |
167 } | 169 } |
168 } | 170 } |
169 #endif // !defined(OS_WIN) | 171 #endif // !defined(OS_WIN) |
170 } | 172 } |
171 | 173 |
| 174 // If |overlay_|'s height has shrunk and |active_top_margin_| was used to |
| 175 // preserve |active_|'s origin in BrowserViewLayout::Layout(), we need to re- |
| 176 // determine if its origin still needs to be preserved. The origin is |
| 177 // preserved if overlay is taller than total height of hidden bookmark and |
| 178 // info bars. In this case, force a re-layout of BrowserView. |
| 179 bool layout_browser_view = false; |
| 180 if (overlay_ && active_top_margin_ > 0 && units == INSTANT_SIZE_PIXELS && |
| 181 height > 0 && height < overlay_height_) { |
| 182 layout_browser_view = true; |
| 183 } |
| 184 |
172 overlay_height_ = height; | 185 overlay_height_ = height; |
173 overlay_height_units_ = units; | 186 overlay_height_units_ = units; |
174 draw_drop_shadow_ = draw_drop_shadow; | 187 draw_drop_shadow_ = draw_drop_shadow; |
175 | 188 |
176 // Add shadow view if there's overlay and drop shadow is needed. | 189 // Add shadow view if there's overlay and drop shadow is needed. |
177 // Remove shadow view if there's no overlay. | 190 // Remove shadow view if there's no overlay. |
178 // If there's overlay and drop shadow is not needed, that means the partial- | 191 // If there's overlay and drop shadow is not needed, that means the partial- |
179 // height overlay is going to be full-height. Don't remove the shadow view | 192 // height overlay is going to be full-height. Don't remove the shadow view |
180 // yet because its view will disappear noticeably faster than the webview-ed | 193 // yet because its view will disappear noticeably faster than the webview-ed |
181 // overlay is repainted at the full height - when resizing web contents page, | 194 // overlay is repainted at the full height - when resizing web contents page, |
182 // RenderWidgetHostViewAura locks the compositor until texture is updated or | 195 // RenderWidgetHostViewAura locks the compositor until texture is updated or |
183 // timeout occurs. This out-of-sync refresh results in a split second where | 196 // timeout occurs. This out-of-sync refresh results in a split second where |
184 // there's no separator between the overlay and active contents, making the | 197 // there's no separator between the overlay and active contents, making the |
185 // overlay contents erroneously appear to be part of active contents. | 198 // overlay contents erroneously appear to be part of active contents. |
186 // When the overlay is repainted at the full height, we'll be notified via | 199 // When the overlay is repainted at the full height, we'll be notified via |
187 // NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKGING_STORE, at which time | 200 // NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKGING_STORE, at which time |
188 // the shadow view will be removed. | 201 // the shadow view will be removed. |
189 if (overlay_ && draw_drop_shadow_) { | 202 if (overlay_ && draw_drop_shadow_) { |
190 #if !defined(OS_WIN) | 203 #if !defined(OS_WIN) |
191 if (!shadow_view_.get()) // Shadow view has not been created. | 204 if (!shadow_view_.get()) // Shadow view has not been created. |
192 shadow_view_.reset(new ShadowView()); | 205 shadow_view_.reset(new ShadowView()); |
193 if (!shadow_view_->parent()) // Shadow view has not been added. | 206 if (!shadow_view_->parent()) // Shadow view has not been added. |
194 AddChildView(shadow_view_.get()); | 207 AddChildView(shadow_view_.get()); |
195 #endif // !defined(OS_WIN) | 208 #endif // !defined(OS_WIN) |
196 } else if (!overlay_) { | 209 } else if (!overlay_) { |
197 shadow_view_.reset(); | 210 shadow_view_.reset(); |
198 } | 211 } |
199 | 212 |
200 Layout(); | 213 if (layout_browser_view) |
| 214 browser_view_->Layout(); // This will trigger |this| Layout. |
| 215 else |
| 216 Layout(); |
201 } | 217 } |
202 | 218 |
203 void ContentsContainer::MaybeStackOverlayAtTop() { | 219 void ContentsContainer::MaybeStackOverlayAtTop() { |
204 if (!overlay_) | 220 if (!overlay_) |
205 return; | 221 return; |
206 // To force |overlay_| to the topmost in the z-order, remove it, then add it | 222 // To force |overlay_| to the topmost in the z-order, remove it, then add it |
207 // back. | 223 // back. |
208 // See comments in SetOverlay() for why shadow view is removed. | 224 // See comments in SetOverlay() for why shadow view is removed. |
209 bool removed_shadow = false; | 225 bool removed_shadow = false; |
210 if (shadow_view_.get()) { | 226 if (shadow_view_.get()) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |