| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/input/ScrollManager.h" | 5 #include "core/input/ScrollManager.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMNodeIds.h" | 7 #include "core/dom/DOMNodeIds.h" |
| 8 #include "core/events/GestureEvent.h" | 8 #include "core/events/GestureEvent.h" |
| 9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 11 #include "core/frame/TopControls.h" | 11 #include "core/frame/TopControls.h" |
| 12 #include "core/html/HTMLFrameOwnerElement.h" | 12 #include "core/html/HTMLFrameOwnerElement.h" |
| 13 #include "core/input/EventHandler.h" | 13 #include "core/input/EventHandler.h" |
| 14 #include "core/layout/LayoutPart.h" | 14 #include "core/layout/LayoutPart.h" |
| 15 #include "core/loader/DocumentLoader.h" | 15 #include "core/loader/DocumentLoader.h" |
| 16 #include "core/page/AutoscrollController.h" | 16 #include "core/page/AutoscrollController.h" |
| 17 #include "core/page/Page.h" | 17 #include "core/page/Page.h" |
| 18 #include "core/page/scrolling/OverscrollController.h" | 18 #include "core/page/scrolling/OverscrollController.h" |
| 19 #include "core/page/scrolling/ScrollState.h" | 19 #include "core/page/scrolling/ScrollState.h" |
| 20 #include "core/paint/PaintLayer.h" | 20 #include "core/paint/PaintLayer.h" |
| 21 #include "platform/PlatformGestureEvent.h" | 21 #include "platform/PlatformGestureEvent.h" |
| 22 #include "wtf/PtrUtil.h" | 22 #include "wtf/PtrUtil.h" |
| 23 #include <memory> | 23 #include <memory> |
| 24 | 24 |
| 25 | 25 |
| 26 namespace blink { | 26 namespace blink { |
| 27 | 27 |
| 28 namespace { | |
| 29 | |
| 30 // TODO(bokan): This method can go away once all scrolls happen through the | |
| 31 // scroll customization path. | |
| 32 void computeScrollChainForSingleNode(Node& node, std::deque<int>& scrollChain) | |
| 33 { | |
| 34 scrollChain.clear(); | |
| 35 | |
| 36 DCHECK(node.layoutObject()); | |
| 37 Element* element = toElement(&node); | |
| 38 | |
| 39 scrollChain.push_front(DOMNodeIds::idForNode(element)); | |
| 40 } | |
| 41 | |
| 42 void recomputeScrollChain(const LocalFrame& frame, const Node& startNode, | |
| 43 std::deque<int>& scrollChain) | |
| 44 { | |
| 45 scrollChain.clear(); | |
| 46 | |
| 47 DCHECK(startNode.layoutObject()); | |
| 48 LayoutBox* curBox = startNode.layoutObject()->enclosingBox(); | |
| 49 | |
| 50 // Scrolling propagates along the containing block chain. | |
| 51 while (curBox && !curBox->isLayoutView()) { | |
| 52 Node* curNode = curBox->node(); | |
| 53 // FIXME: this should reject more elements, as part of crbug.com/410974. | |
| 54 if (curNode && curNode->isElementNode()) { | |
| 55 Element* curElement = toElement(curNode); | |
| 56 if (curElement == frame.document()->scrollingElement()) | |
| 57 break; | |
| 58 scrollChain.push_front(DOMNodeIds::idForNode(curElement)); | |
| 59 } | |
| 60 curBox = curBox->containingBlock(); | |
| 61 } | |
| 62 // TODO(tdresser): this should sometimes be excluded, as part of crbug.com/4
10974. | |
| 63 // We need to ensure that the scrollingElement is always part of | |
| 64 // the scroll chain. In quirks mode, when the scrollingElement is | |
| 65 // the body, some elements may use the documentElement as their | |
| 66 // containingBlock, so we ensure the scrollingElement is added | |
| 67 // here. | |
| 68 scrollChain.push_front(DOMNodeIds::idForNode(frame.document()->scrollingElem
ent())); | |
| 69 } | |
| 70 | |
| 71 } // namespace | |
| 72 | |
| 73 ScrollManager::ScrollManager(LocalFrame* frame) | 28 ScrollManager::ScrollManager(LocalFrame* frame) |
| 74 : m_frame(frame) | 29 : m_frame(frame) |
| 75 { | 30 { |
| 76 clear(); | 31 clear(); |
| 77 } | 32 } |
| 78 | 33 |
| 79 ScrollManager::~ScrollManager() | 34 ScrollManager::~ScrollManager() |
| 80 { | 35 { |
| 81 } | 36 } |
| 82 | 37 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return autoscrollController() && autoscrollController()->panScrollInProgress
(); | 69 return autoscrollController() && autoscrollController()->panScrollInProgress
(); |
| 115 } | 70 } |
| 116 | 71 |
| 117 AutoscrollController* ScrollManager::autoscrollController() const | 72 AutoscrollController* ScrollManager::autoscrollController() const |
| 118 { | 73 { |
| 119 if (Page* page = m_frame->page()) | 74 if (Page* page = m_frame->page()) |
| 120 return &page->autoscrollController(); | 75 return &page->autoscrollController(); |
| 121 return nullptr; | 76 return nullptr; |
| 122 } | 77 } |
| 123 | 78 |
| 124 ScrollResult ScrollManager::physicalScroll(ScrollGranularity granularity, | 79 void ScrollManager::recomputeScrollChain(const Node& startNode, |
| 125 const FloatSize& delta, const FloatPoint& position, | 80 std::deque<int>& scrollChain) |
| 126 const FloatSize& velocity, Node* startNode, Node** stopNode, bool* consumed) | |
| 127 { | 81 { |
| 128 if (consumed) | 82 scrollChain.clear(); |
| 129 *consumed = false; | |
| 130 if (delta.isZero()) | |
| 131 return ScrollResult(); | |
| 132 | 83 |
| 133 Node* node = startNode; | 84 DCHECK(startNode.layoutObject()); |
| 134 DCHECK(node && node->layoutObject()); | 85 LayoutBox* curBox = startNode.layoutObject()->enclosingBox(); |
| 135 | 86 |
| 136 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 87 // Scrolling propagates along the containing block chain and ends at the |
| 88 // RootScroller element. The RootScroller element will have a custom |
| 89 // applyScroll callback that scrolls the frame or element. |
| 90 while (curBox) { |
| 91 Node* curNode = curBox->node(); |
| 92 Element* curElement = nullptr; |
| 137 | 93 |
| 138 ScrollResult result; | 94 // FIXME: this should reject more elements, as part of crbug.com/410974. |
| 95 if (curNode && curNode->isElementNode()) { |
| 96 curElement = toElement(curNode); |
| 97 } else if (curNode && curNode->isDocumentNode()) { |
| 98 // In normal circumastances, the documentElement will be the root |
| 99 // scroller but the documentElement itself isn't a containing block, |
| 100 // that'll be the document node rather than the element. |
| 101 curElement = m_frame->document()->documentElement(); |
| 102 DCHECK(!curElement || isEffectiveRootScroller(*curElement)); |
| 103 } |
| 139 | 104 |
| 140 LayoutBox* curBox = node->layoutObject()->enclosingBox(); | 105 if (curElement) { |
| 141 while (curBox) { | 106 scrollChain.push_front(DOMNodeIds::idForNode(curElement)); |
| 142 // If we're at the stopNode, we should try to scroll it but we shouldn't | 107 if (isEffectiveRootScroller(*curElement)) |
| 143 // chain past it. | 108 break; |
| 144 bool shouldStopChaining = | |
| 145 stopNode && *stopNode && curBox->node() == *stopNode; | |
| 146 bool wasRootScroller = false; | |
| 147 | |
| 148 result = scrollBox( | |
| 149 curBox, | |
| 150 granularity, | |
| 151 delta, | |
| 152 position, | |
| 153 velocity, | |
| 154 &wasRootScroller); | |
| 155 | |
| 156 if (result.didScroll() && stopNode) | |
| 157 *stopNode = curBox->node(); | |
| 158 | |
| 159 if (result.didScroll() || shouldStopChaining) { | |
| 160 setFrameWasScrolledByUser(); | |
| 161 if (consumed) | |
| 162 *consumed = true; | |
| 163 return result; | |
| 164 } | |
| 165 if (wasRootScroller) { | |
| 166 // Don't try to chain past the root scroller, even if there's | |
| 167 // eligible ancestors. | |
| 168 break; | |
| 169 } | 109 } |
| 170 | 110 |
| 171 curBox = curBox->containingBlock(); | 111 curBox = curBox->containingBlock(); |
| 172 } | 112 } |
| 173 | |
| 174 return result; | |
| 175 } | 113 } |
| 176 | 114 |
| 177 bool ScrollManager::logicalScroll(ScrollDirection direction, ScrollGranularity g
ranularity, Node* startNode, Node* mousePressNode) | 115 bool ScrollManager::logicalScroll(ScrollDirection direction, ScrollGranularity g
ranularity, Node* startNode, Node* mousePressNode) |
| 178 { | 116 { |
| 179 Node* node = startNode; | 117 Node* node = startNode; |
| 180 | 118 |
| 181 if (!node) | 119 if (!node) |
| 182 node = m_frame->document()->focusedElement(); | 120 node = m_frame->document()->focusedElement(); |
| 183 | 121 |
| 184 if (!node) | 122 if (!node) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (logicalScroll(direction, granularity, startingNode, mousePressNode)) | 159 if (logicalScroll(direction, granularity, startingNode, mousePressNode)) |
| 222 return true; | 160 return true; |
| 223 | 161 |
| 224 Frame* parentFrame = m_frame->tree().parent(); | 162 Frame* parentFrame = m_frame->tree().parent(); |
| 225 if (!parentFrame || !parentFrame->isLocalFrame()) | 163 if (!parentFrame || !parentFrame->isLocalFrame()) |
| 226 return false; | 164 return false; |
| 227 // FIXME: Broken for OOPI. | 165 // FIXME: Broken for OOPI. |
| 228 return toLocalFrame(parentFrame)->eventHandler().bubblingScroll(direction, g
ranularity, m_frame->deprecatedLocalOwner()); | 166 return toLocalFrame(parentFrame)->eventHandler().bubblingScroll(direction, g
ranularity, m_frame->deprecatedLocalOwner()); |
| 229 } | 167 } |
| 230 | 168 |
| 231 ScrollResult ScrollManager::scrollBox(LayoutBox* box, | |
| 232 ScrollGranularity granularity, const FloatSize& delta, | |
| 233 const FloatPoint& position, const FloatSize& velocity, | |
| 234 bool* wasRootScroller) | |
| 235 { | |
| 236 DCHECK(box); | |
| 237 Node* node = box->node(); | |
| 238 | |
| 239 // If there's no ApplyScroll callback on the element, scroll as usuall in | |
| 240 // the non-scroll-customization case. | |
| 241 if (!node || !node->isElementNode() || !toElement(node)->getApplyScroll()) { | |
| 242 *wasRootScroller = false; | |
| 243 return box->scroll(granularity, delta); | |
| 244 } | |
| 245 | |
| 246 // If there is an ApplyScroll callback, its because we placed one on the | |
| 247 // root scroller to control top controls and overscroll. Invoke a scroll | |
| 248 // using parts of the scroll customization framework on just this element. | |
| 249 computeScrollChainForSingleNode(*node, m_currentScrollChain); | |
| 250 | |
| 251 std::unique_ptr<ScrollStateData> scrollStateData = wrapUnique(new ScrollStat
eData()); | |
| 252 scrollStateData->delta_x = delta.width(); | |
| 253 scrollStateData->delta_y = delta.height(); | |
| 254 scrollStateData->position_x = position.x(); | |
| 255 scrollStateData->position_y = position.y(); | |
| 256 // TODO(bokan): delta_granularity is meant to be the number of pixels per | |
| 257 // unit of delta but we can't determine that until we get to the area we'll | |
| 258 // scroll. This is a hack, we stuff the enum into the double value for | |
| 259 // now. | |
| 260 scrollStateData->delta_granularity = static_cast<double>(granularity); | |
| 261 scrollStateData->velocity_x = velocity.width(); | |
| 262 scrollStateData->velocity_y = velocity.height(); | |
| 263 scrollStateData->should_propagate = false; | |
| 264 scrollStateData->is_in_inertial_phase = false; | |
| 265 scrollStateData->from_user_input = true; | |
| 266 scrollStateData->delta_consumed_for_scroll_sequence = false; | |
| 267 ScrollState* scrollState = | |
| 268 ScrollState::create(std::move(scrollStateData)); | |
| 269 | |
| 270 customizedScroll(*node, *scrollState); | |
| 271 | |
| 272 ScrollResult result( | |
| 273 scrollState->deltaX() != delta.width(), | |
| 274 scrollState->deltaY() != delta.height(), | |
| 275 scrollState->deltaX(), | |
| 276 scrollState->deltaY()); | |
| 277 | |
| 278 *wasRootScroller = true; | |
| 279 m_currentScrollChain.clear(); | |
| 280 | |
| 281 return result; | |
| 282 } | |
| 283 | |
| 284 void ScrollManager::setFrameWasScrolledByUser() | 169 void ScrollManager::setFrameWasScrolledByUser() |
| 285 { | 170 { |
| 286 if (DocumentLoader* documentLoader = m_frame->loader().documentLoader()) | 171 if (DocumentLoader* documentLoader = m_frame->loader().documentLoader()) |
| 287 documentLoader->initialScrollState().wasScrolledByUser = true; | 172 documentLoader->initialScrollState().wasScrolledByUser = true; |
| 288 } | 173 } |
| 289 | 174 |
| 290 void ScrollManager::customizedScroll(const Node& startNode, ScrollState& scrollS
tate) | 175 void ScrollManager::customizedScroll(const Node& startNode, ScrollState& scrollS
tate) |
| 291 { | 176 { |
| 292 if (scrollState.fullyConsumed()) | 177 if (scrollState.fullyConsumed()) |
| 293 return; | 178 return; |
| 294 | 179 |
| 295 if (scrollState.deltaX() || scrollState.deltaY()) | 180 if (scrollState.deltaX() || scrollState.deltaY()) |
| 296 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 181 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 297 | 182 |
| 298 if (m_currentScrollChain.empty()) | 183 if (m_currentScrollChain.empty()) |
| 299 recomputeScrollChain(*m_frame, startNode, m_currentScrollChain); | 184 recomputeScrollChain(startNode, m_currentScrollChain); |
| 300 scrollState.setScrollChain(m_currentScrollChain); | 185 scrollState.setScrollChain(m_currentScrollChain); |
| 301 | 186 |
| 302 scrollState.distributeToScrollChainDescendant(); | 187 scrollState.distributeToScrollChainDescendant(); |
| 303 } | 188 } |
| 304 | 189 |
| 305 WebInputEventResult ScrollManager::handleGestureScrollBegin(const PlatformGestur
eEvent& gestureEvent) | 190 WebInputEventResult ScrollManager::handleGestureScrollBegin(const PlatformGestur
eEvent& gestureEvent) |
| 306 { | 191 { |
| 307 Document* document = m_frame->document(); | 192 Document* document = m_frame->document(); |
| 193 |
| 308 if (document->layoutViewItem().isNull()) | 194 if (document->layoutViewItem().isNull()) |
| 309 return WebInputEventResult::NotHandled; | 195 return WebInputEventResult::NotHandled; |
| 310 | 196 |
| 311 FrameView* view = m_frame->view(); | 197 FrameView* view = m_frame->view(); |
| 312 if (!view) | 198 if (!view) |
| 313 return WebInputEventResult::NotHandled; | 199 return WebInputEventResult::NotHandled; |
| 314 | 200 |
| 315 // If there's no layoutObject on the node, send the event to the nearest anc
estor with a layoutObject. | 201 // If there's no layoutObject on the node, send the event to the nearest anc
estor with a layoutObject. |
| 316 // Needed for <option> and <optgroup> elements so we can touch scroll <selec
t>s | 202 // Needed for <option> and <optgroup> elements so we can touch scroll <selec
t>s |
| 317 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->layoutOb
ject()) | 203 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->layoutOb
ject()) |
| 318 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado
wHostNode(); | 204 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado
wHostNode(); |
| 319 | 205 |
| 320 if (!m_scrollGestureHandlingNode) { | 206 if (!m_scrollGestureHandlingNode) |
| 321 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) | 207 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); |
| 322 m_scrollGestureHandlingNode = m_frame->document()->documentElement()
; | 208 |
| 323 else | |
| 324 return WebInputEventResult::NotHandled; | |
| 325 } | |
| 326 DCHECK(m_scrollGestureHandlingNode); | 209 DCHECK(m_scrollGestureHandlingNode); |
| 327 | 210 |
| 328 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->la
youtObject()); | 211 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->la
youtObject()); |
| 329 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) { | 212 |
| 330 m_currentScrollChain.clear(); | 213 m_currentScrollChain.clear(); |
| 331 std::unique_ptr<ScrollStateData> scrollStateData = wrapUnique(new Scroll
StateData()); | 214 std::unique_ptr<ScrollStateData> scrollStateData = wrapUnique(new ScrollStat
eData()); |
| 332 scrollStateData->position_x = gestureEvent.position().x(); | 215 scrollStateData->position_x = gestureEvent.position().x(); |
| 333 scrollStateData->position_y = gestureEvent.position().y(); | 216 scrollStateData->position_y = gestureEvent.position().y(); |
| 334 scrollStateData->is_beginning = true; | 217 scrollStateData->is_beginning = true; |
| 335 scrollStateData->from_user_input = true; | 218 scrollStateData->from_user_input = true; |
| 336 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsumedFor
ScrollSequence; | 219 scrollStateData->is_direct_manipulation = gestureEvent.source() == PlatformG
estureSourceTouchscreen; |
| 337 ScrollState* scrollState = ScrollState::create(std::move(scrollStateData
)); | 220 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsumedForScro
llSequence; |
| 338 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState); | 221 ScrollState* scrollState = ScrollState::create(std::move(scrollStateData)); |
| 339 } else { | 222 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState); |
| 340 if (m_frame->isMainFrame()) | |
| 341 m_frame->host()->topControls().scrollBegin(); | |
| 342 } | |
| 343 return WebInputEventResult::HandledSystem; | 223 return WebInputEventResult::HandledSystem; |
| 344 } | 224 } |
| 345 | 225 |
| 346 WebInputEventResult ScrollManager::handleGestureScrollUpdate(const PlatformGestu
reEvent& gestureEvent) | 226 WebInputEventResult ScrollManager::handleGestureScrollUpdate(const PlatformGestu
reEvent& gestureEvent) |
| 347 { | 227 { |
| 348 DCHECK_EQ(gestureEvent.type(), PlatformEvent::GestureScrollUpdate); | 228 DCHECK_EQ(gestureEvent.type(), PlatformEvent::GestureScrollUpdate); |
| 349 | 229 |
| 350 // Negate the deltas since the gesture event stores finger movement and | 230 // Negate the deltas since the gesture event stores finger movement and |
| 351 // scrolling occurs in the direction opposite the finger's movement | 231 // scrolling occurs in the direction opposite the finger's movement |
| 352 // direction. e.g. Finger moving up has negative event delta but causes the | 232 // direction. e.g. Finger moving up has negative event delta but causes the |
| 353 // page to scroll down causing positive scroll delta. | 233 // page to scroll down causing positive scroll delta. |
| 354 FloatSize delta(-gestureEvent.deltaX(), -gestureEvent.deltaY()); | 234 FloatSize delta(-gestureEvent.deltaX(), -gestureEvent.deltaY()); |
| 355 FloatSize velocity(-gestureEvent.velocityX(), -gestureEvent.velocityY()); | 235 FloatSize velocity(-gestureEvent.velocityX(), -gestureEvent.velocityY()); |
| 236 FloatPoint position(gestureEvent.position()); |
| 237 |
| 356 if (delta.isZero()) | 238 if (delta.isZero()) |
| 357 return WebInputEventResult::NotHandled; | 239 return WebInputEventResult::NotHandled; |
| 358 | 240 |
| 359 ScrollGranularity granularity = gestureEvent.deltaUnits(); | |
| 360 Node* node = m_scrollGestureHandlingNode.get(); | 241 Node* node = m_scrollGestureHandlingNode.get(); |
| 361 | 242 |
| 362 // Scroll customization is only available for touch. | 243 if (!node) |
| 363 bool handleScrollCustomization = RuntimeEnabledFeatures::scrollCustomization
Enabled() && gestureEvent.source() == PlatformGestureSourceTouchscreen; | 244 return WebInputEventResult::NotHandled; |
| 364 if (node) { | |
| 365 LayoutObject* layoutObject = node->layoutObject(); | |
| 366 if (!layoutObject) | |
| 367 return WebInputEventResult::NotHandled; | |
| 368 | 245 |
| 369 // Try to send the event to the correct view. | 246 LayoutObject* layoutObject = node->layoutObject(); |
| 370 WebInputEventResult result = passScrollGestureEventToWidget(gestureEvent
, layoutObject); | 247 if (!layoutObject) |
| 371 if (result != WebInputEventResult::NotHandled) { | 248 return WebInputEventResult::NotHandled; |
| 372 if (gestureEvent.preventPropagation() | |
| 373 && !RuntimeEnabledFeatures::scrollCustomizationEnabled()) { | |
| 374 // This is an optimization which doesn't apply with | |
| 375 // scroll customization enabled. | |
| 376 m_previousGestureScrolledNode = m_scrollGestureHandlingNode; | |
| 377 } | |
| 378 // FIXME: we should allow simultaneous scrolling of nested | |
| 379 // iframes along perpendicular axes. See crbug.com/466991. | |
| 380 m_deltaConsumedForScrollSequence = true; | |
| 381 return result; | |
| 382 } | |
| 383 | 249 |
| 384 if (handleScrollCustomization) { | 250 // Try to send the event to the correct view. |
| 385 std::unique_ptr<ScrollStateData> scrollStateData = wrapUnique(new Sc
rollStateData()); | 251 WebInputEventResult result = passScrollGestureEventToWidget(gestureEvent, la
youtObject); |
| 386 scrollStateData->delta_x = delta.width(); | 252 if (result != WebInputEventResult::NotHandled) { |
| 387 scrollStateData->delta_y = delta.height(); | 253 // FIXME: we should allow simultaneous scrolling of nested |
| 388 scrollStateData->delta_granularity = ScrollByPrecisePixel; | 254 // iframes along perpendicular axes. See crbug.com/466991. |
| 389 scrollStateData->velocity_x = velocity.width(); | 255 m_deltaConsumedForScrollSequence = true; |
| 390 scrollStateData->velocity_y = velocity.height(); | 256 return result; |
| 391 scrollStateData->should_propagate = !gestureEvent.preventPropagation
(); | 257 } |
| 392 scrollStateData->is_in_inertial_phase = gestureEvent.inertialPhase()
== ScrollInertialPhaseMomentum; | |
| 393 scrollStateData->from_user_input = true; | |
| 394 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsume
dForScrollSequence; | |
| 395 ScrollState* scrollState = ScrollState::create(std::move(scrollState
Data)); | |
| 396 if (m_previousGestureScrolledNode) { | |
| 397 // The ScrollState needs to know what the current | |
| 398 // native scrolling element is, so that for an | |
| 399 // inertial scroll that shouldn't propagate, only the | |
| 400 // currently scrolling element responds. | |
| 401 DCHECK(m_previousGestureScrolledNode->isElementNode()); | |
| 402 scrollState->setCurrentNativeScrollingElement(toElement(m_previo
usGestureScrolledNode.get())); | |
| 403 } | |
| 404 customizedScroll(*node, *scrollState); | |
| 405 m_previousGestureScrolledNode = scrollState->currentNativeScrollingE
lement(); | |
| 406 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScro
llSequence(); | |
| 407 if (scrollState->deltaX() != delta.width() | |
| 408 || scrollState->deltaY() != delta.height()) { | |
| 409 setFrameWasScrolledByUser(); | |
| 410 return WebInputEventResult::HandledSystem; | |
| 411 } | |
| 412 } else { | |
| 413 Node* stopNode = nullptr; | |
| 414 if (gestureEvent.preventPropagation()) | |
| 415 stopNode = m_previousGestureScrolledNode.get(); | |
| 416 | 258 |
| 417 bool consumed = false; | 259 std::unique_ptr<ScrollStateData> scrollStateData = wrapUnique(new ScrollStat
eData()); |
| 418 ScrollResult result = physicalScroll( | 260 scrollStateData->delta_x = delta.width(); |
| 419 granularity, | 261 scrollStateData->delta_y = delta.height(); |
| 420 delta, | 262 scrollStateData->delta_granularity = static_cast<double>(gestureEvent.deltaU
nits()); |
| 421 FloatPoint(gestureEvent.position()), | 263 scrollStateData->velocity_x = velocity.width(); |
| 422 velocity, | 264 scrollStateData->velocity_y = velocity.height(); |
| 423 node, | 265 scrollStateData->position_x = position.x(); |
| 424 &stopNode, | 266 scrollStateData->position_y = position.y(); |
| 425 &consumed); | 267 scrollStateData->should_propagate = !gestureEvent.preventPropagation(); |
| 268 scrollStateData->is_in_inertial_phase = gestureEvent.inertialPhase() == Scro
llInertialPhaseMomentum; |
| 269 scrollStateData->is_direct_manipulation = gestureEvent.source() == PlatformG
estureSourceTouchscreen; |
| 270 scrollStateData->from_user_input = true; |
| 271 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsumedForScro
llSequence; |
| 272 ScrollState* scrollState = ScrollState::create(std::move(scrollStateData)); |
| 273 if (m_previousGestureScrolledNode) { |
| 274 // The ScrollState needs to know what the current |
| 275 // native scrolling element is, so that for an |
| 276 // inertial scroll that shouldn't propagate, only the |
| 277 // currently scrolling element responds. |
| 278 DCHECK(m_previousGestureScrolledNode->isElementNode()); |
| 279 scrollState->setCurrentNativeScrollingElement(toElement(m_previousGestur
eScrolledNode.get())); |
| 280 } |
| 281 customizedScroll(*node, *scrollState); |
| 282 m_previousGestureScrolledNode = scrollState->currentNativeScrollingElement()
; |
| 283 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScrollSequen
ce(); |
| 426 | 284 |
| 427 if (gestureEvent.preventPropagation()) | 285 bool didScrollX = scrollState->deltaX() != delta.width(); |
| 428 m_previousGestureScrolledNode = stopNode; | 286 bool didScrollY = scrollState->deltaY() != delta.height(); |
| 429 | 287 |
| 430 if ((!stopNode || !isRootScroller(*stopNode)) && frameHost()) { | 288 if ((!m_previousGestureScrolledNode || !isEffectiveRootScroller(*m_previousG
estureScrolledNode)) && frameHost()) |
| 431 frameHost()->overscrollController().resetAccumulated( | 289 frameHost()->overscrollController().resetAccumulated(didScrollX, didScro
llY); |
| 432 result.didScrollX, result.didScrollY); | |
| 433 } | |
| 434 | 290 |
| 435 if (consumed) | 291 if (didScrollX || didScrollY) { |
| 436 return WebInputEventResult::HandledSystem; | 292 setFrameWasScrolledByUser(); |
| 437 } | 293 return WebInputEventResult::HandledSystem; |
| 438 } | 294 } |
| 439 | 295 |
| 440 return WebInputEventResult::NotHandled; | 296 return WebInputEventResult::NotHandled; |
| 441 } | 297 } |
| 442 | 298 |
| 443 WebInputEventResult ScrollManager::handleGestureScrollEnd(const PlatformGestureE
vent& gestureEvent) | 299 WebInputEventResult ScrollManager::handleGestureScrollEnd(const PlatformGestureE
vent& gestureEvent) |
| 444 { | 300 { |
| 445 Node* node = m_scrollGestureHandlingNode; | 301 Node* node = m_scrollGestureHandlingNode; |
| 446 | 302 |
| 447 if (node) { | 303 if (node) { |
| 448 passScrollGestureEventToWidget(gestureEvent, node->layoutObject()); | 304 passScrollGestureEventToWidget(gestureEvent, node->layoutObject()); |
| 449 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) { | 305 std::unique_ptr<ScrollStateData> scrollStateData = wrapUnique(new Scroll
StateData()); |
| 450 std::unique_ptr<ScrollStateData> scrollStateData = wrapUnique(new Sc
rollStateData()); | 306 scrollStateData->is_ending = true; |
| 451 scrollStateData->is_ending = true; | 307 scrollStateData->is_in_inertial_phase = gestureEvent.inertialPhase() ==
ScrollInertialPhaseMomentum; |
| 452 scrollStateData->is_in_inertial_phase = gestureEvent.inertialPhase()
== ScrollInertialPhaseMomentum; | 308 scrollStateData->from_user_input = true; |
| 453 scrollStateData->from_user_input = true; | 309 scrollStateData->is_direct_manipulation = gestureEvent.source() == Platf
ormGestureSourceTouchscreen; |
| 454 scrollStateData->is_direct_manipulation = true; | 310 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsumedFor
ScrollSequence; |
| 455 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsume
dForScrollSequence; | 311 ScrollState* scrollState = ScrollState::create(std::move(scrollStateData
)); |
| 456 ScrollState* scrollState = ScrollState::create(std::move(scrollState
Data)); | 312 customizedScroll(*node, *scrollState); |
| 457 customizedScroll(*node, *scrollState); | |
| 458 } | |
| 459 } | 313 } |
| 460 | 314 |
| 461 clearGestureScrollState(); | 315 clearGestureScrollState(); |
| 462 return WebInputEventResult::NotHandled; | 316 return WebInputEventResult::NotHandled; |
| 463 } | 317 } |
| 464 | 318 |
| 465 FrameHost* ScrollManager::frameHost() const | 319 FrameHost* ScrollManager::frameHost() const |
| 466 { | 320 { |
| 467 if (!m_frame->page()) | 321 if (!m_frame->page()) |
| 468 return nullptr; | 322 return nullptr; |
| 469 | 323 |
| 470 return &m_frame->page()->frameHost(); | 324 return &m_frame->page()->frameHost(); |
| 471 } | 325 } |
| 472 | 326 |
| 473 WebInputEventResult ScrollManager::passScrollGestureEventToWidget(const Platform
GestureEvent& gestureEvent, LayoutObject* layoutObject) | 327 WebInputEventResult ScrollManager::passScrollGestureEventToWidget(const Platform
GestureEvent& gestureEvent, LayoutObject* layoutObject) |
| 474 { | 328 { |
| 475 DCHECK(gestureEvent.isScrollEvent()); | 329 DCHECK(gestureEvent.isScrollEvent()); |
| 476 | 330 |
| 477 if (!m_lastGestureScrollOverWidget || !layoutObject || !layoutObject->isLayo
utPart()) | 331 if (!m_lastGestureScrollOverWidget || !layoutObject || !layoutObject->isLayo
utPart()) |
| 478 return WebInputEventResult::NotHandled; | 332 return WebInputEventResult::NotHandled; |
| 479 | 333 |
| 480 Widget* widget = toLayoutPart(layoutObject)->widget(); | 334 Widget* widget = toLayoutPart(layoutObject)->widget(); |
| 481 | 335 |
| 482 if (!widget || !widget->isFrameView()) | 336 if (!widget || !widget->isFrameView()) |
| 483 return WebInputEventResult::NotHandled; | 337 return WebInputEventResult::NotHandled; |
| 484 | 338 |
| 485 return toFrameView(widget)->frame().eventHandler().handleGestureScrollEvent(
gestureEvent); | 339 return toFrameView(widget)->frame().eventHandler().handleGestureScrollEvent(
gestureEvent); |
| 486 } | 340 } |
| 487 | 341 |
| 488 bool ScrollManager::isRootScroller(const Node& node) const | 342 bool ScrollManager::isEffectiveRootScroller(const Node& node) const |
| 489 { | 343 { |
| 490 // The root scroller is the one Element on the page designated to perform | 344 // The root scroller is the one Element on the page designated to perform |
| 491 // "viewport actions" like top controls movement and overscroll glow. | 345 // "viewport actions" like top controls movement and overscroll glow. |
| 492 if (!m_frame->document()) | 346 if (!m_frame->document()) |
| 493 return false; | 347 return false; |
| 494 | 348 |
| 495 if (!node.isElementNode()) | 349 if (!node.isElementNode()) |
| 496 return false; | 350 return false; |
| 497 | 351 |
| 498 return m_frame->document()->topDocument().isEffectiveRootScroller(toElement(
node)); | 352 return node.isSameNode(m_frame->document()->effectiveRootScroller()); |
| 499 } | 353 } |
| 500 | 354 |
| 501 | 355 |
| 502 WebInputEventResult ScrollManager::handleGestureScrollEvent(const PlatformGestur
eEvent& gestureEvent) | 356 WebInputEventResult ScrollManager::handleGestureScrollEvent(const PlatformGestur
eEvent& gestureEvent) |
| 503 { | 357 { |
| 504 Node* eventTarget = nullptr; | 358 Node* eventTarget = nullptr; |
| 505 Scrollbar* scrollbar = nullptr; | 359 Scrollbar* scrollbar = nullptr; |
| 506 if (gestureEvent.type() != PlatformEvent::GestureScrollBegin) { | 360 if (gestureEvent.type() != PlatformEvent::GestureScrollBegin) { |
| 507 scrollbar = m_scrollbarHandlingScrollGesture.get(); | 361 scrollbar = m_scrollbarHandlingScrollGesture.get(); |
| 508 eventTarget = m_scrollGestureHandlingNode.get(); | 362 eventTarget = m_scrollGestureHandlingNode.get(); |
| 509 } | 363 } |
| 510 | 364 |
| 511 if (!eventTarget) { | 365 if (!eventTarget) { |
| 512 Document* document = m_frame->document(); | 366 Document* document = m_frame->document(); |
| 513 if (document->layoutViewItem().isNull()) | 367 if (document->layoutViewItem().isNull()) |
| 514 return WebInputEventResult::NotHandled; | 368 return WebInputEventResult::NotHandled; |
| 515 | 369 |
| 516 FrameView* view = m_frame->view(); | 370 FrameView* view = m_frame->view(); |
| 517 LayoutPoint viewPoint = view->rootFrameToContents(gestureEvent.position(
)); | 371 LayoutPoint viewPoint = view->rootFrameToContents(gestureEvent.position(
)); |
| 518 HitTestRequest request(HitTestRequest::ReadOnly); | 372 HitTestRequest request(HitTestRequest::ReadOnly); |
| 519 HitTestResult result(request, viewPoint); | 373 HitTestResult result(request, viewPoint); |
| 520 document->layoutViewItem().hitTest(result); | 374 document->layoutViewItem().hitTest(result); |
| 521 | 375 |
| 522 eventTarget = result.innerNode(); | 376 eventTarget = result.innerNode(); |
| 523 | 377 |
| 524 m_lastGestureScrollOverWidget = result.isOverWidget(); | 378 m_lastGestureScrollOverWidget = result.isOverWidget(); |
| 525 m_scrollGestureHandlingNode = eventTarget; | 379 m_scrollGestureHandlingNode = eventTarget; |
| 526 m_previousGestureScrolledNode = nullptr; | 380 m_previousGestureScrolledNode = nullptr; |
| 381 m_deltaConsumedForScrollSequence = false; |
| 527 | 382 |
| 528 if (!scrollbar) | 383 if (!scrollbar) |
| 529 scrollbar = result.scrollbar(); | 384 scrollbar = result.scrollbar(); |
| 530 } | 385 } |
| 531 | 386 |
| 532 if (scrollbar) { | 387 if (scrollbar) { |
| 533 bool shouldUpdateCapture = false; | 388 bool shouldUpdateCapture = false; |
| 534 if (scrollbar->gestureEvent(gestureEvent, &shouldUpdateCapture)) { | 389 if (scrollbar->gestureEvent(gestureEvent, &shouldUpdateCapture)) { |
| 535 if (shouldUpdateCapture) | 390 if (shouldUpdateCapture) |
| 536 m_scrollbarHandlingScrollGesture = scrollbar; | 391 m_scrollbarHandlingScrollGesture = scrollbar; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 DEFINE_TRACE(ScrollManager) | 503 DEFINE_TRACE(ScrollManager) |
| 649 { | 504 { |
| 650 visitor->trace(m_frame); | 505 visitor->trace(m_frame); |
| 651 visitor->trace(m_scrollGestureHandlingNode); | 506 visitor->trace(m_scrollGestureHandlingNode); |
| 652 visitor->trace(m_previousGestureScrolledNode); | 507 visitor->trace(m_previousGestureScrolledNode); |
| 653 visitor->trace(m_scrollbarHandlingScrollGesture); | 508 visitor->trace(m_scrollbarHandlingScrollGesture); |
| 654 visitor->trace(m_resizeScrollableArea); | 509 visitor->trace(m_resizeScrollableArea); |
| 655 } | 510 } |
| 656 | 511 |
| 657 } // namespace blink | 512 } // namespace blink |
| OLD | NEW |