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

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

Powered by Google App Engine
This is Rietveld 408576698