Back to index

lightning-sunbird  0.9+nobinonly
Enumerations | Functions | Variables
AltWindowHandling.cpp File Reference
#include <Controls.h>
#include <Events.h>
#include "nsIPluginManager2.h"
#include "EventFilter.h"
#include "nsIEventHandler.h"
#include "AltWindowHandling.h"

Go to the source code of this file.

Enumerations

enum  { kBaseMenuID = 20000, kBaseSubMenuID = 200 }

Functions

Boolean EventFilter (EventRecord *event)
 This method filters events using a very low-level mechanism known as a jGNE filter.
Boolean MenuFilter (long menuSelection)
RegisteredWindow ** GetRegisteredWindow (nsPluginPlatformWindowRef window)
NS_METHOD AltRegisterWindow (nsIEventHandler *handler, nsPluginPlatformWindowRef window)
NS_METHOD AltUnregisterWindow (nsIEventHandler *handler, nsPluginPlatformWindowRef window)
static void sendActivateEvent (nsIEventHandler *handler, WindowRef window, Boolean active)
RegisteredWindowFindRegisteredWindow (nsPluginPlatformWindowRef window)

Variables

RegisteredWindowtheRegisteredWindows = NULL
RegisteredWindowtheActiveWindow = NULL
Boolean mEventFiltersInstalled = nil
static PRInt16 nextMenuID = kBaseMenuID
static PRInt16 nextSubMenuID = kBaseSubMenuID

Enumeration Type Documentation

anonymous enum
Enumerator:
kBaseMenuID 
kBaseSubMenuID 

Definition at line 269 of file AltWindowHandling.cpp.

     {
    kBaseMenuID = 20000,
    kBaseSubMenuID = 200
};

Function Documentation

Definition at line 67 of file AltWindowHandling.cpp.

{
    theRegisteredWindows = new RegisteredWindow(theRegisteredWindows, handler, window);
    
#ifdef XP_MAC
    // use jGNE to obtain events for registered windows.
    if (!mEventFiltersInstalled) {
        ::InstallEventFilters(&EventFilter, &MenuFilter);
        mEventFiltersInstalled = true;
    }

    // plugin expects the window to be shown and selected at this point.
    
    SInt16 variant = ::GetWVariant(window);
    if (variant == plainDBox) {
        ::ShowHide(window, true);
        ::BringToFront(window);
    } else {
        ::ShowWindow(window);
        ::SelectWindow(window);
    }
#endif

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 94 of file AltWindowHandling.cpp.

{
    RegisteredWindow** link = GetRegisteredWindow(window);
    if (link != NULL) {
        RegisteredWindow* registeredWindow = *link;
        if (registeredWindow == theActiveWindow)
            theActiveWindow = NULL;
        *link = registeredWindow->mNext;
        delete registeredWindow;
    }

#ifdef XP_MAC
    ::HideWindow(window);

    // if no windows registered, remove the filter.
    if (theRegisteredWindows == NULL) {
        ::RemoveEventFilters();
        mEventFiltersInstalled = false;
    }
#endif

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean EventFilter ( EventRecord *  event)

This method filters events using a very low-level mechanism known as a jGNE filter.

This filter gets first crack at all events before they are returned by WaitNextEvent or EventAvail. One trickiness is that the filter runs in all processes, so care must be taken not to act on events if the browser's process isn't current. So far, with activates, updates, and mouse clicks, it works quite well.

Definition at line 161 of file AltWindowHandling.cpp.

{
    Boolean filteredEvent = false;

    WindowRef window = WindowRef(event->message);
    nsPluginEvent pluginEvent = { event, window };
    EventRecord simulatedEvent;

    RegisteredWindow* registeredWindow;
    PRBool handled = PR_FALSE;
    
    // see if this event is for one of our registered windows.
    switch (event->what) {
    case nullEvent:
        // See if the frontmost window is one of our registered windows.
        // we want to somehow deliver mouse enter/leave events.
        window = ::FrontWindow();
        registeredWindow = FindRegisteredWindow(window);
        if (registeredWindow != NULL) {
            simulatedEvent = *event;
            simulatedEvent.what = nsPluginEventType_AdjustCursorEvent;
            pluginEvent.event = &simulatedEvent;
            pluginEvent.window = registeredWindow->mWindow;
            registeredWindow->mHandler->HandleEvent(&pluginEvent, &handled);
        }
        break;
    case keyDown:
    case keyUp:
    case autoKey:
        // See if the frontmost window is one of our registered windows.
        window = ::FrontWindow();
        registeredWindow = FindRegisteredWindow(window);
        if (registeredWindow != NULL) {
            pluginEvent.window = window;
            registeredWindow->mHandler->HandleEvent(&pluginEvent, &handled);
            filteredEvent = true;
        }
        break;
    case mouseDown:
        // use FindWindow to see if the click was in one our registered windows.
        short partCode = FindWindow(event->where, &window);
        switch (partCode) {
        case inContent:
        case inDrag:
        case inGrow:
        case inGoAway:
        case inZoomIn:
        case inZoomOut:
        case inCollapseBox:
        case inProxyIcon:
            registeredWindow = FindRegisteredWindow(window);
            if (registeredWindow != NULL) {
                // make sure this window has been activated before passing it the click.
                if (theActiveWindow == NULL) {
                    sendActivateEvent(registeredWindow->mHandler, window, true);
                    theActiveWindow = registeredWindow;
                }
                pluginEvent.window = window;
                registeredWindow->mHandler->HandleEvent(&pluginEvent, &handled);
                filteredEvent = true;
            } else if (theActiveWindow != NULL) {
                // a click is going into an unregistered window, if we are active,
                // the browser doesn't seem to be generating a deactivate event.
                // I think this is because PowerPlant is managing the windows, dang it.
                window = theActiveWindow->mWindow;
                sendActivateEvent(theActiveWindow->mHandler, window, false);
                ::HiliteWindow(window, false);
                theActiveWindow = NULL;
            }
            break;
        }
        break;
    case activateEvt:
        registeredWindow = FindRegisteredWindow(window);
        if (registeredWindow != NULL) {
            registeredWindow->mHandler->HandleEvent(&pluginEvent, &handled);
            filteredEvent = true;
            theActiveWindow = registeredWindow;
        }
        break;
    case updateEvt:
        registeredWindow = FindRegisteredWindow(window);
        if (registeredWindow != NULL) {
            GrafPtr port; GetPort(&port); SetPort(window); BeginUpdate(window);
                registeredWindow->mHandler->HandleEvent(&pluginEvent, &handled);
            EndUpdate(window); SetPort(port);
            filteredEvent = true;
        }
        break;
    case osEvt:
        if ((event->message & osEvtMessageMask) == (suspendResumeMessage << 24)) {
            registeredWindow = theActiveWindow;
            if (registeredWindow != NULL) {
                window = registeredWindow->mWindow;
                Boolean active = (event->message & resumeFlag) != 0;
                sendActivateEvent(registeredWindow->mHandler, window, active);
                pluginEvent.window = window;
                registeredWindow->mHandler->HandleEvent(&pluginEvent, &handled);
                ::HiliteWindow(window, active);
            }
        }
        break;
    }
    
    return filteredEvent;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 148 of file AltWindowHandling.cpp.

{
    RegisteredWindow** link = GetRegisteredWindow(window);
    return (link != NULL ? *link : NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 135 of file AltWindowHandling.cpp.

{
    RegisteredWindow** link = &theRegisteredWindows;
    RegisteredWindow* registeredWindow = *link;
    while (registeredWindow != NULL) {
        if (registeredWindow->mWindow == window)
            return link;
        link = &registeredWindow->mNext;
        registeredWindow = *link;
    }
    return NULL;
}

Here is the caller graph for this function:

Boolean MenuFilter ( long  menuSelection)

Definition at line 277 of file AltWindowHandling.cpp.

{
    if (theActiveWindow != NULL) {
        UInt16 menuID = (menuSelection >> 16);
        if ((menuID >= kBaseMenuID && menuID < nextMenuID) || (menuID >= kBaseSubMenuID && menuID < nextSubMenuID)) {
            EventRecord menuEvent;
            ::OSEventAvail(0, &menuEvent);
            menuEvent.what = nsPluginEventType_MenuCommandEvent;
            menuEvent.message = menuSelection;

            WindowRef window = theActiveWindow->mWindow;
            nsPluginEvent pluginEvent = { &menuEvent, window };
            PRBool handled = PR_FALSE;
            theActiveWindow->mHandler->HandleEvent(&pluginEvent, &handled);
            
            return handled;
        }
    }
    return false;
}

Here is the caller graph for this function:

static void sendActivateEvent ( nsIEventHandler handler,
WindowRef  window,
Boolean  active 
) [static]

Definition at line 118 of file AltWindowHandling.cpp.

{
    EventRecord event;
    ::OSEventAvail(0, &event);
    event.what = activateEvt;
    event.message = UInt32(window);
    if (active)
        event.modifiers |= activeFlag;
    else
        event.modifiers &= ~activeFlag;

    nsPluginEvent pluginEvent = { &event, window };
    PRBool handled = PR_FALSE;

    handler->HandleEvent(&pluginEvent, &handled);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 60 of file AltWindowHandling.cpp.

Definition at line 274 of file AltWindowHandling.cpp.

Definition at line 275 of file AltWindowHandling.cpp.

Definition at line 59 of file AltWindowHandling.cpp.

Definition at line 58 of file AltWindowHandling.cpp.