Changeset 69150 in webkit


Ignore:
Timestamp:
Oct 5, 2010 2:42:35 PM (14 years ago)
Author:
andersca@apple.com
Message:

Start sending Carbon plug-in events in th Carbon event model
https://bugs.webkit.org/show_bug.cgi?id=47209
<rdar://problem/8515677>

Reviewed by Sam Weinig.

  • WebProcess/Plugins/Netscape/NetscapePlugin.cpp:

(WebKit::NetscapePlugin::NetscapePlugin):
Initialize the NP_CGContext struct.

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

(WebKit::NetscapePlugin::platformPostInitialize):
Create a fake Carbon window.

(WebKit::NetscapePlugin::platformDestroy):
Destroy the Carbon window.

(WebKit::modifiersForEvent):
Given a WebEvent, return the EventRecord modifiers.

(WebKit::NetscapePlugin::platformPaint):
(WebKit::NetscapePlugin::platformHandleMouseEvent):
(WebKit::NetscapePlugin::platformHandleWheelEvent):
(WebKit::NetscapePlugin::platformHandleMouseEnterEvent):
(WebKit::NetscapePlugin::platformHandleMouseLeaveEvent):
(WebKit::NetscapePlugin::platformSetFocus):
(WebKit::NetscapePlugin::windowFocusChanged):
Create Carbon EventRecords and call NPP_HandleEvent.

