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" |
11 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
| 12 #include "content/public/browser/render_widget_host_view.h" |
12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
13 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
14 #include "ui/compositor/layer_animation_observer.h" | 15 #include "ui/compositor/layer_animation_observer.h" |
15 #include "ui/compositor/scoped_layer_animation_settings.h" | 16 #include "ui/compositor/scoped_layer_animation_settings.h" |
16 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/image/image_png_rep.h" | 18 #include "ui/gfx/image/image_png_rep.h" |
18 #include "ui/gfx/image/image_skia.h" | 19 #include "ui/gfx/image/image_skia.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return CreateSlideLayer(-1); | 230 return CreateSlideLayer(-1); |
230 } | 231 } |
231 | 232 |
232 ui::Layer* OverscrollNavigationOverlay::CreateFrontLayer() { | 233 ui::Layer* OverscrollNavigationOverlay::CreateFrontLayer() { |
233 if (!web_contents_->GetController().CanGoForward()) | 234 if (!web_contents_->GetController().CanGoForward()) |
234 return NULL; | 235 return NULL; |
235 slide_direction_ = SLIDE_FRONT; | 236 slide_direction_ = SLIDE_FRONT; |
236 return CreateSlideLayer(1); | 237 return CreateSlideLayer(1); |
237 } | 238 } |
238 | 239 |
239 void OverscrollNavigationOverlay::OnWindowSlideComplete() { | 240 void OverscrollNavigationOverlay::OnWindowSlideCompleting() { |
240 if (slide_direction_ == SLIDE_UNKNOWN) { | 241 if (slide_direction_ == SLIDE_UNKNOWN) |
241 window_slider_.reset(); | |
242 StopObservingIfDone(); | |
243 return; | 242 return; |
244 } | |
245 | |
246 // Change the image used for the overlay window. | |
247 image_delegate_->SetImage(layer_delegate_->image()); | |
248 window_->layer()->SetTransform(gfx::Transform()); | |
249 window_->SchedulePaintInRect(gfx::Rect(window_->bounds().size())); | |
250 | |
251 SlideDirection direction = slide_direction_; | |
252 slide_direction_ = SLIDE_UNKNOWN; | |
253 | 243 |
254 // Reset state and wait for the new navigation page to complete | 244 // Reset state and wait for the new navigation page to complete |
255 // loading/painting. | 245 // loading/painting. |
256 StartObserving(); | 246 StartObserving(); |
257 | 247 |
258 // Perform the navigation. | 248 // Perform the navigation. |
259 if (direction == SLIDE_BACK) | 249 if (slide_direction_ == SLIDE_BACK) |
260 web_contents_->GetController().GoBack(); | 250 web_contents_->GetController().GoBack(); |
261 else if (direction == SLIDE_FRONT) | 251 else if (slide_direction_ == SLIDE_FRONT) |
262 web_contents_->GetController().GoForward(); | 252 web_contents_->GetController().GoForward(); |
263 else | 253 else |
264 NOTREACHED(); | 254 NOTREACHED(); |
265 | 255 |
266 NavigationEntry* pending_entry = | 256 NavigationEntry* pending_entry = |
267 web_contents_->GetController().GetPendingEntry(); | 257 web_contents_->GetController().GetPendingEntry(); |
268 // Save id of the pending entry to identify when it loads and paints later. | 258 // Save id of the pending entry to identify when it loads and paints later. |
269 // Under some circumstances navigation can leave a null pending entry - | 259 // Under some circumstances navigation can leave a null pending entry - |
270 // see comments in NavigationControllerImpl::NavigateToPendingEntry(). | 260 // see comments in NavigationControllerImpl::NavigateToPendingEntry(). |
271 pending_entry_id_ = pending_entry ? pending_entry->GetUniqueID() : 0; | 261 pending_entry_id_ = pending_entry ? pending_entry->GetUniqueID() : 0; |
272 } | 262 } |
273 | 263 |
| 264 void OverscrollNavigationOverlay::OnWindowSlideCompleted() { |
| 265 if (slide_direction_ == SLIDE_UNKNOWN) { |
| 266 window_slider_.reset(); |
| 267 StopObservingIfDone(); |
| 268 return; |
| 269 } |
| 270 |
| 271 // Change the image used for the overlay window. |
| 272 image_delegate_->SetImage(layer_delegate_->image()); |
| 273 window_->layer()->SetTransform(gfx::Transform()); |
| 274 window_->SchedulePaintInRect(gfx::Rect(window_->bounds().size())); |
| 275 slide_direction_ = SLIDE_UNKNOWN; |
| 276 |
| 277 // Make sure the overlay layer is repainted before we dismiss it, otherwise |
| 278 // OverlayDismissAnimator may end up showing the wrong screenshot during the |
| 279 // fadeout animation. |
| 280 if (received_paint_update_ && need_paint_update_) { |
| 281 received_paint_update_ = false; |
| 282 RenderWidgetHost* host = |
| 283 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(); |
| 284 RenderViewHostImpl* view_host = |
| 285 static_cast<RenderViewHostImpl*> (RenderViewHost::From(host)); |
| 286 view_host->ScheduleComposite(); |
| 287 } else if (!need_paint_update_) { |
| 288 StopObservingIfDone(); |
| 289 } |
| 290 } |
| 291 |
274 void OverscrollNavigationOverlay::OnWindowSlideAborted() { | 292 void OverscrollNavigationOverlay::OnWindowSlideAborted() { |
275 StopObservingIfDone(); | 293 StopObservingIfDone(); |
276 } | 294 } |
277 | 295 |
278 void OverscrollNavigationOverlay::OnWindowSliderDestroyed() { | 296 void OverscrollNavigationOverlay::OnWindowSliderDestroyed() { |
279 // We only want to take an action here if WindowSlider is being destroyed | 297 // We only want to take an action here if WindowSlider is being destroyed |
280 // outside of OverscrollNavigationOverlay. If window_slider_.get() is NULL, | 298 // outside of OverscrollNavigationOverlay. If window_slider_.get() is NULL, |
281 // then OverscrollNavigationOverlay is the one destroying WindowSlider, and | 299 // then OverscrollNavigationOverlay is the one destroying WindowSlider, and |
282 // we don't need to do anything. | 300 // we don't need to do anything. |
283 // This check prevents StopObservingIfDone() being called multiple times | 301 // This check prevents StopObservingIfDone() being called multiple times |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 bool OverscrollNavigationOverlay::OnMessageReceived( | 349 bool OverscrollNavigationOverlay::OnMessageReceived( |
332 const IPC::Message& message) { | 350 const IPC::Message& message) { |
333 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 351 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
334 IPC_BEGIN_MESSAGE_MAP(OverscrollNavigationOverlay, message) | 352 IPC_BEGIN_MESSAGE_MAP(OverscrollNavigationOverlay, message) |
335 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 353 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
336 IPC_END_MESSAGE_MAP() | 354 IPC_END_MESSAGE_MAP() |
337 return false; | 355 return false; |
338 } | 356 } |
339 | 357 |
340 } // namespace content | 358 } // namespace content |
OLD | NEW |