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/overscroll_window_delegate.h" |
| 10 #include "content/browser/web_contents/aura/shadow_layer_delegate.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 11 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/common/view_messages.h" | 12 #include "content/common/view_messages.h" |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/render_widget_host_view.h" | 14 #include "content/public/browser/render_widget_host_view.h" |
13 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
14 #include "ui/aura_extra/image_window_delegate.h" | 16 #include "ui/aura_extra/image_window_delegate.h" |
15 #include "ui/base/layout.h" | 17 #include "ui/base/layout.h" |
16 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
17 #include "ui/compositor/layer_animation_observer.h" | 19 #include "ui/compositor/layer_animation_observer.h" |
18 #include "ui/compositor/scoped_layer_animation_settings.h" | 20 #include "ui/compositor/scoped_layer_animation_settings.h" |
19 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
20 #include "ui/gfx/image/image_png_rep.h" | 22 #include "ui/gfx/image/image_png_rep.h" |
21 #include "ui/gfx/image/image_skia.h" | |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 namespace { | 25 namespace { |
25 | 26 |
26 // Returns true if the entry's URL or any of the URLs in entry's redirect chain | 27 // Returns true if the entry's URL or any of the URLs in entry's redirect chain |
27 // match |url|. | 28 // match |url|. |
28 bool DoesEntryMatchURL(NavigationEntry* entry, const GURL& url) { | 29 bool DoesEntryMatchURL(NavigationEntry* entry, const GURL& url) { |
29 if (!entry) | 30 if (!entry) |
30 return false; | 31 return false; |
31 if (entry->GetURL() == url) | 32 if (entry->GetURL() == url) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 124 |
124 private: | 125 private: |
125 ~OverlayDismissAnimator() override {} | 126 ~OverlayDismissAnimator() override {} |
126 | 127 |
127 scoped_ptr<ui::Layer> layer_; | 128 scoped_ptr<ui::Layer> layer_; |
128 | 129 |
129 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); | 130 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); |
130 }; | 131 }; |
131 | 132 |
132 OverscrollNavigationOverlay::OverscrollNavigationOverlay( | 133 OverscrollNavigationOverlay::OverscrollNavigationOverlay( |
133 WebContentsImpl* web_contents) | 134 WebContentsImpl* web_contents, |
134 : web_contents_(web_contents), | 135 WebContentsViewAura* wcva, |
| 136 aura::Window* web_contents_window) |
| 137 : direction_(OverscrollWindowAnimation::NONE), |
| 138 web_contents_(web_contents), |
135 image_delegate_(NULL), | 139 image_delegate_(NULL), |
136 loading_complete_(false), | 140 loading_complete_(false), |
137 received_paint_update_(false), | 141 received_paint_update_(false), |
138 slide_direction_(SLIDE_UNKNOWN) { | 142 wcva_(wcva), |
| 143 web_contents_window_(web_contents_window) { |
139 } | 144 } |
140 | 145 |
141 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() { | 146 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() { |
142 } | 147 } |
143 | 148 |
144 void OverscrollNavigationOverlay::StartObserving() { | 149 void OverscrollNavigationOverlay::StartObserving() { |
145 loading_complete_ = false; | 150 LOG(ERROR) << "Starting to observe"; |
| 151 /*loading_complete_ = false; |
146 received_paint_update_ = false; | 152 received_paint_update_ = false; |
147 overlay_dismiss_layer_.reset(); | 153 overlay_dismiss_layer_.reset();*/ |
148 Observe(web_contents_); | 154 Observe(web_contents_); |
149 | 155 |
150 // Make sure the overlay window is on top. | 156 /*// Make sure the overlay window is on top. |
151 if (window_.get() && window_->parent()) | 157 if (window_.get() && window_->parent()) |
152 window_->parent()->StackChildAtTop(window_.get()); | 158 window_->parent()->StackChildAtTop(window_.get());*/ |
153 | 159 |
154 // Assumes the navigation has been initiated. | 160 // Assumes the navigation has been initiated. |
155 NavigationEntry* pending_entry = | 161 NavigationEntry* pending_entry = |
156 web_contents_->GetController().GetPendingEntry(); | 162 web_contents_->GetController().GetPendingEntry(); |
157 // Save url of the pending entry to identify when it loads and paints later. | 163 // Save url of the pending entry to identify when it loads and paints later. |
158 // Under some circumstances navigation can leave a null pending entry - | 164 // Under some circumstances navigation can leave a null pending entry - |
159 // see comments in NavigationControllerImpl::NavigateToPendingEntry(). | 165 // see comments in NavigationControllerImpl::NavigateToPendingEntry(). |
160 pending_entry_url_ = pending_entry ? pending_entry->GetURL() : GURL(); | 166 pending_entry_url_ = pending_entry ? pending_entry->GetURL() : GURL(); |
| 167 LOG(ERROR) << "URL: " << pending_entry_url_.GetContent(); |
161 } | 168 } |
162 | 169 |
163 void OverscrollNavigationOverlay::SetOverlayWindow( | 170 void OverscrollNavigationOverlay::SetOverlayWindow( |
164 scoped_ptr<aura::Window> window, | 171 scoped_ptr<aura::Window> window, |
165 aura_extra::ImageWindowDelegate* delegate) { | 172 aura_extra::ImageWindowDelegate* delegate) { |
166 window_ = window.Pass(); | 173 LOG(ERROR) << "Setting overlay window"; |
| 174 /*window_ = window.Pass(); |
167 if (window_.get() && window_->parent()) | 175 if (window_.get() && window_->parent()) |
168 window_->parent()->StackChildAtTop(window_.get()); | 176 window_->parent()->StackChildAtTop(window_.get()); |
169 image_delegate_ = delegate; | 177 image_delegate_ = delegate; |
170 | 178 |
171 if (window_.get() && delegate->has_image()) { | 179 if (window_.get() && delegate->has_image()) { |
172 window_slider_.reset(new WindowSlider(this, | 180 window_slider_.reset(new WindowSlider(this, |
173 window_->parent(), | 181 window_->parent(), |
174 window_.get())); | 182 window_.get())); |
175 slide_direction_ = SLIDE_UNKNOWN; | 183 slide_direction_ = SLIDE_UNKNOWN; |
176 } else { | 184 } else { |
177 window_slider_.reset(); | 185 window_slider_.reset(); |
| 186 }*/ |
| 187 } |
| 188 |
| 189 const gfx::Image OverscrollNavigationOverlay::GetImageForDirection( |
| 190 OverscrollWindowAnimation::Direction direction) { |
| 191 const NavigationControllerImpl& controller = web_contents_->GetController(); |
| 192 const NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( |
| 193 controller.GetEntryAtOffset( |
| 194 direction == OverscrollWindowAnimation::FORWARD ? 1 : -1)); |
| 195 |
| 196 if (entry && entry->screenshot().get()) { |
| 197 std::vector<gfx::ImagePNGRep> image_reps; |
| 198 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f)); |
| 199 return gfx::Image(image_reps); |
178 } | 200 } |
| 201 return gfx::Image(); |
| 202 } |
| 203 |
| 204 OverscrollWindowAnimation::Direction |
| 205 OverscrollNavigationOverlay::StartNavigation(OverscrollMode mode) { |
| 206 return OverscrollWindowAnimation::NONE; |
| 207 } |
| 208 |
| 209 void OverscrollNavigationOverlay::SetTransform( |
| 210 const gfx::Transform& transform) { |
| 211 |
| 212 } |
| 213 |
| 214 ui::LayerAnimator* OverscrollNavigationOverlay::GetAnimator() { |
| 215 return nullptr; |
| 216 } |
| 217 |
| 218 gfx::Rect OverscrollNavigationOverlay::GetContentsBounds() const { |
| 219 return gfx::Rect(); |
| 220 } |
| 221 |
| 222 void OverscrollNavigationOverlay::OnAnimationCompleted() { |
| 223 |
| 224 } |
| 225 |
| 226 void OverscrollNavigationOverlay::OnAnimationCompleting() { |
| 227 |
| 228 } |
| 229 |
| 230 void OverscrollNavigationOverlay::FadeOutOverscrollWindow() { |
| 231 LOG(ERROR) << "FadeOutOverscrollWindow"; |
| 232 // TODO maybe we do not need this check. |
| 233 if (!window_) |
| 234 return; |
| 235 aura::Window* contents = web_contents_->GetContentNativeView(); |
| 236 contents->layer()->SetLayerBrightness(1.f); |
| 237 { |
| 238 ui::ScopedLayerAnimationSettings settings(contents->layer()->GetAnimator()); |
| 239 settings.SetPreemptionStrategy( |
| 240 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 241 settings.SetTweenType(gfx::Tween::EASE_OUT); |
| 242 contents->layer()->SetLayerBrightness(0.f); |
| 243 } |
| 244 scoped_ptr<ui::Layer> dismiss_layer = window_->AcquireLayer(); |
| 245 window_.reset(); |
| 246 (new OverlayDismissAnimator(dismiss_layer.Pass()))->Animate(); |
| 247 // TODO delete shadow when the dismiss animation finishes? |
| 248 shadow_.reset(); |
179 } | 249 } |
180 | 250 |
181 void OverscrollNavigationOverlay::StopObservingIfDone() { | 251 void OverscrollNavigationOverlay::StopObservingIfDone() { |
| 252 LOG(ERROR) << "Stop observing if done"; |
182 // Normally we dismiss the overlay once we receive a paint update, however | 253 // Normally we dismiss the overlay once we receive a paint update, however |
183 // for in-page navigations DidFirstVisuallyNonEmptyPaint() does not get | 254 // for in-page navigations DidFirstVisuallyNonEmptyPaint() does not get |
184 // called, and we rely on loading_complete_ for those cases. | 255 // called, and we rely on loading_complete_ for those cases. |
185 if (!received_paint_update_ && !loading_complete_) | 256 if (!received_paint_update_ && !loading_complete_) |
186 return; | 257 return; |
187 | 258 |
188 // If a slide is in progress, then do not destroy the window or the slide. | 259 if (owa_->IsSlideInProgress()) |
189 if (window_slider_.get() && window_slider_->IsSlideInProgress()) | |
190 return; | 260 return; |
191 | 261 |
192 // The layer to be animated by OverlayDismissAnimator | 262 // The layer to be animated by OverlayDismissAnimator |
193 scoped_ptr<ui::Layer> overlay_dismiss_layer; | 263 scoped_ptr<ui::Layer> overlay_dismiss_layer; |
194 if (overlay_dismiss_layer_) | 264 if (overlay_dismiss_layer_) |
195 overlay_dismiss_layer = overlay_dismiss_layer_.Pass(); | 265 overlay_dismiss_layer = overlay_dismiss_layer_.Pass(); |
196 else if (window_.get()) | 266 else if (window_.get()) |
197 overlay_dismiss_layer = window_->AcquireLayer(); | 267 overlay_dismiss_layer = window_->AcquireLayer(); |
| 268 LOG(ERROR) << "Resetting window slider"; |
198 Observe(NULL); | 269 Observe(NULL); |
199 window_slider_.reset(); | |
200 window_.reset(); | |
201 image_delegate_ = NULL; | |
202 if (overlay_dismiss_layer.get()) { | |
203 // OverlayDismissAnimator deletes overlay_dismiss_layer and itself when the | |
204 // animation completes. | |
205 (new OverlayDismissAnimator(overlay_dismiss_layer.Pass()))->Animate(); | |
206 } | |
207 } | 270 } |
208 | 271 |
| 272 // TODO delete these *Layer functions. |
209 ui::Layer* OverscrollNavigationOverlay::CreateSlideLayer(int offset) { | 273 ui::Layer* OverscrollNavigationOverlay::CreateSlideLayer(int offset) { |
210 const NavigationControllerImpl& controller = web_contents_->GetController(); | |
211 const NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( | |
212 controller.GetEntryAtOffset(offset)); | |
213 | |
214 gfx::Image image; | |
215 if (entry && entry->screenshot().get()) { | |
216 std::vector<gfx::ImagePNGRep> image_reps; | |
217 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f)); | |
218 image = gfx::Image(image_reps); | |
219 } | |
220 if (!layer_delegate_) | 274 if (!layer_delegate_) |
221 layer_delegate_.reset(new ImageLayerDelegate()); | 275 layer_delegate_.reset(new ImageLayerDelegate()); |
222 layer_delegate_->SetImage(image); | 276 // TODO fixme. |
| 277 layer_delegate_->SetImage( |
| 278 GetImageForDirection(offset == -1 ? OverscrollWindowAnimation::BACKWARD |
| 279 : OverscrollWindowAnimation::FORWARD)); |
223 | 280 |
224 ui::Layer* layer = new ui::Layer(ui::LAYER_TEXTURED); | 281 ui::Layer* layer = new ui::Layer(ui::LAYER_TEXTURED); |
225 layer->set_delegate(layer_delegate_.get()); | 282 layer->set_delegate(layer_delegate_.get()); |
226 return layer; | 283 return layer; |
227 } | 284 } |
228 | 285 |
229 ui::Layer* OverscrollNavigationOverlay::CreateBackLayer() { | 286 OverscrollWindowAnimation::Direction |
| 287 OverscrollNavigationOverlay::GetNavigationDirection() { |
| 288 return direction_; |
| 289 } |
| 290 |
| 291 /*ui::Layer* OverscrollNavigationOverlay::CreateBackLayer() { |
230 if (!web_contents_->GetController().CanGoBack()) | 292 if (!web_contents_->GetController().CanGoBack()) |
231 return NULL; | 293 return NULL; |
232 slide_direction_ = SLIDE_BACK; | 294 slide_direction_ = SLIDE_BACK; |
233 return CreateSlideLayer(-1); | 295 return CreateSlideLayer(-1); |
234 } | 296 } |
235 | 297 |
236 ui::Layer* OverscrollNavigationOverlay::CreateFrontLayer() { | 298 ui::Layer* OverscrollNavigationOverlay::CreateFrontLayer() { |
237 if (!web_contents_->GetController().CanGoForward()) | 299 if (!web_contents_->GetController().CanGoForward()) |
238 return NULL; | 300 return NULL; |
239 slide_direction_ = SLIDE_FRONT; | 301 slide_direction_ = SLIDE_FRONT; |
240 return CreateSlideLayer(1); | 302 return CreateSlideLayer(1); |
241 } | 303 } |
242 | 304 |
243 void OverscrollNavigationOverlay::OnWindowSlideCompleting() { | 305 void OverscrollNavigationOverlay::OnWindowSlideCompleting() { |
244 if (slide_direction_ == SLIDE_UNKNOWN) | 306 if (slide_direction_ == SLIDE_UNKNOWN) |
245 return; | 307 return; |
246 | 308 |
247 // Perform the navigation. | 309 // Perform the navigation. |
248 if (slide_direction_ == SLIDE_BACK) | 310 if (slide_direction_ == SLIDE_BACK) |
249 web_contents_->GetController().GoBack(); | 311 web_contents_->GetController().GoBack(); |
250 else if (slide_direction_ == SLIDE_FRONT) | 312 else if (slide_direction_ == SLIDE_FRONT) |
251 web_contents_->GetController().GoForward(); | 313 web_contents_->GetController().GoForward(); |
252 else | 314 else |
253 NOTREACHED(); | 315 NOTREACHED(); |
254 | 316 |
255 // Reset state and wait for the new navigation page to complete | 317 // Reset state and wait for the new navigation page to complete |
256 // loading/painting. | 318 // loading/painting. |
257 StartObserving(); | 319 StartObserving(); |
258 } | 320 }*/ |
259 | 321 |
260 void OverscrollNavigationOverlay::OnWindowSlideCompleted( | 322 /*void OverscrollNavigationOverlay::OnWindowSlideAborted() { |
261 scoped_ptr<ui::Layer> layer) { | |
262 if (slide_direction_ == SLIDE_UNKNOWN) { | |
263 window_slider_.reset(); | |
264 StopObservingIfDone(); | |
265 return; | |
266 } | |
267 | |
268 // Change the image used for the overlay window. | |
269 image_delegate_->SetImage(layer_delegate_->image()); | |
270 window_->layer()->SetTransform(gfx::Transform()); | |
271 window_->SchedulePaintInRect(gfx::Rect(window_->bounds().size())); | |
272 slide_direction_ = SLIDE_UNKNOWN; | |
273 // We may end up dismissing the overlay before it has a chance to repaint, so | |
274 // set the slider layer to be the one animated by OverlayDismissAnimator. | |
275 if (layer.get()) | |
276 overlay_dismiss_layer_ = layer.Pass(); | |
277 StopObservingIfDone(); | 323 StopObservingIfDone(); |
278 } | 324 } |
279 | 325 |
280 void OverscrollNavigationOverlay::OnWindowSlideAborted() { | |
281 StopObservingIfDone(); | |
282 } | |
283 | |
284 void OverscrollNavigationOverlay::OnWindowSliderDestroyed() { | 326 void OverscrollNavigationOverlay::OnWindowSliderDestroyed() { |
285 // We only want to take an action here if WindowSlider is being destroyed | 327 // We only want to take an action here if WindowSlider is being destroyed |
286 // outside of OverscrollNavigationOverlay. If window_slider_.get() is NULL, | 328 // outside of OverscrollNavigationOverlay. If window_slider_.get() is NULL, |
287 // then OverscrollNavigationOverlay is the one destroying WindowSlider, and | 329 // then OverscrollNavigationOverlay is the one destroying WindowSlider, and |
288 // we don't need to do anything. | 330 // we don't need to do anything. |
289 // This check prevents StopObservingIfDone() being called multiple times | 331 // This check prevents StopObservingIfDone() being called multiple times |
290 // (including recursively) for a single event. | 332 // (including recursively) for a single event. |
291 if (window_slider_.get()) { | 333 if (window_slider_.get()) { |
292 // The slider has just been destroyed. Release the ownership. | 334 // The slider has just been destroyed. Release the ownership. |
293 ignore_result(window_slider_.release()); | 335 ignore_result(window_slider_.release()); |
294 StopObservingIfDone(); | 336 StopObservingIfDone(); |
295 } | 337 } |
296 } | 338 }*/ |
297 | 339 |
298 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { | 340 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { |
| 341 LOG(ERROR) << "Did first visually non empty paint"; |
299 NavigationEntry* visible_entry = | 342 NavigationEntry* visible_entry = |
300 web_contents_->GetController().GetVisibleEntry(); | 343 web_contents_->GetController().GetVisibleEntry(); |
301 if (pending_entry_url_.is_empty() || | 344 if (pending_entry_url_.is_empty() || |
302 DoesEntryMatchURL(visible_entry, pending_entry_url_)) { | 345 DoesEntryMatchURL(visible_entry, pending_entry_url_)) { |
303 received_paint_update_ = true; | 346 received_paint_update_ = true; |
304 StopObservingIfDone(); | 347 StopObservingIfDone(); |
305 } | 348 } |
306 } | 349 } |
307 | 350 |
308 void OverscrollNavigationOverlay::DidStopLoading(RenderViewHost* host) { | 351 void OverscrollNavigationOverlay::DidStopLoading(RenderViewHost* host) { |
| 352 LOG(ERROR) << "Did stop loading"; |
309 // Don't compare URLs in this case - it's possible they won't match if | 353 // Don't compare URLs in this case - it's possible they won't match if |
310 // a gesture-nav initiated navigation was interrupted by some other in-site | 354 // a gesture-nav initiated navigation was interrupted by some other in-site |
311 // navigation ((e.g., from a script, or from a bookmark). | 355 // navigation ((e.g., from a script, or from a bookmark). |
312 loading_complete_ = true; | 356 loading_complete_ = true; |
313 StopObservingIfDone(); | 357 StopObservingIfDone(); |
314 } | 358 } |
315 | 359 |
| 360 /*aura::Window* OverscrollNavigationOverlay::GetWindowToAnimateForOverscroll() |
| 361 const { |
| 362 return direction_ == OverscrollNavigationOverlay::FORWARD |
| 363 ? window_.get() |
| 364 : web_contents_->GetContentNativeView(); |
| 365 } |
| 366 |
| 367 gfx::Rect OverscrollNavigationOverlay::GetStarterBounds() const { |
| 368 gfx::Rect bounds = gfx::Rect(web_contents_window_->bounds().size()); |
| 369 if (direction_ == OverscrollNavigationOverlay::FORWARD) { |
| 370 // The overlay will be sliding in from the right edge towards the left in |
| 371 // non-RTL, or sliding in from the left edge towards the right in RTL. |
| 372 // So position the overlay window accordingly. |
| 373 bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0); |
| 374 } |
| 375 return bounds; |
| 376 }*/ |
| 377 |
316 } // namespace content | 378 } // namespace content |
OLD | NEW |