Changeset 64063 in webkit


Ignore:
Timestamp:
Jul 26, 2010 12:41:59 PM (14 years ago)
Author:
andersca@apple.com
Message:

Deliver mouse and wheel events to plug-ins
https://bugs.webkit.org/show_bug.cgi?id=42988

Reviewed by Sam Weinig.

  • Shared/WebEvent.h:

(WebKit::WebMouseEvent::WebMouseEvent):
(WebKit::WebMouseEvent::deltaX):
(WebKit::WebMouseEvent::deltaY):
(WebKit::WebMouseEvent::deltaZ):

  • Shared/mac/WebEventFactory.mm:

(WebKit::WebEventFactory::createWebMouseEvent):
Add deltaX, deltaY and deltaZ member variables to WebMosueEvent.

  • WebKit2.xcodeproj/project.pbxproj:

Rename NetscapePluginMac.cpp to NetscapePluginMac.mm.

  • WebProcess/Plugins/Netscape/NetscapePlugin.cpp:

(WebKit::NetscapePlugin::NPP_HandleEvent):
Add NPP_ wrapper.

(WebKit::NetscapePlugin::handleMouseEvent):
(WebKit::NetscapePlugin::handleWheelEvent):
Call the platform variants.

  • WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm: Added.

(WebKit::modifierFlags):
(WebKit::buttonNumber):
(WebKit::initializeMouseEvent):
(WebKit::NetscapePlugin::platformHandleMouseEvent):
Create an NPCocoaEvent and send it to the plug-in.

(WebKit::NetscapePlugin::platformHandleWheelEvent):
Ditto.

  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::handleEvent):
Get the current WebEvent and send it to the plug-in if necessary.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::currentEvent):
(WebKit::CurrentEvent::CurrentEvent):
(WebKit::CurrentEvent::~CurrentEvent):
(WebKit::WebPage::mouseEvent):
(WebKit::WebPage::wheelEvent):
(WebKit::WebPage::keyEvent):

  • WebProcess/WebPage/WebPage.h:

Add RAII object for keeping track of the current event.

Location:
trunk/WebKit2
Files:
1 added
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r64059 r64063  
    2323        * WebProcess/WebPage/LayerBackedDrawingArea.cpp:
    2424        (WebKit::LayerBackedDrawingArea::LayerBackedDrawingArea):
     25
     262010-07-26  Anders Carlsson  <andersca@apple.com>
     27
     28        Reviewed by Sam Weinig.
     29
     30        Deliver mouse and wheel events to plug-ins
     31        https://bugs.webkit.org/show_bug.cgi?id=42988
     32
     33        * Shared/WebEvent.h:
     34        (WebKit::WebMouseEvent::WebMouseEvent):
     35        (WebKit::WebMouseEvent::deltaX):
     36        (WebKit::WebMouseEvent::deltaY):
     37        (WebKit::WebMouseEvent::deltaZ):
     38        * Shared/mac/WebEventFactory.mm:
     39        (WebKit::WebEventFactory::createWebMouseEvent):
     40        Add deltaX, deltaY and deltaZ member variables to WebMosueEvent.
     41
     42        * WebKit2.xcodeproj/project.pbxproj:
     43        Rename NetscapePluginMac.cpp to NetscapePluginMac.mm.
     44       
     45        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
     46        (WebKit::NetscapePlugin::NPP_HandleEvent):
     47        Add NPP_ wrapper.
     48
     49        (WebKit::NetscapePlugin::handleMouseEvent):
     50        (WebKit::NetscapePlugin::handleWheelEvent):
     51        Call the platform variants.
     52   
     53        * WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm: Added.
     54        (WebKit::modifierFlags):       
     55        (WebKit::buttonNumber):
     56        (WebKit::initializeMouseEvent):
     57        (WebKit::NetscapePlugin::platformHandleMouseEvent):
     58        Create an NPCocoaEvent and send it to the plug-in.
     59       
     60        (WebKit::NetscapePlugin::platformHandleWheelEvent):
     61        Ditto.
     62
     63        * WebProcess/Plugins/PluginView.cpp:
     64        (WebKit::PluginView::handleEvent):
     65        Get the current WebEvent and send it to the plug-in if necessary.
     66
     67        * WebProcess/WebPage/WebPage.cpp:
     68        (WebKit::WebPage::currentEvent):
     69        (WebKit::CurrentEvent::CurrentEvent):
     70        (WebKit::CurrentEvent::~CurrentEvent):
     71        (WebKit::WebPage::mouseEvent):
     72        (WebKit::WebPage::wheelEvent):
     73        (WebKit::WebPage::keyEvent):
     74        * WebProcess/WebPage/WebPage.h:
     75        Add RAII object for keeping track of the current event.
    2576
    26772010-07-26  Anders Carlsson  <andersca@apple.com>
  • trunk/WebKit2/Shared/WebEvent.h

    r61719 r64063  
    121121    }
    122122
    123     WebMouseEvent(Type type, Button button, int x, int y, int globalX, int globalY, int clickCount, Modifiers modifiers, double timestamp)
     123    WebMouseEvent(Type type, Button button, int x, int y, int globalX, int globalY, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers modifiers, double timestamp)
    124124        : WebEvent(type, modifiers, timestamp)
    125125        , m_button(button)
     
    128128        , m_globalPositionX(globalX)
    129129        , m_globalPositionY(globalY)
     130        , m_deltaX(deltaX)
     131        , m_deltaY(deltaY)
     132        , m_deltaZ(deltaZ)
    130133        , m_clickCount(clickCount)
    131134    {
     
    138141    int globalPositionX() const { return m_globalPositionX; }
    139142    int globalPositionY() const { return m_globalPositionY; }
     143    float deltaX() const { return m_deltaX; }
     144    float deltaY() const { return m_deltaY; }
     145    float deltaZ() const { return m_deltaZ; }
    140146    int clickCount() const { return m_clickCount; }
    141147
     
    161167    int m_globalPositionX;
    162168    int m_globalPositionY;
     169    float m_deltaX;
     170    float m_deltaY;
     171    float m_deltaZ;
    163172    int m_clickCount;
    164173};
  • trunk/WebKit2/Shared/mac/WebEventFactory.mm

    r57308 r64063  
    964964    int globalPositionX                     = globalPosition.x;
    965965    int globalPositionY                     = globalPosition.y;
     966    float deltaX                            = [event deltaX];
     967    float deltaY                            = [event deltaY];
     968    float deltaZ                            = [event deltaZ];
    966969    int clickCount                          = clickCountForEvent(event);
    967970    WebEvent::Modifiers modifiers           = modifiersForEvent(event);
    968971    double timestamp                        = [event timestamp];
    969972
    970     return WebMouseEvent(type, button, positionX, positionY, globalPositionX, globalPositionY, clickCount, modifiers, timestamp);
     973    return WebMouseEvent(type, button, positionX, positionY, globalPositionX, globalPositionY, deltaX, deltaY, deltaZ, clickCount, modifiers, timestamp);
    971974}
    972975
  • trunk/WebKit2/Shared/win/WebEventFactory.cpp

    r57308 r64063  
    404404    WebEvent::Modifiers modifiers = modifiersForEvent(wParam);
    405405
    406     return WebMouseEvent(type, button, positionX, positionY, globalPositionX, globalPositionY, clickCount, modifiers, timestamp);
     406    return WebMouseEvent(type, button, positionX, positionY, globalPositionX, globalPositionY, 0, 0, 0, clickCount, modifiers, timestamp);
    407407}
    408408
  • trunk/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r63930 r64063  
    7474                1AADE6FF10D855FC00D3D63D /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AADE6FE10D855FC00D3D63D /* ApplicationServices.framework */; };
    7575                1AE117F611DBB30900981615 /* ProcessLauncher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE117F511DBB30900981615 /* ProcessLauncher.cpp */; };
    76                 1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.cpp */; };
     76                1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */; };
    7777                1AEFCC1211D01F96008219D3 /* PluginInfoStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */; };
    7878                1AEFCC1311D01F96008219D3 /* PluginInfoStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AEFCC1111D01F96008219D3 /* PluginInfoStore.cpp */; };
     
    359359                1AADE6FE10D855FC00D3D63D /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; };
    360360                1AE117F511DBB30900981615 /* ProcessLauncher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessLauncher.cpp; sourceTree = "<group>"; };
    361                 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetscapePluginMac.cpp; sourceTree = "<group>"; };
     361                1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetscapePluginMac.mm; sourceTree = "<group>"; };
    362362                1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginInfoStore.h; sourceTree = "<group>"; };
    363363                1AEFCC1111D01F96008219D3 /* PluginInfoStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginInfoStore.cpp; sourceTree = "<group>"; };
     
    709709                        isa = PBXGroup;
    710710                        children = (
    711                                 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.cpp */,
     711                                1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */,
    712712                                1A6FBA0211E6813E00DB1371 /* NetscapePluginModuleMac.cpp */,
    713713                        );
     
    14021402                                1A6FBA2B11E6862700DB1371 /* NetscapeBrowserFuncs.cpp in Sources */,
    14031403                                1A6FBD2911E69BC200DB1371 /* NetscapePlugin.cpp in Sources */,
    1404                                 1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.cpp in Sources */,
     1404                                1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.mm in Sources */,
    14051405                                1A6FB90C11E66FBC00DB1371 /* NetscapePluginModule.cpp in Sources */,
    14061406                                1A6FBA0311E6813E00DB1371 /* NetscapePluginModuleMac.cpp in Sources */,
  • trunk/WebKit2/WebProcess/Plugins/DummyPlugin.cpp

    r63493 r64063  
    9696}
    9797
     98bool DummyPlugin::handleMouseEvent(const WebMouseEvent&)
     99{
     100    return false;
     101}
     102
     103bool DummyPlugin::handleWheelEvent(const WebWheelEvent&)
     104{
     105    return false;
     106}
     107
    98108} // namespace WebKit
  • trunk/WebKit2/WebProcess/Plugins/DummyPlugin.h

    r63493 r64063  
    5555    virtual void streamDidFinishLoading(uint64_t streamID);
    5656    virtual void streamDidFail(uint64_t streamID, bool wasCancelled);
    57 
     57    virtual bool handleMouseEvent(const WebMouseEvent&);
     58    virtual bool handleWheelEvent(const WebWheelEvent&);
     59   
    5860    virtual PluginController* controller();
    5961};
  • trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp

    r63704 r64063  
    206206}
    207207
     208int16_t NetscapePlugin::NPP_HandleEvent(void* event)
     209{
     210    return m_pluginModule->pluginFuncs().event(&m_npp, event);
     211}
     212
    208213void NetscapePlugin::NPP_URLNotify(const char* url, NPReason reason, void* notifyData)
    209214{
     
    409414}
    410415
     416bool NetscapePlugin::handleMouseEvent(const WebMouseEvent& mouseEvent)
     417{
     418    return platformHandleMouseEvent(mouseEvent);
     419}
     420   
     421bool NetscapePlugin::handleWheelEvent(const WebWheelEvent& wheelEvent)
     422{
     423    return platformHandleWheelEvent(wheelEvent);
     424}
     425
    411426PluginController* NetscapePlugin::controller()
    412427{
  • trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h

    r63704 r64063  
    7575    NPError NPP_DestroyStream(NPStream*, NPReason);
    7676    void NPP_StreamAsFile(NPStream*, const char* filename);
    77 
    7877    int32_t NPP_WriteReady(NPStream*);
    7978    int32_t NPP_Write(NPStream*, int32_t offset, int32_t len, void* buffer);
     79    int16_t NPP_HandleEvent(void* event);
    8080    void NPP_URLNotify(const char* url, NPReason, void* notifyData);
    8181    NPError NPP_GetValue(NPPVariable, void *value);
     
    9393    void platformPaint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect);
    9494
     95    bool platformHandleMouseEvent(const WebMouseEvent&);
     96    bool platformHandleWheelEvent(const WebWheelEvent&);
     97
    9598    // Plugin
    9699    virtual bool initialize(PluginController*, const Parameters&);
     
    106109    virtual void streamDidFinishLoading(uint64_t streamID);
    107110    virtual void streamDidFail(uint64_t streamID, bool wasCancelled);
     111    virtual bool handleMouseEvent(const WebMouseEvent&);
     112    virtual bool handleWheelEvent(const WebWheelEvent&);
    108113
    109114    virtual PluginController* controller();
     
    146151{
    147152}
     153
     154bool NetscapePlugin::platformHandleMouseEvent(const WebMouseEvent&)
     155{
     156    return false;
     157}
     158
     159bool NetscapePlugin::platformHandleWheelEvent(const WebWheelEvent&)
     160{
     161    return false;
     162}
     163
    148164#endif
    149165
  • trunk/WebKit2/WebProcess/Plugins/Plugin.h

    r63493 r64063  
    3838namespace WebKit {
    3939
     40class WebMouseEvent;
     41class WebWheelEvent;
     42   
    4043class PluginController;
    4144
     
    8790    virtual void streamDidFail(uint64_t streamID, bool wasCancelled) = 0;
    8891
     92    // Tells the plug-in to handle the passed in mouse event. The plug-in should return true if it processed the event.
     93    virtual bool handleMouseEvent(const WebMouseEvent&) = 0;
     94
     95    // Tells the plug-in to handle the passed in wheel event. The plug-in should return true if it processed the event.
     96    virtual bool handleWheelEvent(const WebWheelEvent&) = 0;
     97
    8998    // Returns the plug-in controller for this plug-in.
    9099    // FIXME: We could just have the controller be a member variable of Plugin.
  • trunk/WebKit2/WebProcess/Plugins/PluginView.cpp

    r63846 r64063  
    2727
    2828#include "Plugin.h"
     29#include "WebEvent.h"
     30#include "WebPage.h"
    2931#include <WebCore/DocumentLoader.h>
    3032#include <WebCore/Event.h>
     
    319321}
    320322
    321 void PluginView::handleEvent(Event*)
    322 {
    323     // FIXME: Implement.
     323void PluginView::handleEvent(Event* event)
     324{
     325    const WebEvent* currentEvent = WebPage::currentEvent();
     326    if (!currentEvent)
     327        return;
     328
     329    bool didHandleEvent = false;
     330
     331    if ((event->type() == eventNames().mousemoveEvent && currentEvent->type() == WebEvent::MouseMove)
     332        || (event->type() == eventNames().mousedownEvent && currentEvent->type() == WebEvent::MouseDown)
     333        || (event->type() == eventNames().mouseupEvent && currentEvent->type() == WebEvent::MouseUp)) {
     334        // We have a mouse event.
     335        didHandleEvent = m_plugin->handleMouseEvent(static_cast<const WebMouseEvent&>(*currentEvent));
     336    } else if (event->type() == eventNames().mousewheelEvent && currentEvent->type() == WebEvent::Wheel) {
     337        // We have a wheel event.
     338        didHandleEvent = m_plugin->handleWheelEvent(static_cast<const WebWheelEvent&>(*currentEvent));
     339    }
     340
     341    if (didHandleEvent)
     342        event->setDefaultHandled();
    324343}
    325344   
  • trunk/WebKit2/WebProcess/WebPage/WebPage.cpp

    r64050 r64063  
    278278// Events
    279279
     280static const WebEvent* g_currentEvent = 0;
     281
     282// FIXME: WebPage::currentEvent is used by the plug-in code to avoid having to convert from DOM events back to
     283// WebEvents. When we get the event handling sorted out, this should go away and the Widgets should get the correct
     284// platform events passed to the event handler code.
     285const WebEvent* WebPage::currentEvent()
     286{
     287    return g_currentEvent;
     288}
     289
     290class CurrentEvent {
     291public:
     292    explicit CurrentEvent(const WebEvent& event)
     293        : m_previousCurrentEvent(g_currentEvent)
     294    {
     295        g_currentEvent = &event;
     296    }
     297
     298    ~CurrentEvent()
     299    {
     300        g_currentEvent = m_previousCurrentEvent;
     301    }
     302
     303private:
     304    const WebEvent* m_previousCurrentEvent;
     305};
     306
    280307void WebPage::mouseEvent(const WebMouseEvent& mouseEvent)
    281308{
     309    CurrentEvent currentEvent(mouseEvent);
     310
    282311    WebProcess::shared().connection()->send(WebPageProxyMessage::DidReceiveEvent, m_pageID, CoreIPC::In(static_cast<uint32_t>(mouseEvent.type())));
    283312
     
    305334void WebPage::wheelEvent(const WebWheelEvent& wheelEvent)
    306335{
     336    CurrentEvent currentEvent(wheelEvent);
     337
    307338    WebProcess::shared().connection()->send(WebPageProxyMessage::DidReceiveEvent, m_pageID, CoreIPC::In(static_cast<uint32_t>(wheelEvent.type())));
    308339    if (!m_mainFrame->coreFrame()->view())
     
    315346void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
    316347{
     348    CurrentEvent currentEvent(keyboardEvent);
     349
    317350    WebProcess::shared().connection()->send(WebPageProxyMessage::DidReceiveEvent, m_pageID, CoreIPC::In(static_cast<uint32_t>(keyboardEvent.type())));
    318351
  • trunk/WebKit2/WebProcess/WebPage/WebPage.h

    r64050 r64063  
    5555
    5656class DrawingArea;
     57class WebEvent;
    5758class WebFrame;
    5859class WebKeyboardEvent;
     
    110111#endif
    111112
     113    static const WebEvent* currentEvent();
     114
    112115private:
    113116    WebPage(uint64_t pageID, const WebCore::IntSize& viewSize, const WebPreferencesStore&, DrawingArea::Type);
Note: See TracChangeset for help on using the changeset viewer.