WebCore:
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2008 00:28:17 +0000 (00:28 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2008 00:28:17 +0000 (00:28 +0000)
2008-04-30  Anders Carlsson  <andersca@apple.com>

        Reviewed by Adam.

        Add new Cocoa event model type declarations.

        * bridge/npapi.h:

WebKit:

2008-04-30  Anders Carlsson  <andersca@apple.com>

        Reviewed by Adam.

        Add Cocoa event handler.

        * WebKit.xcodeproj/project.pbxproj:

WebKit/mac:

2008-04-30  Anders Carlsson  <andersca@apple.com>

        Reviewed by Adam.

        Add new Cocoa event model and the NPN_ScheduleTimer/NPN_UnscheduleTimer methods.

        * Plugins/WebBaseNetscapePluginView.h:
        * Plugins/WebBaseNetscapePluginView.mm:
        (PluginTimer::PluginTimer):
        (PluginTimer::start):
        (PluginTimer::fired):
        (-[WebBaseNetscapePluginView saveAndSetNewPortStateForUpdate:]):
        (-[WebBaseNetscapePluginView stopTimers]):
        (-[WebBaseNetscapePluginView restartTimers]):
        (-[WebBaseNetscapePluginView scrollWheel:]):
        (-[WebBaseNetscapePluginView flagsChanged:]):
        (-[WebBaseNetscapePluginView start]):
        (-[WebBaseNetscapePluginView eventModel]):
        (-[WebBaseNetscapePluginView fini]):
        (-[WebBaseNetscapePluginView getVariable:value:]):
        (-[WebBaseNetscapePluginView setVariable:value:]):
        (-[WebBaseNetscapePluginView scheduleTimerWithInterval:repeat:timerFunc:]):
        (-[WebBaseNetscapePluginView unscheduleTimer:]):
        * Plugins/WebBaseNetscapePluginViewInternal.h:
        * Plugins/WebBaseNetscapePluginViewPrivate.h:
        * Plugins/WebNetscapePluginEventHandler.h:
        * Plugins/WebNetscapePluginEventHandler.mm:
        (WebNetscapePluginEventHandler::create):
        * Plugins/WebNetscapePluginEventHandlerCarbon.h:
        * Plugins/WebNetscapePluginEventHandlerCarbon.mm:
        (WebNetscapePluginEventHandlerCarbon::scrollWheel):
        (WebNetscapePluginEventHandlerCarbon::flagsChanged):
        (WebNetscapePluginEventHandlerCarbon::platformWindow):
        * Plugins/WebNetscapePluginEventHandlerCocoa.h: Added.
        (WebNetscapePluginEventHandlerCocoa::startTimers):
        (WebNetscapePluginEventHandlerCocoa::stopTimers):
        * Plugins/WebNetscapePluginEventHandlerCocoa.mm: Added.
        (WebNetscapePluginEventHandlerCocoa::WebNetscapePluginEventHandlerCocoa):
        (WebNetscapePluginEventHandlerCocoa::drawRect):
        (WebNetscapePluginEventHandlerCocoa::mouseDown):
        (WebNetscapePluginEventHandlerCocoa::mouseDragged):
        (WebNetscapePluginEventHandlerCocoa::mouseEntered):
        (WebNetscapePluginEventHandlerCocoa::mouseExited):
        (WebNetscapePluginEventHandlerCocoa::mouseMoved):
        (WebNetscapePluginEventHandlerCocoa::mouseUp):
        (WebNetscapePluginEventHandlerCocoa::scrollWheel):
        (WebNetscapePluginEventHandlerCocoa::sendMouseEvent):
        (WebNetscapePluginEventHandlerCocoa::keyDown):
        (WebNetscapePluginEventHandlerCocoa::keyUp):
        (WebNetscapePluginEventHandlerCocoa::flagsChanged):
        (WebNetscapePluginEventHandlerCocoa::sendKeyEvent):
        (WebNetscapePluginEventHandlerCocoa::windowFocusChanged):
        (WebNetscapePluginEventHandlerCocoa::focusChanged):
        (WebNetscapePluginEventHandlerCocoa::platformWindow):
        (WebNetscapePluginEventHandlerCocoa::sendEvent):
        * Plugins/WebNetscapePluginPackage.m:
        (-[WebNetscapePluginPackage load]):
        * Plugins/npapi.m:
        (NPN_ScheduleTimer):
        (NPN_UnscheduleTimer):
        * Plugins/npfunctions.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@32752 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
WebCore/ChangeLog
WebCore/bridge/npapi.h
WebKit/ChangeLog
WebKit/WebKit.xcodeproj/project.pbxproj
WebKit/mac/ChangeLog
WebKit/mac/Plugins/WebBaseNetscapePluginView.h
WebKit/mac/Plugins/WebBaseNetscapePluginView.mm
WebKit/mac/Plugins/WebBaseNetscapePluginViewInternal.h
WebKit/mac/Plugins/WebBaseNetscapePluginViewPrivate.h
WebKit/mac/Plugins/WebNetscapePluginEventHandler.h
WebKit/mac/Plugins/WebNetscapePluginEventHandler.mm
WebKit/mac/Plugins/WebNetscapePluginEventHandlerCarbon.h
WebKit/mac/Plugins/WebNetscapePluginEventHandlerCarbon.mm
WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.h [new file with mode: 0644]
WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.mm [new file with mode: 0644]
WebKit/mac/Plugins/WebNetscapePluginPackage.m
WebKit/mac/Plugins/npapi.m
WebKit/mac/Plugins/npfunctions.h

index e03843bbab49040c60c855c13c05ab5124118217..b608379dacdeb413f6973975e5088ad1fa7ea9b8 100644 (file)
@@ -1,3 +1,11 @@
+2008-04-30  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        Add new Cocoa event model type declarations.
+        
+        * bridge/npapi.h:
+
 2008-04-30  Beth Dakin  <bdakin@apple.com>
 
         Reviewed by Sam Weinig.
index 9e60c0ae596402593a3057828c1ba7f714a81e80..aa5b9f6ac4ddf43bb9feeef4212693bdda56fb51 100644 (file)
     #include <Events.h>
 #endif
 
+#if defined(XP_MACOSX) && defined(__LP64__)
+#define NP_NO_QUICKDRAW
+#define NP_NO_CARBON
+#endif
+
 #ifdef XP_MACOSX
-    #include <Carbon/Carbon.h>
     #include <ApplicationServices/ApplicationServices.h>
     #include <OpenGL/OpenGL.h>
+#ifndef NP_NO_CARBON
+    #include <Carbon/Carbon.h>
+#endif
 #endif
 
 #ifdef XP_UNIX
     #include <windows.h>
 #endif
 
-#if defined(XP_MACOSX) && defined(__LP64__)
-#error 64-bit Netscape plug-ins are not supported on Mac OS X
-#endif
-
 /*----------------------------------------------------------------------*/
 /*             Plugin Version Constants                                 */
 /*----------------------------------------------------------------------*/
 
 #define NP_VERSION_MAJOR 0
-#define NP_VERSION_MINOR 18
+#define NP_VERSION_MINOR 20
 
 
 
@@ -334,7 +337,9 @@ typedef enum {
     NPPVformValue = 16,    /* Not implemented in WebKit */
 #ifdef XP_MACOSX
     /* Used for negotiating drawing models */
-    NPPVpluginDrawingModel = 1000
+    NPPVpluginDrawingModel = 1000,
+    /* Used for negotiating event models */
+    NPPVpluginEventModel = 1001,
 #endif
 } NPPVariable;
 
@@ -370,6 +375,12 @@ typedef enum {
 #endif
     , NPNVsupportsCoreGraphicsBool = 2001 /* TRUE if the browser supports the CoreGraphics drawing model */
     , NPNVsupportsOpenGLBool = 2002 /* TRUE if the browser supports the OpenGL drawing model (CGL on Mac) */
+    
+    , NPNVpluginEventModel = 1001 /* The NPEventModel specified by the plugin */
+#ifndef NP_NO_CARBON
+    , NPNVsupportsCarbonBool = 2003 /* TRUE if the browser supports the Carbon event model */
+#endif
+    , NPNVsupportsCocoaBool = 2004 /* TRUE if the browser supports the Cocoa event model */
 #endif /* XP_MACOSX */
 } NPNVariable;
 
@@ -396,6 +407,70 @@ typedef enum {
     NPDrawingModelOpenGL = 2
 } NPDrawingModel;
 
+/*
+ * The event model for a Mac OS X plugin. These are the possible values for the NPNVpluginEventModel variable.
+ */
+
+typedef enum {
+#ifndef NP_NO_CARBON
+    NPEventModelCarbon = 0,
+#endif
+    NPEventModelCocoa = 1,
+} NPEventModel;
+
+typedef enum {
+    NPCocoaEventDrawRect = 1,
+    NPCocoaEventMouseDown,
+    NPCocoaEventMouseUp,
+    NPCocoaEventMouseMoved,
+    NPCocoaEventMouseEntered,
+    NPCocoaEventMouseExited,
+    NPCocoaEventMouseDragged,
+    NPCocoaEventKeyDown,
+    NPCocoaEventKeyUp,
+    NPCocoaEventFlagsChanged,
+    NPCocoaEventFocusChanged,
+    NPCocoaEventWindowFocusChanged,
+    NPCocoaEventScrollWheel,
+} NPCocoaEventType;
+
+typedef struct _NPNSString NPNSString;
+typedef struct _NPNSWindow NPNSWindow;
+
+typedef struct _NPCocoaEvent {
+    NPCocoaEventType type;
+    union {
+        struct {
+            uint32 modifierFlags;
+            double pluginX;
+            double pluginY;            
+            int32 buttonNumber;
+            int32 clickCount;
+            double deltaX;
+            double deltaY;
+            double deltaZ;
+        } mouse;
+        struct {
+            uint32 modifierFlags;
+            double pluginX;
+            double pluginY;            
+            NPNSString *characters;
+            NPNSString *charactersIgnoringModifiers;
+            NPBool isARepeat;
+            uint16 keyCode;
+        } key;
+        struct {
+            double x;
+            double y;
+            double width;
+            double height;
+        } draw;
+        struct {
+            NPBool hasFocus;
+        } focus;        
+    };
+} NPCocoaEvent;
+
 #endif
 
 typedef struct _NPWindow
@@ -440,7 +515,11 @@ typedef struct _NPPrint
 } NPPrint;
 
 #if defined(XP_MAC) || defined(XP_MACOSX)
