1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 :
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * John B. Keiser
20 : * Portions created by the Initial Developer are Copyright (C) 2001
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsITextControlElement_h___
40 : #define nsITextControlElement_h___
41 :
42 : #include "nsISupports.h"
43 : class nsIContent;
44 : class nsAString;
45 : class nsIEditor;
46 : class nsISelectionController;
47 : class nsFrameSelection;
48 : class nsTextControlFrame;
49 :
50 : // IID for the nsITextControl interface
51 : #define NS_ITEXTCONTROLELEMENT_IID \
52 : { 0x2e758eee, 0xd023, 0x4fd1, \
53 : { 0x97, 0x93, 0xae, 0xeb, 0xbb, 0xf3, 0xa8, 0x3f } }
54 :
55 : /**
56 : * This interface is used for the text control frame to get the editor and
57 : * selection controller objects, and some helper properties.
58 : */
59 1 : class nsITextControlElement : public nsISupports {
60 : public:
61 :
62 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEXTCONTROLELEMENT_IID)
63 :
64 : /**
65 : * Tell the control that value has been deliberately changed (or not).
66 : */
67 : NS_IMETHOD SetValueChanged(bool changed) = 0;
68 :
69 : /**
70 : * Find out whether this is a single line text control. (text or password)
71 : * @return whether this is a single line text control
72 : */
73 : NS_IMETHOD_(bool) IsSingleLineTextControl() const = 0;
74 :
75 : /**
76 : * Find out whether this control is a textarea.
77 : * @return whether this is a textarea text control
78 : */
79 : NS_IMETHOD_(bool) IsTextArea() const = 0;
80 :
81 : /**
82 : * Find out whether this control edits plain text. (Currently always true.)
83 : * @return whether this is a plain text control
84 : */
85 : NS_IMETHOD_(bool) IsPlainTextControl() const = 0;
86 :
87 : /**
88 : * Find out whether this is a password control (input type=password)
89 : * @return whether this is a password ontrol
90 : */
91 : NS_IMETHOD_(bool) IsPasswordTextControl() const = 0;
92 :
93 : /**
94 : * Get the cols attribute (if textarea) or a default
95 : * @return the number of columns to use
96 : */
97 : NS_IMETHOD_(PRInt32) GetCols() = 0;
98 :
99 : /**
100 : * Get the column index to wrap at, or -1 if we shouldn't wrap
101 : */
102 : NS_IMETHOD_(PRInt32) GetWrapCols() = 0;
103 :
104 : /**
105 : * Get the rows attribute (if textarea) or a default
106 : * @return the number of rows to use
107 : */
108 : NS_IMETHOD_(PRInt32) GetRows() = 0;
109 :
110 : /**
111 : * Get the default value of the text control
112 : */
113 : NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString& aValue) = 0;
114 :
115 : /**
116 : * Return true if the value of the control has been changed.
117 : */
118 : NS_IMETHOD_(bool) ValueChanged() const = 0;
119 :
120 : /**
121 : * Get the current value of the text editor.
122 : *
123 : * @param aValue the buffer to retrieve the value in
124 : * @param aIgnoreWrap whether to ignore the text wrapping behavior specified
125 : * for the element.
126 : */
127 : NS_IMETHOD_(void) GetTextEditorValue(nsAString& aValue, bool aIgnoreWrap) const = 0;
128 :
129 : /**
130 : * Set the current value of the text editor.
131 : *
132 : * @param aValue the new value for the text control.
133 : * @param aUserInput whether this value is coming from user input.
134 : */
135 : NS_IMETHOD_(void) SetTextEditorValue(const nsAString& aValue, bool aUserInput) = 0;
136 :
137 : /**
138 : * Get the editor object associated with the text editor.
139 : * The return value is null if the control does not support an editor
140 : * (for example, if it is a checkbox.)
141 : */
142 : NS_IMETHOD_(nsIEditor*) GetTextEditor() = 0;
143 :
144 : /**
145 : * Get the selection controller object associated with the text editor.
146 : * The return value is null if the control does not support an editor
147 : * (for example, if it is a checkbox.)
148 : */
149 : NS_IMETHOD_(nsISelectionController*) GetSelectionController() = 0;
150 :
151 : NS_IMETHOD_(nsFrameSelection*) GetConstFrameSelection() = 0;
152 :
153 : /**
154 : * Binds a frame to the text control. This is performed when a frame
155 : * is created for the content node.
156 : */
157 : NS_IMETHOD BindToFrame(nsTextControlFrame* aFrame) = 0;
158 :
159 : /**
160 : * Unbinds a frame from the text control. This is performed when a frame
161 : * belonging to a content node is destroyed.
162 : */
163 : NS_IMETHOD_(void) UnbindFromFrame(nsTextControlFrame* aFrame) = 0;
164 :
165 : /**
166 : * Creates an editor for the text control. This should happen when
167 : * a frame has been created for the text control element, but the created
168 : * editor may outlive the frame itself.
169 : */
170 : NS_IMETHOD CreateEditor() = 0;
171 :
172 : /**
173 : * Get the anonymous root node for the text control.
174 : */
175 : NS_IMETHOD_(nsIContent*) GetRootEditorNode() = 0;
176 :
177 : /**
178 : * Create the placeholder anonymous node for the text control and returns it.
179 : */
180 : NS_IMETHOD_(nsIContent*) CreatePlaceholderNode() = 0;
181 :
182 : /**
183 : * Get the placeholder anonymous node for the text control.
184 : */
185 : NS_IMETHOD_(nsIContent*) GetPlaceholderNode() = 0;
186 :
187 : /**
188 : * Initialize the keyboard event listeners.
189 : */
190 : NS_IMETHOD_(void) InitializeKeyboardEventListeners() = 0;
191 :
192 : /**
193 : * Notify the text control that the placeholder text needs to be updated.
194 : */
195 : NS_IMETHOD_(void) UpdatePlaceholderText(bool aNotify) = 0;
196 :
197 : /**
198 : * Show/hide the placeholder for the control.
199 : */
200 : NS_IMETHOD_(void) SetPlaceholderClass(bool aVisible, bool aNotify) = 0;
201 :
202 : /**
203 : * Callback called whenever the value is changed.
204 : */
205 : NS_IMETHOD_(void) OnValueChanged(bool aNotify) = 0;
206 :
207 : static const PRInt32 DEFAULT_COLS = 20;
208 : static const PRInt32 DEFAULT_ROWS = 1;
209 : static const PRInt32 DEFAULT_ROWS_TEXTAREA = 2;
210 : static const PRInt32 DEFAULT_UNDO_CAP = 1000;
211 :
212 : // wrap can be one of these three values.
213 : typedef enum {
214 : eHTMLTextWrap_Off = 1, // "off"
215 : eHTMLTextWrap_Hard = 2, // "hard"
216 : eHTMLTextWrap_Soft = 3 // the default
217 : } nsHTMLTextWrap;
218 :
219 : static bool
220 : GetWrapPropertyEnum(nsIContent* aContent, nsHTMLTextWrap& aWrapProp);
221 :
222 : /**
223 : * Does the editor have a selection cache?
224 : *
225 : * Note that this function has the side effect of making the editor for input
226 : * elements be initialized eagerly.
227 : */
228 : NS_IMETHOD_(bool) HasCachedSelection() = 0;
229 : };
230 :
231 : NS_DEFINE_STATIC_IID_ACCESSOR(nsITextControlElement,
232 : NS_ITEXTCONTROLELEMENT_IID)
233 :
234 : #endif // nsITextControlElement_h___
235 :
|