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

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

Issue 782793002: Update Element API for CSSOM smooth scrolling to match the spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 6 years 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 | Annotate | Revision Log
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 #include "core/editing/TextIterator.h" 78 #include "core/editing/TextIterator.h"
79 #include "core/editing/htmlediting.h" 79 #include "core/editing/htmlediting.h"
80 #include "core/editing/markup.h" 80 #include "core/editing/markup.h"
81 #include "core/events/EventDispatcher.h" 81 #include "core/events/EventDispatcher.h"
82 #include "core/events/FocusEvent.h" 82 #include "core/events/FocusEvent.h"
83 #include "core/frame/FrameHost.h" 83 #include "core/frame/FrameHost.h"
84 #include "core/frame/FrameView.h" 84 #include "core/frame/FrameView.h"
85 #include "core/frame/LocalDOMWindow.h" 85 #include "core/frame/LocalDOMWindow.h"
86 #include "core/frame/LocalFrame.h" 86 #include "core/frame/LocalFrame.h"
87 #include "core/frame/PinchViewport.h" 87 #include "core/frame/PinchViewport.h"
88 #include "core/frame/ScrollToOptions.h"
88 #include "core/frame/Settings.h" 89 #include "core/frame/Settings.h"
89 #include "core/frame/UseCounter.h" 90 #include "core/frame/UseCounter.h"
90 #include "core/frame/csp/ContentSecurityPolicy.h" 91 #include "core/frame/csp/ContentSecurityPolicy.h"
91 #include "core/html/ClassList.h" 92 #include "core/html/ClassList.h"
92 #include "core/html/HTMLCanvasElement.h" 93 #include "core/html/HTMLCanvasElement.h"
93 #include "core/html/HTMLCollection.h" 94 #include "core/html/HTMLCollection.h"
94 #include "core/html/HTMLDocument.h" 95 #include "core/html/HTMLDocument.h"
95 #include "core/html/HTMLElement.h" 96 #include "core/html/HTMLElement.h"
96 #include "core/html/HTMLFormControlsCollection.h" 97 #include "core/html/HTMLFormControlsCollection.h"
97 #include "core/html/HTMLFrameElementBase.h" 98 #include "core/html/HTMLFrameElementBase.h"
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 if (document().inQuirksMode()) 683 if (document().inQuirksMode())
683 return; 684 return;
684 685
685 LocalFrame* frame = document().frame(); 686 LocalFrame* frame = document().frame();
686 if (!frame) 687 if (!frame)
687 return; 688 return;
688 FrameView* view = frame->view(); 689 FrameView* view = frame->view();
689 if (!view) 690 if (!view)
690 return; 691 return;
691 692
692 view->setScrollPosition(DoublePoint(newLeft * frame->pageZoomFactor(), v iew->scrollY())); 693 view->setScrollPosition(DoublePoint(newLeft * frame->pageZoomFactor(), v iew->scrollY()), ScrollBehaviorAuto);
693 } 694 }
694 } 695 }
695 696
696 void Element::setScrollLeft(const Dictionary& scrollOptionsHorizontal, Exception State& exceptionState)
697 {
698 String scrollBehaviorString;
699 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
700 if (DictionaryHelper::get(scrollOptionsHorizontal, "behavior", scrollBehavio rString)) {
701 if (!ScrollableArea::scrollBehaviorFromString(scrollBehaviorString, scro llBehavior)) {
702 exceptionState.throwTypeError("The ScrollBehavior provided is invali d.");
703 return;
704 }
705 }
706
707 double position;
708 if (!DictionaryHelper::get(scrollOptionsHorizontal, "x", position)) {
709 exceptionState.throwTypeError("ScrollOptionsHorizontal must include an ' x' member.");
710 return;
711 }
712
713 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instant ly.
714 setScrollLeft(position);
715 }
716
717 void Element::setScrollTop(double newTop) 697 void Element::setScrollTop(double newTop)
718 { 698 {
719 document().updateLayoutIgnorePendingStylesheets(); 699 document().updateLayoutIgnorePendingStylesheets();
720 700
721 if (std::isnan(newTop)) 701 if (std::isnan(newTop))
722 return; 702 return;
723 703
724 if (document().documentElement() != this) { 704 if (document().documentElement() != this) {
725 RenderBox* rend = renderBox(); 705 RenderBox* rend = renderBox();
726 if (rend) 706 if (rend)
727 rend->setScrollTop(LayoutUnit::fromFloatRound(newTop * rend->style() ->effectiveZoom())); 707 rend->setScrollTop(LayoutUnit::fromFloatRound(newTop * rend->style() ->effectiveZoom()));
728 return; 708 return;
729 } 709 }
730 710
731 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { 711 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
732 if (document().inQuirksMode()) 712 if (document().inQuirksMode())
733 return; 713 return;
734 714
735 LocalFrame* frame = document().frame(); 715 LocalFrame* frame = document().frame();
736 if (!frame) 716 if (!frame)
737 return; 717 return;
738 FrameView* view = frame->view(); 718 FrameView* view = frame->view();
739 if (!view) 719 if (!view)
740 return; 720 return;
741 721
742 view->setScrollPosition(DoublePoint(view->scrollX(), newTop * frame->pag eZoomFactor())); 722 view->setScrollPosition(DoublePoint(view->scrollX(), newTop * frame->pag eZoomFactor()), ScrollBehaviorAuto);
743 } 723 }
744 } 724 }
745 725
746 void Element::setScrollTop(const Dictionary& scrollOptionsVertical, ExceptionSta te& exceptionState)
747 {
748 String scrollBehaviorString;
749 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
750 if (DictionaryHelper::get(scrollOptionsVertical, "behavior", scrollBehaviorS tring)) {
751 if (!ScrollableArea::scrollBehaviorFromString(scrollBehaviorString, scro llBehavior)) {
752 exceptionState.throwTypeError("The ScrollBehavior provided is invali d.");
753 return;
754 }
755 }
756
757 double position;
758 if (!DictionaryHelper::get(scrollOptionsVertical, "y", position)) {
759 exceptionState.throwTypeError("ScrollOptionsVertical must include a 'y' member.");
760 return;
761 }
762
763 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instant ly.
764 setScrollTop(position);
765 }
766
767 int Element::scrollWidth() 726 int Element::scrollWidth()
768 { 727 {
769 document().updateLayoutIgnorePendingStylesheets(); 728 document().updateLayoutIgnorePendingStylesheets();
770 if (RenderBox* rend = renderBox()) 729 if (RenderBox* rend = renderBox())
771 return adjustLayoutUnitForAbsoluteZoom(rend->scrollWidth(), *rend).toDou ble(); 730 return adjustLayoutUnitForAbsoluteZoom(rend->scrollWidth(), *rend).toDou ble();
772 return 0; 731 return 0;
773 } 732 }
774 733
775 int Element::scrollHeight() 734 int Element::scrollHeight()
776 { 735 {
777 document().updateLayoutIgnorePendingStylesheets(); 736 document().updateLayoutIgnorePendingStylesheets();
778 if (RenderBox* rend = renderBox()) 737 if (RenderBox* rend = renderBox())
779 return adjustLayoutUnitForAbsoluteZoom(rend->scrollHeight(), *rend).toDo uble(); 738 return adjustLayoutUnitForAbsoluteZoom(rend->scrollHeight(), *rend).toDo uble();
780 return 0; 739 return 0;
781 } 740 }
782 741
742 void Element::scrollBy(double x, double y)
743 {
744 ScrollToOptions scrollToOptions;
745 scrollToOptions.setLeft(x);
746 scrollToOptions.setTop(y);
747 scrollBy(scrollToOptions);
748 }
749
750 void Element::scrollBy(const ScrollToOptions& scrollToOptions)
751 {
752 document().updateLayoutIgnorePendingStylesheets();
Ian Vollick 2014/12/08 16:35:23 Eventually, we'll want to process scrolls after co
ajuma 2014/12/08 18:34:13 No, there's nothing smooth-scroll specific that re
753
754 double left = scrollToOptions.hasLeft() ? scrollToOptions.left() : 0.0;
755 double top = scrollToOptions.hasTop() ? scrollToOptions.top() : 0.0;
756 if (std::isnan(left) || std::isnan(top))
757 return;
758
759 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
760 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB ehavior);
761
762 if (document().documentElement() != this) {
763 RenderBox* rend = renderBox();
764 if (rend) {
765 double currentScaledLeft = rend->scrollLeft();
766 double currentScaledTop = rend->scrollTop();
767 double newScaledLeft = left * rend->style()->effectiveZoom() + curre ntScaledLeft;
768 double newScaledTop = top * rend->style()->effectiveZoom() + current ScaledTop;
769 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instantly.
770 rend->scrollToOffset(DoubleSize(newScaledLeft, newScaledTop));
771 }
772 return;
773 }
774
775 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
776 if (document().inQuirksMode())
777 return;
778
779 LocalFrame* frame = document().frame();
780 if (!frame)
781 return;
782 FrameView* view = frame->view();
783 if (!view)
784 return;
785
786 double newScaledLeft = left * frame->pageZoomFactor() + view->scrollX();
787 double newScaledTop = top * frame->pageZoomFactor() + view->scrollY();
788 view->setScrollPosition(DoublePoint(newScaledLeft, newScaledTop), scroll Behavior);
789 }
790 }
791
792 void Element::scrollTo(double x, double y)
793 {
794 ScrollToOptions scrollToOptions;
795 scrollToOptions.setLeft(x);
796 scrollToOptions.setTop(y);
797 scrollTo(scrollToOptions);
798 }
799
800 void Element::scrollTo(const ScrollToOptions& scrollToOptions)
801 {
802 document().updateLayoutIgnorePendingStylesheets();
803 if ((scrollToOptions.hasLeft() && std::isnan(scrollToOptions.left()))
804 || (scrollToOptions.hasTop() && std::isnan(scrollToOptions.top())))
805 return;
806
807 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
808 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB ehavior);
809
810 if (document().documentElement() != this) {
811 RenderBox* rend = renderBox();
812 if (rend) {
813 double scaledLeft = rend->scrollLeft();
814 double scaledTop = rend->scrollTop();
815 if (scrollToOptions.hasLeft())
816 scaledLeft = scrollToOptions.left() * rend->style()->effectiveZo om();
817 if (scrollToOptions.hasTop())
818 scaledTop = scrollToOptions.top() * rend->style()->effectiveZoom ();
819 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instantly.
820 rend->scrollToOffset(DoubleSize(scaledLeft, scaledTop));
821 }
822 return;
823 }
824
825 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
826 if (document().inQuirksMode())
827 return;
828
829 LocalFrame* frame = document().frame();
830 if (!frame)
831 return;
832 FrameView* view = frame->view();
833 if (!view)
834 return;
835
836 double scaledLeft = view->scrollX();
837 double scaledTop = view->scrollY();
838 if (scrollToOptions.hasLeft())
839 scaledLeft = scrollToOptions.left() * frame->pageZoomFactor();
840 if (scrollToOptions.hasTop())
841 scaledTop = scrollToOptions.top() * frame->pageZoomFactor();
842 view->setScrollPosition(DoublePoint(scaledLeft, scaledTop), scrollBehavi or);
843 }
844 }
845
783 IntRect Element::boundsInRootViewSpace() 846 IntRect Element::boundsInRootViewSpace()
784 { 847 {
785 document().updateLayoutIgnorePendingStylesheets(); 848 document().updateLayoutIgnorePendingStylesheets();
786 849
787 FrameView* view = document().view(); 850 FrameView* view = document().view();
788 if (!view) 851 if (!view)
789 return IntRect(); 852 return IntRect();
790 853
791 Vector<FloatQuad> quads; 854 Vector<FloatQuad> quads;
792 if (isSVGElement() && renderer()) { 855 if (isSVGElement() && renderer()) {
(...skipping 2514 matching lines...) Expand 10 before | Expand all | Expand 10 after
3307 return wrapper; 3370 return wrapper;
3308 3371
3309 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition()); 3372 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition());
3310 3373
3311 wrapper->SetPrototype(binding->prototype()); 3374 wrapper->SetPrototype(binding->prototype());
3312 3375
3313 return V8DOMWrapper::associateObjectWithWrapper(isolate, this, wrapperType, wrapper); 3376 return V8DOMWrapper::associateObjectWithWrapper(isolate, this, wrapperType, wrapper);
3314 } 3377 }
3315 3378
3316 } // namespace blink 3379 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698