1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org) 5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIB. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 * 23 */ 24 25 #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_TRANSFORMS_TRANSFORM_OPERATIONS_H_ 26 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TRANSFORMS_TRANSFORM_OPERATIONS_H_ 27 28 #include "base/memory/scoped_refptr.h" 29 #include "third_party/blink/renderer/platform/geometry/layout_size.h" 30 #include "third_party/blink/renderer/platform/transforms/transform_operation.h" 31 #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" 32 #include "third_party/blink/renderer/platform/wtf/vector.h" 33 34 namespace blink { 35 class FloatBox; 36 37 class PLATFORM_EXPORT EmptyTransformOperations final { 38 DISALLOW_NEW(); 39 }; 40 41 class PLATFORM_EXPORT TransformOperations { 42 DISALLOW_NEW(); 43 44 public: 45 TransformOperations() = default; TransformOperations(const EmptyTransformOperations &)46 TransformOperations(const EmptyTransformOperations&) {} 47 48 bool operator==(const TransformOperations& o) const; 49 bool operator!=(const TransformOperations& o) const { return !(*this == o); } 50 51 // Constructs a transformation matrix from the operations. The parameter 52 // |border_box_size| is used when computing styles that are size-dependent. Apply(const FloatSize & border_box_size,TransformationMatrix & t)53 void Apply(const FloatSize& border_box_size, TransformationMatrix& t) const { 54 for (auto& operation : operations_) 55 operation->Apply(t, border_box_size); 56 } 57 58 // Constructs a transformation matrix from the operations starting from index 59 // |start|. This process facilitates mixing pairwise operations for a common 60 // prefix and matrix interpolation for the remainder. The parameter 61 // |border_box_size| is used when computing styles that are size-dependent. 62 void ApplyRemaining(const FloatSize& border_box_size, 63 wtf_size_t start, 64 TransformationMatrix& t) const; 65 66 // Return true if any of the operation types are 3D operation types (even if 67 // the values describe affine transforms) Has3DOperation()68 bool Has3DOperation() const { 69 for (auto& operation : operations_) 70 if (operation->Is3DOperation()) 71 return true; 72 return false; 73 } 74 75 // Return true if any of the operation types are non-perspective 3D operation 76 // types (even if the values describe affine transforms). HasNonPerspective3DOperation()77 bool HasNonPerspective3DOperation() const { 78 for (auto& operation : operations_) { 79 if (operation->Is3DOperation() && 80 operation->GetType() != TransformOperation::kPerspective) 81 return true; 82 } 83 return false; 84 } 85 PreservesAxisAlignment()86 bool PreservesAxisAlignment() const { 87 for (auto& operation : operations_) { 88 if (!operation->PreservesAxisAlignment()) 89 return false; 90 } 91 return true; 92 } 93 94 // Returns true if any operation has a non-trivial component in the Z axis. HasNonTrivial3DComponent()95 bool HasNonTrivial3DComponent() const { 96 for (auto& operation : operations_) { 97 if (operation->HasNonTrivial3DComponent()) 98 return true; 99 } 100 return false; 101 } 102 103 // Returns true if any operation is perspective. HasPerspective()104 bool HasPerspective() const { 105 for (auto& operation : operations_) { 106 if (operation->GetType() == TransformOperation::kPerspective) 107 return true; 108 } 109 return false; 110 } 111 112 TransformOperation::BoxSizeDependency BoxSizeDependencies( 113 wtf_size_t start = 0) const; 114 115 wtf_size_t MatchingPrefixLength(const TransformOperations&) const; 116 clear()117 void clear() { operations_.clear(); } 118 Operations()119 Vector<scoped_refptr<TransformOperation>>& Operations() { 120 return operations_; 121 } Operations()122 const Vector<scoped_refptr<TransformOperation>>& Operations() const { 123 return operations_; 124 } 125 size()126 wtf_size_t size() const { return operations_.size(); } at(wtf_size_t index)127 const TransformOperation* at(wtf_size_t index) const { 128 return index < operations_.size() ? operations_.at(index).get() : nullptr; 129 } 130 131 bool BlendedBoundsForBox(const FloatBox&, 132 const TransformOperations& from, 133 const double& min_progress, 134 const double& max_progress, 135 FloatBox* bounds) const; 136 137 scoped_refptr<TransformOperation> BlendRemainingByUsingMatrixInterpolation( 138 const TransformOperations& from, 139 wtf_size_t matching_prefix_length, 140 double progress) const; 141 142 TransformOperations Blend(const TransformOperations& from, 143 double progress) const; 144 TransformOperations Add(const TransformOperations& addend) const; 145 TransformOperations Zoom(double factor) const; 146 147 // Perform accumulation of |to| onto |this|, as specified in 148 // https://drafts.csswg.org/css-transforms-2/#combining-transform-lists 149 TransformOperations Accumulate(const TransformOperations& to) const; 150 151 private: 152 Vector<scoped_refptr<TransformOperation>> operations_; 153 }; 154 155 } // namespace blink 156 157 #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TRANSFORMS_TRANSFORM_OPERATIONS_H_ 158