Back to index

lightning-sunbird  0.9+nobinonly
nsFileControlFrame.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 nsFileControlFrame_h___
00039 #define nsFileControlFrame_h___
00040 
00041 #include "nsAreaFrame.h"
00042 #include "nsIFormControlFrame.h"
00043 #include "nsIDOMMouseListener.h"
00044 #include "nsIAnonymousContentCreator.h"
00045 #include "nsCOMPtr.h"
00046 
00047 #include "nsTextControlFrame.h"
00048 #include "nsFormControlHelper.h"
00049 typedef   nsTextControlFrame nsNewFrame;
00050 
00051 class nsISupportsArray;
00052 
00053 class nsFileControlFrame : public nsAreaFrame,
00054                            public nsIFormControlFrame,
00055                            public nsIAnonymousContentCreator
00056 {
00057 public:
00058   nsFileControlFrame();
00059   virtual ~nsFileControlFrame();
00060 
00061   NS_IMETHOD Init(nsPresContext*  aPresContext,
00062                   nsIContent*      aContent,
00063                   nsIFrame*        aParent,
00064                   nsStyleContext*  aContext,
00065                   nsIFrame*        aPrevInFlow);
00066 
00067   NS_IMETHOD Paint(nsPresContext*      aPresContext,
00068                    nsIRenderingContext& aRenderingContext,
00069                    const nsRect&        aDirtyRect,
00070                    nsFramePaintLayer    aWhichLayer,
00071                    PRUint32             aFlags = 0);
00072 
00073       // nsIFormControlFrame
00074   NS_IMETHOD SetProperty(nsPresContext* aPresContext, nsIAtom* aName, const nsAString& aValue);
00075   NS_IMETHOD GetProperty(nsIAtom* aName, nsAString& aValue); 
00076   NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
00077   NS_IMETHOD OnContentReset();
00078 
00079   NS_IMETHOD Reflow(nsPresContext*          aCX,
00080                     nsHTMLReflowMetrics&     aDesiredSize,
00081                     const nsHTMLReflowState& aReflowState,
00082                     nsReflowStatus&          aStatus);
00083 
00084   NS_IMETHOD Destroy(nsPresContext *aPresContext);
00085 
00086 #ifdef NS_DEBUG
00087   NS_IMETHOD GetFrameName(nsAString& aResult) const;
00088 #endif
00089   NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight) { return NS_OK; };
00090   NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint, nsFramePaintLayer aWhichLayer, nsIFrame** aFrame);
00091   NS_IMETHOD AttributeChanged(nsIContent*     aChild,
00092                               PRInt32         aNameSpaceID,
00093                               nsIAtom*        aAttribute,
00094                               PRInt32         aModType);
00095   virtual PRBool IsLeaf() const;
00096 
00097   NS_IMETHOD     GetName(nsAString* aName);
00098   NS_IMETHOD_(PRInt32) GetFormControlType() const;
00099   void           SetFocus(PRBool aOn, PRBool aRepaint);
00100   void           ScrollIntoView(nsPresContext* aPresContext);
00101 
00102   NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
00103   virtual nscoord GetVerticalInsidePadding(nsPresContext* aPresContext,
00104                                            float aPixToTwip,
00105                                            nscoord aInnerHeight) const;
00106   virtual nscoord GetHorizontalInsidePadding(nsPresContext* aPresContext,
00107                                              float aPixToTwip, 
00108                                              nscoord aInnerWidth,
00109                                              nscoord aCharWidth) const;
00110 
00111   // from nsIAnonymousContentCreator
00112   NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext,
00113                                     nsISupportsArray& aChildList);
00114   NS_IMETHOD CreateFrameFor(nsPresContext*   aPresContext,
00115                             nsIContent *      aContent,
00116                             nsIFrame**        aFrame) { if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; }
00117 
00118   // We don't paint our background.
00119   virtual PRBool CanPaintBackground() { return PR_FALSE; }
00120 
00121 protected:
00122   class MouseListener;
00123   friend class MouseListener;
00124   class MouseListener : public nsIDOMMouseListener {
00125   public:
00126     NS_DECL_ISUPPORTS
00127     
00128     MouseListener(nsFileControlFrame* aFrame) :
00129       mFrame(aFrame)
00130     {}
00131  
00132     void ForgetFrame() {
00133       mFrame = nsnull;
00134     }
00135     
00136     // We just want to capture the click events on our browse button
00137     // and textfield.
00138     NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent) { return NS_OK; }
00139     NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent) { return NS_OK; }
00140     NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent);
00141     NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
00142     NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }
00143     NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; }
00144     NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
00145 
00146   private:
00147     nsFileControlFrame* mFrame;
00148   };
00149   
00150   nsresult MouseClick(nsIDOMEvent* aMouseEvent);
00151 
00152   virtual PRIntn GetSkipSides() const;
00153 
00158   nsNewFrame* mTextFrame;
00163   nsCOMPtr<nsIContent> mTextContent;
00168   nsCOMPtr<nsIContent> mBrowse;
00173   nsString*           mCachedState;
00178   nsPresContext*     mPresContext;  // weak reference
00179 
00183   nsRefPtr<MouseListener> mMouseListener;
00184 
00185 private:
00196   nsNewFrame* GetTextControlFrame(nsPresContext* aPresContext,
00197                                   nsIFrame* aStart);
00198 
00206   void SyncAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
00207                 PRBool aWhichControls);
00208 
00209   NS_IMETHOD_(nsrefcnt) AddRef() { return 1; }
00210   NS_IMETHOD_(nsrefcnt) Release() { return 1; }
00211 };
00212 
00213 #endif
00214 
00215