michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIContainerBoxObject.h" michael@0: #include "nsIBrowserBoxObject.h" michael@0: #include "nsIEditorBoxObject.h" michael@0: #include "nsIIFrameBoxObject.h" michael@0: #include "nsBoxObject.h" michael@0: #include "nsIDocShell.h" michael@0: #include "nsIContent.h" michael@0: #include "nsIDocument.h" michael@0: #include "nsIFrame.h" michael@0: #include "nsSubDocumentFrame.h" michael@0: michael@0: /** michael@0: * nsContainerBoxObject implements deprecated nsIBrowserBoxObject, michael@0: * nsIEditorBoxObject and nsIIFrameBoxObject interfaces only because of the michael@0: * backward compatibility. michael@0: */ michael@0: michael@0: class nsContainerBoxObject : public nsBoxObject, michael@0: public nsIBrowserBoxObject, michael@0: public nsIEditorBoxObject, michael@0: public nsIIFrameBoxObject michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSICONTAINERBOXOBJECT michael@0: NS_DECL_NSIBROWSERBOXOBJECT michael@0: NS_DECL_NSIEDITORBOXOBJECT michael@0: NS_DECL_NSIIFRAMEBOXOBJECT michael@0: }; michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(nsContainerBoxObject) michael@0: NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIContainerBoxObject, nsIBrowserBoxObject) michael@0: NS_INTERFACE_MAP_ENTRY(nsIBrowserBoxObject) michael@0: NS_INTERFACE_MAP_ENTRY(nsIEditorBoxObject) michael@0: NS_INTERFACE_MAP_ENTRY(nsIIFrameBoxObject) michael@0: NS_INTERFACE_MAP_END_INHERITING(nsBoxObject) michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(nsContainerBoxObject, nsBoxObject) michael@0: NS_IMPL_RELEASE_INHERITED(nsContainerBoxObject, nsBoxObject) michael@0: michael@0: NS_IMETHODIMP nsContainerBoxObject::GetDocShell(nsIDocShell** aResult) michael@0: { michael@0: *aResult = nullptr; michael@0: michael@0: nsSubDocumentFrame *subDocFrame = do_QueryFrame(GetFrame(false)); michael@0: if (subDocFrame) { michael@0: // Ok, the frame for mContent is an nsSubDocumentFrame, it knows how michael@0: // to reach the docshell, so ask it... michael@0: michael@0: return subDocFrame->GetDocShell(aResult); michael@0: } michael@0: michael@0: if (!mContent) { michael@0: return NS_OK; michael@0: } michael@0: michael@0: // No nsSubDocumentFrame available for mContent, try if there's a mapping michael@0: // between mContent's document to mContent's subdocument. michael@0: michael@0: // XXXbz sXBL/XBL2 issue -- ownerDocument or currentDocument? michael@0: nsIDocument *doc = mContent->GetDocument(); michael@0: michael@0: if (!doc) { michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsIDocument *sub_doc = doc->GetSubDocumentFor(mContent); michael@0: michael@0: if (!sub_doc) { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IF_ADDREF(*aResult = sub_doc->GetDocShell()); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: NS_NewContainerBoxObject(nsIBoxObject** aResult) michael@0: { michael@0: *aResult = new nsContainerBoxObject(); michael@0: if (!*aResult) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: NS_ADDREF(*aResult); michael@0: return NS_OK; michael@0: } michael@0: