| 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 <set> | 5 #include <set> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/trees/property_tree.h" | 10 #include "cc/trees/property_tree.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // Scroll snapping must be done in target space (the pixels we care about). | 309 // Scroll snapping must be done in target space (the pixels we care about). |
| 310 // This means we effectively snap the target space transform. If TT is the | 310 // This means we effectively snap the target space transform. If TT is the |
| 311 // target space transform and TT' is TT with its translation components | 311 // target space transform and TT' is TT with its translation components |
| 312 // rounded, then what we're after is the scroll delta X, where TT * X = TT'. | 312 // rounded, then what we're after is the scroll delta X, where TT * X = TT'. |
| 313 // I.e., we want a transform that will realize our scroll snap. It follows | 313 // I.e., we want a transform that will realize our scroll snap. It follows |
| 314 // that X = TT^-1 * TT'. We cache TT and TT^-1 to make this more efficient. | 314 // that X = TT^-1 * TT'. We cache TT and TT^-1 to make this more efficient. |
| 315 gfx::Transform rounded = node->data.to_target; | 315 gfx::Transform rounded = node->data.to_target; |
| 316 rounded.RoundTranslationComponents(); | 316 rounded.RoundTranslationComponents(); |
| 317 gfx::Transform delta = node->data.from_target; | 317 gfx::Transform delta = node->data.from_target; |
| 318 delta *= rounded; | 318 delta *= rounded; |
| 319 gfx::Transform inverse_delta(gfx::Transform::kSkipInitialization); | |
| 320 bool invertible_delta = delta.GetInverse(&inverse_delta); | |
| 321 | 319 |
| 322 // The delta should be a translation, modulo floating point error, and should | 320 DCHECK(delta.IsIdentityOr2DTranslation()); |
| 323 // therefore be invertible. | 321 |
| 324 DCHECK(invertible_delta); | 322 gfx::Vector2dF translation = delta.To2dTranslation(); |
| 325 | 323 |
| 326 // Now that we have our scroll delta, we must apply it to each of our | 324 // Now that we have our scroll delta, we must apply it to each of our |
| 327 // combined, to/from matrices. | 325 // combined, to/from matrices. |
| 328 node->data.to_parent.PreconcatTransform(delta); | 326 node->data.to_parent.Translate(translation.x(), translation.y()); |
| 329 node->data.to_target.PreconcatTransform(delta); | 327 node->data.to_target.Translate(translation.x(), translation.y()); |
| 330 node->data.from_target.ConcatTransform(inverse_delta); | 328 node->data.from_target.matrix().postTranslate(-translation.x(), |
| 331 node->data.to_screen.PreconcatTransform(delta); | 329 -translation.y(), 0); |
| 332 node->data.from_screen.ConcatTransform(inverse_delta); | 330 node->data.to_screen.Translate(translation.x(), translation.y()); |
| 331 node->data.from_screen.matrix().postTranslate(-translation.x(), |
| 332 -translation.y(), 0); |
| 333 |
| 334 node->data.scroll_snap = translation; |
| 333 } | 335 } |
| 334 | 336 |
| 335 } // namespace cc | 337 } // namespace cc |
| OLD | NEW |