2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebCoreArgumentCoders.h"
29 #include "ShareableBitmap.h"
30 #include <WebCore/AuthenticationChallenge.h>
31 #include <WebCore/Credential.h>
32 #include <WebCore/Cursor.h>
33 #include <WebCore/DatabaseDetails.h>
34 #include <WebCore/Editor.h>
35 #include <WebCore/GraphicsContext.h>
36 #include <WebCore/Image.h>
37 #include <WebCore/PluginData.h>
38 #include <WebCore/ProtectionSpace.h>
39 #include <WebCore/TextCheckerClient.h>
40 #include <WebCore/ViewportArguments.h>
41 #include <WebCore/WindowFeatures.h>
42 #include <wtf/text/StringHash.h>
45 #include <WebCore/Animation.h>
46 #include <WebCore/FloatPoint3D.h>
47 #include <WebCore/IdentityTransformOperation.h>
48 #include <WebCore/Matrix3DTransformOperation.h>
49 #include <WebCore/MatrixTransformOperation.h>
50 #include <WebCore/PerspectiveTransformOperation.h>
51 #include <WebCore/RotateTransformOperation.h>
52 #include <WebCore/ScaleTransformOperation.h>
53 #include <WebCore/SkewTransformOperation.h>
54 #include <WebCore/TimingFunction.h>
55 #include <WebCore/TransformOperation.h>
56 #include <WebCore/TransformOperations.h>
57 #include <WebCore/TranslateTransformOperation.h>
60 using namespace WebCore;
61 using namespace WebKit;
65 void ArgumentCoder<FloatPoint>::encode(ArgumentEncoder* encoder, const FloatPoint& floatPoint)
67 SimpleArgumentCoder<FloatPoint>::encode(encoder, floatPoint);
70 bool ArgumentCoder<FloatPoint>::decode(ArgumentDecoder* decoder, FloatPoint& floatPoint)
72 return SimpleArgumentCoder<FloatPoint>::decode(decoder, floatPoint);
76 void ArgumentCoder<FloatRect>::encode(ArgumentEncoder* encoder, const FloatRect& floatRect)
78 SimpleArgumentCoder<FloatRect>::encode(encoder, floatRect);
81 bool ArgumentCoder<FloatRect>::decode(ArgumentDecoder* decoder, FloatRect& floatRect)
83 return SimpleArgumentCoder<FloatRect>::decode(decoder, floatRect);
87 void ArgumentCoder<FloatSize>::encode(ArgumentEncoder* encoder, const FloatSize& floatSize)
89 SimpleArgumentCoder<FloatSize>::encode(encoder, floatSize);
92 bool ArgumentCoder<FloatSize>::decode(ArgumentDecoder* decoder, FloatSize& floatSize)
94 return SimpleArgumentCoder<FloatSize>::decode(decoder, floatSize);
98 void ArgumentCoder<IntPoint>::encode(ArgumentEncoder* encoder, const IntPoint& intPoint)
100 SimpleArgumentCoder<IntPoint>::encode(encoder, intPoint);
103 bool ArgumentCoder<IntPoint>::decode(ArgumentDecoder* decoder, IntPoint& intPoint)
105 return SimpleArgumentCoder<IntPoint>::decode(decoder, intPoint);
109 void ArgumentCoder<IntRect>::encode(ArgumentEncoder* encoder, const IntRect& intRect)
111 SimpleArgumentCoder<IntRect>::encode(encoder, intRect);
114 bool ArgumentCoder<IntRect>::decode(ArgumentDecoder* decoder, IntRect& intRect)
116 return SimpleArgumentCoder<IntRect>::decode(decoder, intRect);
120 void ArgumentCoder<IntSize>::encode(ArgumentEncoder* encoder, const IntSize& intSize)
122 SimpleArgumentCoder<IntSize>::encode(encoder, intSize);
125 bool ArgumentCoder<IntSize>::decode(ArgumentDecoder* decoder, IntSize& intSize)
127 return SimpleArgumentCoder<IntSize>::decode(decoder, intSize);
131 void ArgumentCoder<ViewportArguments>::encode(ArgumentEncoder* encoder, const ViewportArguments& viewportArguments)
133 SimpleArgumentCoder<ViewportArguments>::encode(encoder, viewportArguments);
136 bool ArgumentCoder<ViewportArguments>::decode(ArgumentDecoder* decoder, ViewportArguments& viewportArguments)
138 return SimpleArgumentCoder<ViewportArguments>::decode(decoder, viewportArguments);
141 void ArgumentCoder<MimeClassInfo>::encode(ArgumentEncoder* encoder, const MimeClassInfo& mimeClassInfo)
143 encoder->encode(mimeClassInfo.type);
144 encoder->encode(mimeClassInfo.desc);
145 encoder->encode(mimeClassInfo.extensions);
148 bool ArgumentCoder<MimeClassInfo>::decode(ArgumentDecoder* decoder, MimeClassInfo& mimeClassInfo)
150 if (!decoder->decode(mimeClassInfo.type))
152 if (!decoder->decode(mimeClassInfo.desc))
154 if (!decoder->decode(mimeClassInfo.extensions))
161 void ArgumentCoder<PluginInfo>::encode(ArgumentEncoder* encoder, const PluginInfo& pluginInfo)
163 encoder->encode(pluginInfo.name);
164 encoder->encode(pluginInfo.file);
165 encoder->encode(pluginInfo.desc);
166 encoder->encode(pluginInfo.mimes);
169 bool ArgumentCoder<PluginInfo>::decode(ArgumentDecoder* decoder, PluginInfo& pluginInfo)
171 if (!decoder->decode(pluginInfo.name))
173 if (!decoder->decode(pluginInfo.file))
175 if (!decoder->decode(pluginInfo.desc))
177 if (!decoder->decode(pluginInfo.mimes))
184 void ArgumentCoder<HTTPHeaderMap>::encode(ArgumentEncoder* encoder, const HTTPHeaderMap& headerMap)
186 encoder->encode(static_cast<const HashMap<AtomicString, String, CaseFoldingHash>&>(headerMap));
189 bool ArgumentCoder<HTTPHeaderMap>::decode(ArgumentDecoder* decoder, HTTPHeaderMap& headerMap)
191 return decoder->decode(static_cast<HashMap<AtomicString, String, CaseFoldingHash>&>(headerMap));
195 void ArgumentCoder<AuthenticationChallenge>::encode(ArgumentEncoder* encoder, const AuthenticationChallenge& challenge)
197 encoder->encode(challenge.protectionSpace());
198 encoder->encode(challenge.proposedCredential());
199 encoder->encode(challenge.previousFailureCount());
200 encoder->encode(challenge.failureResponse());
201 encoder->encode(challenge.error());
204 bool ArgumentCoder<AuthenticationChallenge>::decode(ArgumentDecoder* decoder, AuthenticationChallenge& challenge)
206 ProtectionSpace protectionSpace;
207 if (!decoder->decode(protectionSpace))
210 Credential proposedCredential;
211 if (!decoder->decode(proposedCredential))
214 unsigned previousFailureCount;
215 if (!decoder->decode(previousFailureCount))
218 ResourceResponse failureResponse;
219 if (!decoder->decode(failureResponse))
223 if (!decoder->decode(error))
226 challenge = AuthenticationChallenge(protectionSpace, proposedCredential, previousFailureCount, failureResponse, error);
231 void ArgumentCoder<ProtectionSpace>::encode(ArgumentEncoder* encoder, const ProtectionSpace& space)
233 encoder->encode(space.host());
234 encoder->encode(space.port());
235 encoder->encodeEnum(space.serverType());
236 encoder->encode(space.realm());
237 encoder->encodeEnum(space.authenticationScheme());
240 bool ArgumentCoder<ProtectionSpace>::decode(ArgumentDecoder* decoder, ProtectionSpace& space)
243 if (!decoder->decode(host))
247 if (!decoder->decode(port))
250 ProtectionSpaceServerType serverType;
251 if (!decoder->decodeEnum(serverType))
255 if (!decoder->decode(realm))
258 ProtectionSpaceAuthenticationScheme authenticationScheme;
259 if (!decoder->decodeEnum(authenticationScheme))
262 space = ProtectionSpace(host, port, serverType, realm, authenticationScheme);
266 void ArgumentCoder<Credential>::encode(ArgumentEncoder* encoder, const Credential& credential)
268 encoder->encode(credential.user());
269 encoder->encode(credential.password());
270 encoder->encodeEnum(credential.persistence());
273 bool ArgumentCoder<Credential>::decode(ArgumentDecoder* decoder, Credential& credential)
276 if (!decoder->decode(user))
280 if (!decoder->decode(password))
283 CredentialPersistence persistence;
284 if (!decoder->decodeEnum(persistence))
287 credential = Credential(user, password, persistence);
291 static void encodeImage(ArgumentEncoder* encoder, Image* image)
293 RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(image->size(), ShareableBitmap::SupportsAlpha);
294 bitmap->createGraphicsContext()->drawImage(image, ColorSpaceDeviceRGB, IntPoint());
296 ShareableBitmap::Handle handle;
297 bitmap->createHandle(handle);
299 encoder->encode(handle);
302 static bool decodeImage(ArgumentDecoder* decoder, RefPtr<Image>& image)
304 ShareableBitmap::Handle handle;
305 if (!decoder->decode(handle))
308 RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
311 image = bitmap->createImage();
317 void ArgumentCoder<Cursor>::encode(ArgumentEncoder* encoder, const Cursor& cursor)
319 encoder->encodeEnum(cursor.type());
321 if (cursor.type() != Cursor::Custom)
324 if (cursor.image()->isNull()) {
325 encoder->encodeBool(false); // There is no valid image being encoded.
329 encoder->encodeBool(true);
330 encodeImage(encoder, cursor.image());
331 encoder->encode(cursor.hotSpot());
334 bool ArgumentCoder<Cursor>::decode(ArgumentDecoder* decoder, Cursor& cursor)
337 if (!decoder->decodeEnum(type))
340 if (type > Cursor::Custom)
343 if (type != Cursor::Custom) {
344 const Cursor& cursorReference = Cursor::fromType(type);
345 // Calling platformCursor here will eagerly create the platform cursor for the cursor singletons inside WebCore.
346 // This will avoid having to re-create the platform cursors over and over.
347 (void)cursorReference.platformCursor();
349 cursor = cursorReference;
353 bool isValidImagePresent;
354 if (!decoder->decode(isValidImagePresent))
357 if (!isValidImagePresent) {
358 cursor = Cursor(Image::nullImage(), IntPoint());
363 if (!decodeImage(decoder, image))
367 if (!decoder->decode(hotSpot))
370 if (!image->rect().contains(hotSpot))
373 cursor = Cursor(image.get(), hotSpot);
378 void ArgumentCoder<WindowFeatures>::encode(ArgumentEncoder* encoder, const WindowFeatures& windowFeatures)
380 encoder->encode(windowFeatures.x);
381 encoder->encode(windowFeatures.y);
382 encoder->encode(windowFeatures.width);
383 encoder->encode(windowFeatures.height);
384 encoder->encode(windowFeatures.xSet);
385 encoder->encode(windowFeatures.ySet);
386 encoder->encode(windowFeatures.widthSet);
387 encoder->encode(windowFeatures.heightSet);
388 encoder->encode(windowFeatures.menuBarVisible);
389 encoder->encode(windowFeatures.statusBarVisible);
390 encoder->encode(windowFeatures.toolBarVisible);
391 encoder->encode(windowFeatures.locationBarVisible);
392 encoder->encode(windowFeatures.scrollbarsVisible);
393 encoder->encode(windowFeatures.resizable);
394 encoder->encode(windowFeatures.fullscreen);
395 encoder->encode(windowFeatures.dialog);
398 bool ArgumentCoder<WindowFeatures>::decode(ArgumentDecoder* decoder, WindowFeatures& windowFeatures)
400 if (!decoder->decode(windowFeatures.x))
402 if (!decoder->decode(windowFeatures.y))
404 if (!decoder->decode(windowFeatures.width))
406 if (!decoder->decode(windowFeatures.height))
408 if (!decoder->decode(windowFeatures.xSet))
410 if (!decoder->decode(windowFeatures.ySet))
412 if (!decoder->decode(windowFeatures.widthSet))
414 if (!decoder->decode(windowFeatures.heightSet))
416 if (!decoder->decode(windowFeatures.menuBarVisible))
418 if (!decoder->decode(windowFeatures.statusBarVisible))
420 if (!decoder->decode(windowFeatures.toolBarVisible))
422 if (!decoder->decode(windowFeatures.locationBarVisible))
424 if (!decoder->decode(windowFeatures.scrollbarsVisible))
426 if (!decoder->decode(windowFeatures.resizable))
428 if (!decoder->decode(windowFeatures.fullscreen))
430 if (!decoder->decode(windowFeatures.dialog))
436 void ArgumentCoder<Color>::encode(ArgumentEncoder* encoder, const Color& color)
438 if (!color.isValid()) {
439 encoder->encodeBool(false);
443 encoder->encodeBool(true);
444 encoder->encode(color.rgb());
447 bool ArgumentCoder<Color>::decode(ArgumentDecoder* decoder, Color& color)
450 if (!decoder->decode(isValid))
459 if (!decoder->decode(rgba))
467 void ArgumentCoder<CompositionUnderline>::encode(ArgumentEncoder* encoder, const CompositionUnderline& underline)
469 encoder->encode(underline.startOffset);
470 encoder->encode(underline.endOffset);
471 encoder->encode(underline.thick);
472 encoder->encode(underline.color);
475 bool ArgumentCoder<CompositionUnderline>::decode(ArgumentDecoder* decoder, CompositionUnderline& underline)
477 if (!decoder->decode(underline.startOffset))
479 if (!decoder->decode(underline.endOffset))
481 if (!decoder->decode(underline.thick))
483 if (!decoder->decode(underline.color))
490 void ArgumentCoder<DatabaseDetails>::encode(ArgumentEncoder* encoder, const DatabaseDetails& details)
492 encoder->encode(details.name());
493 encoder->encode(details.displayName());
494 encoder->encode(details.expectedUsage());
495 encoder->encode(details.currentUsage());
498 bool ArgumentCoder<DatabaseDetails>::decode(ArgumentDecoder* decoder, DatabaseDetails& details)
501 if (!decoder->decode(name))
505 if (!decoder->decode(displayName))
508 uint64_t expectedUsage;
509 if (!decoder->decode(expectedUsage))
512 uint64_t currentUsage;
513 if (!decoder->decode(currentUsage))
516 details = DatabaseDetails(name, displayName, expectedUsage, currentUsage);
521 void ArgumentCoder<GrammarDetail>::encode(ArgumentEncoder* encoder, const GrammarDetail& detail)
523 encoder->encode(detail.location);
524 encoder->encode(detail.length);
525 encoder->encode(detail.guesses);
526 encoder->encode(detail.userDescription);
529 bool ArgumentCoder<GrammarDetail>::decode(ArgumentDecoder* decoder, GrammarDetail& detail)
531 if (!decoder->decode(detail.location))
533 if (!decoder->decode(detail.length))
535 if (!decoder->decode(detail.guesses))
537 if (!decoder->decode(detail.userDescription))
544 void ArgumentCoder<TextCheckingResult>::encode(ArgumentEncoder* encoder, const TextCheckingResult& result)
546 encoder->encodeEnum(result.type);
547 encoder->encode(result.location);
548 encoder->encode(result.length);
549 encoder->encode(result.details);
550 encoder->encode(result.replacement);
553 bool ArgumentCoder<TextCheckingResult>::decode(ArgumentDecoder* decoder, TextCheckingResult& result)
555 if (!decoder->decodeEnum(result.type))
557 if (!decoder->decode(result.location))
559 if (!decoder->decode(result.length))
561 if (!decoder->decode(result.details))
563 if (!decoder->decode(result.replacement))
570 void ArgumentCoder<FloatPoint3D>::encode(ArgumentEncoder* encoder, const FloatPoint3D& floatPoint3D)
572 SimpleArgumentCoder<FloatPoint3D>::encode(encoder, floatPoint3D);
575 bool ArgumentCoder<FloatPoint3D>::decode(ArgumentDecoder* decoder, FloatPoint3D& floatPoint3D)
577 return SimpleArgumentCoder<FloatPoint3D>::decode(decoder, floatPoint3D);
581 void ArgumentCoder<Length>::encode(ArgumentEncoder* encoder, const Length& length)
583 SimpleArgumentCoder<Length>::encode(encoder, length);
586 bool ArgumentCoder<Length>::decode(ArgumentDecoder* decoder, Length& length)
588 return SimpleArgumentCoder<Length>::decode(decoder, length);
592 void ArgumentCoder<TransformationMatrix>::encode(ArgumentEncoder* encoder, const TransformationMatrix& transformationMatrix)
594 SimpleArgumentCoder<TransformationMatrix>::encode(encoder, transformationMatrix);
597 bool ArgumentCoder<TransformationMatrix>::decode(ArgumentDecoder* decoder, TransformationMatrix& transformationMatrix)
599 return SimpleArgumentCoder<TransformationMatrix>::decode(decoder, transformationMatrix);
603 void ArgumentCoder<MatrixTransformOperation>::encode(ArgumentEncoder* encoder, const MatrixTransformOperation& operation)
605 SimpleArgumentCoder<MatrixTransformOperation>::encode(encoder, operation);
608 bool ArgumentCoder<MatrixTransformOperation>::decode(ArgumentDecoder* decoder, MatrixTransformOperation& operation)
610 return SimpleArgumentCoder<MatrixTransformOperation>::decode(decoder, operation);
614 void ArgumentCoder<Matrix3DTransformOperation>::encode(ArgumentEncoder* encoder, const Matrix3DTransformOperation& operation)
616 SimpleArgumentCoder<Matrix3DTransformOperation>::encode(encoder, operation);
619 bool ArgumentCoder<Matrix3DTransformOperation>::decode(ArgumentDecoder* decoder, Matrix3DTransformOperation& operation)
621 return SimpleArgumentCoder<Matrix3DTransformOperation>::decode(decoder, operation);
625 void ArgumentCoder<PerspectiveTransformOperation>::encode(ArgumentEncoder* encoder, const PerspectiveTransformOperation& operation)
627 SimpleArgumentCoder<PerspectiveTransformOperation>::encode(encoder, operation);
630 bool ArgumentCoder<PerspectiveTransformOperation>::decode(ArgumentDecoder* decoder, PerspectiveTransformOperation& operation)
632 return SimpleArgumentCoder<PerspectiveTransformOperation>::decode(decoder, operation);
636 void ArgumentCoder<RotateTransformOperation>::encode(ArgumentEncoder* encoder, const RotateTransformOperation& operation)
638 SimpleArgumentCoder<RotateTransformOperation>::encode(encoder, operation);
641 bool ArgumentCoder<RotateTransformOperation>::decode(ArgumentDecoder* decoder, RotateTransformOperation& operation)
643 return SimpleArgumentCoder<RotateTransformOperation>::decode(decoder, operation);
647 void ArgumentCoder<ScaleTransformOperation>::encode(ArgumentEncoder* encoder, const ScaleTransformOperation& operation)
649 SimpleArgumentCoder<ScaleTransformOperation>::encode(encoder, operation);
652 bool ArgumentCoder<ScaleTransformOperation>::decode(ArgumentDecoder* decoder, ScaleTransformOperation& operation)
654 return SimpleArgumentCoder<ScaleTransformOperation>::decode(decoder, operation);
658 void ArgumentCoder<SkewTransformOperation>::encode(ArgumentEncoder* encoder, const SkewTransformOperation& operation)
660 SimpleArgumentCoder<SkewTransformOperation>::encode(encoder, operation);
663 bool ArgumentCoder<SkewTransformOperation>::decode(ArgumentDecoder* decoder, SkewTransformOperation& operation)
665 return SimpleArgumentCoder<SkewTransformOperation>::decode(decoder, operation);
669 void ArgumentCoder<TranslateTransformOperation>::encode(ArgumentEncoder* encoder, const TranslateTransformOperation& operation)
671 SimpleArgumentCoder<TranslateTransformOperation>::encode(encoder, operation);
674 bool ArgumentCoder<TranslateTransformOperation>::decode(ArgumentDecoder* decoder, TranslateTransformOperation& operation)
676 return SimpleArgumentCoder<TranslateTransformOperation>::decode(decoder, operation);
679 void ArgumentCoder<RefPtr<TimingFunction> >::encode(ArgumentEncoder* encoder, const RefPtr<TimingFunction>& function)
681 // We don't want to encode null-references.
684 encoder->encodeEnum(function->type());
685 switch (function->type()) {
686 case TimingFunction::LinearFunction:
688 case TimingFunction::CubicBezierFunction: {
689 CubicBezierTimingFunction* cubicFunction = static_cast<CubicBezierTimingFunction*>(function.get());
690 encoder->encodeDouble(cubicFunction->x1());
691 encoder->encodeDouble(cubicFunction->y1());
692 encoder->encodeDouble(cubicFunction->x2());
693 encoder->encodeDouble(cubicFunction->y2());
696 case TimingFunction::StepsFunction: {
697 StepsTimingFunction* stepsFunction = static_cast<StepsTimingFunction*>(function.get());
698 encoder->encodeInt32(stepsFunction->numberOfSteps());
699 encoder->encodeBool(stepsFunction->stepAtStart());
705 bool ArgumentCoder<RefPtr<TimingFunction> >::decode(ArgumentDecoder* decoder, RefPtr<TimingFunction>& function)
707 TimingFunction::TimingFunctionType type;
708 if (!decoder->decodeEnum(type))
712 case TimingFunction::LinearFunction:
713 function = LinearTimingFunction::create();
716 case TimingFunction::CubicBezierFunction: {
717 double x1, y1, x2, y2;
718 if (!decoder->decodeDouble(x1))
720 if (!decoder->decodeDouble(y1))
722 if (!decoder->decodeDouble(x2))
724 if (!decoder->decodeDouble(y2))
726 function = CubicBezierTimingFunction::create(x1, y1, x2, y2);
730 case TimingFunction::StepsFunction: {
733 if (!decoder->decodeInt32(numSteps))
735 if (!decoder->decodeBool(stepAtStart))
738 function = StepsTimingFunction::create(numSteps, stepAtStart);
749 void encodeOperation(ArgumentEncoder* encoder, const RefPtr<TransformOperation>& operation)
751 encoder->encode(*static_cast<const T*>(operation.get()));
754 void ArgumentCoder<RefPtr<TransformOperation> >::encode(ArgumentEncoder* encoder, const RefPtr<TransformOperation>& operation)
756 // We don't want to encode null-references.
759 encoder->encodeEnum(operation->getOperationType());
760 switch (operation->getOperationType()) {
761 case TransformOperation::SCALE:
762 case TransformOperation::SCALE_X:
763 case TransformOperation::SCALE_Y:
764 case TransformOperation::SCALE_Z:
765 case TransformOperation::SCALE_3D:
766 encodeOperation<ScaleTransformOperation>(encoder, operation);
769 case TransformOperation::TRANSLATE:
770 case TransformOperation::TRANSLATE_X:
771 case TransformOperation::TRANSLATE_Y:
772 case TransformOperation::TRANSLATE_Z:
773 case TransformOperation::TRANSLATE_3D:
774 encodeOperation<TranslateTransformOperation>(encoder, operation);
777 case TransformOperation::ROTATE:
778 case TransformOperation::ROTATE_X:
779 case TransformOperation::ROTATE_Y:
780 case TransformOperation::ROTATE_3D:
781 encodeOperation<RotateTransformOperation>(encoder, operation);
784 case TransformOperation::SKEW:
785 case TransformOperation::SKEW_X:
786 case TransformOperation::SKEW_Y:
787 encodeOperation<SkewTransformOperation>(encoder, operation);
790 case TransformOperation::MATRIX:
791 encodeOperation<MatrixTransformOperation>(encoder, operation);
794 case TransformOperation::MATRIX_3D:
795 encodeOperation<Matrix3DTransformOperation>(encoder, operation);
798 case TransformOperation::PERSPECTIVE:
799 encodeOperation<PerspectiveTransformOperation>(encoder, operation);
802 case TransformOperation::IDENTITY:
803 case TransformOperation::NONE:
809 bool decodeOperation(ArgumentDecoder* decoder, RefPtr<TransformOperation>& operation, PassRefPtr<T> newOperation)
811 if (!decoder->decode(*newOperation.get()))
814 operation = newOperation.get();
818 bool ArgumentCoder<RefPtr<TransformOperation> >::decode(ArgumentDecoder* decoder, RefPtr<TransformOperation>& operation)
820 TransformOperation::OperationType type;
821 if (!decoder->decodeEnum(type))
825 case TransformOperation::SCALE:
826 case TransformOperation::SCALE_X:
827 case TransformOperation::SCALE_Y:
828 case TransformOperation::SCALE_Z:
829 case TransformOperation::SCALE_3D:
830 return decodeOperation(decoder, operation, ScaleTransformOperation::create(1.0, 1.0, type));
832 case TransformOperation::TRANSLATE:
833 case TransformOperation::TRANSLATE_X:
834 case TransformOperation::TRANSLATE_Y:
835 case TransformOperation::TRANSLATE_Z:
836 case TransformOperation::TRANSLATE_3D:
837 return decodeOperation(decoder, operation, TranslateTransformOperation::create(Length(0, WebCore::Fixed), Length(0, WebCore::Fixed), type));
839 case TransformOperation::ROTATE:
840 case TransformOperation::ROTATE_X:
841 case TransformOperation::ROTATE_Y:
842 case TransformOperation::ROTATE_3D:
843 return decodeOperation(decoder, operation, RotateTransformOperation::create(0.0, type));
845 case TransformOperation::SKEW:
846 case TransformOperation::SKEW_X:
847 case TransformOperation::SKEW_Y:
848 return decodeOperation(decoder, operation, SkewTransformOperation::create(0.0, 0.0, type));
850 case TransformOperation::MATRIX:
851 return decodeOperation(decoder, operation, MatrixTransformOperation::create(TransformationMatrix()));
853 case TransformOperation::MATRIX_3D:
854 return decodeOperation(decoder, operation, Matrix3DTransformOperation::create(TransformationMatrix()));
856 case TransformOperation::PERSPECTIVE:
857 return decodeOperation(decoder, operation, PerspectiveTransformOperation::create(Length(0, WebCore::Fixed)));
859 case TransformOperation::IDENTITY:
860 case TransformOperation::NONE:
861 operation = IdentityTransformOperation::create();
868 void ArgumentCoder<TransformOperations>::encode(ArgumentEncoder* encoder, const TransformOperations& operations)
870 Vector<RefPtr<TransformOperation> > operationsVector = operations.operations();
871 int size = operationsVector.size();
872 encoder->encodeInt32(size);
873 for (int i = 0; i < size; ++i)
874 ArgumentCoder<RefPtr<TransformOperation> >::encode(encoder, operationsVector[i]);
877 bool ArgumentCoder<TransformOperations>::decode(ArgumentDecoder* decoder, TransformOperations& operations)
880 if (!decoder->decodeInt32(size))
883 Vector<RefPtr<TransformOperation> >& operationVector = operations.operations();
884 operationVector.clear();
885 operationVector.resize(size);
886 for (int i = 0; i < size; ++i) {
887 RefPtr<TransformOperation> operation;
888 if (!ArgumentCoder<RefPtr<TransformOperation> >::decode(decoder, operation))
890 operationVector[i] = operation;
897 static void encodeBoolAndValue(ArgumentEncoder* encoder, bool isSet, const T& value)
899 encoder->encodeBool(isSet);
901 encoder->encode(value);
905 static void encodeBoolAndEnumValue(ArgumentEncoder* encoder, bool isSet, T value)
907 encoder->encodeBool(isSet);
909 encoder->encodeEnum(value);
912 void ArgumentCoder<Animation>::encode(ArgumentEncoder* encoder, const Animation& animation)
914 encodeBoolAndValue(encoder, animation.isDelaySet(), animation.delay());
915 encodeBoolAndEnumValue(encoder, animation.isDirectionSet(), animation.direction());
916 encodeBoolAndValue(encoder, animation.isDurationSet(), animation.duration());
917 encodeBoolAndValue(encoder, animation.isFillModeSet(), animation.fillMode());
918 encodeBoolAndValue(encoder, animation.isIterationCountSet(), animation.iterationCount());
919 encodeBoolAndValue(encoder, animation.isNameSet(), animation.name());
920 encodeBoolAndEnumValue(encoder, animation.isPlayStateSet(), animation.playState());
921 encodeBoolAndValue(encoder, animation.isPropertySet(), animation.property());
922 encodeBoolAndValue<RefPtr<TimingFunction> >(encoder, animation.isTimingFunctionSet(), animation.timingFunction());
923 encoder->encodeBool(animation.isNoneAnimation());
928 static bool decodeBoolAndValue(ArgumentDecoder* decoder, bool& isSet, T& value)
930 if (!decoder->decodeBool(isSet))
935 return decoder->decode(value);
939 static bool decodeBoolAndEnumValue(ArgumentDecoder* decoder, bool& isSet, T& value)
941 if (!decoder->decodeBool(isSet))
946 return decoder->decodeEnum(value);
949 bool ArgumentCoder<Animation>::decode(ArgumentDecoder* decoder, Animation& animation)
951 bool isDelaySet, isDirectionSet, isDurationSet, isFillModeSet, isIterationCountSet, isNameSet, isPlayStateSet, isPropertySet, isTimingFunctionSet;
952 int property, iterationCount, fillMode;
954 RefPtr<TimingFunction> timingFunction;
957 animation.clearAll();
960 if (!decodeBoolAndValue(decoder, isDelaySet, delay))
963 Animation::AnimationDirection direction = Animation::AnimationDirectionNormal;
964 if (!decodeBoolAndEnumValue(decoder, isDirectionSet, direction))
966 if (!decodeBoolAndValue(decoder, isDurationSet, duration))
968 if (!decodeBoolAndValue(decoder, isFillModeSet, fillMode))
970 if (!decodeBoolAndValue(decoder, isIterationCountSet, iterationCount))
972 if (!decodeBoolAndValue(decoder, isNameSet, name))
975 EAnimPlayState playState = AnimPlayStatePlaying;
976 if (!decodeBoolAndEnumValue(decoder, isPlayStateSet, playState))
978 if (!decodeBoolAndValue(decoder, isPropertySet, property))
980 if (!decodeBoolAndValue<RefPtr<TimingFunction> >(decoder, isTimingFunctionSet, timingFunction))
984 animation.setDelay(delay);
986 animation.setDirection(direction);
988 animation.setDuration(duration);
990 animation.setFillMode(fillMode);
991 if (isIterationCountSet)
992 animation.setIterationCount(iterationCount);
994 animation.setName(name);
996 animation.setPlayState(playState);
998 animation.setProperty(property);
999 if (isTimingFunctionSet)
1000 animation.setTimingFunction(timingFunction);
1006 } // namespace CoreIPC