+
+#ifndef NP_NO_CARBON
 typedef EventRecord    NPEvent;
+#endif
+
 #elif defined(XP_WIN)
 typedef struct _NPEvent
 {
@@ -485,7 +564,11 @@ typedef void *NPRegion;
 typedef struct NP_CGContext
 {
     CGContextRef context;
-    WindowRef window;
+#ifdef NP_NO_CARBON
+    NPNSWindow *window;
+#else
+    void *window; // Can be either an NSWindow or a WindowRef depending on the event model
+#endif
 } NP_CGContext;
 
 /* 
@@ -496,7 +579,11 @@ typedef struct NP_CGContext
 typedef struct NP_GLContext
 {
     CGLContextObj context;
-    WindowRef window;
+#ifdef NP_NO_CARBON
+    NPNSWindow *window;
+#else
+    void *window; // Can be either an NSWindow or a WindowRef depending on the event model
+#endif
 } NP_GLContext;
 
 #endif /* XP_MACOSX */
@@ -615,6 +702,7 @@ typedef struct NP_Port
 #define NPVERS_HAS_RESPONSE_HEADERS       17
 #define NPVERS_HAS_NPOBJECT_ENUM          18
 #define NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL 19
+#define NPVERS_MACOSX_HAS_EVENT_MODELS    20
 
 /*----------------------------------------------------------------------*/
 /*             Function Prototypes                */
@@ -707,6 +795,8 @@ void        NPN_ForceRedraw(NPP instance);
 void        NPN_PushPopupsEnabledState(NPP instance, NPBool enabled);
 void        NPN_PopPopupsEnabledState(NPP instance);
 void        NPN_PluginThreadAsyncCall(NPP instance, void (*func) (void *), void *userData);
+uint32_t    NPN_ScheduleTimer(NPP instance, int32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID));
+void        NPN_UnscheduleTimer(NPP instance, uint32_t timerID);
 
 #ifdef __cplusplus
 }  /* end extern "C" */
