| 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 { |
| 144 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
| 145 DEFINE_STATIC_LOCAL(Persistent<ScrollCustomizationCallbacks>, |
| 146 scrollCustomizationCallbacks, (new ScrollCustomizationCallbacks())); |
| 147 return *scrollCustomizationCallbacks; |
| 148 } |
| 149 |
| 150 } // namespace |
| 151 |
| 131 using namespace HTMLNames; | 152 using namespace HTMLNames; |
| 132 using namespace XMLNames; | 153 using namespace XMLNames; |
| 133 | 154 |
| 134 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do
cument* document) | 155 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do
cument* document) |
| 135 { | 156 { |
| 136 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement)); | 157 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement)); |
| 137 } | 158 } |
| 138 | 159 |
| 139 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT
ype type) | 160 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT
ype type) |
| 140 : ContainerNode(document, type) | 161 : ContainerNode(document, type) |
| 141 , m_tagName(tagName) | 162 , m_tagName(tagName) |
| 142 { | 163 { |
| 143 } | 164 } |
| 144 | 165 |
| 145 Element::~Element() | 166 Element::~Element() |
| 146 { | 167 { |
| 147 ASSERT(needsAttach()); | 168 ASSERT(needsAttach()); |
| 148 | 169 |
| 149 #if !ENABLE(OILPAN) | 170 #if !ENABLE(OILPAN) |
| 150 if (hasRareData()) { | 171 if (hasRareData()) { |
| 151 elementRareData()->clearShadow(); | 172 elementRareData()->clearShadow(); |
| 152 detachAllAttrNodesFromElement(); | 173 detachAllAttrNodesFromElement(); |
| 153 } | 174 } |
| 154 | 175 |
| 155 if (isCustomElement()) | 176 if (isCustomElement()) |
| 156 CustomElement::wasDestroyed(this); | 177 CustomElement::wasDestroyed(this); |
| 157 | 178 |
| 179 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) |
| 180 scrollCustomizationCallbacks().removeCallbacksForElement(this); |
| 181 |
| 158 // With Oilpan, either the Element has been removed from the Document | 182 // 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 | 183 // 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 | 184 // 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 | 185 // resources. If the document is also dead, there is no need to remove |
| 162 // the element from the pending resources. | 186 // the element from the pending resources. |
| 163 if (hasPendingResources()) { | 187 if (hasPendingResources()) { |
| 164 document().accessSVGExtensions().removeElementFromPendingResources(this)
; | 188 document().accessSVGExtensions().removeElementFromPendingResources(this)
; |
| 165 ASSERT(!hasPendingResources()); | 189 ASSERT(!hasPendingResources()); |
| 166 } | 190 } |
| 167 #endif | 191 #endif |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 if (!layoutObject()) | 487 if (!layoutObject()) |
| 464 return; | 488 return; |
| 465 | 489 |
| 466 LayoutRect bounds = boundingBox(); | 490 LayoutRect bounds = boundingBox(); |
| 467 if (centerIfNeeded) | 491 if (centerIfNeeded) |
| 468 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter
IfNeeded, ScrollAlignment::alignCenterIfNeeded); | 492 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter
IfNeeded, ScrollAlignment::alignCenterIfNeeded); |
| 469 else | 493 else |
| 470 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge
IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); | 494 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge
IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); |
| 471 } | 495 } |
| 472 | 496 |
| 473 void Element::distributeScroll(ScrollState& scrollState) | 497 void Element::setDistributeScroll(ScrollStateCallback* scrollStateCallback, Stri
ng nativeScrollBehavior) |
| 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) |
| 474 { | 510 { |
| 475 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 511 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
| 476 if (scrollState.fullyConsumed()) | 512 if (scrollState.fullyConsumed()) |
| 477 return; | 513 return; |
| 478 | 514 |
| 479 scrollState.distributeToScrollChainDescendant(); | 515 scrollState.distributeToScrollChainDescendant(); |
| 480 | 516 |
| 481 // If the scroll doesn't propagate, and we're currently scrolling | 517 // If the scroll doesn't propagate, and we're currently scrolling |
| 482 // an element other than this one, prevent the scroll from | 518 // an element other than this one, prevent the scroll from |
| 483 // propagating to this element. | 519 // propagating to this element. |
| 484 if (!scrollState.shouldPropagate() | 520 if (!scrollState.shouldPropagate() |
| 485 && scrollState.deltaConsumedForScrollSequence() | 521 && scrollState.deltaConsumedForScrollSequence() |
| 486 && scrollState.currentNativeScrollingElement() != this) { | 522 && scrollState.currentNativeScrollingElement() != this) { |
| 487 return; | 523 return; |
| 488 } | 524 } |
| 489 | 525 |
| 490 const double deltaX = scrollState.deltaX(); | 526 const double deltaX = scrollState.deltaX(); |
| 491 const double deltaY = scrollState.deltaY(); | 527 const double deltaY = scrollState.deltaY(); |
| 492 | 528 |
| 493 applyScroll(scrollState); | 529 callApplyScroll(scrollState); |
| 494 | 530 |
| 495 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) | 531 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) |
| 496 scrollState.setCurrentNativeScrollingElement(this); | 532 scrollState.setCurrentNativeScrollingElement(this); |
| 497 } | 533 } |
| 498 | 534 |
| 499 void Element::applyScroll(ScrollState& scrollState) | 535 void Element::callDistributeScroll(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) |
| 500 { | 550 { |
| 501 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 551 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
| 502 if (scrollState.fullyConsumed()) | 552 if (scrollState.fullyConsumed()) |
| 503 return; | 553 return; |
| 504 | 554 |
| 505 const double deltaX = scrollState.deltaX(); | 555 const double deltaX = scrollState.deltaX(); |
| 506 const double deltaY = scrollState.deltaY(); | 556 const double deltaY = scrollState.deltaY(); |
| 507 bool scrolled = false; | 557 bool scrolled = false; |
| 508 | 558 |
| 509 // Handle the documentElement separately, as it scrolls the FrameView. | 559 if (deltaY || deltaX) |
| 510 if (this == document().documentElement()) { | 560 document().updateLayoutIgnorePendingStylesheets(); |
| 561 |
| 562 // Handle the scrollingElement separately, as it scrolls the viewport. |
| 563 if (this == document().scrollingElement()) { |
| 511 FloatSize delta(deltaX, deltaY); | 564 FloatSize delta(deltaX, deltaY); |
| 512 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning(
)).didScroll()) { | 565 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning(
)).didScroll()) { |
| 513 scrolled = true; | 566 scrolled = true; |
| 514 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del
taY()); | 567 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del
taY()); |
| 515 } | 568 } |
| 516 } else { | 569 } else { |
| 517 if (!layoutObject()) | 570 if (!layoutObject()) |
| 518 return; | 571 return; |
| 519 LayoutBox* curBox = layoutObject()->enclosingBox(); | 572 LayoutBox* curBox = layoutObject()->enclosingBox(); |
| 520 // FIXME: Native scrollers should only consume the scroll they | 573 // FIXME: Native scrollers should only consume the scroll they |
| (...skipping 14 matching lines...) Expand all Loading... |
| 535 | 588 |
| 536 // We need to setCurrentNativeScrollingElement in both the | 589 // We need to setCurrentNativeScrollingElement in both the |
| 537 // distributeScroll and applyScroll default implementations so | 590 // distributeScroll and applyScroll default implementations so |
| 538 // that if JS overrides one of these methods, but not the | 591 // that if JS overrides one of these methods, but not the |
| 539 // other, this bookkeeping remains accurate. | 592 // other, this bookkeeping remains accurate. |
| 540 scrollState.setCurrentNativeScrollingElement(this); | 593 scrollState.setCurrentNativeScrollingElement(this); |
| 541 if (scrollState.fromUserInput()) | 594 if (scrollState.fromUserInput()) |
| 542 document().frame()->view()->setWasScrolledByUser(true); | 595 document().frame()->view()->setWasScrolledByUser(true); |
| 543 }; | 596 }; |
| 544 | 597 |
| 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 |
| 545 static float localZoomForLayoutObject(LayoutObject& layoutObject) | 612 static float localZoomForLayoutObject(LayoutObject& layoutObject) |
| 546 { | 613 { |
| 547 // FIXME: This does the wrong thing if two opposing zooms are in effect and
canceled each | 614 // 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 | 615 // 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). | 616 // time (or store an additional bit in the ComputedStyle to indicate that a
zoom was specified). |
| 550 float zoomFactor = 1; | 617 float zoomFactor = 1; |
| 551 if (layoutObject.style()->effectiveZoom() != 1) { | 618 if (layoutObject.style()->effectiveZoom() != 1) { |
| 552 // Need to find the nearest enclosing LayoutObject that set up | 619 // 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. | 620 // a differing zoom, and then we divide our result by it to eliminate th
e zoom. |
| 554 LayoutObject* prev = &layoutObject; | 621 LayoutObject* prev = &layoutObject; |
| (...skipping 2894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3449 { | 3516 { |
| 3450 #if ENABLE(OILPAN) | 3517 #if ENABLE(OILPAN) |
| 3451 if (hasRareData()) | 3518 if (hasRareData()) |
| 3452 visitor->trace(elementRareData()); | 3519 visitor->trace(elementRareData()); |
| 3453 visitor->trace(m_elementData); | 3520 visitor->trace(m_elementData); |
| 3454 #endif | 3521 #endif |
| 3455 ContainerNode::trace(visitor); | 3522 ContainerNode::trace(visitor); |
| 3456 } | 3523 } |
| 3457 | 3524 |
| 3458 } // namespace blink | 3525 } // namespace blink |
| OLD | NEW |