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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/web_contents/aura/overscroll_window_delegate.h"
6
7 #include "base/i18n/rtl.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
11 #include "content/public/browser/overscroll_configuration.h"
12 #include "ui/aura/window.h"
13 #include "ui/gfx/image/image_png_rep.h"
14
15 namespace content {
16
17 OverscrollWindowDelegate::OverscrollWindowDelegate(
18 OverscrollControllerDelegate* delegate,
19 const gfx::Image& image)
20 : delegate_(delegate),
21 overscroll_mode_(OVERSCROLL_NONE),
22 delta_x_(0.f),
23 complete_threshold_ratio_(content::GetOverscrollConfig(
24 content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE)) {
25 SetImage(image);
26 }
27
28 OverscrollWindowDelegate::~OverscrollWindowDelegate() {
29 }
30
31 void OverscrollWindowDelegate::StartOverscroll() {
32 LOG(ERROR) << "OWD: StartOverscroll";
33 OverscrollMode old_mode = overscroll_mode_;
34 // TODO take into account RTL here?
35 if (delta_x_ > 0)
36 overscroll_mode_ = OVERSCROLL_EAST;
37 else
38 overscroll_mode_ = OVERSCROLL_WEST;
39 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_);
40 }
41
42 void OverscrollWindowDelegate::ResetOverscroll() {
43 LOG(ERROR) << "OWD: ResetOverscroll";
44 delegate_->OnOverscrollModeChange(overscroll_mode_, OVERSCROLL_NONE);
45 overscroll_mode_ = OVERSCROLL_NONE;
46 delta_x_ = 0;
47 }
48
49 void OverscrollWindowDelegate::CompleteOrResetOverscroll() {
50 LOG(ERROR) << "OWD: CompleteOrResetOverscroll";
51 if (overscroll_mode_ == OVERSCROLL_NONE)
52 return;
53 int width = delegate_->GetVisibleBounds().width();
54 float ratio = (fabs(delta_x_)) / width;
55 if (ratio < complete_threshold_ratio_) {
56 ResetOverscroll();
57 return;
58 }
59 delegate_->OnOverscrollComplete(overscroll_mode_);
60 overscroll_mode_ = OVERSCROLL_NONE;
61 }
62
63 void OverscrollWindowDelegate::UpdateOverscroll(float delta_x) {
64 LOG(ERROR) << "OWD: UpdateOverscroll";
65 delta_x_ += delta_x;
66 if (overscroll_mode_ == OVERSCROLL_NONE)
67 StartOverscroll();
68 delegate_->OnOverscrollUpdate(delta_x_, 0.f);
69 }
70
71 void OverscrollWindowDelegate::OnKeyEvent(ui::KeyEvent* event) {
72 ResetOverscroll();
73 }
74
75 void OverscrollWindowDelegate::OnMouseEvent(ui::MouseEvent* event) {
76 LOG(ERROR) << "OWD: OnMouseEvent";
77 // TODO is this a hack or something?
78 if (!(event->flags() & ui::EF_IS_SYNTHESIZED))
79 ResetOverscroll();
80 }
81
82 void OverscrollWindowDelegate::OnScrollEvent(ui::ScrollEvent* event) {
83 // 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.
84 // active_start_threshold_ = start_threshold_touchpad_;
85 LOG(ERROR) << "OWD: OnScrollEvent";
86 if (event->type() == ui::ET_SCROLL)
87 UpdateOverscroll(event->x_offset_ordinal());
88 else if (event->type() == ui::ET_SCROLL_FLING_START)
89 CompleteOrResetOverscroll();
90 else
91 ResetOverscroll();
92 event->SetHandled();
93 }
94
95 void OverscrollWindowDelegate::OnGestureEvent(ui::GestureEvent* event) {
96 LOG(ERROR) << "OWD: OnGestureEvent";
97 // active_start_threshold_ = start_threshold_touchscreen_;
98 switch (event->type()) {
99 case ui::ET_GESTURE_SCROLL_BEGIN:
100 // StartOverscroll();
101 break;
102
103 case ui::ET_GESTURE_SCROLL_UPDATE:
104 UpdateOverscroll(event->details().scroll_x());
105 break;
106
107 case ui::ET_GESTURE_SCROLL_END:
108 CompleteOrResetOverscroll();
109 break;
110
111 case ui::ET_SCROLL_FLING_START:
112 CompleteOrResetOverscroll();
113 break;
114
115 case ui::ET_GESTURE_PINCH_BEGIN:
116 case ui::ET_GESTURE_PINCH_UPDATE:
117 case ui::ET_GESTURE_PINCH_END:
118 ResetOverscroll();
119 break;
120
121 default:
122 break;
123 }
124
125 event->SetHandled();
126 }
127
128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698