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

This commit is contained in:
jst%netscape.com 2000-08-22 04:14:53 +00:00
Родитель 465ed581f8
Коммит 2d62b60d0c
9 изменённых файлов: 162 добавлений и 49 удалений

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

@ -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;
}

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

@ -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;
}

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

@ -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;
};

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

@ -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;
};

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

@ -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;
};

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

@ -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}
};

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

@ -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}
};

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

@ -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;
}

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

@ -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;
}