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