Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: content/browser/web_contents/aura/overscroll_window_delegate.cc

Issue 895543005: Refactor GestureNavigation to eliminate code redundancy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Following suggestions by Mikhail, rewritten OWA to use a delegate interface (to be implemented) Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..70ffbf3d607e59cf85cec28818c3ce9a73073727
--- /dev/null
+++ b/content/browser/web_contents/aura/overscroll_window_delegate.cc
@@ -0,0 +1,128 @@
+// 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";
+ // TODO is this a hack or something?
+ if (!(event->flags() & ui::EF_IS_SYNTHESIZED))
+ ResetOverscroll();
+}
+
+void OverscrollWindowDelegate::OnScrollEvent(ui::ScrollEvent* event) {
+ // TODO dafuq this does?
mfomitchev 2015/02/19 19:05:00 Thresholds on how much you need to drag before the
Nina 2015/02/27 19:32:51 Acknowledged.
+ // 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

Powered by Google App Engine
This is Rietveld 408576698