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 12 matching lines...) Expand all Loading... |
23 * Boston, MA 02110-1301, USA. | 23 * Boston, MA 02110-1301, USA. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/dom/Element.h" | 27 #include "core/dom/Element.h" |
28 | 28 |
29 #include "bindings/core/v8/DOMDataStore.h" | 29 #include "bindings/core/v8/DOMDataStore.h" |
30 #include "bindings/core/v8/Dictionary.h" | 30 #include "bindings/core/v8/Dictionary.h" |
31 #include "bindings/core/v8/ExceptionMessages.h" | 31 #include "bindings/core/v8/ExceptionMessages.h" |
32 #include "bindings/core/v8/ExceptionState.h" | 32 #include "bindings/core/v8/ExceptionState.h" |
| 33 #include "bindings/core/v8/ToV8.h" |
33 #include "bindings/core/v8/V8DOMWrapper.h" | 34 #include "bindings/core/v8/V8DOMWrapper.h" |
34 #include "bindings/core/v8/V8PerContextData.h" | 35 #include "bindings/core/v8/V8PerContextData.h" |
35 #include "core/CSSValueKeywords.h" | 36 #include "core/CSSValueKeywords.h" |
36 #include "core/SVGNames.h" | 37 #include "core/SVGNames.h" |
37 #include "core/XLinkNames.h" | 38 #include "core/XLinkNames.h" |
38 #include "core/XMLNames.h" | 39 #include "core/XMLNames.h" |
39 #include "core/animation/AnimationTimeline.h" | 40 #include "core/animation/AnimationTimeline.h" |
40 #include "core/animation/css/CSSAnimations.h" | 41 #include "core/animation/css/CSSAnimations.h" |
41 #include "core/css/CSSImageValue.h" | 42 #include "core/css/CSSImageValue.h" |
42 #include "core/css/CSSStyleSheet.h" | 43 #include "core/css/CSSStyleSheet.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 #include "core/html/parser/HTMLParserIdioms.h" | 107 #include "core/html/parser/HTMLParserIdioms.h" |
107 #include "core/inspector/InspectorInstrumentation.h" | 108 #include "core/inspector/InspectorInstrumentation.h" |
108 #include "core/layout/LayoutTextFragment.h" | 109 #include "core/layout/LayoutTextFragment.h" |
109 #include "core/layout/LayoutView.h" | 110 #include "core/layout/LayoutView.h" |
110 #include "core/page/ChromeClient.h" | 111 #include "core/page/ChromeClient.h" |
111 #include "core/page/FocusController.h" | 112 #include "core/page/FocusController.h" |
112 #include "core/page/Page.h" | 113 #include "core/page/Page.h" |
113 #include "core/page/PointerLockController.h" | 114 #include "core/page/PointerLockController.h" |
114 #include "core/page/SpatialNavigation.h" | 115 #include "core/page/SpatialNavigation.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" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 if (!layoutObject()) | 465 if (!layoutObject()) |
464 return; | 466 return; |
465 | 467 |
466 LayoutRect bounds = boundingBox(); | 468 LayoutRect bounds = boundingBox(); |
467 if (centerIfNeeded) | 469 if (centerIfNeeded) |
468 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter
IfNeeded, ScrollAlignment::alignCenterIfNeeded); | 470 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter
IfNeeded, ScrollAlignment::alignCenterIfNeeded); |
469 else | 471 else |
470 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge
IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); | 472 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge
IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); |
471 } | 473 } |
472 | 474 |
473 void Element::distributeScroll(ScrollState& scrollState) | 475 namespace { |
| 476 |
| 477 class DistributeScrollCallback : public ScrollStateCallback { |
| 478 public: |
| 479 DistributeScrollCallback() |
| 480 { |
| 481 m_callbackType = CallbackType::DISTRIBUTE_SCROLL; |
| 482 } |
| 483 void handleEvent(ScrollState* scrollState) |
| 484 { |
| 485 ASSERT(m_targetElement); |
| 486 ASSERT(scrollState); |
| 487 m_targetElement->nativeDistributeScroll(*scrollState); |
| 488 } |
| 489 }; |
| 490 |
| 491 class ApplyScrollCallback : public ScrollStateCallback { |
| 492 public: |
| 493 ApplyScrollCallback() |
| 494 { |
| 495 m_callbackType = CallbackType::APPLY_SCROLL; |
| 496 } |
| 497 |
| 498 void handleEvent(ScrollState* scrollState) |
| 499 { |
| 500 ASSERT(m_targetElement); |
| 501 ASSERT(scrollState); |
| 502 m_targetElement->nativeApplyScroll(*scrollState); |
| 503 } |
| 504 }; |
| 505 |
| 506 } // namespace |
| 507 |
| 508 void Element::setDistributeScroll(ScrollStateCallback* scrollStateCallback) |
| 509 { |
| 510 scrollStateCallback->setCallbackType(ScrollStateCallback::CallbackType::DIST
RIBUTE_SCROLL); |
| 511 ensureElementRareData().setDistributeScroll(adoptRefWillBeNoop(scrollStateCa
llback)); |
| 512 } |
| 513 |
| 514 ScriptValue Element::distributeScroll(ScriptState* scriptState) |
| 515 { |
| 516 if (!hasRareData() || !elementRareData()->getDistributeScroll()) |
| 517 setDistributeScroll(new DistributeScrollCallback()); |
| 518 return elementRareData()->getDistributeScroll()->toScriptValue(scriptState); |
| 519 } |
| 520 |
| 521 void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback) |
| 522 { |
| 523 scrollStateCallback->setCallbackType(ScrollStateCallback::CallbackType::APPL
Y_SCROLL); |
| 524 ensureElementRareData().setApplyScroll(adoptRefWillBeNoop(scrollStateCallbac
k)); |
| 525 } |
| 526 |
| 527 ScriptValue Element::applyScroll(ScriptState* scriptState) |
| 528 { |
| 529 if (!hasRareData() || !elementRareData()->getApplyScroll()) |
| 530 setApplyScroll(new ApplyScrollCallback()); |
| 531 return elementRareData()->getApplyScroll()->toScriptValue(scriptState); |
| 532 } |
| 533 |
| 534 void Element::nativeDistributeScroll(ScrollState& scrollState) |
474 { | 535 { |
475 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 536 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
476 if (scrollState.fullyConsumed()) | 537 if (scrollState.fullyConsumed()) |
477 return; | 538 return; |
478 | 539 |
479 scrollState.distributeToScrollChainDescendant(); | 540 scrollState.distributeToScrollChainDescendant(); |
480 | 541 |
481 // If the scroll doesn't propagate, and we're currently scrolling | 542 // If the scroll doesn't propagate, and we're currently scrolling |
482 // an element other than this one, prevent the scroll from | 543 // an element other than this one, prevent the scroll from |
483 // propagating to this element. | 544 // propagating to this element. |
484 if (!scrollState.shouldPropagate() | 545 if (!scrollState.shouldPropagate() |
485 && scrollState.deltaConsumedForScrollSequence() | 546 && scrollState.deltaConsumedForScrollSequence() |
486 && scrollState.currentNativeScrollingElement() != this) { | 547 && scrollState.currentNativeScrollingElement() != this) { |
487 return; | 548 return; |
488 } | 549 } |
489 | 550 |
490 const double deltaX = scrollState.deltaX(); | 551 const double deltaX = scrollState.deltaX(); |
491 const double deltaY = scrollState.deltaY(); | 552 const double deltaY = scrollState.deltaY(); |
492 | 553 |
493 applyScroll(scrollState); | 554 callApplyScroll(scrollState); |
494 | 555 |
495 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) | 556 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) |
496 scrollState.setCurrentNativeScrollingElement(this); | 557 scrollState.setCurrentNativeScrollingElement(this); |
497 } | 558 } |
498 | 559 |
499 void Element::applyScroll(ScrollState& scrollState) | 560 void Element::callDistributeScroll(ScrollState& scrollState) |
| 561 { |
| 562 if (!hasRareData() || !elementRareData()->getDistributeScroll()) |
| 563 nativeDistributeScroll(scrollState); |
| 564 else |
| 565 elementRareData()->getDistributeScroll()->handleEventForElement(*this, &
scrollState); |
| 566 }; |
| 567 |
| 568 void Element::nativeApplyScroll(ScrollState& scrollState) |
500 { | 569 { |
501 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 570 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
| 571 document().updateLayoutIgnorePendingStylesheets(); |
| 572 |
502 if (scrollState.fullyConsumed()) | 573 if (scrollState.fullyConsumed()) |
503 return; | 574 return; |
504 | 575 |
505 const double deltaX = scrollState.deltaX(); | 576 const double deltaX = scrollState.deltaX(); |
506 const double deltaY = scrollState.deltaY(); | 577 const double deltaY = scrollState.deltaY(); |
507 bool scrolled = false; | 578 bool scrolled = false; |
508 | 579 |
509 // Handle the documentElement separately, as it scrolls the FrameView. | 580 // Handle the scrollingElement separately, as it scrolls the FrameView. |
510 if (this == document().documentElement()) { | 581 if (this == document().scrollingElement()) { |
511 FloatSize delta(deltaX, deltaY); | 582 FloatSize delta(deltaX, deltaY); |
512 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning(
)).didScroll()) { | 583 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning(
)).didScroll()) { |
513 scrolled = true; | 584 scrolled = true; |
514 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del
taY()); | 585 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del
taY()); |
515 } | 586 } |
516 } else { | 587 } else { |
517 if (!layoutObject()) | 588 if (!layoutObject()) |
518 return; | 589 return; |
519 LayoutBox* curBox = layoutObject()->enclosingBox(); | 590 LayoutBox* curBox = layoutObject()->enclosingBox(); |
520 // FIXME: Native scrollers should only consume the scroll they | 591 // FIXME: Native scrollers should only consume the scroll they |
(...skipping 14 matching lines...) Expand all Loading... |
535 | 606 |
536 // We need to setCurrentNativeScrollingElement in both the | 607 // We need to setCurrentNativeScrollingElement in both the |
537 // distributeScroll and applyScroll default implementations so | 608 // distributeScroll and applyScroll default implementations so |
538 // that if JS overrides one of these methods, but not the | 609 // that if JS overrides one of these methods, but not the |
539 // other, this bookkeeping remains accurate. | 610 // other, this bookkeeping remains accurate. |
540 scrollState.setCurrentNativeScrollingElement(this); | 611 scrollState.setCurrentNativeScrollingElement(this); |
541 if (scrollState.fromUserInput()) | 612 if (scrollState.fromUserInput()) |
542 document().frame()->view()->setWasScrolledByUser(true); | 613 document().frame()->view()->setWasScrolledByUser(true); |
543 }; | 614 }; |
544 | 615 |
| 616 void Element::callApplyScroll(ScrollState& scrollState) |
| 617 { |
| 618 if (!hasRareData() || !elementRareData()->getApplyScroll()) |
| 619 nativeApplyScroll(scrollState); |
| 620 else |
| 621 elementRareData()->getApplyScroll()->handleEventForElement(*this, &scrol
lState); |
| 622 }; |
| 623 |
545 static float localZoomForLayoutObject(LayoutObject& layoutObject) | 624 static float localZoomForLayoutObject(LayoutObject& layoutObject) |
546 { | 625 { |
547 // FIXME: This does the wrong thing if two opposing zooms are in effect and
canceled each | 626 // 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 | 627 // 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). | 628 // time (or store an additional bit in the ComputedStyle to indicate that a
zoom was specified). |
550 float zoomFactor = 1; | 629 float zoomFactor = 1; |
551 if (layoutObject.style()->effectiveZoom() != 1) { | 630 if (layoutObject.style()->effectiveZoom() != 1) { |
552 // Need to find the nearest enclosing LayoutObject that set up | 631 // 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. | 632 // a differing zoom, and then we divide our result by it to eliminate th
e zoom. |
554 LayoutObject* prev = &layoutObject; | 633 LayoutObject* prev = &layoutObject; |
(...skipping 2877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3432 { | 3511 { |
3433 #if ENABLE(OILPAN) | 3512 #if ENABLE(OILPAN) |
3434 if (hasRareData()) | 3513 if (hasRareData()) |
3435 visitor->trace(elementRareData()); | 3514 visitor->trace(elementRareData()); |
3436 visitor->trace(m_elementData); | 3515 visitor->trace(m_elementData); |
3437 #endif | 3516 #endif |
3438 ContainerNode::trace(visitor); | 3517 ContainerNode::trace(visitor); |
3439 } | 3518 } |
3440 | 3519 |
3441 } // namespace blink | 3520 } // namespace blink |
OLD | NEW |