Back to index

lightning-sunbird  0.9+nobinonly
nsXTFVisualWrapper.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Mozilla XTF project.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Alex Fritze.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Alex Fritze <alex@croczilla.com> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsCOMPtr.h"
00040 #include "nsXTFVisualWrapper.h"
00041 #include "nsISupportsArray.h"
00042 #include "nsIPresShell.h"
00043 #include "nsPresContext.h"
00044 #include "nsIDocument.h"
00045 
00046 nsXTFVisualWrapper::nsXTFVisualWrapper(nsINodeInfo* aNodeInfo)
00047     : nsXTFVisualWrapperBase(aNodeInfo)
00048 {}
00049 
00050 //----------------------------------------------------------------------
00051 // nsISupports implementation
00052 
00053 
00054 NS_IMPL_ADDREF_INHERITED(nsXTFVisualWrapper,nsXTFVisualWrapperBase)
00055 NS_IMPL_RELEASE_INHERITED(nsXTFVisualWrapper,nsXTFVisualWrapperBase)
00056 
00057 NS_INTERFACE_MAP_BEGIN(nsXTFVisualWrapper)
00058   NS_INTERFACE_MAP_ENTRY(nsIXTFVisualWrapperPrivate)
00059 NS_INTERFACE_MAP_END_INHERITING(nsXTFVisualWrapperBase)
00060 
00061 //----------------------------------------------------------------------
00062 // nsIXTFVisualWrapperPrivate implementation:
00063 
00064 NS_IMETHODIMP
00065 nsXTFVisualWrapper::CreateAnonymousContent(nsPresContext* aPresContext,
00066                                            nsISupportsArray& aAnonymousItems)
00067 {
00068   nsIDocument *doc = GetCurrentDoc();
00069   NS_ASSERTION(doc, "no document; cannot create anonymous content");
00070 
00071   if (!mVisualContent) {
00072     GetXTFVisual()->GetVisualContent(getter_AddRefs(mVisualContent));
00073   }    
00074   if (!mVisualContent) return NS_OK; // nothing to append
00075   
00076   // Check if we are creating content for the primary presShell
00077   bool isPrimaryShell =
00078     (aPresContext->PresShell() == doc->GetShellAt(0));
00079 
00080   nsCOMPtr<nsIDOMNode> contentToAppend;
00081   if (!isPrimaryShell) {
00082     // The presShell we are generating content for is not a primary
00083     // shell. In practice that means it means we are constructing
00084     // content for printing. Instead of asking the xtf element to
00085     // construct new visual content, we just clone the exisiting
00086     // content. In this way, the xtf element only ever has to provide
00087     // one visual content tree which it can dynamically manipulate.
00088     mVisualContent->CloneNode(PR_TRUE, getter_AddRefs(contentToAppend));
00089   }
00090   else
00091     contentToAppend = mVisualContent;
00092 
00093   if (contentToAppend)
00094     aAnonymousItems.AppendElement(contentToAppend);
00095   
00096   return NS_OK;
00097 }
00098 
00099 void
00100 nsXTFVisualWrapper::DidLayout()
00101 {
00102   if (mNotificationMask & nsIXTFVisual::NOTIFY_DID_LAYOUT)
00103     GetXTFVisual()->DidLayout();
00104 }
00105 
00106 void
00107 nsXTFVisualWrapper::GetInsertionPoint(nsIDOMElement** insertionPoint)
00108 {
00109   GetXTFVisual()->GetInsertionPoint(insertionPoint);
00110 }
00111 
00112 PRBool
00113 nsXTFVisualWrapper::ApplyDocumentStyleSheets()
00114 {
00115   PRBool retval = PR_FALSE;
00116   GetXTFVisual()->GetApplyDocumentStyleSheets(&retval);
00117   return retval;
00118 }
00119 
00120 nsresult
00121 nsXTFVisualWrapper::Init()
00122 {
00123   return nsXTFVisualWrapperBase::Init();
00124 }