Back to index

lightning-sunbird  0.9+nobinonly
nsFormControlFrame.h
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 #ifndef nsFormControlFrame_h___
00039 #define nsFormControlFrame_h___
00040 
00041 #include "nsIFormControlFrame.h"
00042 #include "nsFormControlHelper.h"
00043 #include "nsISupports.h"
00044 #include "nsIWidget.h"
00045 #include "nsLeafFrame.h"
00046 #include "nsCoord.h"
00047 #include "nsPresContext.h"
00048 #include "nsCOMPtr.h"
00049 
00050 class nsIView;
00051 class nsPresContext;
00052 class nsStyleCoord;
00053 
00054 #define CSS_NOTSET -1
00055 #define ATTR_NOTSET -1
00056 
00057 #define NS_FORMSIZE_NOTSET -1
00058 
00059 #ifdef DEBUG_rods
00060 
00061 #define COMPARE_QUIRK_SIZE(__class, __navWidth, __navHeight) \
00062 { \
00063   float t2p;                                            \
00064   t2p = aPresContext->TwipsToPixels();                  \
00065   printf ("%-25s::Size=%4d,%4d %3d,%3d Nav:%3d,%3d Diffs: %3d,%3d\n",  \
00066            (__class),                                   \
00067            aDesiredSize.width, aDesiredSize.height,     \
00068            NSToCoordRound(aDesiredSize.width * t2p),    \
00069            NSToCoordRound(aDesiredSize.height * t2p),   \
00070            (__navWidth),                                \
00071            (__navHeight),                               \
00072            NSToCoordRound(aDesiredSize.width * t2p) - (__navWidth),   \
00073            NSToCoordRound(aDesiredSize.height * t2p) - (__navHeight)); \
00074 }
00075 
00076 #else
00077 #define COMPARE_QUIRK_SIZE(__class, __navWidth, __navHeight)
00078 #endif
00079 
00085 class nsFormControlFrame : public nsLeafFrame,
00086                            public nsIFormControlFrame
00087 {
00088 
00089 public:
00095   nsFormControlFrame();
00096 
00097   NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
00098 
00103   NS_IMETHOD HandleEvent(nsPresContext* aPresContext, 
00104                          nsGUIEvent* aEvent,
00105                          nsEventStatus* aEventStatus);
00106 
00111   NS_IMETHOD Paint(nsPresContext*      aPresContext,
00112                    nsIRenderingContext& aRenderingContext,
00113                    const nsRect&        aDirtyRect,
00114                    nsFramePaintLayer    aWhichLayer,
00115                    PRUint32             aFlags = 0);
00116 
00117   NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint,
00118                               nsFramePaintLayer aWhichLayer,
00119                               nsIFrame** aFrame);
00120 
00121   NS_IMETHOD SetInitialChildList(nsPresContext* aPresContext,
00122                                  nsIAtom*        aListName,
00123                                  nsIFrame*       aChildList);
00124 
00125   NS_IMETHOD DidReflow(nsPresContext*           aPresContext,
00126                        const nsHTMLReflowState*  aReflowState,
00127                        nsDidReflowStatus         aStatus);
00128 
00133   NS_IMETHOD Reflow(nsPresContext*      aCX,
00134                     nsHTMLReflowMetrics& aDesiredSize,
00135                     const nsHTMLReflowState& aReflowState,
00136                     nsReflowStatus&      aStatus);
00137 
00138   NS_IMETHOD Destroy(nsPresContext *aPresContext);
00139 
00140   // new behavior
00141 
00146   virtual const nsIID& GetCID(); 
00147 
00152   virtual const nsIID& GetIID(); 
00153 
00154   NS_IMETHOD_(PRInt32) GetFormControlType() const;
00155   NS_IMETHOD GetName(nsAString* aName);
00156   NS_IMETHOD GetValue(nsAString* aName);
00157 
00161   virtual void EnterPressed(nsPresContext* aPresContext) {} 
00162 
00166   virtual void ControlChanged(nsPresContext* aPresContext) {}
00167 
00171   virtual void InitializeControl(nsPresContext* aPresContext);
00172 
00173   virtual void SetFocus(PRBool aOn = PR_TRUE, PRBool aRepaint = PR_FALSE);
00174   virtual void ScrollIntoView(nsPresContext* aPresContext);
00175 
00180   virtual nsWidgetInitData* GetWidgetInitData(nsPresContext* aPresContext);  
00181 
00182   void GetWidgetSize(nsSize& aSize) const { aSize.width  = mWidgetSize.width; 
00183                                             aSize.height = mWidgetSize.height; }
00184 
00185   // XXX similar functionality needs to be added to widget library and these
00186   //     need to change to use it.
00187   static  nscoord GetScrollbarWidth(float aPixToTwip);
00188 
00189   virtual nsresult GetSizeFromContent(PRInt32* aSize) const;
00190   NS_IMETHOD GetMaxLength(PRInt32* aSize);
00191 
00192   virtual void SetClickPoint(nscoord aX, nscoord aY);
00193 
00194   NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
00195 
00202   static void GetStyleSize(nsPresContext* aContext,
00203                             const nsHTMLReflowState& aReflowState,
00204                             nsSize& aSize);
00205 
00206     // nsIFormControlFrame
00207   NS_IMETHOD SetProperty(nsPresContext* aPresContext, nsIAtom* aName, const nsAString& aValue);
00208 
00209   NS_IMETHOD GetProperty(nsIAtom* aName, nsAString& aValue); 
00210   // Resize Reflow Optimiaztion Methods
00211   static void SetupCachedSizes(nsSize& aCacheSize,
00212                                nscoord& aCachedAscent,
00213                                nscoord& aCachedMaxElementWidth,
00214                                nsHTMLReflowMetrics& aDesiredSize);
00215 
00216   static void SkipResizeReflow(nsSize& aCacheSize,
00217                                nscoord& aCachedAscent,
00218                                nscoord& aCachedMaxElementWidth,
00219                                nsSize& aCachedAvailableSize,
00220                                nsHTMLReflowMetrics& aDesiredSize,
00221                                const nsHTMLReflowState& aReflowState,
00222                                nsReflowStatus& aStatus,
00223                                PRBool& aBailOnWidth,
00224                                PRBool& aBailOnHeight);
00225   // AccessKey Helper function
00226   static nsresult RegUnRegAccessKey(nsPresContext* aPresContext, nsIFrame * aFrame, PRBool aDoReg);
00227 
00232   static nsresult GetScreenHeight(nsPresContext* aPresContext, nscoord& aHeight);
00233 
00238   static nsresult GetAbsoluteFramePosition(nsPresContext* aPresContext,
00239                                            nsIFrame *aFrame, 
00240                                            nsRect& aAbsoluteTwipsRect, 
00241                                            nsRect& aAbsolutePixelRect);
00242 protected:
00243 
00244   virtual ~nsFormControlFrame();
00245 
00252   virtual void GetDesiredSize(nsPresContext* aPresContext,
00253                               const nsHTMLReflowState& aReflowState,
00254                               nsHTMLReflowMetrics& aDesiredSize);
00255 
00256   virtual void GetDesiredSize(nsPresContext* aPresContext,
00257                               const nsHTMLReflowState& aReflowState,
00258                               nsHTMLReflowMetrics& aDesiredLayoutSize,
00259                               nsSize& aDesiredWidgetSize);
00260 
00261   NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
00262 
00263 //
00264 //-------------------------------------------------------------------------------------
00265 //  Utility methods for managing checkboxes and radiobuttons
00266 //-------------------------------------------------------------------------------------
00267 //   
00275   nsresult GetCurrentCheckState(PRBool* aState);
00276  
00284   nsresult SetCurrentCheckState(PRBool aState);
00285 
00293   nsresult GetDefaultCheckState(PRBool* aState);
00294 
00302   nsresult SetDefaultCheckState(PRBool aState);
00303 
00304   nsSize       mWidgetSize;
00305   PRBool       mDidInit;
00306   nsPoint      mLastClickPoint;
00307   nscoord      mSuggestedWidth;
00308   nscoord      mSuggestedHeight;
00309 
00310   nsPresContext * mPresContext;
00311 
00312   // Reflow Optimization
00313   nsSize       mCacheSize;
00314   nscoord      mCachedAscent;
00315   nscoord      mCachedMaxElementWidth;
00316 
00317 private:
00318   NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
00319   NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
00320 
00321 };
00322 
00323 #endif
00324