| OLD | NEW |
| 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 Loading... |
| 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 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 FloatRect(scroll_container_relative_padding_box_rect.Location() + | 924 FloatRect(scroll_container_relative_padding_box_rect.Location() + |
| 943 ToFloatSize(sticky_location), | 925 ToFloatSize(sticky_location), |
| 944 flipped_sticky_box_rect.Size())); | 926 flipped_sticky_box_rect.Size())); |
| 945 | 927 |
| 946 // To correctly compute the offsets, the constraints need to know about any | 928 // To correctly compute the offsets, the constraints need to know about any |
| 947 // nested position:sticky elements between themselves and their | 929 // nested position:sticky elements between themselves and their |
| 948 // containingBlock, and between the containingBlock and their scrollAncestor. | 930 // containingBlock, and between the containingBlock and their scrollAncestor. |
| 949 // | 931 // |
| 950 // The respective search ranges are [container, containingBlock) and | 932 // The respective search ranges are [container, containingBlock) and |
| 951 // [containingBlock, scrollAncestor). | 933 // [containingBlock, scrollAncestor). |
| 952 constraints.SetNearestStickyBoxShiftingStickyBox( | 934 constraints.SetNearestStickyLayerShiftingStickyBox( |
| 953 FindFirstStickyBetween(location_container, containing_block)); | 935 FindFirstStickyBetween(location_container, containing_block)); |
| 954 // We cannot use |scrollAncestor| here as it disregards the root | 936 // We cannot use |scrollAncestor| here as it disregards the root |
| 955 // ancestorOverflowLayer(), which we should include. | 937 // ancestorOverflowLayer(), which we should include. |
| 956 constraints.SetNearestStickyBoxShiftingContainingBlock(FindFirstStickyBetween( | 938 constraints.SetNearestStickyLayerShiftingContainingBlock( |
| 957 containing_block, &Layer()->AncestorOverflowLayer()->GetLayoutObject())); | 939 FindFirstStickyBetween( |
| 940 containing_block, |
| 941 &Layer()->AncestorOverflowLayer()->GetLayoutObject())); |
| 958 | 942 |
| 959 // We skip the right or top sticky offset if there is not enough space to | 943 // We skip the right or top sticky offset if there is not enough space to |
| 960 // honor both the left/right or top/bottom offsets. | 944 // honor both the left/right or top/bottom offsets. |
| 961 LayoutUnit horizontal_offsets = | 945 LayoutUnit horizontal_offsets = |
| 962 MinimumValueForLength(Style()->Right(), | 946 MinimumValueForLength(Style()->Right(), |
| 963 LayoutUnit(constraining_size.Width())) + | 947 LayoutUnit(constraining_size.Width())) + |
| 964 MinimumValueForLength(Style()->Left(), | 948 MinimumValueForLength(Style()->Left(), |
| 965 LayoutUnit(constraining_size.Width())); | 949 LayoutUnit(constraining_size.Width())); |
| 966 bool skip_right = false; | 950 bool skip_right = false; |
| 967 bool skip_left = false; | 951 bool skip_left = false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 enclosing_clipping_box->PaddingRight(), | 1031 enclosing_clipping_box->PaddingRight(), |
| 1048 enclosing_clipping_box->PaddingTop() + | 1032 enclosing_clipping_box->PaddingTop() + |
| 1049 enclosing_clipping_box->PaddingBottom())); | 1033 enclosing_clipping_box->PaddingBottom())); |
| 1050 return constraining_rect; | 1034 return constraining_rect; |
| 1051 } | 1035 } |
| 1052 | 1036 |
| 1053 LayoutSize LayoutBoxModelObject::StickyPositionOffset() const { | 1037 LayoutSize LayoutBoxModelObject::StickyPositionOffset() const { |
| 1054 const PaintLayer* ancestor_overflow_layer = Layer()->AncestorOverflowLayer(); | 1038 const PaintLayer* ancestor_overflow_layer = Layer()->AncestorOverflowLayer(); |
| 1055 // TODO: Force compositing input update if we ask for offset before | 1039 // TODO: Force compositing input update if we ask for offset before |
| 1056 // compositing inputs have been computed? | 1040 // compositing inputs have been computed? |
| 1057 if (!ancestor_overflow_layer) | 1041 if (!ancestor_overflow_layer || !ancestor_overflow_layer->GetScrollableArea()) |
| 1058 return LayoutSize(); | 1042 return LayoutSize(); |
| 1059 | 1043 |
| 1060 StickyPositionScrollingConstraints* constraints = | 1044 StickyConstraintsMap& constraints_map = |
| 1061 StickyConstraintsForLayoutObject(this, ancestor_overflow_layer); | 1045 ancestor_overflow_layer->GetScrollableArea()->GetStickyConstraintsMap(); |
| 1062 if (!constraints) | 1046 auto it = constraints_map.find(Layer()); |
| 1047 if (it == constraints_map.end()) |
| 1063 return LayoutSize(); | 1048 return LayoutSize(); |
| 1064 | 1049 StickyPositionScrollingConstraints* constraints = &it->value; |
| 1065 StickyPositionScrollingConstraints* shifting_sticky_box_constraints = | |
| 1066 StickyConstraintsForLayoutObject( | |
| 1067 constraints->NearestStickyBoxShiftingStickyBox(), | |
| 1068 ancestor_overflow_layer); | |
| 1069 | |
| 1070 StickyPositionScrollingConstraints* shifting_containing_block_constraints = | |
| 1071 StickyConstraintsForLayoutObject( | |
| 1072 constraints->NearestStickyBoxShiftingContainingBlock(), | |
| 1073 ancestor_overflow_layer); | |
| 1074 | 1050 |
| 1075 // The sticky offset is physical, so we can just return the delta computed in | 1051 // The sticky offset is physical, so we can just return the delta computed in |
| 1076 // absolute coords (though it may be wrong with transforms). | 1052 // absolute coords (though it may be wrong with transforms). |
| 1077 FloatRect constraining_rect = ComputeStickyConstrainingRect(); | 1053 FloatRect constraining_rect = ComputeStickyConstrainingRect(); |
| 1078 return LayoutSize(constraints->ComputeStickyOffset( | 1054 return LayoutSize( |
| 1079 constraining_rect, shifting_sticky_box_constraints, | 1055 constraints->ComputeStickyOffset(constraining_rect, constraints_map)); |
| 1080 shifting_containing_block_constraints)); | |
| 1081 } | 1056 } |
| 1082 | 1057 |
| 1083 LayoutPoint LayoutBoxModelObject::AdjustedPositionRelativeTo( | 1058 LayoutPoint LayoutBoxModelObject::AdjustedPositionRelativeTo( |
| 1084 const LayoutPoint& start_point, | 1059 const LayoutPoint& start_point, |
| 1085 const Element* offset_parent) const { | 1060 const Element* offset_parent) const { |
| 1086 // If the element is the HTML body element or doesn't have a parent | 1061 // If the element is the HTML body element or doesn't have a parent |
| 1087 // return 0 and stop this algorithm. | 1062 // return 0 and stop this algorithm. |
| 1088 if (IsBody() || !Parent()) | 1063 if (IsBody() || !Parent()) |
| 1089 return LayoutPoint(); | 1064 return LayoutPoint(); |
| 1090 | 1065 |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1442 if (root_element_style->HasBackground()) | 1417 if (root_element_style->HasBackground()) |
| 1443 return false; | 1418 return false; |
| 1444 | 1419 |
| 1445 if (GetNode() != GetDocument().FirstBodyElement()) | 1420 if (GetNode() != GetDocument().FirstBodyElement()) |
| 1446 return false; | 1421 return false; |
| 1447 | 1422 |
| 1448 return true; | 1423 return true; |
| 1449 } | 1424 } |
| 1450 | 1425 |
| 1451 } // namespace blink | 1426 } // namespace blink |
| OLD | NEW |