2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "WebInputEventFactory.h"
34 #include "WebInputEvent.h"
35 #include "platform/KeyCodeConversion.h"
36 #include "platform/KeyboardCodes.h"
37 #include "wtf/Assertions.h"
41 WebKeyboardEvent WebInputEventFactory::keyboardEvent(WebInputEvent::Type type,
43 double timeStampSeconds,
45 WebUChar unicodeCharacter,
48 WebKeyboardEvent result;
51 result.modifiers = modifiers;
52 result.timeStampSeconds = timeStampSeconds;
53 int windowsKeyCode = WebCore::windowsKeyCodeForKeyEvent(keycode);
54 result.windowsKeyCode = WebKeyboardEvent::windowsKeyCodeWithoutLocation(windowsKeyCode);
55 result.modifiers |= WebKeyboardEvent::locationModifiersFromWindowsKeyCode(windowsKeyCode);
56 result.nativeKeyCode = keycode;
57 result.unmodifiedText[0] = unicodeCharacter;
58 if (result.windowsKeyCode == WebCore::VKEY_RETURN) {
59 // This is the same behavior as GTK:
60 // We need to treat the enter key as a key press of character \r. This
61 // is apparently just how webkit handles it and what it expects.
62 result.unmodifiedText[0] = '\r';
64 result.text[0] = result.unmodifiedText[0];
65 result.setKeyIdentifierFromWindowsKeyCode();
66 result.isSystemKey = isSystemKey;
71 WebMouseEvent WebInputEventFactory::mouseEvent(MouseEventType type,
72 WebMouseEvent::Button button,
73 double timeStampSeconds,
83 result.windowX = windowX;
84 result.windowY = windowY;
85 result.timeStampSeconds = timeStampSeconds;
86 result.clickCount = clickCount;
87 result.modifiers = modifiers;
90 case MouseEventTypeDown:
91 result.type = WebInputEvent::MouseDown;
92 result.button = button;
94 case MouseEventTypeUp:
95 result.type = WebInputEvent::MouseUp;
96 result.button = button;
98 case MouseEventTypeMove:
99 result.type = WebInputEvent::MouseMove;
100 result.button = WebMouseEvent::ButtonNone;
107 bool WebInputEventFactory::isSystemKeyEvent(const WebKeyboardEvent& event)
109 // On Windows all keys with Alt modifier will be marked as system key.
110 // We keep the same behavior on Linux and everywhere non-Mac.
111 return event.modifiers & WebInputEvent::AltKey;
114 // WebMouseWheelEvent ------------------------------------------------------------
116 WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(MouseWheelDirectionType direction,
117 double timeStampSeconds,
121 WebMouseWheelEvent result;
123 result.type = WebInputEvent::MouseWheel;
126 result.windowX = windowX;
127 result.windowY = windowY;
128 result.timeStampSeconds = timeStampSeconds;
129 result.button = WebMouseEvent::ButtonNone;
131 // The below choices are matched from GTK.
132 static const float scrollbarPixelsPerTick = 160.0f / 3.0f;
135 case MouseWheelDirectionTypeUp:
136 result.deltaY = scrollbarPixelsPerTick;
137 result.wheelTicksY = 1;
139 case MouseWheelDirectionTypeDown:
140 result.deltaY = -scrollbarPixelsPerTick;
141 result.wheelTicksY = -1;
143 case MouseWheelDirectionTypeLeft:
144 result.deltaX = scrollbarPixelsPerTick;
145 result.wheelTicksX = 1;
147 case MouseWheelDirectionTypeRight:
148 result.deltaX = -scrollbarPixelsPerTick;
149 result.wheelTicksX = -1;
156 // WebGestureEvent ------------------------------------------------------------
158 // FIXME: remove this obsolete version
159 WebGestureEvent WebInputEventFactory::gestureEvent(WebInputEvent::Type type,
160 double timeStampSeconds,
166 return gestureEvent(type, timeStampSeconds, x, y, modifiers);
169 WebGestureEvent WebInputEventFactory::gestureEvent(WebInputEvent::Type type,
170 double timeStampSeconds,
175 WebGestureEvent result;
180 result.timeStampSeconds = timeStampSeconds;
181 result.modifiers = modifiers;