index 6b7fd0c60419d219767e3a53ac5f79e7000586c5..23cc828f03274e35337bf8292d83f6f998e65ba3 100644 (file)
@@ -1,3 +1,11 @@
+2008-04-30  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        Add Cocoa event handler.
+        
+        * WebKit.xcodeproj/project.pbxproj:
+
 2008-04-29  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Adam.
index e97e48563de8c1c01a4d12ed7b2c45f8a1040462..da17eacbf0ef00a592ab1e0af30d847ea9fd5c02 100644 (file)
@@ -17,6 +17,8 @@
                1AEA66D50DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEA66D30DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm */; };
                1AEA66D80DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEA66D60DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h */; };
                1AEA66D90DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEA66D70DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm */; };
+               1AEA6A500DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEA6A4E0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h */; };
+               1AEA6A510DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEA6A4F0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm */; };
                1C0706630A431E01001078F6 /* WebScriptDebugServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0706620A431E01001078F6 /* WebScriptDebugServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C07073D0A433BD8001078F6 /* WebScriptDebugServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C07073C0A433BD8001078F6 /* WebScriptDebugServer.m */; };
                1C07079A0A433E22001078F6 /* WebScriptDebugServerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0707990A433E22001078F6 /* WebScriptDebugServerPrivate.h */; };
                1AEA66D30DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNetscapePluginEventHandler.mm; sourceTree = "<group>"; };
                1AEA66D60DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNetscapePluginEventHandlerCarbon.h; sourceTree = "<group>"; };
                1AEA66D70DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNetscapePluginEventHandlerCarbon.mm; sourceTree = "<group>"; };
+               1AEA6A4E0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNetscapePluginEventHandlerCocoa.h; sourceTree = "<group>"; };
+               1AEA6A4F0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNetscapePluginEventHandlerCocoa.mm; sourceTree = "<group>"; };
                1C0706620A431E01001078F6 /* WebScriptDebugServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptDebugServer.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                1C07073C0A433BD8001078F6 /* WebScriptDebugServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebScriptDebugServer.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                1C0707990A433E22001078F6 /* WebScriptDebugServerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptDebugServerPrivate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                                1AEA66D30DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm */,
                                1AEA66D60DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h */,
                                1AEA66D70DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm */,
+                               1AEA6A4E0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h */,
+                               1AEA6A4F0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm */,
                                F5F7171E0288493C018635CA /* WebNetscapePluginPackage.h */,
                                F5F7171F0288493C018635CA /* WebNetscapePluginPackage.m */,
                                83402EFA035A58D100BE770A /* WebNetscapePluginStream.h */,
                                934C11670D8710BB00C32ABD /* WebDynamicScrollBarsViewInternal.h in Headers */,
                                1AEA66D40DC6B1FF003D12BF /* WebNetscapePluginEventHandler.h in Headers */,
                                1AEA66D80DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h in Headers */,
+                               1AEA6A500DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                C0167BF90D7F5DD00028696E /* WebScriptDebugger.mm in Sources */,
                                1AEA66D50DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm in Sources */,
                                1AEA66D90DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm in Sources */,
+                               1AEA6A510DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 9f1b1c9ea3f2030fb3c25e47cb32796aee0a8af3..d9164152dc1f769abd2096cd1d5307ca4a35d16b 100644 (file)
@@ -1,3 +1,65 @@
+2008-04-30  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        Add new Cocoa event model and the NPN_ScheduleTimer/NPN_UnscheduleTimer methods.
+        
+        * Plugins/WebBaseNetscapePluginView.h:
+        * Plugins/WebBaseNetscapePluginView.mm:
+        (PluginTimer::PluginTimer):
+        (PluginTimer::start):
+        (PluginTimer::fired):
+        (-[WebBaseNetscapePluginView saveAndSetNewPortStateForUpdate:]):
+        (-[WebBaseNetscapePluginView stopTimers]):
+        (-[WebBaseNetscapePluginView restartTimers]):
+        (-[WebBaseNetscapePluginView scrollWheel:]):
+        (-[WebBaseNetscapePluginView flagsChanged:]):
+        (-[WebBaseNetscapePluginView start]):
+        (-[WebBaseNetscapePluginView eventModel]):
+        (-[WebBaseNetscapePluginView fini]):
+        (-[WebBaseNetscapePluginView getVariable:value:]):
+        (-[WebBaseNetscapePluginView setVariable:value:]):
+        (-[WebBaseNetscapePluginView scheduleTimerWithInterval:repeat:timerFunc:]):
+        (-[WebBaseNetscapePluginView unscheduleTimer:]):
+        * Plugins/WebBaseNetscapePluginViewInternal.h:
+        * Plugins/WebBaseNetscapePluginViewPrivate.h:
+        * Plugins/WebNetscapePluginEventHandler.h:
+        * Plugins/WebNetscapePluginEventHandler.mm:
+        (WebNetscapePluginEventHandler::create):
+        * Plugins/WebNetscapePluginEventHandlerCarbon.h:
+        * Plugins/WebNetscapePluginEventHandlerCarbon.mm:
+        (WebNetscapePluginEventHandlerCarbon::scrollWheel):
+        (WebNetscapePluginEventHandlerCarbon::flagsChanged):
+        (WebNetscapePluginEventHandlerCarbon::platformWindow):
+        * Plugins/WebNetscapePluginEventHandlerCocoa.h: Added.
+        (WebNetscapePluginEventHandlerCocoa::startTimers):
+        (WebNetscapePluginEventHandlerCocoa::stopTimers):
+        * Plugins/WebNetscapePluginEventHandlerCocoa.mm: Added.
+        (WebNetscapePluginEventHandlerCocoa::WebNetscapePluginEventHandlerCocoa):
+        (WebNetscapePluginEventHandlerCocoa::drawRect):
+        (WebNetscapePluginEventHandlerCocoa::mouseDown):
+        (WebNetscapePluginEventHandlerCocoa::mouseDragged):
+        (WebNetscapePluginEventHandlerCocoa::mouseEntered):
+        (WebNetscapePluginEventHandlerCocoa::mouseExited):
+        (WebNetscapePluginEventHandlerCocoa::mouseMoved):
+        (WebNetscapePluginEventHandlerCocoa::mouseUp):
+        (WebNetscapePluginEventHandlerCocoa::scrollWheel):
+        (WebNetscapePluginEventHandlerCocoa::sendMouseEvent):
+        (WebNetscapePluginEventHandlerCocoa::keyDown):
+        (WebNetscapePluginEventHandlerCocoa::keyUp):
+        (WebNetscapePluginEventHandlerCocoa::flagsChanged):
+        (WebNetscapePluginEventHandlerCocoa::sendKeyEvent):
+        (WebNetscapePluginEventHandlerCocoa::windowFocusChanged):
+        (WebNetscapePluginEventHandlerCocoa::focusChanged):
+        (WebNetscapePluginEventHandlerCocoa::platformWindow):
+        (WebNetscapePluginEventHandlerCocoa::sendEvent):
+        * Plugins/WebNetscapePluginPackage.m:
+        (-[WebNetscapePluginPackage load]):
+        * Plugins/npapi.m:
+        (NPN_ScheduleTimer):
+        (NPN_UnscheduleTimer):
+        * Plugins/npfunctions.h:
+
 2008-04-30  Brady Eidson  <beidson@apple.com>
 
         Fix my WebPreferences revert check-in
