Bug 298677, Mac Carbon scrollbars draw in the wrong location and jump out from under the mouse since CFRunLoopSource (bug 282940). Be more careful about restoring the QD origin. Obsoletes and backs out an earlier partial fix, cleaning up bug 300058, drawing artifacts in scrollbars. r=pinkerton sr=smfr a=bsmedberg

This commit is contained in:
mark%moxienet.com 2005-07-14 22:48:34 +00:00
Родитель ae10010020
Коммит d8ce3ba315
5 изменённых файлов: 50 добавлений и 90 удалений

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Mark Mentovai <mark@moxienet.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -70,6 +71,10 @@
nsRenderingContextMac::nsRenderingContextMac()
: mP2T(1.0f)
, mContext(nsnull)
#ifndef MOZ_WIDGET_COCOA
, mSavePort(nsnull)
, mSaveDevice(nsnull)
#endif /* ! MOZ_WIDGET_COCOA */
, mCurrentSurface(nsnull)
, mPort(nsnull)
, mGS(nsnull)
@ -88,6 +93,13 @@ nsRenderingContextMac::~nsRenderingContextMac()
// restore stuff
NS_IF_RELEASE(mContext);
#ifndef MOZ_WIDGET_COCOA
if (mSavePort) {
::SetGWorld(mSavePort, mSaveDevice);
::SetOrigin(mSavePortRect.left, mSavePortRect.top);
}
#endif /* ! MOZ_WIDGET_COCOA */
// release surfaces
NS_IF_RELEASE(mFrontSurface);
NS_IF_RELEASE(mCurrentSurface);
@ -190,6 +202,15 @@ void nsRenderingContextMac::SelectDrawingSurface(nsDrawingSurfaceMac* aSurface,
return;
NS_ASSERTION(ValidateDrawingState(), "Bad drawing state");
#ifndef MOZ_WIDGET_COCOA
if (!mSavePort) {
::GetGWorld(&mSavePort, &mSaveDevice);
if (mSavePort) {
::GetPortBounds(mSavePort, &mSavePortRect);
}
}
#endif /* ! MOZ_WIDGET_COCOA */
// if surface is changing, be extra conservative about graphic state changes.
if (mCurrentSurface != aSurface)

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

@ -196,6 +196,12 @@ protected:
float mP2T; // Pixel to Twip conversion factor
nsIDeviceContext * mContext;
#ifndef MOZ_WIDGET_COCOA
CGrafPtr mSavePort;
GDHandle mSaveDevice;
Rect mSavePortRect;
#endif /* ! MOZ_WIDGET_COCOA */
nsDrawingSurfaceMac* mFrontSurface;
nsDrawingSurfaceMac* mCurrentSurface; // pointer to the current surface

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

@ -82,56 +82,6 @@ static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CI
nsIUnicodeEncoder * nsMacControl::mUnicodeEncoder = nsnull;
nsIUnicodeDecoder * nsMacControl::mUnicodeDecoder = nsnull;
static const EventTypeSpec kControlEventList[] =
{
{ kEventClassControl, kEventControlDraw }
};
static pascal OSStatus MacControlDrawHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
{
nsMacControl* macControl = NS_REINTERPRET_CAST(nsMacControl*, inUserData);
ControlRef theControl;
::GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &theControl);
CGrafPtr controlPort; // port we're drawing into (usually the control's port)
if (::GetEventParameter(inEvent, kEventParamGrafPort, typeGrafPtr, NULL, sizeof(CGrafPtr), NULL, &controlPort) != noErr)
controlPort = ::GetWindowPort(::GetControlOwner(theControl));
OSStatus err = eventNotHandledErr;
// see if we're already inside a StartDraw/EndDraw (e.g. OnPaint())
if (macControl->IsDrawing())
{
// we need to make sure that the port origin is set correctly for the control's
// widget, because other handlers before us may have messed with it.
nsRect controlBounds;
macControl->GetBounds(controlBounds);
nsPoint origin(controlBounds.x, controlBounds.y);
macControl->LocalToWindowCoordinate(origin);
Point newOrigin;
newOrigin.h = -origin.x;
newOrigin.v = -origin.y;
StOriginSetter setter(controlPort, &newOrigin);
err = ::CallNextEventHandler(inHandlerCallRef, inEvent);
}
else
{
// make sure we leave the origin set for other controls
StOriginSetter originSetter(controlPort);
macControl->StartDraw();
err = ::CallNextEventHandler(inHandlerCallRef, inEvent);
macControl->EndDraw();
}
return err;
}
#pragma mark -
//-------------------------------------------------------------------------
@ -147,7 +97,6 @@ nsMacControl::nsMacControl()
mMouseInButton = PR_FALSE;
mControl = nsnull;
mControlEventHandler = nsnull;
mControlType = pushButProc;
mLastBounds.SetRect(0,0,0,0);
@ -194,6 +143,25 @@ nsMacControl::~nsMacControl()
}
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsMacControl::Destroy()
{
if (mOnDestroyCalled)
return NS_OK;
// Hide the control to avoid drawing. Even if we're very careful
// and avoid drawing the control ourselves after Destroy() is
// called, the system still might draw it, and it might wind up
// in the wrong location.
Show(PR_FALSE);
return Inherited::Destroy();
}
#pragma mark -
//-------------------------------------------------------------------------
//
@ -428,9 +396,6 @@ nsresult nsMacControl::CreateOrReplaceMacControl(short inControlType)
mControl = ::NewControl(mWindowPtr, &macRect, "\p", mVisible, mValue, mMin, mMax, inControlType, nil);
EndDraw();
if (mControl)
InstallEventHandlerOnControl();
// need to reset the font now
// XXX to do: transfer the text in the old control over too
if (mControl && mFontMetrics)
@ -448,7 +413,6 @@ nsresult nsMacControl::CreateOrReplaceMacControl(short inControlType)
//-------------------------------------------------------------------------
void nsMacControl::ClearControl()
{
RemoveEventHandlerFromControl();
if (mControl)
{
::DisposeControl(mControl);
@ -456,34 +420,6 @@ void nsMacControl::ClearControl()
}
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
DEFINE_ONE_SHOT_HANDLER_GETTER(MacControlDrawHandler)
OSStatus nsMacControl::InstallEventHandlerOnControl()
{
return ::InstallControlEventHandler(mControl,
GetMacControlDrawHandlerUPP(),
GetEventTypeCount(kControlEventList), kControlEventList,
(void*)this, &mControlEventHandler);
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
void nsMacControl::RemoveEventHandlerFromControl()
{
if (mControlEventHandler)
{
::RemoveEventHandler(mControlEventHandler);
mControlEventHandler = nsnull;
}
}
//-------------------------------------------------------------------------
//
//

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

@ -59,6 +59,7 @@ public:
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD Destroy();
virtual void SetControlType(short type) {mControlType = type;}
short GetControlType() {return mControlType;}
@ -81,9 +82,6 @@ protected:
nsresult CreateOrReplaceMacControl(short inControlType);
OSStatus InstallEventHandlerOnControl();
void RemoveEventHandlerFromControl();
void ClearControl();
virtual void GetRectForMacControl(nsRect &outRect);
@ -103,7 +101,6 @@ protected:
PRInt32 mMin;
PRInt32 mMax;
ControlHandle mControl;
EventHandlerRef mControlEventHandler;
short mControlType;
nsString mLastLabel;

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

@ -1249,7 +1249,7 @@ NS_IMETHODIMP nsWindow::Update()
// draw the widget
StPortSetter portSetter(mWindowPtr);
::SetOrigin(0, 0);
StOriginSetter originSetter(mWindowPtr);
// BeginUpate replaces the visRgn with the intersection of the
// visRgn and the updateRgn.
@ -2205,7 +2205,7 @@ NS_IMETHODIMP nsWindow::WidgetToScreen(const nsRect& aLocalRect, nsRect& aGlobal
// When there is no parent, we're at the top level window. Use
// the origin (shifted into global coordinates) to find the offset.
StPortSetter portSetter(mWindowPtr);
::SetOrigin(0,0);
StOriginSetter originSetter(mWindowPtr);
// convert origin into global coords and shift output rect by that ammount
Point origin = {0, 0};
@ -2246,7 +2246,7 @@ NS_IMETHODIMP nsWindow::ScreenToWidget(const nsRect& aGlobalRect, nsRect& aLocal
// When there is no parent, we're at the top level window. Use
// the origin (shifted into local coordinates) to find the offset.
StPortSetter portSetter(mWindowPtr);
::SetOrigin(0,0);
StOriginSetter originSetter(mWindowPtr);
// convert origin into local coords and shift output rect by that ammount
Point origin = {0, 0};