Back to index

lightning-sunbird  0.9+nobinonly
nsTextControlFrame.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 nsTextControlFrame_h___
00039 #define nsTextControlFrame_h___
00040 
00041 #include "nsStackFrame.h"
00042 #include "nsAreaFrame.h"
00043 #include "nsIFormControlFrame.h"
00044 #include "nsIDOMMouseListener.h"
00045 #include "nsIAnonymousContentCreator.h"
00046 #include "nsIEditor.h"
00047 #include "nsITextControlFrame.h"
00048 #include "nsFormControlHelper.h"//for the inputdimensions
00049 #include "nsIFontMetrics.h"
00050 #include "nsWeakReference.h" //for service and presshell pointers
00051 #include "nsIScrollableViewProvider.h"
00052 #include "nsIPhonetic.h"
00053 #include "nsContentUtils.h"
00054 
00055 class nsISupportsArray;
00056 class nsIEditor;
00057 class nsISelectionController;
00058 class nsTextInputSelectionImpl;
00059 class nsTextInputListener;
00060 class nsIDOMCharacterData;
00061 class nsIScrollableView;
00062 #ifdef ACCESSIBILITY
00063 class nsIAccessible;
00064 #endif
00065 
00066 
00067 class nsTextControlFrame : public nsStackFrame,
00068                            public nsIAnonymousContentCreator,
00069                            public nsITextControlFrame,
00070                            public nsIScrollableViewProvider,
00071                            public nsIPhonetic
00072 
00073 {
00074 public:
00075   nsTextControlFrame(nsIPresShell* aShell);
00076   virtual ~nsTextControlFrame();
00077 
00078   virtual void RemovedAsPrimaryFrame(nsPresContext* aPresContext); 
00079 
00080   NS_IMETHOD Destroy(nsPresContext* aPresContext);
00081 
00082   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
00083                     nsHTMLReflowMetrics&     aDesiredSize,
00084                     const nsHTMLReflowState& aReflowState,
00085                     nsReflowStatus&          aStatus);
00086 
00087   NS_IMETHOD  Paint(nsPresContext*      aPresContext,
00088                     nsIRenderingContext& aRenderingContext,
00089                     const nsRect&        aDirtyRect,
00090                     nsFramePaintLayer    aWhichLayer,
00091                     PRUint32             aFlags = 0);
00092 
00093   NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint,
00094                               nsFramePaintLayer aWhichLayer,
00095                               nsIFrame** aFrame);
00096 
00097   NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
00098                          nsGUIEvent* aEvent,
00099                          nsEventStatus* aEventStatus);
00100 
00101   NS_IMETHOD GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00102   NS_IMETHOD GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00103   NS_IMETHOD GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00104   NS_IMETHOD GetAscent(nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent);
00105 
00106   virtual PRBool IsLeaf() const;
00107   
00108 #ifdef ACCESSIBILITY
00109   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
00110 #endif
00111 
00112 #ifdef NS_DEBUG
00113   NS_IMETHOD GetFrameName(nsAString& aResult) const
00114   {
00115     aResult.AssignLiteral("nsTextControlFrame");
00116     return NS_OK;
00117   }
00118 #endif
00119 
00120   // from nsIAnonymousContentCreator
00121   NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext,
00122                                     nsISupportsArray& aChildList);
00123   NS_IMETHOD CreateFrameFor(nsPresContext*   aPresContext,
00124                                nsIContent *      aContent,
00125                                nsIFrame**        aFrame);
00126   virtual void PostCreateFrames();
00127 
00128   // Utility methods to set current widget state
00129 
00130   // Be careful when using this method.
00131   // Calling it may cause |this| to be deleted.
00132   // In that case the method returns an error value.
00133   nsresult SetValue(const nsAString& aValue);
00134   NS_IMETHOD SetInitialChildList(nsPresContext* aPresContext,
00135                                   nsIAtom*        aListName,
00136                                   nsIFrame*       aChildList);
00137 
00138 //==== BEGIN NSIFORMCONTROLFRAME
00139   NS_IMETHOD_(PRInt32) GetFormControlType() const; //*
00140   NS_IMETHOD GetName(nsAString* aName);//*
00141   virtual void SetFocus(PRBool aOn , PRBool aRepaint); 
00142   virtual void ScrollIntoView(nsPresContext* aPresContext);
00143   virtual nscoord GetVerticalInsidePadding(nsPresContext* aPresContext,
00144                                            float aPixToTwip,
00145                                            nscoord aInnerHeight) const;
00146   virtual nscoord GetHorizontalInsidePadding(nsPresContext* aPresContext,
00147                                              float aPixToTwip, 
00148                                              nscoord aInnerWidth,
00149                                              nscoord aCharWidth) const;
00150   NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
00151   NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
00152   NS_IMETHOD SetProperty(nsPresContext* aPresContext, nsIAtom* aName, const nsAString& aValue);
00153   NS_IMETHOD GetProperty(nsIAtom* aName, nsAString& aValue); 
00154   NS_IMETHOD OnContentReset();
00155 
00156 
00157 //==== END NSIFORMCONTROLFRAME
00158 
00159 //==== NSIGFXTEXTCONTROLFRAME2
00160 
00161   NS_IMETHOD    GetEditor(nsIEditor **aEditor);
00162   NS_IMETHOD    OwnsValue(PRBool* aOwnsValue);
00163   NS_IMETHOD    GetValue(nsAString& aValue, PRBool aIgnoreWrap);
00164   NS_IMETHOD    GetTextLength(PRInt32* aTextLength);
00165   NS_IMETHOD    CheckFireOnChange();
00166   NS_IMETHOD    SetSelectionStart(PRInt32 aSelectionStart);
00167   NS_IMETHOD    SetSelectionEnd(PRInt32 aSelectionEnd);
00168   NS_IMETHOD    SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd);
00169   NS_IMETHOD    GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd);
00170   NS_IMETHOD    GetSelectionContr(nsISelectionController **aSelCon);
00171 
00172   // nsIPhonetic
00173   NS_DECL_NSIPHONETIC
00174 
00175 //==== END NSIGFXTEXTCONTROLFRAME2
00176 //==== OVERLOAD of nsIFrame
00177   virtual nsIAtom* GetType() const;
00178 
00180   NS_IMETHOD AttributeChanged(nsIContent*     aChild,
00181                               PRInt32         aNameSpaceID,
00182                               nsIAtom*        aAttribute,
00183                               PRInt32         aModType);
00184 
00185   NS_IMETHOD GetText(nsString* aText);
00186 
00187   NS_DECL_ISUPPORTS_INHERITED
00188 
00189 public: //for methods who access nsTextControlFrame directly
00190 
00191   void FireOnInput();//notify that we have some kind of change.
00196   PRBool IsSingleLineTextControl() const;
00201   PRBool IsTextArea() const;
00206   PRBool IsPlainTextControl() const;
00211   PRBool IsPasswordTextControl() const;
00212   void SetValueChanged(PRBool aValueChanged);
00214   nsresult InitFocusedValue();
00215   nsresult DOMPointToOffset(nsIDOMNode* aNode, PRInt32 aNodeOffset, PRInt32 *aResult);
00216   nsresult OffsetToDOMPoint(PRInt32 aOffset, nsIDOMNode** aResult, PRInt32* aPosition);
00217 
00218   void SetHasFocus(PRBool aHasFocus)
00219   {
00220     mHasFocus = aHasFocus;
00221   };
00222 
00223   /* called to free up native keybinding services */
00224   static NS_HIDDEN_(void) ShutDown();
00225 
00226 protected:
00227 
00233   PRBool IsScrollable() const;
00239   nsresult InitEditor();
00244   void RemoveNewlines(nsString &aString);
00250   nsresult GetMaxLength(PRInt32* aMaxLength);
00256   PRBool AttributeExists(nsIAtom *aAtt) const
00257   { return mContent && mContent->HasAttr(kNameSpaceID_None, aAtt); }
00258 
00263   void PreDestroy(nsPresContext* aPresContext);
00267   nsresult FireOnChange();
00268 
00269 //helper methods
00270   nsresult GetSizeFromContent(PRInt32* aSize) const;
00271 
00276   PRInt32 GetCols();
00281   PRInt32 GetRows();
00282 
00283   nsresult ReflowStandard(nsPresContext*          aPresContext,
00284                           nsSize&                  aDesiredSize,
00285                           const nsHTMLReflowState& aReflowState,
00286                           nsReflowStatus&          aStatus);
00287 
00288   nsresult CalculateSizeStandard(nsPresContext*       aPresContext,
00289                                  const nsHTMLReflowState& aReflowState,
00290                                  nsSize&               aDesiredSize,
00291                                  nsSize&               aMinSize);
00292 
00293   PRInt32 GetWidthInCharacters() const;
00294 
00295   // nsIScrollableViewProvider
00296   virtual nsIScrollableView* GetScrollableView();
00297 
00298 private:
00299   //helper methods
00300   nsresult SetSelectionInternal(nsIDOMNode *aStartNode, PRInt32 aStartOffset,
00301                                 nsIDOMNode *aEndNode, PRInt32 aEndOffset);
00302   nsresult SelectAllContents();
00303   nsresult SetSelectionEndPoints(PRInt32 aSelStart, PRInt32 aSelEnd);
00304 
00305 private:
00306   nsCOMPtr<nsIEditor> mEditor;
00307   nsCOMPtr<nsISelectionController> mSelCon;
00308 
00309   //cached sizes and states
00310   nscoord      mSuggestedWidth;
00311   nscoord      mSuggestedHeight;
00312   nsSize       mSize;
00313 
00314   // these packed bools could instead use the high order bits on mState, saving 4 bytes 
00315   PRPackedBool mUseEditor;
00316   PRPackedBool mIsProcessing;
00317   PRPackedBool mNotifyOnInput;//default this to off to stop any notifications until setup is complete
00318   PRPackedBool mDidPreDestroy; // has PreDestroy been called
00319   PRPackedBool mHasFocus;
00320 
00321   nsTextInputSelectionImpl *mTextSelImpl;
00322   nsTextInputListener *mTextListener;
00323   nsIScrollableView *mScrollableView;
00324   nsString mFocusedValue;
00325 };
00326 
00327 #endif
00328 
00329