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

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp

Issue 2841113002: Add convenience methods for PLSA visible client dimensions. (Closed)
Patch Set: cleanup Created 3 years, 7 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) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Portions are Copyright (C) 1998 Netscape Communications Corporation. 5 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
6 * 6 *
7 * Other contributors: 7 * Other contributors:
8 * Robert O'Callahan <roc+@cs.cmu.edu> 8 * Robert O'Callahan <roc+@cs.cmu.edu>
9 * David Baron <dbaron@fas.harvard.edu> 9 * David Baron <dbaron@fas.harvard.edu>
10 * Christian Biesinger <cbiesinger@gmail.com> 10 * Christian Biesinger <cbiesinger@gmail.com>
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 548 }
549 549
550 int PaintLayerScrollableArea::VisibleHeight() const { 550 int PaintLayerScrollableArea::VisibleHeight() const {
551 return Layer()->size().Height(); 551 return Layer()->size().Height();
552 } 552 }
553 553
554 int PaintLayerScrollableArea::VisibleWidth() const { 554 int PaintLayerScrollableArea::VisibleWidth() const {
555 return Layer()->size().Width(); 555 return Layer()->size().Width();
556 } 556 }
557 557
558 LayoutSize PaintLayerScrollableArea::ClientSize() const {
559 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
560 bool is_main_frame_root_layer =
561 layer_.IsRootLayer() && Box().GetDocument().GetFrame()->IsMainFrame();
562 if (is_main_frame_root_layer) {
563 return LayoutSize(Box().GetFrameView()->GetLayoutSize());
564 }
565 }
566 return LayoutSize(Box().ClientWidth(), Box().ClientHeight());
567 }
568
569 IntSize PaintLayerScrollableArea::PixelSnappedClientSize() const {
570 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
571 bool is_main_frame_root_layer =
572 layer_.IsRootLayer() && Box().GetDocument().GetFrame()->IsMainFrame();
573 if (is_main_frame_root_layer) {
574 return Box().GetFrameView()->GetLayoutSize();
575 }
576 }
577 return IntSize(Box().PixelSnappedClientWidth(),
578 Box().PixelSnappedClientHeight());
579 }
580
558 IntSize PaintLayerScrollableArea::ContentsSize() const { 581 IntSize PaintLayerScrollableArea::ContentsSize() const {
559 return IntSize(PixelSnappedScrollWidth(), PixelSnappedScrollHeight()); 582 return IntSize(PixelSnappedScrollWidth(), PixelSnappedScrollHeight());
560 } 583 }
561 584
562 void PaintLayerScrollableArea::ContentsResized() { 585 void PaintLayerScrollableArea::ContentsResized() {
563 ScrollableArea::ContentsResized(); 586 ScrollableArea::ContentsResized();
564 // Need to update the bounds of the scroll property. 587 // Need to update the bounds of the scroll property.
565 Box().SetNeedsPaintPropertyUpdate(); 588 Box().SetNeedsPaintPropertyUpdate();
566 } 589 }
567 590
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 843
821 { 844 {
822 // Hits in 845 // Hits in
823 // compositing/overflow/automatically-opt-into-composited-scrolling-after-st yle-change.html. 846 // compositing/overflow/automatically-opt-into-composited-scrolling-after-st yle-change.html.
824 DisableCompositingQueryAsserts disabler; 847 DisableCompositingQueryAsserts disabler;
825 848
826 UpdateScrollbarEnabledState(); 849 UpdateScrollbarEnabledState();
827 850
828 // Set up the range (and page step/line step). 851 // Set up the range (and page step/line step).
829 if (Scrollbar* horizontal_scrollbar = this->HorizontalScrollbar()) { 852 if (Scrollbar* horizontal_scrollbar = this->HorizontalScrollbar()) {
830 int client_width = Box().PixelSnappedClientWidth(); 853 int client_width = PixelSnappedClientSize().Width();
831 horizontal_scrollbar->SetProportion(client_width, 854 horizontal_scrollbar->SetProportion(client_width,
832 OverflowRect().Width().ToInt()); 855 OverflowRect().Width().ToInt());
833 } 856 }
834 if (Scrollbar* vertical_scrollbar = this->VerticalScrollbar()) { 857 if (Scrollbar* vertical_scrollbar = this->VerticalScrollbar()) {
835 int client_height = Box().PixelSnappedClientHeight(); 858 int client_height = PixelSnappedClientSize().Height();
836 vertical_scrollbar->SetProportion(client_height, 859 vertical_scrollbar->SetProportion(client_height,
837 OverflowRect().Height().ToInt()); 860 OverflowRect().Height().ToInt());
838 } 861 }
839 } 862 }
840 863
841 if (!scrollbars_are_frozen && HasOverlayScrollbars()) { 864 if (!scrollbars_are_frozen && HasOverlayScrollbars()) {
842 if (!ScrollSize(kHorizontalScrollbar)) 865 if (!ScrollSize(kHorizontalScrollbar))
843 SetHasHorizontalScrollbar(false); 866 SetHasHorizontalScrollbar(false);
844 if (!ScrollSize(kVerticalScrollbar)) 867 if (!ScrollSize(kVerticalScrollbar))
845 SetHasVerticalScrollbar(false); 868 SetHasVerticalScrollbar(false);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 945
923 bool PaintLayerScrollableArea::HasHorizontalOverflow() const { 946 bool PaintLayerScrollableArea::HasHorizontalOverflow() const {
924 // TODO(szager): Make the algorithm for adding/subtracting overflow:auto 947 // TODO(szager): Make the algorithm for adding/subtracting overflow:auto
925 // scrollbars memoryless (crbug.com/625300). This clientWidth hack will 948 // scrollbars memoryless (crbug.com/625300). This clientWidth hack will
926 // prevent the spurious horizontal scrollbar, but it can cause a converse 949 // prevent the spurious horizontal scrollbar, but it can cause a converse
927 // problem: it can leave a sliver of horizontal overflow hidden behind the 950 // problem: it can leave a sliver of horizontal overflow hidden behind the
928 // vertical scrollbar without creating a horizontal scrollbar. This 951 // vertical scrollbar without creating a horizontal scrollbar. This
929 // converse problem seems to happen much less frequently in practice, so we 952 // converse problem seems to happen much less frequently in practice, so we
930 // bias the logic towards preventing unwanted horizontal scrollbars, which 953 // bias the logic towards preventing unwanted horizontal scrollbars, which
931 // are more common and annoying. 954 // are more common and annoying.
932 int client_width = Box().PixelSnappedClientWidth(); 955 int client_width = PixelSnappedClientSize().Width();
933 if (NeedsRelayout() && !HadVerticalScrollbarBeforeRelayout()) 956 if (NeedsRelayout() && !HadVerticalScrollbarBeforeRelayout())
934 client_width += VerticalScrollbarWidth(); 957 client_width += VerticalScrollbarWidth();
935 return PixelSnappedScrollWidth() > client_width; 958 return PixelSnappedScrollWidth() > client_width;
936 } 959 }
937 960
938 bool PaintLayerScrollableArea::HasVerticalOverflow() const { 961 bool PaintLayerScrollableArea::HasVerticalOverflow() const {
939 return PixelSnappedScrollHeight() > Box().PixelSnappedClientHeight(); 962 return PixelSnappedScrollHeight() > PixelSnappedClientSize().Height();
940 } 963 }
941 964
942 bool PaintLayerScrollableArea::HasScrollableHorizontalOverflow() const { 965 bool PaintLayerScrollableArea::HasScrollableHorizontalOverflow() const {
943 return HasHorizontalOverflow() && Box().ScrollsOverflowX(); 966 return HasHorizontalOverflow() && Box().ScrollsOverflowX();
944 } 967 }
945 968
946 bool PaintLayerScrollableArea::HasScrollableVerticalOverflow() const { 969 bool PaintLayerScrollableArea::HasScrollableVerticalOverflow() const {
947 return HasVerticalOverflow() && Box().ScrollsOverflowY(); 970 return HasVerticalOverflow() && Box().ScrollsOverflowY();
948 } 971 }
949 972
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 const bool layers_changed = 1060 const bool layers_changed =
1038 topmost_scroll_child_ != next_topmost_scroll_child_; 1061 topmost_scroll_child_ != next_topmost_scroll_child_;
1039 topmost_scroll_child_ = next_topmost_scroll_child_; 1062 topmost_scroll_child_ = next_topmost_scroll_child_;
1040 next_topmost_scroll_child_ = nullptr; 1063 next_topmost_scroll_child_ = nullptr;
1041 return layers_changed; 1064 return layers_changed;
1042 } 1065 }
1043 1066
1044 void PaintLayerScrollableArea::UpdateAfterOverflowRecalc() { 1067 void PaintLayerScrollableArea::UpdateAfterOverflowRecalc() {
1045 UpdateScrollDimensions(); 1068 UpdateScrollDimensions();
1046 if (Scrollbar* horizontal_scrollbar = this->HorizontalScrollbar()) { 1069 if (Scrollbar* horizontal_scrollbar = this->HorizontalScrollbar()) {
1047 int client_width = Box().PixelSnappedClientWidth(); 1070 int client_width = PixelSnappedClientSize().Width();
1048 horizontal_scrollbar->SetProportion(client_width, 1071 horizontal_scrollbar->SetProportion(client_width,
1049 OverflowRect().Width().ToInt()); 1072 OverflowRect().Width().ToInt());
1050 } 1073 }
1051 if (Scrollbar* vertical_scrollbar = this->VerticalScrollbar()) { 1074 if (Scrollbar* vertical_scrollbar = this->VerticalScrollbar()) {
1052 int client_height = Box().PixelSnappedClientHeight(); 1075 int client_height = PixelSnappedClientSize().Height();
1053 vertical_scrollbar->SetProportion(client_height, 1076 vertical_scrollbar->SetProportion(client_height,
1054 OverflowRect().Height().ToInt()); 1077 OverflowRect().Height().ToInt());
1055 } 1078 }
1056 1079
1057 bool needs_horizontal_scrollbar; 1080 bool needs_horizontal_scrollbar;
1058 bool needs_vertical_scrollbar; 1081 bool needs_vertical_scrollbar;
1059 ComputeScrollbarExistence(needs_horizontal_scrollbar, 1082 ComputeScrollbarExistence(needs_horizontal_scrollbar,
1060 needs_vertical_scrollbar); 1083 needs_vertical_scrollbar);
1061 1084
1062 bool horizontal_scrollbar_should_change = 1085 bool horizontal_scrollbar_should_change =
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 LayoutRect PaintLayerScrollableArea::ScrollIntoView( 1720 LayoutRect PaintLayerScrollableArea::ScrollIntoView(
1698 const LayoutRect& rect, 1721 const LayoutRect& rect,
1699 const ScrollAlignment& align_x, 1722 const ScrollAlignment& align_x,
1700 const ScrollAlignment& align_y, 1723 const ScrollAlignment& align_y,
1701 ScrollType scroll_type) { 1724 ScrollType scroll_type) {
1702 LayoutRect local_expose_rect( 1725 LayoutRect local_expose_rect(
1703 Box() 1726 Box()
1704 .AbsoluteToLocalQuad(FloatQuad(FloatRect(rect)), kUseTransforms) 1727 .AbsoluteToLocalQuad(FloatQuad(FloatRect(rect)), kUseTransforms)
1705 .BoundingBox()); 1728 .BoundingBox());
1706 local_expose_rect.Move(-Box().BorderLeft(), -Box().BorderTop()); 1729 local_expose_rect.Move(-Box().BorderLeft(), -Box().BorderTop());
1707 LayoutRect layer_bounds( 1730 LayoutRect visible_rect(LayoutPoint(), ClientSize());
1708 LayoutPoint(), LayoutSize(Box().ClientWidth(), Box().ClientHeight()));
1709 LayoutRect r = ScrollAlignment::GetRectToExpose( 1731 LayoutRect r = ScrollAlignment::GetRectToExpose(
1710 layer_bounds, local_expose_rect, align_x, align_y); 1732 visible_rect, local_expose_rect, align_x, align_y);
1711 1733
1712 ScrollOffset old_scroll_offset = GetScrollOffset(); 1734 ScrollOffset old_scroll_offset = GetScrollOffset();
1713 ScrollOffset new_scroll_offset(ClampScrollOffset(RoundedIntSize( 1735 ScrollOffset new_scroll_offset(ClampScrollOffset(RoundedIntSize(
1714 ToScrollOffset(FloatPoint(r.Location()) + old_scroll_offset)))); 1736 ToScrollOffset(FloatPoint(r.Location()) + old_scroll_offset))));
1715 SetScrollOffset(new_scroll_offset, scroll_type, kScrollBehaviorInstant); 1737 SetScrollOffset(new_scroll_offset, scroll_type, kScrollBehaviorInstant);
1716 ScrollOffset scroll_offset_difference = GetScrollOffset() - old_scroll_offset; 1738 ScrollOffset scroll_offset_difference = GetScrollOffset() - old_scroll_offset;
1717 local_expose_rect.Move(-LayoutSize(scroll_offset_difference)); 1739 local_expose_rect.Move(-LayoutSize(scroll_offset_difference));
1718 1740
1719 LayoutRect intersect = 1741 LayoutRect intersect =
1720 LocalToAbsolute(Box(), Intersection(layer_bounds, local_expose_rect)); 1742 LocalToAbsolute(Box(), Intersection(visible_rect, local_expose_rect));
1721 if (intersect.IsEmpty() && !layer_bounds.IsEmpty() && 1743 if (intersect.IsEmpty() && !visible_rect.IsEmpty() &&
1722 !local_expose_rect.IsEmpty()) { 1744 !local_expose_rect.IsEmpty()) {
1723 return LocalToAbsolute(Box(), local_expose_rect); 1745 return LocalToAbsolute(Box(), local_expose_rect);
1724 } 1746 }
1725 return intersect; 1747 return intersect;
1726 } 1748 }
1727 1749
1728 void PaintLayerScrollableArea::UpdateScrollableAreaSet(bool has_overflow) { 1750 void PaintLayerScrollableArea::UpdateScrollableAreaSet(bool has_overflow) {
1729 LocalFrame* frame = Box().GetFrame(); 1751 LocalFrame* frame = Box().GetFrame();
1730 if (!frame) 1752 if (!frame)
1731 return; 1753 return;
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 2171
2150 void PaintLayerScrollableArea::DelayScrollOffsetClampScope:: 2172 void PaintLayerScrollableArea::DelayScrollOffsetClampScope::
2151 ClampScrollableAreas() { 2173 ClampScrollableAreas() {
2152 for (auto& scrollable_area : *needs_clamp_) 2174 for (auto& scrollable_area : *needs_clamp_)
2153 scrollable_area->ClampScrollOffsetAfterOverflowChange(); 2175 scrollable_area->ClampScrollOffsetAfterOverflowChange();
2154 delete needs_clamp_; 2176 delete needs_clamp_;
2155 needs_clamp_ = nullptr; 2177 needs_clamp_ = nullptr;
2156 } 2178 }
2157 2179
2158 } // namespace blink 2180 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698