WebKit:
[WebKit-https.git] / WebKit / mac / Plugins / WebNetscapePluginEventHandlerCocoa.mm
index fe6ec9a..f952f6b 100644 (file)
@@ -23,6 +23,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
+#if ENABLE(NETSCAPE_PLUGIN_API)
+
 #import "WebNetscapePluginEventHandlerCocoa.h"
 
 #import "WebBaseNetscapePluginViewInternal.h"
@@ -37,10 +39,10 @@ void WebNetscapePluginEventHandlerCocoa::drawRect(const NSRect& rect)
     NPCocoaEvent event;
     
     event.type = NPCocoaEventDrawRect;
-    event.draw.x = rect.origin.x;
-    event.draw.y = rect.origin.y;
-    event.draw.width = rect.size.width;
-    event.draw.height = rect.size.height;
+    event.event.draw.x = rect.origin.x;
+    event.event.draw.y = rect.origin.y;
+    event.event.draw.width = rect.size.width;
+    event.event.draw.height = rect.size.height;
     
     sendEvent(&event);
 }
@@ -86,21 +88,32 @@ bool WebNetscapePluginEventHandlerCocoa::sendMouseEvent(NSEvent *nsEvent, NPCoco
     
     NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
     
+    int clickCount;
+    if (type == NPCocoaEventMouseEntered || type == NPCocoaEventMouseExited || type == NPCocoaEventScrollWheel)
+        clickCount = 0;
+    else
+        clickCount = [nsEvent clickCount];
+    
     event.type = type;
-    event.mouse.modifierFlags = [nsEvent modifierFlags];
-    event.mouse.buttonNumber = [nsEvent buttonNumber];
-    event.mouse.pluginX = point.x;
-    event.mouse.pluginY = point.y;
-    event.mouse.deltaX = [nsEvent deltaX];
-    event.mouse.deltaY = [nsEvent deltaY];
-    event.mouse.deltaZ = [nsEvent deltaZ];
+    event.event.mouse.modifierFlags = [nsEvent modifierFlags];
+    event.event.mouse.buttonNumber = [nsEvent buttonNumber];
+    event.event.mouse.clickCount = clickCount;
+    event.event.mouse.pluginX = point.x;
+    event.event.mouse.pluginY = point.y;
+    event.event.mouse.deltaX = [nsEvent deltaX];
+    event.event.mouse.deltaY = [nsEvent deltaY];
+    event.event.mouse.deltaZ = [nsEvent deltaZ];
     
     return sendEvent(&event);
 }
 
 void WebNetscapePluginEventHandlerCocoa::keyDown(NSEvent *event)
 {
-    sendKeyEvent(event, NPCocoaEventKeyDown);
+    bool retval = sendKeyEvent(event, NPCocoaEventKeyDown);
+    
+    // If the plug-in did not handle the event, pass it on to the Input Manager.
+    if (!retval)
+        [m_pluginView interpretKeyEvents:[NSArray arrayWithObject:event]];
 }
 
 void WebNetscapePluginEventHandlerCocoa::keyUp(NSEvent *event)
@@ -111,37 +124,29 @@ void WebNetscapePluginEventHandlerCocoa::keyUp(NSEvent *event)
 void WebNetscapePluginEventHandlerCocoa::flagsChanged(NSEvent *nsEvent)
 {
     NPCocoaEvent event;
-    
-    NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
-    
+        
     event.type = NPCocoaEventFlagsChanged;
-    event.key.modifierFlags = [nsEvent modifierFlags];
-    event.key.pluginX = point.x;
-    event.key.pluginY = point.y;
-    event.key.keyCode = [nsEvent keyCode];
-    event.key.isARepeat = false;
-    event.key.characters = 0;
-    event.key.charactersIgnoringModifiers = 0;
+    event.event.key.modifierFlags = [nsEvent modifierFlags];
+    event.event.key.keyCode = [nsEvent keyCode];
+    event.event.key.isARepeat = false;
+    event.event.key.characters = 0;
+    event.event.key.charactersIgnoringModifiers = 0;
     
     sendEvent(&event);
 }
 
-void WebNetscapePluginEventHandlerCocoa::sendKeyEvent(NSEvent* nsEvent, NPCocoaEventType type)
+bool WebNetscapePluginEventHandlerCocoa::sendKeyEvent(NSEvent* nsEvent, NPCocoaEventType type)
 {
     NPCocoaEvent event;
-    
-    NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
-    
+        
     event.type = type;
-    event.key.modifierFlags = [nsEvent modifierFlags];
-    event.key.pluginX = point.x;
-    event.key.pluginY = point.y;
-    event.key.keyCode = [nsEvent keyCode];
-    event.key.isARepeat = [nsEvent isARepeat];
-    event.key.characters = (NPNSString *)[nsEvent characters];
-    event.key.charactersIgnoringModifiers = (NPNSString *)[nsEvent charactersIgnoringModifiers];
+    event.event.key.modifierFlags = [nsEvent modifierFlags];
+    event.event.key.keyCode = [nsEvent keyCode];
+    event.event.key.isARepeat = [nsEvent isARepeat];
+    event.event.key.characters = (NPNSString *)[nsEvent characters];
+    event.event.key.charactersIgnoringModifiers = (NPNSString *)[nsEvent charactersIgnoringModifiers];
      
-    sendEvent(&event);
+    return sendEvent(&event);
 }
 
 void WebNetscapePluginEventHandlerCocoa::windowFocusChanged(bool hasFocus)
@@ -149,7 +154,7 @@ void WebNetscapePluginEventHandlerCocoa::windowFocusChanged(bool hasFocus)
     NPCocoaEvent event;
     
     event.type = NPCocoaEventWindowFocusChanged;
-    event.focus.hasFocus = hasFocus;
+    event.event.focus.hasFocus = hasFocus;
     
     sendEvent(&event);
 }
@@ -159,7 +164,7 @@ void WebNetscapePluginEventHandlerCocoa::focusChanged(bool hasFocus)
     NPCocoaEvent event;
     
     event.type = NPCocoaEventFocusChanged;
-    event.focus.hasFocus = hasFocus;
+    event.event.focus.hasFocus = hasFocus;
     
     sendEvent(&event);
 }
@@ -190,3 +195,5 @@ bool WebNetscapePluginEventHandlerCocoa::sendEvent(NPCocoaEvent* event)
     m_currentEventIsUserGesture = false;
     return result;
 }
+
+#endif // ENABLE(NETSCAPE_PLUGIN_API)