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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 // from the destination to the source, with flattening, and then invert the | 346 // from the destination to the source, with flattening, and then invert the |
347 // result. | 347 // result. |
348 gfx::Transform dest_to_source; | 348 gfx::Transform dest_to_source; |
349 CombineTransformsBetween(dest_id, source_id, &dest_to_source); | 349 CombineTransformsBetween(dest_id, source_id, &dest_to_source); |
350 gfx::Transform source_to_dest; | 350 gfx::Transform source_to_dest; |
351 bool all_are_invertible = dest_to_source.GetInverse(&source_to_dest); | 351 bool all_are_invertible = dest_to_source.GetInverse(&source_to_dest); |
352 transform->PreconcatTransform(source_to_dest); | 352 transform->PreconcatTransform(source_to_dest); |
353 return all_are_invertible; | 353 return all_are_invertible; |
354 } | 354 } |
355 | 355 |
356 gfx::Vector2dF StickyPositionOffset(TransformTree* tree, TransformNode* node) { | 356 gfx::Vector2dF StickyPositionOffset(TransformTree* tree, TransformNode* node) { |
trchen
2017/06/06 21:17:21
nits: I think it'd be nice to add a comment here t
yigu
2017/06/07 15:52:32
This function doesn't really match the one from bl
| |
357 if (node->sticky_position_constraint_id == -1) | 357 if (node->sticky_position_constraint_id == -1) |
358 return gfx::Vector2dF(); | 358 return gfx::Vector2dF(); |
359 StickyPositionNodeData* sticky_data = tree->StickyPositionData(node->id); | 359 StickyPositionNodeData* sticky_data = tree->StickyPositionData(node->id); |
360 const LayerStickyPositionConstraint& constraint = sticky_data->constraints; | 360 const LayerStickyPositionConstraint& constraint = sticky_data->constraints; |
361 auto& property_trees = *tree->property_trees(); | 361 auto& property_trees = *tree->property_trees(); |
362 ScrollNode* scroll_node = | 362 ScrollNode* scroll_node = |
363 property_trees.scroll_tree.Node(sticky_data->scroll_ancestor); | 363 property_trees.scroll_tree.Node(sticky_data->scroll_ancestor); |
364 TransformNode* transform_node = | 364 TransformNode* transform_node = |
365 property_trees.transform_tree.Node(scroll_node->transform_id); | 365 property_trees.transform_tree.Node(scroll_node->transform_id); |
366 const auto& scroll_offset = transform_node->scroll_offset; | 366 const auto& scroll_offset = transform_node->scroll_offset; |
367 DCHECK(property_trees.scroll_tree.current_scroll_offset( | 367 DCHECK(property_trees.scroll_tree.current_scroll_offset( |
368 scroll_node->owning_layer_id) == scroll_offset); | 368 scroll_node->owning_layer_id) == scroll_offset); |
369 gfx::PointF scroll_position(scroll_offset.x(), scroll_offset.y()); | 369 gfx::PointF scroll_position(scroll_offset.x(), scroll_offset.y()); |
370 if (transform_node->scrolls) { | 370 if (transform_node->scrolls) { |
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->sticky_main_thread_offset; |
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 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2191 const EffectNode* effect_node = effect_tree.Node(effect_id); | 2188 const EffectNode* effect_node = effect_tree.Node(effect_id); |
2192 | 2189 |
2193 if (effect_node->surface_contents_scale.x() != 0.0 && | 2190 if (effect_node->surface_contents_scale.x() != 0.0 && |
2194 effect_node->surface_contents_scale.y() != 0.0) | 2191 effect_node->surface_contents_scale.y() != 0.0) |
2195 screen_space_transform.Scale(1.0 / effect_node->surface_contents_scale.x(), | 2192 screen_space_transform.Scale(1.0 / effect_node->surface_contents_scale.x(), |
2196 1.0 / effect_node->surface_contents_scale.y()); | 2193 1.0 / effect_node->surface_contents_scale.y()); |
2197 return screen_space_transform; | 2194 return screen_space_transform; |
2198 } | 2195 } |
2199 | 2196 |
2200 } // namespace cc | 2197 } // namespace cc |
OLD | NEW |