index 869bb4bce958e4711cf5936394a34bfac31d43a4..dc3cf461e4ae32499985ffcc5cfee1fae590978e 100644 (file)
@@ -33,6 +33,7 @@
 #import <WebKit/npfunctions.h>
 #import <WebKit/npapi.h>
 #import <WebKit/WebBasePluginPackage.h>
+#import <wtf/HashMap.h>
 
 @class DOMElement;
 @class WebDataSource;
@@ -43,6 +44,7 @@
 @class WebNetscapePluginStream;
 @class WebView;
 
+class PluginTimer;
 class WebNetscapePluginEventHandler;
 
 typedef union PluginPort {
@@ -77,6 +79,7 @@ typedef union PluginPort {
     PluginPort nPort;
     PluginPort lastSetPort;
     NPDrawingModel drawingModel;
+    NPEventModel eventModel;
     
     // These are only valid when drawingModel is NPDrawingModelOpenGL
     AGLContext aglContext;
@@ -95,8 +98,11 @@ typedef union PluginPort {
     BOOL isTransparent;
     BOOL isCompletelyObscured;
     BOOL shouldStopSoon;
+
     BOOL shouldFireTimers;
-    
+    uint32_t currentTimerID;
+    HashMap<uint32_t, PluginTimer*>* timers;
+
     unsigned pluginFunctionCallDepth;
     
     DOMElement *element;
index 3c47318f6587b3f793066bd6d2ab70d08e6ca1bb..9397fe1268a5ca4d0056fb63a60ff6f61ff8203f 100644 (file)
@@ -116,6 +116,47 @@ static WebBaseNetscapePluginView *currentPluginView = nil;
 
 typedef struct OpaquePortState* PortState;
 
+static const double ThrottledTimerInterval = 0.25;
+
+class PluginTimer : public TimerBase {
+public:
+    typedef void (*TimerFunc)(NPP npp, uint32_t timerID);
+    
+    PluginTimer(NPP npp, uint32_t timerID, uint32_t interval, NPBool repeat, TimerFunc timerFunc)
+        : m_npp(npp)
+        , m_timerID(timerID)
+        , m_interval(interval)
+        , m_repeat(repeat)
+        , m_timerFunc(timerFunc)
+    {
+    }
+    
+    void start(bool throttle)
+    {
+        ASSERT(!isActive());
+        
+        double timeInterval = throttle ? ThrottledTimerInterval : m_interval / 1000.0;
+        if (m_repeat)
+            startRepeating(timeInterval);
+        else
+            startOneShot(timeInterval);
+    }
+
+private:
+    virtual void fired() 
+    {
+        m_timerFunc(m_npp, m_timerID);
+        if (!m_repeat)
+            delete this;
+    }
+    
+    NPP m_npp;
+    uint32_t m_timerID;
+    uint32_t m_interval;
+    NPBool m_repeat;
+    TimerFunc m_timerFunc;
+};
+
 #ifndef NP_NO_QUICKDRAW
 
 // QuickDraw is not available in 64-bit
@@ -282,9 +323,6 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
         [self fixWindowPort];
 #endif
 
-    WindowRef windowRef = (WindowRef)[[self currentWindow] windowRef];
-    ASSERT(windowRef);
-    
     // Use AppKit to convert view coordinates to NSWindow coordinates.
     NSRect boundsInWindow = [self convertRect:[self bounds] toView:nil];
     NSRect visibleRectInWindow = [self convertRect:[self visibleRect] toView:nil];
@@ -295,6 +333,9 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
     visibleRectInWindow.origin.y = borderViewHeight - NSMaxY(visibleRectInWindow);
     
 #ifndef NP_NO_QUICKDRAW
+    WindowRef windowRef = (WindowRef)[[self currentWindow] windowRef];
+    ASSERT(windowRef);
+        
     // Look at the Carbon port to convert top-left-based window coordinates into top-left-based content coordinates.
     if (drawingModel == NPDrawingModelQuickDraw) {
         ::Rect portBounds;
@@ -498,7 +539,7 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
             cgPortState->context = context;
             
             // Update the plugin's window/context
-            nPort.cgPort.window = windowRef;
+            nPort.cgPort.window = eventHandler->platformWindow([self currentWindow]);
             nPort.cgPort.context = context;
             window.window = &nPort.cgPort;
 
@@ -535,7 +576,7 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
             }
             
             // Update the plugin's window/context
-            nPort.aglPort.window = windowRef;
+            nPort.aglPort.window = eventHandler->platformWindow([self currentWindow]);;
             nPort.aglPort.context = [self _cglContext];
             window.window = &nPort.aglPort;
             
@@ -721,6 +762,15 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
 {
     eventHandler->stopTimers();    
     shouldFireTimers = NO;
+    
+    if (!timers)
+        return;
+
+    HashMap<uint32_t, PluginTimer*>::const_iterator end = timers->end();
+    for (HashMap<uint32_t, PluginTimer*>::const_iterator it = timers->begin(); it != end; ++it) {
+        PluginTimer* timer = it->second;
+        timer->stop();
+    }    
 }
 
 - (void)restartTimers
@@ -738,6 +788,16 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
     // If the plugin is completely obscured (scrolled out of view, for example), then we will
     // send null events at a reduced rate.
     eventHandler->startTimers(isCompletelyObscured);
+    
+    if (!timers)
+        return;
+    
+    HashMap<uint32_t, PluginTimer*>::const_iterator end = timers->end();
+    for (HashMap<uint32_t, PluginTimer*>::const_iterator it = timers->begin(); it != end; ++it) {
+        PluginTimer* timer = it->second;
+        ASSERT(!timer->isActive());
+        timer->start(isCompletelyObscured);
+    }    
 }
 
 - (BOOL)acceptsFirstResponder
@@ -812,6 +872,12 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
     eventHandler->mouseDragged(theEvent);
 }
 
+- (void)scrollWheel:(NSEvent *)theEvent
+{
+    if (!eventHandler->scrollWheel(theEvent))
+        [super scrollWheel:theEvent];
+}
+
 - (void)keyUp:(NSEvent *)theEvent
 {
     eventHandler->keyUp(theEvent);
@@ -822,6 +888,11 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
     eventHandler->keyDown(theEvent);
 }
 
+- (void)flagsChanged:(NSEvent *)theEvent
+{
+    eventHandler->flagsChanged(theEvent);
+}
+
 - (void)cut:(id)sender
 {
     eventHandler->keyDown([NSApp currentEvent]);
@@ -1092,6 +1163,9 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
     // Initialize drawingModel to an invalid value so that we can detect when the plugin does not specify a drawingModel
     drawingModel = (NPDrawingModel)-1;
     
+    // Initialize eventModel to an invalid value so that we can detect when the plugin does not specify an event model.
+    eventModel = (NPEventModel)-1;
+    
     // Plug-ins are "windowed" by default.  On MacOS, windowed plug-ins share the same window and graphics port as the main
     // browser window.  Windowless plug-ins are rendered off-screen, then copied into the main browser window.
     window.type = NPWindowTypeWindow;
@@ -1109,16 +1183,29 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
         // Default to QuickDraw if the plugin did not specify a drawing model.
         drawingModel = NPDrawingModelQuickDraw;
 #else
-        // QuickDraw is not available, so we can't default to it.  We could default to CoreGraphics instead, but
-        // if the plugin did not specify the CoreGraphics drawing model then it must be one of the old QuickDraw
-        // plugins.  Thus, the plugin is unsupported and should not be started.  Destroy it here and bail out.
-        LOG(Plugins, "Plugin only supports QuickDraw, but QuickDraw is unavailable: %@", pluginPackage);
-        [self _destroyPlugin];
-        [pluginPackage close];
-        return NO;
+        // QuickDraw is not available, so we can't default to it. Instead, default to CoreGraphics.
+        drawingModel = NPDrawingModelCoreGraphics;
+#endif
+    }
+
+    if (eventModel == (NPEventModel)-1) {
+        // If the plug-in did not specify a drawing model we default to Carbon when it is available.
+#ifndef NP_NO_CARBON
+        eventModel = NPEventModelCarbon;
+#else
+        eventModel = NPEventModelCocoa;
 #endif
     }
 
+    if (eventModel == NPEventModelCocoa &&
+        drawingModel == NPDrawingModelQuickDraw) {
+        LOG(Plugins, "Plugin can't use use Cocoa event model with QuickDraw drawing model: %@", pluginPackage);
+        [self _destroyPlugin];
+        [pluginPackage close];
+        
+        return NO;
+    }        
+    
     // Create the event handler
     eventHandler = WebNetscapePluginEventHandler::create(self);
     
@@ -1191,6 +1278,11 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
     return isStarted;
 }
 
