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

Side by Side Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 1840113005: Move viewport actions into an ApplyScroll callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 // We need to retain the scroll customization callbacks until the element 141 // We need to retain the scroll customization callbacks until the element
142 // they're associated with is destroyed. It would be simplest if the callbacks 142 // they're associated with is destroyed. It would be simplest if the callbacks
143 // could be stored in ElementRareData, but we can't afford the space 143 // could be stored in ElementRareData, but we can't afford the space
144 // increase. Instead, keep the scroll customization callbacks here. The other 144 // increase. Instead, keep the scroll customization callbacks here. The other
145 // option would be to store these callbacks on the FrameHost or document, but 145 // option would be to store these callbacks on the FrameHost or document, but
146 // that necessitates a bunch more logic for transferring the callbacks between 146 // that necessitates a bunch more logic for transferring the callbacks between
147 // FrameHosts when elements are moved around. 147 // FrameHosts when elements are moved around.
148 ScrollCustomizationCallbacks& scrollCustomizationCallbacks() 148 ScrollCustomizationCallbacks& scrollCustomizationCallbacks()
149 { 149 {
150 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
151 DEFINE_STATIC_LOCAL(ScrollCustomizationCallbacks, scrollCustomizationCallbac ks, (new ScrollCustomizationCallbacks)); 150 DEFINE_STATIC_LOCAL(ScrollCustomizationCallbacks, scrollCustomizationCallbac ks, (new ScrollCustomizationCallbacks));
152 return scrollCustomizationCallbacks; 151 return scrollCustomizationCallbacks;
153 } 152 }
154 153
155 } // namespace 154 } // namespace
156 155
157 using namespace HTMLNames; 156 using namespace HTMLNames;
158 using namespace XMLNames; 157 using namespace XMLNames;
159 158
160 enum class ClassStringContent { Empty, WhiteSpaceOnly, HasClasses }; 159 enum class ClassStringContent { Empty, WhiteSpaceOnly, HasClasses };
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc rollBehavior(nativeScrollBehavior)); 496 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc rollBehavior(nativeScrollBehavior));
498 scrollCustomizationCallbacks().setDistributeScroll(this, scrollStateCallback ); 497 scrollCustomizationCallbacks().setDistributeScroll(this, scrollStateCallback );
499 } 498 }
500 499
501 void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback, String na tiveScrollBehavior) 500 void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback, String na tiveScrollBehavior)
502 { 501 {
503 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc rollBehavior(nativeScrollBehavior)); 502 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc rollBehavior(nativeScrollBehavior));
504 scrollCustomizationCallbacks().setApplyScroll(this, scrollStateCallback); 503 scrollCustomizationCallbacks().setApplyScroll(this, scrollStateCallback);
505 } 504 }
506 505
506 void Element::removeApplyScroll()
507 {
508 scrollCustomizationCallbacks().removeApplyScroll(this);
509 }
510
511 ScrollStateCallback* Element::getApplyScroll()
512 {
513 return scrollCustomizationCallbacks().getApplyScroll(this);
514 }
515
507 void Element::nativeDistributeScroll(ScrollState& scrollState) 516 void Element::nativeDistributeScroll(ScrollState& scrollState)
508 { 517 {
509 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
510 if (scrollState.fullyConsumed()) 518 if (scrollState.fullyConsumed())
511 return; 519 return;
512 520
513 scrollState.distributeToScrollChainDescendant(); 521 scrollState.distributeToScrollChainDescendant();
514 522
515 // If the scroll doesn't propagate, and we're currently scrolling 523 // If the scroll doesn't propagate, and we're currently scrolling
516 // an element other than this one, prevent the scroll from 524 // an element other than this one, prevent the scroll from
517 // propagating to this element. 525 // propagating to this element.
518 if (!scrollState.shouldPropagate() 526 if (!scrollState.shouldPropagate()
519 && scrollState.deltaConsumedForScrollSequence() 527 && scrollState.deltaConsumedForScrollSequence()
(...skipping 21 matching lines...) Expand all
541 callback->handleEvent(&scrollState); 549 callback->handleEvent(&scrollState);
542 if (callback->nativeScrollBehavior() != WebNativeScrollBehavior::DisableNati veScroll) 550 if (callback->nativeScrollBehavior() != WebNativeScrollBehavior::DisableNati veScroll)
543 nativeDistributeScroll(scrollState); 551 nativeDistributeScroll(scrollState);
544 if (callback->nativeScrollBehavior() == WebNativeScrollBehavior::PerformAfte rNativeScroll) 552 if (callback->nativeScrollBehavior() == WebNativeScrollBehavior::PerformAfte rNativeScroll)
545 callback->handleEvent(&scrollState); 553 callback->handleEvent(&scrollState);
546 }; 554 };
547 555
548 void Element::nativeApplyScroll(ScrollState& scrollState) 556 void Element::nativeApplyScroll(ScrollState& scrollState)
549 { 557 {
550 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); 558 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
559
560 // All elements in the scroll chain should be boxes.
561 ASSERT(!layoutObject() || layoutObject()->isBox());
562
551 if (scrollState.fullyConsumed()) 563 if (scrollState.fullyConsumed())
552 return; 564 return;
553 565
554 const double deltaX = scrollState.deltaX(); 566 FloatSize delta(scrollState.deltaX(), scrollState.deltaY());
555 const double deltaY = scrollState.deltaY(); 567
556 bool scrolled = false; 568 if (delta.isZero())
569 return;
557 570
558 // TODO(esprehn): This should use updateLayoutIgnorePendingStylesheetsForNod e. 571 // TODO(esprehn): This should use updateLayoutIgnorePendingStylesheetsForNod e.
559 if (deltaY || deltaX) 572 document().updateLayoutIgnorePendingStylesheets();
560 document().updateLayoutIgnorePendingStylesheets();
561 573
562 // Handle the scrollingElement separately, as it scrolls the viewport. 574 LayoutBox* boxToScroll = nullptr;
563 if (this == document().scrollingElement()) {
564 FloatSize delta(deltaX, deltaY);
565 if (document().frame()->applyScrollDelta(ScrollByPrecisePixel, delta, sc rollState.isBeginning()).didScroll()) {
566 scrolled = true;
567 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del taY());
568 }
569 } else {
570 if (!layoutObject())
571 return;
572 LayoutBoxItem curBox = LayoutBoxItem(toLayoutBox(layoutObject())).enclos ingBox();
573 // FIXME: Native scrollers should only consume the scroll they
574 // apply. See crbug.com/457765.
575 if (deltaX && curBox.scroll(ScrollByPrecisePixel, FloatSize(deltaX, 0)). didScrollX) {
576 scrollState.consumeDeltaNative(scrollState.deltaX(), 0);
577 scrolled = true;
578 }
579 575
580 if (deltaY && curBox.scroll(ScrollByPrecisePixel, FloatSize(0, deltaY)). didScrollY) { 576 // Handle the scrollingElement separately, as it should scroll the viewport.
581 scrollState.consumeDeltaNative(0, scrollState.deltaY()); 577 if (this == document().scrollingElement())
582 scrolled = true; 578 boxToScroll = document().layoutView();
583 } 579 else if (layoutObject())
584 } 580 boxToScroll = toLayoutBox(layoutObject());
585 581
586 if (!scrolled) 582 if (!boxToScroll)
587 return; 583 return;
588 584
585 ScrollResult result =
586 LayoutBoxItem(boxToScroll).enclosingBox().scroll(
587 ScrollByPrecisePixel,
588 delta);
589
590 if (!result.didScroll())
591 return;
592
593 // FIXME: Native scrollers should only consume the scroll they
594 // apply. See crbug.com/457765.
595 scrollState.consumeDeltaNative(delta.width(), delta.height());
596
589 // We need to setCurrentNativeScrollingElement in both the 597 // We need to setCurrentNativeScrollingElement in both the
590 // distributeScroll and applyScroll default implementations so 598 // distributeScroll and applyScroll default implementations so
591 // that if JS overrides one of these methods, but not the 599 // that if JS overrides one of these methods, but not the
592 // other, this bookkeeping remains accurate. 600 // other, this bookkeeping remains accurate.
593 scrollState.setCurrentNativeScrollingElement(this); 601 scrollState.setCurrentNativeScrollingElement(this);
594 if (scrollState.fromUserInput()) { 602 if (scrollState.fromUserInput()) {
595 if (DocumentLoader* documentLoader = document().loader()) 603 if (DocumentLoader* documentLoader = document().loader())
596 documentLoader->initialScrollState().wasScrolledByUser = true; 604 documentLoader->initialScrollState().wasScrolledByUser = true;
597 } 605 }
598 }; 606 };
(...skipping 3070 matching lines...) Expand 10 before | Expand all | Expand 10 after
3669 { 3677 {
3670 #if ENABLE(OILPAN) 3678 #if ENABLE(OILPAN)
3671 if (hasRareData()) 3679 if (hasRareData())
3672 visitor->trace(elementRareData()); 3680 visitor->trace(elementRareData());
3673 visitor->trace(m_elementData); 3681 visitor->trace(m_elementData);
3674 #endif 3682 #endif
3675 ContainerNode::trace(visitor); 3683 ContainerNode::trace(visitor);
3676 } 3684 }
3677 3685
3678 } // namespace blink 3686 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698