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

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: New design with window|wrapper in OWA Created 5 years, 9 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 start_threshold_touchscreen_(content::GetOverscrollConfig(
26 content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN)),
27 start_threshold_touchpad_(content::GetOverscrollConfig(
28 content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD)),
29 active_start_threshold_(0.f) {
30 SetImage(image);
31 }
32
33 OverscrollWindowDelegate::~OverscrollWindowDelegate() {
34 }
35
36 void OverscrollWindowDelegate::StartOverscroll() {
37 LOG(ERROR) << "OWD: StartOverscroll";
38 OverscrollMode old_mode = overscroll_mode_;
39 if (delta_x_ > 0)
40 overscroll_mode_ = OVERSCROLL_EAST;
41 else
42 overscroll_mode_ = OVERSCROLL_WEST;
43 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_);
44 }
45
46 void OverscrollWindowDelegate::ResetOverscroll() {
47 LOG(ERROR) << "OWD: ResetOverscroll";
48 delegate_->OnOverscrollModeChange(overscroll_mode_, OVERSCROLL_NONE);
49 overscroll_mode_ = OVERSCROLL_NONE;
50 delta_x_ = 0;
51 }
52
53 void OverscrollWindowDelegate::CompleteOrResetOverscroll() {
54 LOG(ERROR) << "OWD: CompleteOrResetOverscroll";
55 if (overscroll_mode_ == OVERSCROLL_NONE)
56 return;
57 int width = delegate_->GetVisibleBounds().width();
58 float ratio = (fabs(delta_x_)) / width;
59 if (ratio < complete_threshold_ratio_) {
60 ResetOverscroll();
61 return;
62 }
63 delegate_->OnOverscrollComplete(overscroll_mode_);
64 overscroll_mode_ = OVERSCROLL_NONE;
65 }
66
67 void OverscrollWindowDelegate::UpdateOverscroll(float delta_x) {
68 LOG(ERROR) << "OWD: UpdateOverscroll";
69 float old_delta_x = delta_x_;
70 delta_x_ += delta_x;
71 if (overscroll_mode_ == OVERSCROLL_NONE) {
72 if (fabs(delta_x_) > active_start_threshold_)
73 StartOverscroll();
74 return;
75 }
76 if ((old_delta_x < 0 && delta_x_ > 0) ||
77 (old_delta_x > 0 && delta_x_ < 0)) {
78 LOG(ERROR) << "Direction changed";
79 ResetOverscroll();
80 return;
81 }
82 delegate_->OnOverscrollUpdate(delta_x_, 0.f);
83 }
84
85 void OverscrollWindowDelegate::OnKeyEvent(ui::KeyEvent* event) {
86 ResetOverscroll();
87 }
88
89 void OverscrollWindowDelegate::OnMouseEvent(ui::MouseEvent* event) {
90 LOG(ERROR) << "OWD: OnMouseEvent";
91 if (!(event->flags() & ui::EF_IS_SYNTHESIZED))
92 ResetOverscroll();
93 }
94
95 void OverscrollWindowDelegate::OnScrollEvent(ui::ScrollEvent* event) {
96 active_start_threshold_ = start_threshold_touchpad_;
97 LOG(ERROR) << "OWD: OnScrollEvent";
98 if (event->type() == ui::ET_SCROLL)
99 UpdateOverscroll(event->x_offset_ordinal());
100 else if (event->type() == ui::ET_SCROLL_FLING_START)
101 CompleteOrResetOverscroll();
102 else
103 ResetOverscroll();
104 event->SetHandled();
105 }
106
107 void OverscrollWindowDelegate::OnGestureEvent(ui::GestureEvent* event) {
108 LOG(ERROR) << "OWD: OnGestureEvent";
109 active_start_threshold_ = start_threshold_touchscreen_;
110 switch (event->type()) {
111 case ui::ET_GESTURE_SCROLL_BEGIN:
112 // StartOverscroll();
113 break;
114
115 case ui::ET_GESTURE_SCROLL_UPDATE:
116 UpdateOverscroll(event->details().scroll_x());
117 break;
118
119 case ui::ET_GESTURE_SCROLL_END:
120 CompleteOrResetOverscroll();
121 break;
122
123 case ui::ET_SCROLL_FLING_START:
124 CompleteOrResetOverscroll();
125 break;
126
127 case ui::ET_GESTURE_PINCH_BEGIN:
128 case ui::ET_GESTURE_PINCH_UPDATE:
129 case ui::ET_GESTURE_PINCH_END:
130 ResetOverscroll();
131 break;
132
133 default:
134 break;
135 }
136
137 event->SetHandled();
138 }
139
140 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698