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

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

Issue 1075393002: Implement Document.scrollingElement API behind experimental feature flag (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Minor fix and comment tweak 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Document.idl ('k') | Source/core/frame/FrameView.cpp » ('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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 704
705 if (LayoutBox* renderer = layoutBox()) 705 if (LayoutBox* renderer = layoutBox())
706 return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedClientHeigh t(), *renderer).round(); 706 return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedClientHeigh t(), *renderer).round();
707 return 0; 707 return 0;
708 } 708 }
709 709
710 double Element::scrollLeft() 710 double Element::scrollLeft()
711 { 711 {
712 document().updateLayoutIgnorePendingStylesheets(); 712 document().updateLayoutIgnorePendingStylesheets();
713 713
714 if (document().documentElement() != this) { 714 if (document().scrollingElement() == this) {
715 if (LayoutBox* box = layoutBox()) 715 if (document().domWindow())
716 return adjustScrollForAbsoluteZoom(box->scrollLeft(), *box); 716 return document().domWindow()->scrollX();
717 return 0; 717 return 0;
718 } 718 }
719 719
720 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { 720 if (LayoutBox* box = layoutBox())
721 if (document().inQuirksMode()) 721 return adjustScrollForAbsoluteZoom(box->scrollLeft(), *box);
722 return 0;
723
724 if (LocalDOMWindow* window = document().domWindow())
725 return window->scrollX();
726 }
727 722
728 return 0; 723 return 0;
729 } 724 }
730 725
731 double Element::scrollTop() 726 double Element::scrollTop()
732 { 727 {
733 document().updateLayoutIgnorePendingStylesheets(); 728 document().updateLayoutIgnorePendingStylesheets();
734 729
735 if (document().documentElement() != this) { 730 if (document().scrollingElement() == this) {
736 if (LayoutBox* box = layoutBox()) 731 if (document().domWindow())
737 return adjustScrollForAbsoluteZoom(box->scrollTop(), *box); 732 return document().domWindow()->scrollY();
738 return 0; 733 return 0;
739 } 734 }
740 735
741 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { 736 if (LayoutBox* box = layoutBox())
742 if (document().inQuirksMode()) 737 return adjustScrollForAbsoluteZoom(box->scrollTop(), *box);
743 return 0;
744
745 if (LocalDOMWindow* window = document().domWindow())
746 return window->scrollY();
747 }
748 738
749 return 0; 739 return 0;
750 } 740 }
751 741
752 void Element::setScrollLeft(double newLeft) 742 void Element::setScrollLeft(double newLeft)
753 { 743 {
754 document().updateLayoutIgnorePendingStylesheets(); 744 document().updateLayoutIgnorePendingStylesheets();
755 745
756 if (std::isnan(newLeft)) 746 if (std::isnan(newLeft))
757 return; 747 return;
758 748
759 if (document().documentElement() != this) { 749 if (document().scrollingElement() == this) {
750 if (LocalDOMWindow* window = document().domWindow())
751 window->scrollTo(newLeft, window->scrollY());
752 } else {
760 LayoutBox* box = layoutBox(); 753 LayoutBox* box = layoutBox();
761 if (box) 754 if (box)
762 box->setScrollLeft(LayoutUnit::fromFloatRound(newLeft * box->style() ->effectiveZoom())); 755 box->setScrollLeft(LayoutUnit::fromFloatRound(newLeft * box->style() ->effectiveZoom()));
763 return;
764 }
765
766 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
767 if (document().inQuirksMode())
768 return;
769
770 if (LocalDOMWindow* window = document().domWindow())
771 window->scrollTo(newLeft, window->scrollY());
772 } 756 }
773 } 757 }
774 758
775 void Element::setScrollTop(double newTop) 759 void Element::setScrollTop(double newTop)
776 { 760 {
777 document().updateLayoutIgnorePendingStylesheets(); 761 document().updateLayoutIgnorePendingStylesheets();
778 762
779 if (std::isnan(newTop)) 763 if (std::isnan(newTop))
780 return; 764 return;
781 765
782 if (document().documentElement() != this) { 766 if (document().scrollingElement() == this) {
767 if (LocalDOMWindow* window = document().domWindow())
768 window->scrollTo(window->scrollX(), newTop);
769 } else {
783 LayoutBox* box = layoutBox(); 770 LayoutBox* box = layoutBox();
784 if (box) 771 if (box)
785 box->setScrollTop(LayoutUnit::fromFloatRound(newTop * box->style()-> effectiveZoom())); 772 box->setScrollTop(LayoutUnit::fromFloatRound(newTop * box->style()-> effectiveZoom()));
786 return;
787 }
788
789 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
790 if (document().inQuirksMode())
791 return;
792
793 if (LocalDOMWindow* window = document().domWindow())
794 window->scrollTo(window->scrollX(), newTop);
795 } 773 }
796 } 774 }
797 775
798 int Element::scrollWidth() 776 int Element::scrollWidth()
799 { 777 {
800 document().updateLayoutIgnorePendingStylesheets(); 778 document().updateLayoutIgnorePendingStylesheets();
779
780 if (document().scrollingElement() == this) {
781 if (document().view())
782 return adjustForAbsoluteZoom(document().view()->contentsWidth(), doc ument().frame()->pageZoomFactor());
783 return 0;
784 }
785
801 if (LayoutBox* box = layoutBox()) 786 if (LayoutBox* box = layoutBox())
802 return adjustLayoutUnitForAbsoluteZoom(box->scrollWidth(), *box).round() ; 787 return adjustLayoutUnitForAbsoluteZoom(box->scrollWidth(), *box).round() ;
803 return 0; 788 return 0;
804 } 789 }
805 790
806 int Element::scrollHeight() 791 int Element::scrollHeight()
807 { 792 {
808 document().updateLayoutIgnorePendingStylesheets(); 793 document().updateLayoutIgnorePendingStylesheets();
794
795 if (document().scrollingElement() == this) {
796 if (document().view())
797 return adjustForAbsoluteZoom(document().view()->contentsHeight(), do cument().frame()->pageZoomFactor());
798 return 0;
799 }
800
809 if (LayoutBox* box = layoutBox()) 801 if (LayoutBox* box = layoutBox())
810 return adjustLayoutUnitForAbsoluteZoom(box->scrollHeight(), *box).round( ); 802 return adjustLayoutUnitForAbsoluteZoom(box->scrollHeight(), *box).round( );
811 return 0; 803 return 0;
812 } 804 }
813 805
814 void Element::scrollBy(double x, double y) 806 void Element::scrollBy(double x, double y)
815 { 807 {
816 ScrollToOptions scrollToOptions; 808 ScrollToOptions scrollToOptions;
817 scrollToOptions.setLeft(x); 809 scrollToOptions.setLeft(x);
818 scrollToOptions.setTop(y); 810 scrollToOptions.setTop(y);
819 scrollBy(scrollToOptions); 811 scrollBy(scrollToOptions);
820 } 812 }
821 813
822 void Element::scrollBy(const ScrollToOptions& scrollToOptions) 814 void Element::scrollBy(const ScrollToOptions& scrollToOptions)
823 { 815 {
824 // FIXME: This should be removed once scroll updates are processed only afte r 816 // FIXME: This should be removed once scroll updates are processed only afte r
825 // the compositing update. See http://crbug.com/420741. 817 // the compositing update. See http://crbug.com/420741.
826 document().updateLayoutIgnorePendingStylesheets(); 818 document().updateLayoutIgnorePendingStylesheets();
827 819
828 if (document().documentElement() != this) { 820 if (document().scrollingElement() == this) {
821 scrollFrameBy(scrollToOptions);
822 } else {
829 scrollLayoutBoxBy(scrollToOptions); 823 scrollLayoutBoxBy(scrollToOptions);
830 return;
831 }
832
833 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
834 if (document().inQuirksMode())
835 return;
836 scrollFrameBy(scrollToOptions);
837 } 824 }
838 } 825 }
839 826
840 void Element::scrollTo(double x, double y) 827 void Element::scrollTo(double x, double y)
841 { 828 {
842 ScrollToOptions scrollToOptions; 829 ScrollToOptions scrollToOptions;
843 scrollToOptions.setLeft(x); 830 scrollToOptions.setLeft(x);
844 scrollToOptions.setTop(y); 831 scrollToOptions.setTop(y);
845 scrollTo(scrollToOptions); 832 scrollTo(scrollToOptions);
846 } 833 }
847 834
848 void Element::scrollTo(const ScrollToOptions& scrollToOptions) 835 void Element::scrollTo(const ScrollToOptions& scrollToOptions)
849 { 836 {
850 // FIXME: This should be removed once scroll updates are processed only afte r 837 // FIXME: This should be removed once scroll updates are processed only afte r
851 // the compositing update. See http://crbug.com/420741. 838 // the compositing update. See http://crbug.com/420741.
852 document().updateLayoutIgnorePendingStylesheets(); 839 document().updateLayoutIgnorePendingStylesheets();
853 840
854 if (document().documentElement() != this) { 841 if (document().scrollingElement() == this) {
842 scrollFrameTo(scrollToOptions);
843 } else {
855 scrollLayoutBoxTo(scrollToOptions); 844 scrollLayoutBoxTo(scrollToOptions);
856 return;
857 }
858
859 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
860 if (document().inQuirksMode())
861 return;
862 scrollFrameTo(scrollToOptions);
863 } 845 }
864 } 846 }
865 847
866 void Element::scrollLayoutBoxBy(const ScrollToOptions& scrollToOptions) 848 void Element::scrollLayoutBoxBy(const ScrollToOptions& scrollToOptions)
867 { 849 {
868 double left = scrollToOptions.hasLeft() ? scrollToOptions.left() : 0.0; 850 double left = scrollToOptions.hasLeft() ? scrollToOptions.left() : 0.0;
869 double top = scrollToOptions.hasTop() ? scrollToOptions.top() : 0.0; 851 double top = scrollToOptions.hasTop() ? scrollToOptions.top() : 0.0;
870 if (std::isnan(left) || std::isnan(top)) 852 if (std::isnan(left) || std::isnan(top))
871 return; 853 return;
872 854
(...skipping 2623 matching lines...) Expand 10 before | Expand all | Expand 10 after
3496 { 3478 {
3497 #if ENABLE(OILPAN) 3479 #if ENABLE(OILPAN)
3498 if (hasRareData()) 3480 if (hasRareData())
3499 visitor->trace(elementRareData()); 3481 visitor->trace(elementRareData());
3500 visitor->trace(m_elementData); 3482 visitor->trace(m_elementData);
3501 #endif 3483 #endif
3502 ContainerNode::trace(visitor); 3484 ContainerNode::trace(visitor);
3503 } 3485 }
3504 3486
3505 } // namespace blink 3487 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/Document.idl ('k') | Source/core/frame/FrameView.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698