Back to index

lightning-sunbird  0.9+nobinonly
nsXTFXMLDisplayFrame.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 "nsStyleSet.h"
00041 #include "nsPresContext.h"
00042 #include "nsIPresShell.h"
00043 #include "nsBlockFrame.h"
00044 #include "nsInlineFrame.h"
00045 #include "nsIXTFXMLVisual.h"
00046 #include "nsIDOMElement.h"
00047 #include "nsIXTFVisualWrapperPrivate.h"
00048 #include "nsIAnonymousContentCreator.h"
00049 #include "nsXTFFrameUtils.h"
00050 
00052 // nsXTFXMLBlockDisplayFrame
00053 
00054 nsresult NS_NewXTFXMLDisplayFrame(nsIPresShell* aPresShell,
00055                                   PRBool isBlock, nsIFrame** aNewFrame);
00056   
00057 
00058 typedef nsBlockFrame nsXTFXMLBlockDisplayFrameBase;
00059 
00060 class nsXTFXMLBlockDisplayFrame : public nsXTFXMLBlockDisplayFrameBase,
00061                                   public nsIAnonymousContentCreator
00062 {
00063 public:
00064   nsXTFXMLBlockDisplayFrame();
00065 
00066   // nsISupports interface:
00067   NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
00068 private:
00069   NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
00070   NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
00071   
00072 public:
00073   // nsIFrame
00074   virtual nsIFrame* GetContentInsertionFrame();
00075   virtual already_AddRefed<nsIContent> GetContentInsertionNode();
00076 
00077   NS_IMETHOD  DidReflow(nsPresContext*           aPresContext,
00078                         const nsHTMLReflowState*  aReflowState,
00079                         nsDidReflowStatus         aStatus);
00080 
00081   // nsIAnonymousContentCreator
00082   NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext,
00083                                     nsISupportsArray& aAnonymousItems);
00084   
00085   // If the creator doesn't want to create special frame for frame hierarchy
00086   // then it should null out the style content arg and return NS_ERROR_FAILURE
00087   NS_IMETHOD CreateFrameFor(nsPresContext*   aPresContext,
00088                             nsIContent *      aContent,
00089                             nsIFrame**        aFrame) {
00090     if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; }  
00091 };
00092 
00093 //----------------------------------------------------------------------
00094 // Implementation
00095 
00096 nsXTFXMLBlockDisplayFrame::nsXTFXMLBlockDisplayFrame()
00097     : nsXTFXMLBlockDisplayFrameBase()
00098 {}
00099 
00100 //----------------------------------------------------------------------
00101 // nsISupports methods
00102 
00103 NS_INTERFACE_MAP_BEGIN(nsXTFXMLBlockDisplayFrame)
00104   NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
00105 NS_INTERFACE_MAP_END_INHERITING(nsXTFXMLBlockDisplayFrameBase)
00106 
00107 //----------------------------------------------------------------------
00108 // nsIFrame methods
00109 
00110 nsIFrame*
00111 nsXTFXMLBlockDisplayFrame::GetContentInsertionFrame()
00112 {
00113   return nsXTFFrameUtils::GetContentInsertionFrame(this);
00114 }
00115 
00116 
00117 already_AddRefed<nsIContent>
00118 nsXTFXMLBlockDisplayFrame::GetContentInsertionNode()
00119 {
00120   return nsXTFFrameUtils::GetContentInsertionNode(this);
00121 }
00122 
00123 NS_IMETHODIMP
00124 nsXTFXMLBlockDisplayFrame::DidReflow(nsPresContext*           aPresContext,
00125                                 const nsHTMLReflowState*  aReflowState,
00126                                 nsDidReflowStatus         aStatus)
00127 {
00128   nsresult rv = nsXTFXMLBlockDisplayFrameBase::DidReflow(aPresContext, aReflowState, aStatus);
00129   nsCOMPtr<nsIXTFVisualWrapperPrivate> visual = do_QueryInterface(mContent);
00130   NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate");
00131   visual->DidLayout();
00132   
00133   return rv;
00134 }
00135 
00136 //----------------------------------------------------------------------
00137 // nsIAnonymousContentCreator methods:
00138 
00139 NS_IMETHODIMP
00140 nsXTFXMLBlockDisplayFrame::CreateAnonymousContent(nsPresContext* aPresContext,
00141                                              nsISupportsArray& aAnonymousItems)
00142 {
00143   nsCOMPtr<nsIXTFVisualWrapperPrivate> visual = do_QueryInterface(mContent);
00144   NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate");
00145   return visual->CreateAnonymousContent(aPresContext, aAnonymousItems);
00146 }
00147 
00149 // nsXTFXMLInlineDisplayFrame
00150 
00151 nsresult NS_NewXTFXMLDisplayFrame(nsIPresShell* aPresShell,
00152                                   PRBool isInline, nsIFrame** aNewFrame);
00153   
00154 
00155 typedef nsInlineFrame nsXTFXMLInlineDisplayFrameBase;
00156 
00157 class nsXTFXMLInlineDisplayFrame : public nsXTFXMLInlineDisplayFrameBase,
00158                                    public nsIAnonymousContentCreator
00159 {
00160 public:
00161   nsXTFXMLInlineDisplayFrame();
00162 
00163   // nsISupports interface:
00164   NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
00165 private:
00166   NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
00167   NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
00168   
00169 public:
00170   // nsIFrame
00171   virtual nsIFrame* GetContentInsertionFrame();
00172   virtual already_AddRefed<nsIContent> GetContentInsertionNode();
00173 
00174   NS_IMETHOD  DidReflow(nsPresContext*           aPresContext,
00175                         const nsHTMLReflowState*  aReflowState,
00176                         nsDidReflowStatus         aStatus);
00177 
00178   // nsIAnonymousContentCreator
00179   NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext,
00180                                     nsISupportsArray& aAnonymousItems);
00181   
00182   // If the creator doesn't want to create special frame for frame hierarchy
00183   // then it should null out the style content arg and return NS_ERROR_FAILURE
00184   NS_IMETHOD CreateFrameFor(nsPresContext*   aPresContext,
00185                             nsIContent *      aContent,
00186                             nsIFrame**        aFrame) {
00187     if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; }
00188 };
00189 
00190 //----------------------------------------------------------------------
00191 // Implementation
00192 
00193 nsXTFXMLInlineDisplayFrame::nsXTFXMLInlineDisplayFrame()
00194     : nsXTFXMLInlineDisplayFrameBase()
00195 {}
00196 
00197 //----------------------------------------------------------------------
00198 // nsISupports methods
00199 
00200 NS_INTERFACE_MAP_BEGIN(nsXTFXMLInlineDisplayFrame)
00201   NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
00202 NS_INTERFACE_MAP_END_INHERITING(nsXTFXMLInlineDisplayFrameBase)
00203 
00204 //----------------------------------------------------------------------
00205 // nsIFrame methods
00206 
00207 nsIFrame*
00208 nsXTFXMLInlineDisplayFrame::GetContentInsertionFrame()
00209 {
00210   return nsXTFFrameUtils::GetContentInsertionFrame(this);
00211 }
00212 
00213 already_AddRefed<nsIContent>
00214 nsXTFXMLInlineDisplayFrame::GetContentInsertionNode()
00215 {
00216   return nsXTFFrameUtils::GetContentInsertionNode(this);
00217 }
00218 
00219 NS_IMETHODIMP
00220 nsXTFXMLInlineDisplayFrame::DidReflow(nsPresContext*           aPresContext,
00221                                       const nsHTMLReflowState*  aReflowState,
00222                                       nsDidReflowStatus         aStatus)
00223 {
00224   nsresult rv = nsXTFXMLInlineDisplayFrameBase::DidReflow(aPresContext, aReflowState, aStatus);
00225   nsCOMPtr<nsIXTFVisualWrapperPrivate> visual = do_QueryInterface(mContent);
00226   NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate");
00227   visual->DidLayout();
00228   
00229   return rv;
00230 }
00231 
00232 //----------------------------------------------------------------------
00233 // nsIAnonymousContentCreator methods:
00234 
00235 NS_IMETHODIMP
00236 nsXTFXMLInlineDisplayFrame::CreateAnonymousContent(nsPresContext* aPresContext,
00237                                                    nsISupportsArray& aAnonymousItems)
00238 {
00239   nsCOMPtr<nsIXTFVisualWrapperPrivate> visual = do_QueryInterface(mContent);
00240   NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate");
00241   return visual->CreateAnonymousContent(aPresContext, aAnonymousItems);
00242 }
00243 
00244 
00246 // Construction API
00247 
00248 nsresult
00249 NS_NewXTFXMLDisplayFrame(nsIPresShell* aPresShell, PRBool isBlock, nsIFrame** aNewFrame)
00250 {
00251   if (isBlock)
00252     *aNewFrame = new (aPresShell) nsXTFXMLBlockDisplayFrame();
00253   else
00254     *aNewFrame = new (aPresShell) nsXTFXMLInlineDisplayFrame();
00255   
00256   if (nsnull == *aNewFrame)
00257     return NS_ERROR_OUT_OF_MEMORY;
00258 
00259   return NS_OK;
00260 }