author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 0 | 1918ee327afb |
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, 2009 Apple Inc. All rights reserved. |
|
6 |
* (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
|
7 |
* |
|
8 |
* This library is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU Library General Public |
|
10 |
* License as published by the Free Software Foundation; either |
|
11 |
* version 2 of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This library is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
* Library General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU Library General Public License |
|
19 |
* along with this library; see the file COPYING.LIB. If not, write to |
|
20 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
21 |
* Boston, MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "config.h" |
|
26 |
#include "HTMLFormElement.h" |
|
27 |
||
28 |
#include "CSSHelper.h" |
|
29 |
#include "ChromeClient.h" |
|
30 |
#include "Document.h" |
|
31 |
#include "Event.h" |
|
32 |
#include "EventNames.h" |
|
33 |
#include "FileList.h" |
|
34 |
#include "FileSystem.h" |
|
35 |
#include "FormData.h" |
|
36 |
#include "FormDataList.h" |
|
37 |
#include "FormState.h" |
|
38 |
#include "Frame.h" |
|
39 |
#include "FrameLoader.h" |
|
40 |
#include "HTMLDocument.h" |
|
41 |
#include "HTMLFormCollection.h" |
|
42 |
#include "HTMLImageElement.h" |
|
43 |
#include "HTMLInputElement.h" |
|
44 |
#include "HTMLNames.h" |
|
45 |
#include "ScriptEventListener.h" |
|
46 |
#include "MIMETypeRegistry.h" |
|
47 |
#include "MappedAttribute.h" |
|
48 |
#include "Page.h" |
|
49 |
#include "RenderTextControl.h" |
|
50 |
#include "ValidityState.h" |
|
51 |
#include <limits> |
|
52 |
#include <wtf/CurrentTime.h> |
|
53 |
#include <wtf/RandomNumber.h> |
|
54 |
||
55 |
#if PLATFORM(WX) |
|
56 |
#include <wx/defs.h> |
|
57 |
#include <wx/filename.h> |
|
58 |
#endif |
|
59 |
||
60 |
using namespace std; |
|
61 |
||
62 |
namespace WebCore { |
|
63 |
||
64 |
using namespace HTMLNames; |
|
65 |
||
66 |
static int64_t generateFormDataIdentifier() |
|
67 |
{ |
|
68 |
// Initialize to the current time to reduce the likelihood of generating |
|
69 |
// identifiers that overlap with those from past/future browser sessions. |
|
70 |
static int64_t nextIdentifier = static_cast<int64_t>(currentTime() * 1000000.0); |
|
71 |
return ++nextIdentifier; |
|
72 |
} |
|
73 |
||
74 |
HTMLFormElement::HTMLFormElement(const QualifiedName& tagName, Document* doc) |
|
75 |
: HTMLElement(tagName, doc) |
|
76 |
, m_elementAliases(0) |
|
77 |
, collectionInfo(0) |
|
78 |
, m_autocomplete(true) |
|
79 |
, m_insubmit(false) |
|
80 |
, m_doingsubmit(false) |
|
81 |
, m_inreset(false) |
|
82 |
, m_malformed(false) |
|
83 |
, m_demoted(false) |
|
84 |
{ |
|
85 |
ASSERT(hasTagName(formTag)); |
|
86 |
} |
|
87 |
||
88 |
HTMLFormElement::~HTMLFormElement() |
|
89 |
{ |
|
90 |
if (!m_autocomplete) |
|
91 |
document()->unregisterForDocumentActivationCallbacks(this); |
|
92 |
||
93 |
delete m_elementAliases; |
|
94 |
delete collectionInfo; |
|
95 |
||
96 |
for (unsigned i = 0; i < formElements.size(); ++i) |
|
97 |
formElements[i]->formDestroyed(); |
|
98 |
for (unsigned i = 0; i < imgElements.size(); ++i) |
|
99 |
imgElements[i]->m_form = 0; |
|
100 |
} |
|
101 |
||
102 |
bool HTMLFormElement::formWouldHaveSecureSubmission(const String& url) |
|
103 |
{ |
|
104 |
return document()->completeURL(url).protocolIs("https"); |
|
105 |
} |
|
106 |
||
107 |
void HTMLFormElement::attach() |
|
108 |
{ |
|
109 |
HTMLElement::attach(); |
|
110 |
} |
|
111 |
||
112 |
bool HTMLFormElement::rendererIsNeeded(RenderStyle* style) |
|
113 |
{ |
|
114 |
if (!isDemoted()) |
|
115 |
return HTMLElement::rendererIsNeeded(style); |
|
116 |
||
117 |
Node* node = parentNode(); |
|
118 |
RenderObject* parentRenderer = node->renderer(); |
|
119 |
bool parentIsTableElementPart = (parentRenderer->isTable() && node->hasTagName(tableTag)) |
|
120 |
|| (parentRenderer->isTableRow() && node->hasTagName(trTag)) |
|
121 |
|| (parentRenderer->isTableSection() && node->hasTagName(tbodyTag)) |
|
122 |
|| (parentRenderer->isTableCol() && node->hasTagName(colTag)) |
|
123 |
|| (parentRenderer->isTableCell() && node->hasTagName(trTag)); |
|
124 |
||
125 |
if (!parentIsTableElementPart) |
|
126 |
return true; |
|
127 |
||
128 |
EDisplay display = style->display(); |
|
129 |
bool formIsTablePart = display == TABLE || display == INLINE_TABLE || display == TABLE_ROW_GROUP |
|
130 |
|| display == TABLE_HEADER_GROUP || display == TABLE_FOOTER_GROUP || display == TABLE_ROW |
|
131 |
|| display == TABLE_COLUMN_GROUP || display == TABLE_COLUMN || display == TABLE_CELL |
|
132 |
|| display == TABLE_CAPTION; |
|
133 |
||
134 |
return formIsTablePart; |
|
135 |
} |
|
136 |
||
137 |
void HTMLFormElement::insertedIntoDocument() |
|
138 |
{ |
|
139 |
if (document()->isHTMLDocument()) |
|
140 |
static_cast<HTMLDocument*>(document())->addNamedItem(m_name); |
|
141 |
||
142 |
HTMLElement::insertedIntoDocument(); |
|
143 |
} |
|
144 |
||
145 |
void HTMLFormElement::removedFromDocument() |
|
146 |
{ |
|
147 |
if (document()->isHTMLDocument()) |
|
148 |
static_cast<HTMLDocument*>(document())->removeNamedItem(m_name); |
|
149 |
||
150 |
HTMLElement::removedFromDocument(); |
|
151 |
} |
|
152 |
||
153 |
void HTMLFormElement::handleLocalEvents(Event* event) |
|
154 |
{ |
|
155 |
Node* targetNode = event->target()->toNode(); |
|
156 |
if (event->eventPhase() != Event::CAPTURING_PHASE && targetNode && targetNode != this && (event->type() == eventNames().submitEvent || event->type() == eventNames().resetEvent)) { |
|
157 |
event->stopPropagation(); |
|
158 |
return; |
|
159 |
} |
|
160 |
HTMLElement::handleLocalEvents(event); |
|
161 |
} |
|
162 |
||
163 |
unsigned HTMLFormElement::length() const |
|
164 |
{ |
|
165 |
int len = 0; |
|
166 |
for (unsigned i = 0; i < formElements.size(); ++i) |
|
167 |
if (formElements[i]->isEnumeratable()) |
|
168 |
++len; |
|
169 |
||
170 |
return len; |
|
171 |
} |
|
172 |
||
173 |
Node* HTMLFormElement::item(unsigned index) |
|
174 |
{ |
|
175 |
return elements()->item(index); |
|
176 |
} |
|
177 |
||
178 |
void HTMLFormElement::submitClick(Event* event) |
|
179 |
{ |
|
180 |
bool submitFound = false; |
|
181 |
for (unsigned i = 0; i < formElements.size(); ++i) { |
|
182 |
if (formElements[i]->hasLocalName(inputTag)) { |
|
183 |
HTMLInputElement* element = static_cast<HTMLInputElement*>(formElements[i]); |
|
184 |
if (element->isSuccessfulSubmitButton() && element->renderer()) { |
|
185 |
submitFound = true; |
|
186 |
element->dispatchSimulatedClick(event); |
|
187 |
break; |
|
188 |
} |
|
189 |
} |
|
190 |
} |
|
191 |
if (!submitFound) // submit the form without a submit or image input |
|
192 |
prepareSubmit(event); |
|
193 |
} |
|
194 |
||
195 |
TextEncoding HTMLFormElement::dataEncoding() const |
|
196 |
{ |
|
197 |
if (isMailtoForm()) |
|
198 |
return UTF8Encoding(); |
|
199 |
||
200 |
return m_formDataBuilder.dataEncoding(document()); |
|
201 |
} |
|
202 |
||
203 |
PassRefPtr<FormData> HTMLFormElement::createFormData(const CString& boundary) |
|
204 |
{ |
|
205 |
Vector<char> encodedData; |
|
206 |
TextEncoding encoding = dataEncoding().encodingForFormSubmission(); |
|
207 |
||
208 |
RefPtr<FormData> result = FormData::create(); |
|
209 |
||
210 |
for (unsigned i = 0; i < formElements.size(); ++i) { |
|
211 |
HTMLFormControlElement* control = formElements[i]; |
|
212 |
FormDataList list(encoding); |
|
213 |
||
214 |
if (!control->disabled() && control->appendFormData(list, m_formDataBuilder.isMultiPartForm())) { |
|
215 |
size_t formDataListSize = list.list().size(); |
|
216 |
ASSERT(formDataListSize % 2 == 0); |
|
217 |
for (size_t j = 0; j < formDataListSize; j += 2) { |
|
218 |
const FormDataList::Item& key = list.list()[j]; |
|
219 |
const FormDataList::Item& value = list.list()[j + 1]; |
|
220 |
if (!m_formDataBuilder.isMultiPartForm()) { |
|
221 |
// Omit the name "isindex" if it's the first form data element. |
|
222 |
// FIXME: Why is this a good rule? Is this obsolete now? |
|
223 |
if (encodedData.isEmpty() && key.data() == "isindex") |
|
224 |
FormDataBuilder::encodeStringAsFormData(encodedData, value.data()); |
|
225 |
else |
|
226 |
m_formDataBuilder.addKeyValuePairAsFormData(encodedData, key.data(), value.data()); |
|
227 |
} else { |
|
228 |
Vector<char> header; |
|
229 |
m_formDataBuilder.beginMultiPartHeader(header, boundary, key.data()); |
|
230 |
||
231 |
bool shouldGenerateFile = false; |
|
232 |
// if the current type is FILE, then we also need to include the filename |
|
233 |
if (value.file()) { |
|
234 |
const String& path = value.file()->path(); |
|
235 |
String fileName = value.file()->fileName(); |
|
236 |
||
237 |
// Let the application specify a filename if it's going to generate a replacement file for the upload. |
|
238 |
if (!path.isEmpty()) { |
|
239 |
if (Page* page = document()->page()) { |
|
240 |
String generatedFileName; |
|
241 |
shouldGenerateFile = page->chrome()->client()->shouldReplaceWithGeneratedFileForUpload(path, generatedFileName); |
|
242 |
if (shouldGenerateFile) |
|
243 |
fileName = generatedFileName; |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
// We have to include the filename=".." part in the header, even if the filename is empty |
|
248 |
m_formDataBuilder.addFilenameToMultiPartHeader(header, encoding, fileName); |
|
249 |
||
250 |
if (!fileName.isEmpty()) { |
|
251 |
// FIXME: The MIMETypeRegistry function's name makes it sound like it takes a path, |
|
252 |
// not just a basename. But filename is not the path. But note that it's not safe to |
|
253 |
// just use path instead since in the generated-file case it will not reflect the |
|
254 |
// MIME type of the generated file. |
|
255 |
String mimeType = MIMETypeRegistry::getMIMETypeForPath(fileName); |
|
256 |
if (!mimeType.isEmpty()) |
|
257 |
m_formDataBuilder.addContentTypeToMultiPartHeader(header, mimeType.latin1()); |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
m_formDataBuilder.finishMultiPartHeader(header); |
|
262 |
||
263 |
// Append body |
|
264 |
result->appendData(header.data(), header.size()); |
|
265 |
if (size_t dataSize = value.data().length()) |
|
266 |
result->appendData(value.data().data(), dataSize); |
|
267 |
else if (value.file() && !value.file()->path().isEmpty()) |
|
268 |
result->appendFile(value.file()->path(), shouldGenerateFile); |
|
269 |
||
270 |
result->appendData("\r\n", 2); |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
if (m_formDataBuilder.isMultiPartForm()) |
|
277 |
m_formDataBuilder.addBoundaryToMultiPartHeader(encodedData, boundary, true); |
|
278 |
||
279 |
result->appendData(encodedData.data(), encodedData.size()); |
|
280 |
||
281 |
result->setIdentifier(generateFormDataIdentifier()); |
|
282 |
return result; |
|
283 |
} |
|
284 |
||
285 |
bool HTMLFormElement::isMailtoForm() const |
|
286 |
{ |
|
287 |
return protocolIs(m_url, "mailto"); |
|
288 |
} |
|
289 |
||
290 |
bool HTMLFormElement::prepareSubmit(Event* event) |
|
291 |
{ |
|
292 |
Frame* frame = document()->frame(); |
|
293 |
if (m_insubmit || !frame) |
|
294 |
return m_insubmit; |
|
295 |
||
296 |
m_insubmit = true; |
|
297 |
m_doingsubmit = false; |
|
298 |
||
299 |
if (dispatchEvent(Event::create(eventNames().submitEvent, true, true)) && !m_doingsubmit) |
|
300 |
m_doingsubmit = true; |
|
301 |
||
302 |
m_insubmit = false; |
|
303 |
||
304 |
if (m_doingsubmit) |
|
305 |
submit(event, true); |
|
306 |
||
307 |
return m_doingsubmit; |
|
308 |
} |
|
309 |
||
310 |
static void transferMailtoPostFormDataToURL(RefPtr<FormData>& data, KURL& url, const String& encodingType) |
|
311 |
{ |
|
312 |
String body = data->flattenToString(); |
|
313 |
data = FormData::create(); |
|
314 |
||
315 |
if (equalIgnoringCase(encodingType, "text/plain")) { |
|
316 |
// Convention seems to be to decode, and s/&/\r\n/. Also, spaces are encoded as %20. |
|
317 |
body = decodeURLEscapeSequences(body.replace('&', "\r\n").replace('+', ' ') + "\r\n"); |
|
318 |
} |
|
319 |
||
320 |
Vector<char> bodyData; |
|
321 |
bodyData.append("body=", 5); |
|
322 |
FormDataBuilder::encodeStringAsFormData(bodyData, body.utf8()); |
|
323 |
body = String(bodyData.data(), bodyData.size()).replace('+', "%20"); |
|
324 |
||
325 |
String query = url.query(); |
|
326 |
if (!query.isEmpty()) |
|
327 |
query.append('&'); |
|
328 |
query.append(body); |
|
329 |
url.setQuery(query); |
|
330 |
} |
|
331 |
||
332 |
void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool lockHistory) |
|
333 |
{ |
|
334 |
FrameView* view = document()->view(); |
|
335 |
Frame* frame = document()->frame(); |
|
336 |
if (!view || !frame) |
|
337 |
return; |
|
338 |
||
339 |
if (m_insubmit) { |
|
340 |
m_doingsubmit = true; |
|
341 |
return; |
|
342 |
} |
|
343 |
||
344 |
m_insubmit = true; |
|
345 |
||
346 |
HTMLFormControlElement* firstSuccessfulSubmitButton = 0; |
|
347 |
bool needButtonActivation = activateSubmitButton; // do we need to activate a submit button? |
|
348 |
||
349 |
Vector<pair<String, String> > formValues; |
|
350 |
||
351 |
for (unsigned i = 0; i < formElements.size(); ++i) { |
|
352 |
HTMLFormControlElement* control = formElements[i]; |
|
353 |
if (control->hasLocalName(inputTag)) { |
|
354 |
HTMLInputElement* input = static_cast<HTMLInputElement*>(control); |
|
355 |
if (input->isTextField()) { |
|
356 |
formValues.append(pair<String, String>(input->name(), input->value())); |
|
357 |
if (input->isSearchField()) |
|
358 |
input->addSearchResult(); |
|
359 |
} |
|
360 |
} |
|
361 |
if (needButtonActivation) { |
|
362 |
if (control->isActivatedSubmit()) |
|
363 |
needButtonActivation = false; |
|
364 |
else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSubmitButton()) |
|
365 |
firstSuccessfulSubmitButton = control; |
|
366 |
} |
|
367 |
} |
|
368 |
||
369 |
RefPtr<FormState> formState = FormState::create(this, formValues, frame); |
|
370 |
||
371 |
if (needButtonActivation && firstSuccessfulSubmitButton) |
|
372 |
firstSuccessfulSubmitButton->setActivatedSubmit(true); |
|
373 |
||
374 |
if (m_url.isEmpty()) |
|
375 |
m_url = document()->url().string(); |
|
376 |
||
377 |
if (m_formDataBuilder.isPostMethod()) { |
|
378 |
if (m_formDataBuilder.isMultiPartForm() && isMailtoForm()) { |
|
379 |
setEnctype("application/x-www-form-urlencoded"); |
|
380 |
ASSERT(!m_formDataBuilder.isMultiPartForm()); |
|
381 |
} |
|
382 |
||
383 |
if (!m_formDataBuilder.isMultiPartForm()) { |
|
384 |
RefPtr<FormData> data = createFormData(CString()); |
|
385 |
||
386 |
if (isMailtoForm()) { |
|
387 |
// Convert the form data into a string that we put into the URL. |
|
388 |
KURL url = document()->completeURL(m_url); |
|
389 |
transferMailtoPostFormDataToURL(data, url, m_formDataBuilder.encodingType()); |
|
390 |
m_url = url.string(); |
|
391 |
} |
|
392 |
||
393 |
frame->loader()->submitForm("POST", m_url, data.release(), m_target, m_formDataBuilder.encodingType(), String(), lockHistory, event, formState.release()); |
|
394 |
} else { |
|
395 |
Vector<char> boundary = m_formDataBuilder.generateUniqueBoundaryString(); |
|
396 |
frame->loader()->submitForm("POST", m_url, createFormData(boundary.data()), m_target, m_formDataBuilder.encodingType(), boundary.data(), lockHistory, event, formState.release()); |
|
397 |
} |
|
398 |
} else { |
|
399 |
m_formDataBuilder.setIsMultiPartForm(false); |
|
400 |
frame->loader()->submitForm("GET", m_url, createFormData(CString()), m_target, String(), String(), lockHistory, event, formState.release()); |
|
401 |
} |
|
402 |
||
403 |
if (needButtonActivation && firstSuccessfulSubmitButton) |
|
404 |
firstSuccessfulSubmitButton->setActivatedSubmit(false); |
|
405 |
||
406 |
m_doingsubmit = m_insubmit = false; |
|
407 |
} |
|
408 |
||
409 |
void HTMLFormElement::reset() |
|
410 |
{ |
|
411 |
Frame* frame = document()->frame(); |
|
412 |
if (m_inreset || !frame) |
|
413 |
return; |
|
414 |
||
415 |
m_inreset = true; |
|
416 |
||
417 |
// ### DOM2 labels this event as not cancelable, however |
|
418 |
// common browsers( sick! ) allow it be cancelled. |
|
419 |
if (!dispatchEvent(Event::create(eventNames().resetEvent, true, true))) { |
|
420 |
m_inreset = false; |
|
421 |
return; |
|
422 |
} |
|
423 |
||
424 |
for (unsigned i = 0; i < formElements.size(); ++i) |
|
425 |
formElements[i]->reset(); |
|
426 |
||
427 |
m_inreset = false; |
|
428 |
} |
|
429 |
||
430 |
void HTMLFormElement::parseMappedAttribute(MappedAttribute* attr) |
|
431 |
{ |
|
432 |
if (attr->name() == actionAttr) |
|
433 |
m_url = deprecatedParseURL(attr->value()); |
|
434 |
else if (attr->name() == targetAttr) |
|
435 |
m_target = attr->value(); |
|
436 |
else if (attr->name() == methodAttr) |
|
437 |
m_formDataBuilder.parseMethodType(attr->value()); |
|
438 |
else if (attr->name() == enctypeAttr) |
|
439 |
m_formDataBuilder.parseEncodingType(attr->value()); |
|
440 |
else if (attr->name() == accept_charsetAttr) |
|
441 |
// space separated list of charsets the server |
|
442 |
// accepts - see rfc2045 |
|
443 |
m_formDataBuilder.setAcceptCharset(attr->value()); |
|
444 |
else if (attr->name() == acceptAttr) { |
|
445 |
// ignore this one for the moment... |
|
446 |
} else if (attr->name() == autocompleteAttr) { |
|
447 |
m_autocomplete = !equalIgnoringCase(attr->value(), "off"); |
|
448 |
if (!m_autocomplete) |
|
449 |
document()->registerForDocumentActivationCallbacks(this); |
|
450 |
else |
|
451 |
document()->unregisterForDocumentActivationCallbacks(this); |
|
452 |
} else if (attr->name() == onsubmitAttr) |
|
453 |
setAttributeEventListener(eventNames().submitEvent, createAttributeEventListener(this, attr)); |
|
454 |
else if (attr->name() == onresetAttr) |
|
455 |
setAttributeEventListener(eventNames().resetEvent, createAttributeEventListener(this, attr)); |
|
456 |
else if (attr->name() == nameAttr) { |
|
457 |
const AtomicString& newName = attr->value(); |
|
458 |
if (inDocument() && document()->isHTMLDocument()) { |
|
459 |
HTMLDocument* document = static_cast<HTMLDocument*>(this->document()); |
|
460 |
document->removeNamedItem(m_name); |
|
461 |
document->addNamedItem(newName); |
|
462 |
} |
|
463 |
m_name = newName; |
|
464 |
} else |
|
465 |
HTMLElement::parseMappedAttribute(attr); |
|
466 |
} |
|
467 |
||
468 |
template<class T, size_t n> static void removeFromVector(Vector<T*, n> & vec, T* item) |
|
469 |
{ |
|
470 |
size_t size = vec.size(); |
|
471 |
for (size_t i = 0; i != size; ++i) |
|
472 |
if (vec[i] == item) { |
|
473 |
vec.remove(i); |
|
474 |
break; |
|
475 |
} |
|
476 |
} |
|
477 |
||
478 |
unsigned HTMLFormElement::formElementIndex(HTMLFormControlElement* e) |
|
479 |
{ |
|
480 |
// Check for the special case where this element is the very last thing in |
|
481 |
// the form's tree of children; we don't want to walk the entire tree in that |
|
482 |
// common case that occurs during parsing; instead we'll just return a value |
|
483 |
// that says "add this form element to the end of the array". |
|
484 |
if (e->traverseNextNode(this)) { |
|
485 |
unsigned i = 0; |
|
486 |
for (Node* node = this; node; node = node->traverseNextNode(this)) { |
|
487 |
if (node == e) |
|
488 |
return i; |
|
489 |
if (node->isHTMLElement() |
|
490 |
&& static_cast<Element*>(node)->isFormControlElement() |
|
491 |
&& static_cast<HTMLFormControlElement*>(node)->form() == this) |
|
492 |
++i; |
|
493 |
} |
|
494 |
} |
|
495 |
return formElements.size(); |
|
496 |
} |
|
497 |
||
498 |
void HTMLFormElement::registerFormElement(HTMLFormControlElement* e) |
|
499 |
{ |
|
500 |
document()->checkedRadioButtons().removeButton(e); |
|
501 |
m_checkedRadioButtons.addButton(e); |
|
502 |
formElements.insert(formElementIndex(e), e); |
|
503 |
} |
|
504 |
||
505 |
void HTMLFormElement::removeFormElement(HTMLFormControlElement* e) |
|
506 |
{ |
|
507 |
m_checkedRadioButtons.removeButton(e); |
|
508 |
removeFromVector(formElements, e); |
|
509 |
} |
|
510 |
||
511 |
bool HTMLFormElement::isURLAttribute(Attribute* attr) const |
|
512 |
{ |
|
513 |
return attr->name() == actionAttr; |
|
514 |
} |
|
515 |
||
516 |
void HTMLFormElement::registerImgElement(HTMLImageElement* e) |
|
517 |
{ |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
518 |
ASSERT(imgElements.find(e) == notFound); |
0 | 519 |
imgElements.append(e); |
520 |
} |
|
521 |
||
522 |
void HTMLFormElement::removeImgElement(HTMLImageElement* e) |
|
523 |
{ |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
524 |
ASSERT(imgElements.find(e) != notFound); |
0 | 525 |
removeFromVector(imgElements, e); |
526 |
} |
|
527 |
||
528 |
PassRefPtr<HTMLCollection> HTMLFormElement::elements() |
|
529 |
{ |
|
530 |
return HTMLFormCollection::create(this); |
|
531 |
} |
|
532 |
||
533 |
String HTMLFormElement::name() const |
|
534 |
{ |
|
535 |
return getAttribute(nameAttr); |
|
536 |
} |
|
537 |
||
538 |
void HTMLFormElement::setName(const String &value) |
|
539 |
{ |
|
540 |
setAttribute(nameAttr, value); |
|
541 |
} |
|
542 |
||
543 |
bool HTMLFormElement::noValidate() const |
|
544 |
{ |
|
545 |
return !getAttribute(novalidateAttr).isNull(); |
|
546 |
} |
|
547 |
||
548 |
void HTMLFormElement::setNoValidate(bool novalidate) |
|
549 |
{ |
|
550 |
setAttribute(novalidateAttr, novalidate ? "" : 0); |
|
551 |
} |
|
552 |
||
553 |
void HTMLFormElement::setAcceptCharset(const String &value) |
|
554 |
{ |
|
555 |
setAttribute(accept_charsetAttr, value); |
|
556 |
} |
|
557 |
||
558 |
String HTMLFormElement::action() const |
|
559 |
{ |
|
560 |
return getAttribute(actionAttr); |
|
561 |
} |
|
562 |
||
563 |
void HTMLFormElement::setAction(const String &value) |
|
564 |
{ |
|
565 |
setAttribute(actionAttr, value); |
|
566 |
} |
|
567 |
||
568 |
void HTMLFormElement::setEnctype(const String &value) |
|
569 |
{ |
|
570 |
setAttribute(enctypeAttr, value); |
|
571 |
} |
|
572 |
||
573 |
String HTMLFormElement::method() const |
|
574 |
{ |
|
575 |
return getAttribute(methodAttr); |
|
576 |
} |
|
577 |
||
578 |
void HTMLFormElement::setMethod(const String &value) |
|
579 |
{ |
|
580 |
setAttribute(methodAttr, value); |
|
581 |
} |
|
582 |
||
583 |
String HTMLFormElement::target() const |
|
584 |
{ |
|
585 |
return getAttribute(targetAttr); |
|
586 |
} |
|
587 |
||
588 |
void HTMLFormElement::setTarget(const String &value) |
|
589 |
{ |
|
590 |
setAttribute(targetAttr, value); |
|
591 |
} |
|
592 |
||
593 |
HTMLFormControlElement* HTMLFormElement::defaultButton() const |
|
594 |
{ |
|
595 |
for (unsigned i = 0; i < formElements.size(); ++i) { |
|
596 |
HTMLFormControlElement* control = formElements[i]; |
|
597 |
if (control->isSuccessfulSubmitButton()) |
|
598 |
return control; |
|
599 |
} |
|
600 |
||
601 |
return 0; |
|
602 |
} |
|
603 |
||
604 |
bool HTMLFormElement::checkValidity() |
|
605 |
{ |
|
606 |
// TODO: Check for unhandled invalid controls, see #27452 for tips. |
|
607 |
||
608 |
bool hasOnlyValidControls = true; |
|
609 |
for (unsigned i = 0; i < formElements.size(); ++i) { |
|
610 |
HTMLFormControlElement* control = formElements[i]; |
|
611 |
if (!control->checkValidity()) |
|
612 |
hasOnlyValidControls = false; |
|
613 |
} |
|
614 |
||
615 |
return hasOnlyValidControls; |
|
616 |
} |
|
617 |
||
618 |
PassRefPtr<HTMLFormControlElement> HTMLFormElement::elementForAlias(const AtomicString& alias) |
|
619 |
{ |
|
620 |
if (alias.isEmpty() || !m_elementAliases) |
|
621 |
return 0; |
|
622 |
return m_elementAliases->get(alias.impl()); |
|
623 |
} |
|
624 |
||
625 |
void HTMLFormElement::addElementAlias(HTMLFormControlElement* element, const AtomicString& alias) |
|
626 |
{ |
|
627 |
if (alias.isEmpty()) |
|
628 |
return; |
|
629 |
if (!m_elementAliases) |
|
630 |
m_elementAliases = new AliasMap; |
|
631 |
m_elementAliases->set(alias.impl(), element); |
|
632 |
} |
|
633 |
||
634 |
void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<Node> >& namedItems) |
|
635 |
{ |
|
636 |
elements()->namedItems(name, namedItems); |
|
637 |
||
638 |
// see if we have seen something with this name before |
|
639 |
RefPtr<HTMLFormControlElement> aliasElem; |
|
640 |
if (aliasElem = elementForAlias(name)) { |
|
641 |
bool found = false; |
|
642 |
for (unsigned n = 0; n < namedItems.size(); n++) { |
|
643 |
if (namedItems[n] == aliasElem.get()) { |
|
644 |
found = true; |
|
645 |
break; |
|
646 |
} |
|
647 |
} |
|
648 |
if (!found) |
|
649 |
// we have seen it before but it is gone now. still, we need to return it. |
|
650 |
namedItems.append(aliasElem.get()); |
|
651 |
} |
|
652 |
// name has been accessed, remember it |
|
653 |
if (namedItems.size() && aliasElem != namedItems.first()) |
|
654 |
addElementAlias(static_cast<HTMLFormControlElement*>(namedItems.first().get()), name); |
|
655 |
} |
|
656 |
||
657 |
void HTMLFormElement::documentDidBecomeActive() |
|
658 |
{ |
|
659 |
ASSERT(!m_autocomplete); |
|
660 |
||
661 |
for (unsigned i = 0; i < formElements.size(); ++i) |
|
662 |
formElements[i]->reset(); |
|
663 |
} |
|
664 |
||
665 |
void HTMLFormElement::willMoveToNewOwnerDocument() |
|
666 |
{ |
|
667 |
if (!m_autocomplete) |
|
668 |
document()->unregisterForDocumentActivationCallbacks(this); |
|
669 |
HTMLElement::willMoveToNewOwnerDocument(); |
|
670 |
} |
|
671 |
||
672 |
void HTMLFormElement::didMoveToNewOwnerDocument() |
|
673 |
{ |
|
674 |
if (!m_autocomplete) |
|
675 |
document()->registerForDocumentActivationCallbacks(this); |
|
676 |
HTMLElement::didMoveToNewOwnerDocument(); |
|
677 |
} |
|
678 |
||
679 |
} // namespace |