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

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

Issue 1236913004: Expose scroll customization for touch to JS (behind REF). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add to leak expectations. Created 5 years, 3 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
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 #include "core/html/parser/HTMLParserIdioms.h" 106 #include "core/html/parser/HTMLParserIdioms.h"
107 #include "core/inspector/InspectorInstrumentation.h" 107 #include "core/inspector/InspectorInstrumentation.h"
108 #include "core/layout/LayoutTextFragment.h" 108 #include "core/layout/LayoutTextFragment.h"
109 #include "core/layout/LayoutView.h" 109 #include "core/layout/LayoutView.h"
110 #include "core/loader/DocumentLoader.h" 110 #include "core/loader/DocumentLoader.h"
111 #include "core/page/ChromeClient.h" 111 #include "core/page/ChromeClient.h"
112 #include "core/page/FocusController.h" 112 #include "core/page/FocusController.h"
113 #include "core/page/Page.h" 113 #include "core/page/Page.h"
114 #include "core/page/PointerLockController.h" 114 #include "core/page/PointerLockController.h"
115 #include "core/page/SpatialNavigation.h" 115 #include "core/page/SpatialNavigation.h"
116 #include "core/page/scrolling/ScrollCustomizationCallbacks.h"
116 #include "core/page/scrolling/ScrollState.h" 117 #include "core/page/scrolling/ScrollState.h"
118 #include "core/page/scrolling/ScrollStateCallback.h"
117 #include "core/paint/DeprecatedPaintLayer.h" 119 #include "core/paint/DeprecatedPaintLayer.h"
118 #include "core/svg/SVGDocumentExtensions.h" 120 #include "core/svg/SVGDocumentExtensions.h"
119 #include "core/svg/SVGElement.h" 121 #include "core/svg/SVGElement.h"
120 #include "platform/EventDispatchForbiddenScope.h" 122 #include "platform/EventDispatchForbiddenScope.h"
121 #include "platform/RuntimeEnabledFeatures.h" 123 #include "platform/RuntimeEnabledFeatures.h"
122 #include "platform/UserGestureIndicator.h" 124 #include "platform/UserGestureIndicator.h"
123 #include "platform/scroll/ScrollableArea.h" 125 #include "platform/scroll/ScrollableArea.h"
124 #include "wtf/BitVector.h" 126 #include "wtf/BitVector.h"
125 #include "wtf/HashFunctions.h" 127 #include "wtf/HashFunctions.h"
126 #include "wtf/text/CString.h" 128 #include "wtf/text/CString.h"
127 #include "wtf/text/StringBuilder.h" 129 #include "wtf/text/StringBuilder.h"
128 #include "wtf/text/TextPosition.h" 130 #include "wtf/text/TextPosition.h"
129 131
130 namespace blink { 132 namespace blink {
131 133
134 namespace {
135
136 // We need to retain the scroll customization callbacks until the element
137 // they're associated with is destroyed. It would be simplest if the callbacks
138 // could be stored in ElementRareData, but we can't afford the space
139 // increase. Instead, keep the scroll customization callbacks here. The other
140 // option would be to store these callbacks on the FrameHost or document, but
141 // that necessitates a bunch more logic for transferring the callbacks between
142 // FrameHosts when elements are moved around.
143 ScrollCustomizationCallbacks& scrollCustomizationCallbacks()
144 {
145 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
146 DEFINE_STATIC_LOCAL(Persistent<ScrollCustomizationCallbacks>,
147 scrollCustomizationCallbacks, (new ScrollCustomizationCallbacks()));
148 return *scrollCustomizationCallbacks;
149 }
150
151 } // namespace
152
132 using namespace HTMLNames; 153 using namespace HTMLNames;
133 using namespace XMLNames; 154 using namespace XMLNames;
134 155
135 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do cument* document) 156 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do cument* document)
136 { 157 {
137 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement)); 158 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement));
138 } 159 }
139 160
140 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT ype type) 161 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT ype type)
141 : ContainerNode(document, type) 162 : ContainerNode(document, type)
142 , m_tagName(tagName) 163 , m_tagName(tagName)
143 { 164 {
144 } 165 }
145 166
146 Element::~Element() 167 Element::~Element()
147 { 168 {
148 ASSERT(needsAttach()); 169 ASSERT(needsAttach());
149 170
150 #if !ENABLE(OILPAN) 171 #if !ENABLE(OILPAN)
151 if (hasRareData()) { 172 if (hasRareData()) {
152 elementRareData()->clearShadow(); 173 elementRareData()->clearShadow();
153 detachAllAttrNodesFromElement(); 174 detachAllAttrNodesFromElement();
154 } 175 }
155 176
156 if (isCustomElement()) 177 if (isCustomElement())
157 CustomElement::wasDestroyed(this); 178 CustomElement::wasDestroyed(this);
158 179
180 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
181 scrollCustomizationCallbacks().removeCallbacksForElement(this);
182
159 // With Oilpan, either the Element has been removed from the Document 183 // With Oilpan, either the Element has been removed from the Document
160 // or the Document is dead as well. If the Element has been removed from 184 // or the Document is dead as well. If the Element has been removed from
161 // the Document the element has already been removed from the pending 185 // the Document the element has already been removed from the pending
162 // resources. If the document is also dead, there is no need to remove 186 // resources. If the document is also dead, there is no need to remove
163 // the element from the pending resources. 187 // the element from the pending resources.
164 if (hasPendingResources()) { 188 if (hasPendingResources()) {
165 document().accessSVGExtensions().removeElementFromPendingResources(this) ; 189 document().accessSVGExtensions().removeElementFromPendingResources(this) ;
166 ASSERT(!hasPendingResources()); 190 ASSERT(!hasPendingResources());
167 } 191 }
168 #endif 192 #endif
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 if (!layoutObject()) 488 if (!layoutObject())
465 return; 489 return;
466 490
467 LayoutRect bounds = boundingBox(); 491 LayoutRect bounds = boundingBox();
468 if (centerIfNeeded) 492 if (centerIfNeeded)
469 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter IfNeeded, ScrollAlignment::alignCenterIfNeeded); 493 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter IfNeeded, ScrollAlignment::alignCenterIfNeeded);
470 else 494 else
471 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); 495 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge IfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
472 } 496 }
473 497
474 void Element::distributeScroll(ScrollState& scrollState) 498 void Element::setDistributeScroll(ScrollStateCallback* scrollStateCallback, Stri ng nativeScrollBehavior)
499 {
500 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc rollBehavior(nativeScrollBehavior));
501 scrollCustomizationCallbacks().setDistributeScroll(this, scrollStateCallback );
502 }
503
504 void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback, String na tiveScrollBehavior)
505 {
506 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc rollBehavior(nativeScrollBehavior));
507 scrollCustomizationCallbacks().setApplyScroll(this, scrollStateCallback);
508 }
509
510 void Element::nativeDistributeScroll(ScrollState& scrollState)
475 { 511 {
476 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); 512 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
477 if (scrollState.fullyConsumed()) 513 if (scrollState.fullyConsumed())
478 return; 514 return;
479 515
480 scrollState.distributeToScrollChainDescendant(); 516 scrollState.distributeToScrollChainDescendant();
481 517
482 // If the scroll doesn't propagate, and we're currently scrolling 518 // If the scroll doesn't propagate, and we're currently scrolling
483 // an element other than this one, prevent the scroll from 519 // an element other than this one, prevent the scroll from
484 // propagating to this element. 520 // propagating to this element.
485 if (!scrollState.shouldPropagate() 521 if (!scrollState.shouldPropagate()
486 && scrollState.deltaConsumedForScrollSequence() 522 && scrollState.deltaConsumedForScrollSequence()
487 && scrollState.currentNativeScrollingElement() != this) { 523 && scrollState.currentNativeScrollingElement() != this) {
488 return; 524 return;
489 } 525 }
490 526
491 const double deltaX = scrollState.deltaX(); 527 const double deltaX = scrollState.deltaX();
492 const double deltaY = scrollState.deltaY(); 528 const double deltaY = scrollState.deltaY();
493 529
494 applyScroll(scrollState); 530 callApplyScroll(scrollState);
495 531
496 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) 532 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY())
497 scrollState.setCurrentNativeScrollingElement(this); 533 scrollState.setCurrentNativeScrollingElement(this);
498 } 534 }
499 535
500 void Element::applyScroll(ScrollState& scrollState) 536 void Element::callDistributeScroll(ScrollState& scrollState)
537 {
538 ScrollStateCallback* callback = scrollCustomizationCallbacks().getDistribute Scroll(this);
539 if (!callback) {
540 nativeDistributeScroll(scrollState);
541 return;
542 }
543
544 if (callback->nativeScrollBehavior() != NativeScrollBehavior::PerformAfterNa tiveScroll)
545 callback->handleEvent(&scrollState);
546 if (callback->nativeScrollBehavior() != NativeScrollBehavior::DisableNativeS croll)
547 nativeDistributeScroll(scrollState);
548 if (callback->nativeScrollBehavior() == NativeScrollBehavior::PerformAfterNa tiveScroll)
549 callback->handleEvent(&scrollState);
550 };
551
552 void Element::nativeApplyScroll(ScrollState& scrollState)
501 { 553 {
502 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); 554 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
503 if (scrollState.fullyConsumed()) 555 if (scrollState.fullyConsumed())
504 return; 556 return;
505 557
506 const double deltaX = scrollState.deltaX(); 558 const double deltaX = scrollState.deltaX();
507 const double deltaY = scrollState.deltaY(); 559 const double deltaY = scrollState.deltaY();
508 bool scrolled = false; 560 bool scrolled = false;
509 561
510 // Handle the documentElement separately, as it scrolls the FrameView. 562 if (deltaY || deltaX)
511 if (this == document().documentElement()) { 563 document().updateLayoutIgnorePendingStylesheets();
564
565 // Handle the scrollingElement separately, as it scrolls the viewport.
566 if (this == document().scrollingElement()) {
512 FloatSize delta(deltaX, deltaY); 567 FloatSize delta(deltaX, deltaY);
513 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning( )).didScroll()) { 568 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning( )).didScroll()) {
514 scrolled = true; 569 scrolled = true;
515 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del taY()); 570 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del taY());
516 } 571 }
517 } else { 572 } else {
518 if (!layoutObject()) 573 if (!layoutObject())
519 return; 574 return;
520 LayoutBox* curBox = layoutObject()->enclosingBox(); 575 LayoutBox* curBox = layoutObject()->enclosingBox();
521 // FIXME: Native scrollers should only consume the scroll they 576 // FIXME: Native scrollers should only consume the scroll they
(...skipping 16 matching lines...) Expand all
538 // distributeScroll and applyScroll default implementations so 593 // distributeScroll and applyScroll default implementations so
539 // that if JS overrides one of these methods, but not the 594 // that if JS overrides one of these methods, but not the
540 // other, this bookkeeping remains accurate. 595 // other, this bookkeeping remains accurate.
541 scrollState.setCurrentNativeScrollingElement(this); 596 scrollState.setCurrentNativeScrollingElement(this);
542 if (scrollState.fromUserInput()) { 597 if (scrollState.fromUserInput()) {
543 if (DocumentLoader* documentLoader = document().loader()) 598 if (DocumentLoader* documentLoader = document().loader())
544 documentLoader->initialScrollState().wasScrolledByUser = true; 599 documentLoader->initialScrollState().wasScrolledByUser = true;
545 } 600 }
546 }; 601 };
547 602
603 void Element::callApplyScroll(ScrollState& scrollState)
604 {
605 ScrollStateCallback* callback = scrollCustomizationCallbacks().getApplyScrol l(this);
606 if (!callback) {
607 nativeApplyScroll(scrollState);
608 return;
609 }
610
611 if (callback->nativeScrollBehavior() != NativeScrollBehavior::PerformAfterNa tiveScroll)
612 callback->handleEvent(&scrollState);
613 if (callback->nativeScrollBehavior() != NativeScrollBehavior::DisableNativeS croll)
614 nativeApplyScroll(scrollState);
615 if (callback->nativeScrollBehavior() == NativeScrollBehavior::PerformAfterNa tiveScroll)
616 callback->handleEvent(&scrollState);
617 };
618
548 static float localZoomForLayoutObject(LayoutObject& layoutObject) 619 static float localZoomForLayoutObject(LayoutObject& layoutObject)
549 { 620 {
550 // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each 621 // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each
551 // other out, but the alternative is that we'd have to crawl up the whole la yout tree every 622 // other out, but the alternative is that we'd have to crawl up the whole la yout tree every
552 // time (or store an additional bit in the ComputedStyle to indicate that a zoom was specified). 623 // time (or store an additional bit in the ComputedStyle to indicate that a zoom was specified).
553 float zoomFactor = 1; 624 float zoomFactor = 1;
554 if (layoutObject.style()->effectiveZoom() != 1) { 625 if (layoutObject.style()->effectiveZoom() != 1) {
555 // Need to find the nearest enclosing LayoutObject that set up 626 // Need to find the nearest enclosing LayoutObject that set up
556 // a differing zoom, and then we divide our result by it to eliminate th e zoom. 627 // a differing zoom, and then we divide our result by it to eliminate th e zoom.
557 LayoutObject* prev = &layoutObject; 628 LayoutObject* prev = &layoutObject;
(...skipping 2939 matching lines...) Expand 10 before | Expand all | Expand 10 after
3497 { 3568 {
3498 #if ENABLE(OILPAN) 3569 #if ENABLE(OILPAN)
3499 if (hasRareData()) 3570 if (hasRareData())
3500 visitor->trace(elementRareData()); 3571 visitor->trace(elementRareData());
3501 visitor->trace(m_elementData); 3572 visitor->trace(m_elementData);
3502 #endif 3573 #endif
3503 ContainerNode::trace(visitor); 3574 ContainerNode::trace(visitor);
3504 } 3575 }
3505 3576
3506 } // namespace blink 3577 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698