2002-07-26 21:17:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-07-26 21:17:00 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2002-07-26 21:17:00 +04:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-07-26 21:17:00 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2002-07-26 21:17:00 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-07-26 21:17:00 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-07-26 21:17:00 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2002-07-27 00:57:24 +04:00
|
|
|
#ifndef nsTextControlFrame_h___
|
|
|
|
#define nsTextControlFrame_h___
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
#include "nsStackFrame.h"
|
|
|
|
#include "nsAreaFrame.h"
|
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsIDOMMouseListener.h"
|
|
|
|
#include "nsIAnonymousContentCreator.h"
|
|
|
|
#include "nsIEditor.h"
|
2002-07-27 00:57:24 +04:00
|
|
|
#include "nsITextControlFrame.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsWeakReference.h" //for service and presshell pointers
|
|
|
|
#include "nsIScrollableViewProvider.h"
|
2002-12-18 02:38:04 +03:00
|
|
|
#include "nsIPhonetic.h"
|
2006-02-09 06:50:53 +03:00
|
|
|
#include "nsContentUtils.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
class nsISupportsArray;
|
|
|
|
class nsIEditor;
|
|
|
|
class nsISelectionController;
|
|
|
|
class nsTextInputSelectionImpl;
|
|
|
|
class nsTextInputListener;
|
|
|
|
class nsIDOMCharacterData;
|
|
|
|
class nsIScrollableView;
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
class nsIAccessible;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-07-27 00:57:24 +04:00
|
|
|
class nsTextControlFrame : public nsStackFrame,
|
2002-09-16 10:23:52 +04:00
|
|
|
public nsIAnonymousContentCreator,
|
|
|
|
public nsITextControlFrame,
|
2002-12-18 02:38:04 +03:00
|
|
|
public nsIScrollableViewProvider,
|
|
|
|
public nsIPhonetic
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
public:
|
2006-03-27 01:30:36 +04:00
|
|
|
nsTextControlFrame(nsIPresShell* aShell, nsStyleContext* aContext);
|
2002-07-27 00:57:24 +04:00
|
|
|
virtual ~nsTextControlFrame();
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
virtual void RemovedAsPrimaryFrame();
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
virtual void Destroy();
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
2002-07-26 21:17:00 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
|
|
|
|
NS_IMETHOD GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
|
|
|
NS_IMETHOD GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
|
|
|
NS_IMETHOD GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
|
|
|
NS_IMETHOD GetAscent(nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent);
|
2005-08-17 02:52:48 +04:00
|
|
|
|
|
|
|
virtual PRBool IsLeaf() const;
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aResult.AssignLiteral("nsTextControlFrame");
|
2002-07-26 21:17:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// from nsIAnonymousContentCreator
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext,
|
2002-07-26 21:17:00 +04:00
|
|
|
nsISupportsArray& aChildList);
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD CreateFrameFor(nsPresContext* aPresContext,
|
2003-09-19 19:20:00 +04:00
|
|
|
nsIContent * aContent,
|
|
|
|
nsIFrame** aFrame);
|
|
|
|
virtual void PostCreateFrames();
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
// Utility methods to set current widget state
|
|
|
|
void SetValue(const nsAString& aValue);
|
2006-04-10 04:16:29 +04:00
|
|
|
NS_IMETHOD SetInitialChildList(nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
//==== BEGIN NSIFORMCONTROLFRAME
|
|
|
|
virtual void SetFocus(PRBool aOn , PRBool aRepaint);
|
2005-12-13 02:53:06 +03:00
|
|
|
virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue);
|
|
|
|
virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
//==== END NSIFORMCONTROLFRAME
|
|
|
|
|
|
|
|
//==== NSIGFXTEXTCONTROLFRAME2
|
|
|
|
|
|
|
|
NS_IMETHOD GetEditor(nsIEditor **aEditor);
|
|
|
|
NS_IMETHOD OwnsValue(PRBool* aOwnsValue);
|
2005-12-13 02:53:06 +03:00
|
|
|
NS_IMETHOD GetValue(nsAString& aValue, PRBool aIgnoreWrap) const;
|
2002-07-26 21:17:00 +04:00
|
|
|
NS_IMETHOD GetTextLength(PRInt32* aTextLength);
|
|
|
|
NS_IMETHOD CheckFireOnChange();
|
|
|
|
NS_IMETHOD SetSelectionStart(PRInt32 aSelectionStart);
|
|
|
|
NS_IMETHOD SetSelectionEnd(PRInt32 aSelectionEnd);
|
|
|
|
NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd);
|
|
|
|
NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd);
|
2006-02-21 03:49:04 +03:00
|
|
|
virtual nsISelectionController* GetOwnedSelectionController()
|
|
|
|
{ return mSelCon; }
|
2006-04-26 06:01:07 +04:00
|
|
|
virtual nsFrameSelection* GetOwnedFrameSelection()
|
2006-02-21 03:49:04 +03:00
|
|
|
{ return mFrameSel; }
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-12-18 02:38:04 +03:00
|
|
|
// nsIPhonetic
|
|
|
|
NS_DECL_NSIPHONETIC
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
//==== END NSIGFXTEXTCONTROLFRAME2
|
|
|
|
//==== OVERLOAD of nsIFrame
|
2003-10-31 23:19:18 +03:00
|
|
|
virtual nsIAtom* GetType() const;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
/** handler for attribute changes to mContent */
|
2005-09-07 20:49:21 +04:00
|
|
|
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
|
2002-07-26 21:17:00 +04:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-12 01:16:12 +04:00
|
|
|
PRInt32 aModType);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
NS_IMETHOD GetText(nsString* aText);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2002-07-27 00:57:24 +04:00
|
|
|
public: //for methods who access nsTextControlFrame directly
|
2002-07-26 21:17:00 +04:00
|
|
|
/**
|
|
|
|
* Find out whether this is a single line text control. (text or password)
|
|
|
|
* @return whether this is a single line text control
|
|
|
|
*/
|
2002-11-21 02:19:45 +03:00
|
|
|
PRBool IsSingleLineTextControl() const;
|
2002-07-26 21:17:00 +04:00
|
|
|
/**
|
|
|
|
* Find out whether this control is a textarea.
|
|
|
|
* @return whether this is a textarea text control
|
|
|
|
*/
|
2002-11-21 02:19:45 +03:00
|
|
|
PRBool IsTextArea() const;
|
2002-07-26 21:17:00 +04:00
|
|
|
/**
|
|
|
|
* Find out whether this control edits plain text. (Currently always true.)
|
|
|
|
* @return whether this is a plain text control
|
|
|
|
*/
|
2002-11-21 02:19:45 +03:00
|
|
|
PRBool IsPlainTextControl() const;
|
2002-07-26 21:17:00 +04:00
|
|
|
/**
|
|
|
|
* Find out whether this is a password control (input type=password)
|
|
|
|
* @return whether this is a password ontrol
|
|
|
|
*/
|
2002-11-21 02:19:45 +03:00
|
|
|
PRBool IsPasswordTextControl() const;
|
2006-02-21 03:49:04 +03:00
|
|
|
void FireOnInput();
|
2002-07-26 21:17:00 +04:00
|
|
|
void SetValueChanged(PRBool aValueChanged);
|
|
|
|
/** Called when the frame is focused, to remember the value for onChange. */
|
|
|
|
nsresult InitFocusedValue();
|
2003-01-09 09:06:17 +03:00
|
|
|
nsresult DOMPointToOffset(nsIDOMNode* aNode, PRInt32 aNodeOffset, PRInt32 *aResult);
|
|
|
|
nsresult OffsetToDOMPoint(PRInt32 aOffset, nsIDOMNode** aResult, PRInt32* aPosition);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2006-07-06 02:15:01 +04:00
|
|
|
void SetHasFocus(PRBool aHasFocus)
|
|
|
|
{
|
|
|
|
mHasFocus = aHasFocus;
|
|
|
|
};
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
/* called to free up native keybinding services */
|
|
|
|
static NS_HIDDEN_(void) ShutDown();
|
2006-02-09 06:50:53 +03:00
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Find out whether this control is scrollable (i.e. if it is not a single
|
|
|
|
* line text control)
|
|
|
|
* @return whether this control is scrollable
|
|
|
|
*/
|
|
|
|
PRBool IsScrollable() const;
|
|
|
|
/**
|
|
|
|
* Initialize mEditor with the proper flags and the default value.
|
|
|
|
* @throws NS_ERROR_NOT_INITIALIZED if mEditor has not been created
|
|
|
|
* @throws various and sundry other things
|
|
|
|
*/
|
|
|
|
nsresult InitEditor();
|
|
|
|
/**
|
|
|
|
* Strip all \n, \r and nulls from the given string
|
|
|
|
* @param aString the string to remove newlines from [in/out]
|
|
|
|
*/
|
|
|
|
void RemoveNewlines(nsString &aString);
|
|
|
|
/**
|
|
|
|
* Get the maxlength attribute
|
|
|
|
* @param aMaxLength the value of the max length attr
|
2005-10-28 15:25:24 +04:00
|
|
|
* @returns PR_FALSE if attr not defined
|
2002-07-26 21:17:00 +04:00
|
|
|
*/
|
2005-10-28 15:25:24 +04:00
|
|
|
PRBool GetMaxLength(PRInt32* aMaxLength);
|
2002-07-26 21:17:00 +04:00
|
|
|
/**
|
|
|
|
* Find out whether an attribute exists on the content or not.
|
|
|
|
* @param aAtt the attribute to determine the existence of
|
2005-01-12 22:45:38 +03:00
|
|
|
* @returns PR_FALSE if it does not exist
|
2002-07-26 21:17:00 +04:00
|
|
|
*/
|
2005-01-12 22:45:38 +03:00
|
|
|
PRBool AttributeExists(nsIAtom *aAtt) const
|
|
|
|
{ return mContent && mContent->HasAttr(kNameSpaceID_None, aAtt); }
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
/**
|
|
|
|
* We call this when we are being destroyed or removed from the PFM.
|
|
|
|
* @param aPresContext the current pres context
|
|
|
|
*/
|
2006-04-10 04:16:29 +04:00
|
|
|
void PreDestroy();
|
2002-07-26 21:17:00 +04:00
|
|
|
/**
|
|
|
|
* Fire the onChange event.
|
|
|
|
*/
|
2002-09-16 10:23:52 +04:00
|
|
|
|
2006-02-21 03:49:04 +03:00
|
|
|
// Helper methods
|
2002-09-16 10:23:52 +04:00
|
|
|
/**
|
|
|
|
* Get the cols attribute (if textarea) or a default
|
|
|
|
* @return the number of columns to use
|
|
|
|
*/
|
|
|
|
PRInt32 GetCols();
|
|
|
|
/**
|
|
|
|
* Get the rows attribute (if textarea) or a default
|
|
|
|
* @return the number of rows to use
|
|
|
|
*/
|
|
|
|
PRInt32 GetRows();
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsresult ReflowStandard(nsPresContext* aPresContext,
|
2002-09-23 23:43:48 +04:00
|
|
|
nsSize& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsresult CalculateSizeStandard(nsPresContext* aPresContext,
|
2004-10-10 22:30:28 +04:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
2002-09-23 23:43:48 +04:00
|
|
|
nsSize& aDesiredSize,
|
|
|
|
nsSize& aMinSize);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
// nsIScrollableViewProvider
|
2004-09-06 06:44:43 +04:00
|
|
|
virtual nsIScrollableView* GetScrollableView();
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
//helper methods
|
2003-01-21 18:17:32 +03:00
|
|
|
nsresult SetSelectionInternal(nsIDOMNode *aStartNode, PRInt32 aStartOffset,
|
|
|
|
nsIDOMNode *aEndNode, PRInt32 aEndOffset);
|
|
|
|
nsresult SelectAllContents();
|
2002-07-26 21:17:00 +04:00
|
|
|
nsresult SetSelectionEndPoints(PRInt32 aSelStart, PRInt32 aSelEnd);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIEditor> mEditor;
|
|
|
|
|
|
|
|
//cached sizes and states
|
|
|
|
nsSize mSize;
|
|
|
|
|
|
|
|
// these packed bools could instead use the high order bits on mState, saving 4 bytes
|
|
|
|
PRPackedBool mUseEditor;
|
|
|
|
PRPackedBool mIsProcessing;
|
|
|
|
PRPackedBool mNotifyOnInput;//default this to off to stop any notifications until setup is complete
|
2006-07-06 02:15:01 +04:00
|
|
|
PRPackedBool mDidPreDestroy; // has PreDestroy been called
|
|
|
|
PRPackedBool mHasFocus;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2006-02-21 03:49:04 +03:00
|
|
|
nsCOMPtr<nsISelectionController> mSelCon;
|
2006-04-26 06:01:07 +04:00
|
|
|
nsCOMPtr<nsFrameSelection> mFrameSel;
|
2006-02-21 03:49:04 +03:00
|
|
|
nsTextInputListener* mTextListener;
|
|
|
|
// XXX This seems unsafe; what's keeping it around?
|
2002-07-26 21:17:00 +04:00
|
|
|
nsIScrollableView *mScrollableView;
|
|
|
|
nsString mFocusedValue;
|
2006-05-15 23:35:12 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool mCreateFrameForCalled;
|
|
|
|
#endif
|
2002-07-26 21:17:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|