+- (NPEventModel)eventModel
+{
+    return eventModel;
+}
+
 - (WebDataSource *)dataSource
 {
     WebFrame *webFrame = kit(core(element)->document()->frame());
@@ -1367,6 +1459,11 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
     free(cValues);
     
     ASSERT(!eventHandler);
+    
+    if (timers) {
+        deleteAllValues(*timers);
+        delete timers;
+    }    
 }
 
 - (void)disconnectStream:(WebBaseNetscapePluginStream*)stream
@@ -2245,6 +2342,26 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
             return NPERR_NO_ERROR;
         }
         
+        case NPNVpluginEventModel:
+        {
+            *(NPEventModel *)value = eventModel;
+            return NPERR_NO_ERROR;
+        }
+        
+#ifndef NP_NO_CARBON
+        case NPNVsupportsCarbonBool:
+        {
+            *(NPBool *)value = TRUE;
+            return NPERR_NO_ERROR;
+        }
+#endif /* NP_NO_CARBON */
+            
+        case NPNVsupportsCocoaBool:
+        {
+            *(NPBool *)value = TRUE;
+            return NPERR_NO_ERROR;
+        }
+            
         default:
             break;
     }
@@ -2304,11 +2421,63 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
             }
         }
         
+        case NPPVpluginEventModel:
+        {
+            // Can only set event model inside NPP_New()
+            if (self != [[self class] currentPluginView])
+                return NPERR_GENERIC_ERROR;
+            
+            // Check for valid, supported event model
+            NPEventModel newEventModel = (NPEventModel)(uintptr_t)value;
+            switch (newEventModel) {
+                // Supported event models:
+#ifndef NP_NO_CARBON
+                case NPEventModelCarbon:
+#endif
+                case NPEventModelCocoa:
+                    eventModel = newEventModel;
+                    return NPERR_NO_ERROR;
+                    
+                    // Unsupported (or unknown) event models:
+                default:
+                    LOG(Plugins, "Plugin %@ uses unsupported event model: %d", pluginPackage, eventModel);
+                    return NPERR_GENERIC_ERROR;
+            }
+        }
+            
         default:
             return NPERR_GENERIC_ERROR;
     }
 }
 
