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

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

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