| 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_height_(100), | 87 overlay_height_(0), |
| 88 overlay_height_units_(INSTANT_SIZE_PERCENT) { | 88 overlay_height_units_(INSTANT_SIZE_PIXELS) { |
| 89 AddChildView(active_); | 89 AddChildView(active_); |
| 90 } | 90 } |
| 91 | 91 |
| 92 ContentsContainer::~ContentsContainer() { | 92 ContentsContainer::~ContentsContainer() { |
| 93 } | 93 } |
| 94 | 94 |
| 95 void ContentsContainer::MakeOverlayContentsActiveContents() { | 95 void ContentsContainer::MakeOverlayContentsActiveContents() { |
| 96 DCHECK(overlay_); | 96 DCHECK(overlay_); |
| 97 | 97 |
| 98 active_ = overlay_; | 98 active_ = overlay_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 116 // overlay. | 116 // overlay. |
| 117 // TODO(kuan): remove this when GWS gives chrome the height without the | 117 // TODO(kuan): remove this when GWS gives chrome the height without the |
| 118 // separator. | 118 // separator. |
| 119 #if !defined(OS_WIN) | 119 #if !defined(OS_WIN) |
| 120 if (draw_drop_shadow) | 120 if (draw_drop_shadow) |
| 121 --height; | 121 --height; |
| 122 #endif // !defined(OS_WIN) | 122 #endif // !defined(OS_WIN) |
| 123 | 123 |
| 124 if (overlay_ == overlay && overlay_web_contents_ == overlay_web_contents && | 124 if (overlay_ == overlay && overlay_web_contents_ == overlay_web_contents && |
| 125 overlay_height_ == height && overlay_height_units_ == units && | 125 overlay_height_ == height && overlay_height_units_ == units && |
| 126 draw_drop_shadow_ == draw_drop_shadow) { | 126 draw_drop_shadow_ == draw_drop_shadow) |
| 127 return; | 127 return; |
| 128 } | |
| 129 | 128 |
| 130 if (overlay_ != overlay) { | 129 if (overlay_ != overlay) { |
| 131 if (overlay_) { | 130 if (overlay_) { |
| 132 // Order of children is important: always |active_| first, then | 131 // Order of children is important: always |active_| first, then |
| 133 // |overlay_|, then shadow view if necessary. To make sure the next view | 132 // |overlay_|, then shadow view if necessary. To make sure the next view |
| 134 // is added in the right order, remove shadow view every time |overlay_| | 133 // is added in the right order, remove shadow view every time |overlay_| |
| 135 // is removed. Don't nuke the shadow view now in case it's needed below | 134 // is removed. Don't nuke the shadow view now in case it's needed below |
| 136 // when we handle |draw_drop_shadow|. | 135 // when we handle |draw_drop_shadow|. |
| 137 if (shadow_view_.get()) | 136 if (shadow_view_.get()) |
| 138 RemoveChildView(shadow_view_.get()); | 137 RemoveChildView(shadow_view_.get()); |
| 139 RemoveChildView(overlay_); | 138 RemoveChildView(overlay_); |
| 140 } | 139 } |
| 141 overlay_ = overlay; | 140 overlay_ = overlay; |
| 142 if (overlay_) | 141 if (overlay_) |
| 143 AddChildView(overlay_); | 142 AddChildView(overlay_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 166 #endif // !defined(OS_WIN) | 165 #endif // !defined(OS_WIN) |
| 167 } | 166 } |
| 168 | 167 |
| 169 overlay_height_ = height; | 168 overlay_height_ = height; |
| 170 overlay_height_units_ = units; | 169 overlay_height_units_ = units; |
| 171 draw_drop_shadow_ = draw_drop_shadow; | 170 draw_drop_shadow_ = draw_drop_shadow; |
| 172 | 171 |
| 173 // Add shadow view if there's overlay and drop shadow is needed. | 172 // Add shadow view if there's overlay and drop shadow is needed. |
| 174 // Remove shadow view if there's no overlay. | 173 // Remove shadow view if there's no overlay. |
| 175 // If there's overlay and drop shadow is not needed, that means the partial- | 174 // If there's overlay and drop shadow is not needed, that means the partial- |
| 176 // height overlay is going to be full-height. Don't remove the shadow view | 175 // height overlay is going to be full-height. Don't remove the shadow view yet |
| 177 // yet because its view will disappear noticeably faster than the webview-ed | 176 // because its view will disappear noticeably faster than the webview-ed |
| 178 // overlay is repainted at the full height - when resizing web contents page, | 177 // overlay is repainted at the full height - when resizing web contents page, |
| 179 // RenderWidgetHostViewAura locks the compositor until texture is updated or | 178 // RenderWidgetHostViewAura locks the compositor until texture is updated or |
| 180 // timeout occurs. This out-of-sync refresh results in a split second where | 179 // timeout occurs. This out-of-sync refresh results in a split second where |
| 181 // there's no separator between the overlay and active contents, making the | 180 // there's no separator between the overlay and active contents, making the |
| 182 // overlay contents erroneously appear to be part of active contents. | 181 // overlay contents erroneously appear to be part of active contents. When the |
| 183 // When the overlay is repainted at the full height, we'll be notified via | 182 // overlay is repainted at the full height, we'll be notified via |
| 184 // NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKGING_STORE, at which time | 183 // NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, at which time the |
| 185 // the shadow view will be removed. | 184 // shadow view will be removed. |
| 186 if (overlay_ && draw_drop_shadow_) { | 185 if (overlay_ && draw_drop_shadow_) { |
| 187 #if !defined(OS_WIN) | 186 #if !defined(OS_WIN) |
| 188 if (!shadow_view_.get()) // Shadow view has not been created. | 187 if (!shadow_view_.get()) // Shadow view has not been created. |
| 189 shadow_view_.reset(new ShadowView()); | 188 shadow_view_.reset(new ShadowView()); |
| 190 if (!shadow_view_->parent()) // Shadow view has not been added. | 189 if (!shadow_view_->parent()) // Shadow view has not been added. |
| 191 AddChildView(shadow_view_.get()); | 190 AddChildView(shadow_view_.get()); |
| 192 #endif // !defined(OS_WIN) | 191 #endif // !defined(OS_WIN) |
| 193 } else if (!overlay_) { | 192 } else if (!overlay_) { |
| 194 shadow_view_.reset(); | 193 shadow_view_.reset(); |
| 195 } | 194 } |
| 196 | 195 |
| 197 Layout(); | 196 Layout(); |
| 198 } | 197 } |
| 199 | 198 |
| 200 void ContentsContainer::MaybeStackOverlayAtTop() { | |
| 201 if (!overlay_) | |
| 202 return; | |
| 203 // To force |overlay_| to the topmost in the z-order, remove it, then add it | |
| 204 // back. | |
| 205 // See comments in SetOverlay() for why shadow view is removed. | |
| 206 bool removed_shadow = false; | |
| 207 if (shadow_view_.get()) { | |
| 208 RemoveChildView(shadow_view_.get()); | |
| 209 removed_shadow = true; | |
| 210 } | |
| 211 RemoveChildView(overlay_); | |
| 212 AddChildView(overlay_); | |
| 213 if (removed_shadow) // Add back shadow view if it was removed. | |
| 214 AddChildView(shadow_view_.get()); | |
| 215 Layout(); | |
| 216 } | |
| 217 | |
| 218 void ContentsContainer::SetActiveTopMargin(int margin) { | 199 void ContentsContainer::SetActiveTopMargin(int margin) { |
| 219 if (active_top_margin_ == margin) | 200 if (active_top_margin_ == margin) |
| 220 return; | 201 return; |
| 221 | 202 |
| 222 active_top_margin_ = margin; | 203 active_top_margin_ = margin; |
| 223 // Make sure we layout next time around. We need this in case our bounds | 204 // Make sure we layout next time around. We need this in case our bounds |
| 224 // haven't changed. | 205 // haven't changed. |
| 225 InvalidateLayout(); | 206 InvalidateLayout(); |
| 226 } | 207 } |
| 227 | 208 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 250 |
| 270 void ContentsContainer::Observe(int type, | 251 void ContentsContainer::Observe(int type, |
| 271 const content::NotificationSource& source, | 252 const content::NotificationSource& source, |
| 272 const content::NotificationDetails& details) { | 253 const content::NotificationDetails& details) { |
| 273 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | 254 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, |
| 274 type); | 255 type); |
| 275 // Remove shadow view if it's not needed. | 256 // Remove shadow view if it's not needed. |
| 276 if (overlay_ && !draw_drop_shadow_) | 257 if (overlay_ && !draw_drop_shadow_) |
| 277 shadow_view_.reset(); | 258 shadow_view_.reset(); |
| 278 } | 259 } |
| OLD | NEW |