1999-07-07 06:33:17 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* 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/
|
1999-07-07 06:33:17 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* 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.
|
1999-07-07 06:33:17 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 06:40:37 +03:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1999-07-07 06:33:17 +04:00
|
|
|
*/
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsViewsCID.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
2001-01-18 01:16:09 +03:00
|
|
|
#include "nsIDOMKeyListener.h"
|
1999-07-07 06:33:17 +04:00
|
|
|
#include "nsIPluginHost.h"
|
|
|
|
#include "nsplugin.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURL.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-07-07 06:33:17 +04:00
|
|
|
#include "nsIPluginInstanceOwner.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIJVMPluginTagInfo.h"
|
|
|
|
#include "nsIWebShell.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIEventListener.h"
|
2000-08-24 23:49:08 +04:00
|
|
|
#include "nsIStringStream.h" // for NS_NewCharInputStream
|
1999-07-07 06:33:17 +04:00
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsITimerCallback.h"
|
1999-09-14 01:26:05 +04:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-12-18 05:09:29 +03:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2000-03-11 03:41:57 +03:00
|
|
|
#include "nsIDocShellTreeOwner.h"
|
|
|
|
#include "nsIWebBrowserChrome.h"
|
2000-01-05 04:18:38 +03:00
|
|
|
#include "nsIDOMElement.h"
|
2000-05-25 17:32:42 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2000-10-18 03:13:30 +04:00
|
|
|
#include "nsIDOMMouseListener.h"
|
|
|
|
#include "nsIDOMEventReceiver.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2000-10-19 05:37:53 +04:00
|
|
|
#include "nsIDocumentEncoder.h"
|
|
|
|
#include "nsRange.h"
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// XXX For temporary paint code
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
|
|
|
|
//~~~ For image mime types
|
2000-07-10 11:13:31 +04:00
|
|
|
#include "nsMimeTypes.h"
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2000-04-15 02:48:30 +04:00
|
|
|
#include "nsObjectFrame.h"
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-18 01:16:09 +03:00
|
|
|
/* X headers suck */
|
|
|
|
#ifdef KeyPress
|
|
|
|
#undef KeyPress
|
|
|
|
#endif
|
2000-10-18 03:13:30 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
class nsPluginInstanceOwner : public nsIPluginInstanceOwner,
|
|
|
|
public nsIPluginTagInfo2,
|
|
|
|
public nsIJVMPluginTagInfo,
|
|
|
|
public nsIEventListener,
|
2000-10-18 03:13:30 +04:00
|
|
|
public nsITimerCallback,
|
2001-01-17 23:04:09 +03:00
|
|
|
public nsIDOMMouseListener,
|
|
|
|
public nsIDOMKeyListener
|
2000-10-18 03:13:30 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsPluginInstanceOwner();
|
|
|
|
virtual ~nsPluginInstanceOwner();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
//nsIPluginInstanceOwner interface
|
|
|
|
|
|
|
|
NS_IMETHOD SetInstance(nsIPluginInstance *aInstance);
|
|
|
|
|
|
|
|
NS_IMETHOD GetInstance(nsIPluginInstance *&aInstance);
|
|
|
|
|
|
|
|
NS_IMETHOD GetWindow(nsPluginWindow *&aWindow);
|
|
|
|
|
|
|
|
NS_IMETHOD GetMode(nsPluginMode *aMode);
|
|
|
|
|
|
|
|
NS_IMETHOD CreateWidget(void);
|
|
|
|
|
2000-08-24 23:49:08 +04:00
|
|
|
NS_IMETHOD GetURL(const char *aURL, const char *aTarget, void *aPostData,
|
2000-09-05 23:03:56 +04:00
|
|
|
PRUint32 aPostDataLen, void *aHeadersData,
|
|
|
|
PRUint32 aHeadersDataLen);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
NS_IMETHOD ShowStatus(const char *aStatusMsg);
|
|
|
|
|
|
|
|
NS_IMETHOD GetDocument(nsIDocument* *aDocument);
|
|
|
|
|
|
|
|
//nsIPluginTagInfo interface
|
|
|
|
|
|
|
|
NS_IMETHOD GetAttributes(PRUint16& n, const char*const*& names,
|
|
|
|
const char*const*& values);
|
|
|
|
|
|
|
|
NS_IMETHOD GetAttribute(const char* name, const char* *result);
|
|
|
|
|
2000-01-05 04:18:38 +03:00
|
|
|
NS_IMETHOD GetDOMElement(nsIDOMElement* *result);
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
//nsIPluginTagInfo2 interface
|
|
|
|
|
|
|
|
NS_IMETHOD GetTagType(nsPluginTagType *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetTagText(const char* *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetParameters(PRUint16& n, const char*const*& names, const char*const*& values);
|
|
|
|
|
|
|
|
NS_IMETHOD GetParameter(const char* name, const char* *result);
|
|
|
|
|
1999-08-03 06:51:39 +04:00
|
|
|
NS_IMETHOD GetDocumentBase(const char* *result);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
NS_IMETHOD GetDocumentEncoding(const char* *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetAlignment(const char* *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetWidth(PRUint32 *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetHeight(PRUint32 *result);
|
2000-05-23 01:36:35 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_IMETHOD GetBorderVertSpace(PRUint32 *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetBorderHorizSpace(PRUint32 *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetUniqueID(PRUint32 *result);
|
|
|
|
|
|
|
|
//nsIJVMPluginTagInfo interface
|
|
|
|
|
|
|
|
NS_IMETHOD GetCode(const char* *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetCodeBase(const char* *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetArchive(const char* *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetName(const char* *result);
|
|
|
|
|
|
|
|
NS_IMETHOD GetMayScript(PRBool *result);
|
2000-10-18 03:13:30 +04:00
|
|
|
|
|
|
|
/** nsIDOMMouseListener interfaces
|
|
|
|
* @see nsIDOMMouseListener
|
|
|
|
*/
|
|
|
|
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
|
|
|
|
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
|
|
|
|
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent);
|
|
|
|
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent);
|
|
|
|
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
|
|
|
|
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
|
|
|
|
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
|
|
|
/* END interfaces from nsIDOMMouseListener*/
|
2001-01-17 23:04:09 +03:00
|
|
|
|
|
|
|
// nsIDOMKeyListener interfaces
|
|
|
|
|
|
|
|
virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent);
|
|
|
|
virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent);
|
|
|
|
virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent);
|
|
|
|
// end nsIDOMKeyListener interfaces
|
2000-10-18 03:13:30 +04:00
|
|
|
|
|
|
|
nsresult Destroy();
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
//nsIEventListener interface
|
|
|
|
nsEventStatus ProcessEvent(const nsGUIEvent & anEvent);
|
|
|
|
|
|
|
|
void Paint(const nsRect& aDirtyRect, PRUint32 ndc = nsnull);
|
|
|
|
|
|
|
|
// nsITimerCallback interface
|
2000-01-22 00:56:09 +03:00
|
|
|
NS_IMETHOD_(void) Notify(nsITimer *timer);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
void CancelTimer();
|
|
|
|
|
|
|
|
//locals
|
|
|
|
|
|
|
|
NS_IMETHOD Init(nsIPresContext *aPresContext, nsObjectFrame *aFrame);
|
2000-05-23 01:36:35 +04:00
|
|
|
|
|
|
|
nsresult GetContainingBlock(nsIFrame *aFrame, nsIFrame **aContainingBlock);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsPluginPort* GetPluginPort();
|
|
|
|
void ReleasePluginPort(nsPluginPort * pluginPort);//~~~
|
|
|
|
|
|
|
|
void SetPluginHost(nsIPluginHost* aHost);
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
#ifdef XP_MAC
|
|
|
|
void FixUpPluginWindow();
|
|
|
|
#endif
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
private:
|
|
|
|
nsPluginWindow mPluginWindow;
|
|
|
|
nsIPluginInstance *mInstance;
|
|
|
|
nsObjectFrame *mOwner;
|
|
|
|
PRInt32 mNumAttrs;
|
|
|
|
char **mAttrNames;
|
|
|
|
char **mAttrVals;
|
|
|
|
PRInt32 mNumParams;
|
|
|
|
char **mParamNames;
|
|
|
|
char **mParamVals;
|
1999-08-03 06:51:39 +04:00
|
|
|
char *mDocumentBase;
|
2000-10-19 05:37:53 +04:00
|
|
|
char *mTagText;
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIWidget *mWidget;
|
|
|
|
nsIPresContext *mContext;
|
2000-05-17 06:49:35 +04:00
|
|
|
nsCOMPtr<nsITimer> mPluginTimer;
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIPluginHost *mPluginHost;
|
2001-01-17 23:04:09 +03:00
|
|
|
|
|
|
|
nsresult DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent);
|
1999-07-07 06:33:17 +04:00
|
|
|
};
|
|
|
|
|
2000-09-29 03:29:26 +04:00
|
|
|
// Mac specific code to fix up port position and clip during paint
|
|
|
|
#ifdef XP_MAC
|
2000-10-18 01:45:39 +04:00
|
|
|
// get the absolute widget position and clip
|
2000-09-29 03:29:26 +04:00
|
|
|
static void GetWidgetPosAndClip(nsIWidget* aWidget,nscoord& aAbsX, nscoord& aAbsY, nsRect& aClipRect);
|
2000-10-18 01:45:39 +04:00
|
|
|
static void ConvertTwipsToPixels(nsIPresContext& aPresContext, nsRect& aTwipsRect, nsRect& aPixelRect);
|
|
|
|
// convert relative coordinates to absolute
|
|
|
|
static void ConvertRelativeToWindowAbsolute(nsIFrame* aFrame, nsIPresContext* aPresContext, nsPoint& aRel, nsPoint& aAbs, nsIWidget *&aContainerWidget);
|
2001-01-12 02:56:35 +03:00
|
|
|
#endif // XP_MAC
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsObjectFrame::~nsObjectFrame()
|
|
|
|
{
|
|
|
|
// beard: stop the timer explicitly to reduce reference count.
|
2000-10-18 03:13:30 +04:00
|
|
|
if (nsnull != mInstanceOwner) {
|
1999-07-07 06:33:17 +04:00
|
|
|
mInstanceOwner->CancelTimer();
|
2000-10-18 03:13:30 +04:00
|
|
|
mInstanceOwner->Destroy();
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mWidget);
|
|
|
|
NS_IF_RELEASE(mInstanceOwner);
|
|
|
|
NS_IF_RELEASE(mFullURL);
|
2000-10-18 03:13:30 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
|
|
|
|
static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID);
|
|
|
|
static NS_DEFINE_IID(kCAppShellCID, NS_APPSHELL_CID);
|
2000-04-13 06:53:18 +04:00
|
|
|
static NS_DEFINE_IID(kCPluginManagerCID, NS_PLUGINMANAGER_CID);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsObjectFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//~~~
|
|
|
|
#define IMAGE_EXT_GIF "gif"
|
|
|
|
#define IMAGE_EXT_JPG "jpg"
|
|
|
|
#define IMAGE_EXT_PNG "png"
|
|
|
|
#define IMAGE_EXT_XBM "xbm"
|
|
|
|
|
2000-10-18 01:45:39 +04:00
|
|
|
// #define DO_DIRTY_INTERSECT 1 // enable dirty rect intersection during paint
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
void nsObjectFrame::IsSupportedImage(nsIContent* aContent, PRBool* aImage)
|
|
|
|
{
|
|
|
|
*aImage = PR_FALSE;
|
|
|
|
|
|
|
|
if(aContent == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoString type;
|
|
|
|
nsresult rv = aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, type);
|
|
|
|
if((rv == NS_CONTENT_ATTR_HAS_VALUE) && (type.Length() > 0))
|
|
|
|
{
|
|
|
|
// should be really call to imlib
|
|
|
|
if(type.EqualsIgnoreCase(IMAGE_GIF) ||
|
|
|
|
type.EqualsIgnoreCase(IMAGE_JPG) ||
|
|
|
|
type.EqualsIgnoreCase(IMAGE_PJPG)||
|
|
|
|
type.EqualsIgnoreCase(IMAGE_PNG) ||
|
|
|
|
type.EqualsIgnoreCase(IMAGE_PPM) ||
|
|
|
|
type.EqualsIgnoreCase(IMAGE_XBM) ||
|
|
|
|
type.EqualsIgnoreCase(IMAGE_XBM2)||
|
|
|
|
type.EqualsIgnoreCase(IMAGE_XBM3))
|
|
|
|
{
|
|
|
|
*aImage = PR_TRUE;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString data;
|
|
|
|
rv = aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::data, data);
|
|
|
|
if((rv == NS_CONTENT_ATTR_HAS_VALUE) && (data.Length() > 0))
|
|
|
|
{
|
|
|
|
// should be really call to imlib
|
|
|
|
nsAutoString ext;
|
|
|
|
|
|
|
|
PRInt32 iLastCharOffset = data.Length() - 1;
|
1999-07-19 07:29:56 +04:00
|
|
|
PRInt32 iPointOffset = data.RFindChar('.');
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if(iPointOffset != -1)
|
|
|
|
{
|
|
|
|
data.Mid(ext, iPointOffset + 1, iLastCharOffset - iPointOffset);
|
|
|
|
|
|
|
|
if(ext.EqualsIgnoreCase(IMAGE_EXT_GIF) ||
|
|
|
|
ext.EqualsIgnoreCase(IMAGE_EXT_JPG) ||
|
|
|
|
ext.EqualsIgnoreCase(IMAGE_EXT_PNG) ||
|
|
|
|
ext.EqualsIgnoreCase(IMAGE_EXT_XBM))
|
|
|
|
{
|
|
|
|
*aImage = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHODIMP nsObjectFrame::SetInitialChildList(nsIPresContext* aPresContext,
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
|
|
|
// we don't want to call this if it is already set (image)
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if(mFrames.IsEmpty())
|
|
|
|
rv = nsObjectFrameSuper::SetInitialChildList(aPresContext, aListName, aChildList);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsObjectFrame::Init(nsIPresContext* aPresContext,
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsObjectFrameSuper::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
|
|
|
|
|
|
|
if(rv != NS_OK)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
PRBool bImage = PR_FALSE;
|
|
|
|
|
|
|
|
//Ideally should be call to imlib, when it is available
|
|
|
|
// and even move this code to Reflow when the stream starts to come
|
|
|
|
IsSupportedImage(aContent, &bImage);
|
|
|
|
|
|
|
|
if(bImage)
|
|
|
|
{
|
1999-12-05 02:49:50 +03:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIFrame * aNewFrame = nsnull;
|
1999-12-05 02:49:50 +03:00
|
|
|
rv = NS_NewImageFrame(shell, &aNewFrame);
|
1999-07-07 06:33:17 +04:00
|
|
|
if(rv != NS_OK)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = aNewFrame->Init(aPresContext, aContent, this, aContext, aPrevInFlow);
|
|
|
|
if(rv == NS_OK)
|
|
|
|
{
|
2000-08-12 23:44:11 +04:00
|
|
|
nsHTMLContainerFrame::CreateViewForFrame(aPresContext, aNewFrame, aContext, nsnull, PR_FALSE);
|
1999-07-07 06:33:17 +04:00
|
|
|
mFrames.AppendFrame(this, aNewFrame);
|
|
|
|
}
|
|
|
|
else
|
1999-07-22 06:24:52 +04:00
|
|
|
aNewFrame->Destroy(aPresContext);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-02-25 04:02:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::Destroy(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
// we need to finish with the plugin before native window is destroyed
|
|
|
|
// doing this in the destructor is too late.
|
|
|
|
if(mInstanceOwner != nsnull)
|
|
|
|
{
|
|
|
|
nsIPluginInstance *inst;
|
2000-02-26 03:14:16 +03:00
|
|
|
if(NS_OK == mInstanceOwner->GetInstance(inst))
|
2000-02-25 04:02:53 +03:00
|
|
|
{
|
2000-09-14 12:22:31 +04:00
|
|
|
PRBool doCache = PR_TRUE;
|
|
|
|
PRBool doCallSetWindowAfterDestroy = PR_FALSE;
|
|
|
|
|
|
|
|
// first, determine if the plugin wants to be cached
|
|
|
|
inst->GetValue(nsPluginInstanceVariable_DoCacheBool,
|
|
|
|
(void *) &doCache);
|
|
|
|
if (!doCache) {
|
|
|
|
// then determine if the plugin wants Destroy to be called after
|
|
|
|
// Set Window. This is for bug 50547.
|
|
|
|
inst->GetValue(nsPluginInstanceVariable_CallSetWindowAfterDestroyBool,
|
|
|
|
(void *) &doCallSetWindowAfterDestroy);
|
|
|
|
if (doCallSetWindowAfterDestroy) {
|
|
|
|
inst->Stop();
|
|
|
|
inst->Destroy();
|
|
|
|
inst->SetWindow(nsnull);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
inst->SetWindow(nsnull);
|
|
|
|
inst->Stop();
|
|
|
|
inst->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
inst->SetWindow(nsnull);
|
|
|
|
inst->Stop();
|
|
|
|
}
|
2000-04-27 01:47:45 +04:00
|
|
|
NS_RELEASE(inst);
|
2000-02-25 04:02:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsObjectFrameSuper::Destroy(aPresContext);
|
|
|
|
}
|
|
|
|
|
1999-09-14 01:26:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::objectFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("ObjectFrame", aResult);
|
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsresult
|
1999-10-26 08:44:41 +04:00
|
|
|
nsObjectFrame::CreateWidget(nsIPresContext* aPresContext,
|
|
|
|
nscoord aWidth,
|
|
|
|
nscoord aHeight,
|
|
|
|
PRBool aViewOnly)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2000-07-20 03:46:43 +04:00
|
|
|
#ifndef XP_MAC
|
|
|
|
// Do not create a widget if 'hidden' (except for Mac, where we
|
|
|
|
// always create a widget...)
|
|
|
|
if (IsHidden())
|
|
|
|
return NS_OK;
|
|
|
|
#endif
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIView* view;
|
|
|
|
|
|
|
|
// Create our view and widget
|
|
|
|
|
|
|
|
nsresult result =
|
2001-01-04 23:44:42 +03:00
|
|
|
nsComponentManager::CreateInstance(kViewCID, nsnull, NS_GET_IID(nsIView),
|
1999-07-07 06:33:17 +04:00
|
|
|
(void **)&view);
|
|
|
|
if (NS_OK != result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
nsIViewManager *viewMan; // need to release
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
nsRect boundBox(0, 0, aWidth, aHeight);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsIFrame* parWithView;
|
|
|
|
nsIView *parView;
|
|
|
|
|
1999-10-26 08:44:41 +04:00
|
|
|
GetParentWithView(aPresContext, &parWithView);
|
|
|
|
parWithView->GetView(aPresContext, &parView);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if (NS_OK == parView->GetViewManager(viewMan))
|
|
|
|
{
|
1999-11-24 09:03:41 +03:00
|
|
|
// nsWidgetInitData* initData = GetWidgetInitData(aPresContext); // needs to be deleted
|
1999-07-07 06:33:17 +04:00
|
|
|
// initialize the view as hidden since we don't know the (x,y) until Paint
|
2000-04-25 08:43:11 +04:00
|
|
|
result = view->Init(viewMan, boundBox, parView, nsViewVisibility_kHide);
|
1999-07-07 06:33:17 +04:00
|
|
|
// if (nsnull != initData) {
|
|
|
|
// delete(initData);
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (NS_OK != result) {
|
|
|
|
result = NS_OK; //XXX why OK? MMP
|
|
|
|
goto exit; //XXX sue me. MMP
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// set the content's widget, so it can get content modified by the widget
|
|
|
|
nsIWidget *widget;
|
|
|
|
result = GetWidget(view, &widget);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
nsInput* content = (nsInput *)mContent; // change this cast to QueryInterface
|
|
|
|
content->SetWidget(widget);
|
|
|
|
NS_IF_RELEASE(widget);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(0, "could not get widget");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-09-29 03:29:26 +04:00
|
|
|
// Turn off double buffering on the Mac. This depends on bug 49743 and partially
|
|
|
|
// fixes 32327, 19931 amd 51787
|
|
|
|
#ifdef XP_MAC
|
|
|
|
viewMan->AllowDoubleBuffering(PR_FALSE);
|
|
|
|
#endif
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
viewMan->InsertChild(parView, view, 0);
|
|
|
|
|
|
|
|
result = view->CreateWidget(kWidgetCID);
|
|
|
|
|
|
|
|
if (NS_OK != result) {
|
|
|
|
result = NS_OK; //XXX why OK? MMP
|
|
|
|
goto exit; //XXX sue me. MMP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
//this is ugly. it was ripped off from didreflow(). MMP
|
|
|
|
// Position and size view relative to its parent, not relative to our
|
|
|
|
// parent frame (our parent frame may not have a view).
|
|
|
|
|
|
|
|
nsIView* parentWithView;
|
|
|
|
nsPoint origin;
|
|
|
|
view->SetVisibility(nsViewVisibility_kShow);
|
1999-10-26 08:44:41 +04:00
|
|
|
GetOffsetFromView(aPresContext, origin, &parentWithView);
|
1999-07-07 06:33:17 +04:00
|
|
|
viewMan->ResizeView(view, mRect.width, mRect.height);
|
|
|
|
viewMan->MoveViewTo(view, origin.x, origin.y);
|
|
|
|
}
|
|
|
|
|
1999-10-26 08:44:41 +04:00
|
|
|
SetView(aPresContext, view);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
exit:
|
|
|
|
NS_IF_RELEASE(viewMan);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-08-08 08:45:03 +04:00
|
|
|
#define EMBED_DEF_WIDTH 240
|
|
|
|
#define EMBED_DEF_HEIGHT 200
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aMetrics)
|
|
|
|
{
|
|
|
|
// Determine our size stylistically
|
|
|
|
PRBool haveWidth = PR_FALSE;
|
|
|
|
PRBool haveHeight = PR_FALSE;
|
2000-08-08 08:45:03 +04:00
|
|
|
PRUint32 width = EMBED_DEF_WIDTH;
|
|
|
|
PRUint32 height = EMBED_DEF_HEIGHT;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
1999-07-20 07:41:03 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) {
|
|
|
|
aMetrics.width = aReflowState.mComputedWidth;
|
1999-07-07 06:33:17 +04:00
|
|
|
haveWidth = PR_TRUE;
|
|
|
|
}
|
1999-07-20 07:41:03 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedHeight) {
|
|
|
|
aMetrics.height = aReflowState.mComputedHeight;
|
1999-07-07 06:33:17 +04:00
|
|
|
haveHeight = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-07-20 03:46:43 +04:00
|
|
|
if (IsHidden()) {
|
|
|
|
// If we're hidden, then width and height are zero.
|
|
|
|
haveWidth = haveHeight = PR_TRUE;
|
|
|
|
aMetrics.width = aMetrics.height = 0;
|
|
|
|
}
|
|
|
|
else if(mInstanceOwner != nsnull)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2000-07-20 03:46:43 +04:00
|
|
|
// the first time, mInstanceOwner will be null, so we a temporary default
|
|
|
|
|
2000-08-08 08:45:03 +04:00
|
|
|
// if no width and height attributes specified use embed_def_*.
|
1999-07-27 05:35:30 +04:00
|
|
|
if(NS_OK != mInstanceOwner->GetWidth(&width))
|
|
|
|
{
|
2000-08-08 08:45:03 +04:00
|
|
|
width = EMBED_DEF_WIDTH;
|
2001-01-12 02:56:35 +03:00
|
|
|
haveWidth = PR_FALSE;
|
1999-07-27 05:35:30 +04:00
|
|
|
}
|
|
|
|
else
|
2001-01-12 02:56:35 +03:00
|
|
|
haveWidth = PR_FALSE;
|
1999-07-27 05:35:30 +04:00
|
|
|
|
|
|
|
if(NS_OK != mInstanceOwner->GetHeight(&height))
|
|
|
|
{
|
2000-08-08 08:45:03 +04:00
|
|
|
height = EMBED_DEF_HEIGHT;
|
2001-01-12 02:56:35 +03:00
|
|
|
haveHeight = PR_FALSE;
|
1999-07-27 05:35:30 +04:00
|
|
|
}
|
|
|
|
else
|
2001-01-12 02:56:35 +03:00
|
|
|
haveHeight = PR_FALSE;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// XXX Temporary auto-sizing logic
|
|
|
|
if (!haveWidth) {
|
|
|
|
if (haveHeight) {
|
|
|
|
aMetrics.width = aMetrics.height;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
|
|
aMetrics.width = NSIntPixelsToTwips(width, p2t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!haveHeight) {
|
|
|
|
if (haveWidth) {
|
|
|
|
aMetrics.height = aMetrics.width;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
|
|
aMetrics.height = NSIntPixelsToTwips(height, p2t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aMetrics.ascent = aMetrics.height;
|
|
|
|
aMetrics.descent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define JAVA_CLASS_ID "8AD9C840-044E-11D1-B3E9-00805F499D93"
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsObjectFrame::Reflow(nsIPresContext* aPresContext,
|
1999-07-07 06:33:17 +04:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2000-04-21 18:59:47 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsObjectFrame", aReflowState.reason);
|
1999-07-07 06:33:17 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
char* mimeType = nsnull;
|
|
|
|
PRUint32 buflen;
|
|
|
|
|
|
|
|
// Get our desired size
|
1999-11-24 09:03:41 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// could be an image
|
|
|
|
nsIFrame * child = mFrames.FirstChild();
|
2000-07-12 03:10:29 +04:00
|
|
|
if(child != nsnull)
|
2001-01-12 02:56:35 +03:00
|
|
|
return HandleImage(aPresContext, aMetrics, aReflowState, aStatus, child);
|
2000-07-12 03:10:29 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
// if mInstance is null, we need to determine what kind of object we are and instantiate ourselves
|
|
|
|
if(!mInstanceOwner)
|
|
|
|
{
|
|
|
|
// XXX - do we need to create this for widgets as well?
|
|
|
|
mInstanceOwner = new nsPluginInstanceOwner();
|
|
|
|
if(!mInstanceOwner)
|
2001-01-12 02:56:35 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
NS_ADDREF(mInstanceOwner);
|
1999-11-24 09:03:41 +03:00
|
|
|
mInstanceOwner->Init(aPresContext, this);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
1999-11-14 13:22:00 +03:00
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
nsCOMPtr<nsIPluginHost> pluginHost;
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIURI* baseURL = nsnull;
|
|
|
|
nsIURI* fullURL = nsnull;
|
|
|
|
|
|
|
|
nsAutoString classid;
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
|
|
|
|
// if we have a clsid, we're either an internal widget, an ActiveX control, or an applet
|
|
|
|
mContent->GetNameSpaceID(nameSpaceID);
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(nameSpaceID, nsHTMLAtoms::classid, classid))
|
|
|
|
{
|
|
|
|
nsCID widgetCID;
|
2001-01-12 02:56:35 +03:00
|
|
|
|
|
|
|
PRBool bJavaObject = PR_FALSE;
|
|
|
|
PRBool bJavaPluginClsid = PR_FALSE;
|
|
|
|
|
|
|
|
if (classid.Find("java:") != -1)
|
|
|
|
{
|
|
|
|
classid.Cut(0, 5); // Strip off the "java:". What's left is the class file.
|
|
|
|
bJavaObject = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (classid.Find("clsid:") != -1)
|
|
|
|
{
|
2000-05-23 01:36:35 +04:00
|
|
|
classid.Cut(0, 6); // Strip off the "clsid:". What's left is the class ID.
|
2001-01-12 02:56:35 +03:00
|
|
|
bJavaPluginClsid = (classid.EqualsWithConversion(JAVA_CLASS_ID));
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// if we find "java:" in the class id, or we match the Java classid number, we have a java applet
|
|
|
|
if(bJavaObject || bJavaPluginClsid)
|
|
|
|
{
|
|
|
|
mimeType = (char *)PR_Malloc(PL_strlen("application/x-java-vm") + 1);
|
|
|
|
PL_strcpy(mimeType, "application/x-java-vm");
|
|
|
|
|
2000-05-23 01:36:35 +04:00
|
|
|
if((rv = GetBaseURL(baseURL)) != NS_OK)
|
2001-01-12 02:56:35 +03:00
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsAutoString codeBase;
|
|
|
|
if(NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::codebase, codeBase) &&
|
|
|
|
!bJavaPluginClsid)
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIURI* codeBaseURL = nsnull;
|
|
|
|
rv = NS_NewURI(&codeBaseURL, codeBase, baseURL);
|
|
|
|
if(rv == NS_OK)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(baseURL);
|
|
|
|
baseURL = codeBaseURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an absolute URL
|
|
|
|
if(bJavaPluginClsid) {
|
|
|
|
rv = NS_NewURI(&fullURL, classid, baseURL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fullURL = baseURL;
|
|
|
|
NS_IF_ADDREF(fullURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the nsIPluginHost interface
|
2000-04-13 06:53:18 +04:00
|
|
|
pluginHost = do_GetService(kCPluginManagerCID);
|
2000-09-12 00:27:25 +04:00
|
|
|
if (!pluginHost)
|
2000-09-12 02:56:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-09-12 00:27:25 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
mInstanceOwner->SetPluginHost(pluginHost);
|
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, mimeType, fullURL);
|
|
|
|
}
|
|
|
|
else // otherwise, we're either an ActiveX control or an internal widget
|
|
|
|
{
|
|
|
|
// These are some builtin types that we know about for now.
|
|
|
|
// (Eventually this will move somewhere else.)
|
2000-04-03 15:39:09 +04:00
|
|
|
if (classid.EqualsWithConversion("browser"))
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
widgetCID = kCAppShellCID;
|
2001-01-12 02:56:35 +03:00
|
|
|
rv = InstantiateWidget(aPresContext, aMetrics, aReflowState, widgetCID);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-12 02:56:35 +03:00
|
|
|
// if we haven't matched to an internal type, check to see if we have an ActiveX handler
|
|
|
|
// if not, create the default plugin
|
|
|
|
if((rv = GetBaseURL(baseURL)) != NS_OK)
|
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
// if we have a codebase, add it to the fullURL
|
|
|
|
nsAutoString codeBase;
|
1999-07-07 06:33:17 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::codebase, codeBase))
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIURI* codeBaseURL = nsnull;
|
|
|
|
rv = NS_NewURI(&fullURL, codeBase, baseURL);
|
|
|
|
if(rv == NS_OK)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(baseURL);
|
|
|
|
baseURL = codeBaseURL;
|
|
|
|
}
|
|
|
|
} else {
|
2001-01-12 02:56:35 +03:00
|
|
|
fullURL = baseURL;
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_IF_ADDREF(fullURL);
|
2000-05-23 01:36:35 +04:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// get the nsIPluginHost interface
|
2000-04-13 06:53:18 +04:00
|
|
|
pluginHost = do_GetService(kCPluginManagerCID);
|
2000-09-12 00:27:25 +04:00
|
|
|
if (!pluginHost)
|
2000-09-12 02:56:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-09-12 00:27:25 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
mInstanceOwner->SetPluginHost(pluginHost);
|
|
|
|
if(pluginHost->IsPluginEnabledForType("application/x-oleobject") == NS_OK)
|
2001-01-12 02:56:35 +03:00
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, "application/x-oleobject", fullURL);
|
1999-07-07 06:33:17 +04:00
|
|
|
else if(pluginHost->IsPluginEnabledForType("application/oleobject") == NS_OK)
|
2001-01-12 02:56:35 +03:00
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, "application/oleobject", fullURL);
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_FAILURE;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
NS_IF_RELEASE(baseURL);
|
|
|
|
NS_IF_RELEASE(fullURL);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// finish up
|
|
|
|
if(rv == NS_OK)
|
|
|
|
{
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got an error, we'll check for alternative content with CantRenderReplacedElement()
|
|
|
|
nsIPresShell* presShell;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetShell(&presShell);
|
|
|
|
presShell->CantRenderReplacedElement(aPresContext, this);
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_RELEASE(presShell);
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
// if we're here, the object is either an applet or a plugin
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsIAtom* atom = nsnull;
|
|
|
|
nsAutoString src;
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
if((rv = GetBaseURL(baseURL)) != NS_OK)
|
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// get the nsIPluginHost interface
|
2000-04-13 06:53:18 +04:00
|
|
|
pluginHost = do_GetService(kCPluginManagerCID);
|
2000-09-12 00:27:25 +04:00
|
|
|
if (!pluginHost)
|
2000-09-12 02:56:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-09-12 00:27:25 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
mInstanceOwner->SetPluginHost(pluginHost);
|
|
|
|
|
|
|
|
mContent->GetTag(atom);
|
2001-01-12 02:56:35 +03:00
|
|
|
// check if it's an applet
|
1999-07-07 06:33:17 +04:00
|
|
|
if (atom == nsHTMLAtoms::applet && atom)
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
1999-07-07 06:33:17 +04:00
|
|
|
mimeType = (char *)PR_Malloc(PL_strlen("application/x-java-vm") + 1);
|
|
|
|
PL_strcpy(mimeType, "application/x-java-vm");
|
|
|
|
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::code, src))
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsAutoString codeBase;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::codebase, codeBase))
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIURI* codeBaseURL = nsnull;
|
|
|
|
rv = NS_NewURI(&codeBaseURL, codeBase, baseURL);
|
|
|
|
if(rv == NS_OK)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(baseURL);
|
|
|
|
baseURL = codeBaseURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an absolute URL
|
|
|
|
rv = NS_NewURI(&fullURL, src, baseURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, mimeType, fullURL);
|
|
|
|
}
|
|
|
|
else // traditional plugin
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
|
|
|
nsAutoString type;
|
1999-07-07 06:33:17 +04:00
|
|
|
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, type);
|
|
|
|
|
|
|
|
buflen = type.Length();
|
|
|
|
if (buflen > 0)
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
1999-07-07 06:33:17 +04:00
|
|
|
mimeType = (char *)PR_Malloc(buflen + 1);
|
|
|
|
if (nsnull != mimeType)
|
|
|
|
type.ToCString(mimeType, buflen + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//stream in the object source if there is one...
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, src))
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
1999-07-07 06:33:17 +04:00
|
|
|
// Create an absolute URL
|
|
|
|
rv = NS_NewURI(&fullURL, src, baseURL);
|
2000-05-07 20:48:06 +04:00
|
|
|
if ( rv != NS_OK )
|
|
|
|
// Failed to create URI, maybe because we didn't
|
|
|
|
// reconize the protocol handler ==> treat like
|
|
|
|
// no 'src' was specified in the embed tag
|
|
|
|
fullURL = baseURL;
|
2001-01-12 02:56:35 +03:00
|
|
|
}
|
|
|
|
else if(NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::data, src))
|
|
|
|
{
|
1999-07-07 06:33:17 +04:00
|
|
|
// Create an absolute URL
|
|
|
|
rv = NS_NewURI(&fullURL, src, baseURL);
|
2000-05-07 20:48:06 +04:00
|
|
|
if ( rv != NS_OK )
|
|
|
|
// Failed to create URI, maybe because we didn't
|
|
|
|
// reconize the protocol handler ==> treat like
|
|
|
|
// no 'data' was specified in the object tag
|
|
|
|
fullURL = baseURL;
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
} else {// we didn't find a src or data param, so just set the url to the base
|
|
|
|
fullURL = baseURL;
|
|
|
|
NS_IF_ADDREF(fullURL);
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
// if we didn't find the type, but we do have a src, we can determine the mimetype
|
|
|
|
// based on the file extension
|
1999-07-07 06:33:17 +04:00
|
|
|
if(!mimeType && src.GetUnicode())
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
|
|
|
char* extension;
|
|
|
|
char* cString = src.ToNewCString();
|
|
|
|
extension = PL_strrchr(cString, '.');
|
|
|
|
if(extension)
|
|
|
|
++extension;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
pluginHost->IsPluginEnabledForExtension((const char *)extension, (const char *&)mimeType);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
delete [] cString;
|
2001-01-12 02:56:35 +03:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, mimeType, fullURL);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
NS_IF_RELEASE(atom);
|
|
|
|
NS_IF_RELEASE(baseURL);
|
|
|
|
NS_IF_RELEASE(fullURL);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
1999-09-30 12:07:23 +04:00
|
|
|
else
|
|
|
|
rv = ReinstantiatePlugin(aPresContext, aMetrics, aReflowState);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// finish up
|
|
|
|
if(rv == NS_OK)
|
|
|
|
{
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got an error, we'll check for alternative content with CantRenderReplacedElement()
|
|
|
|
nsIPresShell* presShell;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetShell(&presShell);
|
|
|
|
presShell->CantRenderReplacedElement(aPresContext, this);
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_RELEASE(presShell);
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
nsObjectFrame::InstantiateWidget(nsIPresContext* aPresContext,
|
2001-01-12 02:56:35 +03:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsCID aWidgetCID)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIView *parentWithView;
|
|
|
|
nsPoint origin;
|
1999-11-24 09:03:41 +03:00
|
|
|
GetOffsetFromView(aPresContext, origin, &parentWithView);
|
1999-07-07 06:33:17 +04:00
|
|
|
// Just make the frigging widget
|
|
|
|
|
|
|
|
float t2p;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetTwipsToPixels(&t2p);
|
1999-07-07 06:33:17 +04:00
|
|
|
PRInt32 x = NSTwipsToIntPixels(origin.x, t2p);
|
|
|
|
PRInt32 y = NSTwipsToIntPixels(origin.y, t2p);
|
|
|
|
PRInt32 width = NSTwipsToIntPixels(aMetrics.width, t2p);
|
|
|
|
PRInt32 height = NSTwipsToIntPixels(aMetrics.height, t2p);
|
|
|
|
nsRect r = nsRect(x, y, width, height);
|
|
|
|
|
2001-01-04 23:44:42 +03:00
|
|
|
if((rv = nsComponentManager::CreateInstance(aWidgetCID, nsnull, NS_GET_IID(nsIWidget), (void**)&mWidget)) != NS_OK)
|
1999-07-07 06:33:17 +04:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsIWidget *parent;
|
|
|
|
parentWithView->GetOffsetFromWidget(nsnull, nsnull, parent);
|
|
|
|
mWidget->Create(parent, r, nsnull, nsnull);
|
|
|
|
|
|
|
|
mWidget->Show(PR_TRUE);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext,
|
2001-01-12 02:56:35 +03:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIPluginHost* aPluginHost,
|
|
|
|
const char* aMimetype,
|
|
|
|
nsIURI* aURL)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
nsIView *parentWithView;
|
|
|
|
nsPoint origin;
|
|
|
|
nsPluginWindow *window;
|
|
|
|
float t2p;
|
2001-01-12 02:56:35 +03:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetTwipsToPixels(&t2p);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
SetFullURL(aURL);
|
|
|
|
|
|
|
|
// we need to recalculate this now that we have access to the nsPluginInstanceOwner
|
|
|
|
// and its size info (as set in the tag)
|
1999-11-24 09:03:41 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
1999-07-07 06:33:17 +04:00
|
|
|
if (nsnull != aMetrics.maxElementSize)
|
|
|
|
{
|
|
|
|
//XXX AddBorderPaddingToMaxElementSize(borderPadding);
|
|
|
|
aMetrics.maxElementSize->width = aMetrics.width;
|
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
GetOffsetFromView(aPresContext, origin, &parentWithView);
|
1999-07-07 06:33:17 +04:00
|
|
|
window->x = NSTwipsToIntPixels(origin.x, t2p);
|
|
|
|
window->y = NSTwipsToIntPixels(origin.y, t2p);
|
|
|
|
window->width = NSTwipsToIntPixels(aMetrics.width, t2p);
|
|
|
|
window->height = NSTwipsToIntPixels(aMetrics.height, t2p);
|
2001-01-12 02:56:35 +03:00
|
|
|
|
|
|
|
// on the Mac we need to set the clipRect to { 0, 0, 0, 0 } for now. This will keep
|
|
|
|
// us from drawing on screen until the widget is properly positioned, which will not
|
|
|
|
// happen until we have finished the reflow process.
|
1999-07-07 06:33:17 +04:00
|
|
|
window->clipRect.top = 0;
|
|
|
|
window->clipRect.left = 0;
|
2001-01-12 02:56:35 +03:00
|
|
|
#ifndef XP_MAC
|
1999-07-07 06:33:17 +04:00
|
|
|
window->clipRect.bottom = NSTwipsToIntPixels(aMetrics.height, t2p);
|
|
|
|
window->clipRect.right = NSTwipsToIntPixels(aMetrics.width, t2p);
|
2001-01-12 02:56:35 +03:00
|
|
|
#else
|
|
|
|
window->clipRect.bottom = 0;
|
|
|
|
window->clipRect.right = 0;
|
|
|
|
#endif
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
window->ws_info = nsnull; //XXX need to figure out what this is. MMP
|
|
|
|
#endif
|
2000-05-25 17:32:42 +04:00
|
|
|
|
|
|
|
// Check to see if content-policy wants to veto this
|
2000-06-03 00:20:35 +04:00
|
|
|
if(aURL != nsnull)
|
|
|
|
{
|
|
|
|
PRBool shouldLoad = PR_TRUE; // default permit
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mContent, &rv);
|
|
|
|
|
|
|
|
// For pinkerton: a symphony for string conversion, in 3 parts.
|
|
|
|
nsXPIDLCString urlCString;
|
|
|
|
aURL->GetSpec(getter_Copies(urlCString));
|
|
|
|
nsAutoString url;
|
|
|
|
url.AssignWithConversion((const char *)urlCString);
|
2001-01-12 02:56:35 +03:00
|
|
|
|
2000-06-03 00:20:35 +04:00
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::CONTENT_OBJECT,
|
|
|
|
url, element, &shouldLoad)) &&
|
|
|
|
!shouldLoad) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-25 17:32:42 +04:00
|
|
|
}
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
return aPluginHost->InstantiateEmbededPlugin(aMimetype, aURL, mInstanceOwner);
|
|
|
|
}
|
|
|
|
|
1999-11-11 03:00:07 +03:00
|
|
|
// This is called when the page containing plugin is resized, and plugin has its dimensions
|
1999-09-30 12:07:23 +04:00
|
|
|
// specified in percentage, so it needs to follow the page on the fly.
|
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
nsObjectFrame::ReinstantiatePlugin(nsIPresContext* aPresContext, nsHTMLReflowMetrics& aMetrics, const nsHTMLReflowState& aReflowState)
|
1999-09-30 12:07:23 +04:00
|
|
|
{
|
|
|
|
nsIView *parentWithView;
|
|
|
|
nsPoint origin;
|
|
|
|
nsPluginWindow *window;
|
|
|
|
float t2p;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetTwipsToPixels(&t2p);
|
1999-09-30 12:07:23 +04:00
|
|
|
|
|
|
|
// we need to recalculate this now that we have access to the nsPluginInstanceOwner
|
|
|
|
// and its size info (as set in the tag)
|
1999-11-24 09:03:41 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
1999-09-30 12:07:23 +04:00
|
|
|
if (nsnull != aMetrics.maxElementSize)
|
|
|
|
{
|
|
|
|
//XXX AddBorderPaddingToMaxElementSize(borderPadding);
|
|
|
|
aMetrics.maxElementSize->width = aMetrics.width;
|
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
GetOffsetFromView(aPresContext, origin, &parentWithView);
|
1999-11-11 03:00:07 +03:00
|
|
|
|
1999-09-30 12:07:23 +04:00
|
|
|
window->x = NSTwipsToIntPixels(origin.x, t2p);
|
|
|
|
window->y = NSTwipsToIntPixels(origin.y, t2p);
|
|
|
|
window->width = NSTwipsToIntPixels(aMetrics.width, t2p);
|
|
|
|
window->height = NSTwipsToIntPixels(aMetrics.height, t2p);
|
1999-11-11 03:00:07 +03:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
// ignore this for now on the Mac because the widget is not properly positioned
|
|
|
|
// yet and won't be until we have finished the reflow process.
|
|
|
|
#ifndef XP_MAC
|
1999-09-30 12:07:23 +04:00
|
|
|
window->clipRect.top = 0;
|
|
|
|
window->clipRect.left = 0;
|
|
|
|
window->clipRect.bottom = NSTwipsToIntPixels(aMetrics.height, t2p);
|
|
|
|
window->clipRect.right = NSTwipsToIntPixels(aMetrics.width, t2p);
|
2001-01-12 02:56:35 +03:00
|
|
|
#endif
|
1999-09-30 12:07:23 +04:00
|
|
|
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
window->ws_info = nsnull; //XXX need to figure out what this is. MMP
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
nsObjectFrame::HandleImage(nsIPresContext* aPresContext,
|
2001-01-12 02:56:35 +03:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
nsIFrame* child)
|
|
|
|
{
|
|
|
|
nsSize availSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
nsHTMLReflowMetrics kidDesiredSize(nsnull);
|
|
|
|
|
|
|
|
nsReflowReason reflowReason;
|
|
|
|
nsFrameState frameState;
|
|
|
|
child->GetFrameState(&frameState);
|
|
|
|
if (frameState & NS_FRAME_FIRST_REFLOW)
|
|
|
|
reflowReason = eReflowReason_Initial;
|
|
|
|
else
|
|
|
|
reflowReason = eReflowReason_Resize;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, child,
|
|
|
|
availSize, reflowReason);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
nsReflowStatus status;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
if(PR_TRUE)//reflowReason == eReflowReason_Initial)
|
|
|
|
{
|
|
|
|
kidDesiredSize.width = NS_UNCONSTRAINEDSIZE;
|
|
|
|
kidDesiredSize.height = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// adjust kidReflowState
|
|
|
|
nsIHTMLContent* hc = nsnull;
|
2001-01-04 23:44:42 +03:00
|
|
|
mContent->QueryInterface(NS_GET_IID(nsIHTMLContent), (void**) &hc);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if(hc != nsnull)
|
|
|
|
{
|
|
|
|
float p2t;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsHTMLValue val;
|
|
|
|
if(NS_CONTENT_ATTR_HAS_VALUE == hc->GetHTMLAttribute(nsHTMLAtoms::width, val))
|
|
|
|
{
|
|
|
|
if(eHTMLUnit_Pixel == val.GetUnit())
|
|
|
|
{
|
|
|
|
nscoord width = val.GetPixelValue();
|
1999-07-20 07:41:03 +04:00
|
|
|
kidReflowState.mComputedWidth = NSIntPixelsToTwips(width, p2t);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(NS_CONTENT_ATTR_HAS_VALUE == hc->GetHTMLAttribute(nsHTMLAtoms::height, val))
|
|
|
|
{
|
|
|
|
if(eHTMLUnit_Pixel == val.GetUnit())
|
|
|
|
{
|
|
|
|
nscoord height = val.GetPixelValue();
|
1999-07-20 07:41:03 +04:00
|
|
|
kidReflowState.mComputedHeight = NSIntPixelsToTwips(height, p2t);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
ReflowChild(child, aPresContext, kidDesiredSize, kidReflowState, 0, 0, 0, status);
|
1999-11-19 18:33:29 +03:00
|
|
|
FinishReflowChild(child, aPresContext, kidDesiredSize, 0, 0, 0);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
aMetrics.width = kidDesiredSize.width;
|
|
|
|
aMetrics.height = kidDesiredSize.height;
|
|
|
|
aMetrics.ascent = kidDesiredSize.height;
|
|
|
|
aMetrics.descent = 0;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2001-01-12 02:56:35 +03:00
|
|
|
return NS_OK;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsObjectFrame::GetBaseURL(nsIURI* &aURL)
|
|
|
|
{
|
|
|
|
nsIHTMLContent* htmlContent;
|
2001-01-04 23:44:42 +03:00
|
|
|
if (NS_SUCCEEDED(mContent->QueryInterface(NS_GET_IID(nsIHTMLContent), (void**)&htmlContent)))
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
htmlContent->GetBaseURL(aURL);
|
|
|
|
NS_RELEASE(htmlContent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
if (NS_SUCCEEDED(mContent->GetDocument(doc)))
|
2001-01-12 02:56:35 +03:00
|
|
|
{
|
1999-07-07 06:33:17 +04:00
|
|
|
doc->GetBaseURL(aURL);
|
|
|
|
NS_RELEASE(doc);
|
2001-01-12 02:56:35 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-07-20 03:46:43 +04:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsObjectFrame::IsHidden() const
|
|
|
|
{
|
2001-01-12 02:56:35 +03:00
|
|
|
// check the style visibility first
|
2000-09-04 00:54:26 +04:00
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
2001-01-12 02:56:35 +03:00
|
|
|
if (disp != nsnull)
|
2000-09-04 00:54:26 +04:00
|
|
|
{
|
|
|
|
if(!disp->IsVisibleOrCollapsed())
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-07-20 03:46:43 +04:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
mContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
|
|
|
|
if (tag.get() != nsHTMLAtoms::object) {
|
|
|
|
// The <object> tag doesn't support the 'hidden' attribute, but
|
|
|
|
// everything else does...
|
|
|
|
nsAutoString hidden;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::hidden, hidden);
|
|
|
|
|
|
|
|
// Yes, these are really the kooky ways that you could tell 4.x
|
|
|
|
// not to hide the <embed> once you'd put the 'hidden' attribute
|
|
|
|
// on the tag...
|
2000-08-20 02:23:46 +04:00
|
|
|
// these |NS_ConvertASCIItoUCS2|s can't be |NS_LITERAL_STRING|s until |EqualsIgnoreCase| get's fixed
|
2000-07-20 03:46:43 +04:00
|
|
|
if (hidden.Length() &&
|
2000-08-20 02:23:46 +04:00
|
|
|
! hidden.EqualsIgnoreCase(NS_ConvertASCIItoUCS2("false")) &&
|
|
|
|
! hidden.EqualsIgnoreCase(NS_ConvertASCIItoUCS2("no")) &&
|
|
|
|
! hidden.EqualsIgnoreCase(NS_ConvertASCIItoUCS2("off"))) {
|
2000-07-20 03:46:43 +04:00
|
|
|
// The <embed> or <applet> is hidden.
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::ContentChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsISupports* aSubContent)
|
|
|
|
{
|
|
|
|
// Generate a reflow command with this frame as the target frame
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this,
|
|
|
|
nsIReflowCommand::ContentChanged);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsObjectFrame::DidReflow(nsIPresContext* aPresContext,
|
1999-07-07 06:33:17 +04:00
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = nsObjectFrameSuper::DidReflow(aPresContext, aStatus);
|
|
|
|
|
|
|
|
// The view is created hidden; once we have reflowed it and it has been
|
|
|
|
// positioned then we show it.
|
2000-07-20 03:46:43 +04:00
|
|
|
if (NS_FRAME_REFLOW_FINISHED == aStatus && !IsHidden()) {
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIView* view = nsnull;
|
1999-11-24 09:03:41 +03:00
|
|
|
GetView(aPresContext, &view);
|
1999-07-07 06:33:17 +04:00
|
|
|
if (nsnull != view) {
|
|
|
|
view->SetVisibility(nsViewVisibility_kShow);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mInstanceOwner) {
|
|
|
|
nsPluginWindow *window;
|
|
|
|
|
|
|
|
if (NS_OK == mInstanceOwner->GetWindow(window)) {
|
|
|
|
nsIView *parentWithView;
|
|
|
|
nsPoint origin;
|
|
|
|
float t2p;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetTwipsToPixels(&t2p);
|
1999-07-07 06:33:17 +04:00
|
|
|
nscoord offx, offy;
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
GetOffsetFromView(aPresContext, origin, &parentWithView);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// beard: how do we get this?
|
|
|
|
parentWithView->GetScrollOffset(&offx, &offy);
|
|
|
|
#else
|
|
|
|
offx = offy = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
window->x = NSTwipsToIntPixels(origin.x, t2p);
|
|
|
|
window->y = NSTwipsToIntPixels(origin.y, t2p);
|
|
|
|
// window->width = NSTwipsToIntPixels(aMetrics.width, t2p);
|
|
|
|
// window->height = NSTwipsToIntPixels(aMetrics.height, t2p);
|
|
|
|
|
|
|
|
// refresh the plugin port as well
|
|
|
|
window->window = mInstanceOwner->GetPluginPort();
|
|
|
|
|
|
|
|
// beard: to preserve backward compatibility with Communicator 4.X, the
|
|
|
|
// clipRect must be in port coordinates.
|
2000-10-18 01:45:39 +04:00
|
|
|
#ifndef XP_MAC
|
|
|
|
// this is only well-defined on the Mac OS anyway, or perhaps for windowless plugins.
|
1999-07-07 06:33:17 +04:00
|
|
|
window->clipRect.top = 0;
|
|
|
|
window->clipRect.left = 0;
|
|
|
|
window->clipRect.bottom = window->clipRect.top + window->height;
|
|
|
|
window->clipRect.right = window->clipRect.left + window->width;
|
2001-01-12 02:56:35 +03:00
|
|
|
#else
|
|
|
|
// now that we have finished the reflow process, the widget is properly positioned
|
|
|
|
// and we can validate the plugin clipping information by syncing the plugin
|
|
|
|
// window info to reflect the current widget location.
|
|
|
|
mInstanceOwner->FixUpPluginWindow();
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//~~~
|
|
|
|
mInstanceOwner->ReleasePluginPort((nsPluginPort *)window->window);
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
if (mWidget)
|
|
|
|
{
|
|
|
|
PRInt32 x = NSTwipsToIntPixels(origin.x, t2p);
|
|
|
|
PRInt32 y = NSTwipsToIntPixels(origin.y, t2p);
|
|
|
|
mWidget->Move(x, y);
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsObjectFrame::Paint(nsIPresContext* aPresContext,
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
|
|
|
{
|
2001-01-12 02:56:35 +03:00
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if ((disp != nsnull) && !disp->IsVisibleOrCollapsed()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
nsIFrame * child = mFrames.FirstChild();
|
|
|
|
if (child != NULL) { // This is an image
|
|
|
|
nsObjectFrameSuper::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2000-07-12 00:06:05 +04:00
|
|
|
#if defined (XP_MAC)
|
2001-01-12 02:56:35 +03:00
|
|
|
// delegate all painting to the plugin instance.
|
|
|
|
if ((NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) && (nsnull != mInstanceOwner)) {
|
|
|
|
mInstanceOwner->Paint(aDirtyRect);
|
|
|
|
}
|
2000-07-12 00:06:05 +04:00
|
|
|
#elif defined (XP_PC)
|
2001-01-12 02:56:35 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer)
|
|
|
|
{
|
|
|
|
nsIPluginInstance * inst;
|
|
|
|
if (NS_OK == GetPluginInstance(inst))
|
|
|
|
{
|
|
|
|
NS_RELEASE(inst);
|
|
|
|
// Look if it's windowless
|
|
|
|
nsPluginWindow * window;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
if (window->type == nsPluginWindowType_Drawable)
|
|
|
|
{
|
|
|
|
PRUint32 hdc;
|
|
|
|
aRenderingContext.RetrieveCurrentNativeGraphicData(&hdc);
|
|
|
|
mInstanceOwner->Paint(aDirtyRect, hdc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif /* !XP_MAC */
|
2001-01-12 02:56:35 +03:00
|
|
|
return NS_OK;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsObjectFrame::HandleEvent(nsIPresContext* aPresContext,
|
1999-07-07 06:33:17 +04:00
|
|
|
nsGUIEvent* anEvent,
|
1999-11-24 09:03:41 +03:00
|
|
|
nsEventStatus* anEventStatus)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(anEventStatus);
|
2001-01-12 02:56:35 +03:00
|
|
|
nsresult rv = NS_OK;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
//~~~
|
1999-09-28 04:13:19 +04:00
|
|
|
//FIX FOR CRASHING WHEN NO INSTANCE OWVER
|
|
|
|
if (!mInstanceOwner)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-07-07 06:33:17 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
nsPluginWindow * window;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
if(window->type == nsPluginWindowType_Drawable)
|
|
|
|
{
|
2001-01-12 02:56:35 +03:00
|
|
|
switch (anEvent->message)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2000-10-18 03:13:30 +04:00
|
|
|
//XXX: All of the button down's are handled by the DOM listener
|
|
|
|
// case NS_MOUSE_LEFT_BUTTON_DOWN:
|
1999-07-07 06:33:17 +04:00
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_LEFT_DOUBLECLICK:
|
2000-10-18 03:13:30 +04:00
|
|
|
// case NS_MOUSE_RIGHT_BUTTON_DOWN:
|
1999-07-07 06:33:17 +04:00
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_RIGHT_DOUBLECLICK:
|
2000-10-18 03:13:30 +04:00
|
|
|
// case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
1999-07-07 06:33:17 +04:00
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
|
|
|
case NS_MOUSE_MIDDLE_DOUBLECLICK:
|
|
|
|
case NS_MOUSE_MOVE:
|
2001-01-17 23:04:09 +03:00
|
|
|
//case NS_KEY_UP:
|
|
|
|
//case NS_KEY_DOWN:
|
1999-07-07 06:33:17 +04:00
|
|
|
case NS_GOTFOCUS:
|
|
|
|
case NS_LOSTFOCUS:
|
|
|
|
//case set cursor should be here too:
|
1999-11-24 09:03:41 +03:00
|
|
|
*anEventStatus = mInstanceOwner->ProcessEvent(*anEvent);
|
1999-07-07 06:33:17 +04:00
|
|
|
return rv;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rv = nsObjectFrameSuper::HandleEvent(aPresContext, anEvent, anEventStatus);
|
|
|
|
return rv;
|
|
|
|
#endif
|
|
|
|
|
2001-01-17 23:04:09 +03:00
|
|
|
switch (anEvent->message) {
|
|
|
|
case NS_DESTROY:
|
|
|
|
mInstanceOwner->CancelTimer();
|
|
|
|
break;
|
|
|
|
case NS_GOTFOCUS:
|
|
|
|
case NS_LOSTFOCUS:
|
|
|
|
//case NS_KEY_UP:
|
|
|
|
//case NS_KEY_DOWN:
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
case NS_MOUSE_ENTER:
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
2000-11-04 02:57:24 +03:00
|
|
|
#ifndef XP_MAC
|
2001-01-17 23:04:09 +03:00
|
|
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
2000-11-04 02:57:24 +03:00
|
|
|
#endif
|
2001-01-17 23:04:09 +03:00
|
|
|
*anEventStatus = mInstanceOwner->ProcessEvent(*anEvent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// instead of using an event listener, we can dispatch events to plugins directly.
|
|
|
|
rv = nsObjectFrameSuper::HandleEvent(aPresContext, anEvent, anEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsObjectFrame::Scrolled(nsIView *aView)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsObjectFrame::SetFullURL(nsIURI* aURL)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mFullURL);
|
|
|
|
mFullURL = aURL;
|
|
|
|
NS_IF_ADDREF(mFullURL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsObjectFrame::GetFullURL(nsIURI*& aFullURL)
|
|
|
|
{
|
|
|
|
aFullURL = mFullURL;
|
|
|
|
NS_IF_ADDREF(aFullURL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsObjectFrame::GetPluginInstance(nsIPluginInstance*& aPluginInstance)
|
|
|
|
{
|
2000-02-16 04:49:42 +03:00
|
|
|
if(mInstanceOwner == nsnull)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
else
|
|
|
|
return mInstanceOwner->GetInstance(aPluginInstance);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewObjectFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
nsObjectFrame* it = new (aPresShell) nsObjectFrame;
|
1999-07-07 06:33:17 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: put this in a header file.
|
|
|
|
extern nsresult NS_GetObjectFramePluginInstance(nsIFrame* aFrame, nsIPluginInstance*& aPluginInstance);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_GetObjectFramePluginInstance(nsIFrame* aFrame, nsIPluginInstance*& aPluginInstance)
|
|
|
|
{
|
1999-10-09 03:46:23 +04:00
|
|
|
if(aFrame == nsnull)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
// TODO: any way to determine this cast is safe?
|
|
|
|
nsObjectFrame* objectFrame = NS_STATIC_CAST(nsObjectFrame*, aFrame);
|
|
|
|
return objectFrame->GetPluginInstance(aPluginInstance);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//plugin instance owner
|
|
|
|
|
|
|
|
nsPluginInstanceOwner::nsPluginInstanceOwner()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
memset(&mPluginWindow, 0, sizeof(mPluginWindow));
|
|
|
|
mInstance = nsnull;
|
|
|
|
mOwner = nsnull;
|
|
|
|
mNumAttrs = 0;
|
|
|
|
mAttrNames = nsnull;
|
|
|
|
mAttrVals = nsnull;
|
|
|
|
mWidget = nsnull;
|
|
|
|
mContext = nsnull;
|
|
|
|
mNumParams = 0;
|
|
|
|
mParamNames = nsnull;
|
|
|
|
mParamVals = nsnull;
|
1999-08-03 06:51:39 +04:00
|
|
|
mDocumentBase = nsnull;
|
2000-10-19 05:37:53 +04:00
|
|
|
mTagText = nsnull;
|
1999-07-07 06:33:17 +04:00
|
|
|
mPluginHost = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginInstanceOwner::~nsPluginInstanceOwner()
|
|
|
|
{
|
|
|
|
PRInt32 cnt;
|
|
|
|
|
|
|
|
// shut off the timer.
|
|
|
|
if (mPluginTimer != nsnull) {
|
|
|
|
mPluginTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mInstance)
|
|
|
|
{
|
2000-10-06 06:45:53 +04:00
|
|
|
if (mPluginHost)
|
|
|
|
mPluginHost->StopPluginInstance(mInstance);
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_RELEASE(mInstance);
|
|
|
|
}
|
|
|
|
|
2000-10-06 06:45:53 +04:00
|
|
|
NS_IF_RELEASE(mPluginHost);
|
1999-07-07 06:33:17 +04:00
|
|
|
mOwner = nsnull;
|
|
|
|
|
|
|
|
for (cnt = 0; cnt < mNumAttrs; cnt++)
|
|
|
|
{
|
|
|
|
if ((nsnull != mAttrNames) && (nsnull != mAttrNames[cnt]))
|
|
|
|
{
|
|
|
|
PR_Free(mAttrNames[cnt]);
|
|
|
|
mAttrNames[cnt] = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nsnull != mAttrVals) && (nsnull != mAttrVals[cnt]))
|
|
|
|
{
|
|
|
|
PR_Free(mAttrVals[cnt]);
|
|
|
|
mAttrVals[cnt] = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mAttrNames)
|
|
|
|
{
|
|
|
|
PR_Free(mAttrNames);
|
|
|
|
mAttrNames = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mAttrVals)
|
|
|
|
{
|
|
|
|
PR_Free(mAttrVals);
|
|
|
|
mAttrVals = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cnt = 0; cnt < mNumParams; cnt++)
|
|
|
|
{
|
|
|
|
if ((nsnull != mParamNames) && (nsnull != mParamNames[cnt]))
|
|
|
|
{
|
|
|
|
PR_Free(mParamNames[cnt]);
|
|
|
|
mParamNames[cnt] = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nsnull != mParamVals) && (nsnull != mParamVals[cnt]))
|
|
|
|
{
|
|
|
|
PR_Free(mParamVals[cnt]);
|
|
|
|
mParamVals[cnt] = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mParamNames)
|
|
|
|
{
|
|
|
|
PR_Free(mParamNames);
|
|
|
|
mParamNames = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mParamVals)
|
|
|
|
{
|
|
|
|
PR_Free(mParamVals);
|
|
|
|
mParamVals = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-08-03 06:51:39 +04:00
|
|
|
if (nsnull != mDocumentBase)
|
|
|
|
{
|
|
|
|
nsCRT::free(mDocumentBase);
|
|
|
|
mDocumentBase = nsnull;
|
|
|
|
}
|
2000-10-19 05:37:53 +04:00
|
|
|
|
|
|
|
if (nsnull != mTagText)
|
|
|
|
{
|
|
|
|
nsCRT::free(mTagText);
|
|
|
|
mTagText = nsnull;
|
|
|
|
}
|
1999-08-03 06:51:39 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_IF_RELEASE(mWidget);
|
|
|
|
mContext = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsPluginInstanceOwner);
|
|
|
|
NS_IMPL_RELEASE(nsPluginInstanceOwner);
|
|
|
|
|
|
|
|
nsresult nsPluginInstanceOwner::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
|
|
|
|
if (nsnull == aInstancePtrResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-02-03 01:24:56 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIPluginInstanceOwner)))
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsIPluginInstanceOwner *)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-03 01:24:56 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIPluginTagInfo)) || aIID.Equals(NS_GET_IID(nsIPluginTagInfo2)))
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsIPluginTagInfo2 *)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-03 01:24:56 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIJVMPluginTagInfo)))
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsIJVMPluginTagInfo *)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-03 01:24:56 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIEventListener)))
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsIEventListener *)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-03 01:24:56 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsITimerCallback)))
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsITimerCallback *)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:42 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIDOMMouseListener))) {
|
2000-10-18 03:13:30 +04:00
|
|
|
*aInstancePtrResult = (void*)(nsIDOMMouseListener*) this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-01-17 23:04:09 +03:00
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIDOMKeyListener))) {
|
|
|
|
*aInstancePtrResult = (void*)(nsIDOMKeyListener*) this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
if (aIID.Equals(kISupportsIID))
|
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsISupports *)((nsIPluginTagInfo *)this));
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::SetInstance(nsIPluginInstance *aInstance)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mInstance);
|
|
|
|
mInstance = aInstance;
|
|
|
|
NS_IF_ADDREF(mInstance);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetWindow(nsPluginWindow *&aWindow)
|
|
|
|
{
|
|
|
|
aWindow = &mPluginWindow;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetMode(nsPluginMode *aMode)
|
|
|
|
{
|
|
|
|
*aMode = nsPluginMode_Embedded;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetAttributes(PRUint16& n,
|
|
|
|
const char*const*& names,
|
|
|
|
const char*const*& values)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIContent* iContent;
|
|
|
|
|
|
|
|
if ((nsnull == mAttrNames) && (nsnull != mOwner)) {
|
|
|
|
rv = mOwner->GetContent(&iContent);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRInt32 count;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(iContent->GetAttributeCount(count))) {
|
|
|
|
PRInt32 index;
|
|
|
|
mAttrNames = (char **)PR_Calloc(sizeof(char *) * count, 1);
|
|
|
|
mAttrVals = (char **)PR_Calloc(sizeof(char *) * count, 1);
|
|
|
|
mNumAttrs = 0;
|
|
|
|
|
|
|
|
if ((nsnull != mAttrNames) && (nsnull != mAttrVals)) {
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsIAtom* atom;
|
2000-05-17 04:21:53 +04:00
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
|
|
|
iContent->GetAttributeNameAt(index, nameSpaceID, atom,
|
|
|
|
*getter_AddRefs(prefix));
|
1999-07-07 06:33:17 +04:00
|
|
|
nsAutoString value;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == iContent->GetAttribute(nameSpaceID, atom, value)) {
|
|
|
|
nsAutoString name;
|
|
|
|
atom->ToString(name);
|
|
|
|
|
2000-05-27 02:24:35 +04:00
|
|
|
/* Changing to ToNewUTF8String addressing 17169, 39789
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
mAttrNames[mNumAttrs] = (char *)PR_Malloc(name.Length() + 1);
|
|
|
|
mAttrVals[mNumAttrs] = (char *)PR_Malloc(value.Length() + 1);
|
|
|
|
|
|
|
|
if ((nsnull != mAttrNames[mNumAttrs]) &&
|
|
|
|
(nsnull != mAttrVals[mNumAttrs]))
|
|
|
|
{
|
|
|
|
name.ToCString(mAttrNames[mNumAttrs], name.Length() + 1);
|
|
|
|
value.ToCString(mAttrVals[mNumAttrs], value.Length() + 1);
|
|
|
|
|
|
|
|
mNumAttrs++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nsnull != mAttrNames[mNumAttrs])
|
|
|
|
{
|
|
|
|
PR_Free(mAttrNames[mNumAttrs]);
|
|
|
|
mAttrNames[mNumAttrs] = nsnull;
|
|
|
|
}
|
|
|
|
if (nsnull != mAttrVals[mNumAttrs])
|
|
|
|
{
|
|
|
|
PR_Free(mAttrVals[mNumAttrs]);
|
|
|
|
mAttrVals[mNumAttrs] = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2000-05-27 02:24:35 +04:00
|
|
|
*/
|
|
|
|
mAttrNames[mNumAttrs] = name.ToNewUTF8String();
|
|
|
|
mAttrVals[mNumAttrs] = value.ToNewUTF8String();
|
|
|
|
mNumAttrs++;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (nsnull != mAttrVals) {
|
|
|
|
PR_Free(mAttrVals);
|
|
|
|
mAttrVals = nsnull;
|
|
|
|
}
|
|
|
|
if (nsnull != mAttrNames) {
|
|
|
|
PR_Free(mAttrNames);
|
|
|
|
mAttrNames = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(iContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = mNumAttrs;
|
|
|
|
names = (const char **)mAttrNames;
|
|
|
|
values = (const char **)mAttrVals;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetAttribute(const char* name, const char* *result)
|
|
|
|
{
|
|
|
|
if (nsnull == mAttrNames) {
|
|
|
|
PRUint16 numattrs;
|
|
|
|
const char * const *names, * const *vals;
|
|
|
|
|
|
|
|
GetAttributes(numattrs, names, vals);
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = NULL;
|
|
|
|
|
|
|
|
for (int i = 0; i < mNumAttrs; i++) {
|
|
|
|
if (0 == PL_strcasecmp(mAttrNames[i], name)) {
|
|
|
|
*result = mAttrVals[i];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-01-05 04:18:38 +03:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetDOMElement(nsIDOMElement* *result)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*result = nsnull;
|
|
|
|
|
|
|
|
if (nsnull != mOwner)
|
|
|
|
{
|
|
|
|
nsIContent *cont;
|
|
|
|
|
|
|
|
mOwner->GetContent(&cont);
|
|
|
|
|
|
|
|
if (nsnull != cont)
|
|
|
|
{
|
2000-02-03 01:24:56 +03:00
|
|
|
rv = cont->QueryInterface(NS_GET_IID(nsIDOMElement), (void **)result);
|
2000-01-05 04:18:38 +03:00
|
|
|
NS_RELEASE(cont);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetInstance(nsIPluginInstance *&aInstance)
|
|
|
|
{
|
|
|
|
if (nsnull != mInstance)
|
|
|
|
{
|
|
|
|
aInstance = mInstance;
|
|
|
|
NS_ADDREF(mInstance);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-09-05 23:03:56 +04:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL, const char *aTarget, void *aPostData, PRUint32 aPostDataLen, void *aHeadersData,
|
|
|
|
PRUint32 aHeadersDataLen)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
nsISupports *container;
|
|
|
|
nsILinkHandler *lh;
|
|
|
|
nsresult rv;
|
|
|
|
nsIView *view;
|
|
|
|
nsPoint origin;
|
|
|
|
|
|
|
|
if ((nsnull != mOwner) && (nsnull != mContext))
|
|
|
|
{
|
1999-10-26 08:44:41 +04:00
|
|
|
rv = mOwner->GetOffsetFromView(mContext, origin, &view);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
rv = mContext->GetContainer(&container);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
2001-01-04 23:44:42 +03:00
|
|
|
rv = container->QueryInterface(NS_GET_IID(nsILinkHandler), (void **)&lh);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
2000-04-03 15:39:09 +04:00
|
|
|
nsAutoString uniurl; uniurl.AssignWithConversion(aURL);
|
|
|
|
nsAutoString unitarget; unitarget.AssignWithConversion(aTarget);
|
1999-07-07 06:33:17 +04:00
|
|
|
nsAutoString fullurl;
|
|
|
|
nsIURI* baseURL;
|
|
|
|
|
2000-09-06 03:40:07 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
rv = GetDocument(getter_AddRefs(doc));
|
|
|
|
if (NS_SUCCEEDED(rv) && doc)
|
|
|
|
{
|
|
|
|
baseURL = doc->GetDocumentURL(); // gets the document's url
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mOwner->GetFullURL(baseURL); // gets the plugin's content url
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// Create an absolute URL
|
2000-03-29 07:58:50 +04:00
|
|
|
rv = NS_MakeAbsoluteURI(fullurl, uniurl, baseURL);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
NS_IF_RELEASE(baseURL);
|
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsIContent* content = nsnull;
|
|
|
|
mOwner->GetContent(&content);
|
2000-08-24 23:49:08 +04:00
|
|
|
nsCOMPtr<nsISupports> result = nsnull;
|
|
|
|
nsCOMPtr<nsIInputStream> postDataStream = nsnull;
|
2000-09-05 23:03:56 +04:00
|
|
|
nsCOMPtr<nsIInputStream> headersDataStream = nsnull;
|
2000-08-24 23:49:08 +04:00
|
|
|
if (aPostData) {
|
|
|
|
NS_NewByteInputStream(getter_AddRefs(result),
|
|
|
|
(const char *) aPostData, aPostDataLen);
|
|
|
|
if (result) {
|
|
|
|
postDataStream = do_QueryInterface(result, &rv);
|
|
|
|
}
|
|
|
|
}
|
2000-09-05 23:03:56 +04:00
|
|
|
if (aHeadersData) {
|
|
|
|
NS_NewByteInputStream(getter_AddRefs(result),
|
|
|
|
(const char *) aHeadersData, aHeadersDataLen);
|
|
|
|
if (result) {
|
|
|
|
headersDataStream = do_QueryInterface(result, &rv);
|
|
|
|
}
|
2000-08-25 01:48:01 +04:00
|
|
|
}
|
2000-09-05 23:03:56 +04:00
|
|
|
rv = lh->OnLinkClick(content, eLinkVerb_Replace,
|
|
|
|
fullurl.GetUnicode(),
|
|
|
|
unitarget.GetUnicode(),
|
|
|
|
postDataStream, headersDataStream);
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
}
|
|
|
|
NS_RELEASE(lh);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(container);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::ShowStatus(const char *aStatusMsg)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (nsnull != mContext)
|
|
|
|
{
|
1999-12-18 05:09:29 +03:00
|
|
|
nsCOMPtr<nsISupports> cont;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
1999-12-18 05:09:29 +03:00
|
|
|
rv = mContext->GetContainer(getter_AddRefs(cont));
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if ((NS_OK == rv) && (nsnull != cont))
|
|
|
|
{
|
1999-12-18 05:09:29 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellItem(do_QueryInterface(cont));
|
|
|
|
if (docShellItem)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2000-03-11 03:41:57 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
docShellItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2000-03-11 03:41:57 +03:00
|
|
|
if(treeOwner)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2000-03-11 03:41:57 +03:00
|
|
|
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(treeOwner));
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2000-03-11 03:41:57 +03:00
|
|
|
if(browserChrome)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2000-04-03 15:39:09 +04:00
|
|
|
nsAutoString msg; msg.AssignWithConversion(aStatusMsg);
|
2000-08-25 22:39:46 +04:00
|
|
|
browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_SCRIPT, msg.GetUnicode());
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetDocument(nsIDocument* *aDocument)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
if (nsnull != mContext) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mContext->GetShell(getter_AddRefs(shell));
|
|
|
|
|
|
|
|
rv = shell->GetDocument(aDocument);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetTagType(nsPluginTagType *result)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*result = nsPluginTagType_Unknown;
|
|
|
|
|
|
|
|
if (nsnull != mOwner)
|
|
|
|
{
|
|
|
|
nsIContent *cont;
|
|
|
|
|
|
|
|
mOwner->GetContent(&cont);
|
|
|
|
|
|
|
|
if (nsnull != cont)
|
|
|
|
{
|
|
|
|
nsIAtom *atom;
|
|
|
|
|
|
|
|
cont->GetTag(atom);
|
|
|
|
|
|
|
|
if (nsnull != atom)
|
|
|
|
{
|
|
|
|
if (atom == nsHTMLAtoms::applet)
|
|
|
|
*result = nsPluginTagType_Applet;
|
|
|
|
else if (atom == nsHTMLAtoms::embed)
|
|
|
|
*result = nsPluginTagType_Embed;
|
|
|
|
else if (atom == nsHTMLAtoms::object)
|
|
|
|
*result = nsPluginTagType_Object;
|
|
|
|
|
|
|
|
rv = NS_OK;
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(cont);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetTagText(const char* *result)
|
|
|
|
{
|
2000-10-19 05:37:53 +04:00
|
|
|
if (nsnull == mTagText) {
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
rv = mOwner->GetContent(getter_AddRefs(content));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content, &rv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
rv = GetDocument(getter_AddRefs(document));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
nsCOMPtr<nsIDocumentEncoder> docEncoder(do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/html", &rv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
rv = docEncoder->Init(document, NS_LITERAL_STRING("text/html"), nsIDocumentEncoder::OutputEncodeEntities);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> range(new nsRange);
|
|
|
|
if (!range)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
rv = range->SelectNode(node);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
docEncoder->SetRange(range);
|
|
|
|
nsString elementHTML;
|
|
|
|
rv = docEncoder->EncodeToString(elementHTML);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mTagText = elementHTML.ToNewUTF8String();
|
|
|
|
if (!mTagText)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*result = mTagText;
|
|
|
|
return NS_OK;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetParameters(PRUint16& n, const char*const*& names, const char*const*& values)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if ((nsnull == mParamNames) && (nsnull != mOwner))
|
|
|
|
{
|
|
|
|
nsIContent *cont;
|
|
|
|
|
|
|
|
mOwner->GetContent(&cont);
|
|
|
|
|
|
|
|
if (nsnull != cont)
|
|
|
|
{
|
|
|
|
PRBool haskids = PR_FALSE;
|
|
|
|
|
|
|
|
cont->CanContainChildren(haskids);
|
|
|
|
|
|
|
|
if (PR_TRUE == haskids)
|
|
|
|
{
|
|
|
|
PRInt32 numkids, idx, numparams = 0;
|
|
|
|
|
|
|
|
cont->ChildCount(numkids);
|
|
|
|
|
|
|
|
//first pass, count number of param tags...
|
|
|
|
|
|
|
|
for (idx = 0; idx < numkids; idx++)
|
|
|
|
{
|
|
|
|
nsIContent *kid;
|
|
|
|
|
|
|
|
cont->ChildAt(idx, kid);
|
|
|
|
|
|
|
|
if (nsnull != kid)
|
|
|
|
{
|
|
|
|
nsIAtom *atom;
|
|
|
|
|
|
|
|
kid->GetTag(atom);
|
|
|
|
|
|
|
|
if (nsnull != atom)
|
|
|
|
{
|
|
|
|
if (atom == nsHTMLAtoms::param)
|
|
|
|
numparams++;
|
|
|
|
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(kid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numparams > 0)
|
|
|
|
{
|
|
|
|
//now we need to create arrays
|
|
|
|
//representing the parameter name/value pairs...
|
|
|
|
|
|
|
|
mParamNames = (char **)PR_Calloc(sizeof(char *) * numparams, 1);
|
|
|
|
mParamVals = (char **)PR_Calloc(sizeof(char *) * numparams, 1);
|
|
|
|
|
|
|
|
if ((nsnull != mParamNames) && (nsnull != mParamVals))
|
|
|
|
{
|
|
|
|
for (idx = 0; idx < numkids; idx++)
|
|
|
|
{
|
|
|
|
nsIContent *kid;
|
|
|
|
|
|
|
|
cont->ChildAt(idx, kid);
|
|
|
|
|
|
|
|
if (nsnull != kid)
|
|
|
|
{
|
|
|
|
nsIAtom *atom;
|
|
|
|
|
|
|
|
kid->GetTag(atom);
|
|
|
|
|
|
|
|
if (nsnull != atom)
|
|
|
|
{
|
|
|
|
if (atom == nsHTMLAtoms::param)
|
|
|
|
{
|
|
|
|
nsAutoString val, name;
|
|
|
|
|
|
|
|
//add param to list...
|
|
|
|
|
|
|
|
if ((NS_CONTENT_ATTR_HAS_VALUE == kid->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::name, name)) &&
|
|
|
|
(NS_CONTENT_ATTR_HAS_VALUE == kid->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, val)))
|
|
|
|
{
|
2000-05-27 02:24:35 +04:00
|
|
|
|
|
|
|
/* Changing to ToNewUTF8String addressing 17169, 39789
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
mParamNames[mNumParams] = (char *)PR_Malloc(name.Length() + 1);
|
|
|
|
mParamVals[mNumParams] = (char *)PR_Malloc(val.Length() + 1);
|
|
|
|
|
|
|
|
if ((nsnull != mParamNames[mNumParams]) &&
|
|
|
|
(nsnull != mParamVals[mNumParams]))
|
|
|
|
{
|
|
|
|
name.ToCString(mParamNames[mNumParams], name.Length() + 1);
|
|
|
|
val.ToCString(mParamVals[mNumParams], val.Length() + 1);
|
|
|
|
|
|
|
|
mNumParams++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nsnull != mParamNames[mNumParams])
|
|
|
|
{
|
|
|
|
PR_Free(mParamNames[mNumParams]);
|
|
|
|
mParamNames[mNumParams] = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mParamVals[mNumParams])
|
|
|
|
{
|
|
|
|
PR_Free(mParamVals[mNumParams]);
|
|
|
|
mParamVals[mNumParams] = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2000-05-27 02:24:35 +04:00
|
|
|
*/
|
|
|
|
mParamNames[mNumParams] = name.ToNewUTF8String();
|
|
|
|
mParamVals[mNumParams] = val.ToNewUTF8String();
|
|
|
|
mNumParams++;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(kid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_OK;
|
|
|
|
NS_RELEASE(cont);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n = mNumParams;
|
|
|
|
names = (const char **)mParamNames;
|
|
|
|
values = (const char **)mParamVals;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetParameter(const char* name, const char* *result)
|
|
|
|
{
|
|
|
|
PRInt32 count;
|
|
|
|
|
|
|
|
if (nsnull == mParamNames)
|
|
|
|
{
|
|
|
|
PRUint16 numattrs;
|
|
|
|
const char * const *names, * const *vals;
|
|
|
|
|
|
|
|
GetParameters(numattrs, names, vals);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count = 0; count < mNumParams; count++)
|
|
|
|
{
|
|
|
|
if (0 == PL_strcasecmp(mParamNames[count], name))
|
|
|
|
{
|
|
|
|
*result = mParamVals[count];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count >= mNumParams)
|
|
|
|
*result = "";
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-03 06:51:39 +04:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetDocumentBase(const char* *result)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
1999-08-03 06:51:39 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (nsnull == mDocumentBase) {
|
|
|
|
if (nsnull == mContext) {
|
|
|
|
*result = nsnull;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mContext->GetShell(getter_AddRefs(shell));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
shell->GetDocument(getter_AddRefs(doc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> docURL( dont_AddRef(doc->GetDocumentURL()) );
|
|
|
|
|
1999-08-03 06:51:39 +04:00
|
|
|
rv = docURL->GetSpec(&mDocumentBase);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
1999-08-03 06:51:39 +04:00
|
|
|
if (rv == NS_OK)
|
|
|
|
*result = mDocumentBase;
|
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
1999-08-03 06:51:39 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetDocumentEncoding(const char* *result)
|
|
|
|
{
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("instance owner getdocumentencoding called\n");
|
1999-07-07 06:33:17 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetAlignment(const char* *result)
|
|
|
|
{
|
|
|
|
return GetAttribute("ALIGN", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetWidth(PRUint32 *result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
const char *width;
|
|
|
|
|
|
|
|
rv = GetAttribute("WIDTH", &width);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
if (*result != 0)
|
1999-09-08 04:12:26 +04:00
|
|
|
{
|
1999-11-11 03:00:07 +03:00
|
|
|
*result = 0;
|
|
|
|
|
2000-03-28 05:01:49 +04:00
|
|
|
PRInt32 attr = atol(width);
|
1999-09-08 04:12:26 +04:00
|
|
|
|
|
|
|
if(nsnull == strchr(width, '%'))
|
2000-03-28 05:01:49 +04:00
|
|
|
*result = (PRUint32)attr;
|
1999-09-08 04:12:26 +04:00
|
|
|
else
|
|
|
|
{
|
1999-11-11 03:00:07 +03:00
|
|
|
if(mContext == nsnull)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-09-08 04:12:26 +04:00
|
|
|
attr = (attr > 100) ? 100 : attr;
|
|
|
|
attr = (attr < 0) ? 0 : attr;
|
|
|
|
|
|
|
|
float t2p;
|
1999-11-11 03:00:07 +03:00
|
|
|
|
1999-09-08 04:12:26 +04:00
|
|
|
mContext->GetTwipsToPixels(&t2p);
|
1999-11-11 03:00:07 +03:00
|
|
|
|
1999-09-08 04:12:26 +04:00
|
|
|
nsRect rect;
|
|
|
|
mContext->GetVisibleArea(rect);
|
1999-11-11 03:00:07 +03:00
|
|
|
|
|
|
|
nscoord w = rect.width;
|
|
|
|
|
|
|
|
if(mOwner == nsnull)
|
|
|
|
{
|
|
|
|
*result = NSTwipsToIntPixels(attr*w/100, t2p);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now make it nicely fit counting margins
|
2000-10-30 07:11:59 +03:00
|
|
|
nsIFrame *containingBlock=nsnull;
|
|
|
|
rv = GetContainingBlock(mOwner, &containingBlock);
|
|
|
|
if (NS_SUCCEEDED(rv) && containingBlock)
|
|
|
|
{
|
|
|
|
containingBlock->GetRect(rect);
|
|
|
|
w -= 2*rect.x;
|
|
|
|
// XXX: this math seems suspect to me. Is the parent's margin really twice the x-offset?
|
|
|
|
// in CSS, a frame can have independent left and right margins
|
|
|
|
}
|
1999-11-11 03:00:07 +03:00
|
|
|
*result = NSTwipsToIntPixels(attr*w/100, t2p);
|
1999-09-08 04:12:26 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
else
|
|
|
|
*result = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*result = 0;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetHeight(PRUint32 *result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
const char *height;
|
|
|
|
|
|
|
|
rv = GetAttribute("HEIGHT", &height);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
if (*result != 0)
|
1999-09-08 04:12:26 +04:00
|
|
|
{
|
1999-11-11 03:00:07 +03:00
|
|
|
*result = 0;
|
|
|
|
|
2000-03-28 05:01:49 +04:00
|
|
|
PRInt32 attr = atol(height);
|
1999-09-08 04:12:26 +04:00
|
|
|
|
|
|
|
if(nsnull == strchr(height, '%'))
|
2000-03-28 05:01:49 +04:00
|
|
|
*result = (PRUint32)attr;
|
1999-09-08 04:12:26 +04:00
|
|
|
else
|
|
|
|
{
|
1999-11-11 03:00:07 +03:00
|
|
|
if(mContext == nsnull)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-09-08 04:12:26 +04:00
|
|
|
attr = (attr > 100) ? 100 : attr;
|
|
|
|
attr = (attr < 0) ? 0 : attr;
|
|
|
|
|
|
|
|
float t2p;
|
1999-11-11 03:00:07 +03:00
|
|
|
|
1999-09-08 04:12:26 +04:00
|
|
|
mContext->GetTwipsToPixels(&t2p);
|
1999-11-11 03:00:07 +03:00
|
|
|
|
1999-09-08 04:12:26 +04:00
|
|
|
nsRect rect;
|
|
|
|
mContext->GetVisibleArea(rect);
|
1999-11-11 03:00:07 +03:00
|
|
|
|
|
|
|
nscoord h = rect.height;
|
|
|
|
|
|
|
|
if(mOwner == nsnull)
|
|
|
|
{
|
|
|
|
*result = NSTwipsToIntPixels(attr*h/100, t2p);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now make it nicely fit counting margins
|
2000-05-23 01:36:35 +04:00
|
|
|
nsIFrame *containingBlock=nsnull;
|
|
|
|
rv = GetContainingBlock(mOwner, &containingBlock);
|
|
|
|
if (NS_SUCCEEDED(rv) && containingBlock)
|
|
|
|
{
|
|
|
|
containingBlock->GetRect(rect);
|
|
|
|
h -= 2*rect.y;
|
2000-10-30 07:11:59 +03:00
|
|
|
// XXX: this math seems suspect to me. Is the parent's margin really twice the x-offset?
|
|
|
|
// in CSS, a frame can have independent top and bottom margins
|
2000-05-23 01:36:35 +04:00
|
|
|
}
|
1999-11-11 03:00:07 +03:00
|
|
|
*result = NSTwipsToIntPixels(attr*h/100, t2p);
|
1999-09-08 04:12:26 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
else
|
|
|
|
*result = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*result = 0;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-23 01:36:35 +04:00
|
|
|
|
2000-10-30 07:11:59 +03:00
|
|
|
// it would indicate a serious error in the frame model if aContainingBlock were null when
|
|
|
|
// GetContainingBlock returns
|
2000-05-23 01:36:35 +04:00
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::GetContainingBlock(nsIFrame *aFrame,
|
|
|
|
nsIFrame **aContainingBlock)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFrame);
|
|
|
|
NS_ENSURE_ARG_POINTER(aContainingBlock);
|
|
|
|
|
|
|
|
*aContainingBlock = nsnull;
|
|
|
|
nsIFrame *containingBlock = aFrame;
|
|
|
|
while (containingBlock) {
|
|
|
|
PRBool isContainingBlock=PR_FALSE;
|
|
|
|
nsresult rv = containingBlock->IsPercentageBase(isContainingBlock);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (isContainingBlock)
|
|
|
|
{
|
|
|
|
*aContainingBlock = containingBlock;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
containingBlock->GetParent(&containingBlock);
|
|
|
|
}
|
2000-10-30 07:11:59 +03:00
|
|
|
NS_POSTCONDITION(*aContainingBlock, "bad frame model, this object frame has no containing block");
|
2000-05-23 01:36:35 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetBorderVertSpace(PRUint32 *result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
const char *vspace;
|
|
|
|
|
|
|
|
rv = GetAttribute("VSPACE", &vspace);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
if (*result != 0)
|
|
|
|
*result = (PRUint32)atol(vspace);
|
|
|
|
else
|
|
|
|
*result = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*result = 0;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetBorderHorizSpace(PRUint32 *result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
const char *hspace;
|
|
|
|
|
|
|
|
rv = GetAttribute("HSPACE", &hspace);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
if (*result != 0)
|
|
|
|
*result = (PRUint32)atol(hspace);
|
|
|
|
else
|
|
|
|
*result = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*result = 0;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetUniqueID(PRUint32 *result)
|
|
|
|
{
|
|
|
|
*result = (PRUint32)mContext;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetCode(const char* *result)
|
|
|
|
{
|
|
|
|
return GetAttribute("CODE", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetCodeBase(const char* *result)
|
|
|
|
{
|
|
|
|
return GetAttribute("CODEBASE", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetArchive(const char* *result)
|
|
|
|
{
|
|
|
|
return GetAttribute("ARCHIVE", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetName(const char* *result)
|
|
|
|
{
|
|
|
|
return GetAttribute("NAME", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetMayScript(PRBool *result)
|
|
|
|
{
|
|
|
|
const char* unused;
|
|
|
|
*result = (GetAttribute("MAYSCRIPT", &unused) == NS_OK ? PR_TRUE : PR_FALSE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here's where we forward events to plugins.
|
|
|
|
|
|
|
|
#ifdef XP_MAC
|
2000-06-21 03:10:06 +04:00
|
|
|
|
|
|
|
#if TARGET_CARBON
|
|
|
|
inline Boolean OSEventAvail(EventMask mask, EventRecord* event) { return EventAvail(mask, event); }
|
|
|
|
#endif
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
static void GUItoMacEvent(const nsGUIEvent& anEvent, EventRecord& aMacEvent)
|
|
|
|
{
|
2001-01-17 23:04:09 +03:00
|
|
|
::OSEventAvail(0, &aMacEvent);
|
|
|
|
|
|
|
|
switch (anEvent.message) {
|
|
|
|
case NS_GOTFOCUS:
|
|
|
|
aMacEvent.what = nsPluginEventType_GetFocusEvent;
|
|
|
|
break;
|
|
|
|
case NS_LOSTFOCUS:
|
|
|
|
aMacEvent.what = nsPluginEventType_LoseFocusEvent;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
case NS_MOUSE_ENTER:
|
|
|
|
aMacEvent.what = nsPluginEventType_AdjustCursorEvent;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
aMacEvent.what = nullEvent;
|
|
|
|
break;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-01-17 23:04:09 +03:00
|
|
|
/*=============== nsIKeyListener ======================*/
|
|
|
|
nsresult nsPluginInstanceOwner::KeyDown(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
return DispatchKeyToPlugin(aKeyEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPluginInstanceOwner::KeyUp(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
return DispatchKeyToPlugin(aKeyEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPluginInstanceOwner::KeyPress(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
// If this event is going to the plugin, we want to kill it.
|
|
|
|
// Not actually sending keypress to the plugin, since we didn't before.
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
aKeyEvent->PreventBubble();
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPluginInstanceOwner::DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aKeyEvent));
|
|
|
|
if (privateEvent) {
|
|
|
|
nsKeyEvent* keyEvent = nsnull;
|
|
|
|
privateEvent->GetInternalNSEvent((nsEvent**)&keyEvent);
|
|
|
|
if (keyEvent) {
|
|
|
|
nsEventStatus rv = ProcessEvent(*keyEvent);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == rv) {
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
aKeyEvent->PreventBubble();
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchKeyToPlugin failed, keyEvent null");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchKeyToPlugin failed, privateEvent null");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-10-18 03:13:30 +04:00
|
|
|
|
|
|
|
/*=============== nsIMouseListener ======================*/
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aMouseEvent));
|
|
|
|
if (privateEvent) {
|
|
|
|
nsMouseEvent* mouseEvent = nsnull;
|
|
|
|
privateEvent->GetInternalNSEvent((nsEvent**)&mouseEvent);
|
|
|
|
if (mouseEvent) {
|
|
|
|
nsEventStatus rv = ProcessEvent(*mouseEvent);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == rv) {
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::MouseDown failed, mouseEvent null");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::MouseDown failed, privateEvent null");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseOver(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseOut(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
nsEventStatus nsPluginInstanceOwner::ProcessEvent(const nsGUIEvent& anEvent)
|
|
|
|
{
|
2001-01-12 02:56:35 +03:00
|
|
|
nsEventStatus rv = nsEventStatus_eIgnore;
|
2001-01-11 02:51:07 +03:00
|
|
|
if (!mInstance) // if mInstance is null, we shouldn't be here
|
|
|
|
return rv;
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
#ifdef XP_MAC
|
2001-01-12 02:56:35 +03:00
|
|
|
if (mWidget != NULL) { // check for null mWidget
|
|
|
|
EventRecord* event = (EventRecord*)anEvent.nativeMsg;
|
|
|
|
if (event == NULL || event->what == nullEvent) {
|
|
|
|
EventRecord macEvent;
|
|
|
|
GUItoMacEvent(anEvent, macEvent);
|
|
|
|
event = &macEvent;
|
|
|
|
}
|
|
|
|
nsPluginPort* port = (nsPluginPort*)mWidget->GetNativeData(NS_NATIVE_PLUGIN_PORT);
|
|
|
|
nsPluginEvent pluginEvent = { event, nsPluginPlatformWindowRef(port->port) };
|
|
|
|
PRBool eventHandled = PR_FALSE;
|
|
|
|
mInstance->HandleEvent(&pluginEvent, &eventHandled);
|
|
|
|
if (eventHandled && anEvent.message != NS_MOUSE_LEFT_BUTTON_DOWN)
|
|
|
|
rv = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//~~~
|
|
|
|
#ifdef XP_WIN
|
2001-01-12 02:56:35 +03:00
|
|
|
nsPluginEvent * pPluginEvent = (nsPluginEvent *)anEvent.nativeMsg;
|
|
|
|
PRBool eventHandled = PR_FALSE;
|
|
|
|
mInstance->HandleEvent(pPluginEvent, &eventHandled);
|
|
|
|
if (eventHandled)
|
|
|
|
rv = nsEventStatus_eConsumeNoDefault;
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:13:30 +04:00
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::Destroy()
|
|
|
|
{
|
|
|
|
// Unregister mouse event listener
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mOwner->GetContent(getter_AddRefs(content));
|
|
|
|
if (content) {
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));
|
|
|
|
if (receiver) {
|
|
|
|
nsCOMPtr<nsIDOMMouseListener> mouseListener;
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMMouseListener), getter_AddRefs(mouseListener));
|
|
|
|
if (mouseListener) {
|
|
|
|
receiver->RemoveEventListenerByIID(mouseListener, NS_GET_IID(nsIDOMMouseListener));
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "Unable to remove event listener for plugin");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "plugin was not an event listener");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "plugin had no content");
|
2001-01-17 23:04:09 +03:00
|
|
|
|
|
|
|
// Unregister key event listener;
|
|
|
|
if (content) {
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));
|
|
|
|
if (receiver) {
|
|
|
|
nsCOMPtr<nsIDOMKeyListener> keyListener;
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMKeyListener), getter_AddRefs(keyListener));
|
|
|
|
if (keyListener) {
|
|
|
|
receiver->RemoveEventListenerByIID(keyListener, NS_GET_IID(nsIDOMKeyListener));
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "Unable to remove event listener for plugin");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "plugin was not an event listener");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "plugin had no content");
|
2000-10-18 03:13:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
// Paints are handled differently, so we just simulate an update event.
|
|
|
|
|
|
|
|
void nsPluginInstanceOwner::Paint(const nsRect& aDirtyRect, PRUint32 ndc)
|
|
|
|
{
|
|
|
|
#ifdef XP_MAC
|
2000-09-29 03:29:26 +04:00
|
|
|
if (mInstance != NULL) {
|
2000-10-18 01:45:39 +04:00
|
|
|
|
2000-09-29 03:29:26 +04:00
|
|
|
nsPluginPort* pluginPort = GetPluginPort();
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2000-10-18 01:45:39 +04:00
|
|
|
#ifdef DO_DIRTY_INTERSECT // aDirtyRect isn't always correct, see bug 56128
|
|
|
|
nsPoint rel(aDirtyRect.x, aDirtyRect.y);
|
|
|
|
nsPoint abs(0,0);
|
|
|
|
nsCOMPtr<nsIWidget> containerWidget;
|
|
|
|
|
|
|
|
// Convert dirty rect relative coordinates to absolute and also get the containerWidget
|
|
|
|
ConvertRelativeToWindowAbsolute(mOwner, mContext, rel, abs, *getter_AddRefs(containerWidget));
|
|
|
|
|
|
|
|
nsRect absDirtyRect = nsRect(abs.x, abs.y, aDirtyRect.width, aDirtyRect.height);
|
|
|
|
|
|
|
|
// Convert to absolute pixel values for the dirty rect
|
|
|
|
nsRect absDirtyRectInPixels;
|
|
|
|
ConvertTwipsToPixels(*mContext, absDirtyRect, absDirtyRectInPixels);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Add in child windows absolute position to get make the dirty rect
|
|
|
|
// relative to the top-level window.
|
|
|
|
nscoord absWidgetX = 0;
|
|
|
|
nscoord absWidgetY = 0;
|
|
|
|
nsRect widgetClip(0,0,0,0);
|
|
|
|
GetWidgetPosAndClip(mWidget,absWidgetX,absWidgetY,widgetClip);
|
|
|
|
|
|
|
|
#ifdef DO_DIRTY_INTERSECT // skip intersection for now because possible bad aDirtyRect
|
|
|
|
absDirtyRectInPixels.x += absWidgetX;
|
|
|
|
absDirtyRectInPixels.y += absWidgetY;
|
|
|
|
|
|
|
|
widgetClip.IntersectRect(widgetClip, absDirtyRectInPixels);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// set the port
|
|
|
|
mPluginWindow.x = absWidgetX;
|
|
|
|
mPluginWindow.y = absWidgetY;
|
|
|
|
|
|
|
|
|
|
|
|
// fix up the clipping region
|
|
|
|
mPluginWindow.clipRect.top = widgetClip.y;
|
|
|
|
mPluginWindow.clipRect.left = widgetClip.x;
|
|
|
|
mPluginWindow.clipRect.bottom = mPluginWindow.clipRect.top + widgetClip.height;
|
|
|
|
mPluginWindow.clipRect.right = mPluginWindow.clipRect.left + widgetClip.width;
|
|
|
|
|
2000-09-29 03:29:26 +04:00
|
|
|
EventRecord updateEvent;
|
|
|
|
::OSEventAvail(0, &updateEvent);
|
|
|
|
updateEvent.what = updateEvt;
|
|
|
|
updateEvent.message = UInt32(pluginPort->port);
|
|
|
|
|
|
|
|
nsPluginEvent pluginEvent = { &updateEvent, nsPluginPlatformWindowRef(pluginPort->port) };
|
|
|
|
PRBool eventHandled = PR_FALSE;
|
|
|
|
mInstance->HandleEvent(&pluginEvent, &eventHandled);
|
2001-01-12 02:56:35 +03:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//~~~
|
|
|
|
#ifdef XP_WIN
|
2001-01-12 02:56:35 +03:00
|
|
|
nsPluginEvent pluginEvent;
|
1999-07-07 06:33:17 +04:00
|
|
|
pluginEvent.event = 0x000F; //!!! This is bad, but is it better to include <windows.h> for WM_PAINT only?
|
|
|
|
pluginEvent.wParam = (uint32)ndc;
|
|
|
|
pluginEvent.lParam = nsnull;
|
2001-01-12 02:56:35 +03:00
|
|
|
PRBool eventHandled = PR_FALSE;
|
|
|
|
mInstance->HandleEvent(&pluginEvent, &eventHandled);
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here's how we give idle time to plugins.
|
|
|
|
|
2000-01-22 00:56:09 +03:00
|
|
|
NS_IMETHODIMP_(void) nsPluginInstanceOwner::Notify(nsITimer* /* timer */)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
#ifdef XP_MAC
|
2001-01-12 02:56:35 +03:00
|
|
|
// validate the plugin clipping information by syncing the plugin window info to
|
|
|
|
// reflect the current widget location. This makes sure that everything is updated
|
|
|
|
// correctly in the event of scrolling in the window.
|
|
|
|
FixUpPluginWindow();
|
|
|
|
if (mInstance != NULL) {
|
|
|
|
EventRecord idleEvent;
|
|
|
|
::OSEventAvail(0, &idleEvent);
|
|
|
|
idleEvent.what = nullEvent;
|
|
|
|
|
|
|
|
nsPluginPort* pluginPort = GetPluginPort();
|
|
|
|
nsPluginEvent pluginEvent = { &idleEvent, nsPluginPlatformWindowRef(pluginPort->port) };
|
|
|
|
|
|
|
|
PRBool eventHandled = PR_FALSE;
|
|
|
|
mInstance->HandleEvent(&pluginEvent, &eventHandled);
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif
|
|
|
|
|
2000-01-22 00:56:09 +03:00
|
|
|
#ifndef REPEATING_TIMERS
|
1999-07-07 06:33:17 +04:00
|
|
|
// reprime the timer? currently have to create a new timer for each call, which is
|
|
|
|
// kind of wasteful. need to get periodic timers working on all platforms.
|
2000-05-17 06:49:35 +04:00
|
|
|
nsresult rv;
|
2000-09-14 03:57:52 +04:00
|
|
|
mPluginTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
|
2000-05-17 06:49:35 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-07-07 06:33:17 +04:00
|
|
|
mPluginTimer->Init(this, 1000 / 60);
|
2000-01-22 00:56:09 +03:00
|
|
|
#endif
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsPluginInstanceOwner::CancelTimer()
|
|
|
|
{
|
2001-01-12 02:56:35 +03:00
|
|
|
if (mPluginTimer) {
|
|
|
|
mPluginTimer->Cancel();
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::Init(nsIPresContext* aPresContext, nsObjectFrame *aFrame)
|
|
|
|
{
|
|
|
|
//do not addref to avoid circular refs. MMP
|
|
|
|
mContext = aPresContext;
|
|
|
|
mOwner = aFrame;
|
2000-10-18 03:13:30 +04:00
|
|
|
|
|
|
|
// Register mouse listener
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mOwner->GetContent(getter_AddRefs(content));
|
|
|
|
if (content) {
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));
|
|
|
|
if (receiver) {
|
|
|
|
nsCOMPtr<nsIDOMMouseListener> mouseListener;
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMMouseListener), getter_AddRefs(mouseListener));
|
|
|
|
if (mouseListener) {
|
|
|
|
receiver->AddEventListenerByIID(mouseListener, NS_GET_IID(nsIDOMMouseListener));
|
2001-01-17 23:04:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Register key listener
|
|
|
|
if (content) {
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));
|
|
|
|
if (receiver) {
|
|
|
|
nsCOMPtr<nsIDOMKeyListener> keyListener;
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMKeyListener), getter_AddRefs(keyListener));
|
|
|
|
if (keyListener) {
|
|
|
|
receiver->AddEventListener(NS_LITERAL_STRING("keypress"), keyListener, PR_TRUE);
|
|
|
|
receiver->AddEventListener(NS_LITERAL_STRING("keydown"), keyListener, PR_TRUE);
|
|
|
|
receiver->AddEventListener(NS_LITERAL_STRING("keyup"), keyListener, PR_TRUE);
|
2000-10-18 03:13:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-01-17 23:04:09 +03:00
|
|
|
|
2000-10-18 03:13:30 +04:00
|
|
|
NS_ASSERTION(PR_FALSE, "plugin could not be added as a mouse listener");
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginPort* nsPluginInstanceOwner::GetPluginPort()
|
|
|
|
{
|
|
|
|
//!!! Port must be released for windowless plugins on Windows, because it is HDC !!!
|
|
|
|
|
|
|
|
nsPluginPort* result = NULL;
|
2001-01-12 02:56:35 +03:00
|
|
|
if (mWidget != NULL)
|
1999-07-07 06:33:17 +04:00
|
|
|
{//~~~
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if(mPluginWindow.type == nsPluginWindowType_Drawable)
|
|
|
|
result = (nsPluginPort*) mWidget->GetNativeData(NS_NATIVE_GRAPHIC);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
result = (nsPluginPort*) mWidget->GetNativeData(NS_NATIVE_PLUGIN_PORT);
|
2001-01-12 02:56:35 +03:00
|
|
|
}
|
|
|
|
return result;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//~~~
|
|
|
|
void nsPluginInstanceOwner::ReleasePluginPort(nsPluginPort * pluginPort)
|
|
|
|
{
|
|
|
|
#ifdef XP_WIN
|
2001-01-12 02:56:35 +03:00
|
|
|
if (mWidget != NULL)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
if(mPluginWindow.type == nsPluginWindowType_Drawable)
|
|
|
|
mWidget->FreeNativeData((HDC)pluginPort, NS_NATIVE_GRAPHIC);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void)
|
|
|
|
{
|
|
|
|
nsIView *view;
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2001-01-12 02:56:35 +03:00
|
|
|
float p2t;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if (nsnull != mOwner)
|
|
|
|
{
|
|
|
|
// Create view if necessary
|
|
|
|
|
1999-10-26 08:44:41 +04:00
|
|
|
mOwner->GetView(mContext, &view);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if (nsnull == view)
|
|
|
|
{
|
|
|
|
PRBool windowless;
|
|
|
|
|
|
|
|
mInstance->GetValue(nsPluginInstanceVariable_WindowlessBool, (void *)&windowless);
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
// always create widgets in Twips, not pixels
|
|
|
|
mContext->GetScaledPixelsToTwips(&p2t);
|
1999-10-26 08:44:41 +04:00
|
|
|
rv = mOwner->CreateWidget(mContext,
|
2001-01-12 02:56:35 +03:00
|
|
|
NSIntPixelsToTwips(mPluginWindow.width, p2t),
|
|
|
|
NSIntPixelsToTwips(mPluginWindow.height, p2t),
|
1999-07-07 06:33:17 +04:00
|
|
|
windowless);
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
1999-10-26 08:44:41 +04:00
|
|
|
mOwner->GetView(mContext, &view);
|
2000-07-20 03:46:43 +04:00
|
|
|
if (view)
|
|
|
|
view->GetWidget(mWidget);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if (PR_TRUE == windowless)
|
|
|
|
{
|
|
|
|
mPluginWindow.type = nsPluginWindowType_Drawable;
|
|
|
|
mPluginWindow.window = nsnull; //~~~ this needs to be a HDC according to the spec,
|
|
|
|
// but I do not see the right way to release it
|
|
|
|
// so let's postpone passing HDC till paint event
|
|
|
|
// when it is really needed. Change spec?
|
|
|
|
}
|
2000-07-20 03:46:43 +04:00
|
|
|
else if (mWidget)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2000-05-27 02:24:35 +04:00
|
|
|
mWidget->Resize(mPluginWindow.width, mPluginWindow.height, PR_FALSE);
|
1999-07-07 06:33:17 +04:00
|
|
|
mPluginWindow.window = GetPluginPort();
|
|
|
|
mPluginWindow.type = nsPluginWindowType_Window;
|
|
|
|
|
|
|
|
#if defined(XP_MAC)
|
|
|
|
// start a periodic timer to provide null events to the plugin instance.
|
2000-09-14 03:57:52 +04:00
|
|
|
mPluginTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
|
1999-07-07 06:33:17 +04:00
|
|
|
if (rv == NS_OK)
|
2001-01-12 02:56:35 +03:00
|
|
|
rv = mPluginTimer->Init(this, 1000 / 60, NS_PRIORITY_NORMAL, NS_TYPE_REPEATING_SLACK);
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPluginInstanceOwner::SetPluginHost(nsIPluginHost* aHost)
|
|
|
|
{
|
|
|
|
if(mPluginHost != nsnull)
|
|
|
|
NS_RELEASE(mPluginHost);
|
|
|
|
|
|
|
|
mPluginHost = aHost;
|
2000-09-12 00:27:25 +04:00
|
|
|
NS_IF_ADDREF(mPluginHost);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
2000-09-29 03:29:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
// Mac specific code to fix up the port location and clipping region
|
|
|
|
#ifdef XP_MAC
|
|
|
|
// calculate the absolute position and clip for a widget
|
|
|
|
// and use other windows in calculating the clip
|
|
|
|
static void GetWidgetPosAndClip(nsIWidget* aWidget,nscoord& aAbsX, nscoord& aAbsY,
|
|
|
|
nsRect& aClipRect)
|
|
|
|
{
|
|
|
|
aWidget->GetBounds(aClipRect);
|
|
|
|
aAbsX = aClipRect.x;
|
|
|
|
aAbsY = aClipRect.y;
|
|
|
|
|
|
|
|
nscoord ancestorX = -aClipRect.x, ancestorY = -aClipRect.y;
|
|
|
|
// Calculate clipping relative to the widget passed in
|
|
|
|
aClipRect.x = 0;
|
|
|
|
aClipRect.y = 0;
|
|
|
|
|
|
|
|
// Gather up the absolute position of the widget
|
|
|
|
// + clip window
|
|
|
|
nsCOMPtr<nsIWidget> widget = getter_AddRefs(aWidget->GetParent());
|
|
|
|
while (widget != nsnull) {
|
|
|
|
nsRect wrect;
|
|
|
|
widget->GetClientBounds(wrect);
|
|
|
|
nscoord wx, wy;
|
|
|
|
wx = wrect.x;
|
|
|
|
wy = wrect.y;
|
|
|
|
wrect.x = ancestorX;
|
|
|
|
wrect.y = ancestorY;
|
|
|
|
aClipRect.IntersectRect(aClipRect, wrect);
|
|
|
|
aAbsX += wx;
|
|
|
|
aAbsY += wy;
|
|
|
|
widget = getter_AddRefs(widget->GetParent());
|
|
|
|
if (widget == nsnull) {
|
|
|
|
// Don't include the top-level windows offset
|
2000-10-29 02:17:53 +04:00
|
|
|
// printf("Top level window offset %d %d\n", wx, wy);
|
2000-09-29 03:29:26 +04:00
|
|
|
aAbsX -= wx;
|
|
|
|
aAbsY -= wy;
|
|
|
|
}
|
|
|
|
ancestorX -=wx;
|
|
|
|
ancestorY -=wy;
|
|
|
|
}
|
|
|
|
|
2000-10-18 01:45:39 +04:00
|
|
|
aClipRect.x += aAbsX;
|
|
|
|
aClipRect.y += aAbsY;
|
2000-09-29 03:29:26 +04:00
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
//printf("--------------\n");
|
|
|
|
//printf("Widget clip X %d Y %d rect %d %d %d %d\n", aAbsX, aAbsY, aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height );
|
|
|
|
//printf("--------------\n");
|
2000-09-29 03:29:26 +04:00
|
|
|
}
|
2000-10-18 01:45:39 +04:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef DO_DIRTY_INTERSECT
|
|
|
|
// Convert from a frame relative coordinate to a coordinate relative to its
|
|
|
|
// containing window
|
|
|
|
static void ConvertRelativeToWindowAbsolute(nsIFrame* aFrame, nsIPresContext* aPresContext, nsPoint& aRel, nsPoint& aAbs, nsIWidget *&
|
|
|
|
aContainerWidget)
|
|
|
|
{
|
|
|
|
aAbs.x = 0;
|
|
|
|
aAbs.y = 0;
|
|
|
|
|
|
|
|
nsIView *view = nsnull;
|
|
|
|
// See if this frame has a view
|
|
|
|
aFrame->GetView(aPresContext, &view);
|
|
|
|
if (nsnull == view) {
|
|
|
|
// Calculate frames offset from its nearest view
|
|
|
|
aFrame->GetOffsetFromView(aPresContext,
|
|
|
|
aAbs,
|
|
|
|
&view);
|
|
|
|
} else {
|
|
|
|
// Store frames offset from its view.
|
|
|
|
nsRect rect;
|
|
|
|
aFrame->GetRect(rect);
|
|
|
|
aAbs.x = rect.x;
|
|
|
|
aAbs.y = rect.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view != nsnull) {
|
|
|
|
// Caclulate the views offset from its nearest widget
|
|
|
|
|
|
|
|
nscoord viewx = 0;
|
|
|
|
nscoord viewy = 0;
|
|
|
|
view->GetWidget(aContainerWidget);
|
|
|
|
if (nsnull == aContainerWidget) {
|
|
|
|
view->GetOffsetFromWidget(&viewx, &viewy, aContainerWidget/**getter_AddRefs(widget)*/);
|
|
|
|
aAbs.x += viewx;
|
|
|
|
aAbs.y += viewy;
|
|
|
|
|
|
|
|
|
|
|
|
// GetOffsetFromWidget does not include the views offset, so we need to add
|
|
|
|
// that in.
|
|
|
|
nsRect bounds;
|
|
|
|
view->GetBounds(bounds);
|
|
|
|
aAbs.x += bounds.x;
|
|
|
|
aAbs.y += bounds.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect widgetBounds;
|
|
|
|
aContainerWidget->GetBounds(widgetBounds);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(PR_FALSE, "the object frame does not have a view");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add relative coordinate to the absolute coordinate that has been calculated
|
|
|
|
aAbs += aRel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from a frame relative coordinate to a coordinate relative to its
|
|
|
|
// containing window
|
|
|
|
static void ConvertTwipsToPixels(nsIPresContext& aPresContext, nsRect& aTwipsRect, nsRect& aPixelRect)
|
|
|
|
{
|
|
|
|
float t2p;
|
|
|
|
aPresContext.GetTwipsToPixels(&t2p);
|
|
|
|
aPixelRect.x = NSTwipsToIntPixels(aTwipsRect.x, t2p);
|
|
|
|
aPixelRect.y = NSTwipsToIntPixels(aTwipsRect.y, t2p);
|
|
|
|
aPixelRect.width = NSTwipsToIntPixels(aTwipsRect.width, t2p);
|
|
|
|
aPixelRect.height = NSTwipsToIntPixels(aTwipsRect.height, t2p);
|
|
|
|
}
|
2001-01-12 02:56:35 +03:00
|
|
|
#endif // DO_DIRTY_INTERSECT
|
|
|
|
|
|
|
|
void nsPluginInstanceOwner::FixUpPluginWindow()
|
|
|
|
{
|
|
|
|
if (mWidget) {
|
|
|
|
nscoord absWidgetX = 0;
|
|
|
|
nscoord absWidgetY = 0;
|
|
|
|
nsRect widgetClip(0,0,0,0);
|
|
|
|
GetWidgetPosAndClip(mWidget,absWidgetX,absWidgetY,widgetClip);
|
|
|
|
|
|
|
|
// set the port coordinates
|
|
|
|
mPluginWindow.x = absWidgetX;
|
|
|
|
mPluginWindow.y = absWidgetY;
|
|
|
|
|
|
|
|
// fix up the clipping region
|
|
|
|
mPluginWindow.clipRect.top = widgetClip.y;
|
|
|
|
mPluginWindow.clipRect.left = widgetClip.x;
|
|
|
|
mPluginWindow.clipRect.bottom = mPluginWindow.clipRect.top + widgetClip.height;
|
|
|
|
mPluginWindow.clipRect.right = mPluginWindow.clipRect.left + widgetClip.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // XP_MAC
|