Bug 598397: Remove support for Carbon NPAPI. r=smichaud

This commit is contained in:
Josh Aas
2012-10-15 08:38:34 -04:00
parent edc0ba4ad1
commit 9198e7804c
13 changed files with 92 additions and 1005 deletions

View File

@@ -19,7 +19,7 @@ class nsPluginEvent;
// Do not make this interface scriptable, because the virtual functions in C++
// blocks will make script call the wrong functions.
[uuid(CE1EE148-B201-4DC7-8A65-311143EA01BF)]
[uuid(59BE4CA5-3CB0-40E6-A111-9A88C8477610)]
interface nsIPluginInstanceOwner : nsISupports
{
/**
@@ -111,10 +111,6 @@ interface nsIPluginInstanceOwner : nsISupports
void setEventModel(in int32_t eventModel);
%{C++
virtual void SendIdleEvent() = 0;
%}
/**
* Call NPP_SetWindow on the plugin.
*/

View File

@@ -2127,7 +2127,7 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
#ifndef NP_NO_CARBON
case NPNVsupportsCarbonBool: {
*(NPBool*)result = true;
*(NPBool*)result = false;
return NPERR_NO_ERROR;
}

View File

@@ -368,11 +368,6 @@ nsPluginHost::nsPluginHost()
PLUGIN_LOG(PLUGIN_LOG_ALWAYS,("nsPluginHost::ctor\n"));
PR_LogFlush();
#endif
#ifdef MAC_CARBON_PLUGINS
mVisiblePluginTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
mHiddenPluginTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
#endif
}
nsPluginHost::~nsPluginHost()
@@ -3810,74 +3805,8 @@ nsPluginHost::GetPluginTagForInstance(nsNPAPIPluginInstance *aPluginInstance,
return NS_OK;
}
#ifdef MAC_CARBON_PLUGINS
// Flash requires a minimum of 8 events per second to avoid audio skipping.
// Since WebKit uses a hidden plugin event rate of 4 events per second Flash
// uses a Carbon timer for WebKit which fires at 8 events per second.
#define HIDDEN_PLUGIN_DELAY 125
#define VISIBLE_PLUGIN_DELAY 20
#endif
void nsPluginHost::AddIdleTimeTarget(nsIPluginInstanceOwner* objectFrame, bool isVisible)
{
#ifdef MAC_CARBON_PLUGINS
nsTObserverArray<nsIPluginInstanceOwner*> *targetArray;
if (isVisible) {
targetArray = &mVisibleTimerTargets;
} else {
targetArray = &mHiddenTimerTargets;
}
if (targetArray->Contains(objectFrame)) {
return;
}
targetArray->AppendElement(objectFrame);
if (targetArray->Length() == 1) {
if (isVisible) {
mVisiblePluginTimer->InitWithCallback(this, VISIBLE_PLUGIN_DELAY, nsITimer::TYPE_REPEATING_SLACK);
} else {
mHiddenPluginTimer->InitWithCallback(this, HIDDEN_PLUGIN_DELAY, nsITimer::TYPE_REPEATING_SLACK);
}
}
#endif
}
void nsPluginHost::RemoveIdleTimeTarget(nsIPluginInstanceOwner* objectFrame)
{
#ifdef MAC_CARBON_PLUGINS
bool visibleRemoved = mVisibleTimerTargets.RemoveElement(objectFrame);
if (visibleRemoved && mVisibleTimerTargets.IsEmpty()) {
mVisiblePluginTimer->Cancel();
}
bool hiddenRemoved = mHiddenTimerTargets.RemoveElement(objectFrame);
if (hiddenRemoved && mHiddenTimerTargets.IsEmpty()) {
mHiddenPluginTimer->Cancel();
}
NS_ASSERTION(!(hiddenRemoved && visibleRemoved), "Plugin instance received visible and hidden idle event notifications");
#endif
}
NS_IMETHODIMP nsPluginHost::Notify(nsITimer* timer)
{
#ifdef MAC_CARBON_PLUGINS
if (timer == mVisiblePluginTimer) {
nsTObserverArray<nsIPluginInstanceOwner*>::ForwardIterator iter(mVisibleTimerTargets);
while (iter.HasMore()) {
iter.GetNext()->SendIdleEvent();
}
return NS_OK;
} else if (timer == mHiddenPluginTimer) {
nsTObserverArray<nsIPluginInstanceOwner*>::ForwardIterator iter(mHiddenTimerTargets);
while (iter.HasMore()) {
iter.GetNext()->SendIdleEvent();
}
return NS_OK;
}
#endif
nsRefPtr<nsPluginTag> pluginTag = mPlugins;
while (pluginTag) {
if (pluginTag->mUnloadTimer == timer) {

View File

@@ -38,10 +38,6 @@ class nsPluginNativeWindow;
class nsObjectLoadingContent;
class nsPluginInstanceOwner;
#if defined(XP_MACOSX) && !defined(NP_NO_CARBON)
#define MAC_CARBON_PLUGINS
#endif
class nsInvalidPluginTag : public nsISupports
{
public:
@@ -320,13 +316,6 @@ private:
// We need to hold a global ptr to ourselves because we register for
// two different CIDs for some reason...
static nsPluginHost* sInst;
#ifdef MAC_CARBON_PLUGINS
nsCOMPtr<nsITimer> mVisiblePluginTimer;
nsTObserverArray<nsIPluginInstanceOwner*> mVisibleTimerTargets;
nsCOMPtr<nsITimer> mHiddenPluginTimer;
nsTObserverArray<nsIPluginInstanceOwner*> mHiddenTimerTargets;
#endif
};
class NS_STACK_CLASS PluginDestructionGuard : protected PRCList

View File

@@ -321,6 +321,7 @@ nsPluginInstanceOwner::nsPluginInstanceOwner()
#ifdef XP_MACOSX
#ifndef NP_NO_CARBON
// We don't support Carbon, but it is still the default model for i386 NPAPI.
mEventModel = NPEventModelCarbon;
#else
mEventModel = NPEventModelCocoa;
@@ -328,10 +329,6 @@ nsPluginInstanceOwner::nsPluginInstanceOwner()
mUseAsyncRendering = false;
#endif
#if defined(XP_MACOSX) && !defined(NP_NO_CARBON)
mRegisteredScrollPositionListener = false;
#endif
mWaitingForPaint = false;
#ifdef MOZ_WIDGET_ANDROID
@@ -351,10 +348,6 @@ nsPluginInstanceOwner::~nsPluginInstanceOwner()
NS_DispatchToMainThread(event);
}
#ifdef MAC_CARBON_PLUGINS
CancelTimer();
#endif
mObjectFrame = nullptr;
for (cnt = 0; cnt < (mNumCachedAttrs + 1 + mNumCachedParams); cnt++) {
@@ -767,17 +760,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetNetscapeWindow(void *value)
NS_IMETHODIMP nsPluginInstanceOwner::SetEventModel(int32_t eventModel)
{
#ifdef XP_MACOSX
NPEventModel newEventModel = static_cast<NPEventModel>(eventModel);
#ifndef NP_NO_CARBON
bool eventModelChange = (mEventModel != newEventModel);
if (eventModelChange)
RemoveScrollPositionListener();
#endif
mEventModel = static_cast<NPEventModel>(newEventModel);
#ifndef NP_NO_CARBON
if (eventModelChange)
AddScrollPositionListener();
#endif
mEventModel = static_cast<NPEventModel>(eventModel);
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;
@@ -1353,20 +1336,6 @@ nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays()
#ifdef XP_MACOSX
#ifndef NP_NO_CARBON
static void InitializeEventRecord(EventRecord* event, ::Point* aMousePosition)
{
memset(event, 0, sizeof(EventRecord));
if (aMousePosition) {
event->where = *aMousePosition;
} else {
::GetGlobalMouse(&event->where);
}
event->when = ::TickCount();
event->modifiers = ::GetCurrentKeyModifiers();
}
#endif
static void InitializeNPCocoaEvent(NPCocoaEvent* event)
{
memset(event, 0, sizeof(NPCocoaEvent));
@@ -1595,19 +1564,6 @@ void* nsPluginInstanceOwner::SetPluginPortAndDetectChange()
return nullptr;
mPluginWindow->window = pluginPort;
#ifndef NP_NO_CARBON
if (GetEventModel() == NPEventModelCarbon &&
GetDrawingModel() == NPDrawingModelCoreGraphics) {
NP_CGContext* windowCGPort = static_cast<NP_CGContext*>(mPluginWindow->window);
if ((windowCGPort->context != mCGPluginPortCopy.context) ||
(windowCGPort->window != mCGPluginPortCopy.window)) {
mCGPluginPortCopy.context = windowCGPort->context;
mCGPluginPortCopy.window = windowCGPort->window;
mPluginPortChanged = true;
}
}
#endif
return mPluginWindow->window;
}
@@ -1650,54 +1606,6 @@ nsPluginInstanceOwner::GetEventloopNestingLevel()
return currentLevel;
}
void nsPluginInstanceOwner::ScrollPositionWillChange(nscoord aX, nscoord aY)
{
#ifdef MAC_CARBON_PLUGINS
if (GetEventModel() != NPEventModelCarbon)
return;
CancelTimer();
if (mInstance) {
nsCOMPtr<nsIPluginWidget> pluginWidget = do_QueryInterface(mWidget);
if (pluginWidget && NS_SUCCEEDED(pluginWidget->StartDrawPlugin())) {
EventRecord scrollEvent;
InitializeEventRecord(&scrollEvent, nullptr);
scrollEvent.what = NPEventType_ScrollingBeginsEvent;
void* window = FixUpPluginWindow(ePluginPaintDisable);
if (window) {
mInstance->HandleEvent(&scrollEvent, nullptr);
}
pluginWidget->EndDrawPlugin();
}
}
#endif
}
void nsPluginInstanceOwner::ScrollPositionDidChange(nscoord aX, nscoord aY)
{
#ifdef MAC_CARBON_PLUGINS
if (GetEventModel() != NPEventModelCarbon)
return;
if (mInstance) {
nsCOMPtr<nsIPluginWidget> pluginWidget = do_QueryInterface(mWidget);
if (pluginWidget && NS_SUCCEEDED(pluginWidget->StartDrawPlugin())) {
EventRecord scrollEvent;
InitializeEventRecord(&scrollEvent, nullptr);
scrollEvent.what = NPEventType_ScrollingEndsEvent;
void* window = FixUpPluginWindow(ePluginPaintEnable);
if (window) {
mInstance->HandleEvent(&scrollEvent, nullptr);
}
pluginWidget->EndDrawPlugin();
}
}
#endif
}
#ifdef MOZ_WIDGET_ANDROID
// Modified version of nsFrame::GetOffsetToCrossDoc that stops when it
@@ -1938,35 +1846,6 @@ nsresult nsPluginInstanceOwner::Text(nsIDOMEvent* aTextEvent)
nsresult nsPluginInstanceOwner::ProcessKeyPress(nsIDOMEvent* aKeyEvent)
{
#ifdef XP_MACOSX
#ifndef NP_NO_CARBON
if (GetEventModel() == NPEventModelCarbon) {
// KeyPress events are really synthesized keyDown events.
// Here we check the native message of the event so that
// we won't send the plugin two keyDown events.
nsEvent *theEvent = aKeyEvent->GetInternalNSEvent();
const EventRecord *ev;
if (theEvent &&
theEvent->message == NS_KEY_PRESS &&
(ev = (EventRecord*)(((nsGUIEvent*)theEvent)->pluginEvent)) &&
ev->what == keyDown)
return aKeyEvent->PreventDefault(); // consume event
// Nasty hack to avoid recursive event dispatching with Java. Java can
// dispatch key events to a TSM handler, which comes back and calls
// [ChildView insertText:] on the cocoa widget, which sends a key
// event back down.
static bool sInKeyDispatch = false;
if (sInKeyDispatch)
return aKeyEvent->PreventDefault(); // consume event
sInKeyDispatch = true;
nsresult rv = DispatchKeyToPlugin(aKeyEvent);
sInKeyDispatch = false;
return rv;
}
#endif
return DispatchKeyToPlugin(aKeyEvent);
#else
if (SendNativeEvents())
@@ -2153,9 +2032,6 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const nsGUIEvent& anEvent)
NPEventModel eventModel = GetEventModel();
// If we have to synthesize an event we'll use one of these.
#ifndef NP_NO_CARBON
EventRecord synthCarbonEvent;
#endif
NPCocoaEvent synthCocoaEvent;
void* event = anEvent.pluginEvent;
nsPoint pt =
@@ -2169,99 +2045,45 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const nsGUIEvent& anEvent)
size_t intScaleFactor = ceil(scaleFactor);
nsIntPoint ptPx(presContext->AppUnitsToDevPixels(pt.x) / intScaleFactor,
presContext->AppUnitsToDevPixels(pt.y) / intScaleFactor);
#ifndef NP_NO_CARBON
nsIntPoint geckoScreenCoords = mWidget->WidgetToScreenOffset();
::Point carbonPt = { static_cast<short>(ptPx.y + geckoScreenCoords.y / intScaleFactor),
static_cast<short>(ptPx.x + geckoScreenCoords.x / intScaleFactor) };
if (eventModel == NPEventModelCarbon) {
if (event && anEvent.eventStructType == NS_MOUSE_EVENT) {
static_cast<EventRecord*>(event)->where = carbonPt;
}
}
#endif
if (!event) {
#ifndef NP_NO_CARBON
if (eventModel == NPEventModelCarbon) {
InitializeEventRecord(&synthCarbonEvent, &carbonPt);
} else
#endif
{
InitializeNPCocoaEvent(&synthCocoaEvent);
}
InitializeNPCocoaEvent(&synthCocoaEvent);
switch (anEvent.message) {
case NS_FOCUS_CONTENT:
case NS_BLUR_CONTENT:
#ifndef NP_NO_CARBON
if (eventModel == NPEventModelCarbon) {
synthCarbonEvent.what = (anEvent.message == NS_FOCUS_CONTENT) ?
NPEventType_GetFocusEvent : NPEventType_LoseFocusEvent;
event = &synthCarbonEvent;
}
#endif
break;
case NS_MOUSE_MOVE:
{
// Ignore mouse-moved events that happen as part of a dragging
// operation that started over another frame. See bug 525078.
nsRefPtr<nsFrameSelection> frameselection = mObjectFrame->GetFrameSelection();
if (!frameselection->GetMouseDownState() ||
(nsIPresShell::GetCapturingContent() == mObjectFrame->GetContent())) {
#ifndef NP_NO_CARBON
if (eventModel == NPEventModelCarbon) {
synthCarbonEvent.what = osEvt;
event = &synthCarbonEvent;
} else
#endif
{
synthCocoaEvent.type = NPCocoaEventMouseMoved;
synthCocoaEvent.data.mouse.pluginX = static_cast<double>(ptPx.x);
synthCocoaEvent.data.mouse.pluginY = static_cast<double>(ptPx.y);
event = &synthCocoaEvent;
}
}
}
break;
case NS_MOUSE_BUTTON_DOWN:
#ifndef NP_NO_CARBON
if (eventModel == NPEventModelCarbon) {
synthCarbonEvent.what = mouseDown;
event = &synthCarbonEvent;
} else
#endif
{
synthCocoaEvent.type = NPCocoaEventMouseDown;
(nsIPresShell::GetCapturingContent() == mObjectFrame->GetContent())) {
synthCocoaEvent.type = NPCocoaEventMouseMoved;
synthCocoaEvent.data.mouse.pluginX = static_cast<double>(ptPx.x);
synthCocoaEvent.data.mouse.pluginY = static_cast<double>(ptPx.y);
event = &synthCocoaEvent;
}
}
break;
case NS_MOUSE_BUTTON_DOWN:
synthCocoaEvent.type = NPCocoaEventMouseDown;
synthCocoaEvent.data.mouse.pluginX = static_cast<double>(ptPx.x);
synthCocoaEvent.data.mouse.pluginY = static_cast<double>(ptPx.y);
event = &synthCocoaEvent;
break;
case NS_MOUSE_BUTTON_UP:
// If we're in a dragging operation that started over another frame,
// either ignore the mouse-up event (in the Carbon Event Model) or
// convert it into a mouse-entered event (in the Cocoa Event Model).
// See bug 525078.
if ((static_cast<const nsMouseEvent&>(anEvent).button == nsMouseEvent::eLeftButton) &&
(nsIPresShell::GetCapturingContent() != mObjectFrame->GetContent())) {
if (eventModel == NPEventModelCocoa) {
synthCocoaEvent.type = NPCocoaEventMouseEntered;
synthCocoaEvent.data.mouse.pluginX = static_cast<double>(ptPx.x);
synthCocoaEvent.data.mouse.pluginY = static_cast<double>(ptPx.y);
event = &synthCocoaEvent;
}
synthCocoaEvent.type = NPCocoaEventMouseEntered;
synthCocoaEvent.data.mouse.pluginX = static_cast<double>(ptPx.x);
synthCocoaEvent.data.mouse.pluginY = static_cast<double>(ptPx.y);
event = &synthCocoaEvent;
} else {
#ifndef NP_NO_CARBON
if (eventModel == NPEventModelCarbon) {
synthCarbonEvent.what = mouseUp;
event = &synthCarbonEvent;
} else
#endif
{
synthCocoaEvent.type = NPCocoaEventMouseUp;
synthCocoaEvent.data.mouse.pluginX = static_cast<double>(ptPx.x);
synthCocoaEvent.data.mouse.pluginY = static_cast<double>(ptPx.y);
event = &synthCocoaEvent;
}
synthCocoaEvent.type = NPCocoaEventMouseUp;
synthCocoaEvent.data.mouse.pluginX = static_cast<double>(ptPx.x);
synthCocoaEvent.data.mouse.pluginY = static_cast<double>(ptPx.y);
event = &synthCocoaEvent;
}
break;
default:
@@ -2275,14 +2097,6 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const nsGUIEvent& anEvent)
}
}
#ifndef NP_NO_CARBON
// Work around an issue in the Flash plugin, which can cache a pointer
// to a doomed TSM document (one that belongs to a NSTSMInputContext)
// and try to activate it after it has been deleted. See bug 183313.
if (eventModel == NPEventModelCarbon && anEvent.message == NS_FOCUS_CONTENT)
::DeactivateTSMDocument(::TSMGetActiveDocument());
#endif
int16_t response = kNPEventNotHandled;
void* window = FixUpPluginWindow(ePluginPaintEnable);
if (window || (eventModel == NPEventModelCocoa)) {
@@ -2755,10 +2569,6 @@ nsPluginInstanceOwner::Destroy()
if (mObjectFrame)
mObjectFrame->SetInstanceOwner(nullptr);
#ifdef MAC_CARBON_PLUGINS
// stop the timer explicitly to reduce reference count.
CancelTimer();
#endif
#ifdef XP_MACOSX
RemoveFromCARefreshTimer();
if (mColorProfile)
@@ -2836,20 +2646,7 @@ void nsPluginInstanceOwner::Paint(const gfxRect& aDirtyRect, CGContextRef cgCont
nsCOMPtr<nsIPluginWidget> pluginWidget = do_QueryInterface(mWidget);
if (pluginWidget && NS_SUCCEEDED(pluginWidget->StartDrawPlugin())) {
#ifndef NP_NO_CARBON
void* window = FixUpPluginWindow(ePluginPaintEnable);
if (GetEventModel() == NPEventModelCarbon && window) {
EventRecord updateEvent;
InitializeEventRecord(&updateEvent, nullptr);
updateEvent.what = updateEvt;
updateEvent.message = UInt32(window);
mInstance->HandleEvent(&updateEvent, nullptr);
} else if (GetEventModel() == NPEventModelCocoa)
#endif
{
DoCocoaEventDrawRect(dirtyRectCopy, cgContext);
}
DoCocoaEventDrawRect(dirtyRectCopy, cgContext);
pluginWidget->EndDrawPlugin();
}
}
@@ -3178,50 +2975,6 @@ nsPluginInstanceOwner::Renderer::DrawWithXlib(gfxXlibSurface* xsurface,
}
#endif
void nsPluginInstanceOwner::SendIdleEvent()
{
#ifdef MAC_CARBON_PLUGINS
// validate the plugin clipping information by syncing the plugin window info to
// reflect the current widget location. This makes sure that everything is updated
// correctly in the event of scrolling in the window.
if (mInstance) {
nsCOMPtr<nsIPluginWidget> pluginWidget = do_QueryInterface(mWidget);
if (pluginWidget && NS_SUCCEEDED(pluginWidget->StartDrawPlugin())) {
void* window = FixUpPluginWindow(ePluginPaintEnable);
if (window) {
EventRecord idleEvent;
InitializeEventRecord(&idleEvent, nullptr);
idleEvent.what = nullEvent;
// give a bogus 'where' field of our null event when hidden, so Flash
// won't respond to mouse moves in other tabs, see bug 120875
if (!mWidgetVisible)
idleEvent.where.h = idleEvent.where.v = 20000;
mInstance->HandleEvent(&idleEvent, nullptr);
}
pluginWidget->EndDrawPlugin();
}
}
#endif
}
#ifdef MAC_CARBON_PLUGINS
void nsPluginInstanceOwner::StartTimer(bool isVisible)
{
if (GetEventModel() != NPEventModelCarbon)
return;
mPluginHost->AddIdleTimeTarget(this, isVisible);
}
void nsPluginInstanceOwner::CancelTimer()
{
mPluginHost->RemoveIdleTimeTarget(this);
}
#endif
nsresult nsPluginInstanceOwner::Init(nsIContent* aContent)
{
mLastEventloopNestingLevel = GetEventloopNestingLevel();
@@ -3413,10 +3166,6 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void)
// be initialized first
mPluginWindow->type = NPWindowTypeWindow;
mPluginWindow->window = GetPluginPortFromWidget();
#ifdef MAC_CARBON_PLUGINS
// start the idle timer.
StartTimer(true);
#endif
// tell the plugin window about the widget
mPluginWindow->SetPluginWidget(mWidget);
@@ -3440,36 +3189,23 @@ void* nsPluginInstanceOwner::FixUpPluginWindow(int32_t inPaintState)
if (!mWidget || !mPluginWindow || !mInstance || !mObjectFrame)
return nullptr;
NPEventModel eventModel = GetEventModel();
nsCOMPtr<nsIPluginWidget> pluginWidget = do_QueryInterface(mWidget);
if (!pluginWidget)
return nullptr;
// If we've already set up a CGContext in nsObjectFrame::PaintPlugin(), we
// don't want calls to SetPluginPortAndDetectChange() to step on our work.
void* pluginPort = nullptr;
if (mInCGPaintLevel > 0) {
pluginPort = mPluginWindow->window;
} else {
pluginPort = SetPluginPortAndDetectChange();
if (mInCGPaintLevel < 1) {
SetPluginPortAndDetectChange();
}
#ifdef MAC_CARBON_PLUGINS
if (eventModel == NPEventModelCarbon && !pluginPort)
return nullptr;
#endif
// We'll need the top-level Cocoa window for the Cocoa event model.
void* cocoaTopLevelWindow = nullptr;
if (eventModel == NPEventModelCocoa) {
nsIWidget* widget = mObjectFrame->GetNearestWidget();
if (!widget)
return nullptr;
cocoaTopLevelWindow = widget->GetNativeData(NS_NATIVE_WINDOW);
if (!cocoaTopLevelWindow)
return nullptr;
}
nsIWidget* widget = mObjectFrame->GetNearestWidget();
if (!widget)
return nullptr;
void *cocoaTopLevelWindow = widget->GetNativeData(NS_NATIVE_WINDOW);
if (!cocoaTopLevelWindow)
return nullptr;
nsIntPoint pluginOrigin;
nsIntRect widgetClip;
@@ -3487,14 +3223,7 @@ void* nsPluginInstanceOwner::FixUpPluginWindow(int32_t inPaintState)
nsIntPoint geckoScreenCoords = mWidget->WidgetToScreenOffset();
nsRect windowRect;
#ifndef NP_NO_CARBON
if (eventModel == NPEventModelCarbon) {
NS_NPAPI_CarbonWindowFrame(static_cast<WindowRef>(static_cast<NP_CGContext*>(pluginPort)->window), windowRect);
} else
#endif
{
NS_NPAPI_CocoaWindowFrame(cocoaTopLevelWindow, windowRect);
}
NS_NPAPI_CocoaWindowFrame(cocoaTopLevelWindow, windowRect);
double scaleFactor = 1.0;
GetContentsScaleFactor(&scaleFactor);
@@ -3526,7 +3255,8 @@ void* nsPluginInstanceOwner::FixUpPluginWindow(int32_t inPaintState)
if (mPluginWindow->clipRect.left != oldClipRect.left ||
mPluginWindow->clipRect.top != oldClipRect.top ||
mPluginWindow->clipRect.right != oldClipRect.right ||
mPluginWindow->clipRect.bottom != oldClipRect.bottom)
mPluginWindow->clipRect.bottom != oldClipRect.bottom ||
mPluginPortChanged)
{
if (UseAsyncRendering()) {
mInstance->AsyncSetWindow(mPluginWindow);
@@ -3535,30 +3265,11 @@ void* nsPluginInstanceOwner::FixUpPluginWindow(int32_t inPaintState)
mPluginWindow->CallSetWindow(mInstance);
}
mPluginPortChanged = false;
#ifdef MAC_CARBON_PLUGINS
// if the clipRect is of size 0, make the null timer fire less often
CancelTimer();
if (mPluginWindow->clipRect.left == mPluginWindow->clipRect.right ||
mPluginWindow->clipRect.top == mPluginWindow->clipRect.bottom) {
StartTimer(false);
}
else {
StartTimer(true);
}
#endif
} else if (mPluginPortChanged) {
if (UseAsyncRendering()) {
mInstance->AsyncSetWindow(mPluginWindow);
}
else {
mPluginWindow->CallSetWindow(mInstance);
}
mPluginPortChanged = false;
}
// After the first NPP_SetWindow call we need to send an initial
// top-level window focus event.
if (eventModel == NPEventModelCocoa && !mSentInitialTopLevelWindowEvent) {
if (!mSentInitialTopLevelWindowEvent) {
// Set this before calling ProcessEvent to avoid endless recursion.
mSentInitialTopLevelWindowEvent = true;
@@ -3571,11 +3282,6 @@ void* nsPluginInstanceOwner::FixUpPluginWindow(int32_t inPaintState)
ProcessEvent(pluginEvent);
}
#ifdef MAC_CARBON_PLUGINS
if (GetDrawingModel() == NPDrawingModelCoreGraphics && eventModel == NPEventModelCarbon)
return static_cast<NP_CGContext*>(pluginPort)->window;
#endif
return nullptr;
}
@@ -3689,38 +3395,6 @@ nsPluginInstanceOwner::CallSetWindow()
return NS_OK;
}
#if defined(XP_MACOSX) && !defined(NP_NO_CARBON)
void nsPluginInstanceOwner::AddScrollPositionListener()
{
// We need to register as a scroll position listener on every scrollable frame up to the top.
if (!mRegisteredScrollPositionListener && GetEventModel() == NPEventModelCarbon) {
for (nsIFrame* f = mObjectFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
nsIScrollableFrame* sf = do_QueryFrame(f);
if (sf) {
sf->AddScrollPositionListener(this);
}
}
mRegisteredScrollPositionListener = true;
}
}
void nsPluginInstanceOwner::RemoveScrollPositionListener()
{
// Our frame is changing or going away, unregister for a scroll position listening.
// It's OK to unregister when we didn't register, so don't be strict about unregistering.
// Better to unregister when we didn't have to than to not unregister when we should.
if (mRegisteredScrollPositionListener) {
for (nsIFrame* f = mObjectFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
nsIScrollableFrame* sf = do_QueryFrame(f);
if (sf) {
sf->RemoveScrollPositionListener(this);
}
}
mRegisteredScrollPositionListener = false;
}
}
#endif
NS_IMETHODIMP
nsPluginInstanceOwner::GetContentsScaleFactor(double *result)
{
@@ -3773,11 +3447,6 @@ void nsPluginInstanceOwner::SetFrame(nsObjectFrame *aFrame)
container->SetCurrentImageInTransaction(nullptr);
}
// Scroll position listening is only required for Carbon event model plugins on Mac OS X.
#if defined(XP_MACOSX) && !defined(NP_NO_CARBON)
RemoveScrollPositionListener();
#endif
// Make sure the old frame isn't holding a reference to us.
mObjectFrame->SetInstanceOwner(nullptr);
}
@@ -3795,11 +3464,6 @@ void nsPluginInstanceOwner::SetFrame(nsObjectFrame *aFrame)
}
mObjectFrame->FixupWindow(mObjectFrame->GetContentRectRelativeToSelf().Size());
mObjectFrame->InvalidateFrame();
// Scroll position listening is only required for Carbon event model plugins on Mac OS X.
#if defined(XP_MACOSX) && !defined(NP_NO_CARBON)
AddScrollPositionListener();
#endif
nsFocusManager* fm = nsFocusManager::GetFocusManager();
const nsIContent* content = aFrame->GetContent();

View File

@@ -13,7 +13,6 @@
#include "nsIPluginTagInfo.h"
#include "nsIPrivacyTransitionObserver.h"
#include "nsIDOMEventListener.h"
#include "nsIScrollPositionListener.h"
#include "nsPluginHost.h"
#include "nsPluginNativeWindow.h"
#include "nsWeakReference.h"
@@ -48,7 +47,6 @@ class gfxXlibSurface;
class nsPluginInstanceOwner : public nsIPluginInstanceOwner,
public nsIPluginTagInfo,
public nsIDOMEventListener,
public nsIScrollPositionListener,
public nsIPrivacyTransitionObserver,
public nsSupportsWeakReference
{
@@ -103,17 +101,7 @@ public:
#elif defined(XP_OS2)
void Paint(const nsRect& aDirtyRect, HPS aHPS);
#endif
#ifdef MAC_CARBON_PLUGINS
void CancelTimer();
void StartTimer(bool isVisible);
#endif
void SendIdleEvent();
// nsIScrollPositionListener interface
virtual void ScrollPositionWillChange(nscoord aX, nscoord aY);
virtual void ScrollPositionDidChange(nscoord aX, nscoord aY);
//locals
nsresult Init(nsIContent* aContent);
@@ -275,11 +263,6 @@ private:
bool mFullScreen;
void* mJavaView;
#endif
#if defined(XP_MACOSX) && !defined(NP_NO_CARBON)
void AddScrollPositionListener();
void RemoveScrollPositionListener();
#endif
nsPluginNativeWindow *mPluginWindow;
nsRefPtr<nsNPAPIPluginInstance> mInstance;
@@ -317,9 +300,6 @@ private:
#endif
bool mPluginWindowVisible;
bool mPluginDocumentActiveState;
#if defined(XP_MACOSX) && !defined(NP_NO_CARBON)
bool mRegisteredScrollPositionListener;
#endif
uint16_t mNumCachedAttrs;
uint16_t mNumCachedParams;

View File

@@ -69,20 +69,6 @@ pluginInstanceInit(InstanceData* instanceData)
return NPERR_INCOMPATIBLE_VERSION_ERROR;
}
#ifndef NP_NO_CARBON
// The test plugin will test using Carbon NPAPI if it is available. This
// is simply because we want to test Gecko's Carbon NPAPI support. You can
// override this behavior with an environment variable.
if (!getenv("TEST_COCOA_NPAPI")) {
NPBool supportsCarbonEvents = false;
if ((NPN_GetValue(npp, NPNVsupportsCarbonBool, &supportsCarbonEvents) == NPERR_NO_ERROR) &&
supportsCarbonEvents) {
instanceData->eventModel = NPEventModelCarbon;
return NPERR_NO_ERROR;
}
}
#endif
NPBool supportsCocoaEvents = false;
if ((NPN_GetValue(npp, NPNVsupportsCocoaBool, &supportsCocoaEvents) == NPERR_NO_ERROR) &&
supportsCocoaEvents) {
@@ -158,16 +144,7 @@ pluginDraw(InstanceData* instanceData, NPCocoaEvent* event)
NPWindow window = instanceData->window;
CGContextRef cgContext = NULL;
#ifndef NP_NO_CARBON
if (instanceData->eventModel == NPEventModelCocoa) {
cgContext = event->data.draw.context;
} else {
cgContext = ((NP_CGContext*)(window.window))->context;
}
#else
cgContext = event->data.draw.context;
#endif
CGContextRef cgContext = event->data.draw.context;
float windowWidth = window.width;
float windowHeight = window.height;
@@ -255,40 +232,6 @@ pluginDraw(InstanceData* instanceData, NPCocoaEvent* event)
int16_t
pluginHandleEvent(InstanceData* instanceData, void* event)
{
#ifndef NP_NO_CARBON
if (instanceData->eventModel == NPEventModelCarbon) {
EventRecord* carbonEvent = (EventRecord*)event;
if (!carbonEvent)
return kNPEventNotHandled;
NPWindow* w = &instanceData->window;
switch (carbonEvent->what) {
case updateEvt:
pluginDraw(instanceData, NULL);
break;
case mouseDown:
case mouseUp:
case osEvt:
{
Rect globalBounds = {0};
WindowRef nativeWindow = static_cast<WindowRef>(static_cast<NP_CGContext*>(w->window)->window);
if (nativeWindow)
::GetWindowBounds(nativeWindow, kWindowStructureRgn, &globalBounds);
instanceData->lastMouseX = carbonEvent->where.h - w->x - globalBounds.left;
instanceData->lastMouseY = carbonEvent->where.v - w->y - globalBounds.top;
if (carbonEvent->what == mouseUp) {
instanceData->mouseUpEventCount++;
}
break;
}
default:
return kNPEventNotHandled;
}
return kNPEventHandled;
}
#endif
NPCocoaEvent* cocoaEvent = (NPCocoaEvent*)event;
if (!cocoaEvent)
return kNPEventNotHandled;

View File

@@ -157,9 +157,7 @@ using mozilla::DefaultXDisplay;
static PRLogModuleInfo *nsObjectFrameLM = PR_NewLogModule("nsObjectFrame");
#endif /* PR_LOGGING */
#if defined(XP_MACOSX) && !defined(NP_NO_CARBON)
#define MAC_CARBON_PLUGINS
#if defined(XP_MACOSX) && !defined(__LP64__)
// The header files QuickdrawAPI.h and QDOffscreen.h are missing on OS X 10.7
// and up (though the QuickDraw APIs defined in them are still present) -- so
@@ -194,7 +192,7 @@ extern "C" {
#endif /* __QDOFFSCREEN__ */
}
#endif /* #if defined(XP_MACOSX) && !defined(NP_NO_CARBON) */
#endif /* #if defined(XP_MACOSX) && !defined(__LP64__) */
using namespace mozilla;
using namespace mozilla::plugins;
@@ -1345,7 +1343,7 @@ nsObjectFrame::PrintPlugin(nsRenderingContext& aRenderingContext,
window.clipRect.left = 0; window.clipRect.right = 0;
// platform specific printing code
#ifdef MAC_CARBON_PLUGINS
#if defined(XP_MACOSX) && !defined(__LP64__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Don't use this code if any of the QuickDraw APIs it currently requires
// are missing (as they probably will be on OS X 10.8 and up).
@@ -1815,30 +1813,6 @@ nsObjectFrame::PaintPlugin(nsDisplayListBuilder* aBuilder,
nativeDrawing.EndNativeDrawing();
return;
}
#ifndef NP_NO_CARBON
if (mInstanceOwner->GetEventModel() == NPEventModelCarbon &&
!mInstanceOwner->SetPluginPortAndDetectChange()) {
NS_WARNING("null plugin port during PaintPlugin");
nativeDrawing.EndNativeDrawing();
return;
}
// In the Carbon event model...
// If gfxQuartzNativeDrawing hands out a CGContext different from the
// one set by SetPluginPortAndDetectChange(), we need to pass it to the
// plugin via SetWindow(). This will happen in nsPluginInstanceOwner::
// FixUpPluginWindow(), called from nsPluginInstanceOwner::Paint().
// (If SetPluginPortAndDetectChange() made any changes itself, this has
// already been detected in that method, and will likewise result in a
// call to SetWindow() from FixUpPluginWindow().)
NP_CGContext* windowContext = static_cast<NP_CGContext*>(window->window);
if (mInstanceOwner->GetEventModel() == NPEventModelCarbon &&
windowContext->context != cgContext) {
windowContext->context = cgContext;
cgPluginPortCopy->context = cgContext;
mInstanceOwner->SetPluginPortChanged(true);
}
#endif
mInstanceOwner->BeginCGPaint();
if (mInstanceOwner->GetDrawingModel() == NPDrawingModelCoreAnimation ||
@@ -2122,16 +2096,6 @@ nsObjectFrame::HandleEvent(nsPresContext* aPresContext,
}
#endif
/*
// XXXndeakin review note: I don't see how this would ever be called.
if (anEvent->message == NS_DESTROY) {
#ifdef MAC_CARBON_PLUGINS
mInstanceOwner->CancelTimer();
#endif
return rv;
}
*/
return nsObjectFrameSuper::HandleEvent(aPresContext, anEvent, anEventStatus);
}

View File

@@ -627,7 +627,7 @@ public:
static void ConvertCocoaKeyEventToNPCocoaEvent(NSEvent* aCocoaEvent,
NPCocoaEvent& aPluginEvent);
#ifndef NP_NO_CARBON
#ifndef __LP64__
/**
* InstallPluginKeyEventsHandler() is called when initializing process.
@@ -652,7 +652,7 @@ public:
mPluginTSMInComposition = aInComposition;
}
#endif // #ifndef NP_NO_CARBON
#endif // #ifndef __LP64__
protected:
bool mIgnoreNextKeyUpEvent;
@@ -660,35 +660,13 @@ protected:
PluginTextInputHandler(nsChildView* aWidget, NSView<mozView> *aNativeView);
~PluginTextInputHandler();
#ifndef NP_NO_CARBON
/**
* ConvertCocoaKeyEventToCarbonEvent() converts aCocoaKeyEvent to
* aCarbonKeyEvent.
*
* @param aCocoaKeyEvent A Cocoa key event.
* @param aCarbonKeyEvent Converted Carbon event from aCocoaEvent.
* @param aMakeKeyDownEventIfNSFlagsChanged
* If aCocoaKeyEvent isn't NSFlagsChanged event,
* this is ignored. Otherwise, i.e., if
* aCocoaKeyEvent is NSFlagsChanged event,
* set TRUE if you need a keydown event.
* Otherwise, Set FALSE for a keyup event.
*/
static void ConvertCocoaKeyEventToCarbonEvent(
NSEvent* aCocoaKeyEvent,
EventRecord& aCarbonKeyEvent,
bool aMakeKeyDownEventIfNSFlagsChanged = false);
#endif // #ifndef NP_NO_CARBON
private:
#ifndef NP_NO_CARBON
#ifndef __LP64__
TSMDocumentID mPluginTSMDoc;
bool mPluginTSMInComposition;
#endif // #ifndef NP_NO_CARBON
#endif // #ifndef __LP64__
bool mPluginComplexTextInputRequested;
@@ -711,7 +689,7 @@ private:
*/
bool IsInPluginComposition();
#ifndef NP_NO_CARBON
#ifndef __LP64__
/**
* Create a TSM document for use with plugins, so that we can support IME in
@@ -734,17 +712,6 @@ private:
*/
void HandleCarbonPluginKeyEvent(EventRef aKeyEvent);
/**
* ConvertUnicodeToCharCode() converts aUnichar to native encoded string.
*
* @param aUniChar A unicode character.
* @param aOutChar Native encoded string for aUniChar.
* @return TRUE if the converting succeeded.
* Otherwise, FALSE.
*/
static bool ConvertUnicodeToCharCode(PRUnichar aUniChar,
unsigned char* aOutChar);
/**
* Target for text services events sent as the result of calls made to
* TSMProcessRawKeyEvent() in HandleKeyDownEventForPlugin() when a plugin has
@@ -760,7 +727,7 @@ private:
static EventHandlerRef sPluginKeyEventsHandler;
#endif // #ifndef NP_NO_CARBON
#endif // #ifndef __LP64__
};
/**

View File

@@ -23,17 +23,37 @@
#ifdef __LP64__
#include "ComplexTextInputPanel.h"
#endif // __LP64__
#ifndef NP_NO_CARBON
#include <objc/runtime.h>
#endif // NP_NO_CARBON
#endif // __LP64__
#ifdef MOZ_LOGGING
#define FORCE_PR_LOG
#endif
#include "prlog.h"
#ifndef __LP64__
enum {
// Currently focused ChildView (while this TSM document is active).
// Transient (only set while TSMProcessRawKeyEvent() is processing a key
// event), and the ChildView will be retained and released around the call
// to TSMProcessRawKeyEvent() -- so it can be weak.
kFocusedChildViewTSMDocPropertyTag = 'GKFV', // type ChildView* [WEAK]
};
// Undocumented HIToolbox function used by WebKit to allow Carbon-based IME
// to work in a Cocoa-based browser (like Safari or Cocoa-widgets Firefox).
// (Recent WebKit versions actually use a thin wrapper around this function
// called WKSendKeyEventToTSM().)
//
// Calling TSMProcessRawKeyEvent() from ChildView's keyDown: and keyUp:
// methods (when the ChildView is a plugin view) bypasses Cocoa's IME
// infrastructure and (instead) causes Carbon TSM events to be sent on each
// NSKeyDown event. We install a Carbon event handler
// (PluginKeyEventsHandler()) to catch these events and pass them to Gecko
// (which in turn passes them to the plugin).
extern "C" long TSMProcessRawKeyEvent(EventRef carbonEvent);
#endif // __LP64__
using namespace mozilla;
using namespace mozilla::widget;
@@ -1299,14 +1319,6 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
nsKeyEvent keydownEvent(true, NS_KEY_DOWN, mWidget);
InitKeyEvent(aNativeEvent, keydownEvent);
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
if ([mView pluginEventModel] == NPEventModelCarbon) {
ConvertCocoaKeyEventToCarbonEvent(aNativeEvent, carbonEvent, true);
keydownEvent.pluginEvent = &carbonEvent;
}
#endif // #ifndef NP_NO_CARBON
currentKeyEvent->mKeyDownHandled = DispatchEvent(keydownEvent);
if (Destroyed()) {
PR_LOG(gLog, PR_LOG_ALWAYS,
@@ -1542,9 +1554,6 @@ TextInputHandler::DispatchKeyEventForFlagsChanged(NSEvent* aNativeEvent,
uint32_t message = aDispatchKeyDown ? NS_KEY_DOWN : NS_KEY_UP;
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
#endif // ifndef NP_NO_CARBON
NPCocoaEvent cocoaEvent;
// Fire a key event.
@@ -1553,13 +1562,6 @@ TextInputHandler::DispatchKeyEventForFlagsChanged(NSEvent* aNativeEvent,
// create event for use by plugins
if ([mView isPluginView]) {
#ifndef NP_NO_CARBON
if ([mView pluginEventModel] == NPEventModelCarbon) {
ConvertCocoaKeyEventToCarbonEvent(aNativeEvent, carbonEvent,
aDispatchKeyDown);
keyEvent.pluginEvent = &carbonEvent;
}
#endif // ifndef NP_NO_CARBON
if ([mView pluginEventModel] == NPEventModelCocoa) {
ConvertCocoaKeyEventToNPCocoaEvent(aNativeEvent, cocoaEvent);
keyEvent.pluginEvent = &cocoaEvent;
@@ -1623,26 +1625,9 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
// -insertText: they've already been taken into account in creating
// the input string.
// create event for use by plugins
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
#endif // #ifndef NP_NO_CARBON
if (currentKeyEvent) {
NSEvent* keyEvent = currentKeyEvent->mKeyEvent;
InitKeyEvent(keyEvent, keypressEvent, &str);
// XXX The ASCII characters inputting mode of egbridge (Japanese IME)
// might send the keyDown event with wrong keyboard layout if other
// keyboard layouts are already loaded. In that case, the native event
// doesn't match to this gecko event...
#ifndef NP_NO_CARBON
if ([mView pluginEventModel] == NPEventModelCarbon) {
ConvertCocoaKeyEventToCarbonEvent(keyEvent, carbonEvent, true);
keypressEvent.pluginEvent = &carbonEvent;
}
#endif // #ifndef NP_NO_CARBON
if (currentKeyEvent->mKeyDownHandled) {
keypressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
}
@@ -3054,20 +3039,20 @@ PluginTextInputHandler::PluginTextInputHandler(nsChildView* aWidget,
NSView<mozView> *aNativeView) :
TextInputHandlerBase(aWidget, aNativeView),
mIgnoreNextKeyUpEvent(false),
#ifndef NP_NO_CARBON
#ifndef __LP64__
mPluginTSMDoc(0), mPluginTSMInComposition(false),
#endif // #ifndef NP_NO_CARBON
#endif // #ifndef __LP64__
mPluginComplexTextInputRequested(false)
{
}
PluginTextInputHandler::~PluginTextInputHandler()
{
#ifndef NP_NO_CARBON
#ifndef __LP64__
if (mPluginTSMDoc) {
::DeleteTSMDocument(mPluginTSMDoc);
}
#endif // #ifndef NP_NO_CARBON
#endif // #ifndef __LP64__
}
/* static */ void
@@ -3102,100 +3087,7 @@ PluginTextInputHandler::ConvertCocoaKeyEventToNPCocoaEvent(
}
}
#ifndef NP_NO_CARBON
/* static */ bool
PluginTextInputHandler::ConvertUnicodeToCharCode(PRUnichar aUniChar,
unsigned char* aOutChar)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
UnicodeToTextInfo converterInfo;
TextEncoding systemEncoding;
Str255 convertedString;
*aOutChar = '\0';
OSStatus err =
::UpgradeScriptInfoToTextEncoding(smSystemScript,
kTextLanguageDontCare,
kTextRegionDontCare,
NULL,
&systemEncoding);
NS_ENSURE_TRUE(err == noErr, false);
err = ::CreateUnicodeToTextInfoByEncoding(systemEncoding, &converterInfo);
NS_ENSURE_TRUE(err == noErr, false);
err = ::ConvertFromUnicodeToPString(converterInfo, sizeof(PRUnichar),
&aUniChar, convertedString);
NS_ENSURE_TRUE(err == noErr, false);
*aOutChar = convertedString[1];
::DisposeUnicodeToTextInfo(&converterInfo);
return true;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
}
/* static */ void
PluginTextInputHandler::ConvertCocoaKeyEventToCarbonEvent(
NSEvent* aCocoaKeyEvent,
EventRecord& aCarbonKeyEvent,
bool aMakeKeyDownEventIfNSFlagsChanged)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
UInt32 charCode = 0;
if ([aCocoaKeyEvent type] == NSFlagsChanged) {
aCarbonKeyEvent.what = aMakeKeyDownEventIfNSFlagsChanged ? keyDown : keyUp;
} else {
if ([[aCocoaKeyEvent characters] length] > 0) {
charCode = [[aCocoaKeyEvent characters] characterAtIndex:0];
}
if ([aCocoaKeyEvent type] == NSKeyDown) {
aCarbonKeyEvent.what = [aCocoaKeyEvent isARepeat] ? autoKey : keyDown;
} else {
aCarbonKeyEvent.what = keyUp;
}
}
if (charCode >= 0x0080) {
switch (charCode) {
case NSUpArrowFunctionKey:
charCode = kUpArrowCharCode;
break;
case NSDownArrowFunctionKey:
charCode = kDownArrowCharCode;
break;
case NSLeftArrowFunctionKey:
charCode = kLeftArrowCharCode;
break;
case NSRightArrowFunctionKey:
charCode = kRightArrowCharCode;
break;
default:
unsigned char convertedCharCode;
if (ConvertUnicodeToCharCode(charCode, &convertedCharCode)) {
charCode = convertedCharCode;
}
//NSLog(@"charcode is %d, converted to %c, char is %@",
// charCode, convertedCharCode, [aCocoaKeyEvent characters]);
break;
}
}
aCarbonKeyEvent.message =
(charCode & 0x00FF) | ([aCocoaKeyEvent keyCode] << 8);
aCarbonKeyEvent.when = ::TickCount();
::GetGlobalMouse(&aCarbonKeyEvent.where);
// XXX Is this correct? If ::GetCurrentKeyModifiers() returns "current"
// state and there is one or more pending modifier key events,
// the result is mismatch with the state at current key event.
aCarbonKeyEvent.modifiers = ::GetCurrentKeyModifiers();
NS_OBJC_END_TRY_ABORT_BLOCK;
}
#ifndef __LP64__
EventHandlerRef PluginTextInputHandler::sPluginKeyEventsHandler = NULL;
@@ -3431,7 +3323,7 @@ PluginTextInputHandler::ActivatePluginTSMDocument()
}
}
#endif // #ifndef NP_NO_CARBON
#endif // #ifndef __LP64__
void
PluginTextInputHandler::HandleKeyDownEventForPlugin(NSEvent* aNativeKeyEvent)
@@ -3442,7 +3334,7 @@ PluginTextInputHandler::HandleKeyDownEventForPlugin(NSEvent* aNativeKeyEvent)
NS_ASSERTION(mView, "mView must not be NULL");
#ifdef NP_NO_CARBON
#ifdef __LP64__
if ([mView pluginEventModel] != NPEventModelCocoa) {
return;
@@ -3491,7 +3383,7 @@ PluginTextInputHandler::HandleKeyDownEventForPlugin(NSEvent* aNativeKeyEvent)
}
}
#else // #ifdef NP_NO_CARBON
#else // #ifdef __LP64__
bool wasInComposition = false;
if ([mView pluginEventModel] == NPEventModelCocoa) {
@@ -3550,7 +3442,7 @@ PluginTextInputHandler::HandleKeyDownEventForPlugin(NSEvent* aNativeKeyEvent)
::TSMRemoveDocumentProperty(mPluginTSMDoc,
kFocusedChildViewTSMDocPropertyTag);
#endif // #ifdef NP_NO_CARBON else
#endif // #ifdef __LP64__ else
}
void
@@ -3582,54 +3474,17 @@ PluginTextInputHandler::HandleKeyUpEventForPlugin(NSEvent* aNativeKeyEvent)
DispatchEvent(keyupEvent);
return;
}
#ifndef NP_NO_CARBON
if (eventModel == NPEventModelCarbon) {
// I'm not sure the call to TSMProcessRawKeyEvent() is needed here (though
// WebKit makes one).
::TSMProcessRawKeyEvent([aNativeKeyEvent _eventRef]);
// Don't send a keyUp event if the corresponding keyDown event(s) is/are
// still being processed (idea borrowed from WebKit).
ChildView* keydownTarget = nil;
OSStatus status =
::TSMGetDocumentProperty(mPluginTSMDoc,
kFocusedChildViewTSMDocPropertyTag,
sizeof(ChildView *), nil, &keydownTarget);
NS_ENSURE_TRUE(status == noErr, );
if (keydownTarget == mView) {
return;
}
// PluginKeyEventsHandler() never sends keyUp events to
// HandleCarbonPluginKeyEvent(), so we need to send them to Gecko here.
// (This means that when commiting text from IME, several keyDown events
// may be sent to Gecko (in processPluginKeyEvent) for one keyUp event here.
// But this is how the WebKit does it, and games expect a keyUp event to
// be sent when it actually happens (they need to be able to detect how
// long a key has been held down) -- which wouldn't be possible if we sent
// them from processPluginKeyEvent.)
nsKeyEvent keyupEvent(true, NS_KEY_UP, mWidget);
InitKeyEvent(aNativeKeyEvent, keyupEvent);
EventRecord pluginEvent;
ConvertCocoaKeyEventToCarbonEvent(aNativeKeyEvent, pluginEvent, false);
keyupEvent.pluginEvent = &pluginEvent;
DispatchEvent(keyupEvent);
return;
}
#endif // #ifndef NP_NO_CARBON
}
bool
PluginTextInputHandler::IsInPluginComposition()
{
return
#ifdef NP_NO_CARBON
#ifdef __LP64__
[[ComplexTextInputPanel sharedComplexTextInputPanel] inComposition] != NO;
#else // #ifdef NP_NO_CARBON
#else // #ifdef __LP64__
mPluginTSMInComposition;
#endif // #ifdef NP_NO_CARBON else
#endif // #ifdef __LP64__ else
}
bool
@@ -3653,7 +3508,7 @@ PluginTextInputHandler::DispatchCocoaNPAPITextEvent(NSString* aString)
#pragma mark -
#ifndef NP_NO_CARBON
#ifndef __LP64__
/******************************************************************************
*
@@ -3748,7 +3603,7 @@ PluginTextInputHandler::DispatchCocoaNPAPITextEvent(NSString* aString)
@end
#endif // #ifndef NP_NO_CARBON
#endif // #ifndef __LP64__
#pragma mark -

View File

@@ -316,7 +316,7 @@ nsAppShell::Init()
rv = nsBaseAppShell::Init();
#ifndef NP_NO_CARBON
#ifndef __LP64__
TextInputHandler::InstallPluginKeyEventsHandler();
#endif
@@ -778,7 +778,7 @@ nsAppShell::Exit(void)
delete gCocoaAppModalWindowList;
gCocoaAppModalWindowList = NULL;
#ifndef NP_NO_CARBON
#ifndef __LP64__
TextInputHandler::RemovePluginKeyEventsHandler();
#endif

View File

@@ -92,29 +92,6 @@ class LayerManagerOGL;
}
}
#ifndef NP_NO_CARBON
enum {
// Currently focused ChildView (while this TSM document is active).
// Transient (only set while TSMProcessRawKeyEvent() is processing a key
// event), and the ChildView will be retained and released around the call
// to TSMProcessRawKeyEvent() -- so it can be weak.
kFocusedChildViewTSMDocPropertyTag = 'GKFV', // type ChildView* [WEAK]
};
// Undocumented HIToolbox function used by WebKit to allow Carbon-based IME
// to work in a Cocoa-based browser (like Safari or Cocoa-widgets Firefox).
// (Recent WebKit versions actually use a thin wrapper around this function
// called WKSendKeyEventToTSM().)
//
// Calling TSMProcessRawKeyEvent() from ChildView's keyDown: and keyUp:
// methods (when the ChildView is a plugin view) bypasses Cocoa's IME
// infrastructure and (instead) causes Carbon TSM events to be sent on each
// NSKeyDown event. We install a Carbon event handler
// (PluginKeyEventsHandler()) to catch these events and pass them to Gecko
// (which in turn passes them to the plugin).
extern "C" long TSMProcessRawKeyEvent(EventRef carbonEvent);
#endif // NP_NO_CARBON
@interface NSEvent (Undocumented)
// Return Cocoa event's corresponding Carbon event. Not initialized (on

View File

@@ -154,11 +154,6 @@ uint32_t nsChildView::sLastInputEventCount = 0;
- (BOOL)inactiveWindowAcceptsMouseEvent:(NSEvent*)aEvent;
#ifndef NP_NO_CARBON
- (void)sendCarbonWheelEvent:(SInt32)delta
forAxis:(EventMouseWheelAxis)carbonAxis;
#endif
@end
#pragma mark -
@@ -284,8 +279,7 @@ nsresult nsChildView::Create(nsIWidget *aParent,
nsToolkit::SwizzleMethods([NSEvent class], @selector(removeMonitor:),
@selector(nsChildView_NSEvent_removeMonitor:), true);
}
#endif
#ifndef NP_NO_CARBON
#else
TextInputHandler::SwizzleMethods();
#endif
gChildViewMethodsSwizzled = true;
@@ -562,14 +556,6 @@ void nsChildView::UpdatePluginPort()
// graphics context. See bug 500130.
mPluginCGContext.context = NULL;
mPluginCGContext.window = NULL;
#ifndef NP_NO_CARBON
NSWindow* cocoaWindow = [mView window];
WindowRef carbonWindow = cocoaWindow ? (WindowRef)[cocoaWindow windowRef] : NULL;
if (carbonWindow) {
mPluginCGContext.context = (CGContextRef)[[cocoaWindow graphicsContext] graphicsPort];
mPluginCGContext.window = carbonWindow;
}
#endif
}
static void HideChildPluginViews(NSView* aView)
@@ -961,20 +947,6 @@ NS_IMETHODIMP nsChildView::GetPluginClipRect(nsIntRect& outClipRect, nsIntPoint&
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
#ifndef NP_NO_CARBON
static void InitializeEventRecord(EventRecord* event, Point* aMousePosition)
{
memset(event, 0, sizeof(EventRecord));
if (aMousePosition) {
event->where = *aMousePosition;
} else {
::GetGlobalMouse(&event->where);
}
event->when = ::TickCount();
event->modifiers = ::GetCurrentKeyModifiers();
}
#endif
NS_IMETHODIMP nsChildView::StartDrawPlugin()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
@@ -1920,6 +1892,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
mGeckoChild = inChild;
mIsPluginView = NO;
#ifndef NP_NO_CARBON
// We don't support the Carbon event model but it's still the default
// model for i386 per NPAPI.
mPluginEventModel = NPEventModelCarbon;
#else
mPluginEventModel = NPEventModelCocoa;
@@ -3136,17 +3110,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
// Create event for use by plugins.
// This is going to our child view so we don't need to look up the destination
// event type.
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
if (mPluginEventModel == NPEventModelCarbon) {
carbonEvent.what = mouseDown;
carbonEvent.message = 0;
carbonEvent.when = ::TickCount();
::GetGlobalMouse(&carbonEvent.where);
carbonEvent.modifiers = ::GetCurrentKeyModifiers();
geckoEvent.pluginEvent = &carbonEvent;
}
#endif
NPCocoaEvent cocoaEvent;
if (mPluginEventModel == NPEventModelCocoa) {
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
@@ -3180,9 +3143,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
nsAutoRetainCocoaObject kungFuDeathGrip(self);
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
#endif // ifndef NP_NO_CARBON
NPCocoaEvent cocoaEvent;
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, nsMouseEvent::eReal);
@@ -3196,16 +3156,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
// This is going to our child view so we don't need to look up the destination
// event type.
if (mIsPluginView) {
#ifndef NP_NO_CARBON
if (mPluginEventModel == NPEventModelCarbon) {
carbonEvent.what = mouseUp;
carbonEvent.message = 0;
carbonEvent.when = ::TickCount();
::GetGlobalMouse(&carbonEvent.where);
carbonEvent.modifiers = ::GetCurrentKeyModifiers();
geckoEvent.pluginEvent = &carbonEvent;
}
#endif
if (mPluginEventModel == NPEventModelCocoa) {
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
@@ -3229,10 +3179,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
// happen if it came at the end of a dragging operation), also send our
// Gecko frame a mouse-exit event.
if (mGeckoChild && mIsPluginView) {
#ifndef NP_NO_CARBON
if (mPluginEventModel == NPEventModelCocoa)
#endif
{
if (mPluginEventModel == NPEventModelCocoa) {
if (ChildViewMouseTracker::ViewForEvent(theEvent) != self) {
nsMouseEvent geckoExitEvent(true, NS_MOUSE_EXIT, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoExitEvent];
@@ -3275,21 +3222,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
// Create event for use by plugins.
// This is going to our child view so we don't need to look up the destination
// event type.
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
#endif
NPCocoaEvent cocoaEvent;
if (mIsPluginView) {
#ifndef NP_NO_CARBON
if (mPluginEventModel == NPEventModelCarbon) {
carbonEvent.what = NPEventType_AdjustCursorEvent;
carbonEvent.message = 0;
carbonEvent.when = ::TickCount();
::GetGlobalMouse(&carbonEvent.where);
carbonEvent.modifiers = ::GetCurrentKeyModifiers();
event.pluginEvent = &carbonEvent;
}
#endif
if (mPluginEventModel == NPEventModelCocoa) {
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
cocoaEvent.type = ((msg == NS_MOUSE_ENTER) ? NPCocoaEventMouseEntered : NPCocoaEventMouseExited);
@@ -3323,21 +3257,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
// Create event for use by plugins.
// This is going to our child view so we don't need to look up the destination
// event type.
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
#endif
NPCocoaEvent cocoaEvent;
if (mIsPluginView) {
#ifndef NP_NO_CARBON
if (mPluginEventModel == NPEventModelCarbon) {
carbonEvent.what = NPEventType_AdjustCursorEvent;
carbonEvent.message = 0;
carbonEvent.when = ::TickCount();
::GetGlobalMouse(&carbonEvent.where);
carbonEvent.modifiers = ::GetCurrentKeyModifiers();
geckoEvent.pluginEvent = &carbonEvent;
}
#endif
if (mPluginEventModel == NPEventModelCocoa) {
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
@@ -3367,9 +3288,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
gLastDragView = self;
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
#endif // ifndef NP_NO_CARBON
NPCocoaEvent cocoaEvent;
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, nsMouseEvent::eReal);
@@ -3377,16 +3295,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
// create event for use by plugins
if (mIsPluginView) {
#ifndef NP_NO_CARBON
if (mPluginEventModel == NPEventModelCarbon) {
carbonEvent.what = NPEventType_AdjustCursorEvent;
carbonEvent.message = 0;
carbonEvent.when = ::TickCount();
::GetGlobalMouse(&carbonEvent.where);
carbonEvent.modifiers = btnState | ::GetCurrentKeyModifiers();
geckoEvent.pluginEvent = &carbonEvent;
}
#endif
if (mPluginEventModel == NPEventModelCocoa) {
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
@@ -3431,17 +3339,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
geckoEvent.clickCount = [theEvent clickCount];
// create event for use by plugins
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
if (mPluginEventModel == NPEventModelCarbon) {
carbonEvent.what = mouseDown;
carbonEvent.message = 0;
carbonEvent.when = ::TickCount();
::GetGlobalMouse(&carbonEvent.where);
carbonEvent.modifiers = controlKey; // fake a context menu click
geckoEvent.pluginEvent = &carbonEvent;
}
#endif
NPCocoaEvent cocoaEvent;
if (mPluginEventModel == NPEventModelCocoa) {
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
@@ -3475,9 +3372,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!mGeckoChild)
return;
#ifndef NP_NO_CARBON
EventRecord carbonEvent;
#endif // ifndef NP_NO_CARBON
NPCocoaEvent cocoaEvent;
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, nsMouseEvent::eReal);
@@ -3487,16 +3381,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
// create event for use by plugins
if (mIsPluginView) {
#ifndef NP_NO_CARBON
if (mPluginEventModel == NPEventModelCarbon) {
carbonEvent.what = mouseUp;
carbonEvent.message = 0;
carbonEvent.when = ::TickCount();
::GetGlobalMouse(&carbonEvent.where);
carbonEvent.modifiers = controlKey; // fake a context menu click
geckoEvent.pluginEvent = &carbonEvent;
}
#endif
if (mPluginEventModel == NPEventModelCocoa) {
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
@@ -3676,22 +3560,6 @@ static int32_t RoundUp(double aDouble)
return;
}
#ifndef NP_NO_CARBON
// dispatch scroll wheel carbon event for plugins
if (mPluginEventModel == NPEventModelCarbon) {
[self sendCarbonWheelEvent:RoundUp([theEvent deltaY])
forAxis:kEventMouseWheelAxisY];
if (!mGeckoChild) {
return;
}
[self sendCarbonWheelEvent:RoundUp([theEvent deltaX])
forAxis:kEventMouseWheelAxisX];
if (!mGeckoChild) {
return;
}
}
#endif
#ifdef __LP64__
// overflowDeltaX tells us when the user has tried to scroll past the edge
// of a page to the left or the right (in those cases it's non-zero).
@@ -3756,51 +3624,6 @@ static int32_t RoundUp(double aDouble)
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
#ifndef NP_NO_CARBON
- (void)sendCarbonWheelEvent:(SInt32)delta
forAxis:(EventMouseWheelAxis)carbonAxis
{
if (!delta) {
return;
}
EventRef theEvent;
OSStatus err = ::CreateEvent(NULL,
kEventClassMouse,
kEventMouseWheelMoved,
TicksToEventTime(TickCount()),
kEventAttributeUserEvent,
&theEvent);
if (err != noErr) {
return;
}
SetEventParameter(theEvent,
kEventParamMouseWheelAxis,
typeMouseWheelAxis,
sizeof(EventMouseWheelAxis),
&carbonAxis);
SetEventParameter(theEvent,
kEventParamMouseWheelDelta,
typeLongInteger,
sizeof(SInt32),
&delta);
Point mouseLoc;
::GetGlobalMouse(&mouseLoc);
SetEventParameter(theEvent,
kEventParamMouseLocation,
typeQDPoint,
sizeof(Point),
&mouseLoc);
::SendEventToEventTarget(theEvent,
GetWindowEventTarget((WindowRef)[[self window] windowRef]));
ReleaseEvent(theEvent);
}
#endif // #ifndef NP_NO_CARBON
- (void) convertCocoaMouseEvent:(NSEvent*)aMouseEvent toGeckoEvent:(nsInputEvent*)outGeckoEvent
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
@@ -3977,7 +3800,7 @@ static int32_t RoundUp(double aDouble)
#pragma mark -
#ifdef NP_NO_CARBON
#ifdef __LP64__
- (NSTextInputContext *)inputContext
{
if (mIsPluginView && mPluginEventModel == NPEventModelCocoa)