nsSMILTimeValue
nsSMILTimeValueSpec::ConvertBetweenTimeContainers(
    const nsSMILTimeValue& aSrcTime,
    const nsSMILTimeContainer* aSrcContainer)
{
    // If the source time is either indefinite or unresolved the result is going
    // to be the same
    if (!aSrcTime.IsDefinite())
        return aSrcTime;

    // Convert from source time container to our parent time container
    const nsSMILTimeContainer* dstContainer = mOwner->GetTimeContainer();
    if (dstContainer == aSrcContainer)
        return aSrcTime;

    // If one of the elements is not attached to a time container then we can't do
    // any meaningful conversion
    if (!aSrcContainer || !dstContainer)
        return nsSMILTimeValue(); // unresolved

    nsSMILTimeValue docTime =
        aSrcContainer->ContainerToParentTime(aSrcTime.GetMillis());

    if (docTime.IsIndefinite())
        // This will happen if the source container is paused and we have a future
        // time. Just return the indefinite time.
        return docTime;

    NS_ABORT_IF_FALSE(docTime.IsDefinite(),
                      "ContainerToParentTime gave us an unresolved or indefinite time");

    return dstContainer->ParentToContainerTime(docTime.GetMillis());
}
bool
nsSMILTimeValueSpec::ApplyOffset(nsSMILTimeValue& aTime) const
{
    // indefinite + offset = indefinite. Likewise for unresolved times.
    if (!aTime.IsDefinite()) {
        return true;
    }

    double resultAsDouble =
        (double)aTime.GetMillis() + mParams.mOffset.GetMillis();
    if (resultAsDouble > std::numeric_limits<nsSMILTime>::max() ||
            resultAsDouble < std::numeric_limits<nsSMILTime>::min()) {
        return false;
    }
    aTime.SetMillis(aTime.GetMillis() + mParams.mOffset.GetMillis());
    return true;
}
Ejemplo n.º 3
0
/**
 * @see SMILANIM 3.3.4
 */
nsSMILTimeValue
nsSMILTimedElement::CalcActiveEnd(const nsSMILTimeValue& aBegin,
                                  const nsSMILTimeValue& aEnd)
{
  nsSMILTimeValue result;

  NS_ASSERTION(mSimpleDur.IsResolved() || mSimpleDur.IsIndefinite(),
    "Unresolved simple duration in CalcActiveEnd.");

  if (!aBegin.IsResolved() && !aBegin.IsIndefinite()) {
    NS_ERROR("Unresolved begin time passed to CalcActiveEnd.");
    result.SetIndefinite();
    return result;
  }

  if (mRepeatDur.IsIndefinite() || aBegin.IsIndefinite()) {
    result.SetIndefinite();
  } else {
    result = GetRepeatDuration();
  }

  if (aEnd.IsResolved() && aBegin.IsResolved()) {
    nsSMILTime activeDur = aEnd.GetMillis() - aBegin.GetMillis();

    if (result.IsResolved()) {
      result.SetMillis(PR_MIN(result.GetMillis(), activeDur));
    } else {
      result.SetMillis(activeDur);
    }
  }

  result = ApplyMinAndMax(result);

  if (result.IsResolved()) {
    nsSMILTime activeEnd = result.GetMillis() + aBegin.GetMillis();
    result.SetMillis(activeEnd);
  }

  return result;
}