|
1 /* |
|
2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * 1. Redistributions of source code must retain the above copyright |
|
8 * notice, this list of conditions and the following disclaimer. |
|
9 * 2. Redistributions in binary form must reproduce the above copyright |
|
10 * notice, this list of conditions and the following disclaimer in the |
|
11 * documentation and/or other materials provided with the distribution. |
|
12 * |
|
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
|
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
|
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
|
23 * THE POSSIBILITY OF SUCH DAMAGE. |
|
24 */ |
|
25 |
|
26 #include "WebEventConversion.h" |
|
27 |
|
28 #include "WebEvent.h" |
|
29 #include <WebCore/IntPoint.h> |
|
30 |
|
31 namespace WebKit { |
|
32 |
|
33 class WebKit2PlatformMouseEvent : public WebCore::PlatformMouseEvent { |
|
34 public: |
|
35 WebKit2PlatformMouseEvent(const WebMouseEvent& webEvent) |
|
36 { |
|
37 switch (webEvent.type()) { |
|
38 case WebEvent::MouseDown: |
|
39 m_eventType = WebCore::MouseEventPressed; |
|
40 break; |
|
41 case WebEvent::MouseUp: |
|
42 m_eventType = WebCore::MouseEventReleased; |
|
43 break; |
|
44 case WebEvent::MouseMove: |
|
45 m_eventType = WebCore::MouseEventMoved; |
|
46 break; |
|
47 default: |
|
48 ASSERT_NOT_REACHED(); |
|
49 } |
|
50 |
|
51 switch (webEvent.button()) { |
|
52 case WebMouseEvent::NoButton: |
|
53 m_button = WebCore::NoButton; |
|
54 break; |
|
55 case WebMouseEvent::LeftButton: |
|
56 m_button = WebCore::LeftButton; |
|
57 break; |
|
58 case WebMouseEvent::MiddleButton: |
|
59 m_button = WebCore::MiddleButton; |
|
60 break; |
|
61 case WebMouseEvent::RightButton: |
|
62 m_button = WebCore::RightButton; |
|
63 break; |
|
64 default: |
|
65 ASSERT_NOT_REACHED(); |
|
66 } |
|
67 |
|
68 m_position = WebCore::IntPoint(webEvent.positionX(), webEvent.positionY()); |
|
69 m_globalPosition = WebCore::IntPoint(webEvent.globalPositionX(), webEvent.globalPositionY()); |
|
70 m_clickCount = webEvent.clickCount(); |
|
71 m_timestamp = webEvent.timestamp(); |
|
72 m_shiftKey = webEvent.shiftKey(); |
|
73 m_ctrlKey = webEvent.controlKey(); |
|
74 m_altKey = webEvent.altKey(); |
|
75 m_metaKey = webEvent.metaKey(); |
|
76 |
|
77 m_modifierFlags = 0; |
|
78 } |
|
79 }; |
|
80 |
|
81 WebCore::PlatformMouseEvent platform(const WebMouseEvent& webEvent) |
|
82 { |
|
83 return WebKit2PlatformMouseEvent(webEvent); |
|
84 } |
|
85 |
|
86 class WebKit2PlatformWheelEvent : public WebCore::PlatformWheelEvent { |
|
87 public: |
|
88 WebKit2PlatformWheelEvent(const WebWheelEvent& webEvent) |
|
89 { |
|
90 m_position = WebCore::IntPoint(webEvent.positionX(), webEvent.positionY()); |
|
91 m_globalPosition = WebCore::IntPoint(webEvent.globalPositionX(), webEvent.globalPositionY()); |
|
92 m_deltaX = webEvent.deltaX(); |
|
93 m_deltaY = webEvent.deltaY(); |
|
94 m_wheelTicksX = webEvent.wheelTicksX(); |
|
95 m_wheelTicksY = webEvent.wheelTicksY(); |
|
96 m_granularity = (webEvent.granularity() == WebWheelEvent::ScrollByPageWheelEvent) ? WebCore::ScrollByPageWheelEvent : WebCore::ScrollByPixelWheelEvent; |
|
97 m_shiftKey = webEvent.shiftKey(); |
|
98 m_ctrlKey = webEvent.controlKey(); |
|
99 m_altKey = webEvent.altKey(); |
|
100 m_metaKey = webEvent.metaKey(); |
|
101 } |
|
102 }; |
|
103 |
|
104 WebCore::PlatformWheelEvent platform(const WebWheelEvent& webEvent) |
|
105 { |
|
106 return WebKit2PlatformWheelEvent(webEvent); |
|
107 } |
|
108 |
|
109 class WebKit2PlatformKeyboardEvent : public WebCore::PlatformKeyboardEvent { |
|
110 public: |
|
111 WebKit2PlatformKeyboardEvent(const WebKeyboardEvent& webEvent) |
|
112 { |
|
113 switch (webEvent.type()) { |
|
114 case WebEvent::KeyDown: |
|
115 m_type = PlatformKeyboardEvent::KeyDown; |
|
116 break; |
|
117 case WebEvent::KeyUp: |
|
118 m_type = PlatformKeyboardEvent::KeyUp; |
|
119 break; |
|
120 case WebEvent::RawKeyDown: |
|
121 m_type = PlatformKeyboardEvent::RawKeyDown; |
|
122 break; |
|
123 case WebEvent::Char: |
|
124 m_type = PlatformKeyboardEvent::Char; |
|
125 break; |
|
126 default: |
|
127 ASSERT_NOT_REACHED(); |
|
128 } |
|
129 m_text = webEvent.text(); |
|
130 m_unmodifiedText = webEvent.unmodifiedText(); |
|
131 m_keyIdentifier = webEvent.keyIdentifier(); |
|
132 m_windowsVirtualKeyCode = webEvent.windowsVirtualKeyCode(); |
|
133 m_nativeVirtualKeyCode = webEvent.nativeVirtualKeyCode(); |
|
134 m_autoRepeat = webEvent.isAutoRepeat(); |
|
135 m_isKeypad = webEvent.isKeypad(); |
|
136 m_shiftKey = webEvent.shiftKey(); |
|
137 m_ctrlKey = webEvent.controlKey(); |
|
138 m_altKey = webEvent.altKey(); |
|
139 m_metaKey = webEvent.metaKey(); |
|
140 |
|
141 #if PLATFORM(WIN) |
|
142 // FIXME: We should make m_isSystemKey available (and false) on all platforms |
|
143 // to avoid this #define. |
|
144 m_isSystemKey = webEvent.isSystemKey(); |
|
145 #endif |
|
146 } |
|
147 }; |
|
148 |
|
149 WebCore::PlatformKeyboardEvent platform(const WebKeyboardEvent& webEvent) |
|
150 { |
|
151 return WebKit2PlatformKeyboardEvent(webEvent); |
|
152 } |
|
153 |
|
154 } // namespace WebKit |