| 1 | /* |
| 2 | * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 3 | * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | #include "MatrixTransformOperation.h" |
| 24 | |
| 25 | #include <algorithm> |
| 26 | #include <wtf/text/TextStream.h> |
| 27 | |
| 28 | namespace WebCore { |
| 29 | |
| 30 | bool MatrixTransformOperation::operator==(const TransformOperation& other) const |
| 31 | { |
| 32 | if (!isSameType(other)) |
| 33 | return false; |
| 34 | const MatrixTransformOperation& m = downcast<MatrixTransformOperation>(other); |
| 35 | return m_a == m.m_a && m_b == m.m_b && m_c == m.m_c && m_d == m.m_d && m_e == m.m_e && m_f == m.m_f; |
| 36 | } |
| 37 | |
| 38 | Ref<TransformOperation> MatrixTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity) |
| 39 | { |
| 40 | auto createOperation = [] (TransformationMatrix& to, TransformationMatrix& from, double progress) { |
| 41 | to.blend(from, progress); |
| 42 | return MatrixTransformOperation::create(to); |
| 43 | }; |
| 44 | |
| 45 | if (from && !from->isSameType(*this)) |
| 46 | return *this; |
| 47 | |
| 48 | // convert the TransformOperations into matrices |
| 49 | TransformationMatrix fromT; |
| 50 | TransformationMatrix toT(m_a, m_b, m_c, m_d, m_e, m_f); |
| 51 | if (from) { |
| 52 | const MatrixTransformOperation& m = downcast<MatrixTransformOperation>(*from); |
| 53 | fromT.setMatrix(m.m_a, m.m_b, m.m_c, m.m_d, m.m_e, m.m_f); |
| 54 | } |
| 55 | |
| 56 | if (blendToIdentity) |
| 57 | return createOperation(fromT, toT, progress); |
| 58 | return createOperation(toT, fromT, progress); |
| 59 | } |
| 60 | |
| 61 | void MatrixTransformOperation::dump(TextStream& ts) const |
| 62 | { |
| 63 | ts << "(" |
| 64 | << TextStream::FormatNumberRespectingIntegers(m_a) << ", " |
| 65 | << TextStream::FormatNumberRespectingIntegers(m_b) << ", " |
| 66 | << TextStream::FormatNumberRespectingIntegers(m_c) << ", " |
| 67 | << TextStream::FormatNumberRespectingIntegers(m_d) << ", " |
| 68 | << TextStream::FormatNumberRespectingIntegers(m_e) << ", " |
| 69 | << TextStream::FormatNumberRespectingIntegers(m_f) << ")" ; |
| 70 | } |
| 71 | |
| 72 | } // namespace WebCore |
| 73 | |