Location:
trunk/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r69116 r69150  
     12010-10-05  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Start sending Carbon plug-in events in th Carbon event model
     6        https://bugs.webkit.org/show_bug.cgi?id=47209
     7        <rdar://problem/8515677>
     8
     9        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
     10        (WebKit::NetscapePlugin::NetscapePlugin):
     11        Initialize the NP_CGContext struct.
     12
     13        * WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm:
     14        (WebKit::NetscapePlugin::platformPostInitialize):
     15        Create a fake Carbon window.
     16
     17        (WebKit::NetscapePlugin::platformDestroy):
     18        Destroy the Carbon window.
     19
     20        (WebKit::modifiersForEvent):
     21        Given a WebEvent, return the EventRecord modifiers.
     22
     23        (WebKit::NetscapePlugin::platformPaint):
     24        (WebKit::NetscapePlugin::platformHandleMouseEvent):
     25        (WebKit::NetscapePlugin::platformHandleWheelEvent):
     26        (WebKit::NetscapePlugin::platformHandleMouseEnterEvent):
     27        (WebKit::NetscapePlugin::platformHandleMouseLeaveEvent):
     28        (WebKit::NetscapePlugin::platformSetFocus):
     29        (WebKit::NetscapePlugin::windowFocusChanged):
     30        Create Carbon EventRecords and call NPP_HandleEvent.
     31
    1322010-10-05  Sam Weinig  <sam@webkit.org>
    233
  • trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp

    r68988 r69150  
    5757    , m_drawingModel(static_cast<NPDrawingModel>(-1))
    5858    , m_eventModel(static_cast<NPEventModel>(-1))
     59#ifndef NP_NO_CARBON
     60    , m_npCGContext()
     61#endif   
    5962#endif
    6063{
  • trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h

    r68988 r69150  
    5656    NPError setDrawingModel(NPDrawingModel);
    5757    NPError setEventModel(NPEventModel);
     58#ifndef NP_NO_CARBON
     59    WindowRef windowRef() const;
     60#endif
    5861#elif PLATFORM(WIN)
    5962    HWND containingWindow() const;
     
    187190    NPEventModel m_eventModel;
    188191    RetainPtr<PlatformLayer> m_pluginLayer;
     192#ifndef NP_NO_CARBON
     193    NP_CGContext m_npCGContext;
     194#endif
    189195#elif PLATFORM(WIN)
    190196    HWND m_window;
  • trunk/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm

    r68988 r69150  
    2626#include "NetscapePlugin.h"
    2727
    28 #include <AppKit/AppKit.h>
     28#include "NotImplemented.h"
    2929#include "WebEvent.h"
    3030#include <WebCore/GraphicsContext.h>
     
    123123    }
    124124
     125#ifndef NP_NO_CARBON
     126    if (m_eventModel == NPEventModelCarbon) {
     127        // Initialize the fake Carbon window.
     128        Rect bounds = { 0, 0, 0, 0 };
     129        CreateNewWindow(kDocumentWindowClass, 0, &bounds, reinterpret_cast<WindowRef*>(&m_npCGContext.window));
     130       
     131        // FIXME: Disable the backing store.
     132       
     133        m_npWindow.window = &m_npCGContext;
     134    }
     135#endif
     136
    125137    return true;
    126138}
     
    128140void NetscapePlugin::platformDestroy()
    129141{
     142#ifndef NP_NO_CARBON
     143    if (m_eventModel == NPEventModelCarbon) {
     144        // Destroy the fake Carbon window.
     145        ASSERT(m_npCGContext.window);
     146        DisposeWindow(static_cast<WindowRef>(m_npCGContext.window));
     147    }
     148#endif
    130149}
    131150
     
    144163}
    145164
     165#ifndef NP_NO_CARBON
     166WindowRef NetscapePlugin::windowRef() const
     167{
     168    ASSERT(m_eventModel == NPEventModelCarbon);
     169
     170    return reinterpret_cast<WindowRef>(m_npCGContext.window);
     171}
     172
     173static inline EventRecord initializeEventRecord(EventKind eventKind)
     174{
     175    EventRecord eventRecord;
     176
     177    eventRecord.what = eventKind;
     178    eventRecord.message = 0;
     179    eventRecord.when = TickCount();
     180    eventRecord.where = Point();
     181    eventRecord.modifiers = 0;
     182
     183    return eventRecord;
     184}
     185
     186static bool anyMouseButtonIsDown(const WebEvent& event)
     187{
     188    if (event.type() == WebEvent::MouseDown)
     189        return true;
     190
     191    if (event.type() == WebEvent::MouseMove && static_cast<const WebMouseEvent&>(event).button() != WebMouseEvent::NoButton)
     192        return true;
     193
     194    return false;
     195}
     196
     197static bool rightMouseButtonIsDown(const WebEvent& event)
     198{
     199    if (event.type() == WebEvent::MouseDown && static_cast<const WebMouseEvent&>(event).button() == WebMouseEvent::RightButton)
     200        return true;
     201   
     202    if (event.type() == WebEvent::MouseMove && static_cast<const WebMouseEvent&>(event).button() == WebMouseEvent::RightButton)
     203        return true;
     204   
     205    return false;
     206}
     207
     208   
     209static EventModifiers modifiersForEvent(const WebEvent& event)
     210{
     211    EventModifiers modifiers = 0;
     212
     213    // We only want to set the btnState if a mouse button is _not_ down.
     214    if (!anyMouseButtonIsDown(event))
     215        modifiers |= btnState;
     216
     217    if (event.metaKey())
     218        modifiers |= cmdKey;
     219
     220    if (event.shiftKey())
     221        modifiers |= shiftKey;
     222
     223    if (event.altKey())
     224        modifiers |= optionKey;
     225
     226    // Set controlKey if the control key is down or the right mouse button is down.
     227    if (event.controlKey() || rightMouseButtonIsDown(event))
     228        modifiers |= controlKey;
     229
     230    return modifiers;
     231}
     232
     233#endif
     234
    146235void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect)
    147236{
     237    CGContextRef platformContext = context->platformContext();
     238
    148239    // Translate the context so that the origin is at the top left corner of the plug-in view.
    149240    context->translate(m_frameRect.x(), m_frameRect.y());
     
    157248            NPCocoaEvent event = initializeEvent(NPCocoaEventDrawRect);
    158249
    159             event.data.draw.context = context->platformContext();
     250            event.data.draw.context = platformContext;
    160251            event.data.draw.x = dirtyRect.x() - m_frameRect.x();
    161252            event.data.draw.y = dirtyRect.y() - m_frameRect.y();
     
    166257            break;
    167258        }
    168        
     259
     260#ifndef NP_NO_CARBON
     261        case NPEventModelCarbon: {
     262            if (platformContext != m_npCGContext.context) {
     263                m_npCGContext.context = platformContext;
     264                callSetWindow();
     265            }
     266
     267            EventRecord event = initializeEventRecord(updateEvt);
     268            event.message = reinterpret_cast<unsigned long>(windowRef());
     269           
     270            NPP_HandleEvent(&event);
     271            break;           
     272        }
     273#endif
     274
    169275        default:
    170276            ASSERT_NOT_REACHED();
     
    252358        }
    253359
     360#ifndef NP_NO_CARBON
     361        case NPEventModelCarbon: {
     362            notImplemented();
     363            return false;
     364        }
     365#endif
     366
    254367        default:
    255368            ASSERT_NOT_REACHED();
     
    276389        }
    277390
     391#ifndef NP_NO_CARBON
     392        case NPEventModelCarbon:
     393            // Carbon doesn't have wheel events.
     394            break;
     395#endif
     396
    278397        default:
    279398            ASSERT_NOT_REACHED();
     
    293412        }
    294413
     414#ifndef NP_NO_CARBON
     415        case NPEventModelCarbon: {
     416            EventRecord eventRecord = initializeEventRecord(adjustCursorEvent);
     417            eventRecord.modifiers = modifiersForEvent(mouseEvent);
     418           
     419            return NPP_HandleEvent(&eventRecord);
     420        }
     421#endif
     422
    295423        default:
    296424            ASSERT_NOT_REACHED();
     
    309437            return NPP_HandleEvent(&event);
    310438        }
     439
     440#ifndef NP_NO_CARBON
     441        case NPEventModelCarbon: {
     442            EventRecord eventRecord = initializeEventRecord(adjustCursorEvent);
     443            eventRecord.modifiers = modifiersForEvent(mouseEvent);
     444           
     445            return NPP_HandleEvent(&eventRecord);
     446        }
     447#endif
    311448
    312449        default:
     
    385522        }
    386523
     524#ifndef NP_NO_CARBON
     525        case NPEventModelCarbon: {
     526            EventRecord event = initializeEventRecord(hasFocus ? getFocusEvent : loseFocusEvent);
     527
     528            NPP_HandleEvent(&event);
     529            break;
     530        }
     531#endif
     532           
    387533        default:
    388534            ASSERT_NOT_REACHED();
     
    401547            break;
    402548        }
     549       
     550#ifndef NP_NO_CARBON
     551        case NPEventModelCarbon: {
     552            HiliteWindow(windowRef(), hasFocus);
     553            if (hasFocus)
     554                SetUserFocusWindow(windowRef());
     555
     556            EventRecord event = initializeEventRecord(activateEvt);
     557            event.message = reinterpret_cast<unsigned long>(windowRef());
     558            if (hasFocus)
     559                event.modifiers |= activeFlag;
     560           
     561            NPP_HandleEvent(&event);
     562            break;
     563        }
     564#endif
    403565
    404566        default:
Note: See TracChangeset for help on using the changeset viewer.