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

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

Issue 850443002: Scroll Customization Prototype (Not for review, WIP) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase / cleanup / minor bug fixes Created 5 years, 9 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
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 #include "core/layout/Layer.h" 108 #include "core/layout/Layer.h"
107 #include "core/layout/LayoutTextFragment.h" 109 #include "core/layout/LayoutTextFragment.h"
108 #include "core/layout/LayoutView.h" 110 #include "core/layout/LayoutView.h"
109 #include "core/layout/compositing/LayerCompositor.h" 111 #include "core/layout/compositing/LayerCompositor.h"
110 #include "core/page/Chrome.h" 112 #include "core/page/Chrome.h"
111 #include "core/page/ChromeClient.h" 113 #include "core/page/ChromeClient.h"
112 #include "core/page/FocusController.h" 114 #include "core/page/FocusController.h"
113 #include "core/page/Page.h" 115 #include "core/page/Page.h"
114 #include "core/page/PointerLockController.h" 116 #include "core/page/PointerLockController.h"
115 #include "core/page/SpatialNavigation.h" 117 #include "core/page/SpatialNavigation.h"
118 #include "core/page/scrolling/ScrollState.h"
116 #include "core/svg/SVGDocumentExtensions.h" 119 #include "core/svg/SVGDocumentExtensions.h"
117 #include "core/svg/SVGElement.h" 120 #include "core/svg/SVGElement.h"
118 #include "platform/EventDispatchForbiddenScope.h" 121 #include "platform/EventDispatchForbiddenScope.h"
119 #include "platform/RuntimeEnabledFeatures.h" 122 #include "platform/RuntimeEnabledFeatures.h"
120 #include "platform/UserGestureIndicator.h" 123 #include "platform/UserGestureIndicator.h"
121 #include "platform/scroll/ScrollableArea.h" 124 #include "platform/scroll/ScrollableArea.h"
122 #include "wtf/BitVector.h" 125 #include "wtf/BitVector.h"
123 #include "wtf/HashFunctions.h" 126 #include "wtf/HashFunctions.h"
124 #include "wtf/text/CString.h" 127 #include "wtf/text/CString.h"
125 #include "wtf/text/StringBuilder.h" 128 #include "wtf/text/StringBuilder.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 if (!renderer()) 477 if (!renderer())
475 return; 478 return;
476 479
477 LayoutRect bounds = boundingBox(); 480 LayoutRect bounds = boundingBox();
478 if (centerIfNeeded) 481 if (centerIfNeeded)
479 renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignCenterIfNe eded, ScrollAlignment::alignCenterIfNeeded); 482 renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignCenterIfNe eded, ScrollAlignment::alignCenterIfNeeded);
480 else 483 else
481 renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNe eded, ScrollAlignment::alignToEdgeIfNeeded); 484 renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNe eded, ScrollAlignment::alignToEdgeIfNeeded);
482 } 485 }
483 486
487 // Returns true iff a V8 method existed and was called.
488 static bool callScrollCustomizationV8Method(Element* element, ScrollState* scrol lState, String methodName)
489 {
490 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
491
492 LocalFrame* frame = element->document().frame();
493 if (!frame)
494 return false;
495 ScriptState* scriptState = ScriptState::forMainWorld(frame);
496 ScriptState::Scope scope(scriptState);
497
498 v8::Handle<v8::Object> creationContext = scriptState->context()->Global();
499 ScriptValue thisWrapper = ScriptValue(scriptState, toV8(element, creationCon text, scriptState->isolate()));
500 ScriptValue scrollStateWrapper = ScriptValue(scriptState, toV8(scrollState, creationContext, scriptState->isolate()));
501
502 v8::Handle<v8::Object> thisObject = v8::Handle<v8::Object>::Cast(thisWrapper .v8Value());
503 v8::Local<v8::Value> functionValue = thisObject->Get(v8String(scriptState->i solate(), methodName));
504 ASSERT(functionValue->IsFunction());
505 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(functionVal ue);
506
507 // Native methods should avoid the performance overhead of a v8 method call.
508 if (function->ScriptId() == v8::UnboundScript::kNoScriptId)
509 return false;
510
511 ScriptFunctionCall functionCall(thisWrapper, methodName);
512 functionCall.appendArgument(scrollStateWrapper);
513 functionCall.call();
514 return true;
515 }
516
517 void Element::callDistributeScroll(ScrollState* scrollState)
518 {
519 if (!callScrollCustomizationV8Method(this, scrollState, "distributeScroll"))
520 distributeScroll(scrollState);
521 };
522
523 void Element::distributeScroll(ScrollState* scrollState)
524 {
525 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
526 if (!scrollState) {
527 // FIXME: Ideally we'd throw an exception here...
528 fprintf(stderr, "WE SHOULD HANDLE THIS CASE BETTER\n");
529 return;
530 }
531
532 if (scrollState->fullyConsumed())
533 return;
534
535 scrollState->distributeToScrollChainDescendant();
536
537 if (!scrollState->shouldPropagate() && scrollState->scrollLockedToElement() && scrollState->currentNativeScrollingElement() != this)
538 return;
539
540 const double deltaX = scrollState->deltaX();
541 const double deltaY = scrollState->deltaY();
542
543 callApplyScroll(scrollState);
544
545 bool scrolled = deltaX != scrollState->deltaX() || deltaY != scrollState->de ltaY();
546 if (scrolled)
547 scrollState->setCurrentNativeScrollingElement(this);
548 }
549
550 void Element::callApplyScroll(ScrollState* scrollState)
551 {
552 if (!callScrollCustomizationV8Method(this, scrollState, "applyScroll"))
553 applyScroll(scrollState);
554 }
555
556 void Element::applyScroll(ScrollState* scrollState)
557 {
558 ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
559
560 if (!scrollState) {
561 // FIXME: Ideally we'd throw an exception here...
562 fprintf(stderr, "WE SHOULD HANDLE THIS CASE BETTER\n");
563 return;
564 }
565
566 const double deltaX = scrollState->deltaX();
567 const double deltaY = scrollState->deltaY();
568 bool scrolled = false;
569
570 if (scrollState->fullyConsumed())
571 return;
572
573 // Handle the documentElement separately, as it scrolls the FrameView.
574 if (this == document().documentElement()) {
575 FloatSize delta(deltaX, deltaY);
576 if (!document().frame()->scrollByDelta(delta))
577 return;
578 scrolled = true;
579 } else {
580 LayoutBox* curBox = renderer()->enclosingBox();
581 if (deltaX && curBox->scroll(ScrollLeft, ScrollByPrecisePixel, deltaX))
582 scrolled = true;
583
584 if (deltaY && curBox->scroll(ScrollUp, ScrollByPrecisePixel, deltaY))
585 scrolled = true;
586 }
587
588 if (scrolled) {
589 scrollState->consumeDeltaNative(scrollState->deltaX(), scrollState->delt aY());
590
591 // We need to setCurrentNativeScrollingElement in both the
592 // distributeScroll and applyScroll default implementations so
593 // that if the user overrides one of these methods, but not the
594 // other, this bookkeeping remains accurate.
595 scrollState->setCurrentNativeScrollingElement(this);
596
597 if (scrollState->fromUserInput())
598 document().frame()->view()->setWasScrolledByUser(true);
599 }
600 };
601
484 static float localZoomForRenderer(LayoutObject& renderer) 602 static float localZoomForRenderer(LayoutObject& renderer)
485 { 603 {
486 // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each 604 // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each
487 // other out, but the alternative is that we'd have to crawl up the whole re nder tree every 605 // other out, but the alternative is that we'd have to crawl up the whole re nder tree every
488 // time (or store an additional bit in the LayoutStyle to indicate that a zo om was specified). 606 // time (or store an additional bit in the LayoutStyle to indicate that a zo om was specified).
489 float zoomFactor = 1; 607 float zoomFactor = 1;
490 if (renderer.style()->effectiveZoom() != 1) { 608 if (renderer.style()->effectiveZoom() != 1) {
491 // Need to find the nearest enclosing LayoutObject that set up 609 // Need to find the nearest enclosing LayoutObject that set up
492 // a differing zoom, and then we divide our result by it to eliminate th e zoom. 610 // a differing zoom, and then we divide our result by it to eliminate th e zoom.
493 LayoutObject* prev = &renderer; 611 LayoutObject* prev = &renderer;
(...skipping 2887 matching lines...) Expand 10 before | Expand all | Expand 10 after
3381 { 3499 {
3382 #if ENABLE(OILPAN) 3500 #if ENABLE(OILPAN)
3383 if (hasRareData()) 3501 if (hasRareData())
3384 visitor->trace(elementRareData()); 3502 visitor->trace(elementRareData());
3385 visitor->trace(m_elementData); 3503 visitor->trace(m_elementData);
3386 #endif 3504 #endif
3387 ContainerNode::trace(visitor); 3505 ContainerNode::trace(visitor);
3388 } 3506 }
3389 3507
3390 } // namespace blink 3508 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698