+- (uint32_t)scheduleTimerWithInterval:(uint32_t)interval repeat:(NPBool)repeat timerFunc:(void (*)(NPP npp, uint32_t timerID))timerFunc
+{
+    if (!timerFunc)
+        return 0;
+    
+    if (!timers)
+        timers = new HashMap<uint32_t, PluginTimer*>;
+    
+    uint32_t timerID = ++currentTimerID;
+    
+    PluginTimer* timer = new PluginTimer(plugin, timerID, interval, repeat, timerFunc);
+    timers->set(timerID, timer);
+
+    if (shouldFireTimers)
+        timer->start(isCompletelyObscured);
+    
+    return 0;
+}
+
+- (void)unscheduleTimer:(uint32_t)timerID
+{
+    if (!timers)
+        return;
+    
+    if (PluginTimer* timer = timers->take(timerID))
+        delete timer;
+}
+
 @end
 
 @implementation WebPluginRequest
index 450cc103cc80af5d0f4d6ac4215c78de25c4bc3d..492f3fb32f98092d967ba1d54b6dacd71641489f 100644 (file)
@@ -31,6 +31,7 @@
 
 @interface WebBaseNetscapePluginView (WebInternal)
 - (BOOL)sendEvent:(void*)event isDrawRect:(BOOL)eventIsDrawRect;
+- (NPEventModel)eventModel;
 @end
 #endif
 
index e9f5d183f40b2b34485b56759fbd7eef0d6d24ed..76095d09e497273ceded4c9cfdb4d5e3882f34ea 100644 (file)
@@ -48,6 +48,8 @@
 - (void)forceRedraw;
 - (NPError)getVariable:(NPNVariable)variable value:(void *)value;
 - (NPError)setVariable:(NPPVariable)variable value:(void *)value;
+- (uint32_t)scheduleTimerWithInterval:(uint32_t)interval repeat:(NPBool)repeat timerFunc:(void (*)(NPP npp, uint32_t timerID))timerFunc;
+- (void)unscheduleTimer:(uint32_t)timerID;
 
 @end
 #endif
index 5252f4d2d9830f3e31de3f96feb9850da8a46ab6..5a2760ac45bcf2619a2e93b84f4f5401db8b2efd 100644 (file)
@@ -46,14 +46,20 @@ public:
     virtual void mouseExited(NSEvent*) = 0;
     virtual void mouseMoved(NSEvent*) = 0;
     virtual void mouseUp(NSEvent*) = 0;
+    virtual bool scrollWheel(NSEvent*) = 0;
     
     virtual void keyDown(NSEvent*) = 0;
     virtual void keyUp(NSEvent*) = 0;
+    virtual void flagsChanged(NSEvent*) = 0;
+    
     virtual void focusChanged(bool hasFocus) = 0;
     virtual void windowFocusChanged(bool hasFocus) = 0;
     
-    virtual void startTimers(bool throttleTimers) = 0;
-    virtual void stopTimers() = 0;
+    virtual void startTimers(bool throttleTimers) { }
+    virtual void stopTimers() { }
+    
+    // Returns the platform specific window used in NPP_SetWindow
+    virtual void* platformWindow(NSWindow*) = 0;
     
     bool currentEventIsUserGesture() const { return m_currentEventIsUserGesture; }
 protected:
index 2396f76c91cb875aa2c4547c44f57a584110ec44..e2072907a86a8bd76f0a0ea3684031ebafd6cf9d 100644 (file)
 
 #import "WebNetscapePluginEventHandler.h"
 
+#import <wtf/Assertions.h>
+#import "WebBaseNetscapePluginViewInternal.h"
 #import "WebNetscapePluginEventHandlerCarbon.h"
+#import "WebNetscapePluginEventHandlerCocoa.h"
 
 WebNetscapePluginEventHandler* WebNetscapePluginEventHandler::create(WebBaseNetscapePluginView* pluginView)
 {
-    return new WebNetscapePluginEventHandlerCarbon(pluginView);
+    switch ([pluginView eventModel]) {
+        case NPEventModelCarbon:
+            return new WebNetscapePluginEventHandlerCarbon(pluginView);
+        case NPEventModelCocoa:
+            return new WebNetscapePluginEventHandlerCocoa(pluginView);
+        default:
+            ASSERT_NOT_REACHED();
+            return 0;
+    }
 }
 
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
index 91002103ca0262b45e57f2377bc1f9f050c4c243..203891b52a350ed300dff4e70c2c36cbe967fd27 100644 (file)
@@ -45,9 +45,11 @@ public:
     virtual void mouseExited(NSEvent*);
     virtual void mouseMoved(NSEvent*);
     virtual void mouseUp(NSEvent*);
+    virtual bool scrollWheel(NSEvent*);
     
     virtual void keyDown(NSEvent*);
     virtual void keyUp(NSEvent*);
+    virtual void flagsChanged(NSEvent*);
     
     virtual void windowFocusChanged(bool hasFocus);    
     virtual void focusChanged(bool hasFocus);
@@ -55,6 +57,8 @@ public:
     virtual void startTimers(bool throttleTimers);
     virtual void stopTimers();
 
+    virtual void* platformWindow(NSWindow*);
+    
 private:
     void sendNullEvent();
 
index 8c654e951a01827cb572dd2a3f780ade9780581a..f1a94f9a20969954c95e53dbd5459a0be643abce 100644 (file)
@@ -164,6 +164,11 @@ void WebNetscapePluginEventHandlerCarbon::mouseUp(NSEvent* theEvent)
     LOG(PluginEvents, "NPP_HandleEvent(mouseUp): %d pt.v=%d, pt.h=%d", acceptedEvent, event.where.v, event.where.h);    
 }
 
+bool WebNetscapePluginEventHandlerCarbon::scrollWheel(NSEvent* theEvent)
+{
+    return false;
+}
+
 void WebNetscapePluginEventHandlerCarbon::mouseEntered(NSEvent* theEvent)
 {
     EventRecord event;
@@ -235,6 +240,10 @@ void WebNetscapePluginEventHandlerCarbon::keyUp(NSEvent* theEvent)
     }    
 }
 
+void WebNetscapePluginEventHandlerCarbon::flagsChanged(NSEvent*)
+{
+}
+
 void WebNetscapePluginEventHandlerCarbon::focusChanged(bool hasFocus)
 {
     EventRecord event;
@@ -377,6 +386,11 @@ void WebNetscapePluginEventHandlerCarbon::stopTimers()
     m_nullEventTimer = 0;
 }
 
+void* WebNetscapePluginEventHandlerCarbon::platformWindow(NSWindow* window)
+{
+    return [window windowRef];
+}
+
 bool WebNetscapePluginEventHandlerCarbon::sendEvent(EventRecord* event)
 {
     // If at any point the user clicks or presses a key from within a plugin, set the 
diff --git a/WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.h b/WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.h
new file mode 100644 (file)
index 0000000..b915e5a
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef WebNetscapePluginEventHandlerCocoa_h
+#define WebNetscapePluginEventHandlerCocoa_h
+
+#include <WebKit/npapi.h>
+#include "WebNetscapePluginEventHandler.h"
+
+class WebNetscapePluginEventHandlerCocoa : public WebNetscapePluginEventHandler {
+public:
+    WebNetscapePluginEventHandlerCocoa(WebBaseNetscapePluginView*); 
+
+    virtual void drawRect(const NSRect&);
+
+    virtual void mouseDown(NSEvent*);
+    virtual void mouseDragged(NSEvent*);
+    virtual void mouseEntered(NSEvent*);
+    virtual void mouseExited(NSEvent*);
+    virtual void mouseMoved(NSEvent*);
+    virtual void mouseUp(NSEvent*);
+    virtual bool scrollWheel(NSEvent*);
+    
+    virtual void keyDown(NSEvent*);
+    virtual void keyUp(NSEvent*);
+    virtual void flagsChanged(NSEvent*);
+    
+    virtual void windowFocusChanged(bool hasFocus);    
+    virtual void focusChanged(bool hasFocus);
+
+    virtual void* platformWindow(NSWindow*);
+private:
+    bool sendMouseEvent(NSEvent*, NPCocoaEventType);
+    void sendKeyEvent(NSEvent*, NPCocoaEventType);
+    bool sendEvent(NPCocoaEvent*);
+};
+
+#endif //WebNetscapePluginEventHandlerCocoa_h
+
+
diff --git a/WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.mm b/WebKit/mac/Plugins/WebNetscapePluginEventHandlerCocoa.mm
new file mode 100644 (file)
index 0000000..1e18652
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#import "WebNetscapePluginEventHandlerCocoa.h"
+
+#import "WebBaseNetscapePluginViewInternal.h"
+
+WebNetscapePluginEventHandlerCocoa::WebNetscapePluginEventHandlerCocoa(WebBaseNetscapePluginView* pluginView)
+    : WebNetscapePluginEventHandler(pluginView)
+{
+}
+
+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;
+    
+    sendEvent(&event);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseDown(NSEvent *event)
+{
+    sendMouseEvent(event, NPCocoaEventMouseDown);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseDragged(NSEvent *event)
+{
+    sendMouseEvent(event, NPCocoaEventMouseDragged);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseEntered(NSEvent *event)
+{
+    sendMouseEvent(event, NPCocoaEventMouseEntered);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseExited(NSEvent *event)
+{
+    sendMouseEvent(event, NPCocoaEventMouseExited);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseMoved(NSEvent *event)
+{
+    sendMouseEvent(event, NPCocoaEventMouseMoved);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseUp(NSEvent *event)
+{
+    sendMouseEvent(event, NPCocoaEventMouseUp);
+}
+
+bool WebNetscapePluginEventHandlerCocoa::scrollWheel(NSEvent* event)
+{
+    return sendMouseEvent(event, NPCocoaEventScrollWheel);
+}
+
+bool WebNetscapePluginEventHandlerCocoa::sendMouseEvent(NSEvent *nsEvent, NPCocoaEventType type)
+{
+    NPCocoaEvent event;
+    
+    NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
+    
+    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];
+    
+    return sendEvent(&event);
+}
+
+void WebNetscapePluginEventHandlerCocoa::keyDown(NSEvent *event)
+{
+    sendKeyEvent(event, NPCocoaEventKeyDown);
+}
+
+void WebNetscapePluginEventHandlerCocoa::keyUp(NSEvent *event)
+{
+    sendKeyEvent(event, NPCocoaEventKeyUp);
+}
+
+void WebNetscapePluginEventHandlerCocoa::flagsChanged(NSEvent *event)
+{
+    sendKeyEvent(event, NPCocoaEventFlagsChanged);
+}
+
+void 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];
+     
+    sendEvent(&event);
+}
+
+void WebNetscapePluginEventHandlerCocoa::windowFocusChanged(bool hasFocus)
+{
+    NPCocoaEvent event;
+    
+    event.type = NPCocoaEventWindowFocusChanged;
+    event.focus.hasFocus = hasFocus;
+    
+    sendEvent(&event);
+}
+
+void WebNetscapePluginEventHandlerCocoa::focusChanged(bool hasFocus)
+{
+    NPCocoaEvent event;
+    
+    event.type = NPCocoaEventFocusChanged;
+    event.focus.hasFocus = hasFocus;
+    
+    sendEvent(&event);
+}
+
+void* WebNetscapePluginEventHandlerCocoa::platformWindow(NSWindow* window)
+{
+    return window;
+}
+
+bool WebNetscapePluginEventHandlerCocoa::sendEvent(NPCocoaEvent* event)
+{
+    switch (event->type) {
+        case NPCocoaEventMouseDown:
+        case NPCocoaEventMouseUp:
+        case NPCocoaEventMouseDragged:
+        case NPCocoaEventKeyDown:
+        case NPCocoaEventKeyUp:
+        case NPCocoaEventFlagsChanged:
+        case NPCocoaEventScrollWheel:
+            m_currentEventIsUserGesture = true;
+            break;
+        default:
+            m_currentEventIsUserGesture = false;
+    }
+            
+    bool result = [m_pluginView sendEvent:event isDrawRect:event->type == NPCocoaEventDrawRect];
+    
+    m_currentEventIsUserGesture = false;
+    return result;
+}
index 878fab327c2b1d7a1ffee22e8ead2d3b0077ccbd..6d0cb5512c45702864f3fe5437ffc257e7d81e92 100644 (file)
@@ -423,7 +423,9 @@ static TransitionVector tVectorForFunctionPointer(FunctionPointer);
         browserFuncs.getJavaPeer = (NPN_GetJavaPeerProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_GetJavaPeer);
         browserFuncs.pushpopupsenabledstate = (NPN_PushPopupsEnabledStateProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_PushPopupsEnabledState);
         browserFuncs.poppopupsenabledstate = (NPN_PopPopupsEnabledStateProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_PopPopupsEnabledState);
-        
+        browserFuncs.scheduletimer = (NPN_ScheduleTimerProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_ScheduleTimer);
+        browserFuncs.unscheduletimer = (NPN_UnscheduleTimerProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_UnscheduleTimer);
+
         browserFuncs.releasevariantvalue = (NPN_ReleaseVariantValueProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_ReleaseVariantValue);
         browserFuncs.getstringidentifier = (NPN_GetStringIdentifierProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_GetStringIdentifier);
         browserFuncs.getstringidentifiers = (NPN_GetStringIdentifiersProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_GetStringIdentifiers);
@@ -525,6 +527,8 @@ static TransitionVector tVectorForFunctionPointer(FunctionPointer);
         browserFuncs.getJavaPeer = NPN_GetJavaPeer;
         browserFuncs.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
         browserFuncs.poppopupsenabledstate = NPN_PopPopupsEnabledState;
+        browserFuncs.scheduletimer = NPN_ScheduleTimer;
+        browserFuncs.unscheduletimer = NPN_UnscheduleTimer;
         
         browserFuncs.releasevariantvalue = _NPN_ReleaseVariantValue;
         browserFuncs.getstringidentifier = _NPN_GetStringIdentifier;
index 59fe118e9a3d1ddffd7c58e34b7eb98659e02df1..1315c8c58d1adc041f3a25b1fa85b1bf6221e690 100644 (file)
@@ -169,4 +169,15 @@ void
 NPN_PopPopupsEnabledState(NPP instance)
 {
 }
+
+uint32_t NPN_ScheduleTimer(NPP instance, int32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID))
+{
+    return [pluginViewForInstance(instance) scheduleTimerWithInterval:interval repeat:repeat timerFunc:timerFunc];
+}
+
+void NPN_UnscheduleTimer(NPP instance, uint32_t timerID)
+{
+    [pluginViewForInstance(instance) unscheduleTimer:timerID];
+}
+
 #endif
index 27843b66fcd5238837f8d52f8e0573c684f3e40b..74db3a8825cf0ba5bcdfc00f91de81d91d492408 100644 (file)
@@ -36,8 +36,9 @@ typedef void* (*NPN_GetJavaPeerProcPtr)(NPP instance);
 typedef void  (*NPN_PushPopupsEnabledStateProcPtr)(NPP instance, NPBool enabled);
 typedef void  (*NPN_PopPopupsEnabledStateProcPtr)(NPP instance);
 typedef void (*NPN_PluginThreadAsyncCallProcPtr)(NPP npp, void (*func)(void *), void *userData);
-typedef bool (*NPN_ConstructProcPtr)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
-
+typedef uint32_t (*NPN_ScheduleTimerProcPtr)(NPP npp, int32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID));
+typedef void (*NPN_UnscheduleTimerProcPtr)(NPP npp, uint32_t timerID);
+    
 typedef void (*NPN_ReleaseVariantValueProcPtr) (NPVariant *variant);
 
 typedef NPIdentifier (*NPN_GetStringIdentifierProcPtr) (const NPUTF8 *name);
@@ -60,6 +61,7 @@ typedef bool (*NPN_HasMethodProcPtr) (NPP npp, NPObject *npobj, NPIdentifier met
 typedef bool (*NPN_RemovePropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName);
 typedef void (*NPN_SetExceptionProcPtr) (NPObject *obj, const NPUTF8 *message);
 typedef bool (*NPN_EnumerateProcPtr) (NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t *count);
+typedef bool (*NPN_ConstructProcPtr)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result);    
 
 typedef NPError (*NPP_NewProcPtr)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
 typedef NPError (*NPP_DestroyProcPtr)(NPP instance, NPSavedData** save);
@@ -129,6 +131,8 @@ typedef struct _NPNetscapeFuncs {
     NPN_EnumerateProcPtr enumerate;
     NPN_PluginThreadAsyncCallProcPtr pluginthreadasynccall;
     NPN_ConstructProcPtr construct;
+    NPN_ScheduleTimerProcPtr scheduletimer;
+    NPN_UnscheduleTimerProcPtr unscheduletimer;    
 } NPNetscapeFuncs;
 
 typedef struct _NPPluginFuncs {