| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (C) 2014 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 #include "core/workers/TeleportContext.h" |
| 33 |
| 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "platform/TraceEvent.h" |
| 36 #include "wtf/OwnPtr.h" |
| 37 #include "wtf/text/StringBuilder.h" |
| 38 #include "wtf/text/StringHash.h" |
| 39 |
| 40 namespace blink { |
| 41 |
| 42 namespace { |
| 43 |
| 44 static WebTeleportValue::ValueType toValueType(const String& id) |
| 45 { |
| 46 Vector<String> components; |
| 47 id.split(":", components); |
| 48 if (components[1] == "transform") |
| 49 return WebTeleportValue::ValueTypeTransform; |
| 50 if (components[1] == "opacity") |
| 51 return WebTeleportValue::ValueTypeOpacity; |
| 52 if (components[1] == "scrollTop") |
| 53 return WebTeleportValue::ValueTypeScrollTop; |
| 54 if (components[1] == "pendingScrollDelta") |
| 55 return WebTeleportValue::ValueTypePendingScrollDelta; |
| 56 RELEASE_ASSERT_NOT_REACHED(); |
| 57 } |
| 58 |
| 59 } // namespace |
| 60 |
| 61 // TODO |
| 62 TeleportContext::TeleportContext(const Vector<String>& propertyIds) // TODO list
of inputs and outputs |
| 63 : m_timestamp(0.f) |
| 64 { |
| 65 TRACE_EVENT0("teleport", "TeleportContext::TeleportContext"); |
| 66 for (size_t i = 0; i < propertyIds.size(); ++i) { |
| 67 WebTeleportValue::ValueType type = toValueType(propertyIds[i]); |
| 68 if (type == WebTeleportValue::ValueTypeTransform) |
| 69 m_matrices.add(propertyIds[i], MatrixValue(MatrixValue::READ_WRITE))
; |
| 70 else |
| 71 m_scalars.add(propertyIds[i], ScalarValue(ScalarValue::READ_WRITE)); |
| 72 } |
| 73 } |
| 74 |
| 75 PassRefPtrWillBeRawPtr<CSSMatrix> TeleportContext::getMatrix(const String& prope
rtyId, ExceptionState& exceptionState) const |
| 76 { |
| 77 TRACE_EVENT1("teleport", "TeleportContext::getMatrix", "id", propertyId.asci
i()); |
| 78 MatrixValues::const_iterator iter = m_matrices.find(propertyId); |
| 79 if (iter == m_matrices.end() || !iter->value.initialized) { |
| 80 exceptionState.throwTypeError("Invalid property id: " + propertyId + ".
Did not find matrix: " + String::number(iter == m_matrices.end()) + ". Matrix wa
s uninitialized: " + String::number(!iter->value.initialized)); |
| 81 return nullptr; |
| 82 } else if (!iter->value.isReadable()) { |
| 83 exceptionState.throwTypeError("Property is not readable: " + propertyId)
; |
| 84 return nullptr; |
| 85 } |
| 86 return iter->value.value; |
| 87 } |
| 88 |
| 89 void TeleportContext::setMatrix(const String& propertyId, PassRefPtrWillBeRawPtr
<CSSMatrix> value, ExceptionState& exceptionState) |
| 90 { |
| 91 TRACE_EVENT1("teleport", "TeleportContext::setMatrix", "id", propertyId.asci
i()); |
| 92 |
| 93 MatrixValues::const_iterator iter = m_matrices.find(propertyId); |
| 94 if (iter == m_matrices.end()) { |
| 95 exceptionState.throwTypeError("Invalid property id: " + propertyId); |
| 96 return; |
| 97 } else if (!iter->value.isWritable()) { |
| 98 exceptionState.throwTypeError("Property is not writable: " + propertyId)
; |
| 99 return; |
| 100 } |
| 101 |
| 102 MatrixValue matrixValue; |
| 103 matrixValue.initialized = true; |
| 104 matrixValue.modified = true; |
| 105 matrixValue.value = value; |
| 106 matrixValue.mode = iter->value.mode; |
| 107 matrixValue.layer_id = iter->value.layer_id; |
| 108 |
| 109 m_matrices.set(propertyId, matrixValue); |
| 110 } |
| 111 |
| 112 double TeleportContext::getScalar(const String& propertyId, ExceptionState& exce
ptionState) const |
| 113 { |
| 114 TRACE_EVENT1("teleport", "TeleportContext::getScalar", "id", propertyId.asci
i()); |
| 115 ScalarValues::const_iterator iter = m_scalars.find(propertyId); |
| 116 if (iter == m_scalars.end() || !iter->value.initialized) { |
| 117 exceptionState.throwTypeError("Invalid property id: " + propertyId); |
| 118 return 0.0; |
| 119 } else if (!iter->value.isReadable()) { |
| 120 exceptionState.throwTypeError("Property is not readable: " + propertyId)
; |
| 121 return 0.0; |
| 122 } |
| 123 return iter->value.value; |
| 124 } |
| 125 |
| 126 void TeleportContext::setScalar(const String& propertyId, double value, Exceptio
nState& exceptionState) |
| 127 { |
| 128 TRACE_EVENT1("teleport", "TeleportContext::setScalar", "id", propertyId.asci
i()); |
| 129 ScalarValue scalarValue; |
| 130 scalarValue.initialized = true; |
| 131 scalarValue.modified = true; |
| 132 scalarValue.value = value; |
| 133 |
| 134 ScalarValues::const_iterator iter = m_scalars.find(propertyId); |
| 135 if (iter == m_scalars.end()) { |
| 136 exceptionState.throwTypeError("Invalid property id: " + propertyId); |
| 137 return; |
| 138 } else if (!iter->value.isWritable()) { |
| 139 exceptionState.throwTypeError("Property is not writable: " + propertyId)
; |
| 140 return; |
| 141 } |
| 142 |
| 143 scalarValue.layer_id = iter->value.layer_id; |
| 144 |
| 145 m_scalars.set(propertyId, scalarValue); |
| 146 } |
| 147 |
| 148 static String toString(const TransformationMatrix& matrix) |
| 149 { |
| 150 StringBuilder builder; |
| 151 builder.append("matrix("); |
| 152 builder.append(String::number(matrix.m11()) + ", "); |
| 153 builder.append(String::number(matrix.m12()) + ", "); |
| 154 builder.append(String::number(matrix.m13()) + ", "); |
| 155 builder.append(String::number(matrix.m14()) + ", "); |
| 156 builder.append(String::number(matrix.m21()) + ", "); |
| 157 builder.append(String::number(matrix.m22()) + ", "); |
| 158 builder.append(String::number(matrix.m23()) + ", "); |
| 159 builder.append(String::number(matrix.m24()) + ", "); |
| 160 builder.append(String::number(matrix.m31()) + ", "); |
| 161 builder.append(String::number(matrix.m32()) + ", "); |
| 162 builder.append(String::number(matrix.m33()) + ", "); |
| 163 builder.append(String::number(matrix.m34()) + ", "); |
| 164 builder.append(String::number(matrix.m41()) + ", "); |
| 165 builder.append(String::number(matrix.m42()) + ", "); |
| 166 builder.append(String::number(matrix.m43()) + ", "); |
| 167 builder.append(String::number(matrix.m44()) + ")"); |
| 168 return builder.toString(); |
| 169 } |
| 170 |
| 171 PassOwnPtr<WebTeleportValues> TeleportContext::getWebTeleportValues() const |
| 172 { |
| 173 size_t numValues = m_scalars.size() + m_matrices.size(); |
| 174 |
| 175 TRACE_EVENT1("teleport", "TeleportContext::getWebTeleportValues", "count", s
tatic_cast<int>(numValues)); |
| 176 OwnPtr<WebTeleportValues> values(adoptPtr(new WebTeleportValues(numValues)))
; |
| 177 size_t i = 0; |
| 178 for (ScalarValues::const_iterator it = m_scalars.begin(); it != m_scalars.en
d(); ++it) { |
| 179 WebTeleportValue value; |
| 180 value.id = it->key; |
| 181 value.layer_id = it->value.layer_id; |
| 182 value.type = toValueType(it->key); |
| 183 value.value.scalar = it->value.value; |
| 184 value.initialized = it->value.initialized; |
| 185 value.modified = it->value.modified; |
| 186 (*values)[i++] = value; |
| 187 } |
| 188 |
| 189 for (MatrixValues::const_iterator it = m_matrices.begin(); it != m_matrices.
end(); ++it) { |
| 190 WebTeleportValue value; |
| 191 value.id = it->key; |
| 192 value.layer_id = it->value.layer_id; |
| 193 value.type = toValueType(it->key); |
| 194 value.initialized = it->value.initialized && it->value.value; |
| 195 value.modified = it->value.modified; |
| 196 if (value.initialized) { |
| 197 const TransformationMatrix& matrix = it->value.value->transform(); |
| 198 TRACE_EVENT1("teleport", "TeleportContext::getWebTeleportValues getV
alue", "value", toString(matrix).ascii()); |
| 199 value.value.matrix[0] = matrix.m11(); |
| 200 value.value.matrix[1] = matrix.m21(); |
| 201 value.value.matrix[2] = matrix.m31(); |
| 202 value.value.matrix[3] = matrix.m41(); |
| 203 value.value.matrix[4] = matrix.m12(); |
| 204 value.value.matrix[5] = matrix.m22(); |
| 205 value.value.matrix[6] = matrix.m32(); |
| 206 value.value.matrix[7] = matrix.m42(); |
| 207 value.value.matrix[8] = matrix.m13(); |
| 208 value.value.matrix[9] = matrix.m23(); |
| 209 value.value.matrix[10] = matrix.m33(); |
| 210 value.value.matrix[11] = matrix.m43(); |
| 211 value.value.matrix[12] = matrix.m14(); |
| 212 value.value.matrix[13] = matrix.m24(); |
| 213 value.value.matrix[14] = matrix.m34(); |
| 214 value.value.matrix[15] = matrix.m44(); |
| 215 } |
| 216 (*values)[i++] = value; |
| 217 } |
| 218 |
| 219 return values.release(); |
| 220 } |
| 221 |
| 222 void TeleportContext::setWebTeleportValues(const WebTeleportValues& values) |
| 223 { |
| 224 TRACE_EVENT1("teleport", "TeleportContext::setWebTeleportValues", "count", s
tatic_cast<int>(values.size())); |
| 225 for (size_t i = 0; i < values.size(); ++i) { |
| 226 const WebTeleportValue& value = values[i]; |
| 227 switch (value.type) { |
| 228 case WebTeleportValue::ValueTypeTransform: { |
| 229 TransformationMatrix matrix( |
| 230 value.value.matrix[0], |
| 231 value.value.matrix[4], |
| 232 value.value.matrix[8], |
| 233 value.value.matrix[12], |
| 234 value.value.matrix[1], |
| 235 value.value.matrix[5], |
| 236 value.value.matrix[9], |
| 237 value.value.matrix[13], |
| 238 value.value.matrix[2], |
| 239 value.value.matrix[6], |
| 240 value.value.matrix[10], |
| 241 value.value.matrix[14], |
| 242 value.value.matrix[3], |
| 243 value.value.matrix[7], |
| 244 value.value.matrix[11], |
| 245 value.value.matrix[15]); |
| 246 MatrixValue matrixValue; |
| 247 matrixValue.initialized = true; |
| 248 matrixValue.value = CSSMatrix::create(matrix); |
| 249 matrixValue.layer_id = value.layer_id; |
| 250 m_matrices.set(value.id, matrixValue); |
| 251 TRACE_EVENT1("teleport", "TeleportContext::setWebTeleportValues setV
alue", "value", toString(matrix).ascii()); |
| 252 break; |
| 253 } |
| 254 case WebTeleportValue::ValueTypeScrollTop: |
| 255 case WebTeleportValue::ValueTypePendingScrollDelta: |
| 256 case WebTeleportValue::ValueTypeOpacity: { |
| 257 ScalarValue scalarValue; |
| 258 scalarValue.initialized = true; |
| 259 scalarValue.value = value.value.scalar; |
| 260 scalarValue.layer_id = value.layer_id; |
| 261 m_scalars.set(value.id, scalarValue); |
| 262 break; |
| 263 } |
| 264 case WebTeleportValue::ValueTypeTimestamp: { |
| 265 m_timestamp = value.value.scalar; |
| 266 break; |
| 267 } |
| 268 case WebTeleportValue::ValueTypeError: { |
| 269 break; |
| 270 } |
| 271 default: |
| 272 ASSERT_NOT_REACHED(); |
| 273 break; |
| 274 } |
| 275 } |
| 276 } |
| 277 |
| 278 } // namespace blink |
| OLD | NEW |