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

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: Checked comments 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 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 if (!(event->flags() & ui::EF_IS_SYNTHESIZED))
78 ResetOverscroll();
79 }
80
81 void OverscrollWindowDelegate::OnScrollEvent(ui::ScrollEvent* event) {
82 // active_start_threshold_ = start_threshold_touchpad_;
83 LOG(ERROR) << "OWD: OnScrollEvent";
84 if (event->type() == ui::ET_SCROLL)
85 UpdateOverscroll(event->x_offset_ordinal());
86 else if (event->type() == ui::ET_SCROLL_FLING_START)
87 CompleteOrResetOverscroll();
88 else
89 ResetOverscroll();
90 event->SetHandled();
91 }
92
93 void OverscrollWindowDelegate::OnGestureEvent(ui::GestureEvent* event) {
94 LOG(ERROR) << "OWD: OnGestureEvent";
95 // active_start_threshold_ = start_threshold_touchscreen_;
96 switch (event->type()) {
97 case ui::ET_GESTURE_SCROLL_BEGIN:
98 // StartOverscroll();
99 break;
100
101 case ui::ET_GESTURE_SCROLL_UPDATE:
102 UpdateOverscroll(event->details().scroll_x());
103 break;
104
105 case ui::ET_GESTURE_SCROLL_END:
106 CompleteOrResetOverscroll();
107 break;
108
109 case ui::ET_SCROLL_FLING_START:
110 CompleteOrResetOverscroll();
111 break;
112
113 case ui::ET_GESTURE_PINCH_BEGIN:
114 case ui::ET_GESTURE_PINCH_UPDATE:
115 case ui::ET_GESTURE_PINCH_END:
116 ResetOverscroll();
117 break;
118
119 default:
120 break;
121 }
122
123 event->SetHandled();
124 }
125
126 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698