Home | History | Annotate | Download | only in animatable
      1 /*
      2  * Copyright (c) 2013, Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "config.h"
     32 
     33 #include "core/animation/animatable/AnimatableValueTestHelper.h"
     34 
     35 namespace blink {
     36 
     37 bool operator==(const AnimatableValue& a, const AnimatableValue& b)
     38 {
     39     return a.equals(b);
     40 }
     41 
     42 void PrintTo(const AnimatableClipPathOperation& animValue, ::std::ostream* os)
     43 {
     44     *os << "AnimatableClipPathOperation@" << &animValue;
     45 }
     46 
     47 void PrintTo(const AnimatableColor& animColor, ::std::ostream* os)
     48 {
     49     *os << "AnimatableColor("
     50         << animColor.color().serialized().utf8().data() << ", "
     51         << animColor.visitedLinkColor().serialized().utf8().data() << ")";
     52 }
     53 
     54 void PrintTo(const AnimatableImage& animImage, ::std::ostream* os)
     55 {
     56     PrintTo(*(animImage.toCSSValue()), os, "AnimatableImage");
     57 }
     58 
     59 void PrintTo(const AnimatableNeutral& animValue, ::std::ostream* os)
     60 {
     61     *os << "AnimatableNeutral@" << &animValue;
     62 }
     63 
     64 void PrintTo(const AnimatableRepeatable& animValue, ::std::ostream* os)
     65 {
     66     *os << "AnimatableRepeatable(";
     67 
     68     const WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > v = animValue.values();
     69     for (WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> >::const_iterator it = v.begin(); it != v.end(); ++it) {
     70         PrintTo(*(it->get()), os);
     71         if (it+1 != v.end())
     72             *os << ", ";
     73     }
     74     *os << ")";
     75 }
     76 
     77 void PrintTo(const AnimatableSVGLength& animSVGLength, ::std::ostream* os)
     78 {
     79     *os << "AnimatableSVGLength("
     80         << animSVGLength.toSVGLength()->valueAsString().utf8().data() << ")";
     81 }
     82 
     83 void PrintTo(const AnimatableShapeValue& animValue, ::std::ostream* os)
     84 {
     85     *os << "AnimatableShapeValue@" << &animValue;
     86 }
     87 
     88 void PrintTo(const AnimatableStrokeDasharrayList& animValue, ::std::ostream* os)
     89 {
     90     *os << "AnimatableStrokeDasharrayList(";
     91     RefPtr<SVGLengthList> list = animValue.toSVGLengthList();
     92     size_t length = list->length();
     93     for (size_t i = 0; i < length; ++i) {
     94         *os << list->at(i)->valueAsString().utf8().data();
     95         if (i != length-1)
     96             *os << ", ";
     97     }
     98     *os << ")";
     99 }
    100 
    101 void PrintTo(const AnimatableTransform& animTransform, ::std::ostream* os)
    102 {
    103     TransformOperations ops = animTransform.transformOperations();
    104 
    105     *os << "AnimatableTransform(";
    106     // FIXME: TransformOperations should really have it's own pretty-printer
    107     // then we could just call that.
    108     // FIXME: Output useful names not just the raw matrixes.
    109     for (unsigned i = 0; i < ops.size(); i++) {
    110         const TransformOperation* op = ops.at(i);
    111 
    112         TransformationMatrix matrix;
    113         op->apply(matrix, FloatSize(1.0, 1.0));
    114 
    115         *os << "[";
    116         if (matrix.isAffine()) {
    117             *os << matrix.a();
    118             *os << " " << matrix.b();
    119             *os << " " << matrix.c();
    120             *os << " " << matrix.d();
    121             *os << " " << matrix.e();
    122             *os << " " << matrix.f();
    123         } else {
    124             *os << matrix.m11();
    125             *os << " " << matrix.m12();
    126             *os << " " << matrix.m13();
    127             *os << " " << matrix.m14();
    128             *os << " ";
    129             *os << " " << matrix.m21();
    130             *os << " " << matrix.m22();
    131             *os << " " << matrix.m23();
    132             *os << " " << matrix.m24();
    133             *os << " ";
    134             *os << " " << matrix.m31();
    135             *os << " " << matrix.m32();
    136             *os << " " << matrix.m33();
    137             *os << " " << matrix.m34();
    138             *os << " ";
    139             *os << " " << matrix.m41();
    140             *os << " " << matrix.m42();
    141             *os << " " << matrix.m43();
    142             *os << " " << matrix.m44();
    143         }
    144         *os << "]";
    145         if (i < ops.size() - 1)
    146             *os << ", ";
    147     }
    148     *os << ")";
    149 }
    150 
    151 void PrintTo(const AnimatableUnknown& animUnknown, ::std::ostream* os)
    152 {
    153     PrintTo(*(animUnknown.toCSSValue().get()), os, "AnimatableUnknown");
    154 }
    155 
    156 void PrintTo(const AnimatableVisibility& animVisibility, ::std::ostream* os)
    157 {
    158     *os << "AnimatableVisibility(";
    159     switch (animVisibility.visibility()) {
    160     case VISIBLE:
    161         *os << "VISIBLE";
    162         break;
    163     case HIDDEN:
    164         *os << "HIDDEN";
    165         break;
    166     case COLLAPSE:
    167         *os << "COLLAPSE";
    168         break;
    169     default:
    170         *os << "Unknown Visbilility - update switch in AnimatableValueTestHelper.h";
    171     }
    172     *os << ")";
    173 }
    174 
    175 void PrintTo(const AnimatableValue& animValue, ::std::ostream* os)
    176 {
    177     if (animValue.isClipPathOperation())
    178         PrintTo(toAnimatableClipPathOperation(animValue), os);
    179     else if (animValue.isColor())
    180         PrintTo(toAnimatableColor(animValue), os);
    181     else if (animValue.isImage())
    182         PrintTo(toAnimatableImage(animValue), os);
    183     else if (animValue.isNeutral())
    184         PrintTo(static_cast<const AnimatableNeutral&>(animValue), os);
    185     else if (animValue.isRepeatable())
    186         PrintTo(toAnimatableRepeatable(animValue), os);
    187     else if (animValue.isSVGLength())
    188         PrintTo(toAnimatableSVGLength(animValue), os);
    189     else if (animValue.isSVGPaint())
    190         PrintTo(toAnimatableSVGPaint(animValue), os);
    191     else if (animValue.isShapeValue())
    192         PrintTo(toAnimatableShapeValue(animValue), os);
    193     else if (animValue.isStrokeDasharrayList())
    194         PrintTo(toAnimatableStrokeDasharrayList(animValue), os);
    195     else if (animValue.isTransform())
    196         PrintTo(toAnimatableTransform(animValue), os);
    197     else if (animValue.isUnknown())
    198         PrintTo(toAnimatableUnknown(animValue), os);
    199     else if (animValue.isVisibility())
    200         PrintTo(toAnimatableVisibility(animValue), os);
    201     else
    202         *os << "Unknown AnimatableValue - update ifelse chain in AnimatableValueTestHelper.h";
    203 }
    204 
    205 } // namespace blink
    206