Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / common / input / input_param_traits.cc
blob2a5297c8a1c88c5f99cf085ae9057c4cae195970
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_scroll_gesture_params.h"
10 #include "content/common/input/web_input_event_traits.h"
11 #include "content/common/input_messages.h"
13 namespace IPC {
14 namespace {
15 template<typename GestureType>
16 scoped_ptr<content::SyntheticGestureParams> ReadGestureParams(
17 const Message* m,
18 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.template PassAs<content::SyntheticGestureParams>();
26 } // namespace
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);
32 if (valid_web_event)
33 WriteParam(m, static_cast<WebInputEventPointer>(p.get()));
36 bool ParamTraits<content::ScopedWebInputEvent>::Read(const Message* m,
37 PickleIterator* iter,
38 param_type* p) {
39 bool valid_web_event = false;
40 WebInputEventPointer web_event_pointer = NULL;
41 if (!ReadParam(m, iter, &valid_web_event) ||
42 !valid_web_event ||
43 !ReadParam(m, iter, &web_event_pointer) ||
44 !web_event_pointer)
45 return false;
47 (*p) = content::WebInputEventTraits::Clone(*web_event_pointer);
48 return true;
51 void ParamTraits<content::ScopedWebInputEvent>::Log(const param_type& p,
52 std::string* l) {
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(
63 p.gesture_params()));
64 break;
65 case content::SyntheticGestureParams::PINCH_GESTURE:
66 WriteParam(m, *content::SyntheticPinchGestureParams::Cast(
67 p.gesture_params()));
68 break;
69 case content::SyntheticGestureParams::TAP_GESTURE:
70 WriteParam(m, *content::SyntheticTapGestureParams::Cast(
71 p.gesture_params()));
72 break;
76 bool ParamTraits<content::SyntheticGesturePacket>::Read(const Message* m,
77 PickleIterator* iter,
78 param_type* p) {
79 content::SyntheticGestureParams::GestureType gesture_type;
80 if (!ReadParam(m, iter, &gesture_type))
81 return false;
82 scoped_ptr<content::SyntheticGestureParams> gesture_params;
83 switch (gesture_type) {
84 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE:
85 gesture_params =
86 ReadGestureParams<content::SyntheticSmoothScrollGestureParams>(m,
87 iter);
88 break;
89 case content::SyntheticGestureParams::PINCH_GESTURE:
90 gesture_params =
91 ReadGestureParams<content::SyntheticPinchGestureParams>(m, iter);
92 break;
93 case content::SyntheticGestureParams::TAP_GESTURE:
94 gesture_params =
95 ReadGestureParams<content::SyntheticTapGestureParams>(m, iter);
96 break;
97 default:
98 return false;
101 p->set_gesture_params(gesture_params.Pass());
102 return p->gesture_params() != NULL;
105 void ParamTraits<content::SyntheticGesturePacket>::Log(const param_type& p,
106 std::string* l) {
107 DCHECK(p.gesture_params());
108 switch (p.gesture_params()->GetGestureType()) {
109 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE:
110 LogParam(
111 *content::SyntheticSmoothScrollGestureParams::Cast(
112 p.gesture_params()),
114 break;
115 case content::SyntheticGestureParams::PINCH_GESTURE:
116 LogParam(
117 *content::SyntheticPinchGestureParams::Cast(p.gesture_params()),
119 break;
120 case content::SyntheticGestureParams::TAP_GESTURE:
121 LogParam(
122 *content::SyntheticTapGestureParams::Cast(p.gesture_params()),
124 break;
128 } // namespace IPC