Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: Source/core/dom/Element.cpp

Issue 1057603002: Expose scroll customization for touch to JS (behind REF). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix case where documentElement was added to scroll chain twice. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/ScriptFunctionCall.h"
34 #include "bindings/core/v8/ToV8.h"
33 #include "bindings/core/v8/V8DOMWrapper.h" 35 #include "bindings/core/v8/V8DOMWrapper.h"
34 #include "bindings/core/v8/V8PerContextData.h" 36 #include "bindings/core/v8/V8PerContextData.h"
35 #include "core/CSSValueKeywords.h" 37 #include "core/CSSValueKeywords.h"
36 #include "core/SVGNames.h" 38 #include "core/SVGNames.h"
37 #include "core/XLinkNames.h" 39 #include "core/XLinkNames.h"
38 #include "core/XMLNames.h" 40 #include "core/XMLNames.h"
39 #include "core/animation/AnimationTimeline.h" 41 #include "core/animation/AnimationTimeline.h"
40 #include "core/animation/css/CSSAnimations.h" 42 #include "core/animation/css/CSSAnimations.h"
41 #include "core/css/CSSImageValue.h" 43 #include "core/css/CSSImageValue.h"
42 #include "core/css/CSSStyleSheet.h" 44 #include "core/css/CSSStyleSheet.h"
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 if (!layoutObject()) 484 if (!layoutObject())
483 return; 485 return;
484 486
485 LayoutRect bounds = boundingBox(); 487 LayoutRect bounds = boundingBox();
486 if (centerIfNeeded) 488 if (centerIfNeeded)
487 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter IfNeeded, ScrollAlignment::alignCenterIfNeeded); 489 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignCenter IfNeeded, ScrollAlignment::alignCenterIfNeeded);
488 else 490 else
489 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); 491 layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdge IfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
490 } 492 }
491 493
492 void Element::distributeScroll(ScrollState& scrollState) 494 // Returns true iff a V8 method existed and was called.
495 static bool callScrollCustomizationV8Method(Element* element,
496 ScrollState& scrollState, String methodName)
497 {
498 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
499
500 LocalFrame* frame = element->document().frame();
501 if (!frame)
502 return false;
503 ScriptState* scriptState = ScriptState::forMainWorld(frame);
504 ScriptState::Scope scope(scriptState);
505
506 v8::Handle<v8::Object> creationContext = scriptState->context()->Global();
507 ScriptValue thisWrapper = ScriptValue(scriptState, toV8(element, creationCon text, scriptState->isolate()));
508 ScriptValue scrollStateWrapper = ScriptValue(scriptState, toV8(&scrollState, creationContext, scriptState->isolate()));
509
510 v8::Handle<v8::Object> thisObject = v8::Handle<v8::Object>::Cast(thisWrapper .v8Value());
511 v8::Local<v8::Value> functionValue = thisObject->Get(v8String(scriptState->i solate(), methodName));
512 ASSERT(functionValue->IsFunction());
513 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(functionVal ue);
514
515 // Native methods should avoid the performance overhead of a v8 method call.
516 if (function->ScriptId() == v8::UnboundScript::kNoScriptId)
517 return false;
518
519 ScriptFunctionCall functionCall(thisWrapper, methodName);
520 functionCall.appendArgument(scrollStateWrapper);
521 functionCall.call();
522 return true;
523 }
524
525 void Element::distributeScrollNative(ScrollState& scrollState)
493 { 526 {
494 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); 527 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
495 if (scrollState.fullyConsumed()) 528 if (scrollState.fullyConsumed())
496 return; 529 return;
497 530
498 scrollState.distributeToScrollChainDescendant(); 531 scrollState.distributeToScrollChainDescendant();
499 532
500 // If the scroll doesn't propagate, and we're currently scrolling 533 // If the scroll doesn't propagate, and we're currently scrolling
501 // an element other than this one, prevent the scroll from 534 // an element other than this one, prevent the scroll from
502 // propagating to this element. 535 // propagating to this element.
503 if (!scrollState.shouldPropagate() 536 if (!scrollState.shouldPropagate()
504 && scrollState.deltaConsumedForScrollSequence() 537 && scrollState.deltaConsumedForScrollSequence()
505 && scrollState.currentNativeScrollingElement() != this) { 538 && scrollState.currentNativeScrollingElement() != this) {
506 return; 539 return;
507 } 540 }
508 541
509 const double deltaX = scrollState.deltaX(); 542 const double deltaX = scrollState.deltaX();
510 const double deltaY = scrollState.deltaY(); 543 const double deltaY = scrollState.deltaY();
511 544
512 applyScroll(scrollState); 545 callApplyScroll(scrollState);
513 546
514 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) 547 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY())
515 scrollState.setCurrentNativeScrollingElement(this); 548 scrollState.setCurrentNativeScrollingElement(this);
516 } 549 }
517 550
518 void Element::applyScroll(ScrollState& scrollState) 551 void Element::callDistributeScroll(ScrollState& scrollState)
552 {
553 if (!callScrollCustomizationV8Method(this, scrollState, "distributeScroll"))
554 distributeScrollNative(scrollState);
555 };
556
557 void Element::distributeScroll(ScrollState* scrollState)
558 {
559 ASSERT(scrollState);
560 distributeScrollNative(*scrollState);
561 }
562
563 void Element::applyScrollNative(ScrollState& scrollState)
519 { 564 {
520 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); 565 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
521 if (scrollState.fullyConsumed()) 566 if (scrollState.fullyConsumed())
522 return; 567 return;
523 568
524 const double deltaX = scrollState.deltaX(); 569 const double deltaX = scrollState.deltaX();
525 const double deltaY = scrollState.deltaY(); 570 const double deltaY = scrollState.deltaY();
526 bool scrolled = false; 571 bool scrolled = false;
527 572
528 // Handle the documentElement separately, as it scrolls the FrameView. 573 // Handle the documentElement separately, as it scrolls the FrameView.
(...skipping 25 matching lines...) Expand all
554 599
555 // We need to setCurrentNativeScrollingElement in both the 600 // We need to setCurrentNativeScrollingElement in both the
556 // distributeScroll and applyScroll default implementations so 601 // distributeScroll and applyScroll default implementations so
557 // that if JS overrides one of these methods, but not the 602 // that if JS overrides one of these methods, but not the
558 // other, this bookkeeping remains accurate. 603 // other, this bookkeeping remains accurate.
559 scrollState.setCurrentNativeScrollingElement(this); 604 scrollState.setCurrentNativeScrollingElement(this);
560 if (scrollState.fromUserInput()) 605 if (scrollState.fromUserInput())
561 document().frame()->view()->setWasScrolledByUser(true); 606 document().frame()->view()->setWasScrolledByUser(true);
562 }; 607 };
563 608
609 void Element::callApplyScroll(ScrollState& scrollState)
610 {
611 if (!callScrollCustomizationV8Method(this, scrollState, "applyScroll"))
612 applyScrollNative(scrollState);
613 };
614
615 void Element::applyScroll(ScrollState* scrollState)
616 {
617 ASSERT(scrollState);
618 applyScrollNative(*scrollState);
619 }
620
564 static float localZoomForRenderer(LayoutObject& renderer) 621 static float localZoomForRenderer(LayoutObject& renderer)
565 { 622 {
566 // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each 623 // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each
567 // other out, but the alternative is that we'd have to crawl up the whole re nder tree every 624 // other out, but the alternative is that we'd have to crawl up the whole re nder tree every
568 // time (or store an additional bit in the ComputedStyle to indicate that a zoom was specified). 625 // time (or store an additional bit in the ComputedStyle to indicate that a zoom was specified).
569 float zoomFactor = 1; 626 float zoomFactor = 1;
570 if (renderer.style()->effectiveZoom() != 1) { 627 if (renderer.style()->effectiveZoom() != 1) {
571 // Need to find the nearest enclosing LayoutObject that set up 628 // Need to find the nearest enclosing LayoutObject that set up
572 // a differing zoom, and then we divide our result by it to eliminate th e zoom. 629 // a differing zoom, and then we divide our result by it to eliminate th e zoom.
573 LayoutObject* prev = &renderer; 630 LayoutObject* prev = &renderer;
(...skipping 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after
3496 { 3553 {
3497 #if ENABLE(OILPAN) 3554 #if ENABLE(OILPAN)
3498 if (hasRareData()) 3555 if (hasRareData())
3499 visitor->trace(elementRareData()); 3556 visitor->trace(elementRareData());
3500 visitor->trace(m_elementData); 3557 visitor->trace(m_elementData);
3501 #endif 3558 #endif
3502 ContainerNode::trace(visitor); 3559 ContainerNode::trace(visitor);
3503 } 3560 }
3504 3561
3505 } // namespace blink 3562 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698