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 #import "WebNetscapePluginEventHandlerCocoa.h"
28 #import "WebBaseNetscapePluginViewInternal.h"
30 WebNetscapePluginEventHandlerCocoa::WebNetscapePluginEventHandlerCocoa(WebBaseNetscapePluginView* pluginView)
31 : WebNetscapePluginEventHandler(pluginView)
35 void WebNetscapePluginEventHandlerCocoa::drawRect(const NSRect& rect)
39 event.type = NPCocoaEventDrawRect;
40 event.draw.x = rect.origin.x;
41 event.draw.y = rect.origin.y;
42 event.draw.width = rect.size.width;
43 event.draw.height = rect.size.height;
48 void WebNetscapePluginEventHandlerCocoa::mouseDown(NSEvent *event)
50 sendMouseEvent(event, NPCocoaEventMouseDown);
53 void WebNetscapePluginEventHandlerCocoa::mouseDragged(NSEvent *event)
55 sendMouseEvent(event, NPCocoaEventMouseDragged);
58 void WebNetscapePluginEventHandlerCocoa::mouseEntered(NSEvent *event)
60 sendMouseEvent(event, NPCocoaEventMouseEntered);
63 void WebNetscapePluginEventHandlerCocoa::mouseExited(NSEvent *event)
65 sendMouseEvent(event, NPCocoaEventMouseExited);
68 void WebNetscapePluginEventHandlerCocoa::mouseMoved(NSEvent *event)
70 sendMouseEvent(event, NPCocoaEventMouseMoved);
73 void WebNetscapePluginEventHandlerCocoa::mouseUp(NSEvent *event)
75 sendMouseEvent(event, NPCocoaEventMouseUp);
78 bool WebNetscapePluginEventHandlerCocoa::scrollWheel(NSEvent* event)
80 return sendMouseEvent(event, NPCocoaEventScrollWheel);
83 bool WebNetscapePluginEventHandlerCocoa::sendMouseEvent(NSEvent *nsEvent, NPCocoaEventType type)
87 NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
90 event.mouse.modifierFlags = [nsEvent modifierFlags];
91 event.mouse.buttonNumber = [nsEvent buttonNumber];
92 event.mouse.pluginX = point.x;
93 event.mouse.pluginY = point.y;
94 event.mouse.deltaX = [nsEvent deltaX];
95 event.mouse.deltaY = [nsEvent deltaY];
96 event.mouse.deltaZ = [nsEvent deltaZ];
98 return sendEvent(&event);
101 void WebNetscapePluginEventHandlerCocoa::keyDown(NSEvent *event)
103 sendKeyEvent(event, NPCocoaEventKeyDown);
106 void WebNetscapePluginEventHandlerCocoa::keyUp(NSEvent *event)
108 sendKeyEvent(event, NPCocoaEventKeyUp);
111 void WebNetscapePluginEventHandlerCocoa::flagsChanged(NSEvent *event)
113 sendKeyEvent(event, NPCocoaEventFlagsChanged);
116 void WebNetscapePluginEventHandlerCocoa::sendKeyEvent(NSEvent* nsEvent, NPCocoaEventType type)
120 NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
123 event.key.modifierFlags = [nsEvent modifierFlags];
124 event.key.pluginX = point.x;
125 event.key.pluginY = point.y;
126 event.key.keyCode = [nsEvent keyCode];
127 event.key.isARepeat = [nsEvent isARepeat];
128 event.key.characters = (NPNSString *)[nsEvent characters];
129 event.key.charactersIgnoringModifiers = (NPNSString *)[nsEvent charactersIgnoringModifiers];
134 void WebNetscapePluginEventHandlerCocoa::windowFocusChanged(bool hasFocus)
138 event.type = NPCocoaEventWindowFocusChanged;
139 event.focus.hasFocus = hasFocus;
144 void WebNetscapePluginEventHandlerCocoa::focusChanged(bool hasFocus)
148 event.type = NPCocoaEventFocusChanged;
149 event.focus.hasFocus = hasFocus;
154 void* WebNetscapePluginEventHandlerCocoa::platformWindow(NSWindow* window)
159 bool WebNetscapePluginEventHandlerCocoa::sendEvent(NPCocoaEvent* event)
161 switch (event->type) {
162 case NPCocoaEventMouseDown:
163 case NPCocoaEventMouseUp:
164 case NPCocoaEventMouseDragged:
165 case NPCocoaEventKeyDown:
166 case NPCocoaEventKeyUp:
167 case NPCocoaEventFlagsChanged:
168 case NPCocoaEventScrollWheel:
169 m_currentEventIsUserGesture = true;
172 m_currentEventIsUserGesture = false;
175 bool result = [m_pluginView sendEvent:event isDrawRect:event->type == NPCocoaEventDrawRect];
177 m_currentEventIsUserGesture = false;