From 2d62b60d0cdd3b8289080cb646872ef673df56e2 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Tue, 22 Aug 2000 04:14:53 +0000 Subject: [PATCH] Fixing nsbeta3+ bug 44024. Expose the stylesheets in stye and link elements (DOM Level 2) as 'sheet' properties on the elements. r=harishd@netscape.com --- .../html/content/src/nsHTMLLinkElement.cpp | 27 +++++++++++++++- .../html/content/src/nsHTMLStyleElement.cpp | 31 +++++++++++++++++-- .../idl/coreDom/ProcessingInstruction.idl | 17 ---------- dom/public/idl/html/HTMLLinkElement.idl | 14 --------- dom/public/idl/html/HTMLStyleElement.idl | 8 ----- dom/src/html/nsJSHTMLLinkElement.cpp | 28 ++++++++++++++++- dom/src/html/nsJSHTMLStyleElement.cpp | 28 ++++++++++++++++- layout/html/content/src/nsHTMLLinkElement.cpp | 27 +++++++++++++++- .../html/content/src/nsHTMLStyleElement.cpp | 31 +++++++++++++++++-- 9 files changed, 162 insertions(+), 49 deletions(-) diff --git a/content/html/content/src/nsHTMLLinkElement.cpp b/content/html/content/src/nsHTMLLinkElement.cpp index 8d5f5f02a30..b3f4d5f15e5 100644 --- a/content/html/content/src/nsHTMLLinkElement.cpp +++ b/content/html/content/src/nsHTMLLinkElement.cpp @@ -20,6 +20,7 @@ * Contributor(s): */ #include "nsIDOMHTMLLinkElement.h" +#include "nsIDOMLinkStyle.h" #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" @@ -45,7 +46,8 @@ class nsHTMLLinkElement : public nsIDOMHTMLLinkElement, public nsIJSScriptObject, public nsILink, public nsIHTMLContent, - public nsIStyleSheetLinkingElement + public nsIStyleSheetLinkingElement, + public nsIDOMLinkStyle { public: nsHTMLLinkElement(nsINodeInfo *aNodeInfo); @@ -101,6 +103,9 @@ public: NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet); NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet); + // nsIDOMLinkStyle + NS_DECL_IDOMLINKSTYLE + protected: nsGenericHTMLLeafElement mInner; nsIStyleSheet* mStyleSheet; @@ -164,6 +169,11 @@ nsHTMLLinkElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIDOMLinkStyle))) { + *aInstancePtr = (void*)(nsIDOMLinkStyle*) this; + NS_ADDREF_THIS(); + return NS_OK; + } return NS_NOINTERFACE; } @@ -381,3 +391,18 @@ nsHTMLLinkElement::GetHrefCString(char* &aBuf) return NS_OK; } + +NS_IMETHODIMP +nsHTMLLinkElement::GetSheet(nsIDOMStyleSheet** aSheet) +{ + NS_ENSURE_ARG_POINTER(aSheet); + *aSheet = 0; + + if (mStyleSheet) + mStyleSheet->QueryInterface(NS_GET_IID(nsIDOMStyleSheet), (void **)aSheet); + + // Always return NS_OK to avoid throwing JS exceptions if mStyleSheet + // is not a nsIDOMStyleSheet + return NS_OK; +} + diff --git a/content/html/content/src/nsHTMLStyleElement.cpp b/content/html/content/src/nsHTMLStyleElement.cpp index 24e559ab002..ec2cf64349e 100644 --- a/content/html/content/src/nsHTMLStyleElement.cpp +++ b/content/html/content/src/nsHTMLStyleElement.cpp @@ -20,6 +20,7 @@ * Contributor(s): */ #include "nsIDOMHTMLStyleElement.h" +#include "nsIDOMLinkStyle.h" #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" @@ -41,9 +42,10 @@ static NS_DEFINE_IID(kIStyleSheetLinkingElementIID, NS_ISTYLESHEETLINKINGELEMENT static NS_DEFINE_IID(kIDOMStyleSheetIID, NS_IDOMSTYLESHEET_IID); class nsHTMLStyleElement : public nsIDOMHTMLStyleElement, - public nsIJSScriptObject, - public nsIHTMLContent, - public nsIStyleSheetLinkingElement + public nsIJSScriptObject, + public nsIHTMLContent, + public nsIStyleSheetLinkingElement, + public nsIDOMLinkStyle { public: nsHTMLStyleElement(nsINodeInfo *aNodeInfo); @@ -82,6 +84,9 @@ public: NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet); NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet); + // nsIDOMLinkStyle + NS_DECL_IDOMLINKSTYLE + protected: nsGenericHTMLContainerElement mInner; nsIStyleSheet* mStyleSheet; @@ -134,6 +139,11 @@ nsHTMLStyleElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIDOMLinkStyle))) { + *aInstancePtr = (void*)(nsIDOMLinkStyle*) this; + NS_ADDREF_THIS(); + return NS_OK; + } return NS_NOINTERFACE; } @@ -274,3 +284,18 @@ nsHTMLStyleElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { return mInner.SizeOf(aSizer, aResult, sizeof(*this)); } + +NS_IMETHODIMP +nsHTMLStyleElement::GetSheet(nsIDOMStyleSheet** aSheet) +{ + NS_ENSURE_ARG_POINTER(aSheet); + *aSheet = 0; + + if (mStyleSheet) + mStyleSheet->QueryInterface(NS_GET_IID(nsIDOMStyleSheet), (void **)aSheet); + + // Always return NS_OK to avoid throwing JS exceptions if mStyleSheet + // is not a nsIDOMStyleSheet + return NS_OK; +} + diff --git a/dom/public/idl/coreDom/ProcessingInstruction.idl b/dom/public/idl/coreDom/ProcessingInstruction.idl index 5442b606ae0..e69de29bb2d 100644 --- a/dom/public/idl/coreDom/ProcessingInstruction.idl +++ b/dom/public/idl/coreDom/ProcessingInstruction.idl @@ -1,17 +0,0 @@ -interface ProcessingInstruction : Node { - /* IID: { 0xa6cf907f, 0x15b3, 0x11d2, \ - { 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */ - - readonly attribute DOMString target; - attribute DOMString data; - // raises(DOMException) on setting -}; - -// Introduced in DOM Level 2: -interface LinkStyle { - /* IID: { 0x24d89a65, 0xf598, 0x481e, \ - { 0xa2, 0x97, 0x23, 0xcc, 0x02, 0x59, 0x9b, 0xbd } } */ - - readonly attribute StyleSheet sheet; -}; - diff --git a/dom/public/idl/html/HTMLLinkElement.idl b/dom/public/idl/html/HTMLLinkElement.idl index 2a11fce0044..e69de29bb2d 100644 --- a/dom/public/idl/html/HTMLLinkElement.idl +++ b/dom/public/idl/html/HTMLLinkElement.idl @@ -1,14 +0,0 @@ - interface HTMLLinkElement : HTMLElement { - /* IID: { 0xa6cf9088, 0x15b3, 0x11d2, \ - { 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */ - - attribute boolean disabled; - attribute DOMString charset; - attribute DOMString href; - attribute DOMString hreflang; - attribute DOMString media; - attribute DOMString rel; - attribute DOMString rev; - attribute DOMString target; - attribute DOMString type; - }; diff --git a/dom/public/idl/html/HTMLStyleElement.idl b/dom/public/idl/html/HTMLStyleElement.idl index 53938904c7a..e69de29bb2d 100644 --- a/dom/public/idl/html/HTMLStyleElement.idl +++ b/dom/public/idl/html/HTMLStyleElement.idl @@ -1,8 +0,0 @@ - interface HTMLStyleElement : HTMLElement { - /* IID: { 0xa6cf908d, 0x15b3, 0x11d2, \ - { 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */ - - attribute boolean disabled; - attribute DOMString media; - attribute DOMString type; - }; diff --git a/dom/src/html/nsJSHTMLLinkElement.cpp b/dom/src/html/nsJSHTMLLinkElement.cpp index 52c02f271c2..f655a27117e 100644 --- a/dom/src/html/nsJSHTMLLinkElement.cpp +++ b/dom/src/html/nsJSHTMLLinkElement.cpp @@ -35,12 +35,16 @@ #include "nsDOMPropEnums.h" #include "nsString.h" #include "nsIDOMHTMLLinkElement.h" +#include "nsIDOMStyleSheet.h" +#include "nsIDOMLinkStyle.h" static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); static NS_DEFINE_IID(kIHTMLLinkElementIID, NS_IDOMHTMLLINKELEMENT_IID); +static NS_DEFINE_IID(kIStyleSheetIID, NS_IDOMSTYLESHEET_IID); +static NS_DEFINE_IID(kILinkStyleIID, NS_IDOMLINKSTYLE_IID); // // HTMLLinkElement property ids @@ -54,7 +58,8 @@ enum HTMLLinkElement_slots { HTMLLINKELEMENT_REL = -6, HTMLLINKELEMENT_REV = -7, HTMLLINKELEMENT_TARGET = -8, - HTMLLINKELEMENT_TYPE = -9 + HTMLLINKELEMENT_TYPE = -9, + LINKSTYLE_SHEET = -10 }; /***********************************************************************/ @@ -185,6 +190,26 @@ GetHTMLLinkElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case LINKSTYLE_SHEET: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_LINKSTYLE_SHEET, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMStyleSheet* prop; + nsIDOMLinkStyle* b; + if (NS_OK == a->QueryInterface(kILinkStyleIID, (void **)&b)) { + rv = b->GetSheet(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); } @@ -407,6 +432,7 @@ static JSPropertySpec HTMLLinkElementProperties[] = {"rev", HTMLLINKELEMENT_REV, JSPROP_ENUMERATE}, {"target", HTMLLINKELEMENT_TARGET, JSPROP_ENUMERATE}, {"type", HTMLLINKELEMENT_TYPE, JSPROP_ENUMERATE}, + {"sheet", LINKSTYLE_SHEET, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; diff --git a/dom/src/html/nsJSHTMLStyleElement.cpp b/dom/src/html/nsJSHTMLStyleElement.cpp index 839ed6a3d8e..82e05f5b5bb 100644 --- a/dom/src/html/nsJSHTMLStyleElement.cpp +++ b/dom/src/html/nsJSHTMLStyleElement.cpp @@ -35,12 +35,16 @@ #include "nsDOMPropEnums.h" #include "nsString.h" #include "nsIDOMHTMLStyleElement.h" +#include "nsIDOMStyleSheet.h" +#include "nsIDOMLinkStyle.h" static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); static NS_DEFINE_IID(kIHTMLStyleElementIID, NS_IDOMHTMLSTYLEELEMENT_IID); +static NS_DEFINE_IID(kIStyleSheetIID, NS_IDOMSTYLESHEET_IID); +static NS_DEFINE_IID(kILinkStyleIID, NS_IDOMLINKSTYLE_IID); // // HTMLStyleElement property ids @@ -48,7 +52,8 @@ static NS_DEFINE_IID(kIHTMLStyleElementIID, NS_IDOMHTMLSTYLEELEMENT_IID); enum HTMLStyleElement_slots { HTMLSTYLEELEMENT_DISABLED = -1, HTMLSTYLEELEMENT_MEDIA = -2, - HTMLSTYLEELEMENT_TYPE = -3 + HTMLSTYLEELEMENT_TYPE = -3, + LINKSTYLE_SHEET = -4 }; /***********************************************************************/ @@ -107,6 +112,26 @@ GetHTMLStyleElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case LINKSTYLE_SHEET: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_LINKSTYLE_SHEET, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMStyleSheet* prop; + nsIDOMLinkStyle* b; + if (NS_OK == a->QueryInterface(kILinkStyleIID, (void **)&b)) { + rv = b->GetSheet(&prop); + if(NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + NS_RELEASE(b); + } + else { + rv = NS_ERROR_DOM_WRONG_TYPE_ERR; + } + } + break; + } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); } @@ -251,6 +276,7 @@ static JSPropertySpec HTMLStyleElementProperties[] = {"disabled", HTMLSTYLEELEMENT_DISABLED, JSPROP_ENUMERATE}, {"media", HTMLSTYLEELEMENT_MEDIA, JSPROP_ENUMERATE}, {"type", HTMLSTYLEELEMENT_TYPE, JSPROP_ENUMERATE}, + {"sheet", LINKSTYLE_SHEET, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; diff --git a/layout/html/content/src/nsHTMLLinkElement.cpp b/layout/html/content/src/nsHTMLLinkElement.cpp index 8d5f5f02a30..b3f4d5f15e5 100644 --- a/layout/html/content/src/nsHTMLLinkElement.cpp +++ b/layout/html/content/src/nsHTMLLinkElement.cpp @@ -20,6 +20,7 @@ * Contributor(s): */ #include "nsIDOMHTMLLinkElement.h" +#include "nsIDOMLinkStyle.h" #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" @@ -45,7 +46,8 @@ class nsHTMLLinkElement : public nsIDOMHTMLLinkElement, public nsIJSScriptObject, public nsILink, public nsIHTMLContent, - public nsIStyleSheetLinkingElement + public nsIStyleSheetLinkingElement, + public nsIDOMLinkStyle { public: nsHTMLLinkElement(nsINodeInfo *aNodeInfo); @@ -101,6 +103,9 @@ public: NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet); NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet); + // nsIDOMLinkStyle + NS_DECL_IDOMLINKSTYLE + protected: nsGenericHTMLLeafElement mInner; nsIStyleSheet* mStyleSheet; @@ -164,6 +169,11 @@ nsHTMLLinkElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIDOMLinkStyle))) { + *aInstancePtr = (void*)(nsIDOMLinkStyle*) this; + NS_ADDREF_THIS(); + return NS_OK; + } return NS_NOINTERFACE; } @@ -381,3 +391,18 @@ nsHTMLLinkElement::GetHrefCString(char* &aBuf) return NS_OK; } + +NS_IMETHODIMP +nsHTMLLinkElement::GetSheet(nsIDOMStyleSheet** aSheet) +{ + NS_ENSURE_ARG_POINTER(aSheet); + *aSheet = 0; + + if (mStyleSheet) + mStyleSheet->QueryInterface(NS_GET_IID(nsIDOMStyleSheet), (void **)aSheet); + + // Always return NS_OK to avoid throwing JS exceptions if mStyleSheet + // is not a nsIDOMStyleSheet + return NS_OK; +} + diff --git a/layout/html/content/src/nsHTMLStyleElement.cpp b/layout/html/content/src/nsHTMLStyleElement.cpp index 24e559ab002..ec2cf64349e 100644 --- a/layout/html/content/src/nsHTMLStyleElement.cpp +++ b/layout/html/content/src/nsHTMLStyleElement.cpp @@ -20,6 +20,7 @@ * Contributor(s): */ #include "nsIDOMHTMLStyleElement.h" +#include "nsIDOMLinkStyle.h" #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" @@ -41,9 +42,10 @@ static NS_DEFINE_IID(kIStyleSheetLinkingElementIID, NS_ISTYLESHEETLINKINGELEMENT static NS_DEFINE_IID(kIDOMStyleSheetIID, NS_IDOMSTYLESHEET_IID); class nsHTMLStyleElement : public nsIDOMHTMLStyleElement, - public nsIJSScriptObject, - public nsIHTMLContent, - public nsIStyleSheetLinkingElement + public nsIJSScriptObject, + public nsIHTMLContent, + public nsIStyleSheetLinkingElement, + public nsIDOMLinkStyle { public: nsHTMLStyleElement(nsINodeInfo *aNodeInfo); @@ -82,6 +84,9 @@ public: NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet); NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet); + // nsIDOMLinkStyle + NS_DECL_IDOMLINKSTYLE + protected: nsGenericHTMLContainerElement mInner; nsIStyleSheet* mStyleSheet; @@ -134,6 +139,11 @@ nsHTMLStyleElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIDOMLinkStyle))) { + *aInstancePtr = (void*)(nsIDOMLinkStyle*) this; + NS_ADDREF_THIS(); + return NS_OK; + } return NS_NOINTERFACE; } @@ -274,3 +284,18 @@ nsHTMLStyleElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { return mInner.SizeOf(aSizer, aResult, sizeof(*this)); } + +NS_IMETHODIMP +nsHTMLStyleElement::GetSheet(nsIDOMStyleSheet** aSheet) +{ + NS_ENSURE_ARG_POINTER(aSheet); + *aSheet = 0; + + if (mStyleSheet) + mStyleSheet->QueryInterface(NS_GET_IID(nsIDOMStyleSheet), (void **)aSheet); + + // Always return NS_OK to avoid throwing JS exceptions if mStyleSheet + // is not a nsIDOMStyleSheet + return NS_OK; +} +