1998-07-15 00:22:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS"
|
|
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
* the License for the specific language governing rights and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsLeafFrame.h"
|
|
|
|
#include "nsCSSLayout.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsViewsCID.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
1998-07-23 20:35:43 +00:00
|
|
|
#include "nsIPluginHost.h"
|
1998-08-01 23:02:14 +00:00
|
|
|
#include "nsplugin.h"
|
1998-07-23 20:35:43 +00:00
|
|
|
#include "nsString.h"
|
1998-07-27 23:08:52 +00:00
|
|
|
#include "nsIContentViewerContainer.h"
|
1998-07-23 20:35:43 +00:00
|
|
|
#include "prmem.h"
|
1998-08-05 04:22:51 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURL.h"
|
1998-09-15 03:46:52 +00:00
|
|
|
#include "nsIPluginInstanceOwner.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "nsILinkHandler.h"
|
1998-07-15 00:22:30 +00:00
|
|
|
|
1998-07-29 19:33:48 +00:00
|
|
|
// XXX For temporary paint code
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
class nsObjectFrame;
|
|
|
|
|
|
|
|
class nsPluginInstanceOwner : public nsIPluginInstanceOwner {
|
|
|
|
public:
|
|
|
|
nsPluginInstanceOwner();
|
|
|
|
~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 GetAttributes(PRUint16& n, const char*const*& names,
|
|
|
|
const char*const*& values);
|
|
|
|
|
|
|
|
NS_IMETHOD GetAttribute(const char* name, const char* *result);
|
|
|
|
|
|
|
|
NS_IMETHOD CreateWidget(void);
|
|
|
|
|
|
|
|
NS_IMETHOD GetURL(const char *aURL, const char *aTarget, void *aPostData);
|
|
|
|
|
|
|
|
//locals
|
|
|
|
|
|
|
|
NS_IMETHOD Init(nsIPresContext *aPresContext, nsObjectFrame *aFrame);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsPluginWindow mPluginWindow;
|
|
|
|
nsIPluginInstance *mInstance;
|
|
|
|
nsObjectFrame *mOwner;
|
|
|
|
PRInt32 mNumAttrs;
|
|
|
|
char **mAttrNames;
|
|
|
|
char **mAttrVals;
|
|
|
|
nsIWidget *mWidget;
|
|
|
|
nsIPresContext *mContext;
|
|
|
|
};
|
|
|
|
|
1998-07-15 00:22:30 +00:00
|
|
|
#define nsObjectFrameSuper nsLeafFrame
|
|
|
|
|
|
|
|
class nsObjectFrame : public nsObjectFrameSuper {
|
|
|
|
public:
|
|
|
|
nsObjectFrame(nsIContent* aContent, nsIFrame* aParentFrame);
|
|
|
|
|
1998-07-15 02:53:09 +00:00
|
|
|
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
1998-07-15 00:22:30 +00:00
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
NS_IMETHOD DidReflow(nsIPresContext& aPresContext,
|
1998-07-15 17:05:59 +00:00
|
|
|
nsDidReflowStatus aStatus);
|
1998-07-29 19:33:48 +00:00
|
|
|
NS_IMETHOD Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect);
|
1998-09-15 03:46:52 +00:00
|
|
|
NS_IMETHOD Scrolled(nsIView *aView);
|
|
|
|
|
|
|
|
//local methods
|
|
|
|
nsresult CreateWidget(nscoord aWidth, nscoord aHeight, PRBool aViewOnly);
|
|
|
|
nsresult GetFullURL(nsString& aFullURL);
|
1998-07-15 00:22:30 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsObjectFrame();
|
|
|
|
|
|
|
|
virtual void GetDesiredSize(nsIPresContext* aPresContext,
|
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsReflowMetrics& aDesiredSize);
|
|
|
|
|
1998-08-05 04:22:51 +00:00
|
|
|
|
|
|
|
nsresult SetURL(const nsString& aURLSpec);
|
|
|
|
nsresult SetBaseHREF(const nsString& aBaseHREF);
|
1998-09-15 03:46:52 +00:00
|
|
|
nsresult SetFullURL(const nsString& aURLSpec);
|
1998-08-05 04:22:51 +00:00
|
|
|
|
1998-08-01 23:02:14 +00:00
|
|
|
private:
|
1998-09-15 03:46:52 +00:00
|
|
|
nsPluginInstanceOwner *mInstanceOwner;
|
|
|
|
nsString *mURLSpec;
|
|
|
|
nsString *mBaseHREF;
|
|
|
|
nsString *mFullURL;
|
1998-07-15 00:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nsObjectFrame::nsObjectFrame(nsIContent* aContent, nsIFrame* aParentFrame)
|
|
|
|
: nsObjectFrameSuper(aContent, aParentFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsObjectFrame::~nsObjectFrame()
|
|
|
|
{
|
1998-09-15 03:46:52 +00:00
|
|
|
NS_IF_RELEASE(mInstanceOwner);
|
1998-08-05 04:22:51 +00:00
|
|
|
|
|
|
|
if (nsnull != mURLSpec)
|
|
|
|
{
|
|
|
|
delete mURLSpec;
|
|
|
|
mURLSpec = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mBaseHREF)
|
|
|
|
{
|
|
|
|
delete mBaseHREF;
|
|
|
|
mBaseHREF = nsnull;
|
|
|
|
}
|
1998-09-15 03:46:52 +00:00
|
|
|
|
|
|
|
if (nsnull != mFullURL)
|
|
|
|
{
|
|
|
|
delete mFullURL;
|
|
|
|
mFullURL = nsnull;
|
|
|
|
}
|
1998-07-15 00:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
|
|
|
|
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
|
|
|
|
static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID);
|
|
|
|
|
|
|
|
nsresult
|
1998-09-15 03:46:52 +00:00
|
|
|
nsObjectFrame::CreateWidget(nscoord aWidth, nscoord aHeight, PRBool aViewOnly)
|
1998-07-15 00:22:30 +00:00
|
|
|
{
|
|
|
|
nsIView* view;
|
|
|
|
|
|
|
|
// Create our view and widget
|
|
|
|
|
|
|
|
nsresult result =
|
1998-09-01 00:26:28 +00:00
|
|
|
nsRepository::CreateInstance(kViewCID, nsnull, kIViewIID,
|
1998-07-15 00:22:30 +00:00
|
|
|
(void **)&view);
|
|
|
|
if (NS_OK != result) {
|
|
|
|
return result;
|
|
|
|
}
|
1998-09-15 03:46:52 +00:00
|
|
|
nsIViewManager *viewMan; // need to release
|
1998-07-15 00:22:30 +00:00
|
|
|
|
|
|
|
nsRect boundBox(0, 0, aWidth, aHeight);
|
|
|
|
|
|
|
|
nsIFrame* parWithView;
|
|
|
|
nsIView *parView;
|
|
|
|
|
|
|
|
GetParentWithView(parWithView);
|
|
|
|
parWithView->GetView(parView);
|
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
if (NS_OK == parView->GetViewManager(viewMan))
|
|
|
|
{
|
|
|
|
// nsWidgetInitData* initData = GetWidgetInitData(*aPresContext); // needs to be deleted
|
|
|
|
// initialize the view as hidden since we don't know the (x,y) until Paint
|
|
|
|
result = view->Init(viewMan, boundBox, parView, &kWidgetCID, nsnull,
|
|
|
|
nsnull, 0, nsnull,
|
|
|
|
1.0f, nsViewVisibility_kHide);
|
|
|
|
// if (nsnull != initData) {
|
|
|
|
// delete(initData);
|
|
|
|
// }
|
|
|
|
if (NS_OK != result) {
|
|
|
|
result = NS_OK; //XXX why OK? MMP
|
|
|
|
goto exit; //XXX sue me. MMP
|
|
|
|
}
|
1998-07-15 00:22:30 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
#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
|
|
|
|
|
|
|
|
viewMan->InsertChild(parView, view, 0);
|
1998-07-15 00:22:30 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
{
|
|
|
|
//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);
|
|
|
|
GetOffsetFromView(origin, parentWithView);
|
|
|
|
viewMan->ResizeView(view, mRect.width, mRect.height);
|
|
|
|
viewMan->MoveViewTo(view, origin.x, origin.y);
|
|
|
|
}
|
1998-07-15 00:22:30 +00:00
|
|
|
|
|
|
|
SetView(view);
|
1998-08-01 05:47:53 +00:00
|
|
|
|
|
|
|
exit:
|
1998-07-15 00:22:30 +00:00
|
|
|
NS_IF_RELEASE(viewMan);
|
1998-08-01 05:47:53 +00:00
|
|
|
|
1998-07-15 00:22:30 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define EMBED_DEF_DIM 50
|
|
|
|
|
|
|
|
void
|
|
|
|
nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
1998-07-21 21:20:55 +00:00
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsReflowMetrics& aMetrics)
|
1998-07-15 00:22:30 +00:00
|
|
|
{
|
|
|
|
// Determine our size stylistically
|
|
|
|
nsSize styleSize;
|
|
|
|
PRIntn ss = nsCSSLayout::GetStyleSize(aPresContext, aReflowState, styleSize);
|
|
|
|
PRBool haveWidth = PR_FALSE;
|
|
|
|
PRBool haveHeight = PR_FALSE;
|
|
|
|
if (0 != (ss & NS_SIZE_HAS_WIDTH)) {
|
1998-07-21 21:20:55 +00:00
|
|
|
aMetrics.width = styleSize.width;
|
1998-07-15 00:22:30 +00:00
|
|
|
haveWidth = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (0 != (ss & NS_SIZE_HAS_HEIGHT)) {
|
1998-07-21 21:20:55 +00:00
|
|
|
aMetrics.height = styleSize.height;
|
1998-07-15 00:22:30 +00:00
|
|
|
haveHeight = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Temporary auto-sizing logic
|
|
|
|
if (!haveWidth) {
|
|
|
|
if (haveHeight) {
|
1998-07-21 21:20:55 +00:00
|
|
|
aMetrics.width = aMetrics.height;
|
1998-07-15 00:22:30 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
float p2t = aPresContext->GetPixelsToTwips();
|
1998-07-31 23:34:45 +00:00
|
|
|
aMetrics.width = NSIntPixelsToTwips(EMBED_DEF_DIM, p2t);
|
1998-07-15 00:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!haveHeight) {
|
|
|
|
if (haveWidth) {
|
1998-07-21 21:20:55 +00:00
|
|
|
aMetrics.height = aMetrics.width;
|
1998-07-15 00:22:30 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
float p2t = aPresContext->GetPixelsToTwips();
|
1998-07-31 23:34:45 +00:00
|
|
|
aMetrics.height = NSIntPixelsToTwips(EMBED_DEF_DIM, p2t);
|
1998-07-15 00:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
1998-07-21 21:20:55 +00:00
|
|
|
aMetrics.ascent = aMetrics.height;
|
|
|
|
aMetrics.descent = 0;
|
1998-07-15 00:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-15 02:53:09 +00:00
|
|
|
nsObjectFrame::Reflow(nsIPresContext& aPresContext,
|
1998-07-21 21:20:55 +00:00
|
|
|
nsReflowMetrics& aMetrics,
|
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-07-15 00:22:30 +00:00
|
|
|
{
|
|
|
|
// Get our desired size
|
1998-07-21 21:20:55 +00:00
|
|
|
GetDesiredSize(&aPresContext, aReflowState, aMetrics);
|
|
|
|
if (nsnull != aMetrics.maxElementSize) {
|
|
|
|
aMetrics.maxElementSize->width = aMetrics.width;
|
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
|
|
|
}
|
1998-07-15 00:22:30 +00:00
|
|
|
|
|
|
|
// XXX deal with border and padding the usual way...wrap it up!
|
|
|
|
|
1998-08-29 20:20:38 +00:00
|
|
|
nsIAtom* atom;
|
|
|
|
mContent->GetTag(atom);
|
1998-09-15 03:46:52 +00:00
|
|
|
if ((nsnull != atom) && (nsnull == mInstanceOwner)) {
|
1998-08-05 04:22:51 +00:00
|
|
|
//don't make a view for an applet since we know we can't support them yet...
|
|
|
|
if (atom != nsHTMLAtoms::applet) {
|
|
|
|
static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID);
|
|
|
|
static NS_DEFINE_IID(kIContentViewerContainerIID, NS_ICONTENT_VIEWER_CONTAINER_IID);
|
1998-07-23 20:35:43 +00:00
|
|
|
|
1998-08-05 04:22:51 +00:00
|
|
|
nsISupports *container;
|
|
|
|
nsIPluginHost *pm;
|
|
|
|
nsIContentViewerContainer *cv;
|
|
|
|
nsresult rv;
|
1998-07-23 20:35:43 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
mInstanceOwner = new nsPluginInstanceOwner();
|
1998-07-23 20:35:43 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
if (nsnull != mInstanceOwner) {
|
|
|
|
NS_ADDREF(mInstanceOwner);
|
|
|
|
mInstanceOwner->Init(&aPresContext, this);
|
|
|
|
|
|
|
|
rv = aPresContext.GetContainer(&container);
|
1998-07-23 20:35:43 +00:00
|
|
|
|
1998-07-27 23:08:52 +00:00
|
|
|
if (NS_OK == rv) {
|
1998-09-15 03:46:52 +00:00
|
|
|
rv = container->QueryInterface(kIContentViewerContainerIID, (void **)&cv);
|
1998-08-05 04:22:51 +00:00
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
1998-09-15 03:46:52 +00:00
|
|
|
rv = cv->QueryCapability(kIPluginHostIID, (void **)&pm);
|
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsAutoString type;
|
|
|
|
char *buf = nsnull;
|
|
|
|
PRInt32 buflen;
|
|
|
|
nsPluginWindow *window;
|
|
|
|
float t2p = aPresContext.GetTwipsToPixels();
|
1998-08-01 23:02:14 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
mInstanceOwner->GetWindow(window);
|
1998-08-01 23:02:14 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
mContent->GetAttribute(nsString("type"), type);
|
1998-08-01 23:02:14 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
buflen = type.Length();
|
1998-08-01 23:02:14 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
if (buflen > 0) {
|
|
|
|
buf = (char *)PR_Malloc(buflen + 1);
|
1998-08-05 04:22:51 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
if (nsnull != buf)
|
|
|
|
type.ToCString(buf, buflen + 1);
|
|
|
|
}
|
1998-08-05 04:22:51 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
nsAutoString src, base, fullurl;
|
1998-08-05 04:22:51 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
//stream in the object source if there is one...
|
1998-08-05 04:22:51 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute("SRC", src)) {
|
|
|
|
SetURL(src);
|
1998-08-05 04:22:51 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(NS_HTML_BASE_HREF, base))
|
|
|
|
SetBaseHREF(base);
|
1998-08-05 04:22:51 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
nsIPresShell *shell = aPresContext.GetShell();
|
|
|
|
nsIDocument *doc = shell->GetDocument();
|
|
|
|
nsIURL *docURL = doc->GetDocumentURL();
|
|
|
|
|
|
|
|
// Create an absolute URL
|
|
|
|
nsresult rv = NS_MakeAbsoluteURL(docURL, base, *mURLSpec, fullurl);
|
|
|
|
|
|
|
|
SetFullURL(fullurl);
|
1998-08-05 04:22:51 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
NS_RELEASE(shell);
|
|
|
|
NS_RELEASE(docURL);
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView *parentWithView;
|
|
|
|
nsPoint origin;
|
|
|
|
|
|
|
|
GetOffsetFromView(origin, parentWithView);
|
|
|
|
|
|
|
|
window->x = NSTwipsToIntPixels(origin.x, t2p);
|
|
|
|
window->y = NSTwipsToIntPixels(origin.y, t2p);
|
|
|
|
window->width = NSTwipsToIntPixels(aMetrics.width, t2p);
|
|
|
|
window->height = NSTwipsToIntPixels(aMetrics.height, t2p);
|
|
|
|
window->clipRect.top = 0;
|
|
|
|
window->clipRect.left = 0;
|
|
|
|
// window->clipRect.top = NSTwipsToIntPixels(origin.y, t2p);
|
|
|
|
// window->clipRect.left = NSTwipsToIntPixels(origin.x, t2p);
|
|
|
|
window->clipRect.bottom = NSTwipsToIntPixels(aMetrics.height, t2p);
|
|
|
|
window->clipRect.right = NSTwipsToIntPixels(aMetrics.width, t2p);
|
1998-08-01 23:02:14 +00:00
|
|
|
#ifdef XP_UNIX
|
1998-09-15 03:46:52 +00:00
|
|
|
window->ws_info = nsnull; //XXX need to figure out what this is. MMP
|
1998-08-01 23:02:14 +00:00
|
|
|
#endif
|
1998-09-15 03:46:52 +00:00
|
|
|
rv = pm->InstantiatePlugin(buf, fullurl, mInstanceOwner);
|
1998-08-05 04:22:51 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
PR_Free((void *)buf);
|
1998-08-01 23:02:14 +00:00
|
|
|
|
1998-09-15 03:46:52 +00:00
|
|
|
NS_RELEASE(pm);
|
1998-07-23 20:35:43 +00:00
|
|
|
}
|
1998-09-15 03:46:52 +00:00
|
|
|
NS_RELEASE(cv);
|
1998-07-23 20:35:43 +00:00
|
|
|
}
|
1998-09-15 03:46:52 +00:00
|
|
|
NS_RELEASE(container);
|
1998-07-23 20:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-08-05 04:22:51 +00:00
|
|
|
NS_RELEASE(atom);
|
1998-07-15 00:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::DidReflow(nsIPresContext& aPresContext,
|
1998-07-21 21:20:55 +00:00
|
|
|
nsDidReflowStatus aStatus)
|
1998-07-15 00:22:30 +00:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
if (NS_FRAME_REFLOW_FINISHED == aStatus) {
|
|
|
|
nsIView* view = nsnull;
|
|
|
|
GetView(view);
|
|
|
|
if (nsnull != view) {
|
|
|
|
view->SetVisibility(nsViewVisibility_kShow);
|
|
|
|
}
|
1998-09-15 03:46:52 +00:00
|
|
|
|
|
|
|
if (nsnull != mInstanceOwner) {
|
|
|
|
nsPluginWindow *window;
|
|
|
|
|
|
|
|
if (NS_OK == mInstanceOwner->GetWindow(window)) {
|
|
|
|
nsIView *parentWithView;
|
|
|
|
nsPoint origin;
|
|
|
|
nsIPluginInstance *inst;
|
|
|
|
float t2p = aPresContext.GetTwipsToPixels();
|
|
|
|
nscoord offx, offy;
|
|
|
|
|
|
|
|
GetOffsetFromView(origin, parentWithView);
|
|
|
|
|
|
|
|
parentWithView->GetScrollOffset(&offx, &offy);
|
|
|
|
|
|
|
|
// window->x = NSTwipsToIntPixels(origin.x, t2p);
|
|
|
|
// window->y = NSTwipsToIntPixels(origin.y, t2p);
|
|
|
|
window->x = 0;
|
|
|
|
window->y = 0;
|
|
|
|
|
|
|
|
window->clipRect.top = 0;
|
|
|
|
window->clipRect.left = 0;
|
|
|
|
// window->clipRect.top = NSTwipsToIntPixels(origin.y, t2p);
|
|
|
|
// window->clipRect.left = NSTwipsToIntPixels(origin.x, t2p);
|
|
|
|
// window->clipRect.top = NSTwipsToIntPixels(origin.y + offy, t2p);
|
|
|
|
// window->clipRect.left = NSTwipsToIntPixels(origin.x + offx, t2p);
|
|
|
|
window->clipRect.bottom = window->clipRect.top + window->height;
|
|
|
|
window->clipRect.right = window->clipRect.left + window->width;
|
|
|
|
|
|
|
|
if (NS_OK == mInstanceOwner->GetInstance(inst)) {
|
|
|
|
inst->SetWindow(window);
|
|
|
|
NS_RELEASE(inst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-07-15 00:22:30 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-07-29 19:33:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
|
|
|
const nsStyleFont* font =
|
|
|
|
(const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
|
|
|
|
|
|
|
|
aRenderingContext.SetFont(font->mFont);
|
|
|
|
aRenderingContext.SetColor(NS_RGB(192, 192, 192));
|
|
|
|
aRenderingContext.FillRect(0, 0, mRect.width, mRect.height);
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
|
|
|
aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);
|
|
|
|
float p2t = aPresContext.GetPixelsToTwips();
|
1998-07-31 23:34:45 +00:00
|
|
|
nscoord px3 = NSIntPixelsToTwips(3, p2t);
|
1998-07-29 19:33:48 +00:00
|
|
|
nsAutoString tmp;
|
1998-08-29 20:20:38 +00:00
|
|
|
nsIAtom* atom;
|
|
|
|
mContent->GetTag(atom);
|
1998-07-29 19:33:48 +00:00
|
|
|
if (nsnull != atom) {
|
|
|
|
atom->ToString(tmp);
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
aRenderingContext.DrawString(tmp, px3, px3, 0);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-21 21:20:55 +00:00
|
|
|
nsresult
|
1998-09-15 03:46:52 +00:00
|
|
|
nsObjectFrame::SetURL(const nsString& aURLSpec)
|
1998-07-15 00:22:30 +00:00
|
|
|
{
|
1998-09-15 03:46:52 +00:00
|
|
|
if (nsnull != mURLSpec) {
|
|
|
|
delete mURLSpec;
|
|
|
|
}
|
|
|
|
mURLSpec = new nsString(aURLSpec);
|
|
|
|
if (nsnull == mURLSpec) {
|
1998-07-15 00:22:30 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-08-05 04:22:51 +00:00
|
|
|
|
|
|
|
nsresult
|
1998-09-15 03:46:52 +00:00
|
|
|
nsObjectFrame::SetFullURL(const nsString& aURLSpec)
|
1998-08-05 04:22:51 +00:00
|
|
|
{
|
1998-09-15 03:46:52 +00:00
|
|
|
if (nsnull != mFullURL) {
|
|
|
|
delete mFullURL;
|
1998-08-05 04:22:51 +00:00
|
|
|
}
|
1998-09-15 03:46:52 +00:00
|
|
|
mFullURL = new nsString(aURLSpec);
|
|
|
|
if (nsnull == mFullURL) {
|
1998-08-05 04:22:51 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsObjectFrame::SetBaseHREF(const nsString& aBaseHREF)
|
|
|
|
{
|
|
|
|
if (nsnull != mBaseHREF) {
|
|
|
|
delete mBaseHREF;
|
|
|
|
}
|
|
|
|
mBaseHREF = new nsString(aBaseHREF);
|
|
|
|
if (nsnull == mBaseHREF) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-15 03:46:52 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsObjectFrame::Scrolled(nsIView *aView)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsObjectFrame :: GetFullURL(nsString& aFullURL)
|
|
|
|
{
|
|
|
|
if (nsnull != mFullURL)
|
|
|
|
aFullURL = *mFullURL;
|
|
|
|
else
|
|
|
|
aFullURL = nsString("");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewObjectFrame(nsIContent* aContent, nsIFrame* aParentFrame,
|
|
|
|
nsIFrame*& aFrameResult)
|
|
|
|
{
|
|
|
|
aFrameResult = new nsObjectFrame(aContent, aParentFrame);
|
|
|
|
if (nsnull == aFrameResult) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginInstanceOwner :: ~nsPluginInstanceOwner()
|
|
|
|
{
|
|
|
|
if (nsnull != mInstance)
|
|
|
|
{
|
|
|
|
mInstance->Stop();
|
|
|
|
mInstance->Destroy();
|
|
|
|
NS_RELEASE(mInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
mOwner = nsnull;
|
|
|
|
|
|
|
|
for (PRInt32 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mWidget);
|
|
|
|
mContext = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIPluginInstanceOwnerIID, NS_IPLUGININSTANCEOWNER_IID);
|
|
|
|
|
|
|
|
NS_IMPL_QUERY_INTERFACE(nsPluginInstanceOwner, kIPluginInstanceOwnerIID);
|
|
|
|
NS_IMPL_ADDREF(nsPluginInstanceOwner);
|
|
|
|
NS_IMPL_RELEASE(nsPluginInstanceOwner);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
printf("instance owner getmode called\n");
|
|
|
|
*aMode = nsPluginMode_Embedded;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIHTMLContentIID, NS_IHTMLCONTENT_IID);
|
|
|
|
static NS_DEFINE_IID(kILinkHandlerIID, NS_ILINKHANDLER_IID);
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner :: GetAttributes(PRUint16& n,
|
|
|
|
const char*const*& names,
|
|
|
|
const char*const*& values)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIHTMLContent *content;
|
|
|
|
nsIContent *icontent;
|
|
|
|
|
|
|
|
if (nsnull == mAttrNames)
|
|
|
|
{
|
|
|
|
rv = mOwner->GetContent(icontent);
|
|
|
|
|
|
|
|
if (rv == NS_OK)
|
|
|
|
{
|
|
|
|
rv = icontent->QueryInterface(kIHTMLContentIID, (void **)&content);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
nsISupportsArray *array;
|
|
|
|
|
|
|
|
rv = NS_NewISupportsArray(&array);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
PRInt32 cnt, numattrs;
|
|
|
|
|
|
|
|
if ((NS_OK == content->GetAllAttributeNames(array, numattrs)) && (numattrs > 0))
|
|
|
|
{
|
|
|
|
mAttrNames = (char **)PR_Calloc(sizeof(char *) * numattrs, 1);
|
|
|
|
mAttrVals = (char **)PR_Calloc(sizeof(char *) * numattrs, 1);
|
|
|
|
|
|
|
|
if ((nsnull != mAttrNames) && (nsnull != mAttrVals))
|
|
|
|
{
|
|
|
|
for (cnt = 0; cnt < numattrs; cnt++)
|
|
|
|
{
|
|
|
|
nsIAtom *atom = (nsIAtom *)array->ElementAt(cnt);
|
|
|
|
nsAutoString name, val;
|
|
|
|
|
|
|
|
if (nsnull != atom)
|
|
|
|
{
|
|
|
|
atom->ToString(name);
|
|
|
|
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == icontent->GetAttribute(name, val))
|
|
|
|
{
|
|
|
|
mAttrNames[mNumAttrs] = (char *)PR_Malloc(name.Length() + 1);
|
|
|
|
mAttrVals[mNumAttrs] = (char *)PR_Malloc(val.Length() + 1);
|
|
|
|
|
|
|
|
if ((nsnull != mAttrNames[mNumAttrs]) &&
|
|
|
|
(nsnull != mAttrVals[mNumAttrs]))
|
|
|
|
{
|
|
|
|
name.ToCString(mAttrNames[mNumAttrs], name.Length() + 1);
|
|
|
|
val.ToCString(mAttrVals[mNumAttrs], val.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(array);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
PRInt32 count;
|
|
|
|
|
|
|
|
if (nsnull == mAttrNames)
|
|
|
|
{
|
|
|
|
PRUint16 numattrs;
|
|
|
|
const char * const *names, * const *vals;
|
|
|
|
|
|
|
|
GetAttributes(numattrs, names, vals);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count = 0; count < mNumAttrs; count++)
|
|
|
|
{
|
|
|
|
if (0 == PL_strcasecmp(mAttrNames[count], name))
|
|
|
|
{
|
|
|
|
*result = mAttrVals[count];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count < mNumAttrs)
|
|
|
|
return NS_OK;
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner :: GetInstance(nsIPluginInstance *&aInstance)
|
|
|
|
{
|
|
|
|
if (nsnull != mInstance)
|
|
|
|
{
|
|
|
|
aInstance = mInstance;
|
|
|
|
NS_ADDREF(mInstance);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner :: GetURL(const char *aURL, const char *aTarget, void *aPostData)
|
|
|
|
{
|
|
|
|
nsISupports *container;
|
|
|
|
nsILinkHandler *lh;
|
|
|
|
nsresult rv;
|
|
|
|
nsIView *view;
|
|
|
|
nsPoint origin;
|
|
|
|
|
|
|
|
if ((nsnull != mOwner) && (nsnull != mContext))
|
|
|
|
{
|
|
|
|
rv = mOwner->GetOffsetFromView(origin, view);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
rv = mContext->GetContainer(&container);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
rv = container->QueryInterface(kILinkHandlerIID, (void **)&lh);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
nsAutoString uniurl = nsAutoString(aURL);
|
|
|
|
nsAutoString unitarget = nsAutoString(aTarget);
|
|
|
|
nsAutoString base, fullurl;
|
|
|
|
|
|
|
|
mOwner->GetFullURL(base);
|
|
|
|
|
|
|
|
nsIPresShell *shell = mContext->GetShell();
|
|
|
|
nsIDocument *doc = shell->GetDocument();
|
|
|
|
nsIURL *docURL = doc->GetDocumentURL();
|
|
|
|
|
|
|
|
// Create an absolute URL
|
1998-09-15 20:22:37 +00:00
|
|
|
rv = NS_MakeAbsoluteURL(docURL, base, uniurl, fullurl);
|
1998-09-15 03:46:52 +00:00
|
|
|
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
NS_RELEASE(docURL);
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
|
1998-09-15 20:22:37 +00:00
|
|
|
if (NS_OK == rv)
|
|
|
|
rv = lh->OnLinkClick(mOwner, fullurl.GetUnicode(), unitarget.GetUnicode(), nsnull);
|
1998-09-15 03:46:52 +00:00
|
|
|
|
|
|
|
NS_RELEASE(lh);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(container);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner :: Init(nsIPresContext* aPresContext, nsObjectFrame *aFrame)
|
|
|
|
{
|
|
|
|
//do not addref to avoid circular refs. MMP
|
|
|
|
mContext = aPresContext;
|
|
|
|
mOwner = aFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner :: CreateWidget(void)
|
|
|
|
{
|
|
|
|
nsIView *view;
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (nsnull != mOwner)
|
|
|
|
{
|
|
|
|
// Create view if necessary
|
|
|
|
|
|
|
|
mOwner->GetView(view);
|
|
|
|
|
|
|
|
if (nsnull == view)
|
|
|
|
{
|
|
|
|
PRBool windowless;
|
|
|
|
|
|
|
|
mInstance->GetValue(nsPluginInstanceVariable_WindowlessBool, (void *)&windowless);
|
|
|
|
|
|
|
|
rv = mOwner->CreateWidget(mPluginWindow.width,
|
|
|
|
mPluginWindow.height,
|
|
|
|
windowless);
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
nsIView *view;
|
|
|
|
|
|
|
|
mOwner->GetView(view);
|
|
|
|
view->GetWidget(mWidget);
|
|
|
|
|
|
|
|
if (PR_TRUE == windowless)
|
|
|
|
{
|
|
|
|
mPluginWindow.window = nsnull; //XXX this needs to be a HDC
|
|
|
|
mPluginWindow.type = nsPluginWindowType_Drawable;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mPluginWindow.window = (nsPluginPort *)mWidget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
mPluginWindow.type = nsPluginWindowType_Window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|