| Index: content/browser/web_contents/aura/overscroll_window_delegate.cc
|
| diff --git a/content/browser/web_contents/aura/overscroll_window_delegate.cc b/content/browser/web_contents/aura/overscroll_window_delegate.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e1715f0782e520285d61beff3d739bc970827167
|
| --- /dev/null
|
| +++ b/content/browser/web_contents/aura/overscroll_window_delegate.cc
|
| @@ -0,0 +1,126 @@
|
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/web_contents/aura/overscroll_window_delegate.h"
|
| +
|
| +#include "base/i18n/rtl.h"
|
| +#include "content/browser/frame_host/navigation_controller_impl.h"
|
| +#include "content/browser/frame_host/navigation_entry_impl.h"
|
| +#include "content/browser/renderer_host/overscroll_controller_delegate.h"
|
| +#include "content/public/browser/overscroll_configuration.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/gfx/image/image_png_rep.h"
|
| +
|
| +namespace content {
|
| +
|
| +OverscrollWindowDelegate::OverscrollWindowDelegate(
|
| + OverscrollControllerDelegate* delegate,
|
| + const gfx::Image& image)
|
| + : delegate_(delegate),
|
| + overscroll_mode_(OVERSCROLL_NONE),
|
| + delta_x_(0.f),
|
| + complete_threshold_ratio_(content::GetOverscrollConfig(
|
| + content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE)) {
|
| + SetImage(image);
|
| +}
|
| +
|
| +OverscrollWindowDelegate::~OverscrollWindowDelegate() {
|
| +}
|
| +
|
| +void OverscrollWindowDelegate::StartOverscroll() {
|
| + LOG(ERROR) << "OWD: StartOverscroll";
|
| + OverscrollMode old_mode = overscroll_mode_;
|
| + // TODO take into account RTL here?
|
| + if (delta_x_ > 0)
|
| + overscroll_mode_ = OVERSCROLL_EAST;
|
| + else
|
| + overscroll_mode_ = OVERSCROLL_WEST;
|
| + delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_);
|
| +}
|
| +
|
| +void OverscrollWindowDelegate::ResetOverscroll() {
|
| + LOG(ERROR) << "OWD: ResetOverscroll";
|
| + delegate_->OnOverscrollModeChange(overscroll_mode_, OVERSCROLL_NONE);
|
| + overscroll_mode_ = OVERSCROLL_NONE;
|
| + delta_x_ = 0;
|
| +}
|
| +
|
| +void OverscrollWindowDelegate::CompleteOrResetOverscroll() {
|
| + LOG(ERROR) << "OWD: CompleteOrResetOverscroll";
|
| + if (overscroll_mode_ == OVERSCROLL_NONE)
|
| + return;
|
| + int width = delegate_->GetVisibleBounds().width();
|
| + float ratio = (fabs(delta_x_)) / width;
|
| + if (ratio < complete_threshold_ratio_) {
|
| + ResetOverscroll();
|
| + return;
|
| + }
|
| + delegate_->OnOverscrollComplete(overscroll_mode_);
|
| + overscroll_mode_ = OVERSCROLL_NONE;
|
| +}
|
| +
|
| +void OverscrollWindowDelegate::UpdateOverscroll(float delta_x) {
|
| + LOG(ERROR) << "OWD: UpdateOverscroll";
|
| + delta_x_ += delta_x;
|
| + if (overscroll_mode_ == OVERSCROLL_NONE)
|
| + StartOverscroll();
|
| + delegate_->OnOverscrollUpdate(delta_x_, 0.f);
|
| +}
|
| +
|
| +void OverscrollWindowDelegate::OnKeyEvent(ui::KeyEvent* event) {
|
| + ResetOverscroll();
|
| +}
|
| +
|
| +void OverscrollWindowDelegate::OnMouseEvent(ui::MouseEvent* event) {
|
| + LOG(ERROR) << "OWD: OnMouseEvent";
|
| + if (!(event->flags() & ui::EF_IS_SYNTHESIZED))
|
| + ResetOverscroll();
|
| +}
|
| +
|
| +void OverscrollWindowDelegate::OnScrollEvent(ui::ScrollEvent* event) {
|
| + // active_start_threshold_ = start_threshold_touchpad_;
|
| + LOG(ERROR) << "OWD: OnScrollEvent";
|
| + if (event->type() == ui::ET_SCROLL)
|
| + UpdateOverscroll(event->x_offset_ordinal());
|
| + else if (event->type() == ui::ET_SCROLL_FLING_START)
|
| + CompleteOrResetOverscroll();
|
| + else
|
| + ResetOverscroll();
|
| + event->SetHandled();
|
| +}
|
| +
|
| +void OverscrollWindowDelegate::OnGestureEvent(ui::GestureEvent* event) {
|
| + LOG(ERROR) << "OWD: OnGestureEvent";
|
| + // active_start_threshold_ = start_threshold_touchscreen_;
|
| + switch (event->type()) {
|
| + case ui::ET_GESTURE_SCROLL_BEGIN:
|
| + // StartOverscroll();
|
| + break;
|
| +
|
| + case ui::ET_GESTURE_SCROLL_UPDATE:
|
| + UpdateOverscroll(event->details().scroll_x());
|
| + break;
|
| +
|
| + case ui::ET_GESTURE_SCROLL_END:
|
| + CompleteOrResetOverscroll();
|
| + break;
|
| +
|
| + case ui::ET_SCROLL_FLING_START:
|
| + CompleteOrResetOverscroll();
|
| + break;
|
| +
|
| + case ui::ET_GESTURE_PINCH_BEGIN:
|
| + case ui::ET_GESTURE_PINCH_UPDATE:
|
| + case ui::ET_GESTURE_PINCH_END:
|
| + ResetOverscroll();
|
| + break;
|
| +
|
| + default:
|
| + break;
|
| + }
|
| +
|
| + event->SetHandled();
|
| +}
|
| +
|
| +} // namespace content
|
|
|