| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Peter Kelly (pmk@post.com) | 4 * (C) 2001 Peter Kelly (pmk@post.com) |
| 5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 6 * (C) 2007 David Smith (catfish.man@gmail.com) | 6 * (C) 2007 David Smith (catfish.man@gmail.com) |
| 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. | 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. |
| 8 * (C) 2007 Eric Seidel (eric@webkit.org) | 8 * (C) 2007 Eric Seidel (eric@webkit.org) |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 // We need to retain the scroll customization callbacks until the element | 143 // We need to retain the scroll customization callbacks until the element |
| 144 // they're associated with is destroyed. It would be simplest if the callbacks | 144 // they're associated with is destroyed. It would be simplest if the callbacks |
| 145 // could be stored in ElementRareData, but we can't afford the space | 145 // could be stored in ElementRareData, but we can't afford the space |
| 146 // increase. Instead, keep the scroll customization callbacks here. The other | 146 // increase. Instead, keep the scroll customization callbacks here. The other |
| 147 // option would be to store these callbacks on the FrameHost or document, but | 147 // option would be to store these callbacks on the FrameHost or document, but |
| 148 // that necessitates a bunch more logic for transferring the callbacks between | 148 // that necessitates a bunch more logic for transferring the callbacks between |
| 149 // FrameHosts when elements are moved around. | 149 // FrameHosts when elements are moved around. |
| 150 ScrollCustomizationCallbacks& scrollCustomizationCallbacks() | 150 ScrollCustomizationCallbacks& scrollCustomizationCallbacks() |
| 151 { | 151 { |
| 152 DCHECK(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | |
| 153 DEFINE_STATIC_LOCAL(ScrollCustomizationCallbacks, scrollCustomizationCallbac
ks, (new ScrollCustomizationCallbacks)); | 152 DEFINE_STATIC_LOCAL(ScrollCustomizationCallbacks, scrollCustomizationCallbac
ks, (new ScrollCustomizationCallbacks)); |
| 154 return scrollCustomizationCallbacks; | 153 return scrollCustomizationCallbacks; |
| 155 } | 154 } |
| 156 | 155 |
| 157 } // namespace | 156 } // namespace |
| 158 | 157 |
| 159 using namespace HTMLNames; | 158 using namespace HTMLNames; |
| 160 using namespace XMLNames; | 159 using namespace XMLNames; |
| 161 | 160 |
| 162 enum class ClassStringContent { Empty, WhiteSpaceOnly, HasClasses }; | 161 enum class ClassStringContent { Empty, WhiteSpaceOnly, HasClasses }; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc
rollBehavior(nativeScrollBehavior)); | 498 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc
rollBehavior(nativeScrollBehavior)); |
| 500 scrollCustomizationCallbacks().setDistributeScroll(this, scrollStateCallback
); | 499 scrollCustomizationCallbacks().setDistributeScroll(this, scrollStateCallback
); |
| 501 } | 500 } |
| 502 | 501 |
| 503 void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback, String na
tiveScrollBehavior) | 502 void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback, String na
tiveScrollBehavior) |
| 504 { | 503 { |
| 505 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc
rollBehavior(nativeScrollBehavior)); | 504 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc
rollBehavior(nativeScrollBehavior)); |
| 506 scrollCustomizationCallbacks().setApplyScroll(this, scrollStateCallback); | 505 scrollCustomizationCallbacks().setApplyScroll(this, scrollStateCallback); |
| 507 } | 506 } |
| 508 | 507 |
| 508 void Element::removeApplyScroll() |
| 509 { |
| 510 scrollCustomizationCallbacks().removeApplyScroll(this); |
| 511 } |
| 512 |
| 513 ScrollStateCallback* Element::getApplyScroll() |
| 514 { |
| 515 return scrollCustomizationCallbacks().getApplyScroll(this); |
| 516 } |
| 517 |
| 509 void Element::nativeDistributeScroll(ScrollState& scrollState) | 518 void Element::nativeDistributeScroll(ScrollState& scrollState) |
| 510 { | 519 { |
| 511 DCHECK(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | |
| 512 if (scrollState.fullyConsumed()) | 520 if (scrollState.fullyConsumed()) |
| 513 return; | 521 return; |
| 514 | 522 |
| 515 scrollState.distributeToScrollChainDescendant(); | 523 scrollState.distributeToScrollChainDescendant(); |
| 516 | 524 |
| 517 // If the scroll doesn't propagate, and we're currently scrolling | 525 // If the scroll doesn't propagate, and we're currently scrolling |
| 518 // an element other than this one, prevent the scroll from | 526 // an element other than this one, prevent the scroll from |
| 519 // propagating to this element. | 527 // propagating to this element. |
| 520 if (!scrollState.shouldPropagate() | 528 if (!scrollState.shouldPropagate() |
| 521 && scrollState.deltaConsumedForScrollSequence() | 529 && scrollState.deltaConsumedForScrollSequence() |
| (...skipping 21 matching lines...) Expand all Loading... |
| 543 callback->handleEvent(&scrollState); | 551 callback->handleEvent(&scrollState); |
| 544 if (callback->nativeScrollBehavior() != WebNativeScrollBehavior::DisableNati
veScroll) | 552 if (callback->nativeScrollBehavior() != WebNativeScrollBehavior::DisableNati
veScroll) |
| 545 nativeDistributeScroll(scrollState); | 553 nativeDistributeScroll(scrollState); |
| 546 if (callback->nativeScrollBehavior() == WebNativeScrollBehavior::PerformAfte
rNativeScroll) | 554 if (callback->nativeScrollBehavior() == WebNativeScrollBehavior::PerformAfte
rNativeScroll) |
| 547 callback->handleEvent(&scrollState); | 555 callback->handleEvent(&scrollState); |
| 548 }; | 556 }; |
| 549 | 557 |
| 550 void Element::nativeApplyScroll(ScrollState& scrollState) | 558 void Element::nativeApplyScroll(ScrollState& scrollState) |
| 551 { | 559 { |
| 552 DCHECK(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 560 DCHECK(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
| 561 |
| 562 // All elements in the scroll chain should be boxes. |
| 563 DCHECK(!layoutObject() || layoutObject()->isBox()); |
| 564 |
| 553 if (scrollState.fullyConsumed()) | 565 if (scrollState.fullyConsumed()) |
| 554 return; | 566 return; |
| 555 | 567 |
| 556 const double deltaX = scrollState.deltaX(); | 568 FloatSize delta(scrollState.deltaX(), scrollState.deltaY()); |
| 557 const double deltaY = scrollState.deltaY(); | 569 |
| 558 bool scrolled = false; | 570 if (delta.isZero()) |
| 571 return; |
| 559 | 572 |
| 560 // TODO(esprehn): This should use updateLayoutIgnorePendingStylesheetsForNod
e. | 573 // TODO(esprehn): This should use updateLayoutIgnorePendingStylesheetsForNod
e. |
| 561 if (deltaY || deltaX) | 574 document().updateLayoutIgnorePendingStylesheets(); |
| 562 document().updateLayoutIgnorePendingStylesheets(); | |
| 563 | 575 |
| 564 // Handle the scrollingElement separately, as it scrolls the viewport. | 576 LayoutBox* boxToScroll = nullptr; |
| 565 if (this == document().scrollingElement()) { | |
| 566 FloatSize delta(deltaX, deltaY); | |
| 567 if (document().frame()->applyScrollDelta(ScrollByPrecisePixel, delta, sc
rollState.isBeginning()).didScroll()) { | |
| 568 scrolled = true; | |
| 569 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del
taY()); | |
| 570 } | |
| 571 } else { | |
| 572 if (!layoutObject()) | |
| 573 return; | |
| 574 LayoutBoxItem curBox = LayoutBoxItem(toLayoutBox(layoutObject())).enclos
ingBox(); | |
| 575 // FIXME: Native scrollers should only consume the scroll they | |
| 576 // apply. See crbug.com/457765. | |
| 577 if (deltaX && curBox.scroll(ScrollByPrecisePixel, FloatSize(deltaX, 0)).
didScrollX) { | |
| 578 scrollState.consumeDeltaNative(scrollState.deltaX(), 0); | |
| 579 scrolled = true; | |
| 580 } | |
| 581 | 577 |
| 582 if (deltaY && curBox.scroll(ScrollByPrecisePixel, FloatSize(0, deltaY)).
didScrollY) { | 578 // Handle the scrollingElement separately, as it should scroll the viewport. |
| 583 scrollState.consumeDeltaNative(0, scrollState.deltaY()); | 579 if (this == document().scrollingElement()) |
| 584 scrolled = true; | 580 boxToScroll = document().layoutView(); |
| 585 } | 581 else if (layoutObject()) |
| 586 } | 582 boxToScroll = toLayoutBox(layoutObject()); |
| 587 | 583 |
| 588 if (!scrolled) | 584 if (!boxToScroll) |
| 589 return; | 585 return; |
| 590 | 586 |
| 587 ScrollResult result = |
| 588 LayoutBoxItem(boxToScroll).enclosingBox().scroll( |
| 589 ScrollByPrecisePixel, |
| 590 delta); |
| 591 |
| 592 if (!result.didScroll()) |
| 593 return; |
| 594 |
| 595 // FIXME: Native scrollers should only consume the scroll they |
| 596 // apply. See crbug.com/457765. |
| 597 scrollState.consumeDeltaNative(delta.width(), delta.height()); |
| 598 |
| 591 // We need to setCurrentNativeScrollingElement in both the | 599 // We need to setCurrentNativeScrollingElement in both the |
| 592 // distributeScroll and applyScroll default implementations so | 600 // distributeScroll and applyScroll default implementations so |
| 593 // that if JS overrides one of these methods, but not the | 601 // that if JS overrides one of these methods, but not the |
| 594 // other, this bookkeeping remains accurate. | 602 // other, this bookkeeping remains accurate. |
| 595 scrollState.setCurrentNativeScrollingElement(this); | 603 scrollState.setCurrentNativeScrollingElement(this); |
| 596 if (scrollState.fromUserInput()) { | 604 if (scrollState.fromUserInput()) { |
| 597 if (DocumentLoader* documentLoader = document().loader()) | 605 if (DocumentLoader* documentLoader = document().loader()) |
| 598 documentLoader->initialScrollState().wasScrolledByUser = true; | 606 documentLoader->initialScrollState().wasScrolledByUser = true; |
| 599 } | 607 } |
| 600 }; | 608 }; |
| (...skipping 3088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3689 | 3697 |
| 3690 DEFINE_TRACE(Element) | 3698 DEFINE_TRACE(Element) |
| 3691 { | 3699 { |
| 3692 if (hasRareData()) | 3700 if (hasRareData()) |
| 3693 visitor->trace(elementRareData()); | 3701 visitor->trace(elementRareData()); |
| 3694 visitor->trace(m_elementData); | 3702 visitor->trace(m_elementData); |
| 3695 ContainerNode::trace(visitor); | 3703 ContainerNode::trace(visitor); |
| 3696 } | 3704 } |
| 3697 | 3705 |
| 3698 } // namespace blink | 3706 } // namespace blink |
| OLD | NEW |