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/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/ScrollState.h" | 115 #include "core/page/scrolling/ScrollState.h" |
| 116 #include "core/page/scrolling/ScrollStateCallback.h" |
116 #include "core/paint/DeprecatedPaintLayer.h" | 117 #include "core/paint/DeprecatedPaintLayer.h" |
117 #include "core/svg/SVGDocumentExtensions.h" | 118 #include "core/svg/SVGDocumentExtensions.h" |
118 #include "core/svg/SVGElement.h" | 119 #include "core/svg/SVGElement.h" |
119 #include "platform/EventDispatchForbiddenScope.h" | 120 #include "platform/EventDispatchForbiddenScope.h" |
120 #include "platform/RuntimeEnabledFeatures.h" | 121 #include "platform/RuntimeEnabledFeatures.h" |
121 #include "platform/UserGestureIndicator.h" | 122 #include "platform/UserGestureIndicator.h" |
122 #include "platform/scroll/ScrollableArea.h" | 123 #include "platform/scroll/ScrollableArea.h" |
123 #include "wtf/BitVector.h" | 124 #include "wtf/BitVector.h" |
124 #include "wtf/HashFunctions.h" | 125 #include "wtf/HashFunctions.h" |
125 #include "wtf/text/CString.h" | 126 #include "wtf/text/CString.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 if (!layoutObject()) | 464 if (!layoutObject()) |
464 return; | 465 return; |
465 | 466 |
466 LayoutRect bounds = boundingBox(); | 467 LayoutRect bounds = boundingBox(); |
467 if (centerIfNeeded) | 468 if (centerIfNeeded) |
468 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter
IfNeeded, ScrollAlignment::alignCenterIfNeeded); | 469 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter
IfNeeded, ScrollAlignment::alignCenterIfNeeded); |
469 else | 470 else |
470 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge
IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); | 471 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge
IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); |
471 } | 472 } |
472 | 473 |
473 void Element::distributeScroll(ScrollState& scrollState) | 474 namespace { |
| 475 |
| 476 NativeScrollBehavior toNativeScrollBehavior(String nativeScrollBehavior) |
| 477 { |
| 478 DEFINE_STATIC_LOCAL(const String, disable, ("disable-native-scroll")); |
| 479 DEFINE_STATIC_LOCAL(const String, before, ("perform-before-native-scroll")); |
| 480 DEFINE_STATIC_LOCAL(const String, after, ("perform-after-native-scroll")); |
| 481 |
| 482 if (nativeScrollBehavior == disable) |
| 483 return DisableNativeScroll; |
| 484 if (nativeScrollBehavior == before) |
| 485 return PerformBeforeNativeScroll; |
| 486 if (nativeScrollBehavior == after) |
| 487 return PerformAfterNativeScroll; |
| 488 |
| 489 ASSERT_NOT_REACHED(); |
| 490 return DisableNativeScroll; |
| 491 } |
| 492 |
| 493 } // namespace |
| 494 |
| 495 void Element::setDistributeScroll(ScrollStateCallback* scrollStateCallback, Stri
ng nativeScrollBehavior) |
| 496 { |
| 497 scrollStateCallback->setNativeScrollBehavior(toNativeScrollBehavior(nativeSc
rollBehavior)); |
| 498 ensureElementRareData().setDistributeScroll(scrollStateCallback); |
| 499 } |
| 500 |
| 501 void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback, String na
tiveScrollBehavior) |
| 502 { |
| 503 scrollStateCallback->setNativeScrollBehavior(toNativeScrollBehavior(nativeSc
rollBehavior)); |
| 504 ensureElementRareData().setApplyScroll(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 if (!hasRareData() || !elementRareData()->getDistributeScroll()) { |
| 536 nativeDistributeScroll(scrollState); |
| 537 } else { |
| 538 ScrollStateCallback& callback = *elementRareData()->getDistributeScroll(
); |
| 539 if (callback.nativeScrollBehavior() == PerformAfterNativeScroll) |
| 540 nativeDistributeScroll(scrollState); |
| 541 callback.handleEvent(&scrollState); |
| 542 if (callback.nativeScrollBehavior() == PerformBeforeNativeScroll) |
| 543 nativeDistributeScroll(scrollState); |
| 544 } |
| 545 }; |
| 546 |
| 547 void Element::nativeApplyScroll(ScrollState& scrollState) |
500 { | 548 { |
501 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 549 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
| 550 |
502 if (scrollState.fullyConsumed()) | 551 if (scrollState.fullyConsumed()) |
503 return; | 552 return; |
504 | 553 |
505 const double deltaX = scrollState.deltaX(); | 554 const double deltaX = scrollState.deltaX(); |
506 const double deltaY = scrollState.deltaY(); | 555 const double deltaY = scrollState.deltaY(); |
507 bool scrolled = false; | 556 bool scrolled = false; |
508 | 557 |
509 // Handle the documentElement separately, as it scrolls the FrameView. | 558 if (deltaY || deltaX) |
510 if (this == document().documentElement()) { | 559 document().updateLayoutIgnorePendingStylesheets(); |
| 560 |
| 561 // Handle the scrollingElement separately, as it scrolls the FrameView. |
| 562 if (this == document().scrollingElement()) { |
511 FloatSize delta(deltaX, deltaY); | 563 FloatSize delta(deltaX, deltaY); |
512 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning(
)).didScroll()) { | 564 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning(
)).didScroll()) { |
513 scrolled = true; | 565 scrolled = true; |
514 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del
taY()); | 566 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del
taY()); |
515 } | 567 } |
516 } else { | 568 } else { |
517 if (!layoutObject()) | 569 if (!layoutObject()) |
518 return; | 570 return; |
519 LayoutBox* curBox = layoutObject()->enclosingBox(); | 571 LayoutBox* curBox = layoutObject()->enclosingBox(); |
520 // FIXME: Native scrollers should only consume the scroll they | 572 // FIXME: Native scrollers should only consume the scroll they |
(...skipping 14 matching lines...) Expand all Loading... |
535 | 587 |
536 // We need to setCurrentNativeScrollingElement in both the | 588 // We need to setCurrentNativeScrollingElement in both the |
537 // distributeScroll and applyScroll default implementations so | 589 // distributeScroll and applyScroll default implementations so |
538 // that if JS overrides one of these methods, but not the | 590 // that if JS overrides one of these methods, but not the |
539 // other, this bookkeeping remains accurate. | 591 // other, this bookkeeping remains accurate. |
540 scrollState.setCurrentNativeScrollingElement(this); | 592 scrollState.setCurrentNativeScrollingElement(this); |
541 if (scrollState.fromUserInput()) | 593 if (scrollState.fromUserInput()) |
542 document().frame()->view()->setWasScrolledByUser(true); | 594 document().frame()->view()->setWasScrolledByUser(true); |
543 }; | 595 }; |
544 | 596 |
| 597 void Element::callApplyScroll(ScrollState& scrollState) |
| 598 { |
| 599 if (!hasRareData() || !elementRareData()->getApplyScroll()) { |
| 600 nativeApplyScroll(scrollState); |
| 601 } else { |
| 602 ScrollStateCallback& callback = *elementRareData()->getApplyScroll(); |
| 603 if (callback.nativeScrollBehavior() == PerformAfterNativeScroll) |
| 604 nativeApplyScroll(scrollState); |
| 605 callback.handleEvent(&scrollState); |
| 606 if (callback.nativeScrollBehavior() == PerformBeforeNativeScroll) |
| 607 nativeApplyScroll(scrollState); |
| 608 } |
| 609 }; |
| 610 |
545 static float localZoomForLayoutObject(LayoutObject& layoutObject) | 611 static float localZoomForLayoutObject(LayoutObject& layoutObject) |
546 { | 612 { |
547 // FIXME: This does the wrong thing if two opposing zooms are in effect and
canceled each | 613 // 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 | 614 // 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). | 615 // time (or store an additional bit in the ComputedStyle to indicate that a
zoom was specified). |
550 float zoomFactor = 1; | 616 float zoomFactor = 1; |
551 if (layoutObject.style()->effectiveZoom() != 1) { | 617 if (layoutObject.style()->effectiveZoom() != 1) { |
552 // Need to find the nearest enclosing LayoutObject that set up | 618 // 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. | 619 // a differing zoom, and then we divide our result by it to eliminate th
e zoom. |
554 LayoutObject* prev = &layoutObject; | 620 LayoutObject* prev = &layoutObject; |
(...skipping 2874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3429 { | 3495 { |
3430 #if ENABLE(OILPAN) | 3496 #if ENABLE(OILPAN) |
3431 if (hasRareData()) | 3497 if (hasRareData()) |
3432 visitor->trace(elementRareData()); | 3498 visitor->trace(elementRareData()); |
3433 visitor->trace(m_elementData); | 3499 visitor->trace(m_elementData); |
3434 #endif | 3500 #endif |
3435 ContainerNode::trace(visitor); | 3501 ContainerNode::trace(visitor); |
3436 } | 3502 } |
3437 | 3503 |
3438 } // namespace blink | 3504 } // namespace blink |
OLD | NEW |