/* -*- 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 "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 "nsWeakReference.h" #include "nsIDOMEventTarget.h" #include "nsIDOMEventListener.h" #include "nsIDOMWindow.h" #include "nsIRenderingContext.h" // For Accessibility #ifdef ACCESSIBILITY #include "nsIAccessibilityService.h" #endif #include "nsIServiceManager.h" class nsHTMLFrame; static NS_DEFINE_IID(kIFramesetFrameIID, NS_IFRAMESETFRAME_IID); static NS_DEFINE_CID(kWebShellCID, NS_WEB_SHELL_CID); static NS_DEFINE_CID(kCViewCID, NS_VIEW_CID); static NS_DEFINE_CID(kCChildCID, NS_CHILD_CID); // Bug 8065: Limit content frame depth to some reasonable level. // This does not count chrome frames when determining depth, // nor does it prevent chrome recursion. #define MAX_DEPTH_CONTENT_FRAMES 25 /******************************************************************************* * 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: nsHTMLFrameOuterFrame(); #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const; #endif // nsISupports NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); 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 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 nsIWebProgressListener, 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; } NS_DECL_NSIWEBPROGRESSLISTENER #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); NS_IMETHOD GetParentContent(nsIContent*& aContent); PRBool GetURL(nsIContent* aContent, nsString& aResult); PRBool GetName(nsIContent* aContent, nsString& aResult); PRInt32 GetScrolling(nsIContent* aContent); nsFrameborder GetFrameBorder(); PRInt32 GetMarginWidth(nsIPresContext* aPresContext, nsIContent* aContent); PRInt32 GetMarginHeight(nsIPresContext* aPresContext, nsIContent* aContent); nsresult ReloadURL(nsIPresContext* aPresContext); friend class nsHTMLFrameOuterFrame; protected: nsresult CreateDocShell(nsIPresContext* aPresContext); nsresult DoLoadURL(nsIPresContext* aPresContext); nsresult CreateViewAndWidget(nsIPresContext* aPresContext, nsIWidget** aWidget); virtual ~nsHTMLFrameInnerFrame(); virtual void GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize); nsCOMPtr mSubShell; nsWeakPtr mPresShellWeak; // weak reference to the nsIPresShell PRBool 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 //-------------------------------------------------------------- // 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; } 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