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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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::removeScrollCustomizationCallbacksForDocument(Document* document) |
|
haraken
2015/08/27 00:49:40
Can we remove this?
tdresser
2015/08/27 20:48:39
Done.
| |
| 499 { | |
| 500 scrollCustomizationCallbacks().removeAllCallbacksForDocument(document); | |
| 501 } | |
| 502 | |
| 503 void Element::setDistributeScroll(ScrollStateCallback* scrollStateCallback, Stri ng nativeScrollBehavior) | |
| 504 { | |
| 505 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc rollBehavior(nativeScrollBehavior)); | |
| 506 scrollCustomizationCallbacks().setDistributeScroll(this, scrollStateCallback ); | |
| 507 } | |
| 508 | |
| 509 void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback, String na tiveScrollBehavior) | |
| 510 { | |
| 511 scrollStateCallback->setNativeScrollBehavior(ScrollStateCallback::toNativeSc rollBehavior(nativeScrollBehavior)); | |
| 512 scrollCustomizationCallbacks().setApplyScroll(this, scrollStateCallback); | |
| 513 } | |
| 514 | |
| 515 void Element::nativeDistributeScroll(ScrollState& scrollState) | |
| 475 { | 516 { |
| 476 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 517 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
| 477 if (scrollState.fullyConsumed()) | 518 if (scrollState.fullyConsumed()) |
| 478 return; | 519 return; |
| 479 | 520 |
| 480 scrollState.distributeToScrollChainDescendant(); | 521 scrollState.distributeToScrollChainDescendant(); |
| 481 | 522 |
| 482 // If the scroll doesn't propagate, and we're currently scrolling | 523 // If the scroll doesn't propagate, and we're currently scrolling |
| 483 // an element other than this one, prevent the scroll from | 524 // an element other than this one, prevent the scroll from |
| 484 // propagating to this element. | 525 // propagating to this element. |
| 485 if (!scrollState.shouldPropagate() | 526 if (!scrollState.shouldPropagate() |
| 486 && scrollState.deltaConsumedForScrollSequence() | 527 && scrollState.deltaConsumedForScrollSequence() |
| 487 && scrollState.currentNativeScrollingElement() != this) { | 528 && scrollState.currentNativeScrollingElement() != this) { |
| 488 return; | 529 return; |
| 489 } | 530 } |
| 490 | 531 |
| 491 const double deltaX = scrollState.deltaX(); | 532 const double deltaX = scrollState.deltaX(); |
| 492 const double deltaY = scrollState.deltaY(); | 533 const double deltaY = scrollState.deltaY(); |
| 493 | 534 |
| 494 applyScroll(scrollState); | 535 callApplyScroll(scrollState); |
| 495 | 536 |
| 496 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) | 537 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) |
| 497 scrollState.setCurrentNativeScrollingElement(this); | 538 scrollState.setCurrentNativeScrollingElement(this); |
| 498 } | 539 } |
| 499 | 540 |
| 500 void Element::applyScroll(ScrollState& scrollState) | 541 void Element::callDistributeScroll(ScrollState& scrollState) |
| 542 { | |
| 543 ScrollStateCallback* callback = scrollCustomizationCallbacks().getDistribute Scroll(this); | |
| 544 if (!callback) { | |
| 545 nativeDistributeScroll(scrollState); | |
| 546 } else { | |
| 547 if (callback->nativeScrollBehavior() == NativeScrollBehavior::PerformAft erNativeScroll) | |
|
haraken
2015/08/27 00:49:40
Shouldn't this be "Before"?
tdresser
2015/08/27 20:48:40
This is correct, but confusing.
I rearranged it to
| |
| 548 nativeDistributeScroll(scrollState); | |
| 549 callback->handleEvent(&scrollState); | |
| 550 if (callback->nativeScrollBehavior() == NativeScrollBehavior::PerformBef oreNativeScroll) | |
|
haraken
2015/08/27 00:49:40
Shouldn't this be "After"?
tdresser
2015/08/27 20:48:40
Same as above.
| |
| 551 nativeDistributeScroll(scrollState); | |
| 552 } | |
| 553 }; | |
| 554 | |
| 555 void Element::nativeApplyScroll(ScrollState& scrollState) | |
| 501 { | 556 { |
| 502 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 557 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
| 503 if (scrollState.fullyConsumed()) | 558 if (scrollState.fullyConsumed()) |
| 504 return; | 559 return; |
| 505 | 560 |
| 506 const double deltaX = scrollState.deltaX(); | 561 const double deltaX = scrollState.deltaX(); |
| 507 const double deltaY = scrollState.deltaY(); | 562 const double deltaY = scrollState.deltaY(); |
| 508 bool scrolled = false; | 563 bool scrolled = false; |
| 509 | 564 |
| 510 // Handle the documentElement separately, as it scrolls the FrameView. | 565 if (deltaY || deltaX) |
| 511 if (this == document().documentElement()) { | 566 document().updateLayoutIgnorePendingStylesheets(); |
| 567 | |
| 568 // Handle the scrollingElement separately, as it scrolls the viewport. | |
| 569 if (this == document().scrollingElement()) { | |
| 512 FloatSize delta(deltaX, deltaY); | 570 FloatSize delta(deltaX, deltaY); |
| 513 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning( )).didScroll()) { | 571 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning( )).didScroll()) { |
| 514 scrolled = true; | 572 scrolled = true; |
| 515 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del taY()); | 573 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del taY()); |
| 516 } | 574 } |
| 517 } else { | 575 } else { |
| 518 if (!layoutObject()) | 576 if (!layoutObject()) |
| 519 return; | 577 return; |
| 520 LayoutBox* curBox = layoutObject()->enclosingBox(); | 578 LayoutBox* curBox = layoutObject()->enclosingBox(); |
| 521 // FIXME: Native scrollers should only consume the scroll they | 579 // FIXME: Native scrollers should only consume the scroll they |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 538 // distributeScroll and applyScroll default implementations so | 596 // distributeScroll and applyScroll default implementations so |
| 539 // that if JS overrides one of these methods, but not the | 597 // that if JS overrides one of these methods, but not the |
| 540 // other, this bookkeeping remains accurate. | 598 // other, this bookkeeping remains accurate. |
| 541 scrollState.setCurrentNativeScrollingElement(this); | 599 scrollState.setCurrentNativeScrollingElement(this); |
| 542 if (scrollState.fromUserInput()) { | 600 if (scrollState.fromUserInput()) { |
| 543 if (DocumentLoader* documentLoader = document().loader()) | 601 if (DocumentLoader* documentLoader = document().loader()) |
| 544 documentLoader->initialScrollState().wasScrolledByUser = true; | 602 documentLoader->initialScrollState().wasScrolledByUser = true; |
| 545 } | 603 } |
| 546 }; | 604 }; |
| 547 | 605 |
| 606 void Element::callApplyScroll(ScrollState& scrollState) | |
| 607 { | |
| 608 ScrollStateCallback* callback = scrollCustomizationCallbacks().getApplyScrol l(this); | |
| 609 if (!callback) { | |
| 610 nativeApplyScroll(scrollState); | |
| 611 } else { | |
| 612 if (callback->nativeScrollBehavior() == NativeScrollBehavior::PerformAft erNativeScroll) | |
|
haraken
2015/08/27 00:49:40
Ditto.
tdresser
2015/08/27 20:48:40
Same as above.
| |
| 613 nativeApplyScroll(scrollState); | |
| 614 callback->handleEvent(&scrollState); | |
| 615 if (callback->nativeScrollBehavior() == NativeScrollBehavior::PerformBef oreNativeScroll) | |
|
haraken
2015/08/27 00:49:40
Ditto.
tdresser
2015/08/27 20:48:39
Same as above.
| |
| 616 nativeApplyScroll(scrollState); | |
| 617 } | |
| 618 }; | |
| 619 | |
| 548 static float localZoomForLayoutObject(LayoutObject& layoutObject) | 620 static float localZoomForLayoutObject(LayoutObject& layoutObject) |
| 549 { | 621 { |
| 550 // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each | 622 // 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 | 623 // 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). | 624 // time (or store an additional bit in the ComputedStyle to indicate that a zoom was specified). |
| 553 float zoomFactor = 1; | 625 float zoomFactor = 1; |
| 554 if (layoutObject.style()->effectiveZoom() != 1) { | 626 if (layoutObject.style()->effectiveZoom() != 1) { |
| 555 // Need to find the nearest enclosing LayoutObject that set up | 627 // 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. | 628 // a differing zoom, and then we divide our result by it to eliminate th e zoom. |
| 557 LayoutObject* prev = &layoutObject; | 629 LayoutObject* prev = &layoutObject; |
| (...skipping 2939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3497 { | 3569 { |
| 3498 #if ENABLE(OILPAN) | 3570 #if ENABLE(OILPAN) |
| 3499 if (hasRareData()) | 3571 if (hasRareData()) |
| 3500 visitor->trace(elementRareData()); | 3572 visitor->trace(elementRareData()); |
| 3501 visitor->trace(m_elementData); | 3573 visitor->trace(m_elementData); |
| 3502 #endif | 3574 #endif |
| 3503 ContainerNode::trace(visitor); | 3575 ContainerNode::trace(visitor); |
| 3504 } | 3576 } |
| 3505 | 3577 |
| 3506 } // namespace blink | 3578 } // namespace blink |
| OLD | NEW |