/* -*- 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 * * The contents of this file are subject to the Netscape Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * 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. * * Contributor(s): * Travis Bogard * Håkan Waara * * 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 ***** */ #include "nsCOMPtr.h" #include "nsLeafFrame.h" #include "nsHTMLContainerFrame.h" #include "nsIHTMLContent.h" #include "nsIWebShell.h" #include "nsIDocShell.h" #include "nsIDocShellLoadInfo.h" #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeNode.h" #include "nsIDocShellTreeOwner.h" #include "nsIWebNavigation.h" #include "nsIBaseWindow.h" #include "nsIContentViewer.h" #include "nsIMarkupDocumentViewer.h" #include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsHTMLIIDs.h" #include "nsIComponentManager.h" #include "nsIStreamListener.h" #include "nsIURL.h" #include "nsNetUtil.h" #include "nsIDocument.h" #include "nsIView.h" #include "nsIViewManager.h" #include "nsWidgetsCID.h" #include "nsViewsCID.h" #include "nsHTMLAtoms.h" #include "nsIScrollableView.h" #include "nsStyleCoord.h" #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIDocumentLoader.h" #include "nsIPref.h" #include "nsFrameSetFrame.h" #include "nsIDOMHTMLFrameElement.h" #include "nsIDOMHTMLIFrameElement.h" #include "nsIFrameLoader.h" #include "nsLayoutAtoms.h" #include "nsIChromeEventHandler.h" #include "nsIScriptSecurityManager.h" #include "nsICodebasePrincipal.h" #include "nsXPIDLString.h" #include "nsIScrollable.h" #include "nsINameSpaceManager.h" #include "nsIPrintContext.h" #include "nsIPrintPreviewContext.h" #include "nsIWidget.h" #include "nsIWebProgress.h" #include "nsIWebProgressListener.h" #include "nsIWebBrowserPrint.h" #include "nsWeakReference.h" #include "nsIDOMEventTarget.h" #include "nsIDOMEventListener.h" #include "nsIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsPIDOMWindow.h" #include "nsIRenderingContext.h" #include "nsIFrameFrame.h" // For Accessibility #ifdef ACCESSIBILITY #include "nsIAccessibilityService.h" #endif #include "nsIServiceManager.h" class nsHTMLFrame; static NS_DEFINE_CID(kCViewCID, NS_VIEW_CID); static NS_DEFINE_CID(kCChildCID, NS_CHILD_CID); /****************************************************************************** * FrameLoadingInfo *****************************************************************************/ class FrameLoadingInfo : public nsISupports { public: FrameLoadingInfo(const nsSize& aSize); // nsISupports interface... NS_DECL_ISUPPORTS protected: virtual ~FrameLoadingInfo() {} public: nsSize mFrameSize; }; /****************************************************************************** * nsHTMLFrameOuterFrame *****************************************************************************/ #define nsHTMLFrameOuterFrameSuper nsHTMLContainerFrame class nsHTMLFrameOuterFrame : public nsHTMLFrameOuterFrameSuper, public nsIFrameFrame { public: nsHTMLFrameOuterFrame(); #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const; #endif // nsISupports NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); NS_IMETHOD_(nsrefcnt) AddRef(void) { return 2; } NS_IMETHOD_(nsrefcnt) Release(void) { return 1; } NS_IMETHOD GetFrameType(nsIAtom** aType) const; NS_IMETHOD Paint(nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer, PRUint32 aFlags); NS_IMETHOD Init(nsIPresContext* aPresContext, nsIContent* aContent, nsIFrame* aParent, nsIStyleContext* aContext, nsIFrame* aPrevInFlow); NS_IMETHOD Reflow(nsIPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus); NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, nsIContent* aChild, PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aModType, PRInt32 aHint); #ifdef ACCESSIBILITY NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); #endif // nsIFrameFrame NS_IMETHOD GetDocShell(nsIDocShell **aDocShell); NS_IMETHOD VerifyTree() const; PRBool IsInline(); protected: virtual ~nsHTMLFrameOuterFrame(); virtual void GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize); virtual PRIntn GetSkipSides() const; PRBool mIsInline; nsCOMPtr mPresContext; }; /****************************************************************************** * nsHTMLFrameInnerFrame *****************************************************************************/ class nsHTMLFrameInnerFrame : public nsLeafFrame, public nsSupportsWeakReference { public: nsHTMLFrameInnerFrame(); NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); NS_IMETHOD_(nsrefcnt) AddRef(void) { return 2; } NS_IMETHOD_(nsrefcnt) Release(void) { return 1; } #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const; #endif NS_IMETHOD GetFrameType(nsIAtom** aType) const; /** * @see nsIFrame::Paint */ NS_IMETHOD Paint(nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer, PRUint32 aFlags); /** * @see nsIFrame::Reflow */ NS_IMETHOD Reflow(nsIPresContext* aCX, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus); NS_IMETHOD DidReflow(nsIPresContext* aPresContext, const nsHTMLReflowState* aReflowState, nsDidReflowStatus aStatus); NS_IMETHOD Init(nsIPresContext* aPresContext, nsIContent* aContent, nsIFrame* aParent, nsIStyleContext* aContext, nsIFrame* aPrevInFlow); void GetParentContent(nsIContent** aContent); nsresult GetDocShell(nsIDocShell **aDocShell); PRBool GetURL(nsIContent* aContent, nsString& aResult); PRBool GetName(nsIContent* aContent, nsString& aResult); PRInt32 GetScrolling(nsIContent* aContent); nsFrameborder GetFrameBorder(); PRInt32 GetMarginWidth(nsIContent* aContent); PRInt32 GetMarginHeight(nsIContent* aContent); friend class nsHTMLFrameOuterFrame; protected: nsresult ShowDocShell(nsIPresContext* aPresContext); nsresult CreateViewAndWidget(nsIPresContext* aPresContext, nsIWidget** aWidget); virtual ~nsHTMLFrameInnerFrame(); virtual void GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize); nsresult ReloadURL(); nsCOMPtr mFrameLoader; PRPackedBool mOwnsFrameLoader; PRPackedBool mCreatingViewer; }; /****************************************************************************** * nsHTMLFrameOuterFrame *****************************************************************************/ nsHTMLFrameOuterFrame::nsHTMLFrameOuterFrame() : nsHTMLContainerFrame() { mIsInline = PR_FALSE; } nsHTMLFrameOuterFrame::~nsHTMLFrameOuterFrame() { //printf("nsHTMLFrameOuterFrame destructor %X \n", this); } #ifdef ACCESSIBILITY NS_IMETHODIMP nsHTMLFrameOuterFrame::GetAccessible(nsIAccessible** aAccessible) { nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { nsCOMPtr node = do_QueryInterface(mContent); return accService->CreateIFrameAccessible(node, aAccessible); } return NS_ERROR_FAILURE; } #endif NS_IMETHODIMP nsHTMLFrameOuterFrame::GetDocShell(nsIDocShell **aDocShell) { *aDocShell = nsnull; nsHTMLFrameInnerFrame* firstChild = NS_STATIC_CAST(nsHTMLFrameInnerFrame*, mFrames.FirstChild()); if (!firstChild) return NS_OK; return firstChild->GetDocShell(aDocShell); } //-------------------------------------------------------------- // Frames are not refcounted, no need to AddRef NS_IMETHODIMP nsHTMLFrameOuterFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) { NS_PRECONDITION(0 != aInstancePtr, "null ptr"); if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; } if (aIID.Equals(NS_GET_IID(nsIFrameFrame))) { nsISupports *tmp = NS_STATIC_CAST(nsIFrameFrame *, this); *aInstancePtr = tmp; return NS_OK; } return nsHTMLFrameOuterFrameSuper::QueryInterface(aIID, aInstancePtr); } NS_IMETHODIMP nsHTMLFrameOuterFrame::Init(nsIPresContext* aPresContext, nsIContent* aContent, nsIFrame* aParent, nsIStyleContext* aContext, nsIFrame* aPrevInFlow) { mPresContext = aPresContext; // determine if we are a or