Changeset 89038 in webkit


Ignore:
Timestamp:
Jun 16, 2011 10:01:59 AM (13 years ago)
Author:
andersca@apple.com
Message:

2011-06-15 Anders Carlsson <andersca@apple.com>

Reviewed by Sam Weinig.

Move more argument coders to WebCoreArgumentCoders and clean up the animation coders
https://bugs.webkit.org/show_bug.cgi?id=62760

  • Shared/WebCoreArgumentCoders.cpp: (CoreIPC::::encode): (CoreIPC::::decode): (CoreIPC::encodeOperation): (CoreIPC::decodeOperation): (CoreIPC::encodeBoolAndValue): (CoreIPC::encodeBoolAndEnumValue): (CoreIPC::decodeBoolAndValue): (CoreIPC::decodeBoolAndEnumValue):
  • Shared/WebCoreArgumentCoders.h:
  • Shared/mac/ArgumentCodersMac.h:
  • Shared/mac/ArgumentCodersMac.mm:
  • Shared/mac/WebCoreArgumentCodersMac.mm: (CoreIPC::::encode): (CoreIPC::::decode):
Location:
trunk/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r89030 r89038  
     12011-06-15  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Move more argument coders to WebCoreArgumentCoders and clean up the animation coders
     6        https://bugs.webkit.org/show_bug.cgi?id=62760
     7
     8        * Shared/WebCoreArgumentCoders.cpp:
     9        (CoreIPC::::encode):
     10        (CoreIPC::::decode):
     11        (CoreIPC::encodeOperation):
     12        (CoreIPC::decodeOperation):
     13        (CoreIPC::encodeBoolAndValue):
     14        (CoreIPC::encodeBoolAndEnumValue):
     15        (CoreIPC::decodeBoolAndValue):
     16        (CoreIPC::decodeBoolAndEnumValue):
     17        * Shared/WebCoreArgumentCoders.h:
     18        * Shared/mac/ArgumentCodersMac.h:
     19        * Shared/mac/ArgumentCodersMac.mm:
     20        * Shared/mac/WebCoreArgumentCodersMac.mm:
     21        (CoreIPC::::encode):
     22        (CoreIPC::::decode):
     23
    1242011-06-16  Sangyong Park  <sy302.park@gmail.com>
    225
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

    r88973 r89038  
    341341}
    342342
     343
     344void ArgumentCoder<CompositionUnderline>::encode(ArgumentEncoder* encoder, const CompositionUnderline& underline)
     345{
     346    encoder->encode(underline.startOffset);
     347    encoder->encode(underline.endOffset);
     348    encoder->encode(underline.thick);
     349    encoder->encode(underline.color);
     350}
     351
     352bool ArgumentCoder<CompositionUnderline>::decode(ArgumentDecoder* decoder, CompositionUnderline& underline)
     353{
     354    if (!decoder->decode(underline.startOffset))
     355        return false;
     356    if (!decoder->decode(underline.endOffset))
     357        return false;
     358    if (!decoder->decode(underline.thick))
     359        return false;
     360    if (!decoder->decode(underline.color))
     361        return false;
     362
     363    return true;
     364}
     365
     366
     367void ArgumentCoder<DatabaseDetails>::encode(ArgumentEncoder* encoder, const DatabaseDetails& details)
     368{
     369    encoder->encode(details.name());
     370    encoder->encode(details.displayName());
     371    encoder->encode(details.expectedUsage());
     372    encoder->encode(details.currentUsage());
     373}
     374   
     375bool ArgumentCoder<DatabaseDetails>::decode(ArgumentDecoder* decoder, DatabaseDetails& details)
     376{
     377    String name;
     378    if (!decoder->decode(name))
     379        return false;
     380
     381    String displayName;
     382    if (!decoder->decode(displayName))
     383        return false;
     384
     385    uint64_t expectedUsage;
     386    if (!decoder->decode(expectedUsage))
     387        return false;
     388
     389    uint64_t currentUsage;
     390    if (!decoder->decode(currentUsage))
     391        return false;
     392   
     393    details = DatabaseDetails(name, displayName, expectedUsage, currentUsage);
     394    return true;
     395}
     396
     397
     398void ArgumentCoder<GrammarDetail>::encode(ArgumentEncoder* encoder, const GrammarDetail& detail)
     399{
     400    encoder->encode(detail.location);
     401    encoder->encode(detail.length);
     402    encoder->encode(detail.guesses);
     403    encoder->encode(detail.userDescription);
     404}
     405
     406bool ArgumentCoder<GrammarDetail>::decode(ArgumentDecoder* decoder, GrammarDetail& detail)
     407{
     408    if (!decoder->decode(detail.location))
     409        return false;
     410    if (!decoder->decode(detail.length))
     411        return false;
     412    if (!decoder->decode(detail.guesses))
     413        return false;
     414    if (!decoder->decode(detail.userDescription))
     415        return false;
     416
     417    return true;
     418}
     419
     420
     421void ArgumentCoder<TextCheckingResult>::encode(ArgumentEncoder* encoder, const TextCheckingResult& result)
     422{
     423    encoder->encodeEnum(result.type);
     424    encoder->encode(result.location);
     425    encoder->encode(result.length);
     426    encoder->encode(result.details);
     427    encoder->encode(result.replacement);
     428}
     429
     430bool ArgumentCoder<TextCheckingResult>::decode(ArgumentDecoder* decoder, TextCheckingResult& result)
     431{
     432    if (!decoder->decodeEnum(result.type))
     433        return false;
     434    if (!decoder->decode(result.location))
     435        return false;
     436    if (!decoder->decode(result.length))
     437        return false;
     438    if (!decoder->decode(result.details))
     439        return false;
     440    if (!decoder->decode(result.replacement))
     441        return false;
     442    return true;
     443}
     444
     445
     446void ArgumentCoder<RefPtr<TimingFunction> >::encode(ArgumentEncoder* encoder, const RefPtr<TimingFunction>& function)
     447{
     448    // We don't want to encode null-references.
     449    ASSERT(function);
     450
     451    encoder->encodeEnum(function->type());
     452    switch (function->type()) {
     453    case TimingFunction::LinearFunction:
     454        break;
     455    case TimingFunction::CubicBezierFunction: {
     456        CubicBezierTimingFunction* cubicFunction = static_cast<CubicBezierTimingFunction*>(function.get());
     457        encoder->encodeDouble(cubicFunction->x1());
     458        encoder->encodeDouble(cubicFunction->y1());
     459        encoder->encodeDouble(cubicFunction->x2());
     460        encoder->encodeDouble(cubicFunction->y2());
     461        break;
     462    }
     463    case TimingFunction::StepsFunction: {
     464        StepsTimingFunction* stepsFunction = static_cast<StepsTimingFunction*>(function.get());
     465        encoder->encodeInt32(stepsFunction->numberOfSteps());
     466        encoder->encodeBool(stepsFunction->stepAtStart());
     467        break;
     468    }
     469    }
     470}
     471
     472bool ArgumentCoder<RefPtr<TimingFunction> >::decode(ArgumentDecoder* decoder, RefPtr<TimingFunction>& function)
     473{
     474    TimingFunction::TimingFunctionType type;
     475    if (!decoder->decodeEnum(type))
     476        return false;
     477
     478    switch (type) {
     479    case TimingFunction::LinearFunction:
     480        function = LinearTimingFunction::create();
     481        return true;
     482
     483    case TimingFunction::CubicBezierFunction: {
     484        double x1, y1, x2, y2;
     485        if (!decoder->decodeDouble(x1))
     486            return false;
     487        if (!decoder->decodeDouble(y1))
     488            return false;
     489        if (!decoder->decodeDouble(x2))
     490            return false;
     491        if (!decoder->decodeDouble(y2))
     492            return false;
     493        function = CubicBezierTimingFunction::create(x1, y1, x2, y2);
     494        return true;
     495    }
     496
     497    case TimingFunction::StepsFunction: {
     498        int numSteps;
     499        bool stepAtStart;
     500        if (!decoder->decodeInt32(numSteps))
     501            return false;
     502        if (!decoder->decodeBool(stepAtStart))
     503            return false;
     504
     505        function = StepsTimingFunction::create(numSteps, stepAtStart);
     506        return true;
     507    }
     508
     509    }
     510
     511    return false;
     512}
     513
     514
     515template<typename T>
     516void encodeOperation(ArgumentEncoder* encoder, const RefPtr<TransformOperation>& operation)
     517{
     518    encoder->encode(*static_cast<const T*>(operation.get()));
     519}
     520
     521void ArgumentCoder<RefPtr<TransformOperation> >::encode(ArgumentEncoder* encoder, const RefPtr<TransformOperation>& operation)
     522{
     523    // We don't want to encode null-references.
     524    ASSERT(operation);
     525
     526    encoder->encodeEnum(operation->getOperationType());
     527    switch (operation->getOperationType()) {
     528    case TransformOperation::SCALE:
     529    case TransformOperation::SCALE_X:
     530    case TransformOperation::SCALE_Y:
     531    case TransformOperation::SCALE_Z:
     532    case TransformOperation::SCALE_3D:
     533        encodeOperation<ScaleTransformOperation>(encoder, operation);
     534        return;
     535
     536    case TransformOperation::TRANSLATE:
     537    case TransformOperation::TRANSLATE_X:
     538    case TransformOperation::TRANSLATE_Y:
     539    case TransformOperation::TRANSLATE_Z:
     540    case TransformOperation::TRANSLATE_3D:
     541        encodeOperation<TranslateTransformOperation>(encoder, operation);
     542        return;
     543
     544    case TransformOperation::ROTATE:
     545    case TransformOperation::ROTATE_X:
     546    case TransformOperation::ROTATE_Y:
     547    case TransformOperation::ROTATE_3D:
     548        encodeOperation<RotateTransformOperation>(encoder, operation);
     549        return;
     550
     551    case TransformOperation::SKEW:
     552    case TransformOperation::SKEW_X:
     553    case TransformOperation::SKEW_Y:
     554        encodeOperation<SkewTransformOperation>(encoder, operation);
     555        return;
     556
     557    case TransformOperation::MATRIX:
     558        encodeOperation<MatrixTransformOperation>(encoder, operation);
     559        return;
     560
     561    case TransformOperation::MATRIX_3D:
     562        encodeOperation<Matrix3DTransformOperation>(encoder, operation);
     563        return;
     564
     565    case TransformOperation::PERSPECTIVE:
     566        encodeOperation<PerspectiveTransformOperation>(encoder, operation);
     567        return;
     568
     569    case TransformOperation::IDENTITY:
     570    case TransformOperation::NONE:
     571        return;
     572    }
     573}
     574
     575template<typename T>
     576bool decodeOperation(ArgumentDecoder* decoder, RefPtr<TransformOperation>& operation, PassRefPtr<T> newOperation)
     577{
     578    if (!decoder->decode(*newOperation.get()))
     579        return false;
     580
     581    operation = newOperation.get();
     582    return true;
     583}
     584
     585bool ArgumentCoder<RefPtr<TransformOperation> >::decode(ArgumentDecoder* decoder, RefPtr<TransformOperation>& operation)
     586{
     587    TransformOperation::OperationType type;
     588    if (!decoder->decodeEnum(type))
     589        return false;
     590
     591    switch (type) {
     592    case TransformOperation::SCALE:
     593    case TransformOperation::SCALE_X:
     594    case TransformOperation::SCALE_Y:
     595    case TransformOperation::SCALE_Z:
     596    case TransformOperation::SCALE_3D:
     597        return decodeOperation(decoder, operation, ScaleTransformOperation::create(1.0, 1.0, type));
     598
     599    case TransformOperation::TRANSLATE:
     600    case TransformOperation::TRANSLATE_X:
     601    case TransformOperation::TRANSLATE_Y:
     602    case TransformOperation::TRANSLATE_Z:
     603    case TransformOperation::TRANSLATE_3D:
     604        return decodeOperation(decoder, operation, TranslateTransformOperation::create(Length(0, WebCore::Fixed), Length(0, WebCore::Fixed), type));
     605
     606    case TransformOperation::ROTATE:
     607    case TransformOperation::ROTATE_X:
     608    case TransformOperation::ROTATE_Y:
     609    case TransformOperation::ROTATE_3D:
     610        return decodeOperation(decoder, operation, RotateTransformOperation::create(0.0, type));
     611
     612    case TransformOperation::SKEW:
     613    case TransformOperation::SKEW_X:
     614    case TransformOperation::SKEW_Y:
     615        return decodeOperation(decoder, operation, SkewTransformOperation::create(0.0, 0.0, type));
     616
     617    case TransformOperation::MATRIX:
     618        return decodeOperation(decoder, operation, MatrixTransformOperation::create(TransformationMatrix()));
     619
     620    case TransformOperation::MATRIX_3D:
     621        return decodeOperation(decoder, operation, Matrix3DTransformOperation::create(TransformationMatrix()));
     622
     623    case TransformOperation::PERSPECTIVE:
     624        return decodeOperation(decoder, operation, PerspectiveTransformOperation::create(Length(0, WebCore::Fixed)));
     625
     626    case TransformOperation::IDENTITY:
     627    case TransformOperation::NONE:
     628        operation = IdentityTransformOperation::create();
     629        return true;
     630    }
     631
     632    return false;
     633}
     634
     635void ArgumentCoder<TransformOperations>::encode(ArgumentEncoder* encoder, const TransformOperations& operations)
     636{
     637    Vector<RefPtr<TransformOperation> > operationsVector = operations.operations();
     638    int size = operationsVector.size();
     639    encoder->encodeInt32(size);
     640    for (int i = 0; i < size; ++i)
     641        ArgumentCoder<RefPtr<TransformOperation> >::encode(encoder, operationsVector[i]);
     642}
     643
     644bool ArgumentCoder<TransformOperations>::decode(ArgumentDecoder* decoder, TransformOperations& operations)
     645{
     646    int size;
     647    if (!decoder->decodeInt32(size))
     648        return false;
     649
     650    Vector<RefPtr<TransformOperation> >& operationVector = operations.operations();
     651    operationVector.clear();
     652    operationVector.resize(size);
     653    for (int i = 0; i < size; ++i) {
     654        RefPtr<TransformOperation> operation;
     655        if (!ArgumentCoder<RefPtr<TransformOperation> >::decode(decoder, operation))
     656            return false;
     657        operationVector[i] = operation;
     658    }
     659
     660    return true;
     661}
     662
     663template<typename T>
     664static void encodeBoolAndValue(ArgumentEncoder* encoder, bool isSet, const T& value)
     665{
     666    encoder->encodeBool(isSet);
     667    if (isSet)
     668        encoder->encode(value);
     669}
     670
     671template<typename T>
     672static void encodeBoolAndEnumValue(ArgumentEncoder* encoder, bool isSet, T value)
     673{
     674    encoder->encodeBool(isSet);
     675    if (isSet)
     676        encoder->encodeEnum(value);
     677}
     678
     679void ArgumentCoder<Animation>::encode(ArgumentEncoder* encoder, const Animation& animation)
     680{
     681    encodeBoolAndValue(encoder, animation.isDelaySet(), animation.delay());
     682    encodeBoolAndEnumValue(encoder, animation.isDirectionSet(), animation.direction());
     683    encodeBoolAndValue(encoder, animation.isDurationSet(), animation.duration());
     684    encodeBoolAndValue(encoder, animation.isFillModeSet(), animation.fillMode());
     685    encodeBoolAndValue(encoder, animation.isIterationCountSet(), animation.iterationCount());
     686    encodeBoolAndValue(encoder, animation.isNameSet(), animation.name());
     687    encodeBoolAndEnumValue(encoder, animation.isPlayStateSet(), animation.playState());
     688    encodeBoolAndValue(encoder, animation.isPropertySet(), animation.property());
     689    encodeBoolAndValue<RefPtr<TimingFunction> >(encoder, animation.isTimingFunctionSet(), animation.timingFunction());
     690    encoder->encodeBool(animation.isNoneAnimation());
     691}
     692
     693
     694template<typename T>
     695static bool decodeBoolAndValue(ArgumentDecoder* decoder, bool& isSet, T& value)
     696{
     697    if (!decoder->decodeBool(isSet))
     698        return false;
     699    if (!isSet)
     700        return true;
     701
     702    return decoder->decode(value);
     703}
     704
     705template<typename T>
     706static bool decodeBoolAndEnumValue(ArgumentDecoder* decoder, bool& isSet, T& value)
     707{
     708    if (!decoder->decodeBool(isSet))
     709        return false;
     710    if (!isSet)
     711        return true;
     712
     713    return decoder->decodeEnum(value);
     714}
     715
     716bool ArgumentCoder<Animation>::decode(ArgumentDecoder* decoder, Animation& animation)
     717{
     718    bool isDelaySet, isDirectionSet, isDurationSet, isFillModeSet, isIterationCountSet, isNameSet, isPlayStateSet, isPropertySet, isTimingFunctionSet;
     719    int property, iterationCount, fillMode;
     720    double duration;
     721    RefPtr<TimingFunction> timingFunction;
     722    String name;
     723
     724    animation.clearAll();
     725
     726    double delay;
     727    if (!decodeBoolAndValue(decoder, isDelaySet, delay))
     728        return false;
     729
     730    Animation::AnimationDirection direction = Animation::AnimationDirectionNormal;
     731    if (!decodeBoolAndEnumValue(decoder, isDirectionSet, direction))
     732        return false;
     733    if (!decodeBoolAndValue(decoder, isDurationSet, duration))
     734        return false;
     735    if (!decodeBoolAndValue(decoder, isFillModeSet, fillMode))
     736        return false;
     737    if (!decodeBoolAndValue(decoder, isIterationCountSet, iterationCount))
     738        return false;
     739    if (!decodeBoolAndValue(decoder, isNameSet, name))
     740        return false;
     741
     742    EAnimPlayState playState = AnimPlayStatePlaying;
     743    if (!decodeBoolAndEnumValue(decoder, isPlayStateSet, playState))
     744        return false;
     745    if (!decodeBoolAndValue(decoder, isPropertySet, property))
     746        return false;
     747    if (!decodeBoolAndValue<RefPtr<TimingFunction> >(decoder, isTimingFunctionSet, timingFunction))
     748        return false;
     749
     750    if (isDelaySet)
     751        animation.setDelay(delay);
     752    if (isDirectionSet)
     753        animation.setDirection(direction);
     754    if (isDurationSet)
     755        animation.setDuration(duration);
     756    if (isFillModeSet)
     757        animation.setFillMode(fillMode);
     758    if (isIterationCountSet)
     759        animation.setIterationCount(iterationCount);
     760    if (isNameSet)
     761        animation.setName(name);
     762    if (isPlayStateSet)
     763        animation.setPlayState(playState);
     764    if (isPropertySet)
     765        animation.setProperty(property);
     766    if (isTimingFunctionSet)
     767        animation.setTimingFunction(timingFunction);
     768
     769    return true;
     770}
     771
    343772} // namespace CoreIPC
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h

    r88973 r89038  
    191191#if PLATFORM(MAC)
    192192template<> struct ArgumentCoder<WebCore::KeypressCommand> {
    193     static void encode(ArgumentEncoder* encoder, const WebCore::KeypressCommand& keypressCommand)
    194     {
    195         encoder->encode(CoreIPC::In(keypressCommand.commandName, keypressCommand.text));
    196     }
    197    
    198     static bool decode(ArgumentDecoder* decoder, WebCore::KeypressCommand& keypressCommand)
    199     {
    200         return decoder->decode(CoreIPC::Out(keypressCommand.commandName, keypressCommand.text));
    201     }
     193    static void encode(ArgumentEncoder*, const WebCore::KeypressCommand&);
     194    static bool decode(ArgumentDecoder*, WebCore::KeypressCommand&);
    202195};
    203196#endif
    204197
    205198template<> struct ArgumentCoder<WebCore::CompositionUnderline> {
    206     static void encode(ArgumentEncoder* encoder, const WebCore::CompositionUnderline& underline)
    207     {
    208         encoder->encode(CoreIPC::In(underline.startOffset, underline.endOffset, underline.thick, underline.color));
    209     }
    210    
    211     static bool decode(ArgumentDecoder* decoder, WebCore::CompositionUnderline& underline)
    212     {
    213         return decoder->decode(CoreIPC::Out(underline.startOffset, underline.endOffset, underline.thick, underline.color));
    214     }
     199    static void encode(ArgumentEncoder*, const WebCore::CompositionUnderline&);
     200    static bool decode(ArgumentDecoder*, WebCore::CompositionUnderline&);
    215201};
    216202
    217203template<> struct ArgumentCoder<WebCore::DatabaseDetails> {
    218     static void encode(ArgumentEncoder* encoder, const WebCore::DatabaseDetails& details)
    219     {
    220         encoder->encode(CoreIPC::In(details.name(), details.displayName(), details.expectedUsage(), details.currentUsage()));
    221     }
    222    
    223     static bool decode(ArgumentDecoder* decoder, WebCore::DatabaseDetails& details)
    224     {
    225         String name;
    226         String displayName;
    227         uint64_t expectedUsage;
    228         uint64_t currentUsage;
    229         if (!decoder->decode(CoreIPC::Out(name, displayName, expectedUsage, currentUsage)))
    230             return false;
    231        
    232         details = WebCore::DatabaseDetails(name, displayName, expectedUsage, currentUsage);
    233         return true;
    234     }
     204    static void encode(ArgumentEncoder*, const WebCore::DatabaseDetails&);
     205    static bool decode(ArgumentDecoder*, WebCore::DatabaseDetails&);
    235206};
    236207
    237208template<> struct ArgumentCoder<WebCore::GrammarDetail> {
    238     static void encode(ArgumentEncoder* encoder, const WebCore::GrammarDetail& detail)
    239     {
    240         encoder->encodeInt32(detail.location);
    241         encoder->encodeInt32(detail.length);
    242         encoder->encode(detail.guesses);
    243         encoder->encode(detail.userDescription);
    244     }
    245 
    246     static bool decode(ArgumentDecoder* decoder, WebCore::GrammarDetail& detail)
    247     {
    248         if (!decoder->decodeInt32(detail.location))
    249             return false;
    250         if (!decoder->decodeInt32(detail.length))
    251             return false;
    252         if (!decoder->decode(detail.guesses))
    253             return false;
    254         if (!decoder->decode(detail.userDescription))
    255             return false;
    256 
    257         return true;
    258     }
     209    static void encode(ArgumentEncoder*, const WebCore::GrammarDetail&);
     210    static bool decode(ArgumentDecoder*, WebCore::GrammarDetail&);
    259211};
    260212
    261213template<> struct ArgumentCoder<WebCore::TextCheckingResult> {
    262     static void encode(ArgumentEncoder* encoder, const WebCore::TextCheckingResult& result)
    263     {
    264         encoder->encodeEnum(result.type);
    265         encoder->encodeInt32(result.location);
    266         encoder->encodeInt32(result.length);
    267         encoder->encode(result.details);
    268         encoder->encode(result.replacement);
    269     }
    270 
    271     static bool decode(ArgumentDecoder* decoder, WebCore::TextCheckingResult& result)
    272     {
    273         if (!decoder->decodeEnum(result.type))
    274             return false;
    275         if (!decoder->decodeInt32(result.location))
    276             return false;
    277         if (!decoder->decodeInt32(result.length))
    278             return false;
    279         if (!decoder->decode(result.details))
    280             return false;
    281         if (!decoder->decode(result.replacement))
    282             return false;
    283         return true;
    284     }
     214    static void encode(ArgumentEncoder*, const WebCore::TextCheckingResult&);
     215    static bool decode(ArgumentDecoder*, WebCore::TextCheckingResult&);
    285216};
    286217
    287218template<> struct ArgumentCoder<RefPtr<WebCore::TimingFunction> > {
    288     static void encode(ArgumentEncoder* encoder, const RefPtr<WebCore::TimingFunction>& function)
    289     {
    290         // We don't want to encode null-references.
    291         ASSERT(function);
    292 
    293         WebCore::TimingFunction::TimingFunctionType type = function->type();
    294         encoder->encodeInt32(type);
    295         switch (type) {
    296         case WebCore::TimingFunction::LinearFunction:
    297             break;
    298         case WebCore::TimingFunction::CubicBezierFunction: {
    299             WebCore::CubicBezierTimingFunction* cubicFunction = static_cast<WebCore::CubicBezierTimingFunction*>(function.get());
    300             encoder->encodeDouble(cubicFunction->x1());
    301             encoder->encodeDouble(cubicFunction->y1());
    302             encoder->encodeDouble(cubicFunction->x2());
    303             encoder->encodeDouble(cubicFunction->y2());
    304             break;
    305         }
    306         case WebCore::TimingFunction::StepsFunction: {
    307             WebCore::StepsTimingFunction* stepsFunction = static_cast<WebCore::StepsTimingFunction*>(function.get());
    308             encoder->encodeInt32(stepsFunction->numberOfSteps());
    309             encoder->encodeBool(stepsFunction->stepAtStart());
    310             break;
    311         }
    312         }
    313     }
    314 
    315     static bool decode(ArgumentDecoder* decoder, RefPtr<WebCore::TimingFunction>& function)
    316     {
    317         WebCore::TimingFunction::TimingFunctionType type;
    318         int typeInt;
    319         if (!decoder->decodeInt32(typeInt))
    320             return false;
    321 
    322         type = static_cast<WebCore::TimingFunction::TimingFunctionType>(typeInt);
    323         switch (type) {
    324         case WebCore::TimingFunction::LinearFunction:
    325             function = WebCore::LinearTimingFunction::create();
    326             return true;
    327 
    328         case WebCore::TimingFunction::CubicBezierFunction: {
    329             double x1, y1, x2, y2;
    330             if (!decoder->decodeDouble(x1))
    331                 return false;
    332             if (!decoder->decodeDouble(y1))
    333                 return false;
    334             if (!decoder->decodeDouble(x2))
    335                 return false;
    336             if (!decoder->decodeDouble(y2))
    337                 return false;
    338             function = WebCore::CubicBezierTimingFunction::create(x1, y1, x2, y2);
    339             return true;
    340         }
    341 
    342         case WebCore::TimingFunction::StepsFunction: {
    343             int numSteps;
    344             bool stepAtStart;
    345             if (!decoder->decodeInt32(numSteps))
    346                 return false;
    347             if (!decoder->decodeBool(stepAtStart))
    348                 return false;
    349 
    350             function = WebCore::StepsTimingFunction::create(numSteps, stepAtStart);
    351             return true;
    352         }
    353 
    354         }
    355 
    356         return false;
    357     }
     219    static void encode(ArgumentEncoder*, const RefPtr<WebCore::TimingFunction>&);
     220    static bool decode(ArgumentDecoder*, RefPtr<WebCore::TimingFunction>&);
    358221};
    359222
    360223template<> struct ArgumentCoder<RefPtr<WebCore::TransformOperation> > {
    361     template<class T>
    362     static bool decodeOperation(ArgumentDecoder* decoder, RefPtr<WebCore::TransformOperation>& operation, PassRefPtr<T> newOperation)
    363     {
    364         if (!ArgumentCoder<T>::decode(decoder, *newOperation.get()))
    365             return false;
    366         operation = newOperation.get();
    367         return true;
    368     }
    369 
    370     template<class T>
    371     static void encodeOperation(ArgumentEncoder* encoder, const WebCore::TransformOperation* operation)
    372     {
    373         ArgumentCoder<T>::encode(encoder, *static_cast<const T*>(operation));
    374     }
    375 
    376     static void encode(ArgumentEncoder* encoder, const RefPtr<WebCore::TransformOperation>& operation)
    377     {
    378         // We don't want to encode null-references.
    379         ASSERT(operation);
    380 
    381         WebCore::TransformOperation::OperationType type = operation->getOperationType();
    382         encoder->encodeInt32(type);
    383         switch (type) {
    384         case WebCore::TransformOperation::SCALE:
    385         case WebCore::TransformOperation::SCALE_X:
    386         case WebCore::TransformOperation::SCALE_Y:
    387         case WebCore::TransformOperation::SCALE_Z:
    388         case WebCore::TransformOperation::SCALE_3D:
    389             encodeOperation<WebCore::ScaleTransformOperation>(encoder, operation.get());
    390             return;
    391 
    392         case WebCore::TransformOperation::TRANSLATE:
    393         case WebCore::TransformOperation::TRANSLATE_X:
    394         case WebCore::TransformOperation::TRANSLATE_Y:
    395         case WebCore::TransformOperation::TRANSLATE_Z:
    396         case WebCore::TransformOperation::TRANSLATE_3D:
    397             encodeOperation<WebCore::TranslateTransformOperation>(encoder, operation.get());
    398             return;
    399 
    400         case WebCore::TransformOperation::ROTATE:
    401         case WebCore::TransformOperation::ROTATE_X:
    402         case WebCore::TransformOperation::ROTATE_Y:
    403         case WebCore::TransformOperation::ROTATE_3D:
    404             encodeOperation<WebCore::RotateTransformOperation>(encoder, operation.get());
    405             return;
    406 
    407         case WebCore::TransformOperation::SKEW:
    408         case WebCore::TransformOperation::SKEW_X:
    409         case WebCore::TransformOperation::SKEW_Y:
    410             encodeOperation<WebCore::SkewTransformOperation>(encoder, operation.get());
    411             return;
    412 
    413         case WebCore::TransformOperation::MATRIX:
    414             encodeOperation<WebCore::MatrixTransformOperation>(encoder, operation.get());
    415             return;
    416 
    417         case WebCore::TransformOperation::MATRIX_3D:
    418             encodeOperation<WebCore::Matrix3DTransformOperation>(encoder, operation.get());
    419             return;
    420 
    421         case WebCore::TransformOperation::PERSPECTIVE:
    422             encodeOperation<WebCore::PerspectiveTransformOperation>(encoder, operation.get());
    423             return;
    424 
    425         case WebCore::TransformOperation::IDENTITY:
    426         case WebCore::TransformOperation::NONE:
    427             return;
    428         }
    429     }
    430 
    431     static bool decode(ArgumentDecoder* decoder, RefPtr<WebCore::TransformOperation>& operation)
    432     {
    433         WebCore::TransformOperation::OperationType type;
    434         int typeInt;
    435         if (!decoder->decodeInt32(typeInt))
    436             return false;
    437         type = static_cast<WebCore::TransformOperation::OperationType>(typeInt);
    438         switch (type) {
    439         case WebCore::TransformOperation::SCALE:
    440         case WebCore::TransformOperation::SCALE_X:
    441         case WebCore::TransformOperation::SCALE_Y:
    442         case WebCore::TransformOperation::SCALE_Z:
    443         case WebCore::TransformOperation::SCALE_3D:
    444             return decodeOperation<WebCore::ScaleTransformOperation>(decoder, operation, WebCore::ScaleTransformOperation::create(1.0, 1.0, type));
    445 
    446         case WebCore::TransformOperation::TRANSLATE:
    447         case WebCore::TransformOperation::TRANSLATE_X:
    448         case WebCore::TransformOperation::TRANSLATE_Y:
    449         case WebCore::TransformOperation::TRANSLATE_Z:
    450         case WebCore::TransformOperation::TRANSLATE_3D:
    451             return decodeOperation<WebCore::TranslateTransformOperation>(decoder, operation, WebCore::TranslateTransformOperation::create(WebCore::Length(0, WebCore::Fixed), WebCore::Length(0, WebCore::Fixed), type));
    452 
    453         case WebCore::TransformOperation::ROTATE:
    454         case WebCore::TransformOperation::ROTATE_X:
    455         case WebCore::TransformOperation::ROTATE_Y:
    456         case WebCore::TransformOperation::ROTATE_3D:
    457             return decodeOperation<WebCore::RotateTransformOperation>(decoder, operation, WebCore::RotateTransformOperation::create(0.0, type));
    458 
    459         case WebCore::TransformOperation::SKEW:
    460         case WebCore::TransformOperation::SKEW_X:
    461         case WebCore::TransformOperation::SKEW_Y:
    462             return decodeOperation<WebCore::SkewTransformOperation>(decoder, operation, WebCore::SkewTransformOperation::create(0.0, 0.0, type));
    463 
    464         case WebCore::TransformOperation::MATRIX:
    465             return decodeOperation<WebCore::MatrixTransformOperation>(decoder, operation, WebCore::MatrixTransformOperation::create(WebCore::TransformationMatrix()));
    466 
    467         case WebCore::TransformOperation::MATRIX_3D:
    468             return decodeOperation<WebCore::Matrix3DTransformOperation>(decoder, operation, WebCore::Matrix3DTransformOperation::create(WebCore::TransformationMatrix()));
    469 
    470         case WebCore::TransformOperation::PERSPECTIVE:
    471             return decodeOperation<WebCore::PerspectiveTransformOperation>(decoder, operation, WebCore::PerspectiveTransformOperation::create(WebCore::Length(0, WebCore::Fixed)));
    472 
    473         case WebCore::TransformOperation::IDENTITY:
    474         case WebCore::TransformOperation::NONE:
    475             operation = WebCore::IdentityTransformOperation::create();
    476             return true;
    477         }
    478 
    479         return false;
    480     }
     224    static void encode(ArgumentEncoder*, const RefPtr<WebCore::TransformOperation>&);
     225    static bool decode(ArgumentDecoder*, RefPtr<WebCore::TransformOperation>&);
    481226};
    482227
    483228template<> struct ArgumentCoder<WebCore::TransformOperations> {
    484     static void encode(ArgumentEncoder* encoder, const WebCore::TransformOperations& operations)
    485     {
    486         WTF::Vector<RefPtr<WebCore::TransformOperation> > operationsVector = operations.operations();
    487         int size = operationsVector.size();
    488         encoder->encodeInt32(size);
    489         for (int i = 0; i < size; ++i)
    490             ArgumentCoder<RefPtr<WebCore::TransformOperation> >::encode(encoder, operationsVector[i]);
    491     }
    492 
    493     static bool decode(ArgumentDecoder* decoder, WebCore::TransformOperations& operations)
    494     {
    495         int size;
    496         if (!decoder->decodeInt32(size))
    497             return false;
    498 
    499         WTF::Vector<RefPtr<WebCore::TransformOperation> >& operationVector = operations.operations();
    500         operationVector.clear();
    501         operationVector.resize(size);
    502         for (int i = 0; i < size; ++i) {
    503             RefPtr<WebCore::TransformOperation> operation;
    504             if (!ArgumentCoder<RefPtr<WebCore::TransformOperation> >::decode(decoder, operation))
    505                 return false;
    506             operationVector[i] = operation;
    507         }
    508 
    509         return true;
    510     }
    511 };
    512 
     229    static void encode(ArgumentEncoder*, const WebCore::TransformOperations&);
     230    static bool decode(ArgumentDecoder*, WebCore::TransformOperations&);
     231};
    513232
    514233template<> struct ArgumentCoder<WebCore::Animation> {
    515     static bool encodeBoolAndReturnValue(ArgumentEncoder* encoder, bool value)
    516     {
    517         encoder->encodeBool(value);
    518         return value;
    519     }
    520 
    521     template<typename T>
    522     static void encodeBoolAndValue(ArgumentEncoder* encoder, bool isSet, const T& value)
    523     {
    524         if (encodeBoolAndReturnValue(encoder, isSet))
    525             encoder->encode<T>(value);
    526     }
    527 
    528     static bool decodeBoolAndValue(ArgumentDecoder* decoder, bool& isSet, double& value)
    529     {
    530         if (!decoder->decodeBool(isSet))
    531             return false;
    532         if (!isSet)
    533             return true;
    534 
    535         return decoder->decodeDouble(value);
    536     }
    537 
    538     template<class T>
    539     static bool decodeBoolAndValue(ArgumentDecoder* decoder, bool& isSet, T& value)
    540     {
    541         if (!decoder->decodeBool(isSet))
    542             return false;
    543         if (!isSet)
    544             return true;
    545 
    546         return ArgumentCoder<T>::decode(decoder, value);
    547     }
    548 
    549     static bool decodeBoolAndValue(ArgumentDecoder* decoder, bool& isSet, int& value)
    550     {
    551         if (!decoder->decodeBool(isSet))
    552             return false;
    553         if (!isSet)
    554             return true;
    555 
    556         return decoder->decodeInt32(value);
    557     }
    558 
    559     static void encode(ArgumentEncoder* encoder, const WebCore::Animation& animation)
    560     {
    561         encodeBoolAndValue(encoder, animation.isDelaySet(), animation.delay());
    562         encodeBoolAndValue<int>(encoder, animation.isDirectionSet(), animation.direction());
    563         encodeBoolAndValue(encoder, animation.isDurationSet(), animation.duration());
    564         encodeBoolAndValue(encoder, animation.isFillModeSet(), animation.fillMode());
    565         encodeBoolAndValue(encoder, animation.isIterationCountSet(), animation.iterationCount());
    566 
    567         if (encodeBoolAndReturnValue(encoder, animation.isNameSet()))
    568             ArgumentCoder<String>::encode(encoder, animation.name());
    569 
    570         encodeBoolAndValue<int>(encoder, animation.isPlayStateSet(), animation.playState());
    571         encodeBoolAndValue(encoder, animation.isPropertySet(), animation.property());
    572 
    573         if (encodeBoolAndReturnValue(encoder, animation.isTimingFunctionSet()))
    574             ArgumentCoder<RefPtr<WebCore::TimingFunction> >::encode(encoder, animation.timingFunction());
    575         encoder->encodeBool(animation.isNoneAnimation());
    576     }
    577 
    578     static bool decode(ArgumentDecoder* decoder, WebCore::Animation& animation)
    579     {
    580         bool isDelaySet, isDirectionSet, isDurationSet, isFillModeSet, isIterationCountSet, isNameSet, isPlayStateSet, isPropertySet, isTimingFunctionSet;
    581         int property, iterationCount, direction, fillMode, playState;
    582         double delay, duration;
    583         RefPtr<WebCore::TimingFunction> timingFunction;
    584         String name;
    585 
    586         animation.clearAll();
    587 
    588         if (!decodeBoolAndValue(decoder, isDelaySet, delay))
    589             return false;
    590         if (!decodeBoolAndValue(decoder, isDirectionSet, direction))
    591             return false;
    592         if (!decodeBoolAndValue(decoder, isDurationSet, duration))
    593             return false;
    594         if (!decodeBoolAndValue(decoder, isFillModeSet, fillMode))
    595             return false;
    596         if (!decodeBoolAndValue(decoder, isIterationCountSet, iterationCount))
    597             return false;
    598         if (!decodeBoolAndValue<String>(decoder, isNameSet, name))
    599             return false;
    600         if (!decodeBoolAndValue(decoder, isPlayStateSet, playState))
    601             return false;
    602         if (!decodeBoolAndValue(decoder, isPropertySet, property))
    603             return false;
    604         if (!decodeBoolAndValue<RefPtr<WebCore::TimingFunction> >(decoder, isTimingFunctionSet, timingFunction))
    605             return false;
    606 
    607         if (isDelaySet)
    608             animation.setDelay(delay);
    609         if (isDirectionSet)
    610             animation.setDirection(static_cast<WebCore::Animation::AnimationDirection>(direction));
    611         if (isDurationSet)
    612             animation.setDuration(duration);
    613         if (isFillModeSet)
    614             animation.setFillMode(fillMode);
    615         if (isIterationCountSet)
    616             animation.setIterationCount(iterationCount);
    617         if (isNameSet)
    618             animation.setName(name);
    619         if (isPlayStateSet)
    620             animation.setPlayState(static_cast<WebCore::EAnimPlayState>(playState));
    621         if (isPropertySet)
    622             animation.setProperty(property);
    623         if (isTimingFunctionSet)
    624             animation.setTimingFunction(timingFunction);
    625 
    626         return true;
    627     }
     234    static void encode(ArgumentEncoder*, const WebCore::Animation&);
     235    static bool decode(ArgumentDecoder*, WebCore::Animation&);
    628236};
    629237
  • trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.h

    r83204 r89038  
    5858bool decode(ArgumentDecoder*, RetainPtr<NSString>&);
    5959
    60 }
     60} // namespace CoreIPC
    6161
    6262#endif // ArgumentCodersMac_h
  • trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.mm

    r83204 r89038  
    341341}
    342342
    343 }
     343} // namespace CoreIPC
  • trunk/Source/WebKit2/Shared/mac/WebCoreArgumentCodersMac.mm

    r83177 r89038  
    193193}
    194194
     195
     196void ArgumentCoder<KeypressCommand>::encode(ArgumentEncoder* encoder, const KeypressCommand& keypressCommand)
     197{
     198    encoder->encode(keypressCommand.commandName);
     199    encoder->encode(keypressCommand.text);
     200}
     201   
     202bool ArgumentCoder<KeypressCommand>::decode(ArgumentDecoder* decoder, KeypressCommand& keypressCommand)
     203{
     204    if (!decoder->decode(keypressCommand.commandName))
     205        return false;
     206
     207    if (!decoder->decode(keypressCommand.text))
     208        return false;
     209
     210    return true;
     211}
     212
    195213} // namespace CoreIPC
Note: See TracChangeset for help on using the changeset viewer.