Back to index

lightning-sunbird  0.9+nobinonly
nsLegendFrame.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 mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 // YY need to pass isMultiple before create called
00039 
00040 #include "nsLegendFrame.h"
00041 #include "nsIDOMNode.h"
00042 #include "nsIDOMHTMLLegendElement.h"
00043 #include "nsCSSRendering.h"
00044 #include "nsIContent.h"
00045 #include "nsIFrame.h"
00046 #include "nsISupports.h"
00047 #include "nsIAtom.h"
00048 #include "nsGenericHTMLElement.h"
00049 #include "nsHTMLParts.h"
00050 #include "nsHTMLAtoms.h"
00051 #include "nsLayoutAtoms.h"
00052 #include "nsStyleConsts.h"
00053 #include "nsFont.h"
00054 #include "nsFormControlFrame.h"
00055 
00056 static NS_DEFINE_IID(kLegendFrameCID, NS_LEGEND_FRAME_CID);
00057  
00058 nsresult
00059 NS_NewLegendFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
00060 {
00061   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00062   if (nsnull == aNewFrame) {
00063     return NS_ERROR_NULL_POINTER;
00064   }
00065   nsLegendFrame* it = new (aPresShell) nsLegendFrame;
00066   if (!it) {
00067     return NS_ERROR_OUT_OF_MEMORY;
00068   }
00069   *aNewFrame = it;
00070   return NS_OK;
00071 }
00072 
00073 nsLegendFrame::nsLegendFrame()
00074   : nsAreaFrame()
00075 {
00076   mPresContext    = nsnull;
00077 }
00078 
00079 nsLegendFrame::~nsLegendFrame()
00080 {
00081 }
00082 
00083 nsIAtom*
00084 nsLegendFrame::GetType() const
00085 {
00086   return nsLayoutAtoms::legendFrame; 
00087 }
00088 
00089 NS_IMETHODIMP
00090 nsLegendFrame::Destroy(nsPresContext *aPresContext)
00091 {
00092   nsFormControlFrame::RegUnRegAccessKey(aPresContext, NS_STATIC_CAST(nsIFrame*, this), PR_FALSE);
00093   return nsAreaFrame::Destroy(aPresContext);
00094 }
00095 
00096 // Frames are not refcounted, no need to AddRef
00097 NS_IMETHODIMP
00098 nsLegendFrame::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
00099 {
00100   NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
00101   if (nsnull == aInstancePtrResult) {
00102     return NS_ERROR_NULL_POINTER;
00103   }
00104   if (aIID.Equals(kLegendFrameCID)) {
00105     *aInstancePtrResult = (void*) ((nsLegendFrame*)this);
00106     return NS_OK;
00107   }
00108   return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtrResult);
00109 }
00110 
00111 NS_IMETHODIMP 
00112 nsLegendFrame::Reflow(nsPresContext*          aPresContext,
00113                      nsHTMLReflowMetrics&     aDesiredSize,
00114                      const nsHTMLReflowState& aReflowState,
00115                      nsReflowStatus&          aStatus)
00116 {
00117   DO_GLOBAL_REFLOW_COUNT("nsLegendFrame", aReflowState.reason);
00118   DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
00119   if (eReflowReason_Initial == aReflowState.reason) {
00120     mPresContext = aPresContext;
00121     nsFormControlFrame::RegUnRegAccessKey(aPresContext, NS_STATIC_CAST(nsIFrame*, this), PR_TRUE);
00122   } 
00123   return nsAreaFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
00124 }
00125 
00126 
00127 NS_IMETHODIMP
00128 nsLegendFrame::Paint(nsPresContext*      aPresContext,
00129                      nsIRenderingContext& aRenderingContext,
00130                      const nsRect&        aDirtyRect,
00131                      nsFramePaintLayer    aWhichLayer,
00132                      PRUint32             aFlags)
00133 {
00134   PRBool isVisible;
00135   if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) && !isVisible) {
00136     return NS_OK;
00137   }
00138   return nsAreaFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
00139 }
00140 
00141 PRInt32 nsLegendFrame::GetAlign()
00142 {
00143   PRInt32 intValue = NS_STYLE_TEXT_ALIGN_LEFT;
00144 #ifdef IBMBIDI
00145   if (NS_STYLE_DIRECTION_RTL == GetStyleVisibility()->mDirection) {
00146     intValue = NS_STYLE_TEXT_ALIGN_RIGHT;
00147   }
00148 #endif // IBMBIDI
00149 
00150   nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(mContent);
00151 
00152   if (content) {
00153     const nsAttrValue* attr = content->GetParsedAttr(nsHTMLAtoms::align);
00154     if (attr && attr->Type() == nsAttrValue::eEnum) {
00155       intValue = attr->GetEnumValue();
00156     }
00157   }
00158   return intValue;
00159 }
00160 
00161 #ifdef NS_DEBUG
00162 NS_IMETHODIMP
00163 nsLegendFrame::GetFrameName(nsAString& aResult) const
00164 {
00165   return MakeFrameName(NS_LITERAL_STRING("Legend"), aResult);
00166 }
00167 #endif