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