| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 2010 Google Inc. All rights reserved. | 2  * Copyright (C) 2010 Google Inc. All rights reserved. | 
| 3  * | 3  * | 
| 4  * Redistribution and use in source and binary forms, with or without | 4  * Redistribution and use in source and binary forms, with or without | 
| 5  * modification, are permitted provided that the following conditions | 5  * modification, are permitted provided that the following conditions | 
| 6  * are met: | 6  * are met: | 
| 7  * | 7  * | 
| 8  * 1.  Redistributions of source code must retain the above copyright | 8  * 1.  Redistributions of source code must retain the above copyright | 
| 9  *     notice, this list of conditions and the following disclaimer. | 9  *     notice, this list of conditions and the following disclaimer. | 
| 10  * 2.  Redistributions in binary form must reproduce the above copyright | 10  * 2.  Redistributions in binary form must reproduce the above copyright | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 30 #include "platform/scroll/ScrollAnimatorNone.h" | 30 #include "platform/scroll/ScrollAnimatorNone.h" | 
| 31 | 31 | 
| 32 #include "platform/Logging.h" | 32 #include "platform/Logging.h" | 
| 33 #include "platform/geometry/FloatPoint.h" | 33 #include "platform/geometry/FloatPoint.h" | 
| 34 #include "platform/geometry/IntRect.h" | 34 #include "platform/geometry/IntRect.h" | 
| 35 #include "platform/scroll/ScrollAnimator.h" | 35 #include "platform/scroll/ScrollAnimator.h" | 
| 36 #include "platform/scroll/ScrollableArea.h" | 36 #include "platform/scroll/ScrollableArea.h" | 
| 37 #include <gmock/gmock.h> | 37 #include <gmock/gmock.h> | 
| 38 #include <gtest/gtest.h> | 38 #include <gtest/gtest.h> | 
| 39 | 39 | 
| 40 using namespace std; |  | 
| 41 using namespace WebCore; | 40 using namespace WebCore; | 
| 42 | 41 | 
| 43 using testing::AtLeast; | 42 using testing::AtLeast; | 
| 44 using testing::Return; | 43 using testing::Return; | 
| 45 using testing::_; | 44 using testing::_; | 
| 46 | 45 | 
| 47 class MockScrollableArea : public ScrollableArea { | 46 class MockScrollableArea : public ScrollableArea { | 
| 48 public: | 47 public: | 
| 49     MockScrollableArea(bool scrollAnimatorEnabled) | 48     MockScrollableArea(bool scrollAnimatorEnabled) | 
| 50         : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } | 49         : m_scrollAnimatorEnabled(scrollAnimatorEnabled) { } | 
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 270     double oldDesiredVelocity = m_data->m_desiredVelocity; | 269     double oldDesiredVelocity = m_data->m_desiredVelocity; | 
| 271     double oldTimeLeft = m_data->m_animationTime - (m_data->m_lastAnimationTime 
      - m_data->m_startTime); | 270     double oldTimeLeft = m_data->m_animationTime - (m_data->m_lastAnimationTime 
      - m_data->m_startTime); | 
| 272     bool result = m_data->updateDataFromParameters(step, multiplier, scrollableS
      ize, currentTime, parameters); | 271     bool result = m_data->updateDataFromParameters(step, multiplier, scrollableS
      ize, currentTime, parameters); | 
| 273     if (m_scrollingDown) | 272     if (m_scrollingDown) | 
| 274         EXPECT_LE(oldVelocity, m_data->m_currentVelocity); | 273         EXPECT_LE(oldVelocity, m_data->m_currentVelocity); | 
| 275     else | 274     else | 
| 276         EXPECT_GE(oldVelocity, m_data->m_currentVelocity); | 275         EXPECT_GE(oldVelocity, m_data->m_currentVelocity); | 
| 277 | 276 | 
| 278     double deltaTime = m_data->m_lastAnimationTime - m_data->m_startTime; | 277     double deltaTime = m_data->m_lastAnimationTime - m_data->m_startTime; | 
| 279     double timeLeft = m_data->m_animationTime - deltaTime; | 278     double timeLeft = m_data->m_animationTime - deltaTime; | 
| 280     double releaseTimeLeft = min(timeLeft, m_data->m_releaseTime); | 279     double releaseTimeLeft = std::min(timeLeft, m_data->m_releaseTime); | 
| 281     double attackTimeLeft = max(0., m_data->m_attackTime - deltaTime); | 280     double attackTimeLeft = std::max(0., m_data->m_attackTime - deltaTime); | 
| 282     double sustainTimeLeft = max(0., timeLeft - releaseTimeLeft - attackTimeLeft
      ); | 281     double sustainTimeLeft = std::max(0., timeLeft - releaseTimeLeft - attackTim
      eLeft); | 
| 283 | 282 | 
| 284     // If we're getting near the finish, the desired velocity can decrease since
       the time left gets increased. | 283     // If we're getting near the finish, the desired velocity can decrease since
       the time left gets increased. | 
| 285     if (step * multiplier) { | 284     if (step * multiplier) { | 
| 286         double allowedVelocityDecreaseFactor = 0.99 * oldTimeLeft / timeLeft; | 285         double allowedVelocityDecreaseFactor = 0.99 * oldTimeLeft / timeLeft; | 
| 287         allowedVelocityDecreaseFactor *= allowedVelocityDecreaseFactor; | 286         allowedVelocityDecreaseFactor *= allowedVelocityDecreaseFactor; | 
| 288         if (m_scrollingDown) | 287         if (m_scrollingDown) | 
| 289             EXPECT_LE(oldDesiredVelocity * allowedVelocityDecreaseFactor, m_data
      ->m_desiredVelocity); | 288             EXPECT_LE(oldDesiredVelocity * allowedVelocityDecreaseFactor, m_data
      ->m_desiredVelocity); | 
| 290         else | 289         else | 
| 291             EXPECT_GE(oldDesiredVelocity * allowedVelocityDecreaseFactor, m_data
      ->m_desiredVelocity); | 290             EXPECT_GE(oldDesiredVelocity * allowedVelocityDecreaseFactor, m_data
      ->m_desiredVelocity); | 
| 292 | 291 | 
| 293         double startPosition = attackTimeLeft ? m_data->m_attackPosition : m_cur
      rentPosition; | 292         double startPosition = attackTimeLeft ? m_data->m_attackPosition : m_cur
      rentPosition; | 
| 294         double expectedReleasePosition = startPosition + sustainTimeLeft * m_dat
      a->m_desiredVelocity; | 293         double expectedReleasePosition = startPosition + sustainTimeLeft * m_dat
      a->m_desiredVelocity; | 
| 295         EXPECT_NEAR(expectedReleasePosition, m_data->m_releasePosition, result ?
       .0001 : 1); | 294         EXPECT_NEAR(expectedReleasePosition, m_data->m_releasePosition, result ?
       .0001 : 1); | 
| 296     } | 295     } | 
| 297 | 296 | 
| 298     return result; | 297     return result; | 
| 299 } | 298 } | 
| 300 | 299 | 
| 301 bool ScrollAnimatorNoneTest::animateScroll(double currentTime) | 300 bool ScrollAnimatorNoneTest::animateScroll(double currentTime) | 
| 302 { | 301 { | 
| 303     double oldPosition = *m_data->m_currentPosition; | 302     double oldPosition = *m_data->m_currentPosition; | 
| 304     bool testEstimatedMaxVelocity = m_data->m_startTime + m_data->m_animationTim
      e - m_data->m_lastAnimationTime > m_data->m_releaseTime; | 303     bool testEstimatedMaxVelocity = m_data->m_startTime + m_data->m_animationTim
      e - m_data->m_lastAnimationTime > m_data->m_releaseTime; | 
| 305 | 304 | 
| 306     bool result = m_data->animateScroll(currentTime); | 305     bool result = m_data->animateScroll(currentTime); | 
| 307 | 306 | 
| 308     double deltaTime = m_data->m_lastAnimationTime - m_data->m_startTime; | 307     double deltaTime = m_data->m_lastAnimationTime - m_data->m_startTime; | 
| 309     double timeLeft = m_data->m_animationTime - deltaTime; | 308     double timeLeft = m_data->m_animationTime - deltaTime; | 
| 310     double releaseTimeLeft = min(timeLeft, m_data->m_releaseTime); | 309     double releaseTimeLeft = std::min(timeLeft, m_data->m_releaseTime); | 
| 311     double attackTimeLeft = max(0., m_data->m_attackTime - deltaTime); | 310     double attackTimeLeft = std::max(0., m_data->m_attackTime - deltaTime); | 
| 312     double sustainTimeLeft = max(0., timeLeft - releaseTimeLeft - attackTimeLeft
      ); | 311     double sustainTimeLeft = std::max(0., timeLeft - releaseTimeLeft - attackTim
      eLeft); | 
| 313     double distanceLeft = m_data->m_desiredPosition - *m_data->m_currentPosition
      ; | 312     double distanceLeft = m_data->m_desiredPosition - *m_data->m_currentPosition
      ; | 
| 314 | 313 | 
| 315     if (m_scrollingDown) { | 314     if (m_scrollingDown) { | 
| 316         EXPECT_LE(0, m_data->m_currentVelocity); | 315         EXPECT_LE(0, m_data->m_currentVelocity); | 
| 317         EXPECT_LE(oldPosition, *m_data->m_currentPosition); | 316         EXPECT_LE(oldPosition, *m_data->m_currentPosition); | 
| 318     } else { | 317     } else { | 
| 319         EXPECT_GE(0, m_data->m_currentVelocity); | 318         EXPECT_GE(0, m_data->m_currentVelocity); | 
| 320         EXPECT_GE(oldPosition, *m_data->m_currentPosition); | 319         EXPECT_GE(oldPosition, *m_data->m_currentPosition); | 
| 321     } | 320     } | 
| 322     EXPECT_GE(fabs(m_data->m_desiredVelocity) * 2, fabs(m_data->m_currentVelocit
      y)); | 321     EXPECT_GE(fabs(m_data->m_desiredVelocity) * 2, fabs(m_data->m_currentVelocit
      y)); | 
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1044     EXPECT_TRUE(result); | 1043     EXPECT_TRUE(result); | 
| 1045     result = result && animateScroll(t); | 1044     result = result && animateScroll(t); | 
| 1046     double after = m_currentPosition; | 1045     double after = m_currentPosition; | 
| 1047     EXPECT_GE(before, after); | 1046     EXPECT_GE(before, after); | 
| 1048 | 1047 | 
| 1049     t += kAnimationTime; | 1048     t += kAnimationTime; | 
| 1050     for (; result && t < kEndTime; t += kAnimationTime) | 1049     for (; result && t < kEndTime; t += kAnimationTime) | 
| 1051         result = result && animateScroll(t); | 1050         result = result && animateScroll(t); | 
| 1052     EXPECT_GE(before, m_currentPosition); | 1051     EXPECT_GE(before, m_currentPosition); | 
| 1053 } | 1052 } | 
| OLD | NEW | 
|---|