Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights | 3 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights |
| 4 * reserved. | 4 * reserved. |
| 5 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 6 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | 6 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #include "core/page/ChromeClient.h" | 39 #include "core/page/ChromeClient.h" |
| 40 #include "core/page/Page.h" | 40 #include "core/page/Page.h" |
| 41 #include "platform/wtf/Time.h" | 41 #include "platform/wtf/Time.h" |
| 42 | 42 |
| 43 namespace blink { | 43 namespace blink { |
| 44 | 44 |
| 45 // Delay time in second for start autoscroll if pointer is in border edge of | 45 // Delay time in second for start autoscroll if pointer is in border edge of |
| 46 // scrollable element. | 46 // scrollable element. |
| 47 static const TimeDelta kAutoscrollDelay = TimeDelta::FromSecondsD(0.2); | 47 static const TimeDelta kAutoscrollDelay = TimeDelta::FromSecondsD(0.2); |
| 48 | 48 |
| 49 static const int kNoMiddleClickAutoscrollRadius = 15; | |
| 50 | |
| 51 static const Cursor& MiddleClickAutoscrollCursor(const FloatSize& velocity) { | |
| 52 // At the original click location we draw a 4 arrowed icon. Over this icon | |
| 53 // there won't be any scroll, So don't change the cursor over this area. | |
| 54 bool east = velocity.Width() < 0; | |
| 55 bool west = velocity.Width() > 0; | |
| 56 bool north = velocity.Height() > 0; | |
| 57 bool south = velocity.Height() < 0; | |
| 58 | |
| 59 if (north) { | |
| 60 if (east) | |
| 61 return NorthEastPanningCursor(); | |
| 62 if (west) | |
| 63 return NorthWestPanningCursor(); | |
| 64 return NorthPanningCursor(); | |
| 65 } | |
| 66 if (south) { | |
| 67 if (east) | |
| 68 return SouthEastPanningCursor(); | |
| 69 if (west) | |
| 70 return SouthWestPanningCursor(); | |
| 71 return SouthPanningCursor(); | |
| 72 } | |
| 73 if (east) | |
| 74 return EastPanningCursor(); | |
| 75 if (west) | |
| 76 return WestPanningCursor(); | |
| 77 return MiddlePanningCursor(); | |
| 78 } | |
| 79 | |
| 49 AutoscrollController* AutoscrollController::Create(Page& page) { | 80 AutoscrollController* AutoscrollController::Create(Page& page) { |
| 50 return new AutoscrollController(page); | 81 return new AutoscrollController(page); |
| 51 } | 82 } |
| 52 | 83 |
| 53 AutoscrollController::AutoscrollController(Page& page) | 84 AutoscrollController::AutoscrollController(Page& page) : page_(&page) {} |
| 54 : page_(&page), | |
| 55 autoscroll_layout_object_(nullptr), | |
| 56 pressed_layout_object_(nullptr), | |
| 57 autoscroll_type_(kNoAutoscroll), | |
| 58 did_latch_for_middle_click_autoscroll_(false) {} | |
| 59 | 85 |
| 60 DEFINE_TRACE(AutoscrollController) { | 86 DEFINE_TRACE(AutoscrollController) { |
| 61 visitor->Trace(page_); | 87 visitor->Trace(page_); |
| 62 } | 88 } |
| 63 | 89 |
| 64 bool AutoscrollController::AutoscrollInProgress() const { | 90 bool AutoscrollController::SelectionAutoscrollInProgress() const { |
| 65 return autoscroll_type_ == kAutoscrollForSelection; | 91 return autoscroll_type_ == kAutoscrollForSelection; |
| 66 } | 92 } |
| 67 | 93 |
| 68 bool AutoscrollController::AutoscrollInProgress( | 94 bool AutoscrollController::AutoscrollInProgress( |
| 69 const LayoutBox* layout_object) const { | 95 const LayoutBox* layout_object) const { |
| 70 return autoscroll_layout_object_ == layout_object; | 96 return autoscroll_layout_object_ == layout_object; |
| 71 } | 97 } |
| 72 | 98 |
| 73 void AutoscrollController::StartAutoscrollForSelection( | 99 void AutoscrollController::StartAutoscrollForSelection( |
| 74 LayoutObject* layout_object) { | 100 LayoutObject* layout_object) { |
| 75 // We don't want to trigger the autoscroll or the middleClickAutoscroll if | 101 // We don't want to trigger the autoscroll or the middleClickAutoscroll if |
| 76 // it's already active. | 102 // it's already active. |
| 77 if (autoscroll_type_ != kNoAutoscroll) | 103 if (autoscroll_type_ != kNoAutoscroll) |
| 78 return; | 104 return; |
| 79 LayoutBox* scrollable = LayoutBox::FindAutoscrollable(layout_object); | 105 LayoutBox* scrollable = LayoutBox::FindAutoscrollable(layout_object); |
| 80 if (!scrollable) | 106 if (!scrollable) |
| 81 scrollable = | 107 scrollable = |
| 82 layout_object->IsListBox() ? ToLayoutListBox(layout_object) : nullptr; | 108 layout_object->IsListBox() ? ToLayoutListBox(layout_object) : nullptr; |
| 83 if (!scrollable) | 109 if (!scrollable) |
| 84 return; | 110 return; |
| 85 | 111 |
| 86 pressed_layout_object_ = layout_object && layout_object->IsBox() | 112 pressed_layout_object_ = layout_object && layout_object->IsBox() |
| 87 ? ToLayoutBox(layout_object) | 113 ? ToLayoutBox(layout_object) |
| 88 : nullptr; | 114 : nullptr; |
| 89 autoscroll_type_ = kAutoscrollForSelection; | 115 autoscroll_type_ = kAutoscrollForSelection; |
| 90 autoscroll_layout_object_ = scrollable; | 116 autoscroll_layout_object_ = scrollable; |
| 91 StartAutoscroll(); | 117 ScheduleMainThreadAnimation(); |
| 92 } | 118 } |
| 93 | 119 |
| 94 void AutoscrollController::StopAutoscroll() { | 120 void AutoscrollController::StopAutoscroll() { |
| 95 if (pressed_layout_object_) { | 121 if (pressed_layout_object_) { |
| 96 pressed_layout_object_->StopAutoscroll(); | 122 pressed_layout_object_->StopAutoscroll(); |
| 97 pressed_layout_object_ = nullptr; | 123 pressed_layout_object_ = nullptr; |
| 98 } | 124 } |
| 99 LayoutBox* scrollable = autoscroll_layout_object_; | |
| 100 autoscroll_layout_object_ = nullptr; | 125 autoscroll_layout_object_ = nullptr; |
| 101 | |
| 102 if (!scrollable) | |
| 103 return; | |
| 104 | |
| 105 if (RuntimeEnabledFeatures::MiddleClickAutoscrollEnabled() && | |
| 106 MiddleClickAutoscrollInProgress()) { | |
| 107 if (LocalFrameView* view = scrollable->GetFrame()->View()) { | |
| 108 view->SetCursor(PointerCursor()); | |
| 109 } | |
| 110 } | |
| 111 autoscroll_type_ = kNoAutoscroll; | 126 autoscroll_type_ = kNoAutoscroll; |
| 112 } | 127 } |
| 113 | 128 |
| 114 void AutoscrollController::StopAutoscrollIfNeeded(LayoutObject* layout_object) { | 129 void AutoscrollController::StopAutoscrollIfNeeded(LayoutObject* layout_object) { |
| 115 if (pressed_layout_object_ == layout_object) | 130 if (pressed_layout_object_ == layout_object) |
| 116 pressed_layout_object_ = nullptr; | 131 pressed_layout_object_ = nullptr; |
| 117 | 132 |
| 118 if (autoscroll_layout_object_ != layout_object) | 133 if (autoscroll_layout_object_ != layout_object) |
| 119 return; | 134 return; |
| 120 autoscroll_layout_object_ = nullptr; | 135 autoscroll_layout_object_ = nullptr; |
| 121 autoscroll_type_ = kNoAutoscroll; | 136 autoscroll_type_ = kNoAutoscroll; |
| 122 } | 137 } |
| 123 | 138 |
| 124 void AutoscrollController::UpdateAutoscrollLayoutObject() { | 139 void AutoscrollController::UpdateAutoscrollLayoutObject() { |
| 125 if (!autoscroll_layout_object_) | 140 if (!autoscroll_layout_object_) |
| 126 return; | 141 return; |
| 127 | 142 |
| 128 LayoutObject* layout_object = autoscroll_layout_object_; | 143 LayoutObject* layout_object = autoscroll_layout_object_; |
| 129 | 144 |
| 130 if (RuntimeEnabledFeatures::MiddleClickAutoscrollEnabled()) { | |
| 131 HitTestResult hit_test = | |
| 132 layout_object->GetFrame()->GetEventHandler().HitTestResultAtPoint( | |
| 133 middle_click_autoscroll_start_pos_, | |
| 134 HitTestRequest::kReadOnly | HitTestRequest::kActive); | |
| 135 | |
| 136 if (Node* node_at_point = hit_test.InnerNode()) | |
| 137 layout_object = node_at_point->GetLayoutObject(); | |
| 138 } | |
| 139 | |
| 140 while (layout_object && !(layout_object->IsBox() && | 145 while (layout_object && !(layout_object->IsBox() && |
| 141 ToLayoutBox(layout_object)->CanAutoscroll())) | 146 ToLayoutBox(layout_object)->CanAutoscroll())) |
| 142 layout_object = layout_object->Parent(); | 147 layout_object = layout_object->Parent(); |
| 143 | 148 |
| 144 autoscroll_layout_object_ = layout_object && layout_object->IsBox() | 149 autoscroll_layout_object_ = layout_object && layout_object->IsBox() |
| 145 ? ToLayoutBox(layout_object) | 150 ? ToLayoutBox(layout_object) |
| 146 : nullptr; | 151 : nullptr; |
| 147 | 152 |
| 148 if (autoscroll_type_ != kNoAutoscroll && !autoscroll_layout_object_) | 153 if (!autoscroll_layout_object_) |
| 149 autoscroll_type_ = kNoAutoscroll; | 154 autoscroll_type_ = kNoAutoscroll; |
| 150 } | 155 } |
| 151 | 156 |
| 152 void AutoscrollController::UpdateDragAndDrop(Node* drop_target_node, | 157 void AutoscrollController::UpdateDragAndDrop(Node* drop_target_node, |
| 153 const IntPoint& event_position, | 158 const IntPoint& event_position, |
| 154 TimeTicks event_time) { | 159 TimeTicks event_time) { |
| 155 if (!drop_target_node || !drop_target_node->GetLayoutObject()) { | 160 if (!drop_target_node || !drop_target_node->GetLayoutObject()) { |
| 156 StopAutoscroll(); | 161 StopAutoscroll(); |
| 157 return; | 162 return; |
| 158 } | 163 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 187 } | 192 } |
| 188 | 193 |
| 189 drag_and_drop_autoscroll_reference_position_ = event_position + offset; | 194 drag_and_drop_autoscroll_reference_position_ = event_position + offset; |
| 190 | 195 |
| 191 if (autoscroll_type_ == kNoAutoscroll) { | 196 if (autoscroll_type_ == kNoAutoscroll) { |
| 192 autoscroll_type_ = kAutoscrollForDragAndDrop; | 197 autoscroll_type_ = kAutoscrollForDragAndDrop; |
| 193 autoscroll_layout_object_ = scrollable; | 198 autoscroll_layout_object_ = scrollable; |
| 194 drag_and_drop_autoscroll_start_time_ = event_time; | 199 drag_and_drop_autoscroll_start_time_ = event_time; |
| 195 UseCounter::Count(autoscroll_layout_object_->GetFrame(), | 200 UseCounter::Count(autoscroll_layout_object_->GetFrame(), |
| 196 WebFeature::kDragAndDropScrollStart); | 201 WebFeature::kDragAndDropScrollStart); |
| 197 StartAutoscroll(); | 202 ScheduleMainThreadAnimation(); |
| 198 } else if (autoscroll_layout_object_ != scrollable) { | 203 } else if (autoscroll_layout_object_ != scrollable) { |
| 199 drag_and_drop_autoscroll_start_time_ = event_time; | 204 drag_and_drop_autoscroll_start_time_ = event_time; |
| 200 autoscroll_layout_object_ = scrollable; | 205 autoscroll_layout_object_ = scrollable; |
| 201 } | 206 } |
| 202 } | 207 } |
| 203 | 208 |
| 204 void AutoscrollController::HandleMouseReleaseForMiddleClickAutoscroll( | 209 void AutoscrollController::HandleMouseMoveForMiddleClickAutoscroll( |
| 205 LocalFrame* frame, | 210 LocalFrame* frame, |
| 206 const WebMouseEvent& mouse_event) { | 211 const FloatPoint& position_global, |
| 207 DCHECK(RuntimeEnabledFeatures::MiddleClickAutoscrollEnabled()); | 212 bool is_middle_button) { |
| 208 if (!frame->IsMainFrame()) | 213 if (!MiddleClickAutoscrollInProgress()) |
| 209 return; | 214 return; |
| 210 switch (autoscroll_type_) { | 215 |
| 211 case kAutoscrollForMiddleClick: | 216 LocalFrameView* view = frame->View(); |
| 212 if (mouse_event.button == WebPointerProperties::Button::kMiddle) | 217 if (!view) |
| 213 autoscroll_type_ = kAutoscrollForMiddleClickCanStop; | 218 return; |
| 214 break; | 219 |
| 215 case kAutoscrollForMiddleClickCanStop: | 220 FloatSize distance = |
| 216 StopAutoscroll(); | 221 (position_global - middle_click_autoscroll_start_pos_global_) |
| 217 break; | 222 .ScaledBy(1 / frame->DevicePixelRatio()); |
| 218 case kAutoscrollForDragAndDrop: | 223 |
| 219 case kAutoscrollForSelection: | 224 if (fabs(distance.Width()) <= kNoMiddleClickAutoscrollRadius) |
| 220 case kNoAutoscroll: | 225 distance.SetWidth(0); |
| 221 // Nothing to do. | 226 if (fabs(distance.Height()) <= kNoMiddleClickAutoscrollRadius) |
| 222 break; | 227 distance.SetHeight(0); |
| 228 | |
| 229 const float kExponent = 1.1f; | |
| 230 const float kMultiplier = -0.002f; | |
| 231 const int x_signum = (distance.Width() < 0) ? -1 : (distance.Width() > 0); | |
| 232 const int y_signum = (distance.Height() < 0) ? -1 : (distance.Height() > 0); | |
| 233 FloatSize velocity( | |
| 234 pow(fabs(distance.Width()), kExponent) * kMultiplier * x_signum, | |
| 235 pow(fabs(distance.Height()), kExponent) * kMultiplier * y_signum); | |
| 236 | |
| 237 if (velocity != last_velocity_) { | |
| 238 last_velocity_ = velocity; | |
| 239 if (middle_click_mode_ == kMiddleClickInitial) | |
| 240 middle_click_mode_ = kMiddleClickHolding; | |
| 241 view->SetCursor(MiddleClickAutoscrollCursor(velocity)); | |
| 242 page_->GetChromeClient().AutoscrollFling(velocity, frame); | |
| 223 } | 243 } |
| 224 } | 244 } |
| 225 | 245 |
| 246 void AutoscrollController::HandleMouseReleaseForMiddleClickAutoscroll( | |
| 247 LocalFrame* frame, | |
| 248 bool is_middle_button) { | |
| 249 DCHECK(RuntimeEnabledFeatures::MiddleClickAutoscrollEnabled()); | |
| 250 if (!MiddleClickAutoscrollInProgress()) | |
| 251 return; | |
| 252 | |
| 253 if (!frame->IsMainFrame()) | |
| 254 return; | |
| 255 | |
| 256 if (middle_click_mode_ == kMiddleClickInitial && is_middle_button) { | |
|
bokan
2017/06/15 17:40:13
Nit: no braces
aelias_OOO_until_Jul13
2017/06/15 22:19:54
Done.
| |
| 257 middle_click_mode_ = kMiddleClickToggled; | |
| 258 } else if (middle_click_mode_ == kMiddleClickHolding) { | |
| 259 StopMiddleClickAutoscroll(frame); | |
| 260 } | |
| 261 } | |
| 262 | |
| 263 void AutoscrollController::StopMiddleClickAutoscroll(LocalFrame* frame) { | |
|
bokan
2017/06/15 17:40:13
I don't see where you reset the cursor on stopping
aelias_OOO_until_Jul13
2017/06/15 22:19:54
Good catch, there was a cursor reset bug if you re
| |
| 264 if (!MiddleClickAutoscrollInProgress()) | |
| 265 return; | |
| 266 | |
| 267 page_->GetChromeClient().AutoscrollEnd(frame); | |
| 268 autoscroll_type_ = kNoAutoscroll; | |
| 269 } | |
| 270 | |
| 226 bool AutoscrollController::MiddleClickAutoscrollInProgress() const { | 271 bool AutoscrollController::MiddleClickAutoscrollInProgress() const { |
| 227 return autoscroll_type_ == kAutoscrollForMiddleClickCanStop || | 272 return autoscroll_type_ == kAutoscrollForMiddleClick; |
| 228 autoscroll_type_ == kAutoscrollForMiddleClick; | |
| 229 } | 273 } |
| 230 | 274 |
| 231 void AutoscrollController::StartMiddleClickAutoscroll( | 275 void AutoscrollController::StartMiddleClickAutoscroll( |
| 232 LayoutBox* scrollable, | 276 LocalFrame* frame, |
| 233 const IntPoint& last_known_mouse_position) { | 277 const FloatPoint& position, |
| 278 const FloatPoint& position_global) { | |
| 234 DCHECK(RuntimeEnabledFeatures::MiddleClickAutoscrollEnabled()); | 279 DCHECK(RuntimeEnabledFeatures::MiddleClickAutoscrollEnabled()); |
| 235 // We don't want to trigger the autoscroll or the middleClickAutoscroll if | 280 // We don't want to trigger the autoscroll or the middleClickAutoscroll if |
| 236 // it's already active. | 281 // it's already active. |
| 237 if (autoscroll_type_ != kNoAutoscroll) | 282 if (autoscroll_type_ != kNoAutoscroll) |
| 238 return; | 283 return; |
| 239 | 284 |
| 240 autoscroll_type_ = kAutoscrollForMiddleClick; | 285 autoscroll_type_ = kAutoscrollForMiddleClick; |
| 241 autoscroll_layout_object_ = scrollable; | 286 middle_click_mode_ = kMiddleClickInitial; |
| 242 middle_click_autoscroll_start_pos_ = last_known_mouse_position; | 287 middle_click_autoscroll_start_pos_global_ = position_global; |
| 243 did_latch_for_middle_click_autoscroll_ = false; | |
| 244 | 288 |
| 245 UseCounter::Count(autoscroll_layout_object_->GetFrame(), | 289 UseCounter::Count(frame, WebFeature::kMiddleClickAutoscrollStart); |
| 246 WebFeature::kMiddleClickAutoscrollStart); | |
| 247 StartAutoscroll(); | |
| 248 } | |
| 249 | 290 |
| 250 static inline int AdjustedScrollDelta(int beginning_delta) { | 291 last_velocity_ = FloatSize(); |
| 251 // This implemention matches Firefox's. | 292 if (LocalFrameView* view = frame->View()) |
| 252 // http://mxr.mozilla.org/firefox/source/toolkit/content/widgets/browser.xml#8 56. | 293 view->SetCursor(MiddleClickAutoscrollCursor(last_velocity_)); |
| 253 const int kSpeedReducer = 12; | 294 page_->GetChromeClient().AutoscrollStart( |
| 254 | 295 position.ScaledBy(1 / frame->DevicePixelRatio()), frame); |
| 255 int adjusted_delta = beginning_delta / kSpeedReducer; | |
| 256 if (adjusted_delta > 1) { | |
| 257 adjusted_delta = | |
| 258 static_cast<int>(adjusted_delta * | |
| 259 sqrt(static_cast<double>(adjusted_delta))) - | |
| 260 1; | |
| 261 } else if (adjusted_delta < -1) { | |
| 262 adjusted_delta = | |
| 263 static_cast<int>(adjusted_delta * | |
| 264 sqrt(static_cast<double>(-adjusted_delta))) + | |
| 265 1; | |
| 266 } | |
| 267 | |
| 268 return adjusted_delta; | |
| 269 } | |
| 270 | |
| 271 static inline IntSize AdjustedScrollDelta(const IntSize& delta) { | |
| 272 return IntSize(AdjustedScrollDelta(delta.Width()), | |
| 273 AdjustedScrollDelta(delta.Height())); | |
| 274 } | |
| 275 | |
| 276 FloatSize AutoscrollController::CalculateAutoscrollDelta() { | |
| 277 LocalFrame* frame = autoscroll_layout_object_->GetFrame(); | |
| 278 if (!frame) | |
| 279 return FloatSize(); | |
| 280 | |
| 281 IntPoint last_known_mouse_position = | |
| 282 frame->GetEventHandler().LastKnownMousePosition(); | |
| 283 | |
| 284 // We need to check if the last known mouse position is out of the window. | |
| 285 // When the mouse is out of the window, the position is incoherent | |
| 286 static IntPoint previous_mouse_position; | |
| 287 if (last_known_mouse_position.X() < 0 || last_known_mouse_position.Y() < 0) | |
| 288 last_known_mouse_position = previous_mouse_position; | |
| 289 else | |
| 290 previous_mouse_position = last_known_mouse_position; | |
| 291 | |
| 292 IntSize delta = | |
| 293 last_known_mouse_position - middle_click_autoscroll_start_pos_; | |
| 294 | |
| 295 // at the center we let the space for the icon. | |
| 296 if (abs(delta.Width()) <= kNoMiddleClickAutoscrollRadius) | |
| 297 delta.SetWidth(0); | |
| 298 if (abs(delta.Height()) <= kNoMiddleClickAutoscrollRadius) | |
| 299 delta.SetHeight(0); | |
| 300 return FloatSize(AdjustedScrollDelta(delta)); | |
| 301 } | 296 } |
| 302 | 297 |
| 303 void AutoscrollController::Animate(double) { | 298 void AutoscrollController::Animate(double) { |
| 299 // Middle-click autoscroll isn't handled on the main thread. | |
| 300 if (MiddleClickAutoscrollInProgress()) | |
| 301 return; | |
| 302 | |
| 304 if (!autoscroll_layout_object_ || !autoscroll_layout_object_->GetFrame()) { | 303 if (!autoscroll_layout_object_ || !autoscroll_layout_object_->GetFrame()) { |
| 305 StopAutoscroll(); | 304 StopAutoscroll(); |
| 306 return; | 305 return; |
| 307 } | 306 } |
| 308 | 307 |
| 309 EventHandler& event_handler = | 308 EventHandler& event_handler = |
| 310 autoscroll_layout_object_->GetFrame()->GetEventHandler(); | 309 autoscroll_layout_object_->GetFrame()->GetEventHandler(); |
| 311 IntSize offset = autoscroll_layout_object_->CalculateAutoscrollDirection( | 310 IntSize offset = autoscroll_layout_object_->CalculateAutoscrollDirection( |
| 312 event_handler.LastKnownMousePosition()); | 311 event_handler.LastKnownMousePosition()); |
| 313 IntPoint selection_point = event_handler.LastKnownMousePosition() + offset; | 312 IntPoint selection_point = event_handler.LastKnownMousePosition() + offset; |
| 314 switch (autoscroll_type_) { | 313 switch (autoscroll_type_) { |
| 315 case kAutoscrollForDragAndDrop: | 314 case kAutoscrollForDragAndDrop: |
| 315 ScheduleMainThreadAnimation(); | |
| 316 if ((TimeTicks::Now() - drag_and_drop_autoscroll_start_time_) > | 316 if ((TimeTicks::Now() - drag_and_drop_autoscroll_start_time_) > |
| 317 kAutoscrollDelay) | 317 kAutoscrollDelay) |
| 318 autoscroll_layout_object_->Autoscroll( | 318 autoscroll_layout_object_->Autoscroll( |
| 319 drag_and_drop_autoscroll_reference_position_); | 319 drag_and_drop_autoscroll_reference_position_); |
| 320 break; | 320 break; |
| 321 case kAutoscrollForSelection: | 321 case kAutoscrollForSelection: |
| 322 if (!event_handler.MousePressed()) { | 322 if (!event_handler.MousePressed()) { |
| 323 StopAutoscroll(); | 323 StopAutoscroll(); |
| 324 return; | 324 return; |
| 325 } | 325 } |
| 326 event_handler.UpdateSelectionForMouseDrag(); | 326 event_handler.UpdateSelectionForMouseDrag(); |
| 327 ScheduleMainThreadAnimation(); | |
| 327 autoscroll_layout_object_->Autoscroll(selection_point); | 328 autoscroll_layout_object_->Autoscroll(selection_point); |
| 328 break; | 329 break; |
| 329 case kNoAutoscroll: | 330 case kNoAutoscroll: |
| 331 case kAutoscrollForMiddleClick: | |
| 330 break; | 332 break; |
| 331 case kAutoscrollForMiddleClickCanStop: | |
| 332 case kAutoscrollForMiddleClick: | |
| 333 DCHECK(RuntimeEnabledFeatures::MiddleClickAutoscrollEnabled()); | |
| 334 if (!MiddleClickAutoscrollInProgress()) { | |
| 335 StopAutoscroll(); | |
| 336 return; | |
| 337 } | |
| 338 if (LocalFrameView* view = autoscroll_layout_object_->GetFrame()->View()) | |
| 339 UpdateMiddleClickAutoscrollState( | |
| 340 view, event_handler.LastKnownMousePosition()); | |
| 341 FloatSize delta = CalculateAutoscrollDelta(); | |
| 342 if (delta.IsZero()) | |
| 343 break; | |
| 344 ScrollResult result = | |
| 345 autoscroll_layout_object_->Scroll(kScrollByPixel, delta); | |
| 346 LayoutObject* layout_object = autoscroll_layout_object_; | |
| 347 while (!did_latch_for_middle_click_autoscroll_ && !result.DidScroll()) { | |
| 348 if (layout_object->GetNode() && | |
| 349 layout_object->GetNode()->IsDocumentNode()) { | |
| 350 Element* owner = ToDocument(layout_object->GetNode())->LocalOwner(); | |
| 351 layout_object = owner ? owner->GetLayoutObject() : nullptr; | |
| 352 } else { | |
| 353 layout_object = layout_object->Parent(); | |
| 354 } | |
| 355 if (!layout_object) { | |
| 356 break; | |
| 357 } | |
| 358 if (layout_object && layout_object->IsBox() && | |
| 359 ToLayoutBox(layout_object)->CanBeScrolledAndHasScrollableArea()) | |
| 360 result = ToLayoutBox(layout_object)->Scroll(kScrollByPixel, delta); | |
| 361 } | |
| 362 if (result.DidScroll()) { | |
| 363 did_latch_for_middle_click_autoscroll_ = true; | |
| 364 autoscroll_layout_object_ = ToLayoutBox(layout_object); | |
| 365 } | |
| 366 break; | |
| 367 } | |
| 368 if (autoscroll_type_ != kNoAutoscroll && autoscroll_layout_object_) { | |
| 369 page_->GetChromeClient().ScheduleAnimation( | |
| 370 autoscroll_layout_object_->GetFrame()->View()); | |
| 371 } | 333 } |
| 372 } | 334 } |
| 373 | 335 |
| 374 void AutoscrollController::StartAutoscroll() { | 336 void AutoscrollController::ScheduleMainThreadAnimation() { |
| 375 page_->GetChromeClient().ScheduleAnimation( | 337 page_->GetChromeClient().ScheduleAnimation( |
| 376 autoscroll_layout_object_->GetFrame()->View()); | 338 autoscroll_layout_object_->GetFrame()->View()); |
| 377 } | 339 } |
| 378 | 340 |
| 379 void AutoscrollController::UpdateMiddleClickAutoscrollState( | |
| 380 LocalFrameView* view, | |
| 381 const IntPoint& last_known_mouse_position) { | |
| 382 DCHECK(RuntimeEnabledFeatures::MiddleClickAutoscrollEnabled()); | |
| 383 // At the original click location we draw a 4 arrowed icon. Over this icon | |
| 384 // there won't be any scroll, So don't change the cursor over this area. | |
| 385 bool east = middle_click_autoscroll_start_pos_.X() < | |
| 386 (last_known_mouse_position.X() - kNoMiddleClickAutoscrollRadius); | |
| 387 bool west = middle_click_autoscroll_start_pos_.X() > | |
| 388 (last_known_mouse_position.X() + kNoMiddleClickAutoscrollRadius); | |
| 389 bool north = middle_click_autoscroll_start_pos_.Y() > | |
| 390 (last_known_mouse_position.Y() + kNoMiddleClickAutoscrollRadius); | |
| 391 bool south = middle_click_autoscroll_start_pos_.Y() < | |
| 392 (last_known_mouse_position.Y() - kNoMiddleClickAutoscrollRadius); | |
| 393 | |
| 394 if (autoscroll_type_ == kAutoscrollForMiddleClick && | |
| 395 (east || west || north || south)) | |
| 396 autoscroll_type_ = kAutoscrollForMiddleClickCanStop; | |
| 397 | |
| 398 if (north) { | |
| 399 if (east) | |
| 400 view->SetCursor(NorthEastPanningCursor()); | |
| 401 else if (west) | |
| 402 view->SetCursor(NorthWestPanningCursor()); | |
| 403 else | |
| 404 view->SetCursor(NorthPanningCursor()); | |
| 405 } else if (south) { | |
| 406 if (east) | |
| 407 view->SetCursor(SouthEastPanningCursor()); | |
| 408 else if (west) | |
| 409 view->SetCursor(SouthWestPanningCursor()); | |
| 410 else | |
| 411 view->SetCursor(SouthPanningCursor()); | |
| 412 } else if (east) { | |
| 413 view->SetCursor(EastPanningCursor()); | |
| 414 } else if (west) { | |
| 415 view->SetCursor(WestPanningCursor()); | |
| 416 } else { | |
| 417 view->SetCursor(MiddlePanningCursor()); | |
| 418 } | |
| 419 } | |
| 420 | |
| 421 } // namespace blink | 341 } // namespace blink |
| OLD | NEW |