| Index: Source/core/workers/TeleportContext.cpp
|
| diff --git a/Source/core/workers/TeleportContext.cpp b/Source/core/workers/TeleportContext.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2aac6824b1ae1144faf6a1e176c14dadf932d4f1
|
| --- /dev/null
|
| +++ b/Source/core/workers/TeleportContext.cpp
|
| @@ -0,0 +1,278 @@
|
| +/*
|
| + * Copyright (C) 2014 Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#include "config.h"
|
| +#include "core/workers/TeleportContext.h"
|
| +
|
| +#include "bindings/core/v8/ExceptionState.h"
|
| +#include "platform/TraceEvent.h"
|
| +#include "wtf/OwnPtr.h"
|
| +#include "wtf/text/StringBuilder.h"
|
| +#include "wtf/text/StringHash.h"
|
| +
|
| +namespace blink {
|
| +
|
| +namespace {
|
| +
|
| +static WebTeleportValue::ValueType toValueType(const String& id)
|
| +{
|
| + Vector<String> components;
|
| + id.split(":", components);
|
| + if (components[1] == "transform")
|
| + return WebTeleportValue::ValueTypeTransform;
|
| + if (components[1] == "opacity")
|
| + return WebTeleportValue::ValueTypeOpacity;
|
| + if (components[1] == "scrollTop")
|
| + return WebTeleportValue::ValueTypeScrollTop;
|
| + if (components[1] == "pendingScrollDelta")
|
| + return WebTeleportValue::ValueTypePendingScrollDelta;
|
| + RELEASE_ASSERT_NOT_REACHED();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// TODO
|
| +TeleportContext::TeleportContext(const Vector<String>& propertyIds) // TODO list of inputs and outputs
|
| + : m_timestamp(0.f)
|
| +{
|
| + TRACE_EVENT0("teleport", "TeleportContext::TeleportContext");
|
| + for (size_t i = 0; i < propertyIds.size(); ++i) {
|
| + WebTeleportValue::ValueType type = toValueType(propertyIds[i]);
|
| + if (type == WebTeleportValue::ValueTypeTransform)
|
| + m_matrices.add(propertyIds[i], MatrixValue(MatrixValue::READ_WRITE));
|
| + else
|
| + m_scalars.add(propertyIds[i], ScalarValue(ScalarValue::READ_WRITE));
|
| + }
|
| +}
|
| +
|
| +PassRefPtrWillBeRawPtr<CSSMatrix> TeleportContext::getMatrix(const String& propertyId, ExceptionState& exceptionState) const
|
| +{
|
| + TRACE_EVENT1("teleport", "TeleportContext::getMatrix", "id", propertyId.ascii());
|
| + MatrixValues::const_iterator iter = m_matrices.find(propertyId);
|
| + if (iter == m_matrices.end() || !iter->value.initialized) {
|
| + exceptionState.throwTypeError("Invalid property id: " + propertyId + ". Did not find matrix: " + String::number(iter == m_matrices.end()) + ". Matrix was uninitialized: " + String::number(!iter->value.initialized));
|
| + return nullptr;
|
| + } else if (!iter->value.isReadable()) {
|
| + exceptionState.throwTypeError("Property is not readable: " + propertyId);
|
| + return nullptr;
|
| + }
|
| + return iter->value.value;
|
| +}
|
| +
|
| +void TeleportContext::setMatrix(const String& propertyId, PassRefPtrWillBeRawPtr<CSSMatrix> value, ExceptionState& exceptionState)
|
| +{
|
| + TRACE_EVENT1("teleport", "TeleportContext::setMatrix", "id", propertyId.ascii());
|
| +
|
| + MatrixValues::const_iterator iter = m_matrices.find(propertyId);
|
| + if (iter == m_matrices.end()) {
|
| + exceptionState.throwTypeError("Invalid property id: " + propertyId);
|
| + return;
|
| + } else if (!iter->value.isWritable()) {
|
| + exceptionState.throwTypeError("Property is not writable: " + propertyId);
|
| + return;
|
| + }
|
| +
|
| + MatrixValue matrixValue;
|
| + matrixValue.initialized = true;
|
| + matrixValue.modified = true;
|
| + matrixValue.value = value;
|
| + matrixValue.mode = iter->value.mode;
|
| + matrixValue.layer_id = iter->value.layer_id;
|
| +
|
| + m_matrices.set(propertyId, matrixValue);
|
| +}
|
| +
|
| +double TeleportContext::getScalar(const String& propertyId, ExceptionState& exceptionState) const
|
| +{
|
| + TRACE_EVENT1("teleport", "TeleportContext::getScalar", "id", propertyId.ascii());
|
| + ScalarValues::const_iterator iter = m_scalars.find(propertyId);
|
| + if (iter == m_scalars.end() || !iter->value.initialized) {
|
| + exceptionState.throwTypeError("Invalid property id: " + propertyId);
|
| + return 0.0;
|
| + } else if (!iter->value.isReadable()) {
|
| + exceptionState.throwTypeError("Property is not readable: " + propertyId);
|
| + return 0.0;
|
| + }
|
| + return iter->value.value;
|
| +}
|
| +
|
| +void TeleportContext::setScalar(const String& propertyId, double value, ExceptionState& exceptionState)
|
| +{
|
| + TRACE_EVENT1("teleport", "TeleportContext::setScalar", "id", propertyId.ascii());
|
| + ScalarValue scalarValue;
|
| + scalarValue.initialized = true;
|
| + scalarValue.modified = true;
|
| + scalarValue.value = value;
|
| +
|
| + ScalarValues::const_iterator iter = m_scalars.find(propertyId);
|
| + if (iter == m_scalars.end()) {
|
| + exceptionState.throwTypeError("Invalid property id: " + propertyId);
|
| + return;
|
| + } else if (!iter->value.isWritable()) {
|
| + exceptionState.throwTypeError("Property is not writable: " + propertyId);
|
| + return;
|
| + }
|
| +
|
| + scalarValue.layer_id = iter->value.layer_id;
|
| +
|
| + m_scalars.set(propertyId, scalarValue);
|
| +}
|
| +
|
| +static String toString(const TransformationMatrix& matrix)
|
| +{
|
| + StringBuilder builder;
|
| + builder.append("matrix(");
|
| + builder.append(String::number(matrix.m11()) + ", ");
|
| + builder.append(String::number(matrix.m12()) + ", ");
|
| + builder.append(String::number(matrix.m13()) + ", ");
|
| + builder.append(String::number(matrix.m14()) + ", ");
|
| + builder.append(String::number(matrix.m21()) + ", ");
|
| + builder.append(String::number(matrix.m22()) + ", ");
|
| + builder.append(String::number(matrix.m23()) + ", ");
|
| + builder.append(String::number(matrix.m24()) + ", ");
|
| + builder.append(String::number(matrix.m31()) + ", ");
|
| + builder.append(String::number(matrix.m32()) + ", ");
|
| + builder.append(String::number(matrix.m33()) + ", ");
|
| + builder.append(String::number(matrix.m34()) + ", ");
|
| + builder.append(String::number(matrix.m41()) + ", ");
|
| + builder.append(String::number(matrix.m42()) + ", ");
|
| + builder.append(String::number(matrix.m43()) + ", ");
|
| + builder.append(String::number(matrix.m44()) + ")");
|
| + return builder.toString();
|
| +}
|
| +
|
| +PassOwnPtr<WebTeleportValues> TeleportContext::getWebTeleportValues() const
|
| +{
|
| + size_t numValues = m_scalars.size() + m_matrices.size();
|
| +
|
| + TRACE_EVENT1("teleport", "TeleportContext::getWebTeleportValues", "count", static_cast<int>(numValues));
|
| + OwnPtr<WebTeleportValues> values(adoptPtr(new WebTeleportValues(numValues)));
|
| + size_t i = 0;
|
| + for (ScalarValues::const_iterator it = m_scalars.begin(); it != m_scalars.end(); ++it) {
|
| + WebTeleportValue value;
|
| + value.id = it->key;
|
| + value.layer_id = it->value.layer_id;
|
| + value.type = toValueType(it->key);
|
| + value.value.scalar = it->value.value;
|
| + value.initialized = it->value.initialized;
|
| + value.modified = it->value.modified;
|
| + (*values)[i++] = value;
|
| + }
|
| +
|
| + for (MatrixValues::const_iterator it = m_matrices.begin(); it != m_matrices.end(); ++it) {
|
| + WebTeleportValue value;
|
| + value.id = it->key;
|
| + value.layer_id = it->value.layer_id;
|
| + value.type = toValueType(it->key);
|
| + value.initialized = it->value.initialized && it->value.value;
|
| + value.modified = it->value.modified;
|
| + if (value.initialized) {
|
| + const TransformationMatrix& matrix = it->value.value->transform();
|
| + TRACE_EVENT1("teleport", "TeleportContext::getWebTeleportValues getValue", "value", toString(matrix).ascii());
|
| + value.value.matrix[0] = matrix.m11();
|
| + value.value.matrix[1] = matrix.m21();
|
| + value.value.matrix[2] = matrix.m31();
|
| + value.value.matrix[3] = matrix.m41();
|
| + value.value.matrix[4] = matrix.m12();
|
| + value.value.matrix[5] = matrix.m22();
|
| + value.value.matrix[6] = matrix.m32();
|
| + value.value.matrix[7] = matrix.m42();
|
| + value.value.matrix[8] = matrix.m13();
|
| + value.value.matrix[9] = matrix.m23();
|
| + value.value.matrix[10] = matrix.m33();
|
| + value.value.matrix[11] = matrix.m43();
|
| + value.value.matrix[12] = matrix.m14();
|
| + value.value.matrix[13] = matrix.m24();
|
| + value.value.matrix[14] = matrix.m34();
|
| + value.value.matrix[15] = matrix.m44();
|
| + }
|
| + (*values)[i++] = value;
|
| + }
|
| +
|
| + return values.release();
|
| +}
|
| +
|
| +void TeleportContext::setWebTeleportValues(const WebTeleportValues& values)
|
| +{
|
| + TRACE_EVENT1("teleport", "TeleportContext::setWebTeleportValues", "count", static_cast<int>(values.size()));
|
| + for (size_t i = 0; i < values.size(); ++i) {
|
| + const WebTeleportValue& value = values[i];
|
| + switch (value.type) {
|
| + case WebTeleportValue::ValueTypeTransform: {
|
| + TransformationMatrix matrix(
|
| + value.value.matrix[0],
|
| + value.value.matrix[4],
|
| + value.value.matrix[8],
|
| + value.value.matrix[12],
|
| + value.value.matrix[1],
|
| + value.value.matrix[5],
|
| + value.value.matrix[9],
|
| + value.value.matrix[13],
|
| + value.value.matrix[2],
|
| + value.value.matrix[6],
|
| + value.value.matrix[10],
|
| + value.value.matrix[14],
|
| + value.value.matrix[3],
|
| + value.value.matrix[7],
|
| + value.value.matrix[11],
|
| + value.value.matrix[15]);
|
| + MatrixValue matrixValue;
|
| + matrixValue.initialized = true;
|
| + matrixValue.value = CSSMatrix::create(matrix);
|
| + matrixValue.layer_id = value.layer_id;
|
| + m_matrices.set(value.id, matrixValue);
|
| + TRACE_EVENT1("teleport", "TeleportContext::setWebTeleportValues setValue", "value", toString(matrix).ascii());
|
| + break;
|
| + }
|
| + case WebTeleportValue::ValueTypeScrollTop:
|
| + case WebTeleportValue::ValueTypePendingScrollDelta:
|
| + case WebTeleportValue::ValueTypeOpacity: {
|
| + ScalarValue scalarValue;
|
| + scalarValue.initialized = true;
|
| + scalarValue.value = value.value.scalar;
|
| + scalarValue.layer_id = value.layer_id;
|
| + m_scalars.set(value.id, scalarValue);
|
| + break;
|
| + }
|
| + case WebTeleportValue::ValueTypeTimestamp: {
|
| + m_timestamp = value.value.scalar;
|
| + break;
|
| + }
|
| + case WebTeleportValue::ValueTypeError: {
|
| + break;
|
| + }
|
| + default:
|
| + ASSERT_NOT_REACHED();
|
| + break;
|
| + }
|
| + }
|
| +}
|
| +
|
| +} // namespace blink
|
|
|