Optimize plugin views to be opaque, since they don't need to draw. Check in all the plugin code for cocoa widgets.

This commit is contained in:
hyatt%netscape.com 2002-04-27 00:19:49 +00:00
Родитель 43640a3f6b
Коммит f62b7cdc6a
2 изменённых файлов: 158 добавлений и 19 удалений

Просмотреть файл

@ -81,6 +81,9 @@ class nsChildView;
// tag for our mouse enter/exit tracking rect // tag for our mouse enter/exit tracking rect
NSTrackingRectTag mMouseEnterExitTag; NSTrackingRectTag mMouseEnterExitTag;
// Whether we're a plugin view.
BOOL mIsPluginView;
} }
// sets up our view, attaching it to its owning gecko view // sets up our view, attaching it to its owning gecko view
@ -98,6 +101,8 @@ class nsChildView;
-(NSMenu*)getContextMenu; -(NSMenu*)getContextMenu;
-(void)setIsPluginView:(BOOL)aIsPlugin;
@end @end
@ -250,7 +255,8 @@ protected:
// does not create something that inherits from NSQuickDrawView! // does not create something that inherits from NSQuickDrawView!
virtual GrafPtr GetQuickDrawPort() ; virtual GrafPtr GetQuickDrawPort() ;
protected: /* protected: */
public:
#if DEBUG #if DEBUG
const char* gInstanceClassName; const char* gInstanceClassName;
#endif #endif

Просмотреть файл

@ -61,6 +61,7 @@
#include "profilerutils.h" #include "profilerutils.h"
#endif #endif
#include <unistd.h>
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
nsIRollupListener * gRollupListener = nsnull; nsIRollupListener * gRollupListener = nsnull;
@ -323,6 +324,43 @@ NS_IMETHODIMP nsChildView::Destroy()
#pragma mark - #pragma mark -
static pascal OSStatus OnContentClick(EventHandlerCallRef handler, EventRef event, void* userData)
{
WindowRef window;
GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL,
sizeof(window), NULL, &window);
EventRecord macEvent;
ConvertEventRefToEventRecord(event, &macEvent);
GrafPtr port = GetWindowPort(window);
StPortSetter setter(port);
Point localWhere = macEvent.where;
GlobalToLocal(&localWhere);
nsChildView* childView = (nsChildView*) userData;
nsMouseEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_EVENT;
geckoEvent.message = NS_MOUSE_LEFT_BUTTON_DOWN;
geckoEvent.nativeMsg = &macEvent;
geckoEvent.widget = childView;
geckoEvent.time = PR_IntervalNow();
geckoEvent.flags = 0;
geckoEvent.clickCount = 1;
geckoEvent.refPoint.x = geckoEvent.point.x = localWhere.h;
geckoEvent.refPoint.y = geckoEvent.point.y = localWhere.v;
geckoEvent.isShift = ((macEvent.modifiers & (shiftKey|rightShiftKey)) != 0);
geckoEvent.isControl = ((macEvent.modifiers & controlKey) != 0);
geckoEvent.isAlt = ((macEvent.modifiers & optionKey) != 0);
geckoEvent.isMeta = ((macEvent.modifiers & cmdKey) != 0);
// send event into Gecko by going directly to the
// the widget.
childView->DispatchMouseEvent(geckoEvent);
return noErr;
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// //
@ -376,23 +414,47 @@ void* nsChildView::GetNativeData(PRUint32 aDataType)
case NS_NATIVE_COLORMAP: case NS_NATIVE_COLORMAP:
//¥TODO //¥TODO
break; break;
#endif
case NS_NATIVE_PLUGIN_PORT: case NS_NATIVE_PLUGIN_PORT:
// this needs to be a combination of the port and the offsets. // this needs to be a combination of the port and the offsets.
if (mPluginPort == nsnull) if (mPluginPort == nsnull)
mPluginPort = new nsPluginPort; mPluginPort = new nsPluginPort;
point.MoveTo(mBounds.x, mBounds.y); [mView setIsPluginView: YES];
LocalToWindowCoordinate(point);
NSWindow* window = [mView window];
if (window) {
WindowRef topLevelWindow = (WindowRef) [window _windowRef]; // PRIVATE APPLE SPI FOO.
if (topLevelWindow) {
mPluginPort->port = GetWindowPort(topLevelWindow);
// for compatibility with 4.X, this origin is what you'd pass NSPoint viewOrigin = [mView convertPoint:NSZeroPoint toView:nil];
// to SetOrigin. NSRect frame = [window frame];
mPluginPort->port = ::GetWindowPort(mWindowPtr); viewOrigin.y = frame.size.height - viewOrigin.y;
mPluginPort->portx = -point.x;
mPluginPort->porty = -point.y; // need to convert view's origin to window coordinates.
// then, encode as "SetOrigin" ready values.
mPluginPort->portx = -viewOrigin.x;
mPluginPort->porty = -viewOrigin.y;
// set up the clipping region for plugins.
RgnHandle clipRgn = ::NewRgn();
if (clipRgn != NULL) {
NSRect visibleBounds = [mView visibleRect];
NSPoint clipOrigin = [mView convertPoint:visibleBounds.origin toView:nil];
clipOrigin.y = frame.size.height - clipOrigin.y;
SetRectRgn(clipRgn, clipOrigin.x, clipOrigin.y,
clipOrigin.x + visibleBounds.size.width,
clipOrigin.y + visibleBounds.size.height);
SetPortClipRegion(mPluginPort->port, clipRgn);
DisposeRgn(clipRgn);
}
}
}
retVal = (void*)mPluginPort; retVal = (void*)mPluginPort;
#endif break;
} }
return retVal; return retVal;
@ -978,7 +1040,7 @@ NS_IMETHODIMP nsChildView::Invalidate(PRBool aIsSynchronous)
if (aIsSynchronous) if (aIsSynchronous)
[mView display]; [mView display];
else else
[mView setNeedsDisplay]; [mView setNeedsDisplay:true];
return NS_OK; return NS_OK;
} }
@ -1175,13 +1237,13 @@ nsChildView::UpdateWidget(nsRect& aRect, nsIRenderingContext* aContext)
if (! mVisible) if (! mVisible)
return; return;
GrafPtr oldPort; StPortSetter port(GetQuickDrawPort());
::GetPort(&oldPort); if (mPluginPort) ::SetOrigin(mPluginPort->portx, mPluginPort->porty);
::SetPort(GetQuickDrawPort());
// initialize the paint event // initialize the paint event
nsPaintEvent paintEvent; nsPaintEvent paintEvent;
paintEvent.eventStructType = NS_PAINT_EVENT; // nsEvent paintEvent.eventStructType = NS_PAINT_EVENT; // nsEvent
paintEvent.nativeMsg = nsnull;
paintEvent.message = NS_PAINT; paintEvent.message = NS_PAINT;
paintEvent.widget = this; // nsGUIEvent paintEvent.widget = this; // nsGUIEvent
paintEvent.nativeMsg = NULL; paintEvent.nativeMsg = NULL;
@ -1204,7 +1266,19 @@ nsChildView::UpdateWidget(nsRect& aRect, nsIRenderingContext* aContext)
} }
EndDraw(); EndDraw();
::SetPort(oldPort); #if 0
// draw where a plugin will be.
if (mPluginPort) {
::SetOrigin(mPluginPort->portx, mPluginPort->porty);
Rect bounds = { 0, 0, mBounds.height, mBounds.width };
::FrameRect(&bounds);
::MoveTo(bounds.left, bounds.top);
::LineTo(bounds.right, bounds.bottom);
::MoveTo(bounds.right, bounds.top);
::LineTo(bounds.left, bounds.bottom);
::SetOrigin(0, 0);
}
#endif
} }
@ -1298,7 +1372,7 @@ NS_IMETHODIMP nsChildView::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStat
NS_IF_ADDREF(aWidget); NS_IF_ADDREF(aWidget);
if (nsnull != mMenuListener){ if (nsnull != mMenuListener){
if(NS_MENU_EVENT == event->eventStructType) if (NS_MENU_EVENT == event->eventStructType)
aStatus = mMenuListener->MenuSelected( static_cast<nsMenuEvent&>(*event) ); aStatus = mMenuListener->MenuSelected( static_cast<nsMenuEvent&>(*event) );
} }
if (mEventCallback) if (mEventCallback)
@ -1397,6 +1471,7 @@ PRBool nsChildView::ReportDestroyEvent()
// nsEvent // nsEvent
nsGUIEvent moveEvent; nsGUIEvent moveEvent;
moveEvent.eventStructType = NS_GUI_EVENT; moveEvent.eventStructType = NS_GUI_EVENT;
moveEvent.nativeMsg = nsnull;
moveEvent.message = NS_DESTROY; moveEvent.message = NS_DESTROY;
moveEvent.point.x = 0; moveEvent.point.x = 0;
moveEvent.point.y = 0; moveEvent.point.y = 0;
@ -1419,6 +1494,7 @@ PRBool nsChildView::ReportMoveEvent()
// nsEvent // nsEvent
nsGUIEvent moveEvent; nsGUIEvent moveEvent;
moveEvent.eventStructType = NS_GUI_EVENT; moveEvent.eventStructType = NS_GUI_EVENT;
moveEvent.nativeMsg = nsnull;
moveEvent.message = NS_MOVE; moveEvent.message = NS_MOVE;
moveEvent.point.x = mBounds.x; moveEvent.point.x = mBounds.x;
moveEvent.point.y = mBounds.y; moveEvent.point.y = mBounds.y;
@ -1441,6 +1517,7 @@ PRBool nsChildView::ReportSizeEvent()
// nsEvent // nsEvent
nsSizeEvent sizeEvent; nsSizeEvent sizeEvent;
sizeEvent.eventStructType = NS_SIZE_EVENT; sizeEvent.eventStructType = NS_SIZE_EVENT;
sizeEvent.nativeMsg = nsnull;
sizeEvent.message = NS_SIZE; sizeEvent.message = NS_SIZE;
sizeEvent.point.x = 0; sizeEvent.point.x = 0;
sizeEvent.point.y = 0; sizeEvent.point.y = 0;
@ -1671,6 +1748,9 @@ NS_IMETHODIMP nsChildView::ResetInputState()
GrafPtr GrafPtr
nsChildView::GetQuickDrawPort() nsChildView::GetQuickDrawPort()
{ {
if (mPluginPort)
return mPluginPort->port;
else
return [mView qdPort]; return [mView qdPort];
} }
@ -1771,20 +1851,22 @@ nsChildView::Idle()
-(NSMenu*)menuForEvent:(NSEvent*)theEvent -(NSMenu*)menuForEvent:(NSEvent*)theEvent
{ {
nsMouseEvent geckoEvent;
int button = [theEvent buttonNumber]; int button = [theEvent buttonNumber];
if (button == 1) { if (button == 1) {
// The right mouse went down. Fire off a right mouse down and // The right mouse went down. Fire off a right mouse down and
// then send the context menu event. // then send the context menu event.
nsMouseEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_EVENT; geckoEvent.eventStructType = NS_MOUSE_EVENT;
geckoEvent.nativeMsg = nsnull;
[self convert: theEvent message: NS_MOUSE_RIGHT_BUTTON_DOWN toGeckoEvent:&geckoEvent]; [self convert: theEvent message: NS_MOUSE_RIGHT_BUTTON_DOWN toGeckoEvent:&geckoEvent];
geckoEvent.clickCount = 1; geckoEvent.clickCount = 1;
mGeckoChild->DispatchMouseEvent(geckoEvent); mGeckoChild->DispatchMouseEvent(geckoEvent);
} }
// Fire the context menu event into Gecko. // Fire the context menu event into Gecko.
nsMouseEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_EVENT; geckoEvent.eventStructType = NS_MOUSE_EVENT;
geckoEvent.nativeMsg = nsnull;
[self convert:theEvent message:NS_CONTEXTMENU toGeckoEvent:&geckoEvent]; [self convert:theEvent message:NS_CONTEXTMENU toGeckoEvent:&geckoEvent];
geckoEvent.clickCount = 0; geckoEvent.clickCount = 0;
@ -1816,6 +1898,7 @@ nsChildView::Idle()
mGeckoChild = inChild; mGeckoChild = inChild;
mEventSink = inSink; mEventSink = inSink;
// mMouseEnterExitTag = nsnull; // mMouseEnterExitTag = nsnull;
mIsPluginView = NO;
return self; return self;
} }
@ -1882,7 +1965,12 @@ nsChildView::Idle()
// But we can't. :( // But we can't. :(
- (BOOL)isOpaque - (BOOL)isOpaque
{ {
return NO; return mIsPluginView;
}
-(void)setIsPluginView:(BOOL)aIsPlugin
{
mIsPluginView = aIsPlugin;
} }
// //
@ -1918,14 +2006,26 @@ nsChildView::Idle()
mGeckoChild->UpdateWidget(r, rendContext); mGeckoChild->UpdateWidget(r, rendContext);
} }
- (void)mouseDown:(NSEvent *)theEvent - (void)mouseDown:(NSEvent *)theEvent
{ {
nsMouseEvent geckoEvent; nsMouseEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_EVENT; geckoEvent.eventStructType = NS_MOUSE_EVENT;
geckoEvent.nativeMsg = nsnull;
[self convert:theEvent message:NS_MOUSE_LEFT_BUTTON_DOWN toGeckoEvent:&geckoEvent]; [self convert:theEvent message:NS_MOUSE_LEFT_BUTTON_DOWN toGeckoEvent:&geckoEvent];
geckoEvent.clickCount = [theEvent clickCount]; geckoEvent.clickCount = [theEvent clickCount];
NSPoint mouseLoc = [theEvent locationInWindow];
NSPoint screenLoc = [[self window] convertBaseToScreen: mouseLoc];
EventRecord macEvent;
macEvent.what = mouseDown;
macEvent.message = 0;
macEvent.when = ::TickCount();
// macEvent.where.h = screenLoc.x, macEvent.where.v = screenLoc.y; XXX fix this, they are flipped!
GetGlobalMouse(&macEvent.where);
macEvent.modifiers = GetCurrentKeyModifiers();
geckoEvent.nativeMsg = &macEvent;
// send event into Gecko by going directly to the // send event into Gecko by going directly to the
// the widget. // the widget.
mGeckoChild->DispatchMouseEvent(geckoEvent); mGeckoChild->DispatchMouseEvent(geckoEvent);
@ -1937,8 +2037,21 @@ nsChildView::Idle()
{ {
nsMouseEvent geckoEvent; nsMouseEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_EVENT; geckoEvent.eventStructType = NS_MOUSE_EVENT;
geckoEvent.nativeMsg = nsnull;
[self convert:theEvent message:NS_MOUSE_LEFT_BUTTON_UP toGeckoEvent:&geckoEvent]; [self convert:theEvent message:NS_MOUSE_LEFT_BUTTON_UP toGeckoEvent:&geckoEvent];
NSPoint mouseLoc = [theEvent locationInWindow];
NSPoint screenLoc = [[self window] convertBaseToScreen: mouseLoc];
EventRecord macEvent;
macEvent.what = mouseUp;
macEvent.message = 0;
macEvent.when = ::TickCount();
// macEvent.where.h = screenLoc.x, macEvent.where.v = screenLoc.y; XXX fix this, they are flipped!
GetGlobalMouse(&macEvent.where);
macEvent.modifiers = GetCurrentKeyModifiers();
geckoEvent.nativeMsg = &macEvent;
// send event into Gecko by going directly to the // send event into Gecko by going directly to the
// the widget. // the widget.
mGeckoChild->DispatchMouseEvent(geckoEvent); mGeckoChild->DispatchMouseEvent(geckoEvent);
@ -1956,8 +2069,21 @@ nsChildView::Idle()
nsMouseEvent geckoEvent; nsMouseEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_EVENT; geckoEvent.eventStructType = NS_MOUSE_EVENT;
geckoEvent.nativeMsg = nsnull;
[self convert:theEvent message:NS_MOUSE_MOVE toGeckoEvent:&geckoEvent]; [self convert:theEvent message:NS_MOUSE_MOVE toGeckoEvent:&geckoEvent];
NSPoint mouseLoc = [theEvent locationInWindow];
NSPoint screenLoc = [[self window] convertBaseToScreen: mouseLoc];
EventRecord macEvent;
macEvent.what = nullEvent;
macEvent.message = 0;
macEvent.when = ::TickCount();
// macEvent.where.h = screenLoc.x, macEvent.where.v = screenLoc.y; XXX fix this, they are flipped!
GetGlobalMouse(&macEvent.where);
macEvent.modifiers = GetCurrentKeyModifiers();
geckoEvent.nativeMsg = &macEvent;
// send event into Gecko by going directly to the // send event into Gecko by going directly to the
// the widget. // the widget.
mGeckoChild->DispatchMouseEvent(geckoEvent); mGeckoChild->DispatchMouseEvent(geckoEvent);
@ -1967,6 +2093,7 @@ nsChildView::Idle()
{ {
nsMouseEvent geckoEvent; nsMouseEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_EVENT; geckoEvent.eventStructType = NS_MOUSE_EVENT;
geckoEvent.nativeMsg = nsnull;
[self convert:theEvent message:NS_MOUSE_MOVE toGeckoEvent:&geckoEvent]; [self convert:theEvent message:NS_MOUSE_MOVE toGeckoEvent:&geckoEvent];
// send event into Gecko by going directly to the // send event into Gecko by going directly to the
@ -1988,6 +2115,7 @@ nsChildView::Idle()
{ {
nsMouseEvent geckoEvent; nsMouseEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_EVENT; geckoEvent.eventStructType = NS_MOUSE_EVENT;
geckoEvent.nativeMsg = nsnull;
[self convert:theEvent message:NS_MOUSE_MIDDLE_BUTTON_DOWN toGeckoEvent:&geckoEvent]; [self convert:theEvent message:NS_MOUSE_MIDDLE_BUTTON_DOWN toGeckoEvent:&geckoEvent];
geckoEvent.clickCount = [theEvent clickCount]; geckoEvent.clickCount = [theEvent clickCount];
@ -2002,6 +2130,7 @@ nsChildView::Idle()
{ {
nsMouseEvent geckoEvent; nsMouseEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_EVENT; geckoEvent.eventStructType = NS_MOUSE_EVENT;
geckoEvent.nativeMsg = nsnull;
[self convert:theEvent message:NS_MOUSE_MIDDLE_BUTTON_UP toGeckoEvent:&geckoEvent]; [self convert:theEvent message:NS_MOUSE_MIDDLE_BUTTON_UP toGeckoEvent:&geckoEvent];
// send event into Gecko by going directly to the // send event into Gecko by going directly to the
@ -2020,6 +2149,7 @@ const PRInt32 kNumLines = 4;
// the OS). --dwh // the OS). --dwh
nsMouseScrollEvent geckoEvent; nsMouseScrollEvent geckoEvent;
geckoEvent.eventStructType = NS_MOUSE_SCROLL_EVENT; geckoEvent.eventStructType = NS_MOUSE_SCROLL_EVENT;
geckoEvent.nativeMsg = nsnull;
[self convert:theEvent message:NS_MOUSE_SCROLL toGeckoEvent:&geckoEvent]; [self convert:theEvent message:NS_MOUSE_SCROLL toGeckoEvent:&geckoEvent];
geckoEvent.delta = PRInt32([theEvent deltaY])*(-kNumLines); geckoEvent.delta = PRInt32([theEvent deltaY])*(-kNumLines);
geckoEvent.scrollFlags |= nsMouseScrollEvent::kIsVertical; geckoEvent.scrollFlags |= nsMouseScrollEvent::kIsVertical;
@ -2045,6 +2175,7 @@ const PRInt32 kNumLines = 4;
{ {
outGeckoEvent->message = inMsg; outGeckoEvent->message = inMsg;
outGeckoEvent->widget = [self widget]; outGeckoEvent->widget = [self widget];
outGeckoEvent->nativeMsg = nsnull;
outGeckoEvent->time = PR_IntervalNow(); outGeckoEvent->time = PR_IntervalNow();
if (outGeckoEvent->eventStructType != NS_KEY_EVENT) { if (outGeckoEvent->eventStructType != NS_KEY_EVENT) {
@ -2143,6 +2274,7 @@ const PRInt32 kNumLines = 4;
{ {
nsFocusEvent event; nsFocusEvent event;
event.eventStructType = NS_FOCUS_EVENT; event.eventStructType = NS_FOCUS_EVENT;
event.nativeMsg = nsnull;
event.message = NS_GOTFOCUS; event.message = NS_GOTFOCUS;
event.widget = mGeckoChild; event.widget = mGeckoChild;
@ -2159,6 +2291,7 @@ const PRInt32 kNumLines = 4;
{ {
nsFocusEvent event; nsFocusEvent event;
event.eventStructType = NS_FOCUS_EVENT; event.eventStructType = NS_FOCUS_EVENT;
event.nativeMsg = nsnull;
event.message = NS_LOSTFOCUS; event.message = NS_LOSTFOCUS;
event.widget = mGeckoChild; event.widget = mGeckoChild;