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

Unified Diff: cc/trees/property_tree.cc

Issue 2733633002: Handle nested position:sticky elements correctly (compositor) (Closed)
Patch Set: Addressed the easier reviewer comments. 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
« no previous file with comments | « cc/trees/property_tree.h ('k') | cc/trees/property_tree_builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/property_tree.cc
diff --git a/cc/trees/property_tree.cc b/cc/trees/property_tree.cc
index af6e451a922933eaa1d66b458e59543d8fe6b343..1a0e48b3f8c0c57f5f63406c0d81543c341bcf13 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,81 @@ 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.
+
+ 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::Rect sticky_box_rect =
+ constraint.scroll_container_relative_sticky_box_rect;
+ gfx::Rect containing_block_rect =
+ constraint.scroll_container_relative_containing_block_rect;
+ sticky_box_rect += gfx::ToFlooredVector2d(ancestor_sticky_box_offset +
flackr 2017/03/13 19:49:45 This loss of precision seems dangerous, we could e
+ ancestor_containing_block_offset);
+ containing_block_rect +=
+ gfx::ToFlooredVector2d(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();
+
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) {
« no previous file with comments | « cc/trees/property_tree.h ('k') | cc/trees/property_tree_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698