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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp

Issue 2961613002: Slightly refactor StickyPositionScrollingConstraints API and add documentation (Closed)
Patch Set: Add diagram + example Created 3 years, 4 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 | « no previous file | third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.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) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2010 Google Inc. All rights reserved. 7 * Copyright (C) 2010 Google Inc. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 namespace blink { 46 namespace blink {
47 47
48 namespace { 48 namespace {
49 inline bool IsOutOfFlowPositionedWithImplicitHeight( 49 inline bool IsOutOfFlowPositionedWithImplicitHeight(
50 const LayoutBoxModelObject* child) { 50 const LayoutBoxModelObject* child) {
51 return child->IsOutOfFlowPositioned() && 51 return child->IsOutOfFlowPositioned() &&
52 !child->Style()->LogicalTop().IsAuto() && 52 !child->Style()->LogicalTop().IsAuto() &&
53 !child->Style()->LogicalBottom().IsAuto(); 53 !child->Style()->LogicalBottom().IsAuto();
54 } 54 }
55 55
56 StickyPositionScrollingConstraints* StickyConstraintsForLayoutObject(
57 const LayoutBoxModelObject* obj,
58 const PaintLayer* ancestor_overflow_layer) {
59 if (!obj)
60 return nullptr;
61
62 PaintLayerScrollableArea* scrollable_area =
63 ancestor_overflow_layer->GetScrollableArea();
64 if (!scrollable_area)
65 return nullptr;
66 auto it = scrollable_area->GetStickyConstraintsMap().find(obj->Layer());
67 if (it == scrollable_area->GetStickyConstraintsMap().end())
68 return nullptr;
69
70 return &it->value;
71 }
72
73 // Inclusive of |from|, exclusive of |to|. 56 // Inclusive of |from|, exclusive of |to|.
74 LayoutBoxModelObject* FindFirstStickyBetween(LayoutObject* from, 57 PaintLayer* FindFirstStickyBetween(LayoutObject* from, LayoutObject* to) {
75 LayoutObject* to) {
76 LayoutObject* maybe_sticky_ancestor = from; 58 LayoutObject* maybe_sticky_ancestor = from;
77 while (maybe_sticky_ancestor && maybe_sticky_ancestor != to) { 59 while (maybe_sticky_ancestor && maybe_sticky_ancestor != to) {
78 if (maybe_sticky_ancestor->Style()->HasStickyConstrainedPosition()) { 60 if (maybe_sticky_ancestor->Style()->HasStickyConstrainedPosition()) {
79 return ToLayoutBoxModelObject(maybe_sticky_ancestor); 61 return ToLayoutBoxModelObject(maybe_sticky_ancestor)->Layer();
80 } 62 }
81 63
82 maybe_sticky_ancestor = 64 maybe_sticky_ancestor =
83 maybe_sticky_ancestor->IsLayoutInline() 65 maybe_sticky_ancestor->IsLayoutInline()
84 ? maybe_sticky_ancestor->Container() 66 ? maybe_sticky_ancestor->Container()
85 : ToLayoutBox(maybe_sticky_ancestor)->LocationContainer(); 67 : ToLayoutBox(maybe_sticky_ancestor)->LocationContainer();
86 } 68 }
87 return nullptr; 69 return nullptr;
88 } 70 }
89 } // namespace 71 } // namespace
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 FloatRect(scroll_container_relative_padding_box_rect.Location() + 899 FloatRect(scroll_container_relative_padding_box_rect.Location() +
918 ToFloatSize(sticky_location), 900 ToFloatSize(sticky_location),
919 flipped_sticky_box_rect.Size())); 901 flipped_sticky_box_rect.Size()));
920 902
921 // To correctly compute the offsets, the constraints need to know about any 903 // To correctly compute the offsets, the constraints need to know about any
922 // nested position:sticky elements between themselves and their 904 // nested position:sticky elements between themselves and their
923 // containingBlock, and between the containingBlock and their scrollAncestor. 905 // containingBlock, and between the containingBlock and their scrollAncestor.
924 // 906 //
925 // The respective search ranges are [container, containingBlock) and 907 // The respective search ranges are [container, containingBlock) and
926 // [containingBlock, scrollAncestor). 908 // [containingBlock, scrollAncestor).
927 constraints.SetNearestStickyBoxShiftingStickyBox( 909 constraints.SetNearestStickyLayerShiftingStickyBox(
928 FindFirstStickyBetween(location_container, containing_block)); 910 FindFirstStickyBetween(location_container, containing_block));
929 // We cannot use |scrollAncestor| here as it disregards the root 911 // We cannot use |scrollAncestor| here as it disregards the root
930 // ancestorOverflowLayer(), which we should include. 912 // ancestorOverflowLayer(), which we should include.
931 constraints.SetNearestStickyBoxShiftingContainingBlock(FindFirstStickyBetween( 913 constraints.SetNearestStickyLayerShiftingContainingBlock(
932 containing_block, &Layer()->AncestorOverflowLayer()->GetLayoutObject())); 914 FindFirstStickyBetween(
915 containing_block,
916 &Layer()->AncestorOverflowLayer()->GetLayoutObject()));
933 917
934 // We skip the right or top sticky offset if there is not enough space to 918 // We skip the right or top sticky offset if there is not enough space to
935 // honor both the left/right or top/bottom offsets. 919 // honor both the left/right or top/bottom offsets.
936 LayoutUnit horizontal_offsets = 920 LayoutUnit horizontal_offsets =
937 MinimumValueForLength(Style()->Right(), 921 MinimumValueForLength(Style()->Right(),
938 LayoutUnit(constraining_size.Width())) + 922 LayoutUnit(constraining_size.Width())) +
939 MinimumValueForLength(Style()->Left(), 923 MinimumValueForLength(Style()->Left(),
940 LayoutUnit(constraining_size.Width())); 924 LayoutUnit(constraining_size.Width()));
941 bool skip_right = false; 925 bool skip_right = false;
942 bool skip_left = false; 926 bool skip_left = false;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 enclosing_clipping_box->PaddingRight(), 1006 enclosing_clipping_box->PaddingRight(),
1023 enclosing_clipping_box->PaddingTop() + 1007 enclosing_clipping_box->PaddingTop() +
1024 enclosing_clipping_box->PaddingBottom())); 1008 enclosing_clipping_box->PaddingBottom()));
1025 return constraining_rect; 1009 return constraining_rect;
1026 } 1010 }
1027 1011
1028 LayoutSize LayoutBoxModelObject::StickyPositionOffset() const { 1012 LayoutSize LayoutBoxModelObject::StickyPositionOffset() const {
1029 const PaintLayer* ancestor_overflow_layer = Layer()->AncestorOverflowLayer(); 1013 const PaintLayer* ancestor_overflow_layer = Layer()->AncestorOverflowLayer();
1030 // TODO: Force compositing input update if we ask for offset before 1014 // TODO: Force compositing input update if we ask for offset before
1031 // compositing inputs have been computed? 1015 // compositing inputs have been computed?
1032 if (!ancestor_overflow_layer) 1016 if (!ancestor_overflow_layer || !ancestor_overflow_layer->GetScrollableArea())
1033 return LayoutSize(); 1017 return LayoutSize();
1034 1018
1035 StickyPositionScrollingConstraints* constraints = 1019 StickyConstraintsMap& constraints_map =
1036 StickyConstraintsForLayoutObject(this, ancestor_overflow_layer); 1020 ancestor_overflow_layer->GetScrollableArea()->GetStickyConstraintsMap();
1037 if (!constraints) 1021 auto it = constraints_map.find(Layer());
1022 if (it == constraints_map.end())
1038 return LayoutSize(); 1023 return LayoutSize();
1039 1024 StickyPositionScrollingConstraints* constraints = &it->value;
1040 StickyPositionScrollingConstraints* shifting_sticky_box_constraints =
1041 StickyConstraintsForLayoutObject(
1042 constraints->NearestStickyBoxShiftingStickyBox(),
1043 ancestor_overflow_layer);
1044
1045 StickyPositionScrollingConstraints* shifting_containing_block_constraints =
1046 StickyConstraintsForLayoutObject(
1047 constraints->NearestStickyBoxShiftingContainingBlock(),
1048 ancestor_overflow_layer);
1049 1025
1050 // The sticky offset is physical, so we can just return the delta computed in 1026 // The sticky offset is physical, so we can just return the delta computed in
1051 // absolute coords (though it may be wrong with transforms). 1027 // absolute coords (though it may be wrong with transforms).
1052 FloatRect constraining_rect = ComputeStickyConstrainingRect(); 1028 FloatRect constraining_rect = ComputeStickyConstrainingRect();
1053 return LayoutSize(constraints->ComputeStickyOffset( 1029 return LayoutSize(
1054 constraining_rect, shifting_sticky_box_constraints, 1030 constraints->ComputeStickyOffset(constraining_rect, constraints_map));
1055 shifting_containing_block_constraints));
1056 } 1031 }
1057 1032
1058 LayoutPoint LayoutBoxModelObject::AdjustedPositionRelativeTo( 1033 LayoutPoint LayoutBoxModelObject::AdjustedPositionRelativeTo(
1059 const LayoutPoint& start_point, 1034 const LayoutPoint& start_point,
1060 const Element* offset_parent) const { 1035 const Element* offset_parent) const {
1061 // If the element is the HTML body element or doesn't have a parent 1036 // If the element is the HTML body element or doesn't have a parent
1062 // return 0 and stop this algorithm. 1037 // return 0 and stop this algorithm.
1063 if (IsBody() || !Parent()) 1038 if (IsBody() || !Parent())
1064 return LayoutPoint(); 1039 return LayoutPoint();
1065 1040
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 if (root_element_style->HasBackground()) 1392 if (root_element_style->HasBackground())
1418 return false; 1393 return false;
1419 1394
1420 if (GetNode() != GetDocument().FirstBodyElement()) 1395 if (GetNode() != GetDocument().FirstBodyElement())
1421 return false; 1396 return false;
1422 1397
1423 return true; 1398 return true;
1424 } 1399 }
1425 1400
1426 } // namespace blink 1401 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698