2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-07-07 06:33:17 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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
|
|
|
*
|
2001-09-29 00:14:13 +04: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.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-06-22 11:06:24 +04:00
|
|
|
* Jacek Piskozub <piskozub@iopan.gda.pl>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-08-14 11:59:59 +04:00
|
|
|
#include "nscore.h"
|
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"
|
2001-03-10 06:17:40 +03:00
|
|
|
#include "nsReadableUtils.h"
|
1999-07-07 06:33:17 +04:00
|
|
|
#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"
|
2001-12-11 18:53:07 +03:00
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsIDOMHTMLObjectElement.h"
|
|
|
|
#include "nsIDOMHTMLAppletElement.h"
|
2000-05-25 17:32:42 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-05-22 02:40:10 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2000-10-18 03:13:30 +04:00
|
|
|
#include "nsIDOMMouseListener.h"
|
2001-08-07 05:48:14 +04:00
|
|
|
#include "nsIDOMMouseMotionListener.h"
|
2001-03-20 02:26:41 +03:00
|
|
|
#include "nsIDOMFocusListener.h"
|
2000-10-18 03:13:30 +04:00
|
|
|
#include "nsIDOMEventReceiver.h"
|
2001-12-06 09:57:03 +03:00
|
|
|
#include "nsIDOMNSEvent.h"
|
2000-10-18 03:13:30 +04:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2000-10-19 05:37:53 +04:00
|
|
|
#include "nsIDocumentEncoder.h"
|
2001-03-10 06:17:40 +03:00
|
|
|
#include "nsXPIDLString.h"
|
2001-02-20 00:50:04 +03:00
|
|
|
#include "nsIDOMRange.h"
|
2001-03-30 07:07:52 +04:00
|
|
|
#include "nsIPrintContext.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIContentViewer.h"
|
2001-06-29 04:29:44 +04:00
|
|
|
#include "nsIDocShell.h"
|
2001-09-18 06:11:09 +04:00
|
|
|
#include "npapi.h"
|
|
|
|
#include "nsIPrintOptions.h"
|
|
|
|
#include "nsGfxCIID.h"
|
2001-10-09 14:15:06 +04:00
|
|
|
#include "nsHTMLUtils.h"
|
2001-11-14 04:33:42 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
2001-09-18 06:11:09 +04:00
|
|
|
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
// headers for plugin scriptability
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsIXPCScriptable.h"
|
|
|
|
#include "nsIClassInfo.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
2001-04-14 01:30:14 +04:00
|
|
|
// XXX temporary for Mac double buffering pref
|
|
|
|
#include "nsIPref.h"
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
// XXX For temporary paint code
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
|
2001-09-18 06:11:09 +04:00
|
|
|
// For mime types
|
2000-07-10 11:13:31 +04:00
|
|
|
#include "nsMimeTypes.h"
|
2001-08-16 07:02:05 +04:00
|
|
|
#include "nsIMIMEService.h"
|
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
#include "nsICategoryManager.h"
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2000-04-15 02:48:30 +04:00
|
|
|
#include "nsObjectFrame.h"
|
2001-02-20 00:50:04 +03:00
|
|
|
#include "nsIObjectFrame.h"
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
#include "nsContentCID.h"
|
2001-10-25 05:08:40 +04:00
|
|
|
static NS_DEFINE_CID(kRangeCID, NS_RANGE_CID);
|
2001-04-14 01:30:14 +04:00
|
|
|
|
|
|
|
// XXX temporary for Mac double buffering pref
|
|
|
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
|
|
|
|
2001-01-18 01:16:09 +03:00
|
|
|
/* X headers suck */
|
|
|
|
#ifdef KeyPress
|
|
|
|
#undef KeyPress
|
|
|
|
#endif
|
2000-10-18 03:13:30 +04:00
|
|
|
|
2001-09-18 06:11:09 +04:00
|
|
|
static nsresult GetContainingBlock(nsIFrame *aFrame, nsIFrame **aContainingBlock);
|
2001-03-20 02:26:41 +03: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,
|
2001-08-07 05:48:14 +04:00
|
|
|
public nsIDOMMouseMotionListener,
|
2001-03-20 02:26:41 +03:00
|
|
|
public nsIDOMKeyListener,
|
|
|
|
public nsIDOMFocusListener
|
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,
|
2001-11-07 06:03:04 +03:00
|
|
|
PRUint32 aHeadersDataLen, PRBool isFile = PR_FALSE);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
NS_IMETHOD ShowStatus(const char *aStatusMsg);
|
2001-09-05 07:58:34 +04:00
|
|
|
|
|
|
|
NS_IMETHOD ShowStatus(const PRUnichar *aStatusMsg);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
NS_IMETHOD GetDocument(nsIDocument* *aDocument);
|
|
|
|
|
2001-06-19 01:41:57 +04:00
|
|
|
NS_IMETHOD InvalidateRect(nsPluginRect *invalidRect);
|
|
|
|
|
|
|
|
NS_IMETHOD InvalidateRegion(nsPluginRegion invalidRegion);
|
|
|
|
|
|
|
|
NS_IMETHOD ForceRedraw();
|
|
|
|
|
|
|
|
NS_IMETHOD GetValue(nsPluginInstancePeerVariable variable, void *value);
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
//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
|
|
|
|
*/
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
|
|
|
|
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
|
|
|
|
NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent);
|
|
|
|
NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent);
|
|
|
|
NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent);
|
|
|
|
NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent);
|
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
2000-10-18 03:13:30 +04:00
|
|
|
/* END interfaces from nsIDOMMouseListener*/
|
2001-01-17 23:04:09 +03:00
|
|
|
|
2001-08-07 05:48:14 +04:00
|
|
|
// nsIDOMMouseListener intefaces
|
|
|
|
NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent);
|
|
|
|
NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; }
|
|
|
|
|
|
|
|
// nsIDOMKeyListener interfaces
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent);
|
|
|
|
NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent);
|
|
|
|
NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent);
|
2001-01-17 23:04:09 +03:00
|
|
|
// end nsIDOMKeyListener interfaces
|
2000-10-18 03:13:30 +04:00
|
|
|
|
2001-03-20 02:26:41 +03:00
|
|
|
// nsIDOMFocuListener interfaces
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_IMETHOD Focus(nsIDOMEvent * aFocusEvent);
|
|
|
|
NS_IMETHOD Blur(nsIDOMEvent * aFocusEvent);
|
2001-03-20 02:26:41 +03:00
|
|
|
|
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
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
nsPluginPort* GetPluginPort();
|
2001-09-18 06:11:09 +04:00
|
|
|
void ReleasePluginPort(nsPluginPort * pluginPort);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
void SetPluginHost(nsIPluginHost* aHost);
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
#ifdef XP_MAC
|
|
|
|
void FixUpPluginWindow();
|
2001-05-16 07:46:56 +04:00
|
|
|
void GUItoMacEvent(const nsGUIEvent& anEvent, EventRecord& aMacEvent);
|
2001-01-12 02:56:35 +03:00
|
|
|
#endif
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
private:
|
|
|
|
nsPluginWindow mPluginWindow;
|
|
|
|
nsIPluginInstance *mInstance;
|
|
|
|
nsObjectFrame *mOwner;
|
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-10-09 02:58:59 +04:00
|
|
|
PRPackedBool mContentFocused;
|
2001-12-11 18:53:07 +03:00
|
|
|
PRUint16 mNumCachedAttrs;
|
|
|
|
PRUint16 mNumCachedParams;
|
|
|
|
char **mCachedAttrParamNames;
|
|
|
|
char **mCachedAttrParamValues;
|
2001-01-17 23:04:09 +03:00
|
|
|
|
|
|
|
nsresult DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent);
|
2001-01-28 03:37:48 +03:00
|
|
|
nsresult DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent);
|
2001-03-20 02:26:41 +03:00
|
|
|
nsresult DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent);
|
2001-12-11 18:53:07 +03:00
|
|
|
|
|
|
|
nsresult EnsureCachedAttrParamArrays();
|
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
|
|
|
}
|
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtr);
|
|
|
|
*aInstancePtr = nsnull;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIFrameDebug))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIFrameDebug*,this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIObjectFrame))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIObjectFrame*,this);
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIFrame))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIFrame*,this);
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIObjectFrame*,this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsObjectFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported for frames");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsObjectFrame::Release(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported for frames");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
static NS_DEFINE_CID(kViewCID, NS_VIEW_CID);
|
|
|
|
static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID);
|
|
|
|
static NS_DEFINE_CID(kCAppShellCID, NS_APPSHELL_CID);
|
|
|
|
static NS_DEFINE_CID(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"
|
2001-11-03 10:10:51 +03:00
|
|
|
#define IMAGE_EXT_BMP "bmp"
|
|
|
|
#define IMAGE_EXT_ICO "ico"
|
1999-07-07 06:33:17 +04:00
|
|
|
|
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;
|
2001-08-17 12:14:14 +04:00
|
|
|
nsresult rv = aContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::type, type);
|
1999-07-07 06:33:17 +04:00
|
|
|
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)||
|
2001-11-03 10:10:51 +03:00
|
|
|
type.EqualsIgnoreCase(IMAGE_XBM3)||
|
|
|
|
type.EqualsIgnoreCase(IMAGE_BMP) ||
|
|
|
|
type.EqualsIgnoreCase(IMAGE_ICO))
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
*aImage = PR_TRUE;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString data;
|
2001-08-17 12:14:14 +04:00
|
|
|
rv = aContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::data, data);
|
2001-08-16 04:14:14 +04:00
|
|
|
|
|
|
|
PRBool havedata = (rv == NS_CONTENT_ATTR_HAS_VALUE) && (data.Length() > 0);
|
|
|
|
|
|
|
|
if(!havedata)
|
|
|
|
{// try it once more for SRC attrubute
|
2001-08-17 12:14:14 +04:00
|
|
|
rv = aContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::src, data);
|
2001-08-16 04:14:14 +04:00
|
|
|
havedata = (rv == NS_CONTENT_ATTR_HAS_VALUE) && (data.Length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(havedata)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
// 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) ||
|
2001-11-03 10:10:51 +03:00
|
|
|
ext.EqualsIgnoreCase(IMAGE_EXT_XBM) ||
|
|
|
|
ext.EqualsIgnoreCase(IMAGE_EXT_BMP) ||
|
|
|
|
ext.EqualsIgnoreCase(IMAGE_EXT_ICO))
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
*aImage = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-16 07:02:05 +04:00
|
|
|
void nsObjectFrame::IsSupportedDocument(nsIContent* aContent, PRBool* aDoc)
|
|
|
|
{
|
|
|
|
*aDoc = PR_FALSE;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if(aContent == nsnull)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
nsAutoString type;
|
2001-08-17 12:14:14 +04:00
|
|
|
rv = aContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::type, type);
|
2001-08-16 07:02:05 +04:00
|
|
|
if((rv == NS_CONTENT_ATTR_HAS_VALUE) && (type.Length() > 0))
|
|
|
|
{
|
|
|
|
nsXPIDLCString value;
|
|
|
|
char * buf = ToNewCString(type);
|
|
|
|
rv = catman->GetCategoryEntry("Gecko-Content-Viewers",buf, getter_Copies(value));
|
|
|
|
nsMemory::Free(buf);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && value && *value && (value.Length() > 0))
|
|
|
|
*aDoc = PR_TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we don't have a TYPE= try getting the mime-type via the DATA= url
|
|
|
|
nsAutoString data;
|
2001-08-17 12:14:14 +04:00
|
|
|
rv = aContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::data, data);
|
2001-08-16 07:02:05 +04:00
|
|
|
if((rv == NS_CONTENT_ATTR_HAS_VALUE) && (data.Length() > 0))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsCOMPtr<nsIURI> baseURL;
|
|
|
|
|
|
|
|
if (NS_FAILED(GetBaseURL(*getter_AddRefs(baseURL)))) return; // XXX NS_NewURI fails without base
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), data, baseURL);
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMIMEService> mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
2001-09-13 00:43:40 +04:00
|
|
|
char * contentType = nsnull;
|
2001-08-16 07:02:05 +04:00
|
|
|
rv = mimeService->GetTypeFromURI(uri, &contentType);
|
2001-08-16 08:54:07 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (contentType)
|
|
|
|
nsMemory::Free(contentType);
|
|
|
|
return;
|
|
|
|
}
|
2001-08-16 07:02:05 +04:00
|
|
|
|
|
|
|
nsXPIDLCString value;
|
|
|
|
rv = catman->GetCategoryEntry("Gecko-Content-Viewers",contentType, getter_Copies(value));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && value && *value && (value.Length() > 0))
|
|
|
|
*aDoc = PR_TRUE;
|
2001-08-16 08:54:07 +04:00
|
|
|
|
|
|
|
if (contentType)
|
|
|
|
nsMemory::Free(contentType);
|
2001-08-16 07:02:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2001-05-16 07:46:56 +04:00
|
|
|
mPresContext = aPresContext; // weak ref
|
2001-08-02 04:03:29 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
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);
|
2001-08-16 07:02:05 +04:00
|
|
|
|
|
|
|
return rv; // bail at this point
|
|
|
|
}
|
|
|
|
|
2001-09-12 08:00:52 +04:00
|
|
|
|
|
|
|
// only do the following for the object tag
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag.get() != nsHTMLAtoms::object) return rv;
|
2001-08-16 07:02:05 +04:00
|
|
|
|
|
|
|
// for now, we should try to do the same for "document" types and create
|
|
|
|
// and IFrame-like sub-frame
|
|
|
|
PRBool bDoc = PR_FALSE;
|
|
|
|
IsSupportedDocument(aContent, &bDoc);
|
2001-09-12 08:00:52 +04:00
|
|
|
|
2001-08-16 07:02:05 +04:00
|
|
|
if(bDoc)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
nsIFrame * aNewFrame = nsnull;
|
|
|
|
rv = NS_NewHTMLFrameOuterFrame(shell, &aNewFrame);
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = aNewFrame->Init(aPresContext, aContent, this, aContext, aPrevInFlow);
|
|
|
|
if(NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
nsHTMLContainerFrame::CreateViewForFrame(aPresContext, aNewFrame, aContext, nsnull, PR_FALSE);
|
|
|
|
mFrames.AppendFrame(this, aNewFrame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
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();
|
|
|
|
}
|
2001-08-17 04:45:25 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPluginHost> pluginHost = do_GetService(kCPluginManagerCID);
|
|
|
|
if(pluginHost)
|
|
|
|
pluginHost->StopPluginInstance(inst);
|
|
|
|
|
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
|
2001-11-14 04:33:42 +03:00
|
|
|
nsObjectFrame::GetFrameName(nsAString& aResult) const
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ObjectFrame"), aResult);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
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
|
2001-04-14 01:30:14 +04:00
|
|
|
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID));
|
|
|
|
PRBool doubleBuffer = PR_FALSE;
|
|
|
|
prefs ? prefs->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer) : 0;
|
|
|
|
|
|
|
|
viewMan->AllowDoubleBuffering(doubleBuffer);
|
2000-09-29 03:29:26 +04:00
|
|
|
#endif
|
|
|
|
|
2001-12-01 17:31:45 +03:00
|
|
|
// XXX Put this last in document order
|
|
|
|
// XXX Should we be setting the z-index here?
|
|
|
|
viewMan->InsertChild(parView, view, nsnull, PR_TRUE);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-06-19 01:41:57 +04:00
|
|
|
if(aViewOnly != PR_TRUE) {
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-06-19 01:41:57 +04:00
|
|
|
result = view->CreateWidget(kWidgetCID);
|
|
|
|
|
|
|
|
if (NS_OK != result) {
|
|
|
|
result = NS_OK; //XXX why OK? MMP
|
|
|
|
goto exit; //XXX sue me. MMP
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2001-11-07 02:46:13 +03:00
|
|
|
// Here we set the background color for this widget because some plugins will use
|
|
|
|
// the child window background color when painting. If it's not set, it may default to gray
|
|
|
|
// Sometimes, a frame doesn't have a background color or is transparent. In this
|
|
|
|
// case, walk up the frame tree until we do find a frame with a background color
|
|
|
|
for (nsIFrame* frame = this; frame; frame->GetParent(&frame)) {
|
|
|
|
const nsStyleBackground* color;
|
|
|
|
frame->GetStyleData(eStyleStruct_Background, (const nsStyleStruct*&)color);
|
|
|
|
if (!color->BackgroundIsTransparent()) { // make sure we got an actual color
|
|
|
|
nsCOMPtr<nsIWidget> win;
|
|
|
|
view->GetWidget(*getter_AddRefs(win));
|
|
|
|
if (win)
|
|
|
|
win->SetBackgroundColor(color->mBackgroundColor);
|
|
|
|
else
|
|
|
|
NS_ASSERTION(win, "failed to get widget to set background color on");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-07 06:33:17 +04: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;
|
2001-12-01 17:31:45 +03:00
|
|
|
nsRect r(0, 0, mRect.width, mRect.height);
|
|
|
|
|
|
|
|
viewMan->SetViewVisibility(view, nsViewVisibility_kShow);
|
1999-10-26 08:44:41 +04:00
|
|
|
GetOffsetFromView(aPresContext, origin, &parentWithView);
|
2001-12-01 17:31:45 +03:00
|
|
|
viewMan->ResizeView(view, r);
|
1999-07-07 06:33:17 +04:00
|
|
|
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)
|
|
|
|
{
|
2001-09-18 06:11:09 +04:00
|
|
|
// By default, we have no area
|
|
|
|
aMetrics.width = 0;
|
|
|
|
aMetrics.height = 0;
|
|
|
|
aMetrics.ascent = 0;
|
|
|
|
aMetrics.descent = 0;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-18 06:11:09 +04:00
|
|
|
// for EMBED and APPLET, default to 240x200 for compatibility
|
|
|
|
nsIAtom *atom;
|
|
|
|
mContent->GetTag(atom);
|
|
|
|
if ( nsnull != atom &&
|
|
|
|
((atom == nsHTMLAtoms::applet) || (atom == nsHTMLAtoms::embed))) {
|
2001-05-16 06:24:33 +04:00
|
|
|
|
2001-09-18 06:11:09 +04:00
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
|
|
aMetrics.width = NSIntPixelsToTwips(EMBED_DEF_WIDTH, p2t);
|
|
|
|
aMetrics.height = NSIntPixelsToTwips(EMBED_DEF_HEIGHT, p2t);
|
|
|
|
}
|
|
|
|
|
|
|
|
// now find out size stylisticly
|
|
|
|
const nsStylePosition* position;
|
|
|
|
GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)position);
|
|
|
|
|
|
|
|
// width
|
|
|
|
nsStyleUnit unit = position->mWidth.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
aMetrics.width = position->mWidth.GetCoordValue();
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Percent == unit)
|
|
|
|
{
|
|
|
|
float factor = position->mWidth.GetPercentValue();
|
|
|
|
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.availableWidth)
|
|
|
|
aMetrics.width = NSToCoordRound (factor * aReflowState.availableWidth);
|
|
|
|
else { // unconstrained percent case
|
|
|
|
nsRect rect;
|
|
|
|
aPresContext->GetVisibleArea(rect);
|
|
|
|
nscoord w = rect.width;
|
|
|
|
// now make it nicely fit counting margins
|
|
|
|
nsIFrame *containingBlock = nsnull;
|
|
|
|
if (NS_SUCCEEDED(GetContainingBlock(this, &containingBlock)) && 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 top and bottom margins
|
|
|
|
// but for now, let's just copy what we had before
|
2001-05-16 06:24:33 +04:00
|
|
|
}
|
2001-09-18 06:11:09 +04:00
|
|
|
aMetrics.width = NSToCoordRound (factor * w);
|
2001-05-16 06:24:33 +04:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
2001-09-18 06:11:09 +04:00
|
|
|
// height
|
|
|
|
unit = position->mHeight.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
aMetrics.height = position->mHeight.GetCoordValue();
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
2001-09-18 06:11:09 +04:00
|
|
|
else if (eStyleUnit_Percent == unit)
|
|
|
|
{
|
|
|
|
float factor = position->mHeight.GetPercentValue();
|
|
|
|
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.availableHeight)
|
|
|
|
aMetrics.height = NSToCoordRound (factor * aReflowState.availableHeight);
|
|
|
|
else { // unconstrained percent case
|
|
|
|
nsRect rect;
|
|
|
|
aPresContext->GetVisibleArea(rect);
|
|
|
|
nscoord h = rect.height;
|
|
|
|
// now make it nicely fit counting margins
|
|
|
|
nsIFrame *containingBlock = nsnull;
|
|
|
|
if (NS_SUCCEEDED(GetContainingBlock(this, &containingBlock)) && containingBlock) {
|
|
|
|
containingBlock->GetRect(rect);
|
|
|
|
h -= 2*rect.y;
|
|
|
|
// 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
|
|
|
|
// but for now, let's just copy what we had before
|
|
|
|
}
|
|
|
|
aMetrics.height = NSToCoordRound (factor * h);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
2001-09-18 06:11:09 +04:00
|
|
|
// accent
|
1999-07-07 06:33:17 +04:00
|
|
|
aMetrics.ascent = aMetrics.height;
|
2001-09-18 06:11:09 +04:00
|
|
|
|
|
|
|
if (aMetrics.width || aMetrics.height) {
|
|
|
|
// Make sure that the other dimension is non-zero
|
|
|
|
if (!aMetrics.width) aMetrics.width = 1;
|
|
|
|
if (!aMetrics.height) aMetrics.height = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != aMetrics.maxElementSize) {
|
|
|
|
aMetrics.maxElementSize->width = aMetrics.width;
|
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
2001-10-09 14:15:06 +04:00
|
|
|
nsresult
|
|
|
|
nsObjectFrame::MakeAbsoluteURL(nsIURI* *aFullURI,
|
|
|
|
nsString aSrc,
|
|
|
|
nsIURI* aBaseURI)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
rv = mInstanceOwner->GetDocument(getter_AddRefs(document));
|
|
|
|
|
|
|
|
//trim leading and trailing whitespace
|
|
|
|
aSrc.Trim("\b\t\r\n ", PR_TRUE, PR_TRUE, PR_FALSE);
|
|
|
|
|
|
|
|
//create properly encoded absolute URI using the document charset
|
|
|
|
nsXPIDLCString encodedURI;
|
|
|
|
rv = NS_MakeAbsoluteURIWithCharset(getter_Copies(encodedURI),
|
|
|
|
aSrc, document, aBaseURI,
|
|
|
|
nsHTMLUtils::IOService,
|
|
|
|
nsHTMLUtils::CharsetMgr);
|
|
|
|
rv = NS_NewURI(aFullURI, encodedURI, aBaseURI);
|
|
|
|
return rv;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
#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);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
1999-07-07 06:33:17 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Get our desired size
|
1999-11-24 09:03:41 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-18 06:11:09 +04:00
|
|
|
// handle an image or iframes elsewhere
|
2001-06-13 06:42:47 +04:00
|
|
|
nsIFrame * child = mFrames.FirstChild();
|
|
|
|
if(child != nsnull)
|
2001-08-16 07:02:05 +04:00
|
|
|
return HandleChild(aPresContext, aMetrics, aReflowState, aStatus, child);
|
2001-05-19 06:45:21 +04:00
|
|
|
// if we are printing, bail for now
|
2001-03-30 07:07:52 +04:00
|
|
|
nsCOMPtr<nsIPrintContext> thePrinterContext = do_QueryInterface(aPresContext);
|
2001-09-05 06:45:48 +04:00
|
|
|
if (thePrinterContext) {
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return rv;
|
|
|
|
}
|
2001-03-30 07:07:52 +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
|
2001-05-19 06:45:21 +04:00
|
|
|
if (!mInstanceOwner) {
|
1999-07-07 06:33:17 +04:00
|
|
|
// XXX - do we need to create this for widgets as well?
|
|
|
|
mInstanceOwner = new nsPluginInstanceOwner();
|
2001-05-19 06:45:21 +04:00
|
|
|
if(!mInstanceOwner) 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;
|
2001-03-10 06:17:40 +03:00
|
|
|
nsCOMPtr<nsIURI> baseURL;
|
|
|
|
nsCOMPtr<nsIURI> fullURL;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsAutoString classid;
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
|
|
|
|
// if we have a clsid, we're either an internal widget, an ActiveX control, or an applet
|
|
|
|
mContent->GetNameSpaceID(nameSpaceID);
|
2001-08-17 12:14:14 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttr(nameSpaceID, nsHTMLAtoms::classid, classid)) {
|
2001-03-10 06:17:40 +03:00
|
|
|
PRBool bJavaObject = PR_FALSE;
|
|
|
|
PRBool bJavaPluginClsid = PR_FALSE;
|
2001-01-12 02:56:35 +03:00
|
|
|
|
2001-05-19 06:45:21 +04:00
|
|
|
if (classid.Find("java:") != -1) {
|
2001-03-10 06:17:40 +03:00
|
|
|
classid.Cut(0, 5); // Strip off the "java:". What's left is the class file.
|
|
|
|
bJavaObject = PR_TRUE;
|
|
|
|
}
|
2001-01-12 02:56:35 +03:00
|
|
|
|
2001-05-19 06:45:21 +04:00
|
|
|
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-03-10 06:17:40 +03:00
|
|
|
bJavaPluginClsid = (classid.EqualsWithConversion(JAVA_CLASS_ID));
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-03-10 06:17:40 +03:00
|
|
|
// if we find "java:" in the class id, or we match the Java
|
|
|
|
// classid number, we have a java applet
|
2001-05-19 06:45:21 +04:00
|
|
|
if(bJavaObject || bJavaPluginClsid) {
|
|
|
|
if (NS_FAILED(rv = GetBaseURL(*getter_AddRefs(baseURL)))) return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
nsAutoString codeBase;
|
2001-05-19 06:45:21 +04:00
|
|
|
if ((NS_CONTENT_ATTR_HAS_VALUE ==
|
2001-08-17 12:14:14 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::codebase, codeBase)) &&
|
2001-05-19 06:45:21 +04:00
|
|
|
!bJavaPluginClsid) {
|
2001-03-10 06:17:40 +03:00
|
|
|
nsCOMPtr<nsIURI> codeBaseURL;
|
2001-10-09 14:15:06 +04:00
|
|
|
rv = MakeAbsoluteURL(getter_AddRefs(codeBaseURL), codeBase, baseURL);
|
2001-05-19 06:45:21 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-07-07 06:33:17 +04:00
|
|
|
baseURL = codeBaseURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an absolute URL
|
|
|
|
if(bJavaPluginClsid) {
|
2001-10-09 14:15:06 +04:00
|
|
|
rv = MakeAbsoluteURL(getter_AddRefs(fullURL), classid, baseURL);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
2001-05-19 06:45:21 +04:00
|
|
|
else fullURL = baseURL;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// get the nsIPluginHost interface
|
2000-04-13 06:53:18 +04:00
|
|
|
pluginHost = do_GetService(kCPluginManagerCID);
|
2001-05-19 06:45:21 +04:00
|
|
|
if (!pluginHost) return NS_ERROR_FAILURE;
|
2000-09-12 00:27:25 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
mInstanceOwner->SetPluginHost(pluginHost);
|
2001-03-10 06:17:40 +03:00
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState,
|
|
|
|
pluginHost, "application/x-java-vm", fullURL);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
2001-05-19 06:45:21 +04:00
|
|
|
else { // otherwise, we're either an ActiveX control or an internal widget
|
1999-07-07 06:33:17 +04:00
|
|
|
// These are some builtin types that we know about for now.
|
|
|
|
// (Eventually this will move somewhere else.)
|
2001-05-19 06:45:21 +04:00
|
|
|
if (classid.EqualsWithConversion("browser")) {
|
2001-03-10 06:17:40 +03:00
|
|
|
rv = InstantiateWidget(aPresContext, aMetrics,
|
|
|
|
aReflowState, kCAppShellCID);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
2001-05-19 06:45:21 +04:00
|
|
|
else {
|
2001-03-10 06:17:40 +03:00
|
|
|
// if we haven't matched to an internal type, check to see if
|
|
|
|
// we have an ActiveX handler
|
2001-01-12 02:56:35 +03:00
|
|
|
// if not, create the default plugin
|
2001-05-19 06:45:21 +04:00
|
|
|
if (NS_FAILED(rv = GetBaseURL(*getter_AddRefs(baseURL)))) return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-03-10 06:17:40 +03:00
|
|
|
// if we have a codebase, add it to the fullURL
|
|
|
|
nsAutoString codeBase;
|
2001-08-17 12:14:14 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::codebase, codeBase)) {
|
2001-03-10 06:17:40 +03:00
|
|
|
nsCOMPtr<nsIURI> codeBaseURL;
|
2001-10-09 14:15:06 +04:00
|
|
|
rv = MakeAbsoluteURL(getter_AddRefs(fullURL), codeBase, baseURL);
|
2001-05-19 06:45:21 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-07-07 06:33:17 +04:00
|
|
|
baseURL = codeBaseURL;
|
|
|
|
}
|
2001-05-19 06:45:21 +04:00
|
|
|
}
|
|
|
|
else fullURL = baseURL;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// get the nsIPluginHost interface
|
2000-04-13 06:53:18 +04:00
|
|
|
pluginHost = do_GetService(kCPluginManagerCID);
|
2001-05-19 06:45:21 +04:00
|
|
|
if (!pluginHost) return NS_ERROR_FAILURE;
|
2000-09-12 00:27:25 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
mInstanceOwner->SetPluginHost(pluginHost);
|
2001-05-19 06:45:21 +04:00
|
|
|
if (NS_SUCCEEDED(pluginHost->IsPluginEnabledForType("application/x-oleobject"))) {
|
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost,
|
|
|
|
"application/x-oleobject", fullURL);
|
|
|
|
}
|
|
|
|
else if (NS_SUCCEEDED(pluginHost->IsPluginEnabledForType("application/oleobject"))) {
|
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost,
|
|
|
|
"application/oleobject", fullURL);
|
|
|
|
}
|
|
|
|
else rv = NS_ERROR_FAILURE;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finish up
|
2001-05-19 06:45:21 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-07-07 06:33:17 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2001-05-19 06:45:21 +04:00
|
|
|
else { // the object is either an applet or a plugin
|
|
|
|
nsAutoString src;
|
|
|
|
if (NS_FAILED(rv = GetBaseURL(*getter_AddRefs(baseURL)))) return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-05-19 06:45:21 +04:00
|
|
|
// get the nsIPluginHost interface
|
|
|
|
pluginHost = do_GetService(kCPluginManagerCID);
|
|
|
|
if (!pluginHost) return NS_ERROR_FAILURE;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-05-19 06:45:21 +04:00
|
|
|
mInstanceOwner->SetPluginHost(pluginHost);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-05-19 06:45:21 +04:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
mContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag.get() == nsHTMLAtoms::applet) {
|
2001-08-17 12:14:14 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::code, src)) {
|
2001-05-19 06:45:21 +04:00
|
|
|
nsAutoString codeBase;
|
2001-08-17 12:14:14 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::codebase, codeBase)) {
|
2001-05-19 06:45:21 +04:00
|
|
|
nsCOMPtr<nsIURI> codeBaseURL;
|
2001-10-09 14:15:06 +04:00
|
|
|
rv = MakeAbsoluteURL(getter_AddRefs(codeBaseURL), codeBase, baseURL);
|
2001-05-19 06:45:21 +04:00
|
|
|
if(rv == NS_OK) {
|
|
|
|
baseURL = codeBaseURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Create an absolute URL
|
2001-10-09 14:15:06 +04:00
|
|
|
rv = MakeAbsoluteURL(getter_AddRefs(fullURL), src, baseURL);
|
2001-05-19 06:45:21 +04:00
|
|
|
}
|
2001-09-26 02:04:24 +04:00
|
|
|
else
|
|
|
|
fullURL = baseURL;
|
|
|
|
|
2001-05-19 06:45:21 +04:00
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState,
|
|
|
|
pluginHost, "application/x-java-vm", fullURL);
|
|
|
|
} else { // traditional plugin
|
2001-06-17 09:23:38 +04:00
|
|
|
nsXPIDLCString mimeTypeStr;
|
2001-05-19 06:45:21 +04:00
|
|
|
nsAutoString type;
|
2001-08-17 12:14:14 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::type, type);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-05-19 06:45:21 +04:00
|
|
|
if (type.Length()) {
|
2001-06-17 09:23:38 +04:00
|
|
|
mimeTypeStr.Adopt(ToNewCString(type));
|
2001-05-19 06:45:21 +04:00
|
|
|
}
|
|
|
|
//stream in the object source if there is one...
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE ==
|
2001-08-17 12:14:14 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::src, src)) {
|
2001-05-19 06:45:21 +04:00
|
|
|
// Create an absolute URL
|
2001-10-09 14:15:06 +04:00
|
|
|
rv = MakeAbsoluteURL(getter_AddRefs(fullURL), src, baseURL);
|
2001-05-19 06:45:21 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// 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;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
2001-05-19 06:45:21 +04:00
|
|
|
else if (NS_CONTENT_ATTR_HAS_VALUE ==
|
2001-08-17 12:14:14 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::data, src)) {
|
2001-05-19 06:45:21 +04:00
|
|
|
// Create an absolute URL
|
2001-10-09 14:15:06 +04:00
|
|
|
rv = MakeAbsoluteURL(getter_AddRefs(fullURL), src, baseURL);
|
2001-05-19 06:45:21 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// 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;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-05-19 06:45:21 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// we didn't find a src or data param, so just set the url to the base
|
2000-05-07 20:48:06 +04:00
|
|
|
fullURL = baseURL;
|
2001-05-19 06:45:21 +04:00
|
|
|
}
|
2000-05-07 20:48:06 +04:00
|
|
|
|
2001-07-25 02:45:14 +04:00
|
|
|
// now try to instantiate a plugin instance based on a mime type
|
2001-06-17 09:23:38 +04:00
|
|
|
const char* mimeType = mimeTypeStr.get();
|
2001-07-25 02:45:14 +04:00
|
|
|
if (mimeType || (src.Length() > 0)) {
|
|
|
|
if (!mimeType) {
|
|
|
|
// we don't have a mime type, try to figure it out from extension
|
|
|
|
nsXPIDLCString extension;
|
|
|
|
PRInt32 offset = src.RFindChar(PRUnichar('.'));
|
|
|
|
if (offset != kNotFound)
|
|
|
|
*getter_Copies(extension) = ToNewCString(Substring(src, offset+1, src.Length()));
|
|
|
|
pluginHost->IsPluginEnabledForExtension(extension, mimeType);
|
2001-05-19 06:45:21 +04:00
|
|
|
}
|
2001-07-25 02:45:14 +04:00
|
|
|
// if we fail to get a mime type from extension we can still try to
|
|
|
|
// instantiate plugin as it can be possible to determine it later
|
|
|
|
rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState,
|
|
|
|
pluginHost, mimeType, fullURL);
|
2001-05-19 06:45:21 +04:00
|
|
|
}
|
2001-07-25 02:45:14 +04:00
|
|
|
else // if we have neither we should not bother
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
2001-03-10 06:17:40 +03:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
2001-05-19 06:45:21 +04:00
|
|
|
else { // if (!mInstanceOwner)
|
1999-09-30 12:07:23 +04:00
|
|
|
rv = ReinstantiatePlugin(aPresContext, aMetrics, aReflowState);
|
2001-05-19 06:45:21 +04:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
// finish up
|
2001-06-13 06:42:47 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2001-12-14 06:48:49 +03:00
|
|
|
// if we got an error, we are probably going to be replaced
|
|
|
|
|
|
|
|
// for a replaced object frame, clear our vertical alignment style info, see bug 36997
|
|
|
|
nsStyleTextReset* text = NS_STATIC_CAST(nsStyleTextReset*,
|
|
|
|
mStyleContext->GetUniqueStyleData(mPresContext, eStyleStruct_TextReset));
|
|
|
|
text->mVerticalAlign.SetNormalValue();
|
|
|
|
|
|
|
|
//check for alternative content with CantRenderReplacedElement()
|
2001-06-13 06:42:47 +04:00
|
|
|
nsIPresShell* presShell;
|
|
|
|
aPresContext->GetShell(&presShell);
|
2001-06-22 11:04:24 +04:00
|
|
|
rv = presShell->CantRenderReplacedElement(aPresContext, this);
|
2001-06-13 06:42:47 +04:00
|
|
|
NS_RELEASE(presShell);
|
|
|
|
} else {
|
|
|
|
NotifyContentObjectWrapper();
|
2001-05-19 06:45:21 +04:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2001-05-19 06:45:21 +04:00
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIPluginHost* aPluginHost,
|
|
|
|
const char* aMimetype,
|
2001-05-22 02:40:10 +04:00
|
|
|
nsIURI* aURI)
|
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
|
|
|
|
2001-05-22 02:40:10 +04:00
|
|
|
SetFullURL(aURI);
|
1999-07-07 06:33:17 +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-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
|
2001-05-22 02:40:10 +04:00
|
|
|
if(aURI != nsnull)
|
2000-06-03 00:20:35 +04:00
|
|
|
{
|
|
|
|
PRBool shouldLoad = PR_TRUE; // default permit
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mContent, &rv);
|
2001-05-22 02:40:10 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-06-03 00:20:35 +04:00
|
|
|
|
2001-05-22 02:40:10 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
rv = shell->GetDocument(getter_AddRefs(document));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-07-04 09:54:09 +04:00
|
|
|
if (! document)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-05-22 02:40:10 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalScript;
|
|
|
|
rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWin(do_QueryInterface(globalScript));
|
2001-01-12 02:56:35 +03:00
|
|
|
|
2000-06-03 00:20:35 +04:00
|
|
|
if (NS_SUCCEEDED(rv) &&
|
2001-05-22 02:40:10 +04:00
|
|
|
NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::OBJECT,
|
|
|
|
aURI, element, domWin, &shouldLoad)) &&
|
2000-06-03 00:20:35 +04:00
|
|
|
!shouldLoad) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-25 17:32:42 +04:00
|
|
|
}
|
|
|
|
|
2001-05-22 02:40:10 +04:00
|
|
|
return aPluginHost->InstantiateEmbededPlugin(aMimetype, aURI, mInstanceOwner);
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
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
|
2001-08-16 07:02:05 +04:00
|
|
|
nsObjectFrame::HandleChild(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);
|
2001-12-07 17:51:12 +03:00
|
|
|
FinishReflowChild(child, aPresContext, &kidReflowState, 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
|
|
|
|
{
|
2001-07-04 09:54:09 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
mContent->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (doc)
|
1999-07-07 06:33:17 +04:00
|
|
|
doc->GetBaseURL(aURL);
|
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
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleVisibility* vis = (const nsStyleVisibility*)mStyleContext->GetStyleData(eStyleStruct_Visibility);
|
|
|
|
if (vis != nsnull)
|
2000-09-04 00:54:26 +04:00
|
|
|
{
|
2001-06-01 02:19:43 +04:00
|
|
|
if(!vis->IsVisibleOrCollapsed())
|
2000-09-04 00:54:26 +04:00
|
|
|
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;
|
2001-08-17 12:14:14 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::hidden, hidden);
|
2000-07-20 03:46:43 +04:00
|
|
|
|
|
|
|
// 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() &&
|
2001-11-14 04:33:42 +03:00
|
|
|
(Compare(hidden, NS_LITERAL_STRING("false"), nsCaseInsensitiveStringComparator()) != 0) &&
|
|
|
|
(Compare(hidden, NS_LITERAL_STRING("no"), nsCaseInsensitiveStringComparator()) != 0) &&
|
|
|
|
(Compare(hidden, NS_LITERAL_STRING("off"), nsCaseInsensitiveStringComparator()) != 0)) {
|
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
|
2001-12-07 17:51:12 +03:00
|
|
|
nsObjectFrame::DidReflow(nsIPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState* aReflowState,
|
|
|
|
nsDidReflowStatus aStatus)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2001-12-07 17:51:12 +03:00
|
|
|
nsresult rv = nsObjectFrameSuper::DidReflow(aPresContext, aReflowState, aStatus);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
// 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) {
|
2001-12-01 17:31:45 +03:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
view->GetViewManager(*getter_AddRefs(vm));
|
|
|
|
if (vm) {
|
|
|
|
vm->SetViewVisibility(view, nsViewVisibility_kShow);
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mInstanceOwner) {
|
|
|
|
nsPluginWindow *window;
|
|
|
|
|
|
|
|
if (NS_OK == mInstanceOwner->GetWindow(window)) {
|
|
|
|
nsIView *parentWithView;
|
|
|
|
nsPoint origin;
|
2001-03-28 05:02:30 +04:00
|
|
|
nsIPluginInstance *inst;
|
1999-07-07 06:33:17 +04:00
|
|
|
float t2p;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetTwipsToPixels(&t2p);
|
2001-08-07 05:50:32 +04:00
|
|
|
nscoord offx = 0;
|
|
|
|
nscoord offy = 0;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
GetOffsetFromView(aPresContext, origin, &parentWithView);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-06-19 01:41:57 +04:00
|
|
|
// if it's windowless we want to get the offset from the parent frame
|
|
|
|
if (window->type == nsPluginWindowType_Drawable)
|
|
|
|
{
|
|
|
|
|
2001-08-07 05:50:32 +04:00
|
|
|
nsIWidget* aWidget;
|
|
|
|
parentWithView->GetOffsetFromWidget(&offx, &offy, aWidget);
|
|
|
|
|
|
|
|
nsIFrame* parentFrame;
|
2001-06-19 01:41:57 +04:00
|
|
|
GetParentWithView(aPresContext, &parentFrame);
|
|
|
|
|
|
|
|
if(parentFrame != nsnull)
|
|
|
|
parentFrame->GetOffsetFromView(aPresContext, origin, &parentWithView);
|
|
|
|
|
2001-08-07 05:50:32 +04:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-08-07 05:50:32 +04:00
|
|
|
window->x = NSTwipsToIntPixels(origin.x + offx, t2p);
|
|
|
|
window->y = NSTwipsToIntPixels(origin.y + offy, t2p);
|
1999-07-07 06:33:17 +04:00
|
|
|
// 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
|
2001-03-28 05:02:30 +04:00
|
|
|
if (NS_OK == mInstanceOwner->GetInstance(inst)) {
|
|
|
|
inst->SetWindow(window);
|
|
|
|
NS_RELEASE(inst);
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
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
|
2001-09-19 16:35:19 +04:00
|
|
|
nsObjectFrame::Paint(nsIPresContext* aPresContext,
|
1999-07-07 06:33:17 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-09-19 16:35:19 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleVisibility* vis = (const nsStyleVisibility*)mStyleContext->GetStyleData(eStyleStruct_Visibility);
|
|
|
|
if ((vis != nsnull) && !vis->IsVisibleOrCollapsed()) {
|
2001-03-30 07:07:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame * child = mFrames.FirstChild();
|
2001-09-18 06:11:09 +04:00
|
|
|
if (child) { // if we have children, we are probably not really a plugin
|
2001-03-30 07:07:52 +04:00
|
|
|
nsObjectFrameSuper::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-18 06:11:09 +04:00
|
|
|
// determine if we are printing
|
|
|
|
nsCOMPtr<nsIPrintContext> thePrinterContext = do_QueryInterface(aPresContext);
|
|
|
|
if (thePrinterContext) {
|
|
|
|
// we only want to print on the content layer pass
|
|
|
|
if (eFramePaintLayer_Content != aWhichLayer)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// if we are printing, we need to get the correct nsIPluginInstance
|
|
|
|
// for THIS content node in order to call ->Print() on the right plugin
|
|
|
|
|
|
|
|
// first, we need to get the document
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
mContent->GetDocument(*getter_AddRefs(doc));
|
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
// now we need to get the shell for the screen
|
|
|
|
// XXX assuming that the shell at zero will always be the screen one
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
doc->GetShellAt(0, getter_AddRefs(shell));
|
|
|
|
NS_ENSURE_TRUE(shell, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
// then the shell can give us the screen frame for this content node
|
|
|
|
nsIFrame* frame = nsnull;
|
|
|
|
shell->GetPrimaryFrameFor(mContent, &frame);
|
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
// make sure this is REALLY an nsIObjectFrame
|
|
|
|
// we may need to go through the children to get it
|
|
|
|
nsIObjectFrame* objectFrame = nsnull;
|
|
|
|
CallQueryInterface(frame,&objectFrame);
|
|
|
|
if (!objectFrame)
|
|
|
|
GetNextObjectFrame(aPresContext,frame,&objectFrame);
|
|
|
|
NS_ENSURE_TRUE(objectFrame,NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// finally we can get our plugin instance
|
|
|
|
nsCOMPtr<nsIPluginInstance> pi;
|
|
|
|
if (NS_FAILED(objectFrame->GetPluginInstance(*getter_AddRefs(pi))) || !pi)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// now we need to setup the correct location for printing
|
|
|
|
nsresult rv;
|
|
|
|
nsPluginWindow window;
|
|
|
|
nsIView *parentWithView;
|
|
|
|
nsPoint origin;
|
|
|
|
float t2p;
|
|
|
|
nsMargin margin(0,0,0,0);
|
|
|
|
window.window = nsnull;
|
|
|
|
|
|
|
|
// prepare embedded mode printing struct
|
|
|
|
nsPluginPrint npprint;
|
|
|
|
npprint.mode = nsPluginMode_Embedded;
|
|
|
|
|
|
|
|
// we need to find out if we are windowless or not
|
|
|
|
PRBool windowless;
|
|
|
|
pi->GetValue(nsPluginInstanceVariable_WindowlessBool, (void *)&windowless);
|
|
|
|
window.type = windowless ? nsPluginWindowType_Drawable : nsPluginWindowType_Window;
|
|
|
|
|
|
|
|
// get a few things
|
|
|
|
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
|
|
|
|
NS_ENSURE_TRUE(printService, NS_ERROR_FAILURE);
|
|
|
|
printService->GetMarginInTwips(margin);
|
|
|
|
|
|
|
|
aPresContext->GetTwipsToPixels(&t2p);
|
|
|
|
GetOffsetFromView(aPresContext, origin, &parentWithView);
|
|
|
|
|
|
|
|
// set it all up
|
|
|
|
// XXX is windowless different?
|
|
|
|
window.x = NSToCoordRound((origin.x + margin.left) * t2p);
|
|
|
|
window.y = NSToCoordRound((origin.y + margin.top ) * t2p);
|
|
|
|
window.width = NSToCoordRound(mRect.width * t2p);
|
|
|
|
window.height= NSToCoordRound(mRect.height * t2p);
|
|
|
|
window.clipRect.bottom = 0; window.clipRect.top = 0;
|
|
|
|
window.clipRect.left = 0; window.clipRect.right = 0;
|
|
|
|
|
|
|
|
// XXX platform specific printing code
|
|
|
|
#if defined(XP_MAC) && !TARGET_CARBON
|
|
|
|
// Mac does things a little differently.
|
|
|
|
GrafPort *curPort;
|
|
|
|
::GetPort(&curPort); // get the current port
|
|
|
|
|
|
|
|
nsPluginPort port;
|
|
|
|
port.port = (CGrafPort*)curPort;
|
|
|
|
port.portx = window.x;
|
|
|
|
port.porty = window.y;
|
|
|
|
|
|
|
|
RgnHandle curClip = ::NewRgn();
|
|
|
|
NS_ENSURE_TRUE(curClip, NS_ERROR_NULL_POINTER);
|
|
|
|
::GetClip(curClip); // save old clip
|
|
|
|
|
|
|
|
::SetOrigin(-window.x,-window.y); // port must be set correctly prior to telling plugin to print
|
|
|
|
Rect r = {0,0,window.height,window.width};
|
|
|
|
::ClipRect(&r); // also set the clip
|
|
|
|
|
|
|
|
window.window = &port;
|
|
|
|
npprint.print.embedPrint.platformPrint = (void*)window.window;
|
|
|
|
|
|
|
|
#elif defined (XP_UNIX)
|
|
|
|
// UNIX does things completely differently
|
|
|
|
PRUnichar *printfile = nsnull;
|
|
|
|
printService->GetToFileName(&printfile);
|
|
|
|
if (!printfile)
|
|
|
|
return NS_OK; // XXX what to do on UNIX when we don't have a PS file????
|
|
|
|
|
|
|
|
NPPrintCallbackStruct npPrintInfo;
|
|
|
|
npPrintInfo.type = NP_PRINT;
|
|
|
|
npPrintInfo.fp = (FILE*)printfile;
|
|
|
|
npprint.print.embedPrint.platformPrint = (void*) &npPrintInfo;
|
|
|
|
|
|
|
|
#else // Windows and non-UNIX, non-Mac(Classic) cases
|
|
|
|
// we need the native printer device context to pass to plugin
|
|
|
|
// On Windows, this will be the HDC
|
|
|
|
PRUint32 pDC = 0;
|
|
|
|
aRenderingContext.RetrieveCurrentNativeGraphicData(&pDC);
|
|
|
|
|
|
|
|
if (!pDC)
|
|
|
|
return NS_OK; // no dc implemented so quit
|
|
|
|
|
|
|
|
npprint.print.embedPrint.platformPrint = (void*)pDC;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
npprint.print.embedPrint.window = window;
|
|
|
|
// send off print info to plugin
|
|
|
|
rv = pi->Print(&npprint);
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(XP_MAC) && !TARGET_CARBON
|
|
|
|
// Clean-up on Mac
|
|
|
|
::SetOrigin(0,0);
|
|
|
|
::SetClip(curClip); // restore previous clip
|
|
|
|
::DisposeRgn(curClip);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// XXX Nav 4.x always sent a SetWindow call after print. Should we do the same?
|
|
|
|
nsCOMPtr<nsIPresContext> screenPcx;
|
|
|
|
shell->GetPresContext(getter_AddRefs(screenPcx));
|
|
|
|
nsDidReflowStatus status = NS_FRAME_REFLOW_FINISHED; // should we use a special status?
|
2001-12-07 17:51:12 +03:00
|
|
|
frame->DidReflow(screenPcx, nsnull, status); // DidReflow will take care of it
|
2001-09-18 06:11:09 +04:00
|
|
|
|
|
|
|
return rv; // done with printing
|
|
|
|
}
|
|
|
|
|
|
|
|
// Screen painting code
|
2000-07-12 00:06:05 +04:00
|
|
|
#if defined (XP_MAC)
|
2001-11-13 03:30:44 +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-11-13 03:30:44 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
|
|
|
nsIPluginInstance * inst;
|
|
|
|
if (NS_OK == GetPluginInstance(inst)) {
|
|
|
|
// Look if it's windowless
|
|
|
|
nsPluginWindow * window;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
|
|
|
|
if (window->type == nsPluginWindowType_Drawable) {
|
|
|
|
PRUint32 hdc;
|
|
|
|
aRenderingContext.RetrieveCurrentNativeGraphicData(&hdc);
|
|
|
|
if(NS_REINTERPRET_CAST(PRUint32, window->window) != hdc) {
|
|
|
|
window->window = NS_REINTERPRET_CAST(nsPluginPort*, hdc);
|
|
|
|
inst->SetWindow(window);
|
2001-01-12 02:56:35 +03:00
|
|
|
}
|
2001-11-13 03:30:44 +03:00
|
|
|
mInstanceOwner->Paint(aDirtyRect, hdc);
|
|
|
|
}
|
|
|
|
NS_RELEASE(inst);
|
2001-01-12 02:56:35 +03:00
|
|
|
}
|
2001-11-13 03:30:44 +03:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif /* !XP_MAC */
|
2001-11-13 03:30:44 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsObjectFrame", &aRenderingContext);
|
|
|
|
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;
|
2001-04-25 01:03:27 +04:00
|
|
|
|
|
|
|
if (anEvent->message == NS_PLUGIN_ACTIVATE)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
GetContent(getter_AddRefs(content));
|
|
|
|
if (content)
|
|
|
|
{
|
|
|
|
content->SetFocus(aPresContext);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
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:
|
|
|
|
*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)
|
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
aPluginInstance = nsnull;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsresult
|
|
|
|
nsObjectFrame::NotifyContentObjectWrapper()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
mContent->GetDocument(*getter_AddRefs(doc));
|
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
|
|
|
doc->GetScriptGlobalObject(getter_AddRefs(sgo));
|
|
|
|
NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> scx;
|
|
|
|
sgo->GetContext(getter_AddRefs(scx));
|
|
|
|
NS_ENSURE_TRUE(scx, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
JSContext *cx = (JSContext *)scx->GetNativeContext();
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
|
|
|
xpc->GetWrappedNativeOfNativeObject(cx, ::JS_GetGlobalObject(cx), mContent,
|
|
|
|
NS_GET_IID(nsISupports),
|
|
|
|
getter_AddRefs(wrapper));
|
|
|
|
|
|
|
|
if (!wrapper) {
|
|
|
|
// Nothing to do here if there's no wrapper for mContent
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIClassInfo> ci(do_QueryInterface(mContent));
|
|
|
|
NS_ENSURE_TRUE(ci, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> s;
|
|
|
|
ci->GetHelperForLanguage(nsIProgrammingLanguage::JAVASCRIPT,
|
|
|
|
getter_AddRefs(s));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXPCScriptable> helper(do_QueryInterface(s));
|
|
|
|
|
|
|
|
if (!helper) {
|
|
|
|
// There's nothing we can do if there's no helper
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *obj = nsnull;
|
|
|
|
rv = wrapper->GetJSObject(&obj);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Abuse the scriptable helper to trigger prototype setup for the
|
|
|
|
// wrapper for mContent so that this plugin becomes part of the DOM
|
|
|
|
// object.
|
|
|
|
return helper->PostCreate(wrapper, cx, obj);
|
|
|
|
}
|
|
|
|
|
2001-09-18 06:11:09 +04:00
|
|
|
nsresult
|
|
|
|
nsObjectFrame::GetNextObjectFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aRoot,
|
|
|
|
nsIObjectFrame** outFrame)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outFrame);
|
|
|
|
|
|
|
|
nsIFrame * child;
|
|
|
|
aRoot->FirstChild(aPresContext, nsnull, &child);
|
|
|
|
|
|
|
|
while (child != nsnull) {
|
|
|
|
*outFrame = nsnull;
|
|
|
|
CallQueryInterface(child, outFrame);
|
|
|
|
if (nsnull != *outFrame) {
|
|
|
|
nsCOMPtr<nsIPluginInstance> pi;
|
|
|
|
(*outFrame)->GetPluginInstance(*getter_AddRefs(pi)); // make sure we have a REAL plugin
|
|
|
|
if (pi) return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetNextObjectFrame(aPresContext, child, outFrame);
|
|
|
|
child->GetNextSibling(&child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//plugin instance owner
|
|
|
|
|
|
|
|
nsPluginInstanceOwner::nsPluginInstanceOwner()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
memset(&mPluginWindow, 0, sizeof(mPluginWindow));
|
|
|
|
mInstance = nsnull;
|
|
|
|
mOwner = nsnull;
|
|
|
|
mWidget = nsnull;
|
|
|
|
mContext = 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;
|
2001-10-09 02:58:59 +04:00
|
|
|
mContentFocused = PR_FALSE;
|
2001-12-11 18:53:07 +03:00
|
|
|
mNumCachedAttrs = 0;
|
|
|
|
mNumCachedParams = 0;
|
|
|
|
mCachedAttrParamNames = nsnull;
|
|
|
|
mCachedAttrParamValues = nsnull;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginInstanceOwner::~nsPluginInstanceOwner()
|
|
|
|
{
|
|
|
|
PRInt32 cnt;
|
|
|
|
|
|
|
|
// shut off the timer.
|
|
|
|
if (mPluginTimer != nsnull) {
|
2001-07-11 06:29:45 +04:00
|
|
|
CancelTimer();
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
2001-08-17 04:45:25 +04:00
|
|
|
NS_IF_RELEASE(mInstance);
|
2000-10-06 06:45:53 +04:00
|
|
|
NS_IF_RELEASE(mPluginHost);
|
1999-07-07 06:33:17 +04:00
|
|
|
mOwner = nsnull;
|
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
for (cnt = 0; cnt < (mNumCachedAttrs + 1 + mNumCachedParams); cnt++) {
|
|
|
|
if ((nsnull != mCachedAttrParamNames) && (nsnull != mCachedAttrParamNames[cnt])) {
|
|
|
|
PR_Free(mCachedAttrParamNames[cnt]);
|
|
|
|
mCachedAttrParamNames[cnt] = nsnull;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
if ((nsnull != mCachedAttrParamValues) && (nsnull != mCachedAttrParamValues[cnt])) {
|
|
|
|
PR_Free(mCachedAttrParamValues[cnt]);
|
|
|
|
mCachedAttrParamValues[cnt] = nsnull;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
if (nsnull != mCachedAttrParamNames) {
|
|
|
|
PR_Free(mCachedAttrParamNames);
|
|
|
|
mCachedAttrParamNames = nsnull;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
if (nsnull != mCachedAttrParamValues) {
|
|
|
|
PR_Free(mCachedAttrParamValues);
|
|
|
|
mCachedAttrParamValues = nsnull;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
if (nsnull != mDocumentBase) {
|
1999-08-03 06:51:39 +04:00
|
|
|
nsCRT::free(mDocumentBase);
|
|
|
|
mDocumentBase = nsnull;
|
|
|
|
}
|
2000-10-19 05:37:53 +04:00
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
if (nsnull != mTagText) {
|
2000-10-19 05:37:53 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-08-07 05:48:14 +04:00
|
|
|
NS_IMPL_ISUPPORTS10(nsPluginInstanceOwner,
|
|
|
|
nsIPluginInstanceOwner,
|
|
|
|
nsIPluginTagInfo,
|
|
|
|
nsIPluginTagInfo2,
|
|
|
|
nsIJVMPluginTagInfo,
|
|
|
|
nsIEventListener,
|
|
|
|
nsITimerCallback,
|
|
|
|
nsIDOMMouseListener,
|
|
|
|
nsIDOMMouseMotionListener,
|
|
|
|
nsIDOMKeyListener,
|
|
|
|
nsIDOMFocusListener)
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2001-12-11 18:53:07 +03:00
|
|
|
nsresult rv = EnsureCachedAttrParamArrays();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
n = mNumCachedAttrs;
|
|
|
|
names = (const char **)mCachedAttrParamNames;
|
|
|
|
values = (const char **)mCachedAttrParamValues;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetAttribute(const char* name, const char* *result)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(name);
|
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
2001-12-11 18:53:07 +03:00
|
|
|
|
|
|
|
nsresult rv = EnsureCachedAttrParamArrays();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
*result = nsnull;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
for (int i = 0; i < mNumCachedAttrs; i++) {
|
|
|
|
if (0 == PL_strcasecmp(mCachedAttrParamNames[i], name)) {
|
|
|
|
*result = mCachedAttrParamValues[i];
|
1999-07-07 06:33:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-01-05 04:18:38 +03:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetDOMElement(nsIDOMElement* *result)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
2000-01-05 04:18:38 +03:00
|
|
|
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,
|
2001-11-07 06:03:04 +03:00
|
|
|
PRUint32 aHeadersDataLen, PRBool isFile)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2001-09-26 06:45:20 +04:00
|
|
|
NS_ENSURE_TRUE(mOwner,NS_ERROR_NULL_POINTER);
|
|
|
|
NS_ENSURE_TRUE(mContext,NS_ERROR_NULL_POINTER);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-26 06:45:20 +04:00
|
|
|
// the container of the pres context will give us the link handler
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
nsresult rv = mContext->GetContainer(getter_AddRefs(container));
|
|
|
|
NS_ENSURE_TRUE(container,NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsILinkHandler> lh = do_QueryInterface(container);
|
|
|
|
NS_ENSURE_TRUE(lh, NS_ERROR_FAILURE);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-26 06:45:20 +04:00
|
|
|
nsAutoString uniurl; uniurl.AssignWithConversion(aURL);
|
|
|
|
nsAutoString unitarget; unitarget.AssignWithConversion(aTarget);
|
|
|
|
nsAutoString fullurl;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-26 06:45:20 +04:00
|
|
|
nsCOMPtr<nsIURI> baseURL;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
rv = GetDocument(getter_AddRefs(doc));
|
|
|
|
if (NS_SUCCEEDED(rv) && doc) {
|
|
|
|
rv = doc->GetBaseURL(*getter_AddRefs(baseURL)); // gets the document's url
|
|
|
|
} else {
|
|
|
|
mOwner->GetFullURL(*getter_AddRefs(baseURL)); // gets the plugin's content url
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-26 06:45:20 +04:00
|
|
|
// Create an absolute URL
|
|
|
|
NS_MakeAbsoluteURI(fullurl, uniurl, baseURL);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-26 06:45:20 +04:00
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv),NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mOwner->GetContent(getter_AddRefs(content));
|
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-26 06:45:20 +04:00
|
|
|
nsCOMPtr<nsIInputStream> postDataStream;
|
|
|
|
nsCOMPtr<nsIInputStream> headersDataStream;
|
2001-11-07 06:03:04 +03:00
|
|
|
|
|
|
|
// deal with post data, either in a file or raw data, and any headers
|
2001-09-26 06:45:20 +04:00
|
|
|
if (aPostData) {
|
2001-12-12 04:38:02 +03:00
|
|
|
const char * dataToPost = (const char *)aPostData; // default to raw data
|
|
|
|
nsXPIDLCString filename;
|
|
|
|
|
2001-11-07 06:03:04 +03:00
|
|
|
if (isFile) {
|
2001-12-12 04:38:02 +03:00
|
|
|
// convert file:///c:/ to c: if needed
|
|
|
|
nsCOMPtr<nsILocalFile> aFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
|
|
|
if (NS_SUCCEEDED(aFile->SetURL(dataToPost)) &&
|
|
|
|
NS_SUCCEEDED(aFile->GetPath(getter_Copies(filename))))
|
|
|
|
dataToPost = filename;
|
2001-11-07 06:03:04 +03:00
|
|
|
}
|
|
|
|
|
2001-12-12 04:38:02 +03:00
|
|
|
rv = NS_NewPluginPostDataStream(getter_AddRefs(postDataStream), dataToPost, aPostDataLen, isFile);
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),"failed in creating plugin post data stream");
|
|
|
|
|
|
|
|
if (aHeadersData) {
|
|
|
|
rv = NS_NewPluginPostDataStream(getter_AddRefs(headersDataStream),
|
|
|
|
(const char *) aHeadersData,
|
|
|
|
aHeadersDataLen,
|
|
|
|
PR_FALSE,
|
|
|
|
PR_TRUE); // last arg says we are headers, no /r/n/r/n fixup!
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),"failed in creating plugin header data stream");
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
2001-09-26 06:45:20 +04:00
|
|
|
|
|
|
|
rv = lh->OnLinkClick(content, eLinkVerb_Replace,
|
|
|
|
fullurl.get(), unitarget.get(),
|
|
|
|
postDataStream, headersDataStream);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::ShowStatus(const char *aStatusMsg)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2001-09-05 07:58:34 +04:00
|
|
|
|
|
|
|
rv = this->ShowStatus(NS_ConvertUTF8toUCS2(aStatusMsg).get());
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-05 07:58:34 +04:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::ShowStatus(const PRUnichar *aStatusMsg)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-05 07:58:34 +04:00
|
|
|
if (!mContext) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsISupports> cont;
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
|
|
|
|
rv = mContext->GetContainer(getter_AddRefs(cont));
|
|
|
|
if (NS_FAILED(rv) || !cont) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-05 07:58:34 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellItem(do_QueryInterface(cont, &rv));
|
|
|
|
if (NS_FAILED(rv) || !docShellItem) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-05 07:58:34 +04:00
|
|
|
rv = docShellItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
|
|
|
if (NS_FAILED(rv) || !treeOwner) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-09-05 07:58:34 +04:00
|
|
|
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(treeOwner, &rv));
|
|
|
|
if (NS_FAILED(rv) || !browserChrome) {
|
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
2001-09-05 07:58:34 +04:00
|
|
|
rv = browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_SCRIPT,
|
|
|
|
aStatusMsg);
|
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;
|
|
|
|
}
|
|
|
|
|
2001-06-19 01:41:57 +04:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::InvalidateRect(nsPluginRect *invalidRect)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if(invalidRect)
|
|
|
|
{
|
|
|
|
//no reference count on view
|
|
|
|
nsIView* view;
|
|
|
|
rv = mOwner->GetView(mContext, &view);
|
|
|
|
|
|
|
|
if((rv == NS_OK) && view)
|
|
|
|
{
|
|
|
|
float ptot;
|
|
|
|
mContext->GetPixelsToTwips(&ptot);
|
|
|
|
|
|
|
|
nsRect rect((int)(ptot * invalidRect->left),
|
|
|
|
(int)(ptot * invalidRect->top),
|
|
|
|
(int)(ptot * (invalidRect->right - invalidRect->left)),
|
|
|
|
(int)(ptot * (invalidRect->bottom - invalidRect->top)));
|
|
|
|
|
|
|
|
nsIViewManager* manager;
|
|
|
|
rv = view->GetViewManager(manager);
|
|
|
|
|
|
|
|
//set flags to not do a synchronous update, force update does the redraw
|
|
|
|
if((rv == NS_OK) && manager)
|
|
|
|
{
|
|
|
|
rv = manager->UpdateView(view, rect, NS_VMREFRESH_NO_SYNC);
|
|
|
|
NS_RELEASE(manager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::InvalidateRegion(nsPluginRegion invalidRegion)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::ForceRedraw()
|
|
|
|
{
|
|
|
|
//no reference count on view
|
|
|
|
nsIView* view;
|
|
|
|
nsresult rv = mOwner->GetView(mContext, &view);
|
|
|
|
|
|
|
|
if((rv == NS_OK) && view)
|
|
|
|
{
|
|
|
|
nsIViewManager* manager;
|
|
|
|
rv = view->GetViewManager(manager);
|
|
|
|
|
|
|
|
if((rv == NS_OK) && manager)
|
|
|
|
{
|
|
|
|
rv = manager->Composite();
|
|
|
|
NS_RELEASE(manager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetValue(nsPluginInstancePeerVariable variable, void *value)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
switch(variable)
|
|
|
|
{
|
|
|
|
case nsPluginInstancePeerVariable_NetscapeWindow:
|
|
|
|
{
|
|
|
|
//no reference count on view
|
|
|
|
nsIView* view;
|
|
|
|
rv = mOwner->GetView(mContext, &view);
|
|
|
|
|
|
|
|
if((rv == NS_OK) && view)
|
|
|
|
{
|
|
|
|
nsIViewManager* manager;
|
|
|
|
rv = view->GetViewManager(manager);
|
|
|
|
|
|
|
|
if((rv == NS_OK) && manager)
|
|
|
|
{
|
|
|
|
nsIWidget* widget;
|
|
|
|
rv = manager->GetWidget(&widget);
|
|
|
|
|
|
|
|
if((rv == NS_OK) && widget)
|
|
|
|
{
|
|
|
|
void** pvalue = (void**)value;
|
|
|
|
*pvalue = (void*)widget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
|
|
|
NS_RELEASE(manager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetTagType(nsPluginTagType *result)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
1999-07-07 06:33:17 +04:00
|
|
|
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)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(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;
|
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID,&rv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-10-19 05:37:53 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2001-09-29 12:28:41 +04:00
|
|
|
mTagText = ToNewUTF8String(elementHTML);
|
2000-10-19 05:37:53 +04:00
|
|
|
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)
|
|
|
|
{
|
2001-12-11 18:53:07 +03:00
|
|
|
nsresult rv = EnsureCachedAttrParamArrays();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
// make sure we have at least one param tag because embed's don't have any
|
|
|
|
if (!mNumCachedParams)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
n = mNumCachedParams;
|
|
|
|
names = (const char **)(mCachedAttrParamNames + mNumCachedAttrs + 1);
|
|
|
|
values = (const char **)(mCachedAttrParamValues + mNumCachedAttrs + 1);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetParameter(const char* name, const char* *result)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(name);
|
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
2001-12-11 18:53:07 +03:00
|
|
|
|
|
|
|
nsresult rv = EnsureCachedAttrParamArrays();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
*result = nsnull;
|
1999-07-07 06:33:17 +04:00
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
for (int i = mNumCachedAttrs + 1; i < (mNumCachedParams + 1 + mNumCachedAttrs); i++) {
|
|
|
|
if (0 == PL_strcasecmp(mCachedAttrParamNames[i], name)) {
|
|
|
|
*result = mCachedAttrParamValues[i];
|
|
|
|
return NS_OK;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
1999-08-03 06:51:39 +04:00
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetDocumentBase(const char* *result)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
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));
|
|
|
|
|
2001-06-05 21:58:31 +04:00
|
|
|
nsCOMPtr<nsIURI> docURL;
|
|
|
|
doc->GetBaseURL(*getter_AddRefs(docURL)); // should return base + doc url
|
1999-07-07 06:33:17 +04:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
2001-09-18 06:11:09 +04:00
|
|
|
static nsresult
|
|
|
|
GetContainingBlock(nsIFrame *aFrame, nsIFrame **aContainingBlock)
|
2000-05-23 01:36:35 +04:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
2001-08-14 11:59:59 +04:00
|
|
|
*result = NS_PTR_TO_INT32(mContext);
|
1999-07-07 06:33:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetCode(const char* *result)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsPluginTagType tagType;
|
|
|
|
NS_ENSURE_SUCCESS(rv = GetTagType(&tagType), rv);
|
|
|
|
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
if (nsPluginTagType_Object != tagType)
|
|
|
|
rv = GetAttribute("CODE", result);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = GetParameter("CODE", result);
|
|
|
|
|
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetCodeBase(const char* *result)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
nsresult rv;
|
|
|
|
if (NS_FAILED(rv = GetAttribute("CODEBASE", result)))
|
|
|
|
rv = GetParameter("CODEBASE", result);
|
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetArchive(const char* *result)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
nsresult rv;
|
|
|
|
if (NS_FAILED(rv = GetAttribute("ARCHIVE", result)))
|
|
|
|
rv = GetParameter("ARCHIVE", result);
|
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetName(const char* *result)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsPluginTagType tagType;
|
|
|
|
NS_ENSURE_SUCCESS(rv = GetTagType(&tagType), rv);
|
|
|
|
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
if (nsPluginTagType_Object != tagType)
|
|
|
|
rv = GetAttribute("NAME", result);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = GetParameter("NAME", result);
|
|
|
|
|
|
|
|
return rv;
|
1999-07-07 06:33:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginInstanceOwner::GetMayScript(PRBool *result)
|
|
|
|
{
|
2001-11-20 05:17:21 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
|
|
|
nsPluginTagType tagType;
|
|
|
|
NS_ENSURE_SUCCESS(GetTagType(&tagType), NS_ERROR_FAILURE);
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
const char* unused;
|
2001-11-20 05:17:21 +03:00
|
|
|
if (nsPluginTagType_Object == tagType)
|
|
|
|
*result = NS_SUCCEEDED(GetParameter("MAYSCRIPT", &unused));
|
|
|
|
else
|
|
|
|
*result = NS_SUCCEEDED(GetAttribute("MAYSCRIPT", &unused));
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-11 18:53:07 +03:00
|
|
|
|
|
|
|
// Cache the attributes and/or parameters of our tag into a single set of arrays
|
|
|
|
// to be compatible with 4.x. The attributes go first, followed by a PARAM/null and
|
|
|
|
// then any PARAM tags. Also, hold the cached array around for the duration
|
|
|
|
// of the life of the instance because 4.x did. See bug 111008.
|
|
|
|
nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays()
|
|
|
|
{
|
|
|
|
if (mCachedAttrParamValues)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_PRECONDITION((((mNumCachedAttrs + mNumCachedParams) == 0) && !mCachedAttrParamNames),
|
|
|
|
"re-cache of attrs/params not implemented! use the DOM node directy instead");
|
|
|
|
NS_ENSURE_TRUE(mOwner, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
// first, we need to find out how much we need to allocate for our arrays
|
|
|
|
// count up attributes
|
|
|
|
mNumCachedAttrs = 0;
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
nsresult rv = mOwner->GetContent(getter_AddRefs(content));
|
|
|
|
NS_ENSURE_TRUE(content, rv);
|
2001-12-12 07:15:12 +03:00
|
|
|
PRInt32 cattrs;
|
|
|
|
rv = content->GetAttrCount(cattrs);
|
2001-12-11 18:53:07 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-12-12 07:17:15 +03:00
|
|
|
if (cattrs < 0x0000FFFF)
|
2001-12-12 07:15:12 +03:00
|
|
|
mNumCachedAttrs = NS_STATIC_CAST(PRUint16, cattrs); // signed 32 bits to unsigned 16 bits conversion
|
|
|
|
else
|
2001-12-12 07:18:36 +03:00
|
|
|
mNumCachedParams = 0xFFFF;
|
2001-12-11 18:53:07 +03:00
|
|
|
|
|
|
|
// now, we need to find all the PARAM tags that are children of us
|
|
|
|
// however, be carefull NOT to include any PARAMs that don't have us as a direct
|
|
|
|
// parent. For nested object (or applet) tags, be sure to only round up the
|
|
|
|
// param tags that coorespond with THIS instance. And also, weed out any bogus
|
|
|
|
// tags that may get in the way, see bug 39609. Then, with any param tag that meet our
|
|
|
|
// qualification, temporarly cache them in an nsISupportsArray until we can figure out
|
|
|
|
// what size to make our fixed char* array.
|
|
|
|
mNumCachedParams = 0;
|
|
|
|
nsCOMPtr<nsISupportsArray> ourParams;
|
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(ourParams));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> mydomNode = do_QueryInterface(content);
|
|
|
|
NS_ENSURE_TRUE(mydomNode, NS_ERROR_NO_INTERFACE);
|
|
|
|
|
|
|
|
// use the DOM to get us ALL our dependant PARAM tags, even if not ours
|
|
|
|
nsCOMPtr<nsIDOMElement> mydomElement = do_QueryInterface(mydomNode);
|
|
|
|
NS_ENSURE_TRUE(mydomElement, NS_ERROR_NO_INTERFACE);
|
|
|
|
nsCOMPtr<nsIDOMNodeList> allParams;
|
|
|
|
mydomElement->GetElementsByTagName(NS_LITERAL_STRING("PARAM"), getter_AddRefs(allParams));
|
|
|
|
if (allParams) {
|
|
|
|
PRUint32 numAllParams;
|
|
|
|
allParams->GetLength(&numAllParams);
|
|
|
|
// loop through every so called dependant PARAM tag to check if it "belongs" to us
|
|
|
|
for (PRUint32 i = 0; i < numAllParams; i++) {
|
|
|
|
nsCOMPtr<nsIDOMNode> pnode;
|
|
|
|
allParams->Item(i, getter_AddRefs(pnode));
|
|
|
|
if (pnode) {
|
|
|
|
nsCOMPtr<nsIDOMElement> domelement = do_QueryInterface(pnode);
|
|
|
|
if (domelement) {
|
|
|
|
// let's NOT count up param tags that don't have a name attribute
|
|
|
|
nsAutoString name;
|
|
|
|
domelement->GetAttribute(NS_LITERAL_STRING("name"), name);
|
|
|
|
if (name.Length() > 0) {
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
nsCOMPtr<nsIDOMHTMLObjectElement> domobject;
|
|
|
|
nsCOMPtr<nsIDOMHTMLAppletElement> domapplet;
|
|
|
|
pnode->GetParentNode(getter_AddRefs(parent));
|
|
|
|
// walk up the parents of this PARAM until we find an object (or applet) tag
|
|
|
|
while (!(domobject || domapplet) && parent) {
|
|
|
|
domobject = do_QueryInterface(parent);
|
|
|
|
domapplet = do_QueryInterface(parent);
|
|
|
|
nsCOMPtr<nsIDOMNode> temp;
|
|
|
|
parent->GetParentNode(getter_AddRefs(temp));
|
|
|
|
parent = temp;
|
|
|
|
}
|
|
|
|
if (domapplet || domobject) {
|
2001-12-11 21:41:31 +03:00
|
|
|
if (domapplet)
|
|
|
|
parent = do_QueryInterface(domapplet);
|
|
|
|
else
|
|
|
|
parent = do_QueryInterface(domobject);
|
2001-12-11 18:53:07 +03:00
|
|
|
// now check to see if this PARAM's parent is us. if so, cache it for later
|
|
|
|
if (parent.get() == mydomNode.get()) {
|
|
|
|
nsCOMPtr<nsISupports> sup = do_QueryInterface(pnode);
|
|
|
|
NS_ASSERTION(sup, "lame! DOM node does doesn't QI to nsISupports");
|
|
|
|
ourParams->AppendElement(sup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-12-12 07:15:12 +03:00
|
|
|
PRUint32 cparams;
|
|
|
|
ourParams->Count(&cparams); // unsigned 32 bits to unsigned 16 bits conversion
|
2001-12-12 07:17:15 +03:00
|
|
|
if (cparams < 0x0000FFFF)
|
2001-12-12 07:15:12 +03:00
|
|
|
mNumCachedParams = NS_STATIC_CAST(PRUint16, cparams);
|
|
|
|
else
|
2001-12-12 07:18:36 +03:00
|
|
|
mNumCachedParams = 0xFFFF;
|
2001-12-11 18:53:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
// now lets make the arrays
|
|
|
|
mCachedAttrParamNames = (char **)PR_Calloc(sizeof(char *) * (mNumCachedAttrs + 1 + mNumCachedParams), 1);
|
|
|
|
NS_ENSURE_TRUE(mCachedAttrParamNames, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
mCachedAttrParamValues = (char **)PR_Calloc(sizeof(char *) * (mNumCachedAttrs + 1 + mNumCachedParams), 1);
|
|
|
|
NS_ENSURE_TRUE(mCachedAttrParamValues, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// let's fill in our attributes
|
|
|
|
PRInt16 c = 0;
|
|
|
|
for (PRInt16 index = 0; index < mNumCachedAttrs; index++) {
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsCOMPtr<nsIAtom> atom;
|
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
|
|
|
content->GetAttrNameAt(index, nameSpaceID,
|
|
|
|
*getter_AddRefs(atom),
|
|
|
|
*getter_AddRefs(prefix));
|
|
|
|
nsAutoString value;
|
|
|
|
if (NS_CONTENT_ATTR_NOT_THERE != content->GetAttr(nameSpaceID, atom, value)) {
|
|
|
|
nsAutoString name;
|
|
|
|
atom->ToString(name);
|
|
|
|
mCachedAttrParamNames [c] = ToNewUTF8String(name);
|
|
|
|
mCachedAttrParamValues[c] = ToNewUTF8String(value);
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add our PARAM and null seperator
|
2001-12-12 08:39:46 +03:00
|
|
|
mCachedAttrParamNames [mNumCachedAttrs] = ToNewUTF8String(NS_LITERAL_STRING("PARAM"));
|
|
|
|
mCachedAttrParamValues[mNumCachedAttrs] = nsnull;
|
2001-12-11 18:53:07 +03:00
|
|
|
|
|
|
|
// now fill in the PARAM name/value pairs from the cached DOM nodes
|
|
|
|
c = 0;
|
|
|
|
for (PRInt16 idx = 0; idx < mNumCachedParams; idx++) {
|
|
|
|
nsCOMPtr<nsISupports> sup = ourParams->ElementAt(idx);
|
|
|
|
if (sup) {
|
|
|
|
nsCOMPtr<nsIDOMElement> param = do_QueryInterface(sup);
|
|
|
|
if (param) {
|
|
|
|
nsAutoString name;
|
|
|
|
nsAutoString value;
|
|
|
|
param->GetAttribute(NS_LITERAL_STRING("name"), name); // check for empty done above
|
|
|
|
param->GetAttribute(NS_LITERAL_STRING("value"), value);
|
|
|
|
/*
|
|
|
|
* According to the HTML 4.01 spec, at
|
|
|
|
* http://www.w3.org/TR/html4/types.html#type-cdata
|
|
|
|
* ''User agents may ignore leading and trailing
|
|
|
|
* white space in CDATA attribute values (e.g., "
|
|
|
|
* myval " may be interpreted as "myval"). Authors
|
|
|
|
* should not declare attribute values with
|
|
|
|
* leading or trailing white space.''
|
|
|
|
*/
|
|
|
|
name.CompressWhitespace(); // XXX right function?
|
|
|
|
value.CompressWhitespace();
|
|
|
|
mCachedAttrParamNames [mNumCachedAttrs + 1 + c] = ToNewUTF8String(name);
|
|
|
|
mCachedAttrParamValues[mNumCachedAttrs + 1 + c] = ToNewUTF8String(value);
|
|
|
|
c++; // rules!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
// 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
|
|
|
|
|
2001-05-16 07:46:56 +04:00
|
|
|
void nsPluginInstanceOwner::GUItoMacEvent(const nsGUIEvent& anEvent, EventRecord& aMacEvent)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
2001-01-17 23:04:09 +03:00
|
|
|
::OSEventAvail(0, &aMacEvent);
|
|
|
|
|
|
|
|
switch (anEvent.message) {
|
2001-05-16 07:46:56 +04:00
|
|
|
case NS_FOCUS_EVENT_START: // this is the same as NS_FOCUS_CONTENT
|
2001-01-17 23:04:09 +03:00
|
|
|
aMacEvent.what = nsPluginEventType_GetFocusEvent;
|
2001-05-16 07:46:56 +04:00
|
|
|
if (mOwner && mOwner->mPresContext)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mOwner->GetContent(getter_AddRefs(content));
|
|
|
|
if (content)
|
|
|
|
content->SetFocus(mOwner->mPresContext);
|
|
|
|
}
|
2001-01-17 23:04:09 +03:00
|
|
|
break;
|
2001-05-16 07:46:56 +04:00
|
|
|
case NS_BLUR_CONTENT:
|
2001-01-17 23:04:09 +03:00
|
|
|
aMacEvent.what = nsPluginEventType_LoseFocusEvent;
|
2001-05-16 07:46:56 +04:00
|
|
|
if (mOwner && mOwner->mPresContext)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mOwner->GetContent(getter_AddRefs(content));
|
|
|
|
if (content)
|
|
|
|
content->RemoveFocus(mOwner->mPresContext);
|
|
|
|
}
|
2001-01-17 23:04:09 +03:00
|
|
|
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
|
|
|
}
|
2001-10-09 02:58:59 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
#endif
|
|
|
|
|
2001-03-20 02:26:41 +03:00
|
|
|
/*=============== nsIFocusListener ======================*/
|
|
|
|
nsresult nsPluginInstanceOwner::Focus(nsIDOMEvent * aFocusEvent)
|
|
|
|
{
|
2001-10-09 02:58:59 +04:00
|
|
|
mContentFocused = PR_TRUE;
|
2001-03-20 02:26:41 +03:00
|
|
|
return DispatchFocusToPlugin(aFocusEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPluginInstanceOwner::Blur(nsIDOMEvent * aFocusEvent)
|
|
|
|
{
|
2001-10-09 02:58:59 +04:00
|
|
|
mContentFocused = PR_FALSE;
|
2001-03-20 02:26:41 +03:00
|
|
|
return DispatchFocusToPlugin(aFocusEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPluginInstanceOwner::DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent)
|
|
|
|
{
|
2001-08-07 05:48:14 +04:00
|
|
|
#ifndef XP_MAC
|
|
|
|
if (nsPluginWindowType_Window == mPluginWindow.type)
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
// continue only for cases without child window
|
|
|
|
#endif
|
|
|
|
|
2001-03-20 02:26:41 +03:00
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aFocusEvent));
|
|
|
|
if (privateEvent) {
|
2001-07-10 06:52:50 +04:00
|
|
|
nsEvent * theEvent;
|
|
|
|
privateEvent->GetInternalNSEvent(&theEvent);
|
|
|
|
if (theEvent) {
|
2001-07-14 05:36:45 +04:00
|
|
|
nsGUIEvent focusEvent;
|
|
|
|
memset(&focusEvent, 0, sizeof(focusEvent));
|
|
|
|
focusEvent.message = theEvent->message; // we only care about the message in ProcessEvent
|
|
|
|
nsEventStatus rv = ProcessEvent(focusEvent);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == rv) {
|
|
|
|
aFocusEvent->PreventDefault();
|
2001-12-06 09:57:03 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aFocusEvent));
|
|
|
|
|
|
|
|
if (nsevent) {
|
|
|
|
nsevent->PreventBubble();
|
|
|
|
}
|
|
|
|
|
2001-07-14 05:36:45 +04:00
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
2001-03-20 02:26:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchFocusToPlugin failed, focusEvent null");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchFocusToPlugin failed, privateEvent null");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2001-03-06 06:31:29 +03:00
|
|
|
if (mInstance) {
|
|
|
|
// 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();
|
2001-12-06 09:57:03 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aKeyEvent));
|
|
|
|
|
|
|
|
if (nsevent) {
|
|
|
|
nsevent->PreventBubble();
|
|
|
|
}
|
|
|
|
|
2001-03-06 06:31:29 +03:00
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2001-01-17 23:04:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPluginInstanceOwner::DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
2001-08-07 05:48:14 +04:00
|
|
|
#ifdef XP_MAC // on Mac, we don't have child windows so hook in through DOM events
|
2001-03-06 06:31:29 +03:00
|
|
|
if (mInstance) {
|
|
|
|
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();
|
2001-12-06 09:57:03 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aKeyEvent));
|
|
|
|
|
|
|
|
if (nsevent) {
|
|
|
|
nsevent->PreventBubble();
|
|
|
|
}
|
|
|
|
|
2001-03-06 06:31:29 +03:00
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
}
|
2001-01-17 23:04:09 +03:00
|
|
|
}
|
2001-03-06 06:31:29 +03:00
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchKeyToPlugin failed, keyEvent null");
|
2001-01-17 23:04:09 +03:00
|
|
|
}
|
2001-03-06 06:31:29 +03:00
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchKeyToPlugin failed, privateEvent null");
|
2001-01-17 23:04:09 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2001-04-04 01:32:37 +04:00
|
|
|
#else
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
#endif
|
2001-01-17 23:04:09 +03:00
|
|
|
}
|
2000-10-18 03:13:30 +04:00
|
|
|
|
2001-08-07 05:48:14 +04:00
|
|
|
/*=============== nsIMouseMotionListener ======================*/
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseMove(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
#ifndef XP_MAC
|
|
|
|
if (nsPluginWindowType_Window == mPluginWindow.type)
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
// continue only for cases without child window
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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::MouseMove failed, mouseEvent null");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::MouseMove failed, privateEvent null");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:13:30 +04:00
|
|
|
/*=============== nsIMouseListener ======================*/
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2001-08-07 05:48:14 +04:00
|
|
|
#ifndef XP_MAC
|
|
|
|
if (nsPluginWindowType_Window == mPluginWindow.type)
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
// continue only for cases without child window
|
|
|
|
#endif
|
|
|
|
|
2000-10-18 03:13:30 +04:00
|
|
|
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)
|
|
|
|
{
|
2001-01-28 03:37:48 +03:00
|
|
|
return DispatchMouseToPlugin(aMouseEvent);
|
2000-10-18 03:13:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2001-01-28 03:37:48 +03:00
|
|
|
return DispatchMouseToPlugin(aMouseEvent);
|
2000-10-18 03:13:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2001-01-28 03:37:48 +03:00
|
|
|
return DispatchMouseToPlugin(aMouseEvent);
|
2000-10-18 03:13:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseOver(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2001-01-28 03:37:48 +03:00
|
|
|
return DispatchMouseToPlugin(aMouseEvent);
|
2000-10-18 03:13:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginInstanceOwner::MouseOut(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2001-01-28 03:37:48 +03:00
|
|
|
return DispatchMouseToPlugin(aMouseEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPluginInstanceOwner::DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2001-08-07 05:48:14 +04:00
|
|
|
#ifndef XP_MAC
|
|
|
|
if (nsPluginWindowType_Window == mPluginWindow.type)
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
// continue only for cases without child window
|
|
|
|
#endif
|
|
|
|
|
2001-01-28 03:37:48 +03:00
|
|
|
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) {
|
|
|
|
aMouseEvent->PreventDefault();
|
2001-12-06 09:57:03 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aMouseEvent));
|
|
|
|
|
|
|
|
if (nsevent) {
|
|
|
|
nsevent->PreventBubble();
|
|
|
|
}
|
|
|
|
|
2001-01-28 03:37:48 +03:00
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchMouseToPlugin failed, mouseEvent null");
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchMouseToPlugin failed, privateEvent null");
|
|
|
|
|
2000-10-18 03:13:30 +04:00
|
|
|
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;
|
2001-10-09 02:58:59 +04:00
|
|
|
if ((event == NULL) || (event->what == nullEvent) ||
|
|
|
|
(anEvent.message == NS_FOCUS_EVENT_START) ||
|
|
|
|
(anEvent.message == NS_BLUR_CONTENT) ||
|
|
|
|
(anEvent.message == NS_MOUSE_MOVE) ||
|
|
|
|
(anEvent.message == NS_MOUSE_ENTER))
|
2001-04-25 03:24:01 +04:00
|
|
|
{
|
2001-01-12 02:56:35 +03:00
|
|
|
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);
|
2001-10-09 02:58:59 +04:00
|
|
|
if (eventHandled && !(anEvent.message == NS_MOUSE_LEFT_BUTTON_DOWN && !mContentFocused))
|
2001-01-12 02:56:35 +03:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mOwner->GetContent(getter_AddRefs(content));
|
2001-03-20 02:26:41 +03:00
|
|
|
|
|
|
|
// Unregister focus event listener
|
|
|
|
if (content) {
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));
|
|
|
|
if (receiver) {
|
|
|
|
nsCOMPtr<nsIDOMFocusListener> focusListener;
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMFocusListener), getter_AddRefs(focusListener));
|
|
|
|
if (focusListener) {
|
|
|
|
receiver->RemoveEventListenerByIID(focusListener, NS_GET_IID(nsIDOMFocusListener));
|
|
|
|
}
|
|
|
|
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");
|
|
|
|
|
|
|
|
// Unregister mouse event listener
|
2000-10-18 03:13:30 +04:00
|
|
|
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");
|
2001-08-07 05:48:14 +04:00
|
|
|
// now for the mouse motion listener
|
|
|
|
nsCOMPtr<nsIDOMMouseMotionListener> mouseMotionListener;
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMMouseMotionListener), getter_AddRefs(mouseMotionListener));
|
|
|
|
if (mouseMotionListener) {
|
|
|
|
receiver->RemoveEventListenerByIID(mouseMotionListener, NS_GET_IID(nsIDOMMouseMotionListener));
|
|
|
|
}
|
|
|
|
else NS_ASSERTION(PR_FALSE, "Unable to remove event listener for plugin");
|
2000-10-18 03:13:30 +04:00
|
|
|
}
|
|
|
|
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) {
|
2001-03-20 01:10:23 +03:00
|
|
|
receiver->RemoveEventListener(NS_LITERAL_STRING("keypress"), keyListener, PR_TRUE);
|
|
|
|
receiver->RemoveEventListener(NS_LITERAL_STRING("keydown"), keyListener, PR_TRUE);
|
|
|
|
receiver->RemoveEventListener(NS_LITERAL_STRING("keyup"), keyListener, PR_TRUE);
|
|
|
|
|
2001-01-17 23:04:09 +03:00
|
|
|
}
|
|
|
|
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-09-28 07:34:53 +04:00
|
|
|
|
|
|
|
mOwner = nsnull; // break relationship between frame and plugin instance owner
|
|
|
|
|
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
|
2001-08-18 02:52:12 +04:00
|
|
|
FixUpPluginWindow();
|
2000-10-18 01:45:39 +04:00
|
|
|
|
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))
|
2001-07-10 07:59:39 +04:00
|
|
|
mPluginTimer->Init(this, 1020 / 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();
|
2001-07-11 06:29:45 +04:00
|
|
|
mPluginTimer = nsnull;
|
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;
|
2001-03-20 02:26:41 +03:00
|
|
|
|
2000-10-18 03:13:30 +04:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mOwner->GetContent(getter_AddRefs(content));
|
2001-03-20 02:26:41 +03:00
|
|
|
|
2001-08-02 04:03:29 +04:00
|
|
|
// This is way of ensure the previous document is gone. Important when reloading either
|
|
|
|
// the page or refreshing plugins. In the case of an OBJECT frame,
|
|
|
|
// we want to flush out the prevous content viewer which will cause the previous document
|
|
|
|
// and plugins to be cleaned up. Then we can create our new plugin without the old instance
|
|
|
|
// hanging around.
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
aPresContext->GetContainer(getter_AddRefs(container));
|
|
|
|
if (container) {
|
|
|
|
nsCOMPtr<nsIDocShell> cvc(do_QueryInterface(container));
|
|
|
|
if (cvc) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
cvc->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
if (cv)
|
|
|
|
cv->Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-20 02:26:41 +03:00
|
|
|
// Register focus listener
|
|
|
|
if (content) {
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));
|
|
|
|
if (receiver) {
|
|
|
|
nsCOMPtr<nsIDOMFocusListener> focusListener;
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMFocusListener), getter_AddRefs(focusListener));
|
|
|
|
if (focusListener) {
|
|
|
|
receiver->AddEventListenerByIID(focusListener, NS_GET_IID(nsIDOMFocusListener));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register mouse listener
|
2000-10-18 03:13:30 +04:00
|
|
|
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
|
|
|
}
|
2001-08-07 05:48:14 +04:00
|
|
|
// now do the mouse motion listener
|
|
|
|
nsCOMPtr<nsIDOMMouseMotionListener> mouseMotionListener;
|
|
|
|
QueryInterface(NS_GET_IID(nsIDOMMouseMotionListener), getter_AddRefs(mouseMotionListener));
|
|
|
|
if (mouseMotionListener) {
|
|
|
|
receiver->AddEventListenerByIID(mouseMotionListener, NS_GET_IID(nsIDOMMouseMotionListener));
|
|
|
|
}
|
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)
|
2001-09-18 06:11:09 +04:00
|
|
|
{
|
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
|
|
|
|
2001-08-18 02:52:12 +04:00
|
|
|
if (nsnull == view || nsnull == mWidget)
|
1999-07-07 06:33:17 +04:00
|
|
|
{
|
|
|
|
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)
|
2001-06-19 01:41:57 +04:00
|
|
|
{
|
2000-07-20 03:46:43 +04:00
|
|
|
view->GetWidget(mWidget);
|
2001-06-19 01:41:57 +04:00
|
|
|
PRBool fTransparent;
|
|
|
|
mInstance->GetValue(nsPluginInstanceVariable_TransparentBool, (void *)&fTransparent);
|
2001-12-01 17:31:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
view->GetViewManager(*getter_AddRefs(vm));
|
|
|
|
if (vm) {
|
|
|
|
vm->SetViewContentTransparency(view, fTransparent);
|
|
|
|
}
|
2001-06-19 01:41:57 +04:00
|
|
|
}
|
1999-07-07 06:33:17 +04:00
|
|
|
|
|
|
|
if (PR_TRUE == windowless)
|
|
|
|
{
|
|
|
|
mPluginWindow.type = nsPluginWindowType_Drawable;
|
2001-09-18 06:11:09 +04:00
|
|
|
mPluginWindow.window = nsnull; // this needs to be a HDC according to the spec,
|
1999-07-07 06:33:17 +04:00
|
|
|
// 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);
|
2001-06-19 01:41:57 +04:00
|
|
|
|
1999-07-07 06:33:17 +04:00
|
|
|
mPluginWindow.window = GetPluginPort();
|
|
|
|
mPluginWindow.type = nsPluginWindowType_Window;
|
|
|
|
|
|
|
|
#if defined(XP_MAC)
|
2001-06-19 01:41:57 +04:00
|
|
|
// Is this needed in the windowless case ???
|
1999-07-07 06:33:17 +04:00
|
|
|
// 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-07-10 07:59:39 +04:00
|
|
|
rv = mPluginTimer->Init(this, 1020 / 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
|
|
|
|
|
2001-11-09 03:42:02 +03:00
|
|
|
inline PRUint16 COLOR8TOCOLOR16(PRUint8 color8)
|
|
|
|
{
|
|
|
|
return (color8 << 8) | color8; /* (color8 * 257) == (color8 * 0x0101) */
|
|
|
|
}
|
|
|
|
|
2001-01-12 02:56:35 +03:00
|
|
|
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;
|
2001-11-09 03:42:02 +03:00
|
|
|
|
|
|
|
// the Mac widget doesn't set the background color right away!!
|
|
|
|
// the background color needs to be set here on the plugin port
|
|
|
|
GrafPtr savePort;
|
|
|
|
::GetPort(&savePort); // save our current port
|
|
|
|
nsPluginPort* pluginPort = GetPluginPort();
|
|
|
|
::SetPort((GrafPtr)pluginPort->port);
|
|
|
|
|
|
|
|
nscolor color = mWidget->GetBackgroundColor();
|
|
|
|
RGBColor macColor;
|
|
|
|
macColor.red = COLOR8TOCOLOR16(NS_GET_R(color)); // convert to Mac color
|
|
|
|
macColor.green = COLOR8TOCOLOR16(NS_GET_G(color));
|
|
|
|
macColor.blue = COLOR8TOCOLOR16(NS_GET_B(color));
|
|
|
|
::RGBBackColor(&macColor);
|
|
|
|
::SetPort(savePort); // restore port
|
2001-01-12 02:56:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // XP_MAC
|