| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/input/input_param_traits.h" | 5 #include "content/common/input/input_param_traits.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/common/content_param_traits.h" | 9 #include "content/common/content_param_traits.h" |
| 10 #include "content/common/input/synthetic_pinch_gesture_params.h" | 10 #include "content/common/input/synthetic_pinch_gesture_params.h" |
| 11 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | 11 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
| 12 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 12 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 13 #include "content/common/input/web_input_event_traits.h" | 13 #include "content/common/input/web_input_event_traits.h" |
| 14 #include "content/common/input_messages.h" | 14 #include "content/common/input_messages.h" |
| 15 | 15 |
| 16 namespace IPC { | 16 namespace IPC { |
| 17 namespace { | 17 namespace { |
| 18 template <typename GestureType> | 18 template <typename GestureType> |
| 19 scoped_ptr<content::SyntheticGestureParams> ReadGestureParams( | 19 scoped_ptr<content::SyntheticGestureParams> ReadGestureParams( |
| 20 const Message* m, | 20 const base::Pickle* m, |
| 21 base::PickleIterator* iter) { | 21 base::PickleIterator* iter) { |
| 22 scoped_ptr<GestureType> gesture_params(new GestureType); | 22 scoped_ptr<GestureType> gesture_params(new GestureType); |
| 23 if (!ReadParam(m, iter, gesture_params.get())) | 23 if (!ReadParam(m, iter, gesture_params.get())) |
| 24 return scoped_ptr<content::SyntheticGestureParams>(); | 24 return scoped_ptr<content::SyntheticGestureParams>(); |
| 25 | 25 |
| 26 return std::move(gesture_params); | 26 return std::move(gesture_params); |
| 27 } | 27 } |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 void ParamTraits<content::ScopedWebInputEvent>::Write(Message* m, | 30 void ParamTraits<content::ScopedWebInputEvent>::Write(base::Pickle* m, |
| 31 const param_type& p) { | 31 const param_type& p) { |
| 32 bool valid_web_event = !!p; | 32 bool valid_web_event = !!p; |
| 33 WriteParam(m, valid_web_event); | 33 WriteParam(m, valid_web_event); |
| 34 if (valid_web_event) | 34 if (valid_web_event) |
| 35 WriteParam(m, static_cast<WebInputEventPointer>(p.get())); | 35 WriteParam(m, static_cast<WebInputEventPointer>(p.get())); |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool ParamTraits<content::ScopedWebInputEvent>::Read(const Message* m, | 38 bool ParamTraits<content::ScopedWebInputEvent>::Read(const base::Pickle* m, |
| 39 base::PickleIterator* iter, | 39 base::PickleIterator* iter, |
| 40 param_type* p) { | 40 param_type* p) { |
| 41 bool valid_web_event = false; | 41 bool valid_web_event = false; |
| 42 WebInputEventPointer web_event_pointer = NULL; | 42 WebInputEventPointer web_event_pointer = NULL; |
| 43 if (!ReadParam(m, iter, &valid_web_event) || | 43 if (!ReadParam(m, iter, &valid_web_event) || |
| 44 !valid_web_event || | 44 !valid_web_event || |
| 45 !ReadParam(m, iter, &web_event_pointer) || | 45 !ReadParam(m, iter, &web_event_pointer) || |
| 46 !web_event_pointer) | 46 !web_event_pointer) |
| 47 return false; | 47 return false; |
| 48 | 48 |
| 49 (*p) = content::WebInputEventTraits::Clone(*web_event_pointer); | 49 (*p) = content::WebInputEventTraits::Clone(*web_event_pointer); |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void ParamTraits<content::ScopedWebInputEvent>::Log(const param_type& p, | 53 void ParamTraits<content::ScopedWebInputEvent>::Log(const param_type& p, |
| 54 std::string* l) { | 54 std::string* l) { |
| 55 LogParam(static_cast<WebInputEventPointer>(p.get()), l); | 55 LogParam(static_cast<WebInputEventPointer>(p.get()), l); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void ParamTraits<content::SyntheticGesturePacket>::Write(Message* m, | 58 void ParamTraits<content::SyntheticGesturePacket>::Write(base::Pickle* m, |
| 59 const param_type& p) { | 59 const param_type& p) { |
| 60 DCHECK(p.gesture_params()); | 60 DCHECK(p.gesture_params()); |
| 61 WriteParam(m, p.gesture_params()->GetGestureType()); | 61 WriteParam(m, p.gesture_params()->GetGestureType()); |
| 62 switch (p.gesture_params()->GetGestureType()) { | 62 switch (p.gesture_params()->GetGestureType()) { |
| 63 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: | 63 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: |
| 64 WriteParam(m, *content::SyntheticSmoothScrollGestureParams::Cast( | 64 WriteParam(m, *content::SyntheticSmoothScrollGestureParams::Cast( |
| 65 p.gesture_params())); | 65 p.gesture_params())); |
| 66 break; | 66 break; |
| 67 case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE: | 67 case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE: |
| 68 WriteParam(m, *content::SyntheticSmoothDragGestureParams::Cast( | 68 WriteParam(m, *content::SyntheticSmoothDragGestureParams::Cast( |
| 69 p.gesture_params())); | 69 p.gesture_params())); |
| 70 break; | 70 break; |
| 71 case content::SyntheticGestureParams::PINCH_GESTURE: | 71 case content::SyntheticGestureParams::PINCH_GESTURE: |
| 72 WriteParam(m, *content::SyntheticPinchGestureParams::Cast( | 72 WriteParam(m, *content::SyntheticPinchGestureParams::Cast( |
| 73 p.gesture_params())); | 73 p.gesture_params())); |
| 74 break; | 74 break; |
| 75 case content::SyntheticGestureParams::TAP_GESTURE: | 75 case content::SyntheticGestureParams::TAP_GESTURE: |
| 76 WriteParam(m, *content::SyntheticTapGestureParams::Cast( | 76 WriteParam(m, *content::SyntheticTapGestureParams::Cast( |
| 77 p.gesture_params())); | 77 p.gesture_params())); |
| 78 break; | 78 break; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool ParamTraits<content::SyntheticGesturePacket>::Read( | 82 bool ParamTraits<content::SyntheticGesturePacket>::Read( |
| 83 const Message* m, | 83 const base::Pickle* m, |
| 84 base::PickleIterator* iter, | 84 base::PickleIterator* iter, |
| 85 param_type* p) { | 85 param_type* p) { |
| 86 content::SyntheticGestureParams::GestureType gesture_type; | 86 content::SyntheticGestureParams::GestureType gesture_type; |
| 87 if (!ReadParam(m, iter, &gesture_type)) | 87 if (!ReadParam(m, iter, &gesture_type)) |
| 88 return false; | 88 return false; |
| 89 scoped_ptr<content::SyntheticGestureParams> gesture_params; | 89 scoped_ptr<content::SyntheticGestureParams> gesture_params; |
| 90 switch (gesture_type) { | 90 switch (gesture_type) { |
| 91 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: | 91 case content::SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: |
| 92 gesture_params = | 92 gesture_params = |
| 93 ReadGestureParams<content::SyntheticSmoothScrollGestureParams>(m, | 93 ReadGestureParams<content::SyntheticSmoothScrollGestureParams>(m, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 break; | 135 break; |
| 136 case content::SyntheticGestureParams::TAP_GESTURE: | 136 case content::SyntheticGestureParams::TAP_GESTURE: |
| 137 LogParam( | 137 LogParam( |
| 138 *content::SyntheticTapGestureParams::Cast(p.gesture_params()), | 138 *content::SyntheticTapGestureParams::Cast(p.gesture_params()), |
| 139 l); | 139 l); |
| 140 break; | 140 break; |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 } // namespace IPC | 144 } // namespace IPC |
| OLD | NEW |