зеркало из https://github.com/mozilla/pjs.git
Fixing bug 64755. Moving code around to make plugins instantiated from an <object> tag be scriptable. r=pollmann@netscape.com, sr=hyatt@netscape.com
This commit is contained in:
Родитель
4a77bec32f
Коммит
f451a8c50b
|
@ -94,6 +94,15 @@
|
|||
#include "nsIBindingManager.h"
|
||||
#include "nsIXBLBinding.h"
|
||||
|
||||
#include "nsObjectFrame.h"
|
||||
#include "nsLayoutAtoms.h"
|
||||
#include "xptinfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIPluginInstance.h"
|
||||
#include "nsIScriptablePlugin.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIParser.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsIHTMLContentSink.h"
|
||||
|
@ -102,7 +111,207 @@
|
|||
|
||||
#include "nsIPref.h" // Used by the temp pref, should be removed!
|
||||
|
||||
nsresult
|
||||
nsGenericHTMLElement::GetPluginInstance(nsIPluginInstance** aPluginInstance)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPluginInstance);
|
||||
*aPluginInstance = nsnull;
|
||||
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
|
||||
if (mDocument) {
|
||||
// Make sure the presentation is up-to-date
|
||||
result = mDocument->FlushPendingNotifications();
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
GetPresContext(this, getter_AddRefs(context));
|
||||
if (!context) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
context->GetShell(getter_AddRefs(shell));
|
||||
if (!shell) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIFrame* frame = nsnull;
|
||||
shell->GetPrimaryFrameFor(this, &frame);
|
||||
if (!frame) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAtom> type;
|
||||
|
||||
frame->GetFrameType(getter_AddRefs(type));
|
||||
|
||||
if (type.get() == nsLayoutAtoms::objectFrame) {
|
||||
// XXX We could have created an interface for this, but Troy
|
||||
// preferred the ugliness of a static cast to the weight of
|
||||
// a new interface.
|
||||
|
||||
nsObjectFrame* objectFrame = NS_STATIC_CAST(nsObjectFrame*, frame);
|
||||
|
||||
return objectFrame->GetPluginInstance(*aPluginInstance);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* For plugins, we want to expose both attributes of the plugin tag
|
||||
* and any scriptable methods that the plugin itself exposes. To do
|
||||
* this, we get the plugin object itself (the XPCOM object) and wrap
|
||||
* it as a scriptable object via xpconnect. We then set the original
|
||||
* node element, which exposes the DOM node methods, as the javascript
|
||||
* prototype object of that object. Then we get both sets of methods, and
|
||||
* plugin methods can potentially override DOM methods.
|
||||
*/
|
||||
nsresult
|
||||
nsGenericHTMLElement::GetPluginScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
if (mDOMSlots && mDOMSlots->mScriptObject)
|
||||
return nsGenericElement::GetScriptObject(aContext, aScriptObject);
|
||||
|
||||
nsresult rv;
|
||||
*aScriptObject = nsnull;
|
||||
|
||||
// Get the JS object corresponding to this dom node. This will become
|
||||
// the javascript prototype object of the object we eventually reflect to the
|
||||
// DOM.
|
||||
JSObject* elementObject = nsnull;
|
||||
rv = nsGenericElement::GetScriptObject(aContext, (void**)&elementObject);
|
||||
if (NS_FAILED(rv) || !elementObject)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIPluginInstance> pi;
|
||||
GetPluginInstance(getter_AddRefs(pi));
|
||||
|
||||
// If GetPluginInstance() returns nsnull it most likely means
|
||||
// there's no frame for this element yet, in that case we return the
|
||||
// script object for the element but we don't cache it so that the
|
||||
// next call can get the correct script object if the plugin
|
||||
// instance is available at the next call.
|
||||
if (!pi) {
|
||||
if (mDocument) {
|
||||
// Since we're resetting the script object to null we'll remove the
|
||||
// reference to it so that we won't add the same named reference
|
||||
// again the next time someone requests the script object.
|
||||
aContext->RemoveReference((void *)&mDOMSlots->mScriptObject,
|
||||
mDOMSlots->mScriptObject);
|
||||
}
|
||||
|
||||
SetScriptObject(nsnull);
|
||||
|
||||
*aScriptObject = elementObject;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Check if the plugin object has the nsIScriptablePlugin
|
||||
// interface, describing how to expose it to JavaScript. Given this
|
||||
// interface, use it to get the scriptable peer object (possibly the
|
||||
// plugin object itself) and the scriptable interface to expose it
|
||||
// with
|
||||
nsIID scriptableInterface;
|
||||
nsCOMPtr<nsISupports> scriptablePeer;
|
||||
if (NS_SUCCEEDED(rv) && pi) {
|
||||
nsCOMPtr<nsIScriptablePlugin> spi(do_QueryInterface(pi, &rv));
|
||||
if (NS_SUCCEEDED(rv) && spi) {
|
||||
nsIID *scriptableInterfacePtr = nsnull;
|
||||
rv = spi->GetScriptableInterface(&scriptableInterfacePtr);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && scriptableInterfacePtr) {
|
||||
rv = spi->GetScriptablePeer(getter_AddRefs(scriptablePeer));
|
||||
|
||||
scriptableInterface = *scriptableInterfacePtr;
|
||||
|
||||
nsMemory::Free(scriptableInterfacePtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv) || !scriptablePeer) {
|
||||
// Fall back to returning the element object.
|
||||
*aScriptObject = elementObject;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Wrap it.
|
||||
JSObject* interfaceObject; // XPConnect-wrapped peer object, when we get it.
|
||||
JSContext *cx = (JSContext *)aContext->GetNativeContext();
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
if (cx && xpc) {
|
||||
JSObject* parentObject = JS_GetParent(cx, elementObject);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
if (NS_SUCCEEDED(xpc->WrapNative(cx, parentObject,
|
||||
scriptablePeer, scriptableInterface,
|
||||
getter_AddRefs(holder))) && holder &&
|
||||
NS_SUCCEEDED(holder->GetJSObject(&interfaceObject)) &&
|
||||
interfaceObject) {
|
||||
*aScriptObject = interfaceObject;
|
||||
}
|
||||
}
|
||||
|
||||
// If we got an xpconnect-wrapped plugin object, set its' prototype to the
|
||||
// element object.
|
||||
if (!*aScriptObject || !JS_SetPrototype(cx, interfaceObject,
|
||||
elementObject)) {
|
||||
*aScriptObject = elementObject; // fall back
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Cache it.
|
||||
SetScriptObject(*aScriptObject);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Allow access to arbitrary XPCOM interfaces supported by the plugin
|
||||
// via a pluginObject.nsISomeInterface notation.
|
||||
PRBool
|
||||
nsGenericHTMLElement::GetPluginProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp)
|
||||
{
|
||||
if (JSVAL_IS_STRING(aID)) {
|
||||
PRBool retval = PR_FALSE;
|
||||
char* cString = JS_GetStringBytes(JS_ValueToString(aContext, aID));
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iim =
|
||||
dont_AddRef(XPTI_GetInterfaceInfoManager());
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
|
||||
if (iim && xpc) {
|
||||
nsIID* iid;
|
||||
if (NS_SUCCEEDED(iim->GetIIDForName(cString, &iid)) && iid) {
|
||||
nsCOMPtr<nsIPluginInstance> pi;
|
||||
if (NS_SUCCEEDED(GetPluginInstance(getter_AddRefs(pi))) && pi) {
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
JSObject* ifaceObj;
|
||||
|
||||
if (NS_SUCCEEDED(xpc->WrapNative(aContext, aObj, pi, *iid,
|
||||
getter_AddRefs(holder))) &&
|
||||
holder && NS_SUCCEEDED(holder->GetJSObject(&ifaceObj)) &&
|
||||
ifaceObj) {
|
||||
*aVp = OBJECT_TO_JSVAL(ifaceObj);
|
||||
retval = PR_TRUE;
|
||||
}
|
||||
}
|
||||
nsMemory::Free(iid);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nsGenericElement::GetProperty(aContext, aObj, aID, aVp);
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsDOMCSSAttributeDeclaration : public nsDOMCSSDeclaration
|
||||
|
|
|
@ -54,6 +54,7 @@ class nsIURI;
|
|||
class nsIFormControlFrame;
|
||||
class nsIForm;
|
||||
class nsIPresState;
|
||||
class nsIPluginInstance;
|
||||
|
||||
class nsGenericHTMLElement : public nsGenericElement {
|
||||
public:
|
||||
|
@ -334,6 +335,14 @@ public:
|
|||
static PRBool InNavQuirksMode(nsIDocument* aDoc);
|
||||
|
||||
nsIHTMLAttributes* mAttributes;
|
||||
|
||||
protected:
|
||||
nsresult GetPluginInstance(nsIPluginInstance** aPluginInstance);
|
||||
|
||||
nsresult GetPluginScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject);
|
||||
PRBool GetPluginProperty(JSContext *aContext, JSObject *aObj, jsval aID,
|
||||
jsval *aVp);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -19,32 +19,12 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#include "nsIDOMHTMLElement.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsIDOMHTMLEmbedElement.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIMutableStyleContext.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsObjectFrame.h"
|
||||
#include "nsLayoutAtoms.h"
|
||||
#include "nsObjectFrame.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMemory.h"
|
||||
#include "xptinfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIPluginInstance.h"
|
||||
#include "nsIScriptablePlugin.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIDOMHTMLEmbedElement.h"
|
||||
|
||||
|
||||
class nsHTMLEmbedElement : public nsGenericHTMLLeafElement,
|
||||
public nsIDOMHTMLEmbedElement
|
||||
|
@ -68,10 +48,6 @@ public:
|
|||
// nsIDOMHTMLEmbedElement
|
||||
NS_DECL_IDOMHTMLEMBEDELEMENT
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject);
|
||||
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp);
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAReadableString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
|
@ -84,8 +60,13 @@ public:
|
|||
nsMapAttributesFunc& aMapFunc) const;
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
||||
|
||||
protected:
|
||||
nsresult GetPluginInstance(nsIPluginInstance** aPluginInstance);
|
||||
// nsIScriptObjectOwner
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject);
|
||||
|
||||
// nsIJSScriptObject
|
||||
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp);
|
||||
};
|
||||
|
||||
nsresult
|
||||
|
@ -247,219 +228,18 @@ nsHTMLEmbedElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
// This is cribbed from nsHTMLImageElement::GetImageFrame.
|
||||
|
||||
nsresult
|
||||
nsHTMLEmbedElement::GetPluginInstance(nsIPluginInstance** aPluginInstance)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPluginInstance);
|
||||
*aPluginInstance = nsnull;
|
||||
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
|
||||
if (mDocument) {
|
||||
// Make sure the presentation is up-to-date
|
||||
result = mDocument->FlushPendingNotifications();
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result = GetPresContext(this, getter_AddRefs(context));
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = context->GetShell(getter_AddRefs(shell));
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
nsIFrame* frame;
|
||||
result = shell->GetPrimaryFrameFor(this, &frame);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (frame) {
|
||||
nsCOMPtr<nsIAtom> type;
|
||||
|
||||
frame->GetFrameType(getter_AddRefs(type));
|
||||
|
||||
if (type.get() == nsLayoutAtoms::objectFrame) {
|
||||
// XXX We could have created an interface for this, but Troy
|
||||
// preferred the ugliness of a static cast to the weight of
|
||||
// a new interface.
|
||||
|
||||
nsObjectFrame* objectFrame = NS_STATIC_CAST(nsObjectFrame*, frame);
|
||||
|
||||
return objectFrame->GetPluginInstance(*aPluginInstance);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/*
|
||||
* For plugins, we want to expose both attributes of the plugin tag
|
||||
* and any scriptable methods that the plugin itself exposes. To do
|
||||
* this, we get the plugin object itself (the XPCOM object) and wrap
|
||||
* it as a scriptable object via xpconnect. We then set the original
|
||||
* node element, which exposes the DOM node methods, as the javascript
|
||||
* prototype object of that object. Then we get both sets of methods, and
|
||||
* plugin methods can potentially override DOM methods.
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEmbedElement::GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
if (mDOMSlots && mDOMSlots->mScriptObject)
|
||||
return nsGenericHTMLLeafElement::GetScriptObject(aContext, aScriptObject);
|
||||
|
||||
nsresult rv;
|
||||
*aScriptObject = nsnull;
|
||||
|
||||
// Get the JS object corresponding to this dom node. This will become
|
||||
// the javascript prototype object of the object we eventually reflect to the
|
||||
// DOM.
|
||||
JSObject* elementObject = nsnull;
|
||||
rv = nsGenericHTMLLeafElement::GetScriptObject(aContext,
|
||||
(void**)&elementObject);
|
||||
if (NS_FAILED(rv) || !elementObject)
|
||||
return rv;
|
||||
|
||||
// Flush pending reflows to ensure the plugin is instansiated, assuming
|
||||
// it's visible
|
||||
if (mDocument) {
|
||||
mDocument->FlushPendingNotifications();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPluginInstance> pi;
|
||||
rv = GetPluginInstance(getter_AddRefs(pi));
|
||||
|
||||
// If GetPluginInstance() fails it means there's no frame for this element
|
||||
// yet, in that case we return the script object for the element but we
|
||||
// don't cache it so that the next call can get the correct script object
|
||||
// if the plugin instance is available at the next call.
|
||||
if (NS_FAILED(rv)) {
|
||||
if (mDocument) {
|
||||
// Since we're resetting the script object to null we'll remove the
|
||||
// reference to it so that we won't add the same named reference
|
||||
// again the next time someone requests the script object.
|
||||
aContext->RemoveReference((void *)&mDOMSlots->mScriptObject,
|
||||
mDOMSlots->mScriptObject);
|
||||
}
|
||||
|
||||
SetScriptObject(nsnull);
|
||||
|
||||
*aScriptObject = elementObject;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Check if the plugin object has the nsIScriptablePlugin
|
||||
// interface, describing how to expose it to JavaScript. Given this
|
||||
// interface, use it to get the scriptable peer object (possibly the
|
||||
// plugin object itself) and the scriptable interface to expose it
|
||||
// with
|
||||
nsIID scriptableInterface;
|
||||
nsCOMPtr<nsISupports> scriptablePeer;
|
||||
if (NS_SUCCEEDED(rv) && pi) {
|
||||
nsCOMPtr<nsIScriptablePlugin> spi(do_QueryInterface(pi, &rv));
|
||||
if (NS_SUCCEEDED(rv) && spi) {
|
||||
nsIID *scriptableInterfacePtr = nsnull;
|
||||
rv = spi->GetScriptableInterface(&scriptableInterfacePtr);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && scriptableInterfacePtr) {
|
||||
rv = spi->GetScriptablePeer(getter_AddRefs(scriptablePeer));
|
||||
|
||||
scriptableInterface = *scriptableInterfacePtr;
|
||||
|
||||
nsMemory::Free(scriptableInterfacePtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv) || !scriptablePeer) {
|
||||
// Fall back to returning the element object.
|
||||
*aScriptObject = elementObject;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Wrap it.
|
||||
JSObject* interfaceObject; // XPConnect-wrapped peer object, when we get it.
|
||||
JSContext *cx = (JSContext *)aContext->GetNativeContext();
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
if (cx && xpc) {
|
||||
JSObject* parentObject = JS_GetParent(cx, elementObject);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
if (NS_SUCCEEDED(xpc->WrapNative(cx, parentObject,
|
||||
scriptablePeer, scriptableInterface,
|
||||
getter_AddRefs(holder))) && holder &&
|
||||
NS_SUCCEEDED(holder->GetJSObject(&interfaceObject)) && interfaceObject) {
|
||||
*aScriptObject = interfaceObject;
|
||||
}
|
||||
}
|
||||
|
||||
// If we got an xpconnect-wrapped plugin object, set its' prototype to the
|
||||
// element object.
|
||||
if (!*aScriptObject || !JS_SetPrototype(cx, interfaceObject,
|
||||
elementObject)) {
|
||||
*aScriptObject = elementObject; // fall back
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Cache it.
|
||||
SetScriptObject(*aScriptObject);
|
||||
|
||||
return NS_OK;
|
||||
return GetPluginScriptObject(aContext, aScriptObject);
|
||||
}
|
||||
|
||||
// Allow access to arbitrary XPCOM interfaces supported by the plugin
|
||||
// via a pluginObject.nsISomeInterface notation.
|
||||
PRBool
|
||||
PRBool
|
||||
nsHTMLEmbedElement::GetProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp)
|
||||
{
|
||||
if (JSVAL_IS_STRING(aID)) {
|
||||
PRBool retval = PR_FALSE;
|
||||
char* cString = JS_GetStringBytes(JS_ValueToString(aContext, aID));
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iim =
|
||||
dont_AddRef(XPTI_GetInterfaceInfoManager());
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
|
||||
if (iim && xpc) {
|
||||
nsIID* iid;
|
||||
if (NS_SUCCEEDED(iim->GetIIDForName(cString, &iid)) && iid) {
|
||||
nsCOMPtr<nsIPluginInstance> pi;
|
||||
if (NS_SUCCEEDED(GetPluginInstance(getter_AddRefs(pi))) && pi) {
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
JSObject* ifaceObj;
|
||||
|
||||
if (NS_SUCCEEDED(xpc->WrapNative(aContext, aObj, pi, *iid,
|
||||
getter_AddRefs(holder))) && holder &&
|
||||
NS_SUCCEEDED(holder->GetJSObject(&ifaceObj)) && ifaceObj) {
|
||||
*aVp = OBJECT_TO_JSVAL(ifaceObj);
|
||||
retval = PR_TRUE;
|
||||
}
|
||||
}
|
||||
nsMemory::Free(iid);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLLeafElement::GetProperty(aContext, aObj, aID, aVp);
|
||||
return GetPluginProperty(aContext, aObj, aID, aVp);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
|
|
|
@ -20,16 +20,9 @@
|
|||
* Contributor(s):
|
||||
*/
|
||||
#include "nsIDOMHTMLObjectElement.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIMutableStyleContext.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsDOMError.h"
|
||||
|
||||
|
||||
|
@ -66,6 +59,14 @@ public:
|
|||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint) const;
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
||||
|
||||
// nsIScriptObjectOwner
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject);
|
||||
|
||||
// nsIJSScriptObject
|
||||
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp);
|
||||
};
|
||||
|
||||
nsresult
|
||||
|
@ -266,3 +267,17 @@ nsHTMLObjectElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
return GetPluginScriptObject(aContext, aScriptObject);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLObjectElement::GetProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp)
|
||||
{
|
||||
return GetPluginProperty(aContext, aObj, aID, aVp);
|
||||
}
|
||||
|
|
|
@ -20,16 +20,9 @@
|
|||
* Contributor(s):
|
||||
*/
|
||||
#include "nsIDOMHTMLObjectElement.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIMutableStyleContext.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsDOMError.h"
|
||||
|
||||
|
||||
|
@ -66,6 +59,14 @@ public:
|
|||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint) const;
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
||||
|
||||
// nsIScriptObjectOwner
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject);
|
||||
|
||||
// nsIJSScriptObject
|
||||
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp);
|
||||
};
|
||||
|
||||
nsresult
|
||||
|
@ -266,3 +267,17 @@ nsHTMLObjectElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
return GetPluginScriptObject(aContext, aScriptObject);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLObjectElement::GetProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp)
|
||||
{
|
||||
return GetPluginProperty(aContext, aObj, aID, aVp);
|
||||
}
|
||||
|
|
|
@ -94,6 +94,15 @@
|
|||
#include "nsIBindingManager.h"
|
||||
#include "nsIXBLBinding.h"
|
||||
|
||||
#include "nsObjectFrame.h"
|
||||
#include "nsLayoutAtoms.h"
|
||||
#include "xptinfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIPluginInstance.h"
|
||||
#include "nsIScriptablePlugin.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIParser.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsIHTMLContentSink.h"
|
||||
|
@ -102,7 +111,207 @@
|
|||
|
||||
#include "nsIPref.h" // Used by the temp pref, should be removed!
|
||||
|
||||
nsresult
|
||||
nsGenericHTMLElement::GetPluginInstance(nsIPluginInstance** aPluginInstance)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPluginInstance);
|
||||
*aPluginInstance = nsnull;
|
||||
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
|
||||
if (mDocument) {
|
||||
// Make sure the presentation is up-to-date
|
||||
result = mDocument->FlushPendingNotifications();
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
GetPresContext(this, getter_AddRefs(context));
|
||||
if (!context) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
context->GetShell(getter_AddRefs(shell));
|
||||
if (!shell) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIFrame* frame = nsnull;
|
||||
shell->GetPrimaryFrameFor(this, &frame);
|
||||
if (!frame) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAtom> type;
|
||||
|
||||
frame->GetFrameType(getter_AddRefs(type));
|
||||
|
||||
if (type.get() == nsLayoutAtoms::objectFrame) {
|
||||
// XXX We could have created an interface for this, but Troy
|
||||
// preferred the ugliness of a static cast to the weight of
|
||||
// a new interface.
|
||||
|
||||
nsObjectFrame* objectFrame = NS_STATIC_CAST(nsObjectFrame*, frame);
|
||||
|
||||
return objectFrame->GetPluginInstance(*aPluginInstance);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* For plugins, we want to expose both attributes of the plugin tag
|
||||
* and any scriptable methods that the plugin itself exposes. To do
|
||||
* this, we get the plugin object itself (the XPCOM object) and wrap
|
||||
* it as a scriptable object via xpconnect. We then set the original
|
||||
* node element, which exposes the DOM node methods, as the javascript
|
||||
* prototype object of that object. Then we get both sets of methods, and
|
||||
* plugin methods can potentially override DOM methods.
|
||||
*/
|
||||
nsresult
|
||||
nsGenericHTMLElement::GetPluginScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
if (mDOMSlots && mDOMSlots->mScriptObject)
|
||||
return nsGenericElement::GetScriptObject(aContext, aScriptObject);
|
||||
|
||||
nsresult rv;
|
||||
*aScriptObject = nsnull;
|
||||
|
||||
// Get the JS object corresponding to this dom node. This will become
|
||||
// the javascript prototype object of the object we eventually reflect to the
|
||||
// DOM.
|
||||
JSObject* elementObject = nsnull;
|
||||
rv = nsGenericElement::GetScriptObject(aContext, (void**)&elementObject);
|
||||
if (NS_FAILED(rv) || !elementObject)
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIPluginInstance> pi;
|
||||
GetPluginInstance(getter_AddRefs(pi));
|
||||
|
||||
// If GetPluginInstance() returns nsnull it most likely means
|
||||
// there's no frame for this element yet, in that case we return the
|
||||
// script object for the element but we don't cache it so that the
|
||||
// next call can get the correct script object if the plugin
|
||||
// instance is available at the next call.
|
||||
if (!pi) {
|
||||
if (mDocument) {
|
||||
// Since we're resetting the script object to null we'll remove the
|
||||
// reference to it so that we won't add the same named reference
|
||||
// again the next time someone requests the script object.
|
||||
aContext->RemoveReference((void *)&mDOMSlots->mScriptObject,
|
||||
mDOMSlots->mScriptObject);
|
||||
}
|
||||
|
||||
SetScriptObject(nsnull);
|
||||
|
||||
*aScriptObject = elementObject;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Check if the plugin object has the nsIScriptablePlugin
|
||||
// interface, describing how to expose it to JavaScript. Given this
|
||||
// interface, use it to get the scriptable peer object (possibly the
|
||||
// plugin object itself) and the scriptable interface to expose it
|
||||
// with
|
||||
nsIID scriptableInterface;
|
||||
nsCOMPtr<nsISupports> scriptablePeer;
|
||||
if (NS_SUCCEEDED(rv) && pi) {
|
||||
nsCOMPtr<nsIScriptablePlugin> spi(do_QueryInterface(pi, &rv));
|
||||
if (NS_SUCCEEDED(rv) && spi) {
|
||||
nsIID *scriptableInterfacePtr = nsnull;
|
||||
rv = spi->GetScriptableInterface(&scriptableInterfacePtr);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && scriptableInterfacePtr) {
|
||||
rv = spi->GetScriptablePeer(getter_AddRefs(scriptablePeer));
|
||||
|
||||
scriptableInterface = *scriptableInterfacePtr;
|
||||
|
||||
nsMemory::Free(scriptableInterfacePtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv) || !scriptablePeer) {
|
||||
// Fall back to returning the element object.
|
||||
*aScriptObject = elementObject;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Wrap it.
|
||||
JSObject* interfaceObject; // XPConnect-wrapped peer object, when we get it.
|
||||
JSContext *cx = (JSContext *)aContext->GetNativeContext();
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
if (cx && xpc) {
|
||||
JSObject* parentObject = JS_GetParent(cx, elementObject);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
if (NS_SUCCEEDED(xpc->WrapNative(cx, parentObject,
|
||||
scriptablePeer, scriptableInterface,
|
||||
getter_AddRefs(holder))) && holder &&
|
||||
NS_SUCCEEDED(holder->GetJSObject(&interfaceObject)) &&
|
||||
interfaceObject) {
|
||||
*aScriptObject = interfaceObject;
|
||||
}
|
||||
}
|
||||
|
||||
// If we got an xpconnect-wrapped plugin object, set its' prototype to the
|
||||
// element object.
|
||||
if (!*aScriptObject || !JS_SetPrototype(cx, interfaceObject,
|
||||
elementObject)) {
|
||||
*aScriptObject = elementObject; // fall back
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Cache it.
|
||||
SetScriptObject(*aScriptObject);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Allow access to arbitrary XPCOM interfaces supported by the plugin
|
||||
// via a pluginObject.nsISomeInterface notation.
|
||||
PRBool
|
||||
nsGenericHTMLElement::GetPluginProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp)
|
||||
{
|
||||
if (JSVAL_IS_STRING(aID)) {
|
||||
PRBool retval = PR_FALSE;
|
||||
char* cString = JS_GetStringBytes(JS_ValueToString(aContext, aID));
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iim =
|
||||
dont_AddRef(XPTI_GetInterfaceInfoManager());
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
|
||||
if (iim && xpc) {
|
||||
nsIID* iid;
|
||||
if (NS_SUCCEEDED(iim->GetIIDForName(cString, &iid)) && iid) {
|
||||
nsCOMPtr<nsIPluginInstance> pi;
|
||||
if (NS_SUCCEEDED(GetPluginInstance(getter_AddRefs(pi))) && pi) {
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
JSObject* ifaceObj;
|
||||
|
||||
if (NS_SUCCEEDED(xpc->WrapNative(aContext, aObj, pi, *iid,
|
||||
getter_AddRefs(holder))) &&
|
||||
holder && NS_SUCCEEDED(holder->GetJSObject(&ifaceObj)) &&
|
||||
ifaceObj) {
|
||||
*aVp = OBJECT_TO_JSVAL(ifaceObj);
|
||||
retval = PR_TRUE;
|
||||
}
|
||||
}
|
||||
nsMemory::Free(iid);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nsGenericElement::GetProperty(aContext, aObj, aID, aVp);
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsDOMCSSAttributeDeclaration : public nsDOMCSSDeclaration
|
||||
|
|
|
@ -1,740 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#ifndef nsGenericHTMLElement_h___
|
||||
#define nsGenericHTMLElement_h___
|
||||
|
||||
#include "nsGenericElement.h"
|
||||
#include "nsHTMLParts.h"
|
||||
#include "nsIDOMHTMLElement.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsHTMLValue.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
#include "nsINameSpaceManager.h" // for kNameSpaceID_HTML
|
||||
#include "nsIFormControl.h"
|
||||
|
||||
#include "nsIStatefulFrame.h"
|
||||
|
||||
|
||||
class nsIDOMAttr;
|
||||
class nsIDOMEventListener;
|
||||
class nsIDOMNodeList;
|
||||
class nsIEventListenerManager;
|
||||
class nsIFrame;
|
||||
class nsIHTMLAttributes;
|
||||
class nsIHTMLMappedAttributes;
|
||||
class nsIHTMLContent;
|
||||
class nsIMutableStyleContext;
|
||||
class nsIStyleRule;
|
||||
class nsISupportsArray;
|
||||
class nsIDOMScriptObjectFactory;
|
||||
class nsChildContentList;
|
||||
class nsDOMCSSDeclaration;
|
||||
class nsIDOMCSSStyleDeclaration;
|
||||
class nsIURI;
|
||||
class nsIFormControlFrame;
|
||||
class nsIForm;
|
||||
class nsIPresState;
|
||||
|
||||
class nsGenericHTMLElement : public nsGenericElement {
|
||||
public:
|
||||
nsGenericHTMLElement();
|
||||
virtual ~nsGenericHTMLElement();
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
static nsresult DOMQueryInterface(nsIDOMHTMLElement *aElement,
|
||||
REFNSIID aIID, void **aInstancePtr);
|
||||
|
||||
NS_METHOD CopyInnerTo(nsIContent* aSrcContent,
|
||||
nsGenericHTMLElement* aDest,
|
||||
PRBool aDeep);
|
||||
|
||||
// Implementation for nsIDOMNode
|
||||
NS_METHOD GetNodeName(nsAWritableString& aNodeName);
|
||||
NS_METHOD GetLocalName(nsAWritableString& aLocalName);
|
||||
|
||||
// Implementation for nsIDOMElement
|
||||
NS_METHOD GetAttribute(const nsAReadableString& aName,
|
||||
nsAWritableString& aReturn)
|
||||
{
|
||||
return nsGenericElement::GetAttribute(aName, aReturn);
|
||||
}
|
||||
NS_METHOD SetAttribute(const nsAReadableString& aName,
|
||||
const nsAReadableString& aValue)
|
||||
{
|
||||
return nsGenericElement::SetAttribute(aName, aValue);
|
||||
}
|
||||
NS_METHOD GetTagName(nsAWritableString& aTagName);
|
||||
NS_METHOD GetElementsByTagName(const nsAReadableString& aTagname,
|
||||
nsIDOMNodeList** aReturn);
|
||||
|
||||
// Implementation for nsIDOMHTMLElement
|
||||
NS_METHOD GetId(nsAWritableString& aId);
|
||||
NS_METHOD SetId(const nsAReadableString& aId);
|
||||
NS_METHOD GetTitle(nsAWritableString& aTitle);
|
||||
NS_METHOD SetTitle(const nsAReadableString& aTitle);
|
||||
NS_METHOD GetLang(nsAWritableString& aLang);
|
||||
NS_METHOD SetLang(const nsAReadableString& aLang);
|
||||
NS_METHOD GetDir(nsAWritableString& aDir);
|
||||
NS_METHOD SetDir(const nsAReadableString& aDir);
|
||||
NS_METHOD GetClassName(nsAWritableString& aClassName);
|
||||
NS_METHOD SetClassName(const nsAReadableString& aClassName);
|
||||
NS_METHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
|
||||
NS_METHOD GetOffsetTop(PRInt32* aOffsetTop);
|
||||
NS_METHOD GetOffsetLeft(PRInt32* aOffsetLeft);
|
||||
NS_METHOD GetOffsetWidth(PRInt32* aOffsetWidth);
|
||||
NS_METHOD GetOffsetHeight(PRInt32* aOffsetHeight);
|
||||
NS_METHOD GetOffsetParent(nsIDOMElement** aOffsetParent);
|
||||
NS_METHOD GetInnerHTML(nsAWritableString& aInnerHTML);
|
||||
NS_METHOD SetInnerHTML(const nsAReadableString& aInnerHTML);
|
||||
NS_METHOD GetOffsetRect(nsRect& aRect,
|
||||
nsIAtom* aOffsetParentTag,
|
||||
nsIContent** aOffsetParent);
|
||||
|
||||
// Implementation for nsIContent
|
||||
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep,
|
||||
PRBool aCompileEventHandlers);
|
||||
NS_IMETHOD GetNameSpaceID(PRInt32& aID) const;
|
||||
NS_IMETHOD NormalizeAttributeString(const nsAReadableString& aStr,
|
||||
nsINodeInfo*& aNodeInfo);
|
||||
NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
const nsAReadableString& aValue,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD SetAttribute(nsINodeInfo* aNodeInfo,
|
||||
const nsAReadableString& aValue,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
nsAWritableString& aResult) const;
|
||||
NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
nsIAtom*& aPrefix, nsAWritableString& aResult) const;
|
||||
NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex,
|
||||
PRInt32& aNameSpaceID,
|
||||
nsIAtom*& aName,
|
||||
nsIAtom*& aPrefix) const;
|
||||
NS_IMETHOD GetAttributeCount(PRInt32& aResult) const;
|
||||
NS_IMETHOD List(FILE* out, PRInt32 aIndent) const;
|
||||
NS_IMETHOD DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const;
|
||||
|
||||
nsresult HandleDOMEventForAnchors(nsIContent* aOuter,
|
||||
nsIPresContext* aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus* aEventStatus);
|
||||
|
||||
// Implementation for nsIHTMLContent
|
||||
NS_IMETHOD SetHTMLAttribute(nsIAtom* aAttribute, const nsHTMLValue& aValue,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD GetHTMLAttribute(nsIAtom* aAttribute, nsHTMLValue& aValue) const;
|
||||
NS_IMETHOD GetID(nsIAtom*& aResult) const;
|
||||
NS_IMETHOD GetClasses(nsVoidArray& aArray) const;
|
||||
NS_IMETHOD HasClass(nsIAtom* aClass) const;
|
||||
NS_IMETHOD GetContentStyleRules(nsISupportsArray* aRules);
|
||||
NS_IMETHOD GetInlineStyleRules(nsISupportsArray* aRules);
|
||||
NS_IMETHOD GetBaseURL(nsIURI*& aBaseURL) const;
|
||||
NS_IMETHOD GetBaseTarget(nsAWritableString& aBaseTarget) const;
|
||||
|
||||
//----------------------------------------
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult) const;
|
||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint) const;
|
||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
||||
nsMapAttributesFunc& aMapFunc) const;
|
||||
|
||||
void ListAttributes(FILE* out) const;
|
||||
|
||||
PRUint32 BaseSizeOf(nsISizeOfHandler* aSizer) const;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
// Attribute parsing utilities
|
||||
|
||||
struct EnumTable {
|
||||
const char* tag;
|
||||
PRInt32 value;
|
||||
};
|
||||
|
||||
static PRBool ParseEnumValue(const nsAReadableString& aValue,
|
||||
EnumTable* aTable,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
static PRBool ParseCaseSensitiveEnumValue(const nsAReadableString& aValue,
|
||||
EnumTable* aTable,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
static PRBool EnumValueToString(const nsHTMLValue& aValue,
|
||||
EnumTable* aTable,
|
||||
nsAWritableString& aResult,
|
||||
PRBool aFoldCase=PR_TRUE);
|
||||
|
||||
static PRBool ParseValueOrPercent(const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult,
|
||||
nsHTMLUnit aValueUnit);
|
||||
|
||||
static PRBool ParseValueOrPercentOrProportional(const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult,
|
||||
nsHTMLUnit aValueUnit);
|
||||
|
||||
static PRBool ValueOrPercentToString(const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult);
|
||||
|
||||
static PRBool ValueOrPercentOrProportionalToString(const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult);
|
||||
|
||||
static PRBool ParseValue(const nsAReadableString& aString, PRInt32 aMin,
|
||||
nsHTMLValue& aResult, nsHTMLUnit aValueUnit);
|
||||
|
||||
static PRBool ParseValue(const nsAReadableString& aString, PRInt32 aMin,
|
||||
PRInt32 aMax, nsHTMLValue& aResult,
|
||||
nsHTMLUnit aValueUnit);
|
||||
|
||||
static PRBool ParseColor(const nsAReadableString& aString,
|
||||
nsIDocument* aDocument, nsHTMLValue& aResult);
|
||||
|
||||
static PRBool ColorToString(const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult);
|
||||
|
||||
static PRBool ParseCommonAttribute(nsIAtom* aAttribute,
|
||||
const nsAReadableString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
static PRBool ParseAlignValue(const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
PRBool ParseDivAlignValue(const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult) const;
|
||||
PRBool DivAlignValueToString(const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult) const;
|
||||
|
||||
PRBool ParseTableHAlignValue(const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult) const;
|
||||
PRBool TableHAlignValueToString(const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult) const;
|
||||
|
||||
PRBool ParseTableCellHAlignValue(const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult) const;
|
||||
PRBool TableCellHAlignValueToString(const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult) const;
|
||||
|
||||
static PRBool ParseTableVAlignValue(const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
static PRBool TableVAlignValueToString(const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult);
|
||||
|
||||
static PRBool AlignValueToString(const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult);
|
||||
|
||||
static PRBool ParseImageAttribute(nsIAtom* aAttribute,
|
||||
const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
static PRBool ImageAttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult);
|
||||
|
||||
static PRBool ParseFrameborderValue(PRBool aStandardMode,
|
||||
const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
static PRBool FrameborderValueToString(PRBool aStandardMode,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult);
|
||||
|
||||
static PRBool ParseScrollingValue(PRBool aStandardMode,
|
||||
const nsAReadableString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
static PRBool ScrollingValueToString(PRBool aStandardMode,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult);
|
||||
|
||||
nsresult ReparseStyleAttribute(void);
|
||||
nsresult ParseStyleAttribute(const nsAReadableString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
/** Attribute Mapping Helpers
|
||||
*
|
||||
* All attributes that are mapped into style contexts must have a
|
||||
* matched set of mapping function and impact getter
|
||||
*/
|
||||
|
||||
static void MapCommonAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
||||
nsIMutableStyleContext* aStyleContext,
|
||||
nsIPresContext* aPresContext);
|
||||
static PRBool GetCommonMappedAttributesImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint);
|
||||
|
||||
static void MapImageAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
||||
nsIMutableStyleContext* aContext,
|
||||
nsIPresContext* aPresContext);
|
||||
static PRBool GetImageMappedAttributesImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint);
|
||||
|
||||
static void MapImageAlignAttributeInto(const nsIHTMLMappedAttributes* aAttributes,
|
||||
nsIMutableStyleContext* aContext,
|
||||
nsIPresContext* aPresContext);
|
||||
static PRBool GetImageAlignAttributeImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint);
|
||||
|
||||
static void MapImageBorderAttributeInto(const nsIHTMLMappedAttributes* aAttributes,
|
||||
nsIMutableStyleContext* aContext,
|
||||
nsIPresContext* aPresContext,
|
||||
nscolor aBorderColors[4]);
|
||||
static PRBool GetImageBorderAttributeImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint);
|
||||
|
||||
static void MapBackgroundAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
||||
nsIMutableStyleContext* aContext,
|
||||
nsIPresContext* aPresContext);
|
||||
static PRBool GetBackgroundAttributesImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint);
|
||||
|
||||
//XXX These three create a dependency between content and frames
|
||||
static nsresult GetPrimaryFrame(nsIHTMLContent* aContent,
|
||||
nsIFormControlFrame *&aFormControlFrame,
|
||||
PRBool aFlushNotifications=PR_TRUE);
|
||||
static nsresult GetPrimaryPresState(nsIHTMLContent* aContent,
|
||||
nsIStatefulFrame::StateType aStateType,
|
||||
nsIPresState** aPresState);
|
||||
static nsresult GetPresContext(nsIHTMLContent* aContent,
|
||||
nsIPresContext** aPresContext);
|
||||
|
||||
static nsresult GetBaseURL(const nsHTMLValue& aBaseHref,
|
||||
nsIDocument* aDocument,
|
||||
nsIURI** aResult);
|
||||
|
||||
// See if the content object is in a document that has nav-quirks
|
||||
// mode enabled.
|
||||
static PRBool InNavQuirksMode(nsIDocument* aDoc);
|
||||
|
||||
nsIHTMLAttributes* mAttributes;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsGenericHTMLLeafElement : public nsGenericHTMLElement {
|
||||
public:
|
||||
nsGenericHTMLLeafElement();
|
||||
virtual ~nsGenericHTMLLeafElement();
|
||||
|
||||
NS_METHOD CopyInnerTo(nsIContent* aSrcContent,
|
||||
nsGenericHTMLLeafElement* aDest,
|
||||
PRBool aDeep);
|
||||
|
||||
// Remainder of nsIDOMHTMLElement (and nsIDOMNode)
|
||||
NS_METHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
|
||||
NS_METHOD HasChildNodes(PRBool* aHasChildNodes) {
|
||||
*aHasChildNodes = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_METHOD GetFirstChild(nsIDOMNode** aFirstChild) {
|
||||
*aFirstChild = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_METHOD GetLastChild(nsIDOMNode** aLastChild) {
|
||||
*aLastChild = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_METHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
|
||||
nsIDOMNode** aReturn) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_METHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
|
||||
nsIDOMNode** aReturn) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_METHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_METHOD AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Remainder of nsIHTMLContent (and nsIContent)
|
||||
NS_IMETHOD Compact() {
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD CanContainChildren(PRBool& aResult) const {
|
||||
aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD ChildCount(PRInt32& aResult) const {
|
||||
aResult = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const {
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const {
|
||||
aResult = -1;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsGenericHTMLContainerElement : public nsGenericHTMLElement
|
||||
{
|
||||
public:
|
||||
nsGenericHTMLContainerElement();
|
||||
virtual ~nsGenericHTMLContainerElement();
|
||||
|
||||
NS_METHOD CopyInnerTo(nsIContent* aSrcContent,
|
||||
nsGenericHTMLContainerElement* aDest,
|
||||
PRBool aDeep);
|
||||
|
||||
// Remainder of nsIDOMHTMLElement (and nsIDOMNode)
|
||||
NS_METHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
|
||||
NS_METHOD HasChildNodes(PRBool* aHasChildNodes);
|
||||
NS_METHOD GetFirstChild(nsIDOMNode** aFirstChild);
|
||||
NS_METHOD GetLastChild(nsIDOMNode** aLastChild);
|
||||
|
||||
NS_METHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
|
||||
nsIDOMNode** aReturn)
|
||||
{
|
||||
return nsGenericElement::doInsertBefore(aNewChild, aRefChild, aReturn);
|
||||
}
|
||||
NS_METHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
|
||||
nsIDOMNode** aReturn)
|
||||
{
|
||||
return nsGenericElement::doReplaceChild(aNewChild, aOldChild, aReturn);
|
||||
}
|
||||
NS_METHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
|
||||
{
|
||||
return nsGenericElement::doRemoveChild(aOldChild, aReturn);
|
||||
}
|
||||
NS_METHOD AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
|
||||
{
|
||||
return nsGenericElement::doInsertBefore(aNewChild, nsnull, aReturn);
|
||||
}
|
||||
|
||||
// Remainder of nsIHTMLContent (and nsIContent)
|
||||
NS_IMETHOD Compact();
|
||||
NS_IMETHOD CanContainChildren(PRBool& aResult) const;
|
||||
NS_IMETHOD ChildCount(PRInt32& aResult) const;
|
||||
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const;
|
||||
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const;
|
||||
NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify);
|
||||
NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify);
|
||||
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify);
|
||||
NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify);
|
||||
|
||||
nsCheapVoidArray mChildren;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsGenericHTMLContainerFormElement : public nsGenericHTMLContainerElement,
|
||||
public nsIFormControl
|
||||
{
|
||||
public:
|
||||
nsGenericHTMLContainerFormElement();
|
||||
virtual ~nsGenericHTMLContainerFormElement();
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
// nsIFormControl
|
||||
NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm);
|
||||
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
|
||||
NS_IMETHOD Init();
|
||||
|
||||
NS_IMETHOD SetParent(nsIContent *aParent);
|
||||
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep,
|
||||
PRBool aCompileEventHandlers);
|
||||
|
||||
NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
const nsAReadableString& aValue, PRBool aNotify);
|
||||
NS_METHOD SetAttribute(const nsAReadableString& aName,
|
||||
const nsAReadableString& aValue)
|
||||
{
|
||||
return nsGenericHTMLElement::SetAttribute(aName, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
|
||||
|
||||
protected:
|
||||
nsIForm* mForm;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsGenericHTMLLeafFormElement : public nsGenericHTMLLeafElement,
|
||||
public nsIFormControl
|
||||
{
|
||||
public:
|
||||
nsGenericHTMLLeafFormElement();
|
||||
~nsGenericHTMLLeafFormElement();
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
// nsIFormControl
|
||||
NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm);
|
||||
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
|
||||
NS_IMETHOD Init();
|
||||
|
||||
NS_IMETHOD SetParent(nsIContent *aParent);
|
||||
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep,
|
||||
PRBool aCompileEventHandlers);
|
||||
|
||||
NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
const nsAReadableString& aValue, PRBool aNotify);
|
||||
NS_METHOD SetAttribute(const nsAReadableString& aName,
|
||||
const nsAReadableString& aValue)
|
||||
{
|
||||
return nsGenericHTMLElement::SetAttribute(aName, aValue);
|
||||
}
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
|
||||
|
||||
protected:
|
||||
nsIForm* mForm;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#define NS_IMPL_HTMLCONTENT_QI0(_class, _base) \
|
||||
nsresult \
|
||||
_class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtr); \
|
||||
\
|
||||
*aInstancePtr = nsnull; \
|
||||
\
|
||||
nsresult rv; \
|
||||
\
|
||||
rv = _base::QueryInterface(aIID, aInstancePtr); \
|
||||
\
|
||||
if (NS_SUCCEEDED(rv)) \
|
||||
return rv; \
|
||||
\
|
||||
rv = DOMQueryInterface(this, aIID, aInstancePtr); \
|
||||
\
|
||||
if (NS_SUCCEEDED(rv)) \
|
||||
return rv; \
|
||||
\
|
||||
return NS_NOINTERFACE; \
|
||||
}
|
||||
|
||||
#define NS_IMPL_HTMLCONTENT_QI(_class, _base, _if) \
|
||||
nsresult \
|
||||
_class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtr); \
|
||||
\
|
||||
*aInstancePtr = nsnull; \
|
||||
\
|
||||
nsresult rv; \
|
||||
\
|
||||
rv = _base::QueryInterface(aIID, aInstancePtr); \
|
||||
\
|
||||
if (NS_SUCCEEDED(rv)) \
|
||||
return rv; \
|
||||
\
|
||||
rv = DOMQueryInterface(this, aIID, aInstancePtr); \
|
||||
\
|
||||
if (NS_SUCCEEDED(rv)) \
|
||||
return rv; \
|
||||
\
|
||||
nsISupports *inst = nsnull; \
|
||||
\
|
||||
if (aIID.Equals(NS_GET_IID(_if))) { \
|
||||
inst = NS_STATIC_CAST(_if *, this); \
|
||||
} else { \
|
||||
return NS_NOINTERFACE; \
|
||||
} \
|
||||
\
|
||||
NS_ADDREF(inst); \
|
||||
\
|
||||
*aInstancePtr = inst; \
|
||||
\
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
#define NS_IMPL_HTMLCONTENT_QI2(_class, _base, _if1, _if2) \
|
||||
nsresult \
|
||||
_class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtr); \
|
||||
\
|
||||
*aInstancePtr = nsnull; \
|
||||
\
|
||||
nsresult rv; \
|
||||
\
|
||||
rv = _base::QueryInterface(aIID, aInstancePtr); \
|
||||
\
|
||||
if (NS_SUCCEEDED(rv)) \
|
||||
return rv; \
|
||||
\
|
||||
rv = DOMQueryInterface(this, aIID, aInstancePtr); \
|
||||
\
|
||||
if (NS_SUCCEEDED(rv)) \
|
||||
return rv; \
|
||||
\
|
||||
nsISupports *inst = nsnull; \
|
||||
\
|
||||
if (aIID.Equals(NS_GET_IID(_if1))) { \
|
||||
inst = NS_STATIC_CAST(_if1 *, this); \
|
||||
} else if (aIID.Equals(NS_GET_IID(_if2))) { \
|
||||
inst = NS_STATIC_CAST(_if2 *, this); \
|
||||
} else { \
|
||||
return NS_NOINTERFACE; \
|
||||
} \
|
||||
\
|
||||
NS_ADDREF(inst); \
|
||||
\
|
||||
*aInstancePtr = inst; \
|
||||
\
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
#define NS_IMPL_HTMLCONTENT_QI3(_class, _base, _if1, _if2, _if3) \
|
||||
nsresult \
|
||||
_class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtr); \
|
||||
\
|
||||
*aInstancePtr = nsnull; \
|
||||
\
|
||||
nsresult rv; \
|
||||
\
|
||||
rv = _base::QueryInterface(aIID, aInstancePtr); \
|
||||
\
|
||||
if (NS_SUCCEEDED(rv)) \
|
||||
return rv; \
|
||||
\
|
||||
rv = DOMQueryInterface(this, aIID, aInstancePtr); \
|
||||
\
|
||||
if (NS_SUCCEEDED(rv)) \
|
||||
return rv; \
|
||||
\
|
||||
nsISupports *inst = nsnull; \
|
||||
\
|
||||
if (aIID.Equals(NS_GET_IID(_if1))) { \
|
||||
inst = NS_STATIC_CAST(_if1 *, this); \
|
||||
} else if (aIID.Equals(NS_GET_IID(_if2))) { \
|
||||
inst = NS_STATIC_CAST(_if2 *, this); \
|
||||
} else if (aIID.Equals(NS_GET_IID(_if3))) { \
|
||||
inst = NS_STATIC_CAST(_if3 *, this); \
|
||||
} else { \
|
||||
return NS_NOINTERFACE; \
|
||||
} \
|
||||
\
|
||||
NS_ADDREF(inst); \
|
||||
\
|
||||
*aInstancePtr = inst; \
|
||||
\
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
/**
|
||||
* A macro to implement the getter and setter for a given string
|
||||
* valued content property. The method uses the generic SetAttr and
|
||||
* GetAttribute methods.
|
||||
*/
|
||||
#define NS_IMPL_STRING_ATTR(_class, _method, _atom) \
|
||||
NS_IMETHODIMP \
|
||||
_class::Get##_method(nsAWritableString& aValue) \
|
||||
{ \
|
||||
NS_STATIC_CAST(nsIHTMLContent *, this)->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::_atom, aValue); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
NS_IMETHODIMP \
|
||||
_class::Set##_method(const nsAReadableString& aValue) \
|
||||
{ \
|
||||
return NS_STATIC_CAST(nsIHTMLContent *, this)->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::_atom, aValue, PR_TRUE); \
|
||||
}
|
||||
|
||||
/**
|
||||
* A macro to implement the getter and setter for a given boolean
|
||||
* valued content property. The method uses the generic SetAttr and
|
||||
* GetAttribute methods.
|
||||
*/
|
||||
#define NS_IMPL_BOOL_ATTR(_class, _method, _atom) \
|
||||
NS_IMETHODIMP \
|
||||
_class::Get##_method(PRBool* aValue) \
|
||||
{ \
|
||||
nsHTMLValue val; \
|
||||
nsresult rv; \
|
||||
rv = NS_STATIC_CAST(nsIHTMLContent *, this)->GetHTMLAttribute(nsHTMLAtoms::_atom, val); \
|
||||
*aValue = NS_CONTENT_ATTR_NOT_THERE != rv; \
|
||||
return NS_OK; \
|
||||
} \
|
||||
NS_IMETHODIMP \
|
||||
_class::Set##_method(PRBool aValue) \
|
||||
{ \
|
||||
nsHTMLValue empty(eHTMLUnit_Empty); \
|
||||
if (aValue) { \
|
||||
return NS_STATIC_CAST(nsIHTMLContent *, this)->SetHTMLAttribute(nsHTMLAtoms::_atom, empty, PR_TRUE); \
|
||||
} \
|
||||
else { \
|
||||
NS_STATIC_CAST(nsIHTMLContent *, this)->UnsetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::_atom, PR_TRUE); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* A macro to implement the getter and setter for a given integer
|
||||
* valued content property. The method uses the generic SetAttr and
|
||||
* GetAttribute methods.
|
||||
*/
|
||||
#define NS_IMPL_INT_ATTR(_class, _method, _atom) \
|
||||
NS_IMETHODIMP \
|
||||
_class::Get##_method(PRInt32* aValue) \
|
||||
{ \
|
||||
nsHTMLValue value; \
|
||||
*aValue = -1; \
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == \
|
||||
NS_STATIC_CAST(nsIHTMLContent *, this)->GetHTMLAttribute(nsHTMLAtoms::_atom, value)) { \
|
||||
if (value.GetUnit() == eHTMLUnit_Integer) { \
|
||||
*aValue = value.GetIntValue(); \
|
||||
} \
|
||||
} \
|
||||
return NS_OK; \
|
||||
} \
|
||||
NS_IMETHODIMP \
|
||||
_class::Set##_method(PRInt32 aValue) \
|
||||
{ \
|
||||
nsHTMLValue value(aValue, eHTMLUnit_Integer); \
|
||||
return NS_STATIC_CAST(nsIHTMLContent *, this)->SetHTMLAttribute(nsHTMLAtoms::_atom, value, PR_TRUE); \
|
||||
}
|
||||
|
||||
#endif /* nsGenericHTMLElement_h___ */
|
|
@ -1,473 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#include "nsIDOMHTMLElement.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIMutableStyleContext.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsObjectFrame.h"
|
||||
#include "nsLayoutAtoms.h"
|
||||
#include "nsObjectFrame.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMemory.h"
|
||||
#include "xptinfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIPluginInstance.h"
|
||||
#include "nsIScriptablePlugin.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIDOMHTMLEmbedElement.h"
|
||||
|
||||
class nsHTMLEmbedElement : public nsGenericHTMLLeafElement,
|
||||
public nsIDOMHTMLEmbedElement
|
||||
{
|
||||
public:
|
||||
nsHTMLEmbedElement();
|
||||
virtual ~nsHTMLEmbedElement();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode
|
||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::)
|
||||
|
||||
// nsIDOMElement
|
||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::)
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::)
|
||||
|
||||
// nsIDOMHTMLEmbedElement
|
||||
NS_DECL_IDOMHTMLEMBEDELEMENT
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject);
|
||||
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp);
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAReadableString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult) const;
|
||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint) const;
|
||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
||||
nsMapAttributesFunc& aMapFunc) const;
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
||||
|
||||
protected:
|
||||
nsresult GetPluginInstance(nsIPluginInstance** aPluginInstance);
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewHTMLEmbedElement(nsIHTMLContent** aInstancePtrResult,
|
||||
nsINodeInfo *aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
nsHTMLEmbedElement* it = new nsHTMLEmbedElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult rv = it->Init(aNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
delete it;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
||||
NS_ADDREF(*aInstancePtrResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsHTMLEmbedElement::nsHTMLEmbedElement()
|
||||
{
|
||||
}
|
||||
|
||||
nsHTMLEmbedElement::~nsHTMLEmbedElement()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsHTMLEmbedElement, nsGenericElement);
|
||||
NS_IMPL_RELEASE_INHERITED(nsHTMLEmbedElement, nsGenericElement);
|
||||
|
||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLEmbedElement, nsGenericHTMLLeafElement,
|
||||
nsIDOMHTMLEmbedElement);
|
||||
|
||||
|
||||
nsresult
|
||||
nsHTMLEmbedElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aReturn);
|
||||
*aReturn = nsnull;
|
||||
|
||||
nsHTMLEmbedElement* it = new nsHTMLEmbedElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
||||
|
||||
nsresult rv = it->Init(mNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
CopyInnerTo(this, it, aDeep);
|
||||
|
||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
||||
|
||||
NS_ADDREF(*aReturn);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEmbedElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAReadableString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
else if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEmbedElement::AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult) const
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
|
||||
AlignValueToString(aValue, aResult);
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
else if (ImageAttributeToString(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
||||
return nsGenericHTMLLeafElement::AttributeToString(aAttribute, aValue,
|
||||
aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
||||
nsIMutableStyleContext* aContext,
|
||||
nsIPresContext* aPresContext)
|
||||
{
|
||||
nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aContext,
|
||||
aPresContext);
|
||||
nsGenericHTMLElement::MapImageAttributesInto(aAttributes, aContext,
|
||||
aPresContext);
|
||||
nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aContext,
|
||||
aPresContext, nsnull);
|
||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext,
|
||||
aPresContext);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEmbedElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint) const
|
||||
{
|
||||
if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
||||
if (!GetImageMappedAttributesImpact(aAttribute, aHint)) {
|
||||
if (!GetImageAlignAttributeImpact(aAttribute, aHint)) {
|
||||
if (!GetImageBorderAttributeImpact(aAttribute, aHint)) {
|
||||
aHint = NS_STYLE_HINT_CONTENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEmbedElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
||||
nsMapAttributesFunc& aMapFunc) const
|
||||
{
|
||||
aFontMapFunc = nsnull;
|
||||
aMapFunc = &MapAttributesInto;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEmbedElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
||||
{
|
||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// This is cribbed from nsHTMLImageElement::GetImageFrame.
|
||||
|
||||
nsresult
|
||||
nsHTMLEmbedElement::GetPluginInstance(nsIPluginInstance** aPluginInstance)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPluginInstance);
|
||||
*aPluginInstance = nsnull;
|
||||
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
|
||||
if (mDocument) {
|
||||
// Make sure the presentation is up-to-date
|
||||
result = mDocument->FlushPendingNotifications();
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result = GetPresContext(this, getter_AddRefs(context));
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = context->GetShell(getter_AddRefs(shell));
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
nsIFrame* frame;
|
||||
result = shell->GetPrimaryFrameFor(this, &frame);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (frame) {
|
||||
nsCOMPtr<nsIAtom> type;
|
||||
|
||||
frame->GetFrameType(getter_AddRefs(type));
|
||||
|
||||
if (type.get() == nsLayoutAtoms::objectFrame) {
|
||||
// XXX We could have created an interface for this, but Troy
|
||||
// preferred the ugliness of a static cast to the weight of
|
||||
// a new interface.
|
||||
|
||||
nsObjectFrame* objectFrame = NS_STATIC_CAST(nsObjectFrame*, frame);
|
||||
|
||||
return objectFrame->GetPluginInstance(*aPluginInstance);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/*
|
||||
* For plugins, we want to expose both attributes of the plugin tag
|
||||
* and any scriptable methods that the plugin itself exposes. To do
|
||||
* this, we get the plugin object itself (the XPCOM object) and wrap
|
||||
* it as a scriptable object via xpconnect. We then set the original
|
||||
* node element, which exposes the DOM node methods, as the javascript
|
||||
* prototype object of that object. Then we get both sets of methods, and
|
||||
* plugin methods can potentially override DOM methods.
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEmbedElement::GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
if (mDOMSlots && mDOMSlots->mScriptObject)
|
||||
return nsGenericHTMLLeafElement::GetScriptObject(aContext, aScriptObject);
|
||||
|
||||
nsresult rv;
|
||||
*aScriptObject = nsnull;
|
||||
|
||||
// Get the JS object corresponding to this dom node. This will become
|
||||
// the javascript prototype object of the object we eventually reflect to the
|
||||
// DOM.
|
||||
JSObject* elementObject = nsnull;
|
||||
rv = nsGenericHTMLLeafElement::GetScriptObject(aContext,
|
||||
(void**)&elementObject);
|
||||
if (NS_FAILED(rv) || !elementObject)
|
||||
return rv;
|
||||
|
||||
// Flush pending reflows to ensure the plugin is instansiated, assuming
|
||||
// it's visible
|
||||
if (mDocument) {
|
||||
mDocument->FlushPendingNotifications();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPluginInstance> pi;
|
||||
rv = GetPluginInstance(getter_AddRefs(pi));
|
||||
|
||||
// If GetPluginInstance() fails it means there's no frame for this element
|
||||
// yet, in that case we return the script object for the element but we
|
||||
// don't cache it so that the next call can get the correct script object
|
||||
// if the plugin instance is available at the next call.
|
||||
if (NS_FAILED(rv)) {
|
||||
if (mDocument) {
|
||||
// Since we're resetting the script object to null we'll remove the
|
||||
// reference to it so that we won't add the same named reference
|
||||
// again the next time someone requests the script object.
|
||||
aContext->RemoveReference((void *)&mDOMSlots->mScriptObject,
|
||||
mDOMSlots->mScriptObject);
|
||||
}
|
||||
|
||||
SetScriptObject(nsnull);
|
||||
|
||||
*aScriptObject = elementObject;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Check if the plugin object has the nsIScriptablePlugin
|
||||
// interface, describing how to expose it to JavaScript. Given this
|
||||
// interface, use it to get the scriptable peer object (possibly the
|
||||
// plugin object itself) and the scriptable interface to expose it
|
||||
// with
|
||||
nsIID scriptableInterface;
|
||||
nsCOMPtr<nsISupports> scriptablePeer;
|
||||
if (NS_SUCCEEDED(rv) && pi) {
|
||||
nsCOMPtr<nsIScriptablePlugin> spi(do_QueryInterface(pi, &rv));
|
||||
if (NS_SUCCEEDED(rv) && spi) {
|
||||
nsIID *scriptableInterfacePtr = nsnull;
|
||||
rv = spi->GetScriptableInterface(&scriptableInterfacePtr);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && scriptableInterfacePtr) {
|
||||
rv = spi->GetScriptablePeer(getter_AddRefs(scriptablePeer));
|
||||
|
||||
scriptableInterface = *scriptableInterfacePtr;
|
||||
|
||||
nsMemory::Free(scriptableInterfacePtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv) || !scriptablePeer) {
|
||||
// Fall back to returning the element object.
|
||||
*aScriptObject = elementObject;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Wrap it.
|
||||
JSObject* interfaceObject; // XPConnect-wrapped peer object, when we get it.
|
||||
JSContext *cx = (JSContext *)aContext->GetNativeContext();
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
if (cx && xpc) {
|
||||
JSObject* parentObject = JS_GetParent(cx, elementObject);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
if (NS_SUCCEEDED(xpc->WrapNative(cx, parentObject,
|
||||
scriptablePeer, scriptableInterface,
|
||||
getter_AddRefs(holder))) && holder &&
|
||||
NS_SUCCEEDED(holder->GetJSObject(&interfaceObject)) && interfaceObject) {
|
||||
*aScriptObject = interfaceObject;
|
||||
}
|
||||
}
|
||||
|
||||
// If we got an xpconnect-wrapped plugin object, set its' prototype to the
|
||||
// element object.
|
||||
if (!*aScriptObject || !JS_SetPrototype(cx, interfaceObject,
|
||||
elementObject)) {
|
||||
*aScriptObject = elementObject; // fall back
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Cache it.
|
||||
SetScriptObject(*aScriptObject);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Allow access to arbitrary XPCOM interfaces supported by the plugin
|
||||
// via a pluginObject.nsISomeInterface notation.
|
||||
PRBool
|
||||
nsHTMLEmbedElement::GetProperty(JSContext *aContext, JSObject *aObj,
|
||||
jsval aID, jsval *aVp)
|
||||
{
|
||||
if (JSVAL_IS_STRING(aID)) {
|
||||
PRBool retval = PR_FALSE;
|
||||
char* cString = JS_GetStringBytes(JS_ValueToString(aContext, aID));
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iim =
|
||||
dont_AddRef(XPTI_GetInterfaceInfoManager());
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
|
||||
if (iim && xpc) {
|
||||
nsIID* iid;
|
||||
if (NS_SUCCEEDED(iim->GetIIDForName(cString, &iid)) && iid) {
|
||||
nsCOMPtr<nsIPluginInstance> pi;
|
||||
if (NS_SUCCEEDED(GetPluginInstance(getter_AddRefs(pi))) && pi) {
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
JSObject* ifaceObj;
|
||||
|
||||
if (NS_SUCCEEDED(xpc->WrapNative(aContext, aObj, pi, *iid,
|
||||
getter_AddRefs(holder))) && holder &&
|
||||
NS_SUCCEEDED(holder->GetJSObject(&ifaceObj)) && ifaceObj) {
|
||||
*aVp = OBJECT_TO_JSVAL(ifaceObj);
|
||||
retval = PR_TRUE;
|
||||
}
|
||||
}
|
||||
nsMemory::Free(iid);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLLeafElement::GetProperty(aContext, aObj, aID, aVp);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Implement nsIDOMHTMLEmbedElement interface
|
||||
NS_IMPL_STRING_ATTR(nsHTMLEmbedElement, Align, align)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLEmbedElement, Height, height)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLEmbedElement, Width, width)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLEmbedElement, Name, name)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLEmbedElement, Type, type)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLEmbedElement, Src, src)
|
||||
|
|
@ -1,268 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#include "nsIDOMHTMLObjectElement.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIMutableStyleContext.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsDOMError.h"
|
||||
|
||||
|
||||
class nsHTMLObjectElement : public nsGenericHTMLContainerElement,
|
||||
public nsIDOMHTMLObjectElement
|
||||
{
|
||||
public:
|
||||
nsHTMLObjectElement();
|
||||
virtual ~nsHTMLObjectElement();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode
|
||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
||||
|
||||
// nsIDOMElement
|
||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
||||
|
||||
// nsIDOMHTMLObjectElement
|
||||
NS_DECL_IDOMHTMLOBJECTELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAReadableString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult) const;
|
||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
||||
nsMapAttributesFunc& aMapFunc) const;
|
||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint) const;
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewHTMLObjectElement(nsIHTMLContent** aInstancePtrResult,
|
||||
nsINodeInfo *aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
nsHTMLObjectElement* it = new nsHTMLObjectElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult rv = it->Init(aNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
delete it;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
||||
NS_ADDREF(*aInstancePtrResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsHTMLObjectElement::nsHTMLObjectElement()
|
||||
{
|
||||
}
|
||||
|
||||
nsHTMLObjectElement::~nsHTMLObjectElement()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsHTMLObjectElement, nsGenericElement)
|
||||
NS_IMPL_RELEASE_INHERITED(nsHTMLObjectElement, nsGenericElement)
|
||||
|
||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLObjectElement, nsGenericHTMLContainerElement,
|
||||
nsIDOMHTMLObjectElement);
|
||||
|
||||
|
||||
nsresult
|
||||
nsHTMLObjectElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aReturn);
|
||||
*aReturn = nsnull;
|
||||
|
||||
nsHTMLObjectElement* it = new nsHTMLObjectElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
||||
|
||||
nsresult rv = it->Init(mNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
CopyInnerTo(this, it, aDeep);
|
||||
|
||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
||||
|
||||
NS_ADDREF(*aReturn);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
||||
{
|
||||
*aForm = nsnull;/* XXX */
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Code, code)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Align, align)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Archive, archive)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Border, border)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, CodeBase, codebase)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, CodeType, codetype)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Data, data)
|
||||
NS_IMPL_BOOL_ATTR(nsHTMLObjectElement, Declare, declare)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Height, height)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Hspace, hspace)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Name, name)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Standby, standby)
|
||||
NS_IMPL_INT_ATTR(nsHTMLObjectElement, TabIndex, tabindex)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Type, type)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, UseMap, usemap)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Vspace, vspace)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Width, width)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::GetContentDocument(nsIDOMDocument** aContentDocument)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aContentDocument);
|
||||
*aContentDocument = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::SetContentDocument(nsIDOMDocument* aContentDocument)
|
||||
{
|
||||
return NS_ERROR_DOM_INVALID_MODIFICATION_ERR;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAReadableString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
else if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAWritableString& aResult) const
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
|
||||
AlignValueToString(aValue, aResult);
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
else if (ImageAttributeToString(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
||||
return nsGenericHTMLContainerElement::AttributeToString(aAttribute, aValue,
|
||||
aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
||||
nsIMutableStyleContext* aContext,
|
||||
nsIPresContext* aPresContext)
|
||||
{
|
||||
nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aContext,
|
||||
aPresContext);
|
||||
nsGenericHTMLElement::MapImageAttributesInto(aAttributes, aContext,
|
||||
aPresContext);
|
||||
nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aContext,
|
||||
aPresContext, nsnull);
|
||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext,
|
||||
aPresContext);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
||||
PRInt32& aHint) const
|
||||
{
|
||||
if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
||||
if (!GetImageBorderAttributeImpact(aAttribute, aHint)) {
|
||||
if (!GetImageMappedAttributesImpact(aAttribute, aHint)) {
|
||||
if (!GetImageAlignAttributeImpact(aAttribute, aHint)) {
|
||||
aHint = NS_STYLE_HINT_CONTENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
||||
nsMapAttributesFunc& aMapFunc) const
|
||||
{
|
||||
aFontMapFunc = nsnull;
|
||||
aMapFunc = &MapAttributesInto;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
||||
{
|
||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
Загрузка…
Ссылка в новой задаче