Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: third_party/WebKit/Source/platform/geometry/TransformState.cpp

Issue 1777613002: Add localToAbsoluteTransform and localToAncestorTransform. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback about comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 21 matching lines...) Expand all
32 TransformState& TransformState::operator=(const TransformState& other) 32 TransformState& TransformState::operator=(const TransformState& other)
33 { 33 {
34 m_accumulatedOffset = other.m_accumulatedOffset; 34 m_accumulatedOffset = other.m_accumulatedOffset;
35 m_mapPoint = other.m_mapPoint; 35 m_mapPoint = other.m_mapPoint;
36 m_mapQuad = other.m_mapQuad; 36 m_mapQuad = other.m_mapQuad;
37 if (m_mapPoint) 37 if (m_mapPoint)
38 m_lastPlanarPoint = other.m_lastPlanarPoint; 38 m_lastPlanarPoint = other.m_lastPlanarPoint;
39 if (m_mapQuad) 39 if (m_mapQuad)
40 m_lastPlanarQuad = other.m_lastPlanarQuad; 40 m_lastPlanarQuad = other.m_lastPlanarQuad;
41 m_accumulatingTransform = other.m_accumulatingTransform; 41 m_accumulatingTransform = other.m_accumulatingTransform;
42 m_forceAccumulatingTransform = other.m_forceAccumulatingTransform;
42 m_direction = other.m_direction; 43 m_direction = other.m_direction;
43 44
44 m_accumulatedTransform.clear(); 45 m_accumulatedTransform.clear();
45 46
46 if (other.m_accumulatedTransform) 47 if (other.m_accumulatedTransform)
47 m_accumulatedTransform = TransformationMatrix::create(*other.m_accumulat edTransform); 48 m_accumulatedTransform = TransformationMatrix::create(*other.m_accumulat edTransform);
48 49
49 return *this; 50 return *this;
50 } 51 }
51 52
52 void TransformState::translateTransform(const LayoutSize& offset) 53 void TransformState::translateTransform(const LayoutSize& offset)
53 { 54 {
54 if (m_direction == ApplyTransformDirection) 55 if (m_direction == ApplyTransformDirection)
55 m_accumulatedTransform->translateRight(offset.width().toDouble(), offset .height().toDouble()); 56 m_accumulatedTransform->translateRight(offset.width().toDouble(), offset .height().toDouble());
56 else 57 else
57 m_accumulatedTransform->translate(offset.width().toDouble(), offset.heig ht().toDouble()); 58 m_accumulatedTransform->translate(offset.width().toDouble(), offset.heig ht().toDouble());
58 } 59 }
59 60
60 void TransformState::translateMappedCoordinates(const LayoutSize& offset) 61 void TransformState::translateMappedCoordinates(const LayoutSize& offset)
61 { 62 {
62 FloatSize adjustedOffset((m_direction == ApplyTransformDirection) ? offset : -offset); 63 FloatSize adjustedOffset((m_direction == ApplyTransformDirection) ? offset : -offset);
63 if (m_mapPoint) 64 if (m_mapPoint)
64 m_lastPlanarPoint.move(adjustedOffset); 65 m_lastPlanarPoint.move(adjustedOffset);
65 if (m_mapQuad) 66 if (m_mapQuad)
66 m_lastPlanarQuad.move(adjustedOffset); 67 m_lastPlanarQuad.move(adjustedOffset);
67 } 68 }
68 69
69 void TransformState::move(const LayoutSize& offset, TransformAccumulation accumu late) 70 void TransformState::move(const LayoutSize& offset, TransformAccumulation accumu late)
70 { 71 {
72 if (m_forceAccumulatingTransform)
73 accumulate = AccumulateTransform;
74
71 if (accumulate == FlattenTransform || !m_accumulatedTransform) { 75 if (accumulate == FlattenTransform || !m_accumulatedTransform) {
72 m_accumulatedOffset += offset; 76 m_accumulatedOffset += offset;
73 } else { 77 } else {
74 applyAccumulatedOffset(); 78 applyAccumulatedOffset();
75 if (m_accumulatingTransform && m_accumulatedTransform) { 79 if (m_accumulatingTransform && m_accumulatedTransform) {
76 // If we're accumulating into an existing transform, apply the trans lation. 80 // If we're accumulating into an existing transform, apply the trans lation.
77 translateTransform(offset); 81 translateTransform(offset);
78 } else { 82 } else {
79 // Just move the point and/or quad. 83 // Just move the point and/or quad.
80 translateMappedCoordinates(offset); 84 translateMappedCoordinates(offset);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (m_direction == ApplyTransformDirection) 124 if (m_direction == ApplyTransformDirection)
121 m_accumulatedTransform = TransformationMatrix::create(transformFromC ontainer * *m_accumulatedTransform); 125 m_accumulatedTransform = TransformationMatrix::create(transformFromC ontainer * *m_accumulatedTransform);
122 else 126 else
123 m_accumulatedTransform->multiply(transformFromContainer); 127 m_accumulatedTransform->multiply(transformFromContainer);
124 } else if (accumulate == AccumulateTransform) { 128 } else if (accumulate == AccumulateTransform) {
125 // Make one if we started to accumulate 129 // Make one if we started to accumulate
126 m_accumulatedTransform = TransformationMatrix::create(transformFromConta iner); 130 m_accumulatedTransform = TransformationMatrix::create(transformFromConta iner);
127 } 131 }
128 132
129 if (accumulate == FlattenTransform) { 133 if (accumulate == FlattenTransform) {
130 const TransformationMatrix* finalTransform = m_accumulatedTransform ? m_ accumulatedTransform.get() : &transformFromContainer; 134 if (m_forceAccumulatingTransform) {
131 flattenWithTransform(*finalTransform, wasClamped); 135 m_accumulatedTransform->flattenTo2d();
136 } else {
137 const TransformationMatrix* finalTransform = m_accumulatedTransform ? m_accumulatedTransform.get() : &transformFromContainer;
138 flattenWithTransform(*finalTransform, wasClamped);
139 }
132 } 140 }
133 m_accumulatingTransform = accumulate == AccumulateTransform; 141 m_accumulatingTransform = accumulate == AccumulateTransform || m_forceAccumu latingTransform;
134 } 142 }
135 143
136 void TransformState::flatten(bool* wasClamped) 144 void TransformState::flatten(bool* wasClamped)
137 { 145 {
146 ASSERT(!m_forceAccumulatingTransform);
138 if (wasClamped) 147 if (wasClamped)
139 *wasClamped = false; 148 *wasClamped = false;
140 149
141 applyAccumulatedOffset(); 150 applyAccumulatedOffset();
142 151
143 if (!m_accumulatedTransform) { 152 if (!m_accumulatedTransform) {
144 m_accumulatingTransform = false; 153 m_accumulatingTransform = false;
145 return; 154 return;
146 } 155 }
147 156
(...skipping 25 matching lines...) Expand all
173 quad.move(FloatSize((m_direction == ApplyTransformDirection) ? m_accumulated Offset : -m_accumulatedOffset)); 182 quad.move(FloatSize((m_direction == ApplyTransformDirection) ? m_accumulated Offset : -m_accumulatedOffset));
174 if (!m_accumulatedTransform) 183 if (!m_accumulatedTransform)
175 return quad; 184 return quad;
176 185
177 if (m_direction == ApplyTransformDirection) 186 if (m_direction == ApplyTransformDirection)
178 return m_accumulatedTransform->mapQuad(quad); 187 return m_accumulatedTransform->mapQuad(quad);
179 188
180 return m_accumulatedTransform->inverse().projectQuad(quad, wasClamped); 189 return m_accumulatedTransform->inverse().projectQuad(quad, wasClamped);
181 } 190 }
182 191
192 const TransformationMatrix& TransformState::accumulatedTransform() const
193 {
194 ASSERT(m_forceAccumulatingTransform && m_accumulatingTransform);
195 return *m_accumulatedTransform;
196 }
197
183 void TransformState::flattenWithTransform(const TransformationMatrix& t, bool* w asClamped) 198 void TransformState::flattenWithTransform(const TransformationMatrix& t, bool* w asClamped)
184 { 199 {
185 if (m_direction == ApplyTransformDirection) { 200 if (m_direction == ApplyTransformDirection) {
186 if (m_mapPoint) 201 if (m_mapPoint)
187 m_lastPlanarPoint = t.mapPoint(m_lastPlanarPoint); 202 m_lastPlanarPoint = t.mapPoint(m_lastPlanarPoint);
188 if (m_mapQuad) 203 if (m_mapQuad)
189 m_lastPlanarQuad = t.mapQuad(m_lastPlanarQuad); 204 m_lastPlanarQuad = t.mapQuad(m_lastPlanarQuad);
190 } else { 205 } else {
191 TransformationMatrix inverseTransform = t.inverse(); 206 TransformationMatrix inverseTransform = t.inverse();
192 if (m_mapPoint) 207 if (m_mapPoint)
193 m_lastPlanarPoint = inverseTransform.projectPoint(m_lastPlanarPoint) ; 208 m_lastPlanarPoint = inverseTransform.projectPoint(m_lastPlanarPoint) ;
194 if (m_mapQuad) 209 if (m_mapQuad)
195 m_lastPlanarQuad = inverseTransform.projectQuad(m_lastPlanarQuad, wa sClamped); 210 m_lastPlanarQuad = inverseTransform.projectQuad(m_lastPlanarQuad, wa sClamped);
196 } 211 }
197 212
198 // We could throw away m_accumulatedTransform if we wanted to here, but that 213 // We could throw away m_accumulatedTransform if we wanted to here, but that
199 // would cause thrash when traversing hierarchies with alternating 214 // would cause thrash when traversing hierarchies with alternating
200 // preserve-3d and flat elements. 215 // preserve-3d and flat elements.
201 if (m_accumulatedTransform) 216 if (m_accumulatedTransform)
202 m_accumulatedTransform->makeIdentity(); 217 m_accumulatedTransform->makeIdentity();
203 m_accumulatingTransform = false; 218 m_accumulatingTransform = false;
204 } 219 }
205 220
206 } // namespace blink 221 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698