1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/input/input_param_traits.h"
7 #include "content/common/content_param_traits.h"
8 #include "content/common/input/synthetic_pinch_gesture_params.h"
9 #include "content/common/input/synthetic_smooth_drag_gesture_params.h"
10 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
11 #include "content/common/input/web_input_event_traits.h"
12 #include "content/common/input_messages.h"
16 template <typename GestureType
>
17 scoped_ptr
<content::SyntheticGestureParams
> ReadGestureParams(
19 base::PickleIterator
* iter
) {
20 scoped_ptr
<GestureType
> gesture_params(new GestureType
);
21 if (!ReadParam(m
, iter
, gesture_params
.get()))
22 return scoped_ptr
<content::SyntheticGestureParams
>();
24 return gesture_params
.Pass();
28 void ParamTraits
<content::ScopedWebInputEvent
>::Write(Message
* m
,
29 const param_type
& p
) {
30 bool valid_web_event
= !!p
;
31 WriteParam(m
, valid_web_event
);
33 WriteParam(m
, static_cast<WebInputEventPointer
>(p
.get()));
36 bool ParamTraits
<content::ScopedWebInputEvent
>::Read(const Message
* m
,
37 base::PickleIterator
* iter
,
39 bool valid_web_event
= false;
40 WebInputEventPointer web_event_pointer
= NULL
;
41 if (!ReadParam(m
, iter
, &valid_web_event
) ||
43 !ReadParam(m
, iter
, &web_event_pointer
) ||
47 (*p
) = content::WebInputEventTraits::Clone(*web_event_pointer
);
51 void ParamTraits
<content::ScopedWebInputEvent
>::Log(const param_type
& p
,
53 LogParam(static_cast<WebInputEventPointer
>(p
.get()), l
);
56 void ParamTraits
<content::SyntheticGesturePacket
>::Write(Message
* m
,
57 const param_type
& p
) {
58 DCHECK(p
.gesture_params());
59 WriteParam(m
, p
.gesture_params()->GetGestureType());
60 switch (p
.gesture_params()->GetGestureType()) {
61 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE
:
62 WriteParam(m
, *content::SyntheticSmoothScrollGestureParams::Cast(
65 case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE
:
66 WriteParam(m
, *content::SyntheticSmoothDragGestureParams::Cast(
69 case content::SyntheticGestureParams::PINCH_GESTURE
:
70 WriteParam(m
, *content::SyntheticPinchGestureParams::Cast(
73 case content::SyntheticGestureParams::TAP_GESTURE
:
74 WriteParam(m
, *content::SyntheticTapGestureParams::Cast(
80 bool ParamTraits
<content::SyntheticGesturePacket
>::Read(
82 base::PickleIterator
* iter
,
84 content::SyntheticGestureParams::GestureType gesture_type
;
85 if (!ReadParam(m
, iter
, &gesture_type
))
87 scoped_ptr
<content::SyntheticGestureParams
> gesture_params
;
88 switch (gesture_type
) {
89 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE
:
91 ReadGestureParams
<content::SyntheticSmoothScrollGestureParams
>(m
,
94 case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE
:
96 ReadGestureParams
<content::SyntheticSmoothDragGestureParams
>(m
, iter
);
98 case content::SyntheticGestureParams::PINCH_GESTURE
:
100 ReadGestureParams
<content::SyntheticPinchGestureParams
>(m
, iter
);
102 case content::SyntheticGestureParams::TAP_GESTURE
:
104 ReadGestureParams
<content::SyntheticTapGestureParams
>(m
, iter
);
110 p
->set_gesture_params(gesture_params
.Pass());
111 return p
->gesture_params() != NULL
;
114 void ParamTraits
<content::SyntheticGesturePacket
>::Log(const param_type
& p
,
116 DCHECK(p
.gesture_params());
117 switch (p
.gesture_params()->GetGestureType()) {
118 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE
:
120 *content::SyntheticSmoothScrollGestureParams::Cast(
124 case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE
:
126 *content::SyntheticSmoothDragGestureParams::Cast(p
.gesture_params()),
129 case content::SyntheticGestureParams::PINCH_GESTURE
:
131 *content::SyntheticPinchGestureParams::Cast(p
.gesture_params()),
134 case content::SyntheticGestureParams::TAP_GESTURE
:
136 *content::SyntheticTapGestureParams::Cast(p
.gesture_params()),