ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / common / input / input_param_traits.cc
blob1f4b7e4b1630a25d075de7b75e3d2a7c208cb6cc
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"
14 namespace IPC {
15 namespace {
16 template<typename GestureType>
17 scoped_ptr<content::SyntheticGestureParams> ReadGestureParams(
18 const Message* m,
19 PickleIterator* iter)
21 scoped_ptr<GestureType> gesture_params(new GestureType);
22 if (!ReadParam(m, iter, gesture_params.get()))
23 return scoped_ptr<content::SyntheticGestureParams>();
25 return gesture_params.Pass();
27 } // namespace
29 void ParamTraits<content::ScopedWebInputEvent>::Write(Message* m,
30 const param_type& p) {
31 bool valid_web_event = !!p;
32 WriteParam(m, valid_web_event);
33 if (valid_web_event)
34 WriteParam(m, static_cast<WebInputEventPointer>(p.get()));
37 bool ParamTraits<content::ScopedWebInputEvent>::Read(const Message* m,
38 PickleIterator* iter,
39 param_type* p) {
40 bool valid_web_event = false;
41 WebInputEventPointer web_event_pointer = NULL;
42 if (!ReadParam(m, iter, &valid_web_event) ||
43 !valid_web_event ||
44 !ReadParam(m, iter, &web_event_pointer) ||
45 !web_event_pointer)
46 return false;
48 (*p) = content::WebInputEventTraits::Clone(*web_event_pointer);
49 return true;
52 void ParamTraits<content::ScopedWebInputEvent>::Log(const param_type& p,
53 std::string* l) {
54 LogParam(static_cast<WebInputEventPointer>(p.get()), l);
57 void ParamTraits<content::SyntheticGesturePacket>::Write(Message* m,
58 const param_type& p) {
59 DCHECK(p.gesture_params());
60 WriteParam(m, p.gesture_params()->GetGestureType());
61 switch (p.gesture_params()->GetGestureType()) {
62 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE:
63 WriteParam(m, *content::SyntheticSmoothScrollGestureParams::Cast(
64 p.gesture_params()));
65 break;
66 case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
67 WriteParam(m, *content::SyntheticSmoothDragGestureParams::Cast(
68 p.gesture_params()));
69 break;
70 case content::SyntheticGestureParams::PINCH_GESTURE:
71 WriteParam(m, *content::SyntheticPinchGestureParams::Cast(
72 p.gesture_params()));
73 break;
74 case content::SyntheticGestureParams::TAP_GESTURE:
75 WriteParam(m, *content::SyntheticTapGestureParams::Cast(
76 p.gesture_params()));
77 break;
81 bool ParamTraits<content::SyntheticGesturePacket>::Read(const Message* m,
82 PickleIterator* iter,
83 param_type* p) {
84 content::SyntheticGestureParams::GestureType gesture_type;
85 if (!ReadParam(m, iter, &gesture_type))
86 return false;
87 scoped_ptr<content::SyntheticGestureParams> gesture_params;
88 switch (gesture_type) {
89 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE:
90 gesture_params =
91 ReadGestureParams<content::SyntheticSmoothScrollGestureParams>(m,
92 iter);
93 break;
94 case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
95 gesture_params =
96 ReadGestureParams<content::SyntheticSmoothDragGestureParams>(m, iter);
97 break;
98 case content::SyntheticGestureParams::PINCH_GESTURE:
99 gesture_params =
100 ReadGestureParams<content::SyntheticPinchGestureParams>(m, iter);
101 break;
102 case content::SyntheticGestureParams::TAP_GESTURE:
103 gesture_params =
104 ReadGestureParams<content::SyntheticTapGestureParams>(m, iter);
105 break;
106 default:
107 return false;
110 p->set_gesture_params(gesture_params.Pass());
111 return p->gesture_params() != NULL;
114 void ParamTraits<content::SyntheticGesturePacket>::Log(const param_type& p,
115 std::string* l) {
116 DCHECK(p.gesture_params());
117 switch (p.gesture_params()->GetGestureType()) {
118 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE:
119 LogParam(
120 *content::SyntheticSmoothScrollGestureParams::Cast(
121 p.gesture_params()),
123 break;
124 case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
125 LogParam(
126 *content::SyntheticSmoothDragGestureParams::Cast(p.gesture_params()),
128 break;
129 case content::SyntheticGestureParams::PINCH_GESTURE:
130 LogParam(
131 *content::SyntheticPinchGestureParams::Cast(p.gesture_params()),
133 break;
134 case content::SyntheticGestureParams::TAP_GESTURE:
135 LogParam(
136 *content::SyntheticTapGestureParams::Cast(p.gesture_params()),
138 break;
142 } // namespace IPC