From db3e8ca04248c1ddfbc4b8e63cc130b44fb7b67b Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Fri, 13 Dec 2013 13:41:47 +0900 Subject: [PATCH] Bug 948245 part 1 - Rework and test repeat duration calculation; r=dholbert In order to implement the min attribute properly we need to distinguish between cases where the repeat duration is less than the active duration so we can apply the fill mode in the 'gap'. Currently the repeat duration calculation is mostly contained in GetRepeatDuration (but is hard to make sense of) and partly contained in the call site CalcActiveEnd. Furthermore, it does not have thorough tests (there were some unit tests but they were never converted to mochitests). This patch reworks the repeat duration calculation so it is contained in one place, easier to read, and thoroughly tested. --- content/smil/nsSMILRepeatCount.h | 6 +- content/smil/nsSMILTimedElement.cpp | 42 +++--- content/smil/test/mochitest.ini | 1 + .../smil/test/test_smilRepeatDuration.html | 139 ++++++++++++++++++ 4 files changed, 162 insertions(+), 26 deletions(-) create mode 100644 content/smil/test/test_smilRepeatDuration.html diff --git a/content/smil/nsSMILRepeatCount.h b/content/smil/nsSMILRepeatCount.h index 18c6d66db618..8561fe4d8bd4 100644 --- a/content/smil/nsSMILRepeatCount.h +++ b/content/smil/nsSMILRepeatCount.h @@ -27,7 +27,11 @@ public: explicit nsSMILRepeatCount(double aCount) : mCount(kNotSet) { SetCount(aCount); } - operator double() const { return mCount; } + operator double() const { + MOZ_ASSERT(IsDefinite(), + "Converting indefinite or unset repeat count to double"); + return mCount; + } bool IsDefinite() const { return mCount != kNotSet && mCount != kIndefinite; } diff --git a/content/smil/nsSMILTimedElement.cpp b/content/smil/nsSMILTimedElement.cpp index 3538ca5d78b2..4ffde26796ed 100644 --- a/content/smil/nsSMILTimedElement.cpp +++ b/content/smil/nsSMILTimedElement.cpp @@ -1803,11 +1803,7 @@ nsSMILTimedElement::CalcActiveEnd(const nsSMILTimeValue& aBegin, NS_ABORT_IF_FALSE(aBegin.IsDefinite(), "Indefinite or unresolved begin time in CalcActiveEnd"); - if (mRepeatDur.IsIndefinite()) { - result.SetIndefinite(); - } else { - result = GetRepeatDuration(); - } + result = GetRepeatDuration(); if (aEnd.IsDefinite()) { nsSMILTime activeDur = aEnd.GetMillis() - aBegin.GetMillis(); @@ -1832,29 +1828,25 @@ nsSMILTimedElement::CalcActiveEnd(const nsSMILTimeValue& aBegin, nsSMILTimeValue nsSMILTimedElement::GetRepeatDuration() const { - nsSMILTimeValue result; - - if (mRepeatCount.IsDefinite() && mRepeatDur.IsDefinite()) { - if (mSimpleDur.IsDefinite()) { - nsSMILTime activeDur = - nsSMILTime(mRepeatCount * double(mSimpleDur.GetMillis())); - result.SetMillis(std::min(activeDur, mRepeatDur.GetMillis())); - } else { - result = mRepeatDur; - } - } else if (mRepeatCount.IsDefinite() && mSimpleDur.IsDefinite()) { - nsSMILTime activeDur = - nsSMILTime(mRepeatCount * double(mSimpleDur.GetMillis())); - result.SetMillis(activeDur); - } else if (mRepeatDur.IsDefinite()) { - result = mRepeatDur; - } else if (mRepeatCount.IsIndefinite()) { - result.SetIndefinite(); + nsSMILTimeValue multipliedDuration; + if (mRepeatCount.IsDefinite() && mSimpleDur.IsDefinite()) { + multipliedDuration.SetMillis( + nsSMILTime(mRepeatCount * double(mSimpleDur.GetMillis()))); } else { - result = mSimpleDur; + multipliedDuration.SetIndefinite(); } - return result; + nsSMILTimeValue repeatDuration; + + if (mRepeatDur.IsResolved()) { + repeatDuration = std::min(multipliedDuration, mRepeatDur); + } else if (mRepeatCount.IsSet()) { + repeatDuration = multipliedDuration; + } else { + repeatDuration = mSimpleDur; + } + + return repeatDuration; } nsSMILTimeValue diff --git a/content/smil/test/mochitest.ini b/content/smil/test/mochitest.ini index 75d43a4371d7..f208c0e7a81f 100644 --- a/content/smil/test/mochitest.ini +++ b/content/smil/test/mochitest.ini @@ -38,6 +38,7 @@ support-files = [test_smilMappedAttrFromBy.xhtml] [test_smilMappedAttrFromTo.xhtml] [test_smilMappedAttrPaced.xhtml] +[test_smilRepeatDuration.html] [test_smilRepeatTiming.xhtml] [test_smilReset.xhtml] [test_smilRestart.xhtml] diff --git a/content/smil/test/test_smilRepeatDuration.html b/content/smil/test/test_smilRepeatDuration.html new file mode 100644 index 000000000000..99a95bb7b88e --- /dev/null +++ b/content/smil/test/test_smilRepeatDuration.html @@ -0,0 +1,139 @@ + + + + + + Test for repeat duration calculation (Bug 948245) + + + + +Mozilla Bug 948245 +

+ +
+
+
+ +