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

Unified Diff: cc/trees/property_tree.cc

Issue 2733633002: Handle nested position:sticky elements correctly (compositor) (Closed)
Patch Set: Add comment referencing crbug.com/702229 Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: cc/trees/property_tree.cc
diff --git a/cc/trees/property_tree.cc b/cc/trees/property_tree.cc
index f4f78d9f4a2b9c586a92a13028e53793b18420c0..394564e1d599a4462d8c4dd89a927f272adcd9ba 100644
--- a/cc/trees/property_tree.cc
+++ b/cc/trees/property_tree.cc
@@ -346,9 +346,8 @@ bool TransformTree::CombineInversesBetween(int source_id,
gfx::Vector2dF StickyPositionOffset(TransformTree* tree, TransformNode* node) {
if (node->sticky_position_constraint_id == -1)
return gfx::Vector2dF();
- const StickyPositionNodeData* sticky_data =
- tree->StickyPositionData(node->id);
- const LayerStickyPositionConstraint& constraint = sticky_data->constraints;
+ StickyPositionNodeData* sticky_data = tree->StickyPositionData(node->id);
+ LayerStickyPositionConstraint& constraint = sticky_data->constraints;
ScrollNode* scroll_node =
tree->property_trees()->scroll_tree.Node(sticky_data->scroll_ancestor);
gfx::ScrollOffset scroll_offset =
@@ -368,8 +367,6 @@ gfx::Vector2dF StickyPositionOffset(TransformTree* tree, TransformNode* node) {
scroll_position,
gfx::SizeF(tree->property_trees()->scroll_tree.scroll_clip_layer_bounds(
scroll_node->id)));
- gfx::Vector2dF sticky_offset(
- constraint.scroll_container_relative_sticky_box_rect.OffsetFromOrigin());
gfx::Vector2dF layer_offset(sticky_data->main_thread_offset);
// In each of the following cases, we measure the limit which is the point
@@ -381,57 +378,79 @@ gfx::Vector2dF StickyPositionOffset(TransformTree* tree, TransformNode* node) {
// Note: The order of applying the sticky constraints is applied such that
// left offset takes precedence over right offset, and top takes precedence
// over bottom offset.
flackr 2017/03/17 15:01:55 This comment should probably stay next to the limi
smcgruer 2017/03/17 17:36:51 Done.
+
+ gfx::Vector2dF ancestor_sticky_box_offset;
+ if (sticky_data->nearest_node_shifting_sticky_box >= 0) {
+ ancestor_sticky_box_offset =
+ tree->StickyPositionData(sticky_data->nearest_node_shifting_sticky_box)
+ ->constraints.total_sticky_box_sticky_offset;
+ }
+
+ gfx::Vector2dF ancestor_containing_block_offset;
+ if (sticky_data->nearest_node_shifting_containing_block >= 0) {
+ ancestor_containing_block_offset =
+ tree->StickyPositionData(
+ sticky_data->nearest_node_shifting_containing_block)
+ ->constraints.total_containing_block_sticky_offset;
+ }
+
+ gfx::RectF sticky_box_rect =
flackr 2017/03/17 15:01:56 nit: Add a short comment explaining what this is d
smcgruer 2017/03/17 17:36:52 Done.
+ constraint.scroll_container_relative_sticky_box_rect +
+ ancestor_sticky_box_offset + ancestor_containing_block_offset;
+ gfx::RectF containing_block_rect =
+ constraint.scroll_container_relative_containing_block_rect +
+ ancestor_containing_block_offset;
+
+ gfx::Vector2dF sticky_offset(sticky_box_rect.OffsetFromOrigin());
+
if (constraint.is_anchored_right) {
float right_limit = clip.right() - constraint.right_offset;
- float right_delta = std::min<float>(
- 0, right_limit -
- constraint.scroll_container_relative_sticky_box_rect.right());
- float available_space = std::min<float>(
- 0, constraint.scroll_container_relative_containing_block_rect.x() -
- constraint.scroll_container_relative_sticky_box_rect.x());
+ float right_delta =
+ std::min<float>(0, right_limit - sticky_box_rect.right());
+ float available_space =
+ std::min<float>(0, containing_block_rect.x() - sticky_box_rect.x());
if (right_delta < available_space)
right_delta = available_space;
sticky_offset.set_x(sticky_offset.x() + right_delta);
}
if (constraint.is_anchored_left) {
float left_limit = clip.x() + constraint.left_offset;
- float left_delta = std::max<float>(
- 0,
- left_limit - constraint.scroll_container_relative_sticky_box_rect.x());
+ float left_delta = std::max<float>(0, left_limit - sticky_box_rect.x());
float available_space = std::max<float>(
- 0, constraint.scroll_container_relative_containing_block_rect.right() -
- constraint.scroll_container_relative_sticky_box_rect.right());
+ 0, containing_block_rect.right() - sticky_box_rect.right());
if (left_delta > available_space)
left_delta = available_space;
sticky_offset.set_x(sticky_offset.x() + left_delta);
}
if (constraint.is_anchored_bottom) {
float bottom_limit = clip.bottom() - constraint.bottom_offset;
- float bottom_delta = std::min<float>(
- 0, bottom_limit -
- constraint.scroll_container_relative_sticky_box_rect.bottom());
- float available_space = std::min<float>(
- 0, constraint.scroll_container_relative_containing_block_rect.y() -
- constraint.scroll_container_relative_sticky_box_rect.y());
+ float bottom_delta =
+ std::min<float>(0, bottom_limit - sticky_box_rect.bottom());
+ float available_space =
+ std::min<float>(0, containing_block_rect.y() - sticky_box_rect.y());
if (bottom_delta < available_space)
bottom_delta = available_space;
sticky_offset.set_y(sticky_offset.y() + bottom_delta);
}
if (constraint.is_anchored_top) {
float top_limit = clip.y() + constraint.top_offset;
- float top_delta = std::max<float>(
- 0,
- top_limit - constraint.scroll_container_relative_sticky_box_rect.y());
+ float top_delta = std::max<float>(0, top_limit - sticky_box_rect.y());
float available_space = std::max<float>(
- 0, constraint.scroll_container_relative_containing_block_rect.bottom() -
- constraint.scroll_container_relative_sticky_box_rect.bottom());
+ 0, containing_block_rect.bottom() - sticky_box_rect.bottom());
if (top_delta > available_space)
top_delta = available_space;
sticky_offset.set_y(sticky_offset.y() + top_delta);
}
+
+ constraint.total_sticky_box_sticky_offset =
+ ancestor_sticky_box_offset + sticky_offset -
+ sticky_box_rect.OffsetFromOrigin();
+ constraint.total_containing_block_sticky_offset =
+ ancestor_sticky_box_offset + ancestor_containing_block_offset +
+ sticky_offset - sticky_box_rect.OffsetFromOrigin();
flackr 2017/03/17 15:01:55 I think we should keep the passed in constraints c
smcgruer 2017/03/17 17:36:51 Done.
+
return sticky_offset - layer_offset - node->source_to_parent -
- constraint.scroll_container_relative_sticky_box_rect
- .OffsetFromOrigin();
+ sticky_box_rect.OffsetFromOrigin();
}
void TransformTree::UpdateLocalTransform(TransformNode* node) {

Powered by Google App Engine
This is Rietveld 408576698