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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 if (!layoutObject()) | 471 if (!layoutObject()) |
471 return; | 472 return; |
472 | 473 |
473 LayoutRect bounds = boundingBox(); | 474 LayoutRect bounds = boundingBox(); |
474 if (centerIfNeeded) | 475 if (centerIfNeeded) |
475 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter IfNeeded, ScrollAlignment::alignCenterIfNeeded); | 476 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter IfNeeded, ScrollAlignment::alignCenterIfNeeded); |
476 else | 477 else |
477 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); | 478 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); |
478 } | 479 } |
479 | 480 |
480 void Element::distributeScroll(ScrollState& scrollState) | 481 // Returns true iff a V8 method existed and was called. |
482 static bool callScrollCustomizationV8Method(Element* element, | |
483 ScrollState& scrollState, String methodName) | |
484 { | |
485 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | |
486 | |
487 LocalFrame* frame = element->document().frame(); | |
488 if (!frame) | |
489 return false; | |
490 ScriptState* scriptState = ScriptState::forMainWorld(frame); | |
491 ScriptState::Scope scope(scriptState); | |
492 | |
493 v8::Handle<v8::Object> creationContext = scriptState->context()->Global(); | |
494 ScriptValue thisWrapper = ScriptValue(scriptState, toV8(element, creationCon text, scriptState->isolate())); | |
495 ScriptValue scrollStateWrapper = ScriptValue(scriptState, toV8(&scrollState, creationContext, scriptState->isolate())); | |
496 | |
497 v8::Handle<v8::Object> thisObject = v8::Handle<v8::Object>::Cast(thisWrapper .v8Value()); | |
498 v8::Local<v8::Value> functionValue = thisObject->Get(v8String(scriptState->i solate(), methodName)); | |
499 ASSERT(functionValue->IsFunction()); | |
500 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(functionVal ue); | |
501 | |
502 // Native methods should avoid the performance overhead of a v8 method call. | |
503 if (function->ScriptId() == v8::UnboundScript::kNoScriptId) | |
504 return false; | |
505 | |
506 | |
507 V8ScriptRunner scriptRunner; | |
haraken
2015/06/09 15:16:38
We should have DISALLOW_ALLOCATION on V8ScriptRunn
| |
508 v8::Local<v8::Value> info[1]; | |
509 info[0] = scrollStateWrapper.v8Value(); | |
510 scriptRunner.callFunction(function, scriptState->executionContext(), thisObj ect, 1, info, scriptState->isolate()); | |
haraken
2015/06/09 15:16:38
Use V8ScriptRunner::.callFunction().
| |
511 return true; | |
512 } | |
513 | |
514 void Element::distributeScrollNative(ScrollState& scrollState) | |
481 { | 515 { |
482 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 516 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
483 if (scrollState.fullyConsumed()) | 517 if (scrollState.fullyConsumed()) |
484 return; | 518 return; |
485 | 519 |
486 scrollState.distributeToScrollChainDescendant(); | 520 scrollState.distributeToScrollChainDescendant(); |
487 | 521 |
488 // If the scroll doesn't propagate, and we're currently scrolling | 522 // If the scroll doesn't propagate, and we're currently scrolling |
489 // an element other than this one, prevent the scroll from | 523 // an element other than this one, prevent the scroll from |
490 // propagating to this element. | 524 // propagating to this element. |
491 if (!scrollState.shouldPropagate() | 525 if (!scrollState.shouldPropagate() |
492 && scrollState.deltaConsumedForScrollSequence() | 526 && scrollState.deltaConsumedForScrollSequence() |
493 && scrollState.currentNativeScrollingElement() != this) { | 527 && scrollState.currentNativeScrollingElement() != this) { |
494 return; | 528 return; |
495 } | 529 } |
496 | 530 |
497 const double deltaX = scrollState.deltaX(); | 531 const double deltaX = scrollState.deltaX(); |
498 const double deltaY = scrollState.deltaY(); | 532 const double deltaY = scrollState.deltaY(); |
499 | 533 |
500 applyScroll(scrollState); | 534 callApplyScroll(scrollState); |
501 | 535 |
502 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) | 536 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) |
503 scrollState.setCurrentNativeScrollingElement(this); | 537 scrollState.setCurrentNativeScrollingElement(this); |
504 } | 538 } |
505 | 539 |
506 void Element::applyScroll(ScrollState& scrollState) | 540 void Element::callDistributeScroll(ScrollState& scrollState) |
541 { | |
542 if (!callScrollCustomizationV8Method(this, scrollState, "distributeScroll")) | |
543 distributeScrollNative(scrollState); | |
544 }; | |
545 | |
546 void Element::distributeScroll(ScrollState* scrollState) | |
547 { | |
548 ASSERT(scrollState); | |
549 distributeScrollNative(*scrollState); | |
550 } | |
551 | |
552 void Element::applyScrollNative(ScrollState& scrollState) | |
507 { | 553 { |
508 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); | 554 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
555 document().updateLayoutIgnorePendingStylesheets(); | |
556 | |
509 if (scrollState.fullyConsumed()) | 557 if (scrollState.fullyConsumed()) |
510 return; | 558 return; |
511 | 559 |
512 const double deltaX = scrollState.deltaX(); | 560 const double deltaX = scrollState.deltaX(); |
513 const double deltaY = scrollState.deltaY(); | 561 const double deltaY = scrollState.deltaY(); |
514 bool scrolled = false; | 562 bool scrolled = false; |
515 | 563 |
516 // Handle the documentElement separately, as it scrolls the FrameView. | 564 // Handle the scrollingElement separately, as it scrolls the FrameView. |
517 if (this == document().documentElement()) { | 565 if (this == document().scrollingElement()) { |
518 FloatSize delta(deltaX, deltaY); | 566 FloatSize delta(deltaX, deltaY); |
519 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning( ))) { | 567 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning( ))) { |
520 scrolled = true; | 568 scrolled = true; |
521 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del taY()); | 569 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del taY()); |
522 } | 570 } |
523 } else { | 571 } else { |
524 if (!layoutObject()) | 572 if (!layoutObject()) |
525 return; | 573 return; |
526 LayoutBox* curBox = layoutObject()->enclosingBox(); | 574 LayoutBox* curBox = layoutObject()->enclosingBox(); |
527 // FIXME: Native scrollers should only consume the scroll they | 575 // FIXME: Native scrollers should only consume the scroll they |
(...skipping 14 matching lines...) Expand all Loading... | |
542 | 590 |
543 // We need to setCurrentNativeScrollingElement in both the | 591 // We need to setCurrentNativeScrollingElement in both the |
544 // distributeScroll and applyScroll default implementations so | 592 // distributeScroll and applyScroll default implementations so |
545 // that if JS overrides one of these methods, but not the | 593 // that if JS overrides one of these methods, but not the |
546 // other, this bookkeeping remains accurate. | 594 // other, this bookkeeping remains accurate. |
547 scrollState.setCurrentNativeScrollingElement(this); | 595 scrollState.setCurrentNativeScrollingElement(this); |
548 if (scrollState.fromUserInput()) | 596 if (scrollState.fromUserInput()) |
549 document().frame()->view()->setWasScrolledByUser(true); | 597 document().frame()->view()->setWasScrolledByUser(true); |
550 }; | 598 }; |
551 | 599 |
600 void Element::callApplyScroll(ScrollState& scrollState) | |
601 { | |
602 if (!callScrollCustomizationV8Method(this, scrollState, "applyScroll")) | |
603 applyScrollNative(scrollState); | |
604 }; | |
605 | |
606 void Element::applyScroll(ScrollState* scrollState) | |
607 { | |
608 ASSERT(scrollState); | |
609 applyScrollNative(*scrollState); | |
610 } | |
611 | |
552 static float localZoomForLayoutObject(LayoutObject& layoutObject) | 612 static float localZoomForLayoutObject(LayoutObject& layoutObject) |
553 { | 613 { |
554 // 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 |
555 // 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 |
556 // 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). |
557 float zoomFactor = 1; | 617 float zoomFactor = 1; |
558 if (layoutObject.style()->effectiveZoom() != 1) { | 618 if (layoutObject.style()->effectiveZoom() != 1) { |
559 // Need to find the nearest enclosing LayoutObject that set up | 619 // Need to find the nearest enclosing LayoutObject that set up |
560 // 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. |
561 LayoutObject* prev = &layoutObject; | 621 LayoutObject* prev = &layoutObject; |
(...skipping 2888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3450 { | 3510 { |
3451 #if ENABLE(OILPAN) | 3511 #if ENABLE(OILPAN) |
3452 if (hasRareData()) | 3512 if (hasRareData()) |
3453 visitor->trace(elementRareData()); | 3513 visitor->trace(elementRareData()); |
3454 visitor->trace(m_elementData); | 3514 visitor->trace(m_elementData); |
3455 #endif | 3515 #endif |
3456 ContainerNode::trace(visitor); | 3516 ContainerNode::trace(visitor); |
3457 } | 3517 } |
3458 | 3518 |
3459 } // namespace blink | 3519 } // namespace blink |
OLD | NEW |