dom/smil/SMILStringType.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/SMILStringType.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "SMILStringType.h"
    1.10 +#include "nsSMILValue.h"
    1.11 +#include "nsDebug.h"
    1.12 +#include "nsString.h"
    1.13 +
    1.14 +namespace mozilla {
    1.15 +
    1.16 +void
    1.17 +SMILStringType::Init(nsSMILValue& aValue) const
    1.18 +{
    1.19 +  NS_PRECONDITION(aValue.IsNull(), "Unexpected value type");
    1.20 +  aValue.mU.mPtr = new nsString();
    1.21 +  aValue.mType = this;
    1.22 +}
    1.23 +
    1.24 +void
    1.25 +SMILStringType::Destroy(nsSMILValue& aValue) const
    1.26 +{
    1.27 +  NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value");
    1.28 +  delete static_cast<nsAString*>(aValue.mU.mPtr);
    1.29 +  aValue.mU.mPtr = nullptr;
    1.30 +  aValue.mType = nsSMILNullType::Singleton();
    1.31 +}
    1.32 +
    1.33 +nsresult
    1.34 +SMILStringType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const
    1.35 +{
    1.36 +  NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types");
    1.37 +  NS_PRECONDITION(aDest.mType == this, "Unexpected SMIL value");
    1.38 +
    1.39 +  const nsAString* src = static_cast<const nsAString*>(aSrc.mU.mPtr);
    1.40 +  nsAString* dst = static_cast<nsAString*>(aDest.mU.mPtr);
    1.41 +  *dst = *src;
    1.42 +  return NS_OK;
    1.43 +}
    1.44 +
    1.45 +bool
    1.46 +SMILStringType::IsEqual(const nsSMILValue& aLeft,
    1.47 +                        const nsSMILValue& aRight) const
    1.48 +{
    1.49 +  NS_PRECONDITION(aLeft.mType == aRight.mType, "Incompatible SMIL types");
    1.50 +  NS_PRECONDITION(aLeft.mType == this, "Unexpected type for SMIL value");
    1.51 +
    1.52 +  const nsAString* leftString =
    1.53 +    static_cast<const nsAString*>(aLeft.mU.mPtr);
    1.54 +  const nsAString* rightString =
    1.55 +    static_cast<nsAString*>(aRight.mU.mPtr);
    1.56 +  return *leftString == *rightString;
    1.57 +}
    1.58 +
    1.59 +nsresult
    1.60 +SMILStringType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
    1.61 +                    uint32_t aCount) const
    1.62 +{
    1.63 +  NS_PRECONDITION(aValueToAdd.mType == aDest.mType,
    1.64 +                  "Trying to add invalid types");
    1.65 +  NS_PRECONDITION(aValueToAdd.mType == this, "Unexpected source type");
    1.66 +  return NS_ERROR_FAILURE; // string values can't be added to each other
    1.67 +}
    1.68 +
    1.69 +nsresult
    1.70 +SMILStringType::ComputeDistance(const nsSMILValue& aFrom,
    1.71 +                                const nsSMILValue& aTo,
    1.72 +                                double& aDistance) const
    1.73 +{
    1.74 +  NS_PRECONDITION(aFrom.mType == aTo.mType,"Trying to compare different types");
    1.75 +  NS_PRECONDITION(aFrom.mType == this, "Unexpected source type");
    1.76 +  return NS_ERROR_FAILURE; // there is no concept of distance between string values
    1.77 +}
    1.78 +
    1.79 +nsresult
    1.80 +SMILStringType::Interpolate(const nsSMILValue& aStartVal,
    1.81 +                            const nsSMILValue& aEndVal,
    1.82 +                            double aUnitDistance,
    1.83 +                            nsSMILValue& aResult) const
    1.84 +{
    1.85 +  NS_PRECONDITION(aStartVal.mType == aEndVal.mType,
    1.86 +      "Trying to interpolate different types");
    1.87 +  NS_PRECONDITION(aStartVal.mType == this,
    1.88 +      "Unexpected types for interpolation");
    1.89 +  NS_PRECONDITION(aResult.mType   == this, "Unexpected result type");
    1.90 +  return NS_ERROR_FAILURE; // string values do not interpolate
    1.91 +}
    1.92 +
    1.93 +} // namespace mozilla

mercurial