From 068caa63c98eb00d6097addd6200bbd8a458e25d Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Fri, 9 Oct 1998 22:57:36 +0000 Subject: [PATCH] Lame support for nsIDOMRenderingContext API --- content/events/src/nsDOMEvent.cpp | 20 +++++ content/events/src/nsDOMEvent.h | 4 + gfx/makefile.win | 2 +- gfx/src/makefile.win | 9 +- gfx/src/windows/makefile.win | 3 + gfx/src/windows/nsGfxFactoryWin.cpp | 2 +- gfx/src/windows/nsRenderingContextWin.cpp | 101 +++++++++++++++++++++- gfx/src/windows/nsRenderingContextWin.h | 15 +++- layout/events/src/nsDOMEvent.cpp | 20 +++++ layout/events/src/nsDOMEvent.h | 4 + 10 files changed, 174 insertions(+), 6 deletions(-) diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 00fbddc5e1c0..a8ff7aee45b9 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -19,6 +19,8 @@ #include "nsDOMEvent.h" #include "nsIDOMNode.h" #include "nsIEventStateManager.h" +#include "nsIRenderingContext.h" +#include "nsIDOMRenderingContext.h" static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID); @@ -343,6 +345,24 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return nsnull; } +static NS_DEFINE_IID(kIDOMRenderingContextIID, NS_IDOMRENDERINGCONTEXT_IID); + +NS_IMETHODIMP +nsDOMEvent::GetRc(nsIDOMRenderingContext** aRc) +{ + *aRc = nsnull; + if (NS_PAINT_EVENT == mEvent->eventStructType) { + nsPaintEvent* pe = (nsPaintEvent*) mEvent; + if (nsnull != pe->renderingContext) { + nsIDOMRenderingContext* domrc; + if (NS_OK == pe->renderingContext->QueryInterface(kIDOMRenderingContextIID, (void**) &domrc)) { + *aRc = domrc; + } + } + } + return NS_OK; +} + nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext& aPresContext, nsEvent *aEvent) { nsDOMEvent* it = new nsDOMEvent(&aPresContext, aEvent); diff --git a/content/events/src/nsDOMEvent.h b/content/events/src/nsDOMEvent.h index 0eec5295d389..0373ac977e95 100644 --- a/content/events/src/nsDOMEvent.h +++ b/content/events/src/nsDOMEvent.h @@ -29,6 +29,8 @@ #include "nsGUIEvent.h" class nsIContent; +class nsIDOMRenderingContext; + class nsDOMEvent : public nsIDOMEvent, public nsIDOMNSEvent, public nsIPrivateDOMEvent { #define DOM_EVENT_INIT 0x0001 @@ -114,6 +116,8 @@ public: NS_IMETHOD GetLayerY(PRInt32* aLayerY); NS_IMETHOD SetLayerY(PRInt32 aLayerY); + NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc); + // nsIPrivateDOMEvent interface NS_IMETHOD DuplicatePrivateData(); diff --git a/gfx/makefile.win b/gfx/makefile.win index b7909d0e8ea5..803da341ba59 100644 --- a/gfx/makefile.win +++ b/gfx/makefile.win @@ -17,6 +17,6 @@ DEPTH=.. -DIRS= src tests +DIRS= public src tests include <$(DEPTH)\config\rules.mak> diff --git a/gfx/src/makefile.win b/gfx/src/makefile.win index 99536992e9a1..16edaddc57f5 100644 --- a/gfx/src/makefile.win +++ b/gfx/src/makefile.win @@ -45,11 +45,16 @@ CPP_OBJS=.\$(OBJDIR)\nsColor.obj .\$(OBJDIR)\nsColorNames.obj \ .\$(OBJDIR)\nsImageRequest.obj .\$(OBJDIR)\nsImageSystemServices.obj \ .\$(OBJDIR)\nsImageURL.obj .\$(OBJDIR)\nsRect.obj \ .\$(OBJDIR)\nsTransform2D.obj \ - .\$(OBJDIR)\nsDeviceContext.obj .\$(OBJDIR)\nsImageNetContextSync.obj + .\$(OBJDIR)\nsDeviceContext.obj \ + .\$(OBJDIR)\nsImageNetContextSync.obj \ + .\$(OBJDIR)\nsJSRenderingContext.obj LINCS=-I$(PUBLIC)\util -I$(PUBLIC)\img \ -I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ - -I$(PUBLIC)\netlib + -I$(PUBLIC)\netlib \ + -I$(PUBLIC)\dom \ + -I$(PUBLIC)\js \ + $(NULL) LCFLAGS = \ $(LCFLAGS) \ diff --git a/gfx/src/windows/makefile.win b/gfx/src/windows/makefile.win index 3de172d33a53..084d90a7b3af 100644 --- a/gfx/src/windows/makefile.win +++ b/gfx/src/windows/makefile.win @@ -47,6 +47,8 @@ OBJS = \ LINCS= \ -I$(PUBLIC)\raptor \ -I$(PUBLIC)\xpcom \ + -I$(PUBLIC)\dom \ + -I$(PUBLIC)\js \ !if defined(NGLAYOUT_DDRAW) !if "$(MOZ_VCVER)" == "50" -I$(NGLAYOUT_DDRAW)\include \ @@ -65,6 +67,7 @@ LLIBS= \ $(DIST)\lib\xpcom32.lib \ $(DIST)\lib\raptorbase.lib \ $(DIST)\lib\img32$(VERSION_NUMBER).lib \ + $(DIST)\lib\js32$(VERSION_NUMBER).lib \ $(DIST)\lib\util.lib \ $(DIST)\lib\libplc21.lib \ $(DIST)\lib\netlib.lib \ diff --git a/gfx/src/windows/nsGfxFactoryWin.cpp b/gfx/src/windows/nsGfxFactoryWin.cpp index de27d312c606..87b5a4b9cc3b 100644 --- a/gfx/src/windows/nsGfxFactoryWin.cpp +++ b/gfx/src/windows/nsGfxFactoryWin.cpp @@ -135,7 +135,7 @@ nsresult nsGfxFactoryWin::CreateInstance(nsISupports *aOuter, else if (mClassID.Equals(kCRenderingContext)) { nsRenderingContextWin* rc; NS_NEWXPCOM(rc, nsRenderingContextWin); - inst = (nsISupports *)rc; + inst = (nsISupports *)((nsIRenderingContext*)rc); } else if (mClassID.Equals(kCImage)) { nsImageWin* image; diff --git a/gfx/src/windows/nsRenderingContextWin.cpp b/gfx/src/windows/nsRenderingContextWin.cpp index 33562676cfd1..84dd69b77e6f 100644 --- a/gfx/src/windows/nsRenderingContextWin.cpp +++ b/gfx/src/windows/nsRenderingContextWin.cpp @@ -25,11 +25,17 @@ #include #include "libimg.h" #include "nsDeviceContextWin.h" +#include "nsIScriptGlobalObject.h" +#include "prprf.h" #ifdef NGLAYOUT_DDRAW #include "ddraw.h" #endif +static NS_DEFINE_IID(kIDOMRenderingContextIID, NS_IDOMRENDERINGCONTEXT_IID); +static NS_DEFINE_IID(kIRenderingContextIID, NS_IRENDERING_CONTEXT_IID); +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); + #define FLAG_CLIP_VALID 0x0001 #define FLAG_CLIP_CHANGED 0x0002 #define FLAG_LOCAL_CLIP_VALID 0x0004 @@ -446,7 +452,41 @@ nsRenderingContextWin :: ~nsRenderingContextWin() } -NS_IMPL_QUERY_INTERFACE(nsRenderingContextWin, kRenderingContextIID) +nsresult +nsRenderingContextWin::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (nsnull == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kIRenderingContextIID)) { + nsIRenderingContext* tmp = this; + *aInstancePtr = (void*) tmp; + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kIScriptObjectOwnerIID)) { + nsIScriptObjectOwner* tmp = this; + *aInstancePtr = (void*) tmp; + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kIDOMRenderingContextIID)) { + nsIDOMRenderingContext* tmp = this; + *aInstancePtr = (void*) tmp; + NS_ADDREF_THIS(); + return NS_OK; + } + static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + if (aIID.Equals(kISupportsIID)) { + nsIRenderingContext* tmp = this; + nsISupports* tmp2 = tmp; + *aInstancePtr = (void*) tmp2; + NS_ADDREF_THIS(); + return NS_OK; + } + return NS_NOINTERFACE; +} + NS_IMPL_ADDREF(nsRenderingContextWin) NS_IMPL_RELEASE(nsRenderingContextWin) @@ -1691,3 +1731,62 @@ nsresult nsRenderingContextWin :: CreateDDraw() } #endif + +NS_IMETHODIMP +nsRenderingContextWin::GetScriptObject(nsIScriptContext* aContext, + void** aScriptObject) +{ + nsresult res = NS_OK; + nsIScriptGlobalObject *global = aContext->GetGlobalObject(); + + if (nsnull == mScriptObject) { + res = NS_NewScriptRenderingContext(aContext, + (nsISupports *)(nsIRenderingContext*)this, + global, (void**)&mScriptObject); + } + *aScriptObject = mScriptObject; + NS_RELEASE(global); + return res; +} + +NS_IMETHODIMP +nsRenderingContextWin::SetScriptObject(void* aScriptObject) +{ + mScriptObject = aScriptObject; + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextWin::GetColor(nsString& aColor) +{ + char cbuf[40]; + PR_snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x", + NS_GET_R(mCurrentColor), + NS_GET_G(mCurrentColor), + NS_GET_B(mCurrentColor)); + aColor = cbuf; + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextWin::SetColor(const nsString& aColor) +{ + nscolor rgb; + char cbuf[40]; + aColor.ToCString(cbuf, sizeof(cbuf)); + if (NS_ColorNameToRGB(cbuf, &rgb)) { + SetColor(rgb); + } + else if (NS_HexToRGB(cbuf, &rgb)) { + SetColor(rgb); + } + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextWin::DrawLine2(PRInt32 aX0, PRInt32 aY0, + PRInt32 aX1, PRInt32 aY1) +{ + DrawLine(aX0, aY0, aX1, aY1); + return NS_OK; +} diff --git a/gfx/src/windows/nsRenderingContextWin.h b/gfx/src/windows/nsRenderingContextWin.h index ddbc6c3836f3..4e86174d6fa0 100644 --- a/gfx/src/windows/nsRenderingContextWin.h +++ b/gfx/src/windows/nsRenderingContextWin.h @@ -33,6 +33,8 @@ #include "nsImageWin.h" #include "nsIDeviceContext.h" #include "nsVoidArray.h" +#include "nsIScriptObjectOwner.h" +#include "nsIDOMRenderingContext.h" class GraphicsState; class nsDrawingSurfaceWin; @@ -41,7 +43,9 @@ class nsDrawingSurfaceWin; #include "ddraw.h" #endif -class nsRenderingContextWin : public nsIRenderingContext +class nsRenderingContextWin : public nsIRenderingContext, + nsIDOMRenderingContext, + nsIScriptObjectOwner { public: nsRenderingContextWin(); @@ -143,6 +147,13 @@ public: NS_IMETHOD CopyOffScreenBits(nsRect &aBounds); + // nsIScriptObjectOwner + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + NS_IMETHOD SetScriptObject(void* aScriptObject); + + // nsIDOMRenderingContext + NS_DECL_IDOMRENDERINGCONTEXT + private: nsresult CommonInit(void); nsresult SetupDC(HDC aOldDC, HDC aNewDC); @@ -201,6 +212,8 @@ protected: static nsresult mDDrawResult; #endif + void* mScriptObject; + }; diff --git a/layout/events/src/nsDOMEvent.cpp b/layout/events/src/nsDOMEvent.cpp index 00fbddc5e1c0..a8ff7aee45b9 100644 --- a/layout/events/src/nsDOMEvent.cpp +++ b/layout/events/src/nsDOMEvent.cpp @@ -19,6 +19,8 @@ #include "nsDOMEvent.h" #include "nsIDOMNode.h" #include "nsIEventStateManager.h" +#include "nsIRenderingContext.h" +#include "nsIDOMRenderingContext.h" static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID); @@ -343,6 +345,24 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return nsnull; } +static NS_DEFINE_IID(kIDOMRenderingContextIID, NS_IDOMRENDERINGCONTEXT_IID); + +NS_IMETHODIMP +nsDOMEvent::GetRc(nsIDOMRenderingContext** aRc) +{ + *aRc = nsnull; + if (NS_PAINT_EVENT == mEvent->eventStructType) { + nsPaintEvent* pe = (nsPaintEvent*) mEvent; + if (nsnull != pe->renderingContext) { + nsIDOMRenderingContext* domrc; + if (NS_OK == pe->renderingContext->QueryInterface(kIDOMRenderingContextIID, (void**) &domrc)) { + *aRc = domrc; + } + } + } + return NS_OK; +} + nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext& aPresContext, nsEvent *aEvent) { nsDOMEvent* it = new nsDOMEvent(&aPresContext, aEvent); diff --git a/layout/events/src/nsDOMEvent.h b/layout/events/src/nsDOMEvent.h index 0eec5295d389..0373ac977e95 100644 --- a/layout/events/src/nsDOMEvent.h +++ b/layout/events/src/nsDOMEvent.h @@ -29,6 +29,8 @@ #include "nsGUIEvent.h" class nsIContent; +class nsIDOMRenderingContext; + class nsDOMEvent : public nsIDOMEvent, public nsIDOMNSEvent, public nsIPrivateDOMEvent { #define DOM_EVENT_INIT 0x0001 @@ -114,6 +116,8 @@ public: NS_IMETHOD GetLayerY(PRInt32* aLayerY); NS_IMETHOD SetLayerY(PRInt32 aLayerY); + NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc); + // nsIPrivateDOMEvent interface NS_IMETHOD DuplicatePrivateData();