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