1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/xul/nsContainerBoxObject.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,92 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsCOMPtr.h" 1.10 +#include "nsIContainerBoxObject.h" 1.11 +#include "nsIBrowserBoxObject.h" 1.12 +#include "nsIEditorBoxObject.h" 1.13 +#include "nsIIFrameBoxObject.h" 1.14 +#include "nsBoxObject.h" 1.15 +#include "nsIDocShell.h" 1.16 +#include "nsIContent.h" 1.17 +#include "nsIDocument.h" 1.18 +#include "nsIFrame.h" 1.19 +#include "nsSubDocumentFrame.h" 1.20 + 1.21 +/** 1.22 + * nsContainerBoxObject implements deprecated nsIBrowserBoxObject, 1.23 + * nsIEditorBoxObject and nsIIFrameBoxObject interfaces only because of the 1.24 + * backward compatibility. 1.25 + */ 1.26 + 1.27 +class nsContainerBoxObject : public nsBoxObject, 1.28 + public nsIBrowserBoxObject, 1.29 + public nsIEditorBoxObject, 1.30 + public nsIIFrameBoxObject 1.31 +{ 1.32 +public: 1.33 + NS_DECL_ISUPPORTS_INHERITED 1.34 + NS_DECL_NSICONTAINERBOXOBJECT 1.35 + NS_DECL_NSIBROWSERBOXOBJECT 1.36 + NS_DECL_NSIEDITORBOXOBJECT 1.37 + NS_DECL_NSIIFRAMEBOXOBJECT 1.38 +}; 1.39 + 1.40 +NS_INTERFACE_MAP_BEGIN(nsContainerBoxObject) 1.41 + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIContainerBoxObject, nsIBrowserBoxObject) 1.42 + NS_INTERFACE_MAP_ENTRY(nsIBrowserBoxObject) 1.43 + NS_INTERFACE_MAP_ENTRY(nsIEditorBoxObject) 1.44 + NS_INTERFACE_MAP_ENTRY(nsIIFrameBoxObject) 1.45 +NS_INTERFACE_MAP_END_INHERITING(nsBoxObject) 1.46 + 1.47 +NS_IMPL_ADDREF_INHERITED(nsContainerBoxObject, nsBoxObject) 1.48 +NS_IMPL_RELEASE_INHERITED(nsContainerBoxObject, nsBoxObject) 1.49 + 1.50 +NS_IMETHODIMP nsContainerBoxObject::GetDocShell(nsIDocShell** aResult) 1.51 +{ 1.52 + *aResult = nullptr; 1.53 + 1.54 + nsSubDocumentFrame *subDocFrame = do_QueryFrame(GetFrame(false)); 1.55 + if (subDocFrame) { 1.56 + // Ok, the frame for mContent is an nsSubDocumentFrame, it knows how 1.57 + // to reach the docshell, so ask it... 1.58 + 1.59 + return subDocFrame->GetDocShell(aResult); 1.60 + } 1.61 + 1.62 + if (!mContent) { 1.63 + return NS_OK; 1.64 + } 1.65 + 1.66 + // No nsSubDocumentFrame available for mContent, try if there's a mapping 1.67 + // between mContent's document to mContent's subdocument. 1.68 + 1.69 + // XXXbz sXBL/XBL2 issue -- ownerDocument or currentDocument? 1.70 + nsIDocument *doc = mContent->GetDocument(); 1.71 + 1.72 + if (!doc) { 1.73 + return NS_OK; 1.74 + } 1.75 + 1.76 + nsIDocument *sub_doc = doc->GetSubDocumentFor(mContent); 1.77 + 1.78 + if (!sub_doc) { 1.79 + return NS_OK; 1.80 + } 1.81 + 1.82 + NS_IF_ADDREF(*aResult = sub_doc->GetDocShell()); 1.83 + return NS_OK; 1.84 +} 1.85 + 1.86 +nsresult 1.87 +NS_NewContainerBoxObject(nsIBoxObject** aResult) 1.88 +{ 1.89 + *aResult = new nsContainerBoxObject(); 1.90 + if (!*aResult) 1.91 + return NS_ERROR_OUT_OF_MEMORY; 1.92 + NS_ADDREF(*aResult); 1.93 + return NS_OK; 1.94 +} 1.95 +