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.draw.x = rect.origin.x;
43 event.draw.y = rect.origin.y;
44 event.draw.width = rect.size.width;
45 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 event.mouse.modifierFlags = [nsEvent modifierFlags];
93 event.mouse.buttonNumber = [nsEvent buttonNumber];
94 event.mouse.pluginX = point.x;
95 event.mouse.pluginY = point.y;
96 event.mouse.deltaX = [nsEvent deltaX];
97 event.mouse.deltaY = [nsEvent deltaY];
98 event.mouse.deltaZ = [nsEvent deltaZ];
100 return sendEvent(&event);
103 void WebNetscapePluginEventHandlerCocoa::keyDown(NSEvent *event)
105 sendKeyEvent(event, NPCocoaEventKeyDown);
108 void WebNetscapePluginEventHandlerCocoa::keyUp(NSEvent *event)
110 sendKeyEvent(event, NPCocoaEventKeyUp);
113 void WebNetscapePluginEventHandlerCocoa::flagsChanged(NSEvent *nsEvent)
117 NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
119 event.type = NPCocoaEventFlagsChanged;
120 event.key.modifierFlags = [nsEvent modifierFlags];
121 event.key.pluginX = point.x;
122 event.key.pluginY = point.y;
123 event.key.keyCode = [nsEvent keyCode];
124 event.key.isARepeat = false;
125 event.key.characters = 0;
126 event.key.charactersIgnoringModifiers = 0;
131 void WebNetscapePluginEventHandlerCocoa::sendKeyEvent(NSEvent* nsEvent, NPCocoaEventType type)
135 NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
138 event.key.modifierFlags = [nsEvent modifierFlags];
139 event.key.pluginX = point.x;
140 event.key.pluginY = point.y;
141 event.key.keyCode = [nsEvent keyCode];
142 event.key.isARepeat = [nsEvent isARepeat];
143 event.key.characters = (NPNSString *)[nsEvent characters];
144 event.key.charactersIgnoringModifiers = (NPNSString *)[nsEvent charactersIgnoringModifiers];
149 void WebNetscapePluginEventHandlerCocoa::windowFocusChanged(bool hasFocus)
153 event.type = NPCocoaEventWindowFocusChanged;
154 event.focus.hasFocus = hasFocus;
159 void WebNetscapePluginEventHandlerCocoa::focusChanged(bool hasFocus)
163 event.type = NPCocoaEventFocusChanged;
164 event.focus.hasFocus = hasFocus;
169 void* WebNetscapePluginEventHandlerCocoa::platformWindow(NSWindow* window)
174 bool WebNetscapePluginEventHandlerCocoa::sendEvent(NPCocoaEvent* event)
176 switch (event->type) {
177 case NPCocoaEventMouseDown:
178 case NPCocoaEventMouseUp:
179 case NPCocoaEventMouseDragged:
180 case NPCocoaEventKeyDown:
181 case NPCocoaEventKeyUp:
182 case NPCocoaEventFlagsChanged:
183 case NPCocoaEventScrollWheel:
184 m_currentEventIsUserGesture = true;
187 m_currentEventIsUserGesture = false;
190 bool result = [m_pluginView sendEvent:event isDrawRect:event->type == NPCocoaEventDrawRect];
192 m_currentEventIsUserGesture = false;
196 #endif // ENABLE(NETSCAPE_PLUGIN_API)