| Index: content/browser/web_contents/aura/overscroll_navigation_overlay.cc
|
| diff --git a/content/browser/web_contents/aura/overscroll_navigation_overlay.cc b/content/browser/web_contents/aura/overscroll_navigation_overlay.cc
|
| index a96b0d27ed66cd46912ebc7d55fdee0feb5e9f9c..a6e6c3c7d3ba1851bfcc63e2fa8713c94eea3a64 100644
|
| --- a/content/browser/web_contents/aura/overscroll_navigation_overlay.cc
|
| +++ b/content/browser/web_contents/aura/overscroll_navigation_overlay.cc
|
| @@ -6,6 +6,8 @@
|
|
|
| #include "content/browser/frame_host/navigation_entry_impl.h"
|
| #include "content/browser/renderer_host/render_view_host_impl.h"
|
| +#include "content/browser/web_contents/aura/overscroll_layer_wrapper.h"
|
| +#include "content/browser/web_contents/aura/overscroll_window_delegate.h"
|
| #include "content/browser/web_contents/web_contents_impl.h"
|
| #include "content/common/view_messages.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -18,7 +20,6 @@
|
| #include "ui/compositor/scoped_layer_animation_settings.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/image/image_png_rep.h"
|
| -#include "ui/gfx/image/image_skia.h"
|
|
|
| namespace content {
|
| namespace {
|
| @@ -43,6 +44,7 @@ bool DoesEntryMatchURL(NavigationEntry* entry, const GURL& url) {
|
| } // namespace
|
|
|
| // A LayerDelegate that paints an image for the layer.
|
| +// TODO move to overscroll_window.h
|
| class ImageLayerDelegate : public ui::LayerDelegate {
|
| public:
|
| ImageLayerDelegate() {}
|
| @@ -130,18 +132,23 @@ class OverlayDismissAnimator
|
| };
|
|
|
| OverscrollNavigationOverlay::OverscrollNavigationOverlay(
|
| - WebContentsImpl* web_contents)
|
| - : web_contents_(web_contents),
|
| - image_delegate_(NULL),
|
| + WebContentsImpl* web_contents,
|
| + OverscrollWindowAnimation* owa,
|
| + aura::Window* web_contents_window)
|
| + : direction_(OverscrollWindowAnimation::NONE),
|
| + web_contents_(web_contents),
|
| + image_delegate_(nullptr),
|
| loading_complete_(false),
|
| received_paint_update_(false),
|
| - slide_direction_(SLIDE_UNKNOWN) {
|
| + owa_(owa),
|
| + web_contents_window_(web_contents_window) {
|
| }
|
|
|
| OverscrollNavigationOverlay::~OverscrollNavigationOverlay() {
|
| }
|
|
|
| void OverscrollNavigationOverlay::StartObserving() {
|
| + LOG(ERROR) << "Starting to observe";
|
| loading_complete_ = false;
|
| received_paint_update_ = false;
|
| overlay_dismiss_layer_.reset();
|
| @@ -154,16 +161,39 @@ void OverscrollNavigationOverlay::StartObserving() {
|
| // Assumes the navigation has been initiated.
|
| NavigationEntry* pending_entry =
|
| web_contents_->GetController().GetPendingEntry();
|
| +
|
| // Save url of the pending entry to identify when it loads and paints later.
|
| // Under some circumstances navigation can leave a null pending entry -
|
| // see comments in NavigationControllerImpl::NavigateToPendingEntry().
|
| pending_entry_url_ = pending_entry ? pending_entry->GetURL() : GURL();
|
| + LOG(ERROR) << "URL: " << pending_entry_url_.GetContent();
|
| }
|
|
|
| -void OverscrollNavigationOverlay::SetOverlayWindow(
|
| - scoped_ptr<aura::Window> window,
|
| - aura_extra::ImageWindowDelegate* delegate) {
|
| - window_ = window.Pass();
|
| +void OverscrollNavigationOverlay::SetupOverlayWindow() {
|
| + LOG(ERROR) << "ONO: Setting overlay window";
|
| + // TODO use OverscrollWindowDelegate instead.
|
| + aura_extra::ImageWindowDelegate* image_delegate =
|
| + new aura_extra::ImageWindowDelegate();
|
| + image_delegate->set_background_color(SK_ColorWHITE);
|
| + gfx::Image image = GetImageForDirection(direction_);
|
| + if (image.IsEmpty())
|
| + LOG(ERROR) << "Image is empty";
|
| + image_delegate->SetImage(image);
|
| + window_.reset(new aura::Window(image_delegate));
|
| + window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
|
| + window_->SetTransparent(true);
|
| + window_->Init(aura::WINDOW_LAYER_TEXTURED);
|
| + window_->layer()->SetMasksToBounds(false);
|
| + window_->SetName("OverscrollOverlay");
|
| + window_->layer()->SetLayerBrightness(-0.1f);
|
| + web_contents_window_->AddChild(window_.get());
|
| +
|
| + gfx::Rect bounds = gfx::Rect(web_contents_window_->bounds().size());
|
| + if (direction_ == OverscrollWindowAnimation::FORWARD)
|
| + bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0);
|
| + window_->SetBounds(bounds);
|
| + window_->Show();
|
| + /*window_ = window.Pass();
|
| if (window_.get() && window_->parent())
|
| window_->parent()->StackChildAtTop(window_.get());
|
| image_delegate_ = delegate;
|
| @@ -175,18 +205,102 @@ void OverscrollNavigationOverlay::SetOverlayWindow(
|
| slide_direction_ = SLIDE_UNKNOWN;
|
| } else {
|
| window_slider_.reset();
|
| + }*/
|
| +}
|
| +
|
| +const gfx::Image OverscrollNavigationOverlay::GetImageForDirection(
|
| + OverscrollWindowAnimation::Direction direction) const {
|
| + const NavigationControllerImpl& controller = web_contents_->GetController();
|
| + const NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
|
| + controller.GetEntryAtOffset(
|
| + direction == OverscrollWindowAnimation::FORWARD ? 1 : -1));
|
| +
|
| + if (entry && entry->screenshot().get()) {
|
| + std::vector<gfx::ImagePNGRep> image_reps;
|
| + image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f));
|
| + return gfx::Image(image_reps);
|
| + }
|
| + return gfx::Image();
|
| +}
|
| +
|
| +scoped_ptr<OverscrollLayerWrapper> OverscrollNavigationOverlay::CreateLayer() {
|
| + LOG(ERROR) << "ONO: CreateLayer";
|
| + scoped_ptr<OverscrollLayerWrapper> layer_wrapper(
|
| + new OverscrollLayerWrapper());
|
| + if (!window_) {
|
| + SetupOverlayWindow();
|
| + if (direction_ == OverscrollWindowAnimation::FORWARD) {
|
| + layer_wrapper->WrapWindow(window_.get());
|
| + web_contents_window_->StackChildAbove(
|
| + window_.get(), web_contents_->GetContentNativeView());
|
| + } else {
|
| + layer_wrapper->WrapWindow(web_contents_->GetContentNativeView());
|
| + web_contents_window_->StackChildBelow(
|
| + window_.get(), web_contents_->GetContentNativeView());
|
| + }
|
| + } else {
|
| + LOG(ERROR) << "NOT IMPLEMENTED: SET UP LAYER";
|
| + // TODO set up the layer.
|
| }
|
| + return layer_wrapper.Pass();
|
| +}
|
| +
|
| +scoped_ptr<OverscrollLayerWrapper>
|
| +OverscrollNavigationOverlay::CreateFrontLayer() {
|
| + LOG(ERROR) << "ONO: Create front layer";
|
| + if (!web_contents_->GetController().CanGoForward())
|
| + return nullptr;
|
| + direction_ = OverscrollWindowAnimation::FORWARD;
|
| + return CreateLayer();
|
| +}
|
| +
|
| +scoped_ptr<OverscrollLayerWrapper>
|
| +OverscrollNavigationOverlay::CreateBackLayer() {
|
| + LOG(ERROR) << "ONO: Create back layer";
|
| + if (!web_contents_->GetController().CanGoBack())
|
| + return nullptr;
|
| + direction_ = OverscrollWindowAnimation::BACKWARD;
|
| + return CreateLayer();
|
| +}
|
| +
|
| +void OverscrollNavigationOverlay::OnOverscrollCompleted() {
|
| + // TODO write actual code.
|
| + LOG(ERROR) << "ONO: OnOverscrollCompleted";
|
| + window_.reset();
|
| +}
|
| +
|
| +void OverscrollNavigationOverlay::OnOverscrollCompleting() {
|
| +
|
| +}
|
| +
|
| +void OverscrollNavigationOverlay::FadeOutOverscrollWindow() {
|
| + LOG(ERROR) << "FadeOutOverscrollWindow";
|
| + // TODO maybe we do not need this check.
|
| + if (!window_)
|
| + return;
|
| + aura::Window* contents = web_contents_->GetContentNativeView();
|
| + contents->layer()->SetLayerBrightness(1.f);
|
| + {
|
| + ui::ScopedLayerAnimationSettings settings(contents->layer()->GetAnimator());
|
| + settings.SetPreemptionStrategy(
|
| + ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
|
| + settings.SetTweenType(gfx::Tween::EASE_OUT);
|
| + contents->layer()->SetLayerBrightness(0.f);
|
| + }
|
| + scoped_ptr<ui::Layer> dismiss_layer = window_->AcquireLayer();
|
| + window_.reset();
|
| + (new OverlayDismissAnimator(dismiss_layer.Pass()))->Animate();
|
| }
|
|
|
| void OverscrollNavigationOverlay::StopObservingIfDone() {
|
| + LOG(ERROR) << "Stop observing if done";
|
| // Normally we dismiss the overlay once we receive a paint update, however
|
| // for in-page navigations DidFirstVisuallyNonEmptyPaint() does not get
|
| // called, and we rely on loading_complete_ for those cases.
|
| if (!received_paint_update_ && !loading_complete_)
|
| return;
|
|
|
| - // If a slide is in progress, then do not destroy the window or the slide.
|
| - if (window_slider_.get() && window_slider_->IsSlideInProgress())
|
| + if (owa_->is_animation_in_progress())
|
| return;
|
|
|
| // The layer to be animated by OverlayDismissAnimator
|
| @@ -195,37 +309,25 @@ void OverscrollNavigationOverlay::StopObservingIfDone() {
|
| overlay_dismiss_layer = overlay_dismiss_layer_.Pass();
|
| else if (window_.get())
|
| overlay_dismiss_layer = window_->AcquireLayer();
|
| + LOG(ERROR) << "Resetting window slider";
|
| Observe(NULL);
|
| - window_slider_.reset();
|
| - window_.reset();
|
| - image_delegate_ = NULL;
|
| - if (overlay_dismiss_layer.get()) {
|
| - // OverlayDismissAnimator deletes overlay_dismiss_layer and itself when the
|
| - // animation completes.
|
| - (new OverlayDismissAnimator(overlay_dismiss_layer.Pass()))->Animate();
|
| - }
|
| }
|
|
|
| +// TODO delete these *Layer functions.
|
| ui::Layer* OverscrollNavigationOverlay::CreateSlideLayer(int offset) {
|
| - const NavigationControllerImpl& controller = web_contents_->GetController();
|
| - const NavigationEntryImpl* entry = controller.GetEntryAtOffset(offset);
|
| -
|
| - gfx::Image image;
|
| - if (entry && entry->screenshot().get()) {
|
| - std::vector<gfx::ImagePNGRep> image_reps;
|
| - image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f));
|
| - image = gfx::Image(image_reps);
|
| - }
|
| if (!layer_delegate_)
|
| layer_delegate_.reset(new ImageLayerDelegate());
|
| - layer_delegate_->SetImage(image);
|
| + // TODO fixme.
|
| + layer_delegate_->SetImage(
|
| + GetImageForDirection(offset == -1 ? OverscrollWindowAnimation::BACKWARD
|
| + : OverscrollWindowAnimation::FORWARD));
|
|
|
| ui::Layer* layer = new ui::Layer(ui::LAYER_TEXTURED);
|
| layer->set_delegate(layer_delegate_.get());
|
| return layer;
|
| }
|
|
|
| -ui::Layer* OverscrollNavigationOverlay::CreateBackLayer() {
|
| +/*ui::Layer* OverscrollNavigationOverlay::CreateBackLayer() {
|
| if (!web_contents_->GetController().CanGoBack())
|
| return NULL;
|
| slide_direction_ = SLIDE_BACK;
|
| @@ -254,29 +356,9 @@ void OverscrollNavigationOverlay::OnWindowSlideCompleting() {
|
| // Reset state and wait for the new navigation page to complete
|
| // loading/painting.
|
| StartObserving();
|
| -}
|
| +}*/
|
|
|
| -void OverscrollNavigationOverlay::OnWindowSlideCompleted(
|
| - scoped_ptr<ui::Layer> layer) {
|
| - if (slide_direction_ == SLIDE_UNKNOWN) {
|
| - window_slider_.reset();
|
| - StopObservingIfDone();
|
| - return;
|
| - }
|
| -
|
| - // Change the image used for the overlay window.
|
| - image_delegate_->SetImage(layer_delegate_->image());
|
| - window_->layer()->SetTransform(gfx::Transform());
|
| - window_->SchedulePaintInRect(gfx::Rect(window_->bounds().size()));
|
| - slide_direction_ = SLIDE_UNKNOWN;
|
| - // We may end up dismissing the overlay before it has a chance to repaint, so
|
| - // set the slider layer to be the one animated by OverlayDismissAnimator.
|
| - if (layer.get())
|
| - overlay_dismiss_layer_ = layer.Pass();
|
| - StopObservingIfDone();
|
| -}
|
| -
|
| -void OverscrollNavigationOverlay::OnWindowSlideAborted() {
|
| +/*void OverscrollNavigationOverlay::OnWindowSlideAborted() {
|
| StopObservingIfDone();
|
| }
|
|
|
| @@ -292,9 +374,10 @@ void OverscrollNavigationOverlay::OnWindowSliderDestroyed() {
|
| ignore_result(window_slider_.release());
|
| StopObservingIfDone();
|
| }
|
| -}
|
| +}*/
|
|
|
| void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() {
|
| + LOG(ERROR) << "Did first visually non empty paint";
|
| NavigationEntry* visible_entry =
|
| web_contents_->GetController().GetVisibleEntry();
|
| if (pending_entry_url_.is_empty() ||
|
| @@ -305,6 +388,7 @@ void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() {
|
| }
|
|
|
| void OverscrollNavigationOverlay::DidStopLoading(RenderViewHost* host) {
|
| + LOG(ERROR) << "Did stop loading";
|
| // Don't compare URLs in this case - it's possible they won't match if
|
| // a gesture-nav initiated navigation was interrupted by some other in-site
|
| // navigation ((e.g., from a script, or from a bookmark).
|
| @@ -312,4 +396,22 @@ void OverscrollNavigationOverlay::DidStopLoading(RenderViewHost* host) {
|
| StopObservingIfDone();
|
| }
|
|
|
| +/*aura::Window* OverscrollNavigationOverlay::GetWindowToAnimateForOverscroll()
|
| + const {
|
| + return direction_ == OverscrollNavigationOverlay::FORWARD
|
| + ? window_.get()
|
| + : web_contents_->GetContentNativeView();
|
| +}
|
| +
|
| +gfx::Rect OverscrollNavigationOverlay::GetStarterBounds() const {
|
| + gfx::Rect bounds = gfx::Rect(web_contents_window_->bounds().size());
|
| + if (direction_ == OverscrollNavigationOverlay::FORWARD) {
|
| + // The overlay will be sliding in from the right edge towards the left in
|
| + // non-RTL, or sliding in from the left edge towards the right in RTL.
|
| + // So position the overlay window accordingly.
|
| + bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0);
|
| + }
|
| + return bounds;
|
| +}*/
|
| +
|
| } // namespace content
|
|
|