| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/web_contents/aura/overscroll_navigation_overlay.h" | 5 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" |
| 6 | 6 |
| 7 #include "content/browser/frame_host/navigation_entry_impl.h" | 7 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 9 #include "content/browser/web_contents/aura/image_window_delegate.h" | 9 #include "content/browser/web_contents/aura/image_window_delegate.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 scoped_ptr<ui::Layer> layer_; | 106 scoped_ptr<ui::Layer> layer_; |
| 107 | 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); | 108 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 OverscrollNavigationOverlay::OverscrollNavigationOverlay( | 111 OverscrollNavigationOverlay::OverscrollNavigationOverlay( |
| 112 WebContentsImpl* web_contents) | 112 WebContentsImpl* web_contents) |
| 113 : web_contents_(web_contents), | 113 : web_contents_(web_contents), |
| 114 image_delegate_(NULL), | 114 image_delegate_(NULL), |
| 115 loading_complete_(false), | |
| 116 received_paint_update_(false), | 115 received_paint_update_(false), |
| 117 pending_entry_id_(0), | 116 pending_entry_id_(0), |
| 118 slide_direction_(SLIDE_UNKNOWN), | 117 slide_direction_(SLIDE_UNKNOWN), |
| 119 need_paint_update_(true) { | 118 need_paint_update_(true) { |
| 120 } | 119 } |
| 121 | 120 |
| 122 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() { | 121 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() { |
| 123 } | 122 } |
| 124 | 123 |
| 125 void OverscrollNavigationOverlay::StartObserving() { | 124 void OverscrollNavigationOverlay::StartObserving() { |
| 126 loading_complete_ = false; | |
| 127 received_paint_update_ = false; | 125 received_paint_update_ = false; |
| 128 pending_entry_id_ = 0; | 126 pending_entry_id_ = 0; |
| 129 Observe(web_contents_); | 127 Observe(web_contents_); |
| 130 | 128 |
| 131 // Make sure the overlay window is on top. | 129 // Make sure the overlay window is on top. |
| 132 if (window_.get() && window_->parent()) | 130 if (window_.get() && window_->parent()) |
| 133 window_->parent()->StackChildAtTop(window_.get()); | 131 window_->parent()->StackChildAtTop(window_.get()); |
| 134 | 132 |
| 135 // Assumes the navigation has been initiated. | 133 // Assumes the navigation has been initiated. |
| 136 NavigationEntry* pending_entry = | 134 NavigationEntry* pending_entry = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 199 } |
| 202 if (!layer_delegate_) | 200 if (!layer_delegate_) |
| 203 layer_delegate_.reset(new ImageLayerDelegate()); | 201 layer_delegate_.reset(new ImageLayerDelegate()); |
| 204 layer_delegate_->SetImage(image); | 202 layer_delegate_->SetImage(image); |
| 205 | 203 |
| 206 ui::Layer* layer = new ui::Layer(ui::LAYER_TEXTURED); | 204 ui::Layer* layer = new ui::Layer(ui::LAYER_TEXTURED); |
| 207 layer->set_delegate(layer_delegate_.get()); | 205 layer->set_delegate(layer_delegate_.get()); |
| 208 return layer; | 206 return layer; |
| 209 } | 207 } |
| 210 | 208 |
| 211 void OverscrollNavigationOverlay::OnUpdateRect( | |
| 212 const ViewHostMsg_UpdateRect_Params& params) { | |
| 213 if (loading_complete_ && | |
| 214 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags)) { | |
| 215 NavigationEntry* visible_entry = | |
| 216 web_contents_->GetController().GetVisibleEntry(); | |
| 217 int visible_entry_id = visible_entry ? visible_entry->GetUniqueID() : 0; | |
| 218 if (visible_entry_id == pending_entry_id_ || !pending_entry_id_) { | |
| 219 // This is a paint update after the page has been loaded. So do not wait | |
| 220 // for a 'first non-empty' paint update. | |
| 221 received_paint_update_ = true; | |
| 222 StopObservingIfDone(); | |
| 223 } | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 ui::Layer* OverscrollNavigationOverlay::CreateBackLayer() { | 209 ui::Layer* OverscrollNavigationOverlay::CreateBackLayer() { |
| 228 if (!web_contents_->GetController().CanGoBack()) | 210 if (!web_contents_->GetController().CanGoBack()) |
| 229 return NULL; | 211 return NULL; |
| 230 slide_direction_ = SLIDE_BACK; | 212 slide_direction_ = SLIDE_BACK; |
| 231 return CreateSlideLayer(-1); | 213 return CreateSlideLayer(-1); |
| 232 } | 214 } |
| 233 | 215 |
| 234 ui::Layer* OverscrollNavigationOverlay::CreateFrontLayer() { | 216 ui::Layer* OverscrollNavigationOverlay::CreateFrontLayer() { |
| 235 if (!web_contents_->GetController().CanGoForward()) | 217 if (!web_contents_->GetController().CanGoForward()) |
| 236 return NULL; | 218 return NULL; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // we don't need to do anything. | 276 // we don't need to do anything. |
| 295 // This check prevents StopObservingIfDone() being called multiple times | 277 // This check prevents StopObservingIfDone() being called multiple times |
| 296 // (including recursively) for a single event. | 278 // (including recursively) for a single event. |
| 297 if (window_slider_.get()) { | 279 if (window_slider_.get()) { |
| 298 // The slider has just been destroyed. Release the ownership. | 280 // The slider has just been destroyed. Release the ownership. |
| 299 WindowSlider* slider ALLOW_UNUSED = window_slider_.release(); | 281 WindowSlider* slider ALLOW_UNUSED = window_slider_.release(); |
| 300 StopObservingIfDone(); | 282 StopObservingIfDone(); |
| 301 } | 283 } |
| 302 } | 284 } |
| 303 | 285 |
| 304 void OverscrollNavigationOverlay::DocumentOnLoadCompletedInMainFrame() { | |
| 305 // Use the last committed entry rather than the active one, in case a | |
| 306 // pending entry has been created. | |
| 307 int committed_entry_id = | |
| 308 web_contents_->GetController().GetLastCommittedEntry()->GetUniqueID(); | |
| 309 // Consider the loading completed once the main frame has loaded. | |
| 310 if (committed_entry_id == pending_entry_id_ || !pending_entry_id_) { | |
| 311 loading_complete_ = true; | |
| 312 StopObservingIfDone(); | |
| 313 } | |
| 314 } | |
| 315 | |
| 316 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { | 286 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { |
| 317 int visible_entry_id = | 287 int visible_entry_id = |
| 318 web_contents_->GetController().GetVisibleEntry()->GetUniqueID(); | 288 web_contents_->GetController().GetVisibleEntry()->GetUniqueID(); |
| 319 if (visible_entry_id == pending_entry_id_ || !pending_entry_id_) { | 289 if (visible_entry_id == pending_entry_id_ || !pending_entry_id_) { |
| 320 received_paint_update_ = true; | 290 received_paint_update_ = true; |
| 321 StopObservingIfDone(); | 291 StopObservingIfDone(); |
| 322 } | 292 } |
| 323 } | 293 } |
| 324 | 294 |
| 325 void OverscrollNavigationOverlay::DidStopLoading(RenderViewHost* host) { | |
| 326 // Use the last committed entry rather than the active one, in case a | |
| 327 // pending entry has been created. | |
| 328 int committed_entry_id = | |
| 329 web_contents_->GetController().GetLastCommittedEntry()->GetUniqueID(); | |
| 330 if (committed_entry_id == pending_entry_id_ || !pending_entry_id_) { | |
| 331 loading_complete_ = true; | |
| 332 if (!received_paint_update_ && need_paint_update_) { | |
| 333 // Force a repaint after the page is loaded. | |
| 334 RenderViewHostImpl* view = static_cast<RenderViewHostImpl*>(host); | |
| 335 view->ScheduleComposite(); | |
| 336 } | |
| 337 StopObservingIfDone(); | |
| 338 } | |
| 339 } | |
| 340 | |
| 341 bool OverscrollNavigationOverlay::OnMessageReceived( | |
| 342 const IPC::Message& message) { | |
| 343 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 344 IPC_BEGIN_MESSAGE_MAP(OverscrollNavigationOverlay, message) | |
| 345 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | |
| 346 IPC_END_MESSAGE_MAP() | |
| 347 return false; | |
| 348 } | |
| 349 | |
| 350 } // namespace content | 295 } // namespace content |
| OLD | NEW |