2 * Copyright (C) 2008 Apple 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
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #if ENABLE(NETSCAPE_PLUGIN_API)
28 #import "WebNetscapePluginEventHandlerCocoa.h"
30 #import "WebBaseNetscapePluginViewInternal.h"
32 WebNetscapePluginEventHandlerCocoa::WebNetscapePluginEventHandlerCocoa(WebBaseNetscapePluginView* pluginView)
33 : WebNetscapePluginEventHandler(pluginView)
37 void WebNetscapePluginEventHandlerCocoa::drawRect(const NSRect& rect)
41 event.type = NPCocoaEventDrawRect;
42 event.event.draw.x = rect.origin.x;
43 event.event.draw.y = rect.origin.y;
44 event.event.draw.width = rect.size.width;
45 event.event.draw.height = rect.size.height;
50 void WebNetscapePluginEventHandlerCocoa::mouseDown(NSEvent *event)
52 sendMouseEvent(event, NPCocoaEventMouseDown);
55 void WebNetscapePluginEventHandlerCocoa::mouseDragged(NSEvent *event)
57 sendMouseEvent(event, NPCocoaEventMouseDragged);
60 void WebNetscapePluginEventHandlerCocoa::mouseEntered(NSEvent *event)
62 sendMouseEvent(event, NPCocoaEventMouseEntered);
65 void WebNetscapePluginEventHandlerCocoa::mouseExited(NSEvent *event)
67 sendMouseEvent(event, NPCocoaEventMouseExited);
70 void WebNetscapePluginEventHandlerCocoa::mouseMoved(NSEvent *event)
72 sendMouseEvent(event, NPCocoaEventMouseMoved);
75 void WebNetscapePluginEventHandlerCocoa::mouseUp(NSEvent *event)
77 sendMouseEvent(event, NPCocoaEventMouseUp);
80 bool WebNetscapePluginEventHandlerCocoa::scrollWheel(NSEvent* event)
82 return sendMouseEvent(event, NPCocoaEventScrollWheel);
85 bool WebNetscapePluginEventHandlerCocoa::sendMouseEvent(NSEvent *nsEvent, NPCocoaEventType type)
89 NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
92 if (type == NPCocoaEventMouseEntered || type == NPCocoaEventMouseExited || type == NPCocoaEventScrollWheel)
95 clickCount = [nsEvent clickCount];
98 event.event.mouse.modifierFlags = [nsEvent modifierFlags];
99 event.event.mouse.buttonNumber = [nsEvent buttonNumber];
100 event.event.mouse.clickCount = clickCount;
101 event.event.mouse.pluginX = point.x;
102 event.event.mouse.pluginY = point.y;
103 event.event.mouse.deltaX = [nsEvent deltaX];
104 event.event.mouse.deltaY = [nsEvent deltaY];
105 event.event.mouse.deltaZ = [nsEvent deltaZ];
107 return sendEvent(&event);
110 void WebNetscapePluginEventHandlerCocoa::keyDown(NSEvent *event)
112 bool retval = sendKeyEvent(event, NPCocoaEventKeyDown);
114 // If the plug-in did not handle the event, pass it on to the Input Manager.
116 [m_pluginView interpretKeyEvents:[NSArray arrayWithObject:event]];
119 void WebNetscapePluginEventHandlerCocoa::keyUp(NSEvent *event)
121 sendKeyEvent(event, NPCocoaEventKeyUp);
124 void WebNetscapePluginEventHandlerCocoa::flagsChanged(NSEvent *nsEvent)
128 event.type = NPCocoaEventFlagsChanged;
129 event.event.key.modifierFlags = [nsEvent modifierFlags];
130 event.event.key.keyCode = [nsEvent keyCode];
131 event.event.key.isARepeat = false;
132 event.event.key.characters = 0;
133 event.event.key.charactersIgnoringModifiers = 0;
138 bool WebNetscapePluginEventHandlerCocoa::sendKeyEvent(NSEvent* nsEvent, NPCocoaEventType type)
143 event.event.key.modifierFlags = [nsEvent modifierFlags];
144 event.event.key.keyCode = [nsEvent keyCode];
145 event.event.key.isARepeat = [nsEvent isARepeat];
146 event.event.key.characters = (NPNSString *)[nsEvent characters];
147 event.event.key.charactersIgnoringModifiers = (NPNSString *)[nsEvent charactersIgnoringModifiers];
149 return sendEvent(&event);
152 void WebNetscapePluginEventHandlerCocoa::windowFocusChanged(bool hasFocus)
156 event.type = NPCocoaEventWindowFocusChanged;
157 event.event.focus.hasFocus = hasFocus;
162 void WebNetscapePluginEventHandlerCocoa::focusChanged(bool hasFocus)
166 event.type = NPCocoaEventFocusChanged;
167 event.event.focus.hasFocus = hasFocus;
172 void* WebNetscapePluginEventHandlerCocoa::platformWindow(NSWindow* window)
177 bool WebNetscapePluginEventHandlerCocoa::sendEvent(NPCocoaEvent* event)
179 switch (event->type) {
180 case NPCocoaEventMouseDown:
181 case NPCocoaEventMouseUp:
182 case NPCocoaEventMouseDragged:
183 case NPCocoaEventKeyDown:
184 case NPCocoaEventKeyUp:
185 case NPCocoaEventFlagsChanged:
186 case NPCocoaEventScrollWheel:
187 m_currentEventIsUserGesture = true;
190 m_currentEventIsUserGesture = false;
193 bool result = [m_pluginView sendEvent:event isDrawRect:event->type == NPCocoaEventDrawRect];
195 m_currentEventIsUserGesture = false;
199 #endif // ENABLE(NETSCAPE_PLUGIN_API)