author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 3 | 41300fa6a67c |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 |
* (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 |
* (C) 2001 Dirk Mueller (mueller@kde.org) |
|
5 |
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
|
6 |
* (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
|
7 |
* Copyright (C) 2007 Samuel Weinig (sam@webkit.org) |
|
8 |
* |
|
9 |
* This library is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU Library General Public |
|
11 |
* License as published by the Free Software Foundation; either |
|
12 |
* version 2 of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This library is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
* Library General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU Library General Public License |
|
20 |
* along with this library; see the file COPYING.LIB. If not, write to |
|
21 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
22 |
* Boston, MA 02110-1301, USA. |
|
23 |
* |
|
24 |
*/ |
|
25 |
||
26 |
#include "config.h" |
|
27 |
#include "HTMLInputElement.h" |
|
28 |
||
29 |
#include "AXObjectCache.h" |
|
30 |
#include "CSSPropertyNames.h" |
|
31 |
#include "ChromeClient.h" |
|
32 |
#include "Document.h" |
|
33 |
#include "Editor.h" |
|
34 |
#include "Event.h" |
|
35 |
#include "EventHandler.h" |
|
36 |
#include "EventNames.h" |
|
37 |
#include "ExceptionCode.h" |
|
38 |
#include "File.h" |
|
39 |
#include "FileList.h" |
|
40 |
#include "FocusController.h" |
|
41 |
#include "FormDataList.h" |
|
42 |
#include "Frame.h" |
|
43 |
#include "HTMLDataListElement.h" |
|
44 |
#include "HTMLFormElement.h" |
|
45 |
#include "HTMLImageLoader.h" |
|
46 |
#include "HTMLNames.h" |
|
47 |
#include "HTMLOptionElement.h" |
|
48 |
#include "ScriptEventListener.h" |
|
49 |
#include "KeyboardEvent.h" |
|
50 |
#include "LocalizedStrings.h" |
|
51 |
#include "MappedAttribute.h" |
|
52 |
#include "MouseEvent.h" |
|
53 |
#include "Page.h" |
|
54 |
#include "RegularExpression.h" |
|
55 |
#include "RenderButton.h" |
|
56 |
#include "RenderFileUploadControl.h" |
|
57 |
#include "RenderImage.h" |
|
58 |
#include "RenderSlider.h" |
|
59 |
#include "RenderText.h" |
|
60 |
#include "RenderTextControlSingleLine.h" |
|
61 |
#include "RenderTheme.h" |
|
62 |
#include "TextEvent.h" |
|
63 |
#include <wtf/MathExtras.h> |
|
64 |
#include <wtf/StdLibExtras.h> |
|
65 |
||
66 |
using namespace std; |
|
67 |
||
68 |
namespace WebCore { |
|
69 |
||
70 |
using namespace HTMLNames; |
|
71 |
||
72 |
const int maxSavedResults = 256; |
|
73 |
||
74 |
HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) |
|
75 |
: HTMLTextFormControlElement(tagName, doc, f) |
|
76 |
, m_xPos(0) |
|
77 |
, m_yPos(0) |
|
78 |
, m_maxResults(-1) |
|
79 |
, m_type(TEXT) |
|
80 |
, m_checked(false) |
|
81 |
, m_defaultChecked(false) |
|
82 |
, m_useDefaultChecked(true) |
|
83 |
, m_indeterminate(false) |
|
84 |
, m_haveType(false) |
|
85 |
, m_activeSubmit(false) |
|
86 |
, m_autocomplete(Uninitialized) |
|
87 |
, m_autofilled(false) |
|
88 |
, m_inited(false) |
|
89 |
{ |
|
90 |
ASSERT(hasTagName(inputTag) || hasTagName(isindexTag)); |
|
91 |
} |
|
92 |
||
93 |
HTMLInputElement::~HTMLInputElement() |
|
94 |
{ |
|
95 |
if (needsActivationCallback()) |
|
96 |
document()->unregisterForDocumentActivationCallbacks(this); |
|
97 |
||
98 |
document()->checkedRadioButtons().removeButton(this); |
|
99 |
||
100 |
// Need to remove this from the form while it is still an HTMLInputElement, |
|
101 |
// so can't wait for the base class's destructor to do it. |
|
102 |
removeFromForm(); |
|
103 |
} |
|
104 |
||
105 |
const AtomicString& HTMLInputElement::formControlName() const |
|
106 |
{ |
|
107 |
return m_data.name(); |
|
108 |
} |
|
109 |
||
110 |
bool HTMLInputElement::autoComplete() const |
|
111 |
{ |
|
112 |
if (m_autocomplete != Uninitialized) |
|
113 |
return m_autocomplete == On; |
|
114 |
||
115 |
// Assuming we're still in a Form, respect the Form's setting |
|
116 |
if (HTMLFormElement* form = this->form()) |
|
117 |
return form->autoComplete(); |
|
118 |
||
119 |
// The default is true |
|
120 |
return true; |
|
121 |
} |
|
122 |
||
123 |
bool HTMLInputElement::valueMissing() const |
|
124 |
{ |
|
125 |
if (!isRequiredFormControl() || readOnly() || disabled()) |
|
126 |
return false; |
|
127 |
||
128 |
switch (inputType()) { |
|
129 |
case TEXT: |
|
130 |
case SEARCH: |
|
131 |
case URL: |
|
132 |
case TELEPHONE: |
|
133 |
case EMAIL: |
|
134 |
case PASSWORD: |
|
135 |
case NUMBER: |
|
136 |
case FILE: |
|
137 |
return value().isEmpty(); |
|
138 |
case CHECKBOX: |
|
139 |
return !checked(); |
|
140 |
case RADIO: |
|
141 |
return !document()->checkedRadioButtons().checkedButtonForGroup(name()); |
|
142 |
case COLOR: |
|
143 |
return false; |
|
144 |
case HIDDEN: |
|
145 |
case RANGE: |
|
146 |
case SUBMIT: |
|
147 |
case IMAGE: |
|
148 |
case RESET: |
|
149 |
case BUTTON: |
|
150 |
case ISINDEX: |
|
151 |
break; |
|
152 |
} |
|
153 |
||
154 |
ASSERT_NOT_REACHED(); |
|
155 |
return false; |
|
156 |
} |
|
157 |
||
158 |
bool HTMLInputElement::patternMismatch() const |
|
159 |
{ |
|
160 |
switch (inputType()) { |
|
161 |
case ISINDEX: |
|
162 |
case CHECKBOX: |
|
163 |
case RADIO: |
|
164 |
case SUBMIT: |
|
165 |
case RESET: |
|
166 |
case FILE: |
|
167 |
case HIDDEN: |
|
168 |
case IMAGE: |
|
169 |
case BUTTON: |
|
170 |
case RANGE: |
|
171 |
case NUMBER: |
|
172 |
case COLOR: |
|
173 |
return false; |
|
174 |
case TEXT: |
|
175 |
case SEARCH: |
|
176 |
case URL: |
|
177 |
case TELEPHONE: |
|
178 |
case EMAIL: |
|
179 |
case PASSWORD: |
|
180 |
const AtomicString& pattern = getAttribute(patternAttr); |
|
181 |
String value = this->value(); |
|
182 |
||
183 |
// Empty values can't be mismatched |
|
184 |
if (pattern.isEmpty() || value.isEmpty()) |
|
185 |
return false; |
|
186 |
||
187 |
RegularExpression patternRegExp(pattern, TextCaseSensitive); |
|
188 |
int matchLength = 0; |
|
189 |
int valueLength = value.length(); |
|
190 |
int matchOffset = patternRegExp.match(value, 0, &matchLength); |
|
191 |
||
192 |
return matchOffset != 0 || matchLength != valueLength; |
|
193 |
} |
|
194 |
||
195 |
ASSERT_NOT_REACHED(); |
|
196 |
return false; |
|
197 |
} |
|
198 |
||
199 |
bool HTMLInputElement::tooLong() const |
|
200 |
{ |
|
201 |
switch (inputType()) { |
|
202 |
case EMAIL: |
|
203 |
case PASSWORD: |
|
204 |
case SEARCH: |
|
205 |
case TELEPHONE: |
|
206 |
case TEXT: |
|
207 |
case URL: { |
|
208 |
int max = maxLength(); |
|
209 |
if (max < 0) |
|
210 |
return false; |
|
211 |
// Return false for the default value even if it is longer than maxLength. |
|
212 |
bool userEdited = !m_data.value().isNull(); |
|
213 |
if (!userEdited) |
|
214 |
return false; |
|
215 |
return value().length() > static_cast<unsigned>(max); |
|
216 |
} |
|
217 |
case BUTTON: |
|
218 |
case CHECKBOX: |
|
219 |
case COLOR: |
|
220 |
case FILE: |
|
221 |
case HIDDEN: |
|
222 |
case IMAGE: |
|
223 |
case ISINDEX: |
|
224 |
case NUMBER: |
|
225 |
case RADIO: |
|
226 |
case RANGE: |
|
227 |
case RESET: |
|
228 |
case SUBMIT: |
|
229 |
return false; |
|
230 |
} |
|
231 |
ASSERT_NOT_REACHED(); |
|
232 |
return false; |
|
233 |
} |
|
234 |
||
235 |
bool HTMLInputElement::rangeUnderflow() const |
|
236 |
{ |
|
237 |
if (inputType() == NUMBER) { |
|
238 |
double min = 0.0; |
|
239 |
double doubleValue = 0.0; |
|
240 |
if (formStringToDouble(getAttribute(minAttr), &min) && formStringToDouble(value(), &doubleValue)) |
|
241 |
return doubleValue < min; |
|
242 |
} else if (inputType() == RANGE) { |
|
243 |
double doubleValue; |
|
244 |
if (formStringToDouble(value(), &doubleValue)) |
|
245 |
return doubleValue < rangeMinimum(); |
|
246 |
} |
|
247 |
return false; |
|
248 |
} |
|
249 |
||
250 |
bool HTMLInputElement::rangeOverflow() const |
|
251 |
{ |
|
252 |
if (inputType() == NUMBER) { |
|
253 |
double max = 0.0; |
|
254 |
double doubleValue = 0.0; |
|
255 |
if (formStringToDouble(getAttribute(maxAttr), &max) && formStringToDouble(value(), &doubleValue)) |
|
256 |
return doubleValue > max; |
|
257 |
} else if (inputType() == RANGE) { |
|
258 |
double doubleValue; |
|
259 |
if (formStringToDouble(value(), &doubleValue)) |
|
260 |
return doubleValue > rangeMaximum(); |
|
261 |
} |
|
262 |
return false; |
|
263 |
} |
|
264 |
||
265 |
double HTMLInputElement::rangeMinimum() const |
|
266 |
{ |
|
267 |
ASSERT(inputType() == RANGE); |
|
268 |
// The range type's "default minimum" is 0. |
|
269 |
double min = 0.0; |
|
270 |
formStringToDouble(getAttribute(minAttr), &min); |
|
271 |
return min; |
|
272 |
} |
|
273 |
||
274 |
double HTMLInputElement::rangeMaximum() const |
|
275 |
{ |
|
276 |
ASSERT(inputType() == RANGE); |
|
277 |
// The range type's "default maximum" is 100. |
|
278 |
static const double defaultMaximum = 100.0; |
|
279 |
double max = defaultMaximum; |
|
280 |
formStringToDouble(getAttribute(maxAttr), &max); |
|
281 |
const double min = rangeMinimum(); |
|
282 |
||
283 |
if (max < min) { |
|
284 |
// A remedy for the inconsistent min/max values. |
|
285 |
// Sets the maxmimum to the default (100.0) or the minimum value. |
|
286 |
max = min < defaultMaximum ? defaultMaximum : min; |
|
287 |
} |
|
288 |
return max; |
|
289 |
} |
|
290 |
||
291 |
static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement *element) |
|
292 |
{ |
|
293 |
if (HTMLFormElement* form = element->form()) |
|
294 |
return form->checkedRadioButtons(); |
|
295 |
||
296 |
return element->document()->checkedRadioButtons(); |
|
297 |
} |
|
298 |
||
299 |
bool HTMLInputElement::isKeyboardFocusable(KeyboardEvent* event) const |
|
300 |
{ |
|
301 |
// If text fields can be focused, then they should always be keyboard focusable |
|
302 |
if (isTextField()) |
|
303 |
return HTMLFormControlElementWithState::isFocusable(); |
|
304 |
||
305 |
// If the base class says we can't be focused, then we can stop now. |
|
306 |
if (!HTMLFormControlElementWithState::isKeyboardFocusable(event)) |
|
307 |
return false; |
|
308 |
||
309 |
if (inputType() == RADIO) { |
|
310 |
||
311 |
// Never allow keyboard tabbing to leave you in the same radio group. Always |
|
312 |
// skip any other elements in the group. |
|
313 |
Node* currentFocusedNode = document()->focusedNode(); |
|
314 |
if (currentFocusedNode && currentFocusedNode->hasTagName(inputTag)) { |
|
315 |
HTMLInputElement* focusedInput = static_cast<HTMLInputElement*>(currentFocusedNode); |
|
316 |
if (focusedInput->inputType() == RADIO && focusedInput->form() == form() && |
|
317 |
focusedInput->name() == name()) |
|
318 |
return false; |
|
319 |
} |
|
320 |
||
321 |
// Allow keyboard focus if we're checked or if nothing in the group is checked. |
|
322 |
return checked() || !checkedRadioButtons(this).checkedButtonForGroup(name()); |
|
323 |
} |
|
324 |
||
325 |
return true; |
|
326 |
} |
|
327 |
||
328 |
bool HTMLInputElement::isMouseFocusable() const |
|
329 |
{ |
|
330 |
if (isTextField()) |
|
331 |
return HTMLFormControlElementWithState::isFocusable(); |
|
332 |
return HTMLFormControlElementWithState::isMouseFocusable(); |
|
333 |
} |
|
334 |
||
335 |
void HTMLInputElement::updateFocusAppearance(bool restorePreviousSelection) |
|
336 |
{ |
|
337 |
if (isTextField()) |
|
338 |
InputElement::updateFocusAppearance(m_data, this, this, restorePreviousSelection); |
|
339 |
else |
|
340 |
HTMLFormControlElementWithState::updateFocusAppearance(restorePreviousSelection); |
|
341 |
} |
|
342 |
||
343 |
void HTMLInputElement::aboutToUnload() |
|
344 |
{ |
|
345 |
InputElement::aboutToUnload(this, this); |
|
346 |
} |
|
347 |
||
348 |
bool HTMLInputElement::shouldUseInputMethod() const |
|
349 |
{ |
|
350 |
return m_type == TEXT || m_type == SEARCH || m_type == ISINDEX; |
|
351 |
} |
|
352 |
||
353 |
void HTMLInputElement::handleFocusEvent() |
|
354 |
{ |
|
355 |
InputElement::dispatchFocusEvent(this, this); |
|
356 |
||
357 |
if (isTextField()) |
|
358 |
m_autofilled = false; |
|
359 |
} |
|
360 |
||
361 |
void HTMLInputElement::handleBlurEvent() |
|
362 |
{ |
|
363 |
InputElement::dispatchBlurEvent(this, this); |
|
364 |
} |
|
365 |
||
366 |
void HTMLInputElement::setType(const String& t) |
|
367 |
{ |
|
368 |
if (t.isEmpty()) { |
|
369 |
int exccode; |
|
370 |
removeAttribute(typeAttr, exccode); |
|
371 |
} else |
|
372 |
setAttribute(typeAttr, t); |
|
373 |
} |
|
374 |
||
375 |
void HTMLInputElement::setInputType(const String& t) |
|
376 |
{ |
|
377 |
InputType newType; |
|
378 |
||
379 |
if (equalIgnoringCase(t, "password")) |
|
380 |
newType = PASSWORD; |
|
381 |
else if (equalIgnoringCase(t, "checkbox")) |
|
382 |
newType = CHECKBOX; |
|
383 |
else if (equalIgnoringCase(t, "radio")) |
|
384 |
newType = RADIO; |
|
385 |
else if (equalIgnoringCase(t, "submit")) |
|
386 |
newType = SUBMIT; |
|
387 |
else if (equalIgnoringCase(t, "reset")) |
|
388 |
newType = RESET; |
|
389 |
else if (equalIgnoringCase(t, "file")) |
|
390 |
newType = FILE; |
|
391 |
else if (equalIgnoringCase(t, "hidden")) |
|
392 |
newType = HIDDEN; |
|
393 |
else if (equalIgnoringCase(t, "image")) |
|
394 |
newType = IMAGE; |
|
395 |
else if (equalIgnoringCase(t, "button")) |
|
396 |
newType = BUTTON; |
|
397 |
else if (equalIgnoringCase(t, "khtml_isindex")) |
|
398 |
newType = ISINDEX; |
|
399 |
else if (equalIgnoringCase(t, "search")) |
|
400 |
newType = SEARCH; |
|
401 |
else if (equalIgnoringCase(t, "range")) |
|
402 |
newType = RANGE; |
|
403 |
else if (equalIgnoringCase(t, "email")) |
|
404 |
newType = EMAIL; |
|
405 |
else if (equalIgnoringCase(t, "number")) |
|
406 |
newType = NUMBER; |
|
407 |
else if (equalIgnoringCase(t, "tel")) |
|
408 |
newType = TELEPHONE; |
|
409 |
else if (equalIgnoringCase(t, "url")) |
|
410 |
newType = URL; |
|
411 |
else if (equalIgnoringCase(t, "color")) |
|
412 |
newType = COLOR; |
|
413 |
else |
|
414 |
newType = TEXT; |
|
415 |
||
416 |
// IMPORTANT: Don't allow the type to be changed to FILE after the first |
|
417 |
// type change, otherwise a JavaScript programmer would be able to set a text |
|
418 |
// field's value to something like /etc/passwd and then change it to a file field. |
|
419 |
if (inputType() != newType) { |
|
420 |
if (newType == FILE && m_haveType) |
|
421 |
// Set the attribute back to the old value. |
|
422 |
// Useful in case we were called from inside parseMappedAttribute. |
|
423 |
setAttribute(typeAttr, type()); |
|
424 |
else { |
|
425 |
checkedRadioButtons(this).removeButton(this); |
|
426 |
||
427 |
if (newType == FILE && !m_fileList) |
|
428 |
m_fileList = FileList::create(); |
|
429 |
||
430 |
bool wasAttached = attached(); |
|
431 |
if (wasAttached) |
|
432 |
detach(); |
|
433 |
||
434 |
bool didStoreValue = storesValueSeparateFromAttribute(); |
|
435 |
bool wasPasswordField = inputType() == PASSWORD; |
|
436 |
bool didRespectHeightAndWidth = respectHeightAndWidthAttrs(); |
|
437 |
m_type = newType; |
|
438 |
bool willStoreValue = storesValueSeparateFromAttribute(); |
|
439 |
bool isPasswordField = inputType() == PASSWORD; |
|
440 |
bool willRespectHeightAndWidth = respectHeightAndWidthAttrs(); |
|
441 |
||
442 |
if (didStoreValue && !willStoreValue && !m_data.value().isNull()) { |
|
443 |
setAttribute(valueAttr, m_data.value()); |
|
444 |
m_data.setValue(String()); |
|
445 |
} |
|
446 |
if (!didStoreValue && willStoreValue) |
|
447 |
m_data.setValue(sanitizeValue(getAttribute(valueAttr))); |
|
448 |
else |
|
449 |
InputElement::updateValueIfNeeded(m_data, this); |
|
450 |
||
451 |
if (wasPasswordField && !isPasswordField) |
|
452 |
unregisterForActivationCallbackIfNeeded(); |
|
453 |
else if (!wasPasswordField && isPasswordField) |
|
454 |
registerForActivationCallbackIfNeeded(); |
|
455 |
||
456 |
if (didRespectHeightAndWidth != willRespectHeightAndWidth) { |
|
457 |
NamedMappedAttrMap* map = mappedAttributes(); |
|
458 |
ASSERT(map); |
|
459 |
if (Attribute* height = map->getAttributeItem(heightAttr)) |
|
460 |
attributeChanged(height, false); |
|
461 |
if (Attribute* width = map->getAttributeItem(widthAttr)) |
|
462 |
attributeChanged(width, false); |
|
463 |
if (Attribute* align = map->getAttributeItem(alignAttr)) |
|
464 |
attributeChanged(align, false); |
|
465 |
} |
|
466 |
||
467 |
if (wasAttached) { |
|
468 |
attach(); |
|
469 |
if (document()->focusedNode() == this) |
|
470 |
updateFocusAppearance(true); |
|
471 |
} |
|
472 |
||
473 |
checkedRadioButtons(this).addButton(this); |
|
474 |
} |
|
475 |
||
476 |
InputElement::notifyFormStateChanged(this); |
|
477 |
updateValidity(); |
|
478 |
} |
|
479 |
m_haveType = true; |
|
480 |
||
481 |
if (inputType() != IMAGE && m_imageLoader) |
|
482 |
m_imageLoader.clear(); |
|
483 |
} |
|
484 |
||
485 |
const AtomicString& HTMLInputElement::formControlType() const |
|
486 |
{ |
|
487 |
// needs to be lowercase according to DOM spec |
|
488 |
switch (inputType()) { |
|
489 |
case BUTTON: { |
|
490 |
DEFINE_STATIC_LOCAL(const AtomicString, button, ("button")); |
|
491 |
return button; |
|
492 |
} |
|
493 |
case CHECKBOX: { |
|
494 |
DEFINE_STATIC_LOCAL(const AtomicString, checkbox, ("checkbox")); |
|
495 |
return checkbox; |
|
496 |
} |
|
497 |
case COLOR: { |
|
498 |
DEFINE_STATIC_LOCAL(const AtomicString, color, ("color")); |
|
499 |
return color; |
|
500 |
} |
|
501 |
case EMAIL: { |
|
502 |
DEFINE_STATIC_LOCAL(const AtomicString, email, ("email")); |
|
503 |
return email; |
|
504 |
} |
|
505 |
case FILE: { |
|
506 |
DEFINE_STATIC_LOCAL(const AtomicString, file, ("file")); |
|
507 |
return file; |
|
508 |
} |
|
509 |
case HIDDEN: { |
|
510 |
DEFINE_STATIC_LOCAL(const AtomicString, hidden, ("hidden")); |
|
511 |
return hidden; |
|
512 |
} |
|
513 |
case IMAGE: { |
|
514 |
DEFINE_STATIC_LOCAL(const AtomicString, image, ("image")); |
|
515 |
return image; |
|
516 |
} |
|
517 |
case ISINDEX: |
|
518 |
return emptyAtom; |
|
519 |
case NUMBER: { |
|
520 |
DEFINE_STATIC_LOCAL(const AtomicString, number, ("number")); |
|
521 |
return number; |
|
522 |
} |
|
523 |
case PASSWORD: { |
|
524 |
DEFINE_STATIC_LOCAL(const AtomicString, password, ("password")); |
|
525 |
return password; |
|
526 |
} |
|
527 |
case RADIO: { |
|
528 |
DEFINE_STATIC_LOCAL(const AtomicString, radio, ("radio")); |
|
529 |
return radio; |
|
530 |
} |
|
531 |
case RANGE: { |
|
532 |
DEFINE_STATIC_LOCAL(const AtomicString, range, ("range")); |
|
533 |
return range; |
|
534 |
} |
|
535 |
case RESET: { |
|
536 |
DEFINE_STATIC_LOCAL(const AtomicString, reset, ("reset")); |
|
537 |
return reset; |
|
538 |
} |
|
539 |
case SEARCH: { |
|
540 |
DEFINE_STATIC_LOCAL(const AtomicString, search, ("search")); |
|
541 |
return search; |
|
542 |
} |
|
543 |
case SUBMIT: { |
|
544 |
DEFINE_STATIC_LOCAL(const AtomicString, submit, ("submit")); |
|
545 |
return submit; |
|
546 |
} |
|
547 |
case TELEPHONE: { |
|
548 |
DEFINE_STATIC_LOCAL(const AtomicString, telephone, ("tel")); |
|
549 |
return telephone; |
|
550 |
} |
|
551 |
case TEXT: { |
|
552 |
DEFINE_STATIC_LOCAL(const AtomicString, text, ("text")); |
|
553 |
return text; |
|
554 |
} |
|
555 |
case URL: { |
|
556 |
DEFINE_STATIC_LOCAL(const AtomicString, url, ("url")); |
|
557 |
return url; |
|
558 |
} |
|
559 |
} |
|
560 |
return emptyAtom; |
|
561 |
} |
|
562 |
||
563 |
bool HTMLInputElement::saveFormControlState(String& result) const |
|
564 |
{ |
|
565 |
if (!autoComplete()) |
|
566 |
return false; |
|
567 |
||
568 |
switch (inputType()) { |
|
569 |
case BUTTON: |
|
570 |
case COLOR: |
|
571 |
case EMAIL: |
|
572 |
case FILE: |
|
573 |
case HIDDEN: |
|
574 |
case IMAGE: |
|
575 |
case ISINDEX: |
|
576 |
case NUMBER: |
|
577 |
case RANGE: |
|
578 |
case RESET: |
|
579 |
case SEARCH: |
|
580 |
case SUBMIT: |
|
581 |
case TELEPHONE: |
|
582 |
case TEXT: |
|
583 |
case URL: |
|
584 |
result = value(); |
|
585 |
return true; |
|
586 |
case CHECKBOX: |
|
587 |
case RADIO: |
|
588 |
result = checked() ? "on" : "off"; |
|
589 |
return true; |
|
590 |
case PASSWORD: |
|
591 |
return false; |
|
592 |
} |
|
593 |
ASSERT_NOT_REACHED(); |
|
594 |
return false; |
|
595 |
} |
|
596 |
||
597 |
void HTMLInputElement::restoreFormControlState(const String& state) |
|
598 |
{ |
|
599 |
ASSERT(inputType() != PASSWORD); // should never save/restore password fields |
|
600 |
switch (inputType()) { |
|
601 |
case BUTTON: |
|
602 |
case COLOR: |
|
603 |
case EMAIL: |
|
604 |
case FILE: |
|
605 |
case HIDDEN: |
|
606 |
case IMAGE: |
|
607 |
case ISINDEX: |
|
608 |
case NUMBER: |
|
609 |
case RANGE: |
|
610 |
case RESET: |
|
611 |
case SEARCH: |
|
612 |
case SUBMIT: |
|
613 |
case TELEPHONE: |
|
614 |
case TEXT: |
|
615 |
case URL: |
|
616 |
setValue(state); |
|
617 |
break; |
|
618 |
case CHECKBOX: |
|
619 |
case RADIO: |
|
620 |
setChecked(state == "on"); |
|
621 |
break; |
|
622 |
case PASSWORD: |
|
623 |
break; |
|
624 |
} |
|
625 |
} |
|
626 |
||
627 |
bool HTMLInputElement::canStartSelection() const |
|
628 |
{ |
|
629 |
if (!isTextField()) |
|
630 |
return false; |
|
631 |
return HTMLFormControlElementWithState::canStartSelection(); |
|
632 |
} |
|
633 |
||
634 |
bool HTMLInputElement::canHaveSelection() const |
|
635 |
{ |
|
636 |
return isTextField(); |
|
637 |
} |
|
638 |
||
639 |
void HTMLInputElement::accessKeyAction(bool sendToAnyElement) |
|
640 |
{ |
|
641 |
switch (inputType()) { |
|
642 |
case BUTTON: |
|
643 |
case CHECKBOX: |
|
644 |
case FILE: |
|
645 |
case IMAGE: |
|
646 |
case RADIO: |
|
647 |
case RANGE: |
|
648 |
case RESET: |
|
649 |
case SUBMIT: |
|
650 |
focus(false); |
|
651 |
// send the mouse button events iff the caller specified sendToAnyElement |
|
652 |
dispatchSimulatedClick(0, sendToAnyElement); |
|
653 |
break; |
|
654 |
case HIDDEN: |
|
655 |
// a no-op for this type |
|
656 |
break; |
|
657 |
case COLOR: |
|
658 |
case EMAIL: |
|
659 |
case ISINDEX: |
|
660 |
case NUMBER: |
|
661 |
case PASSWORD: |
|
662 |
case SEARCH: |
|
663 |
case TELEPHONE: |
|
664 |
case TEXT: |
|
665 |
case URL: |
|
666 |
// should never restore previous selection here |
|
667 |
focus(false); |
|
668 |
break; |
|
669 |
} |
|
670 |
} |
|
671 |
||
672 |
bool HTMLInputElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const |
|
673 |
{ |
|
674 |
if (((attrName == heightAttr || attrName == widthAttr) && respectHeightAndWidthAttrs()) || |
|
675 |
attrName == vspaceAttr || |
|
676 |
attrName == hspaceAttr) { |
|
677 |
result = eUniversal; |
|
678 |
return false; |
|
679 |
} |
|
680 |
||
681 |
if (attrName == alignAttr) { |
|
682 |
if (inputType() == IMAGE) { |
|
683 |
// Share with <img> since the alignment behavior is the same. |
|
684 |
result = eReplaced; |
|
685 |
return false; |
|
686 |
} |
|
687 |
} |
|
688 |
||
689 |
return HTMLElement::mapToEntry(attrName, result); |
|
690 |
} |
|
691 |
||
692 |
void HTMLInputElement::parseMappedAttribute(MappedAttribute *attr) |
|
693 |
{ |
|
694 |
if (attr->name() == nameAttr) { |
|
695 |
checkedRadioButtons(this).removeButton(this); |
|
696 |
m_data.setName(attr->value()); |
|
697 |
checkedRadioButtons(this).addButton(this); |
|
698 |
HTMLFormControlElementWithState::parseMappedAttribute(attr); |
|
699 |
} else if (attr->name() == autocompleteAttr) { |
|
700 |
if (equalIgnoringCase(attr->value(), "off")) { |
|
701 |
m_autocomplete = Off; |
|
702 |
registerForActivationCallbackIfNeeded(); |
|
703 |
} else { |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
704 |
bool needsToUnregister = m_autocomplete == Off; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
705 |
|
0 | 706 |
if (attr->isEmpty()) |
707 |
m_autocomplete = Uninitialized; |
|
708 |
else |
|
709 |
m_autocomplete = On; |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
710 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
711 |
if (needsToUnregister) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
712 |
unregisterForActivationCallbackIfNeeded(); |
0 | 713 |
} |
714 |
} else if (attr->name() == typeAttr) { |
|
715 |
setInputType(attr->value()); |
|
716 |
} else if (attr->name() == valueAttr) { |
|
717 |
// We only need to setChanged if the form is looking at the default value right now. |
|
718 |
if (m_data.value().isNull()) |
|
719 |
setNeedsStyleRecalc(); |
|
720 |
setFormControlValueMatchesRenderer(false); |
|
721 |
updateValidity(); |
|
722 |
} else if (attr->name() == checkedAttr) { |
|
723 |
m_defaultChecked = !attr->isNull(); |
|
724 |
if (m_useDefaultChecked) { |
|
725 |
setChecked(m_defaultChecked); |
|
726 |
m_useDefaultChecked = true; |
|
727 |
} |
|
728 |
updateValidity(); |
|
729 |
} else if (attr->name() == maxlengthAttr) |
|
730 |
InputElement::parseMaxLengthAttribute(m_data, this, this, attr); |
|
731 |
else if (attr->name() == sizeAttr) |
|
732 |
InputElement::parseSizeAttribute(m_data, this, attr); |
|
733 |
else if (attr->name() == altAttr) { |
|
734 |
if (renderer() && inputType() == IMAGE) |
|
735 |
toRenderImage(renderer())->updateAltText(); |
|
736 |
} else if (attr->name() == srcAttr) { |
|
737 |
if (renderer() && inputType() == IMAGE) { |
|
738 |
if (!m_imageLoader) |
|
739 |
m_imageLoader.set(new HTMLImageLoader(this)); |
|
740 |
m_imageLoader->updateFromElementIgnoringPreviousError(); |
|
741 |
} |
|
742 |
} else if (attr->name() == usemapAttr || |
|
743 |
attr->name() == accesskeyAttr) { |
|
744 |
// FIXME: ignore for the moment |
|
745 |
} else if (attr->name() == vspaceAttr) { |
|
746 |
addCSSLength(attr, CSSPropertyMarginTop, attr->value()); |
|
747 |
addCSSLength(attr, CSSPropertyMarginBottom, attr->value()); |
|
748 |
} else if (attr->name() == hspaceAttr) { |
|
749 |
addCSSLength(attr, CSSPropertyMarginLeft, attr->value()); |
|
750 |
addCSSLength(attr, CSSPropertyMarginRight, attr->value()); |
|
751 |
} else if (attr->name() == alignAttr) { |
|
752 |
if (inputType() == IMAGE) |
|
753 |
addHTMLAlignment(attr); |
|
754 |
} else if (attr->name() == widthAttr) { |
|
755 |
if (respectHeightAndWidthAttrs()) |
|
756 |
addCSSLength(attr, CSSPropertyWidth, attr->value()); |
|
757 |
} else if (attr->name() == heightAttr) { |
|
758 |
if (respectHeightAndWidthAttrs()) |
|
759 |
addCSSLength(attr, CSSPropertyHeight, attr->value()); |
|
760 |
} |
|
761 |
// Search field and slider attributes all just cause updateFromElement to be called through style |
|
762 |
// recalcing. |
|
763 |
else if (attr->name() == onsearchAttr) { |
|
764 |
setAttributeEventListener(eventNames().searchEvent, createAttributeEventListener(this, attr)); |
|
765 |
} else if (attr->name() == resultsAttr) { |
|
766 |
int oldResults = m_maxResults; |
|
767 |
m_maxResults = !attr->isNull() ? std::min(attr->value().toInt(), maxSavedResults) : -1; |
|
768 |
// FIXME: Detaching just for maxResults change is not ideal. We should figure out the right |
|
769 |
// time to relayout for this change. |
|
770 |
if (m_maxResults != oldResults && (m_maxResults <= 0 || oldResults <= 0) && attached()) { |
|
771 |
detach(); |
|
772 |
attach(); |
|
773 |
} |
|
774 |
setNeedsStyleRecalc(); |
|
775 |
} else if (attr->name() == autosaveAttr || |
|
776 |
attr->name() == incrementalAttr || |
|
777 |
attr->name() == minAttr || |
|
778 |
attr->name() == maxAttr || |
|
779 |
attr->name() == multipleAttr || |
|
780 |
attr->name() == precisionAttr) |
|
781 |
setNeedsStyleRecalc(); |
|
782 |
else if (attr->name() == patternAttr) |
|
783 |
updateValidity(); |
|
784 |
#if ENABLE(DATALIST) |
|
785 |
else if (attr->name() == listAttr) |
|
786 |
m_hasNonEmptyList = !attr->isEmpty(); |
|
787 |
// FIXME: we need to tell this change to a renderer if the attribute affects the appearance. |
|
788 |
#endif |
|
789 |
else |
|
790 |
HTMLTextFormControlElement::parseMappedAttribute(attr); |
|
791 |
} |
|
792 |
||
793 |
bool HTMLInputElement::rendererIsNeeded(RenderStyle *style) |
|
794 |
{ |
|
795 |
switch (inputType()) { |
|
796 |
case BUTTON: |
|
797 |
case CHECKBOX: |
|
798 |
case COLOR: |
|
799 |
case EMAIL: |
|
800 |
case FILE: |
|
801 |
case IMAGE: |
|
802 |
case ISINDEX: |
|
803 |
case NUMBER: |
|
804 |
case PASSWORD: |
|
805 |
case RADIO: |
|
806 |
case RANGE: |
|
807 |
case RESET: |
|
808 |
case SEARCH: |
|
809 |
case SUBMIT: |
|
810 |
case TELEPHONE: |
|
811 |
case TEXT: |
|
812 |
case URL: |
|
813 |
return HTMLFormControlElementWithState::rendererIsNeeded(style); |
|
814 |
case HIDDEN: |
|
815 |
return false; |
|
816 |
} |
|
817 |
ASSERT(false); |
|
818 |
return false; |
|
819 |
} |
|
820 |
||
821 |
RenderObject *HTMLInputElement::createRenderer(RenderArena *arena, RenderStyle *style) |
|
822 |
{ |
|
823 |
switch (inputType()) { |
|
824 |
case BUTTON: |
|
825 |
case RESET: |
|
826 |
case SUBMIT: |
|
827 |
return new (arena) RenderButton(this); |
|
828 |
case CHECKBOX: |
|
829 |
case RADIO: |
|
830 |
return RenderObject::createObject(this, style); |
|
831 |
case FILE: |
|
832 |
return new (arena) RenderFileUploadControl(this); |
|
833 |
case HIDDEN: |
|
834 |
break; |
|
835 |
case IMAGE: |
|
836 |
return new (arena) RenderImage(this); |
|
837 |
case RANGE: |
|
838 |
return new (arena) RenderSlider(this); |
|
839 |
case COLOR: |
|
840 |
case EMAIL: |
|
841 |
case ISINDEX: |
|
842 |
case NUMBER: |
|
843 |
case PASSWORD: |
|
844 |
case SEARCH: |
|
845 |
case TELEPHONE: |
|
846 |
case TEXT: |
|
847 |
case URL: |
|
848 |
return new (arena) RenderTextControlSingleLine(this, placeholderShouldBeVisible()); |
|
849 |
} |
|
850 |
ASSERT(false); |
|
851 |
return 0; |
|
852 |
} |
|
853 |
||
854 |
void HTMLInputElement::attach() |
|
855 |
{ |
|
856 |
if (!m_inited) { |
|
857 |
if (!m_haveType) |
|
858 |
setInputType(getAttribute(typeAttr)); |
|
859 |
m_inited = true; |
|
860 |
} |
|
861 |
||
862 |
HTMLFormControlElementWithState::attach(); |
|
863 |
||
864 |
if (inputType() == IMAGE) { |
|
865 |
if (!m_imageLoader) |
|
866 |
m_imageLoader.set(new HTMLImageLoader(this)); |
|
867 |
m_imageLoader->updateFromElement(); |
|
868 |
if (renderer() && m_imageLoader->haveFiredBeforeLoadEvent()) { |
|
869 |
RenderImage* imageObj = toRenderImage(renderer()); |
|
870 |
imageObj->setCachedImage(m_imageLoader->image()); |
|
871 |
||
872 |
// If we have no image at all because we have no src attribute, set |
|
873 |
// image height and width for the alt text instead. |
|
874 |
if (!m_imageLoader->image() && !imageObj->cachedImage()) |
|
875 |
imageObj->setImageSizeForAltText(); |
|
876 |
} |
|
877 |
} |
|
878 |
} |
|
879 |
||
880 |
void HTMLInputElement::detach() |
|
881 |
{ |
|
882 |
HTMLFormControlElementWithState::detach(); |
|
883 |
setFormControlValueMatchesRenderer(false); |
|
884 |
} |
|
885 |
||
886 |
String HTMLInputElement::altText() const |
|
887 |
{ |
|
888 |
// http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen |
|
889 |
// also heavily discussed by Hixie on bugzilla |
|
890 |
// note this is intentionally different to HTMLImageElement::altText() |
|
891 |
String alt = getAttribute(altAttr); |
|
892 |
// fall back to title attribute |
|
893 |
if (alt.isNull()) |
|
894 |
alt = getAttribute(titleAttr); |
|
895 |
if (alt.isNull()) |
|
896 |
alt = getAttribute(valueAttr); |
|
897 |
if (alt.isEmpty()) |
|
898 |
alt = inputElementAltText(); |
|
899 |
return alt; |
|
900 |
} |
|
901 |
||
902 |
bool HTMLInputElement::isSuccessfulSubmitButton() const |
|
903 |
{ |
|
904 |
// HTML spec says that buttons must have names to be considered successful. |
|
905 |
// However, other browsers do not impose this constraint. So we do likewise. |
|
906 |
return !disabled() && (inputType() == IMAGE || inputType() == SUBMIT); |
|
907 |
} |
|
908 |
||
909 |
bool HTMLInputElement::isActivatedSubmit() const |
|
910 |
{ |
|
911 |
return m_activeSubmit; |
|
912 |
} |
|
913 |
||
914 |
void HTMLInputElement::setActivatedSubmit(bool flag) |
|
915 |
{ |
|
916 |
m_activeSubmit = flag; |
|
917 |
} |
|
918 |
||
919 |
bool HTMLInputElement::appendFormData(FormDataList& encoding, bool multipart) |
|
920 |
{ |
|
921 |
// image generates its own names, but for other types there is no form data unless there's a name |
|
922 |
if (name().isEmpty() && inputType() != IMAGE) |
|
923 |
return false; |
|
924 |
||
925 |
switch (inputType()) { |
|
926 |
case COLOR: |
|
927 |
case EMAIL: |
|
928 |
case HIDDEN: |
|
929 |
case ISINDEX: |
|
930 |
case NUMBER: |
|
931 |
case PASSWORD: |
|
932 |
case RANGE: |
|
933 |
case SEARCH: |
|
934 |
case TELEPHONE: |
|
935 |
case TEXT: |
|
936 |
case URL: |
|
937 |
// always successful |
|
938 |
encoding.appendData(name(), value()); |
|
939 |
return true; |
|
940 |
||
941 |
case CHECKBOX: |
|
942 |
case RADIO: |
|
943 |
if (checked()) { |
|
944 |
encoding.appendData(name(), value()); |
|
945 |
return true; |
|
946 |
} |
|
947 |
break; |
|
948 |
||
949 |
case BUTTON: |
|
950 |
case RESET: |
|
951 |
// these types of buttons are never successful |
|
952 |
return false; |
|
953 |
||
954 |
case IMAGE: |
|
955 |
if (m_activeSubmit) { |
|
956 |
encoding.appendData(name().isEmpty() ? "x" : (name() + ".x"), m_xPos); |
|
957 |
encoding.appendData(name().isEmpty() ? "y" : (name() + ".y"), m_yPos); |
|
958 |
if (!name().isEmpty() && !value().isEmpty()) |
|
959 |
encoding.appendData(name(), value()); |
|
960 |
return true; |
|
961 |
} |
|
962 |
break; |
|
963 |
||
964 |
case SUBMIT: |
|
965 |
if (m_activeSubmit) { |
|
966 |
String enc_str = valueWithDefault(); |
|
967 |
encoding.appendData(name(), enc_str); |
|
968 |
return true; |
|
969 |
} |
|
970 |
break; |
|
971 |
||
972 |
case FILE: { |
|
973 |
unsigned numFiles = m_fileList->length(); |
|
974 |
if (!multipart) { |
|
975 |
// Send only the basenames. |
|
976 |
// 4.10.16.4 and 4.10.16.6 sections in HTML5. |
|
977 |
||
978 |
// Unlike the multipart case, we have no special |
|
979 |
// handling for the empty fileList because Netscape |
|
980 |
// doesn't support for non-multipart submission of |
|
981 |
// file inputs, and Firefox doesn't add "name=" query |
|
982 |
// parameter. |
|
983 |
||
984 |
for (unsigned i = 0; i < numFiles; ++i) { |
|
985 |
encoding.appendData(name(), m_fileList->item(i)->fileName()); |
|
986 |
} |
|
987 |
return true; |
|
988 |
} |
|
989 |
||
990 |
// If no filename at all is entered, return successful but empty. |
|
991 |
// Null would be more logical, but Netscape posts an empty file. Argh. |
|
992 |
if (!numFiles) { |
|
993 |
encoding.appendFile(name(), File::create("")); |
|
994 |
return true; |
|
995 |
} |
|
996 |
||
997 |
for (unsigned i = 0; i < numFiles; ++i) |
|
998 |
encoding.appendFile(name(), m_fileList->item(i)); |
|
999 |
return true; |
|
1000 |
} |
|
1001 |
} |
|
1002 |
return false; |
|
1003 |
} |
|
1004 |
||
1005 |
void HTMLInputElement::reset() |
|
1006 |
{ |
|
1007 |
if (storesValueSeparateFromAttribute()) |
|
1008 |
setValue(String()); |
|
1009 |
||
1010 |
setChecked(m_defaultChecked); |
|
1011 |
m_useDefaultChecked = true; |
|
1012 |
} |
|
1013 |
||
1014 |
void HTMLInputElement::setChecked(bool nowChecked, bool sendChangeEvent) |
|
1015 |
{ |
|
1016 |
if (checked() == nowChecked) |
|
1017 |
return; |
|
1018 |
||
1019 |
checkedRadioButtons(this).removeButton(this); |
|
1020 |
||
1021 |
m_useDefaultChecked = false; |
|
1022 |
m_checked = nowChecked; |
|
1023 |
setNeedsStyleRecalc(); |
|
1024 |
||
1025 |
checkedRadioButtons(this).addButton(this); |
|
1026 |
||
1027 |
if (renderer() && renderer()->style()->hasAppearance()) |
|
1028 |
renderer()->theme()->stateChanged(renderer(), CheckedState); |
|
1029 |
||
1030 |
// Ideally we'd do this from the render tree (matching |
|
1031 |
// RenderTextView), but it's not possible to do it at the moment |
|
1032 |
// because of the way the code is structured. |
|
1033 |
if (renderer() && AXObjectCache::accessibilityEnabled()) |
|
1034 |
renderer()->document()->axObjectCache()->postNotification(renderer(), AXObjectCache::AXCheckedStateChanged, true); |
|
1035 |
||
1036 |
// Only send a change event for items in the document (avoid firing during |
|
1037 |
// parsing) and don't send a change event for a radio button that's getting |
|
1038 |
// unchecked to match other browsers. DOM is not a useful standard for this |
|
1039 |
// because it says only to fire change events at "lose focus" time, which is |
|
1040 |
// definitely wrong in practice for these types of elements. |
|
1041 |
if (sendChangeEvent && inDocument() && (inputType() != RADIO || nowChecked)) |
|
1042 |
dispatchFormControlChangeEvent(); |
|
1043 |
} |
|
1044 |
||
1045 |
void HTMLInputElement::setIndeterminate(bool _indeterminate) |
|
1046 |
{ |
|
1047 |
// Only checkboxes honor indeterminate. |
|
1048 |
if (inputType() != CHECKBOX || indeterminate() == _indeterminate) |
|
1049 |
return; |
|
1050 |
||
1051 |
m_indeterminate = _indeterminate; |
|
1052 |
||
1053 |
setNeedsStyleRecalc(); |
|
1054 |
||
1055 |
if (renderer() && renderer()->style()->hasAppearance()) |
|
1056 |
renderer()->theme()->stateChanged(renderer(), CheckedState); |
|
1057 |
} |
|
1058 |
||
1059 |
int HTMLInputElement::size() const |
|
1060 |
{ |
|
1061 |
return m_data.size(); |
|
1062 |
} |
|
1063 |
||
1064 |
void HTMLInputElement::copyNonAttributeProperties(const Element* source) |
|
1065 |
{ |
|
1066 |
const HTMLInputElement* sourceElement = static_cast<const HTMLInputElement*>(source); |
|
1067 |
||
1068 |
m_data.setValue(sourceElement->m_data.value()); |
|
1069 |
m_checked = sourceElement->m_checked; |
|
1070 |
m_indeterminate = sourceElement->m_indeterminate; |
|
1071 |
||
1072 |
HTMLFormControlElementWithState::copyNonAttributeProperties(source); |
|
1073 |
} |
|
1074 |
||
1075 |
String HTMLInputElement::value() const |
|
1076 |
{ |
|
1077 |
// The HTML5 spec (as of the 10/24/08 working draft) says that the value attribute isn't applicable to the file upload control |
|
1078 |
// but we don't want to break existing websites, who may be relying on being able to get the file name as a value. |
|
1079 |
if (inputType() == FILE) { |
|
1080 |
if (!m_fileList->isEmpty()) |
|
1081 |
return m_fileList->item(0)->fileName(); |
|
1082 |
return String(); |
|
1083 |
} |
|
1084 |
||
1085 |
String value = m_data.value(); |
|
1086 |
if (value.isNull()) { |
|
1087 |
value = sanitizeValue(getAttribute(valueAttr)); |
|
1088 |
||
1089 |
// If no attribute exists, then just use "on" or "" based off the checked() state of the control. |
|
1090 |
if (value.isNull() && (inputType() == CHECKBOX || inputType() == RADIO)) |
|
1091 |
return checked() ? "on" : ""; |
|
1092 |
} |
|
1093 |
||
1094 |
return value; |
|
1095 |
} |
|
1096 |
||
1097 |
String HTMLInputElement::valueWithDefault() const |
|
1098 |
{ |
|
1099 |
String v = value(); |
|
1100 |
if (v.isNull()) { |
|
1101 |
switch (inputType()) { |
|
1102 |
case BUTTON: |
|
1103 |
case CHECKBOX: |
|
1104 |
case COLOR: |
|
1105 |
case EMAIL: |
|
1106 |
case FILE: |
|
1107 |
case HIDDEN: |
|
1108 |
case IMAGE: |
|
1109 |
case ISINDEX: |
|
1110 |
case NUMBER: |
|
1111 |
case PASSWORD: |
|
1112 |
case RADIO: |
|
1113 |
case RANGE: |
|
1114 |
case SEARCH: |
|
1115 |
case TELEPHONE: |
|
1116 |
case TEXT: |
|
1117 |
case URL: |
|
1118 |
break; |
|
1119 |
case RESET: |
|
1120 |
v = resetButtonDefaultLabel(); |
|
1121 |
break; |
|
1122 |
case SUBMIT: |
|
1123 |
v = submitButtonDefaultLabel(); |
|
1124 |
break; |
|
1125 |
} |
|
1126 |
} |
|
1127 |
return v; |
|
1128 |
} |
|
1129 |
||
1130 |
void HTMLInputElement::setValue(const String& value) |
|
1131 |
{ |
|
1132 |
// For security reasons, we don't allow setting the filename, but we do allow clearing it. |
|
1133 |
// The HTML5 spec (as of the 10/24/08 working draft) says that the value attribute isn't applicable to the file upload control |
|
1134 |
// but we don't want to break existing websites, who may be relying on this method to clear things. |
|
1135 |
if (inputType() == FILE && !value.isEmpty()) |
|
1136 |
return; |
|
1137 |
||
1138 |
setFormControlValueMatchesRenderer(false); |
|
1139 |
if (storesValueSeparateFromAttribute()) { |
|
1140 |
if (inputType() == FILE) |
|
1141 |
m_fileList->clear(); |
|
1142 |
else { |
|
1143 |
m_data.setValue(sanitizeValue(value)); |
|
1144 |
if (isTextField()) { |
|
1145 |
updatePlaceholderVisibility(false); |
|
1146 |
if (inDocument()) |
|
1147 |
document()->updateStyleIfNeeded(); |
|
1148 |
} |
|
1149 |
} |
|
1150 |
if (renderer()) |
|
1151 |
renderer()->updateFromElement(); |
|
1152 |
setNeedsStyleRecalc(); |
|
1153 |
} else |
|
1154 |
setAttribute(valueAttr, sanitizeValue(value)); |
|
1155 |
||
1156 |
if (isTextField()) { |
|
1157 |
unsigned max = m_data.value().length(); |
|
1158 |
if (document()->focusedNode() == this) |
|
1159 |
InputElement::updateSelectionRange(this, this, max, max); |
|
1160 |
else |
|
1161 |
cacheSelection(max, max); |
|
1162 |
} |
|
1163 |
InputElement::notifyFormStateChanged(this); |
|
1164 |
updateValidity(); |
|
1165 |
} |
|
1166 |
||
1167 |
String HTMLInputElement::placeholder() const |
|
1168 |
{ |
|
1169 |
return getAttribute(placeholderAttr).string(); |
|
1170 |
} |
|
1171 |
||
1172 |
void HTMLInputElement::setPlaceholder(const String& value) |
|
1173 |
{ |
|
1174 |
setAttribute(placeholderAttr, value); |
|
1175 |
} |
|
1176 |
||
1177 |
bool HTMLInputElement::searchEventsShouldBeDispatched() const |
|
1178 |
{ |
|
1179 |
return hasAttribute(incrementalAttr); |
|
1180 |
} |
|
1181 |
||
1182 |
void HTMLInputElement::setValueFromRenderer(const String& value) |
|
1183 |
{ |
|
1184 |
// File upload controls will always use setFileListFromRenderer. |
|
1185 |
ASSERT(inputType() != FILE); |
|
1186 |
updatePlaceholderVisibility(false); |
|
1187 |
InputElement::setValueFromRenderer(m_data, this, this, value); |
|
1188 |
updateValidity(); |
|
1189 |
} |
|
1190 |
||
1191 |
void HTMLInputElement::setFileListFromRenderer(const Vector<String>& paths) |
|
1192 |
{ |
|
1193 |
m_fileList->clear(); |
|
1194 |
int size = paths.size(); |
|
1195 |
for (int i = 0; i < size; i++) |
|
1196 |
m_fileList->append(File::create(paths[i])); |
|
1197 |
||
1198 |
setFormControlValueMatchesRenderer(true); |
|
1199 |
InputElement::notifyFormStateChanged(this); |
|
1200 |
updateValidity(); |
|
1201 |
} |
|
1202 |
||
1203 |
bool HTMLInputElement::storesValueSeparateFromAttribute() const |
|
1204 |
{ |
|
1205 |
switch (inputType()) { |
|
1206 |
case BUTTON: |
|
1207 |
case CHECKBOX: |
|
1208 |
case HIDDEN: |
|
1209 |
case IMAGE: |
|
1210 |
case RADIO: |
|
1211 |
case RESET: |
|
1212 |
case SUBMIT: |
|
1213 |
return false; |
|
1214 |
case COLOR: |
|
1215 |
case EMAIL: |
|
1216 |
case FILE: |
|
1217 |
case ISINDEX: |
|
1218 |
case NUMBER: |
|
1219 |
case PASSWORD: |
|
1220 |
case RANGE: |
|
1221 |
case SEARCH: |
|
1222 |
case TELEPHONE: |
|
1223 |
case TEXT: |
|
1224 |
case URL: |
|
1225 |
return true; |
|
1226 |
} |
|
1227 |
return false; |
|
1228 |
} |
|
1229 |
||
1230 |
void* HTMLInputElement::preDispatchEventHandler(Event *evt) |
|
1231 |
{ |
|
1232 |
// preventDefault or "return false" are used to reverse the automatic checking/selection we do here. |
|
1233 |
// This result gives us enough info to perform the "undo" in postDispatch of the action we take here. |
|
1234 |
void* result = 0; |
|
1235 |
if ((inputType() == CHECKBOX || inputType() == RADIO) && evt->isMouseEvent() |
|
1236 |
&& evt->type() == eventNames().clickEvent && static_cast<MouseEvent*>(evt)->button() == LeftButton) { |
|
1237 |
if (inputType() == CHECKBOX) { |
|
1238 |
// As a way to store the state, we return 0 if we were unchecked, 1 if we were checked, and 2 for |
|
1239 |
// indeterminate. |
|
1240 |
if (indeterminate()) { |
|
1241 |
result = (void*)0x2; |
|
1242 |
setIndeterminate(false); |
|
1243 |
} else { |
|
1244 |
if (checked()) |
|
1245 |
result = (void*)0x1; |
|
1246 |
setChecked(!checked(), true); |
|
1247 |
} |
|
1248 |
} else { |
|
1249 |
// For radio buttons, store the current selected radio object. |
|
1250 |
// We really want radio groups to end up in sane states, i.e., to have something checked. |
|
1251 |
// Therefore if nothing is currently selected, we won't allow this action to be "undone", since |
|
1252 |
// we want some object in the radio group to actually get selected. |
|
1253 |
HTMLInputElement* currRadio = checkedRadioButtons(this).checkedButtonForGroup(name()); |
|
1254 |
if (currRadio) { |
|
1255 |
// We have a radio button selected that is not us. Cache it in our result field and ref it so |
|
1256 |
// that it can't be destroyed. |
|
1257 |
currRadio->ref(); |
|
1258 |
result = currRadio; |
|
1259 |
} |
|
1260 |
setChecked(true, true); |
|
1261 |
} |
|
1262 |
} |
|
1263 |
return result; |
|
1264 |
} |
|
1265 |
||
1266 |
void HTMLInputElement::postDispatchEventHandler(Event *evt, void* data) |
|
1267 |
{ |
|
1268 |
if ((inputType() == CHECKBOX || inputType() == RADIO) && evt->isMouseEvent() |
|
1269 |
&& evt->type() == eventNames().clickEvent && static_cast<MouseEvent*>(evt)->button() == LeftButton) { |
|
1270 |
if (inputType() == CHECKBOX) { |
|
1271 |
// Reverse the checking we did in preDispatch. |
|
1272 |
if (evt->defaultPrevented() || evt->defaultHandled()) { |
|
1273 |
if (data == (void*)0x2) |
|
1274 |
setIndeterminate(true); |
|
1275 |
else |
|
1276 |
setChecked(data); |
|
1277 |
} |
|
1278 |
} else if (data) { |
|
1279 |
HTMLInputElement* input = static_cast<HTMLInputElement*>(data); |
|
1280 |
if (evt->defaultPrevented() || evt->defaultHandled()) { |
|
1281 |
// Restore the original selected radio button if possible. |
|
1282 |
// Make sure it is still a radio button and only do the restoration if it still |
|
1283 |
// belongs to our group. |
|
1284 |
||
1285 |
if (input->form() == form() && input->inputType() == RADIO && input->name() == name()) { |
|
1286 |
// Ok, the old radio button is still in our form and in our group and is still a |
|
1287 |
// radio button, so it's safe to restore selection to it. |
|
1288 |
input->setChecked(true); |
|
1289 |
} |
|
1290 |
} |
|
1291 |
input->deref(); |
|
1292 |
} |
|
1293 |
||
1294 |
// Left clicks on radio buttons and check boxes already performed default actions in preDispatchEventHandler(). |
|
1295 |
evt->setDefaultHandled(); |
|
1296 |
} |
|
1297 |
} |
|
1298 |
||
1299 |
void HTMLInputElement::defaultEventHandler(Event* evt) |
|
1300 |
{ |
|
1301 |
// FIXME: It would be better to refactor this for the different types of input element. |
|
1302 |
// Having them all in one giant function makes this hard to read, and almost all the handling is type-specific. |
|
1303 |
||
1304 |
bool clickDefaultFormButton = false; |
|
1305 |
||
1306 |
if (isTextField() && evt->type() == eventNames().textInputEvent && evt->isTextEvent() && static_cast<TextEvent*>(evt)->data() == "\n") |
|
1307 |
clickDefaultFormButton = true; |
|
1308 |
||
1309 |
if (inputType() == IMAGE && evt->isMouseEvent() && evt->type() == eventNames().clickEvent) { |
|
1310 |
// record the mouse position for when we get the DOMActivate event |
|
1311 |
MouseEvent* me = static_cast<MouseEvent*>(evt); |
|
1312 |
// FIXME: We could just call offsetX() and offsetY() on the event, |
|
1313 |
// but that's currently broken, so for now do the computation here. |
|
1314 |
if (me->isSimulated() || !renderer()) { |
|
1315 |
m_xPos = 0; |
|
1316 |
m_yPos = 0; |
|
1317 |
} else { |
|
1318 |
// FIXME: This doesn't work correctly with transforms. |
|
1319 |
// FIXME: pageX/pageY need adjusting for pageZoomFactor(). Use actualPageLocation()? |
|
1320 |
IntPoint absOffset = roundedIntPoint(renderer()->localToAbsolute()); |
|
1321 |
m_xPos = me->pageX() - absOffset.x(); |
|
1322 |
m_yPos = me->pageY() - absOffset.y(); |
|
1323 |
} |
|
1324 |
} |
|
1325 |
||
1326 |
if (isTextField() |
|
1327 |
&& evt->type() == eventNames().keydownEvent |
|
1328 |
&& evt->isKeyboardEvent() |
|
1329 |
&& focused() |
|
1330 |
&& document()->frame() |
|
1331 |
&& document()->frame()->doTextFieldCommandFromEvent(this, static_cast<KeyboardEvent*>(evt))) { |
|
1332 |
evt->setDefaultHandled(); |
|
1333 |
return; |
|
1334 |
} |
|
1335 |
||
1336 |
if (inputType() == RADIO |
|
1337 |
&& evt->isMouseEvent() |
|
1338 |
&& evt->type() == eventNames().clickEvent |
|
1339 |
&& static_cast<MouseEvent*>(evt)->button() == LeftButton) { |
|
1340 |
evt->setDefaultHandled(); |
|
1341 |
return; |
|
1342 |
} |
|
1343 |
||
1344 |
// Call the base event handler before any of our own event handling for almost all events in text fields. |
|
1345 |
// Makes editing keyboard handling take precedence over the keydown and keypress handling in this function. |
|
1346 |
bool callBaseClassEarly = isTextField() && !clickDefaultFormButton |
|
1347 |
&& (evt->type() == eventNames().keydownEvent || evt->type() == eventNames().keypressEvent); |
|
1348 |
if (callBaseClassEarly) { |
|
1349 |
HTMLFormControlElementWithState::defaultEventHandler(evt); |
|
1350 |
if (evt->defaultHandled()) |
|
1351 |
return; |
|
1352 |
} |
|
1353 |
||
1354 |
// DOMActivate events cause the input to be "activated" - in the case of image and submit inputs, this means |
|
1355 |
// actually submitting the form. For reset inputs, the form is reset. These events are sent when the user clicks |
|
1356 |
// on the element, or presses enter while it is the active element. JavaScript code wishing to activate the element |
|
1357 |
// must dispatch a DOMActivate event - a click event will not do the job. |
|
1358 |
if (evt->type() == eventNames().DOMActivateEvent && !disabled()) { |
|
1359 |
if (inputType() == IMAGE || inputType() == SUBMIT || inputType() == RESET) { |
|
1360 |
if (!form()) |
|
1361 |
return; |
|
1362 |
if (inputType() == RESET) |
|
1363 |
form()->reset(); |
|
1364 |
else { |
|
1365 |
m_activeSubmit = true; |
|
1366 |
// FIXME: Would be cleaner to get m_xPos and m_yPos out of the underlying mouse |
|
1367 |
// event (if any) here instead of relying on the variables set above when |
|
1368 |
// processing the click event. Even better, appendFormData could pass the |
|
1369 |
// event in, and then we could get rid of m_xPos and m_yPos altogether! |
|
1370 |
if (!form()->prepareSubmit(evt)) { |
|
1371 |
m_xPos = 0; |
|
1372 |
m_yPos = 0; |
|
1373 |
} |
|
1374 |
m_activeSubmit = false; |
|
1375 |
} |
|
1376 |
} else if (inputType() == FILE && renderer()) |
|
1377 |
toRenderFileUploadControl(renderer())->click(); |
|
1378 |
} |
|
1379 |
||
1380 |
// Use key press event here since sending simulated mouse events |
|
1381 |
// on key down blocks the proper sending of the key press event. |
|
1382 |
if (evt->type() == eventNames().keypressEvent && evt->isKeyboardEvent()) { |
|
1383 |
bool clickElement = false; |
|
1384 |
||
1385 |
int charCode = static_cast<KeyboardEvent*>(evt)->charCode(); |
|
1386 |
||
1387 |
if (charCode == '\r') { |
|
1388 |
switch (inputType()) { |
|
1389 |
case CHECKBOX: |
|
1390 |
case COLOR: |
|
1391 |
case EMAIL: |
|
1392 |
case HIDDEN: |
|
1393 |
case ISINDEX: |
|
1394 |
case NUMBER: |
|
1395 |
case PASSWORD: |
|
1396 |
case RANGE: |
|
1397 |
case SEARCH: |
|
1398 |
case TELEPHONE: |
|
1399 |
case TEXT: |
|
1400 |
case URL: |
|
1401 |
// Simulate mouse click on the default form button for enter for these types of elements. |
|
1402 |
clickDefaultFormButton = true; |
|
1403 |
break; |
|
1404 |
case BUTTON: |
|
1405 |
case FILE: |
|
1406 |
case IMAGE: |
|
1407 |
case RESET: |
|
1408 |
case SUBMIT: |
|
1409 |
// Simulate mouse click for enter for these types of elements. |
|
1410 |
clickElement = true; |
|
1411 |
break; |
|
1412 |
case RADIO: |
|
1413 |
break; // Don't do anything for enter on a radio button. |
|
1414 |
} |
|
1415 |
} else if (charCode == ' ') { |
|
1416 |
switch (inputType()) { |
|
1417 |
case BUTTON: |
|
1418 |
case CHECKBOX: |
|
1419 |
case FILE: |
|
1420 |
case IMAGE: |
|
1421 |
case RESET: |
|
1422 |
case SUBMIT: |
|
1423 |
case RADIO: |
|
1424 |
// Prevent scrolling down the page. |
|
1425 |
evt->setDefaultHandled(); |
|
1426 |
return; |
|
1427 |
default: |
|
1428 |
break; |
|
1429 |
} |
|
1430 |
} |
|
1431 |
||
1432 |
if (clickElement) { |
|
1433 |
dispatchSimulatedClick(evt); |
|
1434 |
evt->setDefaultHandled(); |
|
1435 |
return; |
|
1436 |
} |
|
1437 |
} |
|
1438 |
||
1439 |
if (evt->type() == eventNames().keydownEvent && evt->isKeyboardEvent()) { |
|
1440 |
String key = static_cast<KeyboardEvent*>(evt)->keyIdentifier(); |
|
1441 |
||
1442 |
if (key == "U+0020") { |
|
1443 |
switch (inputType()) { |
|
1444 |
case BUTTON: |
|
1445 |
case CHECKBOX: |
|
1446 |
case FILE: |
|
1447 |
case IMAGE: |
|
1448 |
case RESET: |
|
1449 |
case SUBMIT: |
|
1450 |
case RADIO: |
|
1451 |
setActive(true, true); |
|
1452 |
// No setDefaultHandled(), because IE dispatches a keypress in this case |
|
1453 |
// and the caller will only dispatch a keypress if we don't call setDefaultHandled. |
|
1454 |
return; |
|
1455 |
default: |
|
1456 |
break; |
|
1457 |
} |
|
1458 |
} |
|
1459 |
||
1460 |
if (inputType() == RADIO && (key == "Up" || key == "Down" || key == "Left" || key == "Right")) { |
|
1461 |
// Left and up mean "previous radio button". |
|
1462 |
// Right and down mean "next radio button". |
|
1463 |
// Tested in WinIE, and even for RTL, left still means previous radio button (and so moves |
|
1464 |
// to the right). Seems strange, but we'll match it. |
|
1465 |
bool forward = (key == "Down" || key == "Right"); |
|
1466 |
||
1467 |
// We can only stay within the form's children if the form hasn't been demoted to a leaf because |
|
1468 |
// of malformed HTML. |
|
1469 |
Node* n = this; |
|
1470 |
while ((n = (forward ? n->traverseNextNode() : n->traversePreviousNode()))) { |
|
1471 |
// Once we encounter a form element, we know we're through. |
|
1472 |
if (n->hasTagName(formTag)) |
|
1473 |
break; |
|
1474 |
||
1475 |
// Look for more radio buttons. |
|
1476 |
if (n->hasTagName(inputTag)) { |
|
1477 |
HTMLInputElement* elt = static_cast<HTMLInputElement*>(n); |
|
1478 |
if (elt->form() != form()) |
|
1479 |
break; |
|
1480 |
if (n->hasTagName(inputTag)) { |
|
1481 |
HTMLInputElement* inputElt = static_cast<HTMLInputElement*>(n); |
|
1482 |
if (inputElt->inputType() == RADIO && inputElt->name() == name() && inputElt->isFocusable()) { |
|
1483 |
inputElt->setChecked(true); |
|
1484 |
document()->setFocusedNode(inputElt); |
|
1485 |
inputElt->dispatchSimulatedClick(evt, false, false); |
|
1486 |
evt->setDefaultHandled(); |
|
1487 |
break; |
|
1488 |
} |
|
1489 |
} |
|
1490 |
} |
|
1491 |
} |
|
1492 |
} |
|
1493 |
} |
|
1494 |
||
1495 |
if (evt->type() == eventNames().keyupEvent && evt->isKeyboardEvent()) { |
|
1496 |
bool clickElement = false; |
|
1497 |
||
1498 |
String key = static_cast<KeyboardEvent*>(evt)->keyIdentifier(); |
|
1499 |
||
1500 |
if (key == "U+0020") { |
|
1501 |
switch (inputType()) { |
|
1502 |
case BUTTON: |
|
1503 |
case CHECKBOX: |
|
1504 |
case FILE: |
|
1505 |
case IMAGE: |
|
1506 |
case RESET: |
|
1507 |
case SUBMIT: |
|
1508 |
// Simulate mouse click for spacebar for these types of elements. |
|
1509 |
// The AppKit already does this for some, but not all, of them. |
|
1510 |
clickElement = true; |
|
1511 |
break; |
|
1512 |
case RADIO: |
|
1513 |
// If an unselected radio is tabbed into (because the entire group has nothing |
|
1514 |
// checked, or because of some explicit .focus() call), then allow space to check it. |
|
1515 |
if (!checked()) |
|
1516 |
clickElement = true; |
|
1517 |
break; |
|
1518 |
case COLOR: |
|
1519 |
case EMAIL: |
|
1520 |
case HIDDEN: |
|
1521 |
case ISINDEX: |
|
1522 |
case NUMBER: |
|
1523 |
case PASSWORD: |
|
1524 |
case RANGE: |
|
1525 |
case SEARCH: |
|
1526 |
case TELEPHONE: |
|
1527 |
case TEXT: |
|
1528 |
case URL: |
|
1529 |
break; |
|
1530 |
} |
|
1531 |
} |
|
1532 |
||
1533 |
if (clickElement) { |
|
1534 |
if (active()) |
|
1535 |
dispatchSimulatedClick(evt); |
|
1536 |
evt->setDefaultHandled(); |
|
1537 |
return; |
|
1538 |
} |
|
1539 |
} |
|
1540 |
||
1541 |
if (clickDefaultFormButton) { |
|
1542 |
if (isSearchField()) { |
|
1543 |
addSearchResult(); |
|
1544 |
onSearch(); |
|
1545 |
} |
|
1546 |
// Fire onChange for text fields. |
|
1547 |
RenderObject* r = renderer(); |
|
1548 |
if (r && r->isTextField() && toRenderTextControl(r)->isEdited()) { |
|
1549 |
dispatchFormControlChangeEvent(); |
|
1550 |
// Refetch the renderer since arbitrary JS code run during onchange can do anything, including destroying it. |
|
1551 |
r = renderer(); |
|
1552 |
if (r && r->isTextField()) |
|
1553 |
toRenderTextControl(r)->setEdited(false); |
|
1554 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1555 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1556 |
RefPtr<HTMLFormElement> formForSubmission = form(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1557 |
// If there is no form and the element is an <isindex>, then create a temporary form just to be used for submission. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1558 |
if (!formForSubmission && inputType() == ISINDEX) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1559 |
formForSubmission = createTemporaryFormForIsIndex(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1560 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1561 |
// Form may never have been present, or may have been destroyed by code responding to the change event. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1562 |
if (formForSubmission) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1563 |
formForSubmission->submitClick(evt); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1564 |
|
0 | 1565 |
evt->setDefaultHandled(); |
1566 |
return; |
|
1567 |
} |
|
1568 |
||
1569 |
if (evt->isBeforeTextInsertedEvent()) |
|
1570 |
InputElement::handleBeforeTextInsertedEvent(m_data, this, this, evt); |
|
1571 |
||
1572 |
if (isTextField() && renderer() && (evt->isMouseEvent() || evt->isDragEvent() || evt->isWheelEvent() || evt->type() == eventNames().blurEvent || evt->type() == eventNames().focusEvent)) |
|
1573 |
toRenderTextControlSingleLine(renderer())->forwardEvent(evt); |
|
1574 |
||
1575 |
if (inputType() == RANGE && renderer() && (evt->isMouseEvent() || evt->isDragEvent() || evt->isWheelEvent())) |
|
1576 |
toRenderSlider(renderer())->forwardEvent(evt); |
|
1577 |
||
1578 |
if (!callBaseClassEarly && !evt->defaultHandled()) |
|
1579 |
HTMLFormControlElementWithState::defaultEventHandler(evt); |
|
1580 |
} |
|
1581 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1582 |
PassRefPtr<HTMLFormElement> HTMLInputElement::createTemporaryFormForIsIndex() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1583 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1584 |
RefPtr<HTMLFormElement> form = new HTMLFormElement(formTag, document()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1585 |
form->registerFormElement(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1586 |
form->setMethod("GET"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1587 |
if (!document()->baseURL().isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1588 |
// We treat the href property of the <base> element as the form action, as per section 7.5 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1589 |
// "Queries and Indexes" of the HTML 2.0 spec. <http://www.w3.org/MarkUp/html-spec/html-spec_7.html#SEC7.5>. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1590 |
form->setAction(document()->baseURL().string()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1591 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1592 |
return form.release(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1593 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1594 |
|
0 | 1595 |
bool HTMLInputElement::isURLAttribute(Attribute *attr) const |
1596 |
{ |
|
1597 |
return (attr->name() == srcAttr); |
|
1598 |
} |
|
1599 |
||
1600 |
String HTMLInputElement::defaultValue() const |
|
1601 |
{ |
|
1602 |
return getAttribute(valueAttr); |
|
1603 |
} |
|
1604 |
||
1605 |
void HTMLInputElement::setDefaultValue(const String &value) |
|
1606 |
{ |
|
1607 |
setAttribute(valueAttr, value); |
|
1608 |
} |
|
1609 |
||
1610 |
bool HTMLInputElement::defaultChecked() const |
|
1611 |
{ |
|
1612 |
return !getAttribute(checkedAttr).isNull(); |
|
1613 |
} |
|
1614 |
||
1615 |
void HTMLInputElement::setDefaultChecked(bool defaultChecked) |
|
1616 |
{ |
|
1617 |
setAttribute(checkedAttr, defaultChecked ? "" : 0); |
|
1618 |
} |
|
1619 |
||
1620 |
void HTMLInputElement::setDefaultName(const AtomicString& name) |
|
1621 |
{ |
|
1622 |
m_data.setName(name); |
|
1623 |
} |
|
1624 |
||
1625 |
String HTMLInputElement::accept() const |
|
1626 |
{ |
|
1627 |
return getAttribute(acceptAttr); |
|
1628 |
} |
|
1629 |
||
1630 |
void HTMLInputElement::setAccept(const String &value) |
|
1631 |
{ |
|
1632 |
setAttribute(acceptAttr, value); |
|
1633 |
} |
|
1634 |
||
1635 |
String HTMLInputElement::accessKey() const |
|
1636 |
{ |
|
1637 |
return getAttribute(accesskeyAttr); |
|
1638 |
} |
|
1639 |
||
1640 |
void HTMLInputElement::setAccessKey(const String &value) |
|
1641 |
{ |
|
1642 |
setAttribute(accesskeyAttr, value); |
|
1643 |
} |
|
1644 |
||
1645 |
String HTMLInputElement::align() const |
|
1646 |
{ |
|
1647 |
return getAttribute(alignAttr); |
|
1648 |
} |
|
1649 |
||
1650 |
void HTMLInputElement::setAlign(const String &value) |
|
1651 |
{ |
|
1652 |
setAttribute(alignAttr, value); |
|
1653 |
} |
|
1654 |
||
1655 |
String HTMLInputElement::alt() const |
|
1656 |
{ |
|
1657 |
return getAttribute(altAttr); |
|
1658 |
} |
|
1659 |
||
1660 |
void HTMLInputElement::setAlt(const String &value) |
|
1661 |
{ |
|
1662 |
setAttribute(altAttr, value); |
|
1663 |
} |
|
1664 |
||
1665 |
int HTMLInputElement::maxLength() const |
|
1666 |
{ |
|
1667 |
return m_data.maxLength(); |
|
1668 |
} |
|
1669 |
||
1670 |
void HTMLInputElement::setMaxLength(int maxLength, ExceptionCode& ec) |
|
1671 |
{ |
|
1672 |
if (maxLength < 0) |
|
1673 |
ec = INDEX_SIZE_ERR; |
|
1674 |
else |
|
1675 |
setAttribute(maxlengthAttr, String::number(maxLength)); |
|
1676 |
} |
|
1677 |
||
1678 |
bool HTMLInputElement::multiple() const |
|
1679 |
{ |
|
1680 |
return !getAttribute(multipleAttr).isNull(); |
|
1681 |
} |
|
1682 |
||
1683 |
void HTMLInputElement::setMultiple(bool multiple) |
|
1684 |
{ |
|
1685 |
setAttribute(multipleAttr, multiple ? "" : 0); |
|
1686 |
} |
|
1687 |
||
1688 |
void HTMLInputElement::setSize(unsigned _size) |
|
1689 |
{ |
|
1690 |
setAttribute(sizeAttr, String::number(_size)); |
|
1691 |
} |
|
1692 |
||
1693 |
KURL HTMLInputElement::src() const |
|
1694 |
{ |
|
1695 |
return document()->completeURL(getAttribute(srcAttr)); |
|
1696 |
} |
|
1697 |
||
1698 |
void HTMLInputElement::setSrc(const String &value) |
|
1699 |
{ |
|
1700 |
setAttribute(srcAttr, value); |
|
1701 |
} |
|
1702 |
||
1703 |
String HTMLInputElement::useMap() const |
|
1704 |
{ |
|
1705 |
return getAttribute(usemapAttr); |
|
1706 |
} |
|
1707 |
||
1708 |
void HTMLInputElement::setUseMap(const String &value) |
|
1709 |
{ |
|
1710 |
setAttribute(usemapAttr, value); |
|
1711 |
} |
|
1712 |
||
1713 |
void HTMLInputElement::setAutofilled(bool b) |
|
1714 |
{ |
|
1715 |
if (b == m_autofilled) |
|
1716 |
return; |
|
1717 |
||
1718 |
m_autofilled = b; |
|
1719 |
setNeedsStyleRecalc(); |
|
1720 |
} |
|
1721 |
||
1722 |
FileList* HTMLInputElement::files() |
|
1723 |
{ |
|
1724 |
if (inputType() != FILE) |
|
1725 |
return 0; |
|
1726 |
return m_fileList.get(); |
|
1727 |
} |
|
1728 |
||
1729 |
String HTMLInputElement::sanitizeValue(const String& proposedValue) const |
|
1730 |
{ |
|
1731 |
if (isTextField()) |
|
1732 |
return InputElement::sanitizeValue(this, proposedValue); |
|
1733 |
return proposedValue; |
|
1734 |
} |
|
1735 |
||
1736 |
bool HTMLInputElement::needsActivationCallback() |
|
1737 |
{ |
|
1738 |
return inputType() == PASSWORD || m_autocomplete == Off; |
|
1739 |
} |
|
1740 |
||
1741 |
void HTMLInputElement::registerForActivationCallbackIfNeeded() |
|
1742 |
{ |
|
1743 |
if (needsActivationCallback()) |
|
1744 |
document()->registerForDocumentActivationCallbacks(this); |
|
1745 |
} |
|
1746 |
||
1747 |
void HTMLInputElement::unregisterForActivationCallbackIfNeeded() |
|
1748 |
{ |
|
1749 |
if (!needsActivationCallback()) |
|
1750 |
document()->unregisterForDocumentActivationCallbacks(this); |
|
1751 |
} |
|
1752 |
||
1753 |
bool HTMLInputElement::isRequiredFormControl() const |
|
1754 |
{ |
|
1755 |
if (!required()) |
|
1756 |
return false; |
|
1757 |
||
1758 |
switch (inputType()) { |
|
1759 |
case TEXT: |
|
1760 |
case SEARCH: |
|
1761 |
case URL: |
|
1762 |
case TELEPHONE: |
|
1763 |
case EMAIL: |
|
1764 |
case PASSWORD: |
|
1765 |
case NUMBER: |
|
1766 |
case CHECKBOX: |
|
1767 |
case RADIO: |
|
1768 |
case FILE: |
|
1769 |
return true; |
|
1770 |
case HIDDEN: |
|
1771 |
case RANGE: |
|
1772 |
case SUBMIT: |
|
1773 |
case IMAGE: |
|
1774 |
case RESET: |
|
1775 |
case BUTTON: |
|
1776 |
case COLOR: |
|
1777 |
case ISINDEX: |
|
1778 |
return false; |
|
1779 |
} |
|
1780 |
||
1781 |
ASSERT_NOT_REACHED(); |
|
1782 |
return false; |
|
1783 |
} |
|
1784 |
||
1785 |
void HTMLInputElement::cacheSelection(int start, int end) |
|
1786 |
{ |
|
1787 |
m_data.setCachedSelectionStart(start); |
|
1788 |
m_data.setCachedSelectionEnd(end); |
|
1789 |
} |
|
1790 |
||
1791 |
void HTMLInputElement::addSearchResult() |
|
1792 |
{ |
|
1793 |
ASSERT(isSearchField()); |
|
1794 |
if (renderer()) |
|
1795 |
toRenderTextControlSingleLine(renderer())->addSearchResult(); |
|
1796 |
} |
|
1797 |
||
1798 |
void HTMLInputElement::onSearch() |
|
1799 |
{ |
|
1800 |
ASSERT(isSearchField()); |
|
1801 |
if (renderer()) |
|
1802 |
toRenderTextControlSingleLine(renderer())->stopSearchEventTimer(); |
|
1803 |
dispatchEvent(Event::create(eventNames().searchEvent, true, false)); |
|
1804 |
} |
|
1805 |
||
1806 |
void HTMLInputElement::documentDidBecomeActive() |
|
1807 |
{ |
|
1808 |
ASSERT(needsActivationCallback()); |
|
1809 |
reset(); |
|
1810 |
} |
|
1811 |
||
1812 |
void HTMLInputElement::willMoveToNewOwnerDocument() |
|
1813 |
{ |
|
1814 |
// Always unregister for cache callbacks when leaving a document, even if we would otherwise like to be registered |
|
1815 |
if (needsActivationCallback()) |
|
1816 |
document()->unregisterForDocumentActivationCallbacks(this); |
|
1817 |
||
1818 |
document()->checkedRadioButtons().removeButton(this); |
|
1819 |
||
1820 |
HTMLFormControlElementWithState::willMoveToNewOwnerDocument(); |
|
1821 |
} |
|
1822 |
||
1823 |
void HTMLInputElement::didMoveToNewOwnerDocument() |
|
1824 |
{ |
|
1825 |
registerForActivationCallbackIfNeeded(); |
|
1826 |
||
1827 |
HTMLFormControlElementWithState::didMoveToNewOwnerDocument(); |
|
1828 |
} |
|
1829 |
||
1830 |
void HTMLInputElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const |
|
1831 |
{ |
|
1832 |
HTMLFormControlElementWithState::addSubresourceAttributeURLs(urls); |
|
1833 |
||
1834 |
addSubresourceURL(urls, src()); |
|
1835 |
} |
|
1836 |
||
1837 |
bool HTMLInputElement::willValidate() const |
|
1838 |
{ |
|
1839 |
// FIXME: This shall check for new WF2 input types too |
|
1840 |
return HTMLFormControlElementWithState::willValidate() && inputType() != HIDDEN && |
|
1841 |
inputType() != BUTTON && inputType() != RESET; |
|
1842 |
} |
|
1843 |
||
1844 |
bool HTMLInputElement::formStringToDouble(const String& src, double* out) |
|
1845 |
{ |
|
1846 |
// See HTML5 2.4.4.3 `Real numbers.' |
|
1847 |
||
1848 |
if (src.isEmpty()) |
|
1849 |
return false; |
|
1850 |
// String::toDouble() accepts leading + \t \n \v \f \r and SPACE, which are invalid in HTML5. |
|
1851 |
// So, check the first character. |
|
1852 |
if (src[0] != '-' && (src[0] < '0' || src[0] > '9')) |
|
1853 |
return false; |
|
1854 |
||
1855 |
bool valid = false; |
|
1856 |
double value = src.toDouble(&valid); |
|
1857 |
if (!valid) |
|
1858 |
return false; |
|
1859 |
// NaN and Infinity are not valid numbers according to the standard. |
|
1860 |
if (isnan(value) || isinf(value)) |
|
1861 |
return false; |
|
1862 |
if (out) |
|
1863 |
*out = value; |
|
1864 |
return true; |
|
1865 |
} |
|
1866 |
||
1867 |
#if ENABLE(DATALIST) |
|
1868 |
HTMLElement* HTMLInputElement::list() const |
|
1869 |
{ |
|
1870 |
return dataList(); |
|
1871 |
} |
|
1872 |
||
1873 |
HTMLDataListElement* HTMLInputElement::dataList() const |
|
1874 |
{ |
|
1875 |
if (!m_hasNonEmptyList) |
|
1876 |
return 0; |
|
1877 |
||
1878 |
switch (inputType()) { |
|
1879 |
case TEXT: |
|
1880 |
case SEARCH: |
|
1881 |
case URL: |
|
1882 |
case TELEPHONE: |
|
1883 |
case EMAIL: |
|
1884 |
case NUMBER: |
|
1885 |
case RANGE: |
|
1886 |
case COLOR: { |
|
1887 |
Element* element = document()->getElementById(getAttribute(listAttr)); |
|
1888 |
if (element && element->hasTagName(datalistTag)) |
|
1889 |
return static_cast<HTMLDataListElement*>(element); |
|
1890 |
break; |
|
1891 |
} |
|
1892 |
case HIDDEN: |
|
1893 |
case PASSWORD: |
|
1894 |
case CHECKBOX: |
|
1895 |
case RADIO: |
|
1896 |
case FILE: |
|
1897 |
case SUBMIT: |
|
1898 |
case IMAGE: |
|
1899 |
case RESET: |
|
1900 |
case BUTTON: |
|
1901 |
case ISINDEX: |
|
1902 |
break; |
|
1903 |
} |
|
1904 |
return 0; |
|
1905 |
} |
|
1906 |
||
1907 |
HTMLOptionElement* HTMLInputElement::selectedOption() const |
|
1908 |
{ |
|
1909 |
String currentValue = value(); |
|
1910 |
// The empty value never matches to a datalist option because it |
|
1911 |
// doesn't represent a suggestion according to the standard. |
|
1912 |
if (currentValue.isEmpty()) |
|
1913 |
return 0; |
|
1914 |
||
1915 |
HTMLDataListElement* sourceElement = dataList(); |
|
1916 |
if (!sourceElement) |
|
1917 |
return 0; |
|
1918 |
RefPtr<HTMLCollection> options = sourceElement->options(); |
|
1919 |
for (unsigned i = 0; options && i < options->length(); ++i) { |
|
1920 |
HTMLOptionElement* option = static_cast<HTMLOptionElement*>(options->item(i)); |
|
1921 |
if (!option->disabled() && currentValue == option->value()) |
|
1922 |
return option; |
|
1923 |
} |
|
1924 |
return 0; |
|
1925 |
} |
|
1926 |
#endif // ENABLE(DATALIST) |
|
1927 |
||
1928 |
} // namespace |