1// Copyright (c) 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.
4
5// IPC messages for input events and other messages that require processing in
6// order relative to input events.
7// Multiply-included message file, hence no include guard.
8
9#include "base/strings/string16.h"
10#include "content/common/content_export.h"
11#include "content/common/content_param_traits.h"
12#include "content/common/edit_command.h"
13#include "content/common/input/did_overscroll_params.h"
14#include "content/common/input/input_event.h"
15#include "content/common/input/input_event_ack_state.h"
16#include "content/common/input/input_param_traits.h"
17#include "content/common/input/synthetic_gesture_packet.h"
18#include "content/common/input/synthetic_gesture_params.h"
19#include "content/common/input/synthetic_pinch_gesture_params.h"
20#include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
21#include "content/common/input/synthetic_tap_gesture_params.h"
22#include "content/public/common/common_param_traits.h"
23#include "content/common/input/touch_action.h"
24#include "ipc/ipc_message_macros.h"
25#include "third_party/WebKit/public/web/WebInputEvent.h"
26#include "ui/events/ipc/latency_info_param_traits.h"
27#include "ui/gfx/point.h"
28#include "ui/gfx/rect.h"
29#include "ui/gfx/vector2d_f.h"
30
31#undef IPC_MESSAGE_EXPORT
32#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
33
34#ifdef IPC_MESSAGE_START
35#error IPC_MESSAGE_START
36#endif
37
38#define IPC_MESSAGE_START InputMsgStart
39
40IPC_ENUM_TRAITS_MAX_VALUE(content::InputEventAckState,
41                          content::INPUT_EVENT_ACK_STATE_MAX)
42IPC_ENUM_TRAITS_MAX_VALUE(
43    content::SyntheticGestureParams::GestureSourceType,
44    content::SyntheticGestureParams::GESTURE_SOURCE_TYPE_MAX)
45IPC_ENUM_TRAITS_MAX_VALUE(
46    content::SyntheticGestureParams::GestureType,
47    content::SyntheticGestureParams::SYNTHETIC_GESTURE_TYPE_MAX)
48IPC_ENUM_TRAITS_VALIDATE(content::TouchAction, (
49    value >= 0 &&
50    value <= content::TOUCH_ACTION_MAX &&
51    (!(value & content::TOUCH_ACTION_NONE) ||
52        (value == content::TOUCH_ACTION_NONE)) &&
53    (!(value & content::TOUCH_ACTION_PINCH_ZOOM) ||
54        (value == content::TOUCH_ACTION_MANIPULATION))))
55
56IPC_STRUCT_TRAITS_BEGIN(content::DidOverscrollParams)
57  IPC_STRUCT_TRAITS_MEMBER(accumulated_overscroll)
58  IPC_STRUCT_TRAITS_MEMBER(latest_overscroll_delta)
59  IPC_STRUCT_TRAITS_MEMBER(current_fling_velocity)
60IPC_STRUCT_TRAITS_END()
61
62IPC_STRUCT_TRAITS_BEGIN(content::EditCommand)
63  IPC_STRUCT_TRAITS_MEMBER(name)
64  IPC_STRUCT_TRAITS_MEMBER(value)
65IPC_STRUCT_TRAITS_END()
66
67IPC_STRUCT_TRAITS_BEGIN(content::InputEvent)
68  IPC_STRUCT_TRAITS_MEMBER(web_event)
69  IPC_STRUCT_TRAITS_MEMBER(latency_info)
70  IPC_STRUCT_TRAITS_MEMBER(is_keyboard_shortcut)
71IPC_STRUCT_TRAITS_END()
72
73IPC_STRUCT_TRAITS_BEGIN(content::SyntheticGestureParams)
74  IPC_STRUCT_TRAITS_MEMBER(gesture_source_type)
75IPC_STRUCT_TRAITS_END()
76
77IPC_STRUCT_TRAITS_BEGIN(content::SyntheticSmoothScrollGestureParams)
78  IPC_STRUCT_TRAITS_PARENT(content::SyntheticGestureParams)
79  IPC_STRUCT_TRAITS_MEMBER(anchor)
80  IPC_STRUCT_TRAITS_MEMBER(distances)
81  IPC_STRUCT_TRAITS_MEMBER(prevent_fling)
82  IPC_STRUCT_TRAITS_MEMBER(speed_in_pixels_s)
83IPC_STRUCT_TRAITS_END()
84
85IPC_STRUCT_TRAITS_BEGIN(content::SyntheticPinchGestureParams)
86  IPC_STRUCT_TRAITS_PARENT(content::SyntheticGestureParams)
87  IPC_STRUCT_TRAITS_MEMBER(scale_factor)
88  IPC_STRUCT_TRAITS_MEMBER(anchor)
89  IPC_STRUCT_TRAITS_MEMBER(relative_pointer_speed_in_pixels_s)
90IPC_STRUCT_TRAITS_END()
91
92IPC_STRUCT_TRAITS_BEGIN(content::SyntheticTapGestureParams)
93  IPC_STRUCT_TRAITS_PARENT(content::SyntheticGestureParams)
94  IPC_STRUCT_TRAITS_MEMBER(position)
95  IPC_STRUCT_TRAITS_MEMBER(duration_ms)
96IPC_STRUCT_TRAITS_END()
97
98IPC_STRUCT_BEGIN(InputHostMsg_HandleInputEvent_ACK_Params)
99  IPC_STRUCT_MEMBER(blink::WebInputEvent::Type, type)
100  IPC_STRUCT_MEMBER(content::InputEventAckState, state)
101  IPC_STRUCT_MEMBER(ui::LatencyInfo, latency)
102  // TODO(jdduke): Use Optional<T> type to avoid heap alloc, crbug.com/375002.
103  IPC_STRUCT_MEMBER(scoped_ptr<content::DidOverscrollParams>, overscroll)
104IPC_STRUCT_END()
105
106// Sends an input event to the render widget.
107IPC_MESSAGE_ROUTED3(InputMsg_HandleInputEvent,
108                    IPC::WebInputEventPointer /* event */,
109                    ui::LatencyInfo /* latency_info */,
110                    bool /* is_keyboard_shortcut */)
111
112// Sends the cursor visibility state to the render widget.
113IPC_MESSAGE_ROUTED1(InputMsg_CursorVisibilityChange,
114                    bool /* is_visible */)
115
116// This message notifies the renderer that the next key event is bound to one
117// or more pre-defined edit commands. If the next key event is not handled
118// by webkit, the specified edit commands shall be executed against current
119// focused frame.
120// Parameters
121// * edit_commands (see chrome/common/edit_command_types.h)
122//   Contains one or more edit commands.
123// See third_party/WebKit/Source/WebCore/editing/EditorCommand.cpp for detailed
124// definition of webkit edit commands.
125//
126// This message must be sent just before sending a key event.
127IPC_MESSAGE_ROUTED1(InputMsg_SetEditCommandsForNextKeyEvent,
128                    std::vector<content::EditCommand> /* edit_commands */)
129
130// Message payload is the name/value of a WebCore edit command to execute.
131IPC_MESSAGE_ROUTED2(InputMsg_ExecuteEditCommand,
132                    std::string, /* name */
133                    std::string /* value */)
134
135IPC_MESSAGE_ROUTED0(InputMsg_MouseCaptureLost)
136
137// TODO(darin): figure out how this meshes with RestoreFocus
138IPC_MESSAGE_ROUTED1(InputMsg_SetFocus,
139                    bool /* enable */)
140
141// Tells the renderer to scroll the currently focused node into rect only if
142// the currently focused node is a Text node (textfield, text area or content
143// editable divs).
144IPC_MESSAGE_ROUTED1(InputMsg_ScrollFocusedEditableNodeIntoRect, gfx::Rect)
145
146// These messages are typically generated from context menus and request the
147// renderer to apply the specified operation to the current selection.
148IPC_MESSAGE_ROUTED0(InputMsg_Undo)
149IPC_MESSAGE_ROUTED0(InputMsg_Redo)
150IPC_MESSAGE_ROUTED0(InputMsg_Cut)
151IPC_MESSAGE_ROUTED0(InputMsg_Copy)
152#if defined(OS_MACOSX)
153IPC_MESSAGE_ROUTED0(InputMsg_CopyToFindPboard)
154#endif
155IPC_MESSAGE_ROUTED0(InputMsg_Paste)
156IPC_MESSAGE_ROUTED0(InputMsg_PasteAndMatchStyle)
157// Replaces the selected region or a word around the cursor with the
158// specified string.
159IPC_MESSAGE_ROUTED1(InputMsg_Replace,
160                    base::string16)
161// Replaces the misspelling in the selected region with the specified string.
162IPC_MESSAGE_ROUTED1(InputMsg_ReplaceMisspelling,
163                    base::string16)
164IPC_MESSAGE_ROUTED0(InputMsg_Delete)
165IPC_MESSAGE_ROUTED0(InputMsg_SelectAll)
166
167IPC_MESSAGE_ROUTED0(InputMsg_Unselect)
168
169// Requests the renderer to select the region between two points.
170// Expects a SelectRange_ACK message when finished.
171IPC_MESSAGE_ROUTED2(InputMsg_SelectRange,
172                    gfx::Point /* start */,
173                    gfx::Point /* end */)
174
175// Requests the renderer to move the caret selection toward the point.
176// Expects a MoveCaret_ACK message when finished.
177IPC_MESSAGE_ROUTED1(InputMsg_MoveCaret,
178                    gfx::Point /* location */)
179
180#if defined(OS_ANDROID)
181// Sent when the user clicks on the find result bar to activate a find result.
182// The point (x,y) is in fractions of the content document's width and height.
183IPC_MESSAGE_ROUTED3(InputMsg_ActivateNearestFindResult,
184                    int /* request_id */,
185                    float /* x */,
186                    float /* y */)
187#endif
188
189IPC_MESSAGE_ROUTED0(InputMsg_SyntheticGestureCompleted);
190
191// -----------------------------------------------------------------------------
192// Messages sent from the renderer to the browser.
193
194// Acknowledges receipt of a InputMsg_HandleInputEvent message.
195IPC_MESSAGE_ROUTED1(InputHostMsg_HandleInputEvent_ACK,
196                    InputHostMsg_HandleInputEvent_ACK_Params)
197
198IPC_MESSAGE_ROUTED1(InputHostMsg_QueueSyntheticGesture,
199                    content::SyntheticGesturePacket)
200
201// Notifies the allowed touch actions for a new touch point.
202IPC_MESSAGE_ROUTED1(InputHostMsg_SetTouchAction,
203                    content::TouchAction /* touch_action */)
204
205// Sent by the compositor when input scroll events are dropped due to bounds
206// restrictions on the root scroll offset.
207IPC_MESSAGE_ROUTED1(InputHostMsg_DidOverscroll,
208                    content::DidOverscrollParams /* params */)
209
210// Adding a new message? Stick to the sort order above: first platform
211// independent InputMsg, then ifdefs for platform specific InputMsg, then
212// platform independent InputHostMsg, then ifdefs for platform specific
213// InputHostMsg.
214