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

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: Address review comments 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
« 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 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 // FIXME: This should be removed once scroll updates are processed only afte r
753 // the compositing update. See http://crbug.com/420741.
754 document().updateLayoutIgnorePendingStylesheets();
755
756 if (document().documentElement() != this) {
757 scrollRenderBoxBy(scrollToOptions);
758 return;
759 }
760
761 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
762 if (document().inQuirksMode())
763 return;
764 scrollFrameBy(scrollToOptions);
765 }
766 }
767
768 void Element::scrollTo(double x, double y)
769 {
770 ScrollToOptions scrollToOptions;
771 scrollToOptions.setLeft(x);
772 scrollToOptions.setTop(y);
773 scrollTo(scrollToOptions);
774 }
775
776 void Element::scrollTo(const ScrollToOptions& scrollToOptions)
777 {
778 // FIXME: This should be removed once scroll updates are processed only afte r
779 // the compositing update. See http://crbug.com/420741.
780 document().updateLayoutIgnorePendingStylesheets();
781
782 if (document().documentElement() != this) {
783 scrollRenderBoxTo(scrollToOptions);
784 return;
785 }
786
787 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
788 if (document().inQuirksMode())
789 return;
790 scrollFrameTo(scrollToOptions);
791 }
792 }
793
794 void Element::scrollRenderBoxBy(const ScrollToOptions& scrollToOptions)
795 {
796 double left = scrollToOptions.hasLeft() ? scrollToOptions.left() : 0.0;
797 double top = scrollToOptions.hasTop() ? scrollToOptions.top() : 0.0;
798 if (std::isnan(left) || std::isnan(top))
799 return;
800
801 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
802 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB ehavior);
803 RenderBox* rend = renderBox();
804 if (rend) {
805 double currentScaledLeft = rend->scrollLeft();
806 double currentScaledTop = rend->scrollTop();
807 double newScaledLeft = left * rend->style()->effectiveZoom() + currentSc aledLeft;
808 double newScaledTop = top * rend->style()->effectiveZoom() + currentScal edTop;
809 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or ins tantly.
810 rend->scrollToOffset(DoubleSize(newScaledLeft, newScaledTop));
811 }
812 }
813
814 void Element::scrollRenderBoxTo(const ScrollToOptions& scrollToOptions)
815 {
816 if ((scrollToOptions.hasLeft() && std::isnan(scrollToOptions.left()))
817 || (scrollToOptions.hasTop() && std::isnan(scrollToOptions.top())))
818 return;
819
820 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
821 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB ehavior);
822
823 RenderBox* rend = renderBox();
824 if (rend) {
825 double scaledLeft = rend->scrollLeft();
826 double scaledTop = rend->scrollTop();
827 if (scrollToOptions.hasLeft())
828 scaledLeft = scrollToOptions.left() * rend->style()->effectiveZoom() ;
829 if (scrollToOptions.hasTop())
830 scaledTop = scrollToOptions.top() * rend->style()->effectiveZoom();
831 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or ins tantly.
832 rend->scrollToOffset(DoubleSize(scaledLeft, scaledTop));
833 }
834 }
835
836 void Element::scrollFrameBy(const ScrollToOptions& scrollToOptions)
837 {
838 double left = scrollToOptions.hasLeft() ? scrollToOptions.left() : 0.0;
839 double top = scrollToOptions.hasTop() ? scrollToOptions.top() : 0.0;
840 if (std::isnan(left) || std::isnan(top))
841 return;
842
843 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
844 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB ehavior);
845 LocalFrame* frame = document().frame();
846 if (!frame)
847 return;
848 FrameView* view = frame->view();
849 if (!view)
850 return;
851
852 double newScaledLeft = left * frame->pageZoomFactor() + view->scrollX();
853 double newScaledTop = top * frame->pageZoomFactor() + view->scrollY();
854 view->setScrollPosition(DoublePoint(newScaledLeft, newScaledTop), scrollBeha vior);
855 }
856
857 void Element::scrollFrameTo(const ScrollToOptions& scrollToOptions)
858 {
859 double left = scrollToOptions.hasLeft() ? scrollToOptions.left() : 0.0;
860 double top = scrollToOptions.hasTop() ? scrollToOptions.top() : 0.0;
861 if (std::isnan(left) || std::isnan(top))
862 return;
863
864 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
865 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB ehavior);
866 LocalFrame* frame = document().frame();
867 if (!frame)
868 return;
869 FrameView* view = frame->view();
870 if (!view)
871 return;
872
873 double scaledLeft = view->scrollX();
874 double scaledTop = view->scrollY();
875 if (scrollToOptions.hasLeft())
876 scaledLeft = scrollToOptions.left() * frame->pageZoomFactor();
877 if (scrollToOptions.hasTop())
878 scaledTop = scrollToOptions.top() * frame->pageZoomFactor();
879 view->setScrollPosition(DoublePoint(scaledLeft, scaledTop), scrollBehavior);
880 }
881
783 IntRect Element::boundsInRootViewSpace() 882 IntRect Element::boundsInRootViewSpace()
784 { 883 {
785 document().updateLayoutIgnorePendingStylesheets(); 884 document().updateLayoutIgnorePendingStylesheets();
786 885
787 FrameView* view = document().view(); 886 FrameView* view = document().view();
788 if (!view) 887 if (!view)
789 return IntRect(); 888 return IntRect();
790 889
791 Vector<FloatQuad> quads; 890 Vector<FloatQuad> quads;
792 if (isSVGElement() && renderer()) { 891 if (isSVGElement() && renderer()) {
(...skipping 2514 matching lines...) Expand 10 before | Expand all | Expand 10 after
3307 return wrapper; 3406 return wrapper;
3308 3407
3309 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition()); 3408 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition());
3310 3409
3311 wrapper->SetPrototype(binding->prototype()); 3410 wrapper->SetPrototype(binding->prototype());
3312 3411
3313 return V8DOMWrapper::associateObjectWithWrapper(isolate, this, wrapperType, wrapper); 3412 return V8DOMWrapper::associateObjectWithWrapper(isolate, this, wrapperType, wrapper);
3314 } 3413 }
3315 3414
3316 } // namespace blink 3415 } // 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