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

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: Address haraken's comments. Created 5 years, 5 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/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
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
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 {
haraken 2015/06/30 07:08:30 We should define this in ScrollStateCallback.h (or
478 public:
479 DistributeScrollCallback() { m_callbackType = CallbackType::DISTRIBUTE_SCROL L; }
480 void handleEvent(ScrollState* scrollState)
481 {
482 ASSERT(m_targetElement);
483 ASSERT(scrollState);
484 m_targetElement->nativeDistributeScroll(*scrollState);
485 }
486 };
487
488 class ApplyScrollCallback : public ScrollStateCallback {
haraken 2015/06/30 07:08:30 Ditto.
489 public:
490 ApplyScrollCallback() { m_callbackType = CallbackType::APPLY_SCROLL; }
491 void handleEvent(ScrollState* scrollState)
492 {
493 ASSERT(m_targetElement);
494 ASSERT(scrollState);
495 m_targetElement->nativeApplyScroll(*scrollState);
496 }
497 };
498
499 } // namespace
500
501 void Element::setDistributeScroll(ScrollStateCallback* scrollStateCallback)
502 {
503 scrollStateCallback->setCallbackType(ScrollStateCallback::CallbackType::DIST RIBUTE_SCROLL);
504 ensureElementRareData().setDistributeScroll(scrollStateCallback);
505 }
506
507 ScriptValue Element::distributeScroll(ScriptState* scriptState)
508 {
509 if (!hasRareData() || !elementRareData()->getDistributeScroll())
510 setDistributeScroll(new DistributeScrollCallback());
haraken 2015/06/30 07:08:30 In a case where we don't have a customized calback
511 return elementRareData()->getDistributeScroll()->toScriptValue(scriptState);
512 }
513
514 void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback)
515 {
516 scrollStateCallback->setCallbackType(ScrollStateCallback::CallbackType::APPL Y_SCROLL);
517 ensureElementRareData().setApplyScroll(scrollStateCallback);
518 }
519
520 ScriptValue Element::applyScroll(ScriptState* scriptState)
521 {
522 if (!hasRareData() || !elementRareData()->getApplyScroll())
523 setApplyScroll(new ApplyScrollCallback());
haraken 2015/06/30 07:08:30 Ditto.
524 return elementRareData()->getApplyScroll()->toScriptValue(scriptState);
525 }
526
527 void Element::nativeDistributeScroll(ScrollState& scrollState)
474 { 528 {
475 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); 529 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
476 if (scrollState.fullyConsumed()) 530 if (scrollState.fullyConsumed())
477 return; 531 return;
478 532
479 scrollState.distributeToScrollChainDescendant(); 533 scrollState.distributeToScrollChainDescendant();
480 534
481 // If the scroll doesn't propagate, and we're currently scrolling 535 // If the scroll doesn't propagate, and we're currently scrolling
482 // an element other than this one, prevent the scroll from 536 // an element other than this one, prevent the scroll from
483 // propagating to this element. 537 // propagating to this element.
484 if (!scrollState.shouldPropagate() 538 if (!scrollState.shouldPropagate()
485 && scrollState.deltaConsumedForScrollSequence() 539 && scrollState.deltaConsumedForScrollSequence()
486 && scrollState.currentNativeScrollingElement() != this) { 540 && scrollState.currentNativeScrollingElement() != this) {
487 return; 541 return;
488 } 542 }
489 543
490 const double deltaX = scrollState.deltaX(); 544 const double deltaX = scrollState.deltaX();
491 const double deltaY = scrollState.deltaY(); 545 const double deltaY = scrollState.deltaY();
492 546
493 applyScroll(scrollState); 547 callApplyScroll(scrollState);
494 548
495 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) 549 if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY())
496 scrollState.setCurrentNativeScrollingElement(this); 550 scrollState.setCurrentNativeScrollingElement(this);
497 } 551 }
498 552
499 void Element::applyScroll(ScrollState& scrollState) 553 void Element::callDistributeScroll(ScrollState& scrollState)
554 {
555 if (!hasRareData() || !elementRareData()->getDistributeScroll())
556 nativeDistributeScroll(scrollState);
557 else
558 elementRareData()->getDistributeScroll()->handleEventForElement(*this, & scrollState);
559 };
560
561 void Element::nativeApplyScroll(ScrollState& scrollState)
500 { 562 {
501 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); 563 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
564 document().updateLayoutIgnorePendingStylesheets();
565
502 if (scrollState.fullyConsumed()) 566 if (scrollState.fullyConsumed())
503 return; 567 return;
504 568
505 const double deltaX = scrollState.deltaX(); 569 const double deltaX = scrollState.deltaX();
506 const double deltaY = scrollState.deltaY(); 570 const double deltaY = scrollState.deltaY();
507 bool scrolled = false; 571 bool scrolled = false;
508 572
509 // Handle the documentElement separately, as it scrolls the FrameView. 573 // Handle the scrollingElement separately, as it scrolls the FrameView.
510 if (this == document().documentElement()) { 574 if (this == document().scrollingElement()) {
511 FloatSize delta(deltaX, deltaY); 575 FloatSize delta(deltaX, deltaY);
512 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning( )).didScroll()) { 576 if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning( )).didScroll()) {
513 scrolled = true; 577 scrolled = true;
514 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del taY()); 578 scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.del taY());
515 } 579 }
516 } else { 580 } else {
517 if (!layoutObject()) 581 if (!layoutObject())
518 return; 582 return;
519 LayoutBox* curBox = layoutObject()->enclosingBox(); 583 LayoutBox* curBox = layoutObject()->enclosingBox();
520 // FIXME: Native scrollers should only consume the scroll they 584 // FIXME: Native scrollers should only consume the scroll they
(...skipping 14 matching lines...) Expand all
535 599
536 // We need to setCurrentNativeScrollingElement in both the 600 // We need to setCurrentNativeScrollingElement in both the
537 // distributeScroll and applyScroll default implementations so 601 // distributeScroll and applyScroll default implementations so
538 // that if JS overrides one of these methods, but not the 602 // that if JS overrides one of these methods, but not the
539 // other, this bookkeeping remains accurate. 603 // other, this bookkeeping remains accurate.
540 scrollState.setCurrentNativeScrollingElement(this); 604 scrollState.setCurrentNativeScrollingElement(this);
541 if (scrollState.fromUserInput()) 605 if (scrollState.fromUserInput())
542 document().frame()->view()->setWasScrolledByUser(true); 606 document().frame()->view()->setWasScrolledByUser(true);
543 }; 607 };
544 608
609 void Element::callApplyScroll(ScrollState& scrollState)
610 {
611 if (!hasRareData() || !elementRareData()->getApplyScroll())
612 nativeApplyScroll(scrollState);
613 else
614 elementRareData()->getApplyScroll()->handleEventForElement(*this, &scrol lState);
615 };
616
545 static float localZoomForLayoutObject(LayoutObject& layoutObject) 617 static float localZoomForLayoutObject(LayoutObject& layoutObject)
546 { 618 {
547 // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each 619 // 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 620 // 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). 621 // time (or store an additional bit in the ComputedStyle to indicate that a zoom was specified).
550 float zoomFactor = 1; 622 float zoomFactor = 1;
551 if (layoutObject.style()->effectiveZoom() != 1) { 623 if (layoutObject.style()->effectiveZoom() != 1) {
552 // Need to find the nearest enclosing LayoutObject that set up 624 // 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. 625 // a differing zoom, and then we divide our result by it to eliminate th e zoom.
554 LayoutObject* prev = &layoutObject; 626 LayoutObject* prev = &layoutObject;
(...skipping 2877 matching lines...) Expand 10 before | Expand all | Expand 10 after
3432 { 3504 {
3433 #if ENABLE(OILPAN) 3505 #if ENABLE(OILPAN)
3434 if (hasRareData()) 3506 if (hasRareData())
3435 visitor->trace(elementRareData()); 3507 visitor->trace(elementRareData());
3436 visitor->trace(m_elementData); 3508 visitor->trace(m_elementData);
3437 #endif 3509 #endif
3438 ContainerNode::trace(visitor); 3510 ContainerNode::trace(visitor);
3439 } 3511 }
3440 3512
3441 } // namespace blink 3513 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698