| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 // The scroll position does not include snapping which shifts the scroll | 371 // The scroll position does not include snapping which shifts the scroll |
| 372 // offset to align to a pixel boundary, we need to manually include it here. | 372 // offset to align to a pixel boundary, we need to manually include it here. |
| 373 // In this case, snapping is caused by a scroll. | 373 // In this case, snapping is caused by a scroll. |
| 374 scroll_position -= transform_node->snap_amount; | 374 scroll_position -= transform_node->snap_amount; |
| 375 } | 375 } |
| 376 | 376 |
| 377 gfx::RectF clip( | 377 gfx::RectF clip( |
| 378 scroll_position, | 378 scroll_position, |
| 379 gfx::SizeF(property_trees.scroll_tree.scroll_clip_layer_bounds( | 379 gfx::SizeF(property_trees.scroll_tree.scroll_clip_layer_bounds( |
| 380 scroll_node->id))); | 380 scroll_node->id))); |
| 381 gfx::Vector2dF layer_offset(sticky_data->main_thread_offset); | |
| 382 | 381 |
| 383 gfx::Vector2dF ancestor_sticky_box_offset; | 382 gfx::Vector2dF ancestor_sticky_box_offset; |
| 384 if (sticky_data->nearest_node_shifting_sticky_box != | 383 if (sticky_data->nearest_node_shifting_sticky_box != |
| 385 TransformTree::kInvalidNodeId) { | 384 TransformTree::kInvalidNodeId) { |
| 386 ancestor_sticky_box_offset = | 385 ancestor_sticky_box_offset = |
| 387 tree->StickyPositionData(sticky_data->nearest_node_shifting_sticky_box) | 386 tree->StickyPositionData(sticky_data->nearest_node_shifting_sticky_box) |
| 388 ->total_sticky_box_sticky_offset; | 387 ->total_sticky_box_sticky_offset; |
| 389 } | 388 } |
| 390 | 389 |
| 391 gfx::Vector2dF ancestor_containing_block_offset; | 390 gfx::Vector2dF ancestor_containing_block_offset; |
| 392 if (sticky_data->nearest_node_shifting_containing_block != | 391 if (sticky_data->nearest_node_shifting_containing_block != |
| 393 TransformTree::kInvalidNodeId) { | 392 TransformTree::kInvalidNodeId) { |
| 394 ancestor_containing_block_offset = | 393 ancestor_containing_block_offset = |
| 395 tree->StickyPositionData( | 394 tree->StickyPositionData( |
| 396 sticky_data->nearest_node_shifting_containing_block) | 395 sticky_data->nearest_node_shifting_containing_block) |
| 397 ->total_containing_block_sticky_offset; | 396 ->total_containing_block_sticky_offset; |
| 398 } | 397 } |
| 399 | 398 |
| 400 // Compute the current position of the constraint rects based on the original | 399 // Compute the current position of the constraint rects based on the original |
| 401 // positions and the offsets from ancestor sticky elements. | 400 // positions and the offsets from ancestor sticky elements. |
| 402 gfx::RectF sticky_box_rect = | 401 gfx::RectF sticky_box_rect = |
| 403 gfx::RectF(constraint.scroll_container_relative_sticky_box_rect) + | 402 gfx::RectF(constraint.scroll_container_relative_sticky_box_rect) + |
| 404 ancestor_sticky_box_offset + ancestor_containing_block_offset; | 403 ancestor_sticky_box_offset + ancestor_containing_block_offset; |
| 405 gfx::RectF containing_block_rect = | 404 gfx::RectF containing_block_rect = |
| 406 gfx::RectF(constraint.scroll_container_relative_containing_block_rect) + | 405 gfx::RectF(constraint.scroll_container_relative_containing_block_rect) + |
| 407 ancestor_containing_block_offset; | 406 ancestor_containing_block_offset; |
| 408 | 407 |
| 409 gfx::Vector2dF sticky_offset(sticky_box_rect.OffsetFromOrigin()); | 408 gfx::Vector2dF sticky_offset; |
| 410 | 409 |
| 411 // In each of the following cases, we measure the limit which is the point | 410 // In each of the following cases, we measure the limit which is the point |
| 412 // that the element should stick to, clamping on one side to 0 (because sticky | 411 // that the element should stick to, clamping on one side to 0 (because sticky |
| 413 // only pushes elements in one direction). Then we clamp to how far we can | 412 // only pushes elements in one direction). Then we clamp to how far we can |
| 414 // push the element in that direction without being pushed outside of its | 413 // push the element in that direction without being pushed outside of its |
| 415 // containing block. | 414 // containing block. |
| 416 // | 415 // |
| 417 // Note: The order of applying the sticky constraints is applied such that | 416 // Note: The order of applying the sticky constraints is applied such that |
| 418 // left offset takes precedence over right offset, and top takes precedence | 417 // left offset takes precedence over right offset, and top takes precedence |
| 419 // over bottom offset. | 418 // over bottom offset. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 450 float top_limit = clip.y() + constraint.top_offset; | 449 float top_limit = clip.y() + constraint.top_offset; |
| 451 float top_delta = std::max<float>(0, top_limit - sticky_box_rect.y()); | 450 float top_delta = std::max<float>(0, top_limit - sticky_box_rect.y()); |
| 452 float available_space = std::max<float>( | 451 float available_space = std::max<float>( |
| 453 0, containing_block_rect.bottom() - sticky_box_rect.bottom()); | 452 0, containing_block_rect.bottom() - sticky_box_rect.bottom()); |
| 454 if (top_delta > available_space) | 453 if (top_delta > available_space) |
| 455 top_delta = available_space; | 454 top_delta = available_space; |
| 456 sticky_offset.set_y(sticky_offset.y() + top_delta); | 455 sticky_offset.set_y(sticky_offset.y() + top_delta); |
| 457 } | 456 } |
| 458 | 457 |
| 459 sticky_data->total_sticky_box_sticky_offset = | 458 sticky_data->total_sticky_box_sticky_offset = |
| 460 ancestor_sticky_box_offset + sticky_offset - | 459 ancestor_sticky_box_offset + sticky_offset; |
| 461 sticky_box_rect.OffsetFromOrigin(); | |
| 462 sticky_data->total_containing_block_sticky_offset = | 460 sticky_data->total_containing_block_sticky_offset = |
| 463 ancestor_sticky_box_offset + ancestor_containing_block_offset + | 461 ancestor_sticky_box_offset + ancestor_containing_block_offset + |
| 464 sticky_offset - sticky_box_rect.OffsetFromOrigin(); | 462 sticky_offset; |
| 465 | 463 |
| 466 return sticky_offset - layer_offset - node->source_to_parent - | 464 return sticky_offset - node->offset_for_sticky_position_from_main_thread; |
| 467 sticky_box_rect.OffsetFromOrigin(); | |
| 468 } | 465 } |
| 469 | 466 |
| 470 void TransformTree::UpdateLocalTransform(TransformNode* node) { | 467 void TransformTree::UpdateLocalTransform(TransformNode* node) { |
| 471 gfx::Transform transform = node->post_local; | 468 gfx::Transform transform = node->post_local; |
| 472 if (NeedsSourceToParentUpdate(node)) { | 469 if (NeedsSourceToParentUpdate(node)) { |
| 473 gfx::Transform to_parent; | 470 gfx::Transform to_parent; |
| 474 ComputeTranslation(node->source_node_id, node->parent_id, &to_parent); | 471 ComputeTranslation(node->source_node_id, node->parent_id, &to_parent); |
| 475 gfx::Vector2dF unsnapping; | 472 gfx::Vector2dF unsnapping; |
| 476 TransformNode* current; | 473 TransformNode* current; |
| 477 TransformNode* parent_node; | 474 TransformNode* parent_node; |
| (...skipping 1718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2196 const EffectNode* effect_node = effect_tree.Node(effect_id); | 2193 const EffectNode* effect_node = effect_tree.Node(effect_id); |
| 2197 | 2194 |
| 2198 if (effect_node->surface_contents_scale.x() != 0.0 && | 2195 if (effect_node->surface_contents_scale.x() != 0.0 && |
| 2199 effect_node->surface_contents_scale.y() != 0.0) | 2196 effect_node->surface_contents_scale.y() != 0.0) |
| 2200 screen_space_transform.Scale(1.0 / effect_node->surface_contents_scale.x(), | 2197 screen_space_transform.Scale(1.0 / effect_node->surface_contents_scale.x(), |
| 2201 1.0 / effect_node->surface_contents_scale.y()); | 2198 1.0 / effect_node->surface_contents_scale.y()); |
| 2202 return screen_space_transform; | 2199 return screen_space_transform; |
| 2203 } | 2200 } |
| 2204 | 2201 |
| 2205 } // namespace cc | 2202 } // namespace cc |
| OLD | NEW |