OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 using namespace HTMLNames; | 60 using namespace HTMLNames; |
61 | 61 |
62 HTMLFormElement::HTMLFormElement(Document& document) | 62 HTMLFormElement::HTMLFormElement(Document& document) |
63 : HTMLElement(formTag, document) | 63 : HTMLElement(formTag, document) |
64 , m_weakPtrFactory(this) | 64 , m_weakPtrFactory(this) |
65 , m_associatedElementsAreDirty(false) | 65 , m_associatedElementsAreDirty(false) |
66 , m_imageElementsAreDirty(false) | 66 , m_imageElementsAreDirty(false) |
67 , m_hasElementsAssociatedByParser(false) | 67 , m_hasElementsAssociatedByParser(false) |
68 , m_didFinishParsingChildren(false) | 68 , m_didFinishParsingChildren(false) |
69 , m_wasUserSubmitted(false) | 69 , m_wasUserSubmitted(false) |
70 , m_isSubmittingOrPreparingForSubmission(false) | 70 , m_isSubmitting(false) |
71 , m_shouldSubmit(false) | |
72 , m_isInResetFunction(false) | 71 , m_isInResetFunction(false) |
73 , m_wasDemoted(false) | 72 , m_wasDemoted(false) |
74 , m_requestAutocompleteTimer(this, &HTMLFormElement::requestAutocompleteTime
rFired) | 73 , m_requestAutocompleteTimer(this, &HTMLFormElement::requestAutocompleteTime
rFired) |
75 { | 74 { |
76 ScriptWrappable::init(this); | 75 ScriptWrappable::init(this); |
77 } | 76 } |
78 | 77 |
79 PassRefPtr<HTMLFormElement> HTMLFormElement::create(Document& document) | 78 PassRefPtr<HTMLFormElement> HTMLFormElement::create(Document& document) |
80 { | 79 { |
81 UseCounter::count(document, UseCounter::FormElement); | 80 UseCounter::count(document, UseCounter::FormElement); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 if (unhandled->isFocusable() && unhandled->inDocument()) | 274 if (unhandled->isFocusable() && unhandled->inDocument()) |
276 continue; | 275 continue; |
277 String message("An invalid form control with name='%name' is not foc
usable."); | 276 String message("An invalid form control with name='%name' is not foc
usable."); |
278 message.replace("%name", unhandledAssociatedElement->name()); | 277 message.replace("%name", unhandledAssociatedElement->name()); |
279 document().addConsoleMessage(RenderingMessageSource, ErrorMessageLev
el, message); | 278 document().addConsoleMessage(RenderingMessageSource, ErrorMessageLev
el, message); |
280 } | 279 } |
281 } | 280 } |
282 return false; | 281 return false; |
283 } | 282 } |
284 | 283 |
285 bool HTMLFormElement::prepareForSubmission(Event* event) | 284 void HTMLFormElement::prepareForSubmission(Event* event) |
286 { | 285 { |
287 RefPtr<HTMLFormElement> protector(this); | 286 RefPtr<HTMLFormElement> protector(this); |
288 Frame* frame = document().frame(); | 287 Frame* frame = document().frame(); |
289 if (m_isSubmittingOrPreparingForSubmission || !frame) | 288 if (m_isSubmitting || !frame) |
290 return m_isSubmittingOrPreparingForSubmission; | 289 return; |
291 | |
292 m_isSubmittingOrPreparingForSubmission = true; | |
293 m_shouldSubmit = false; | |
294 | 290 |
295 // Interactive validation must be done before dispatching the submit event. | 291 // Interactive validation must be done before dispatching the submit event. |
296 if (!validateInteractively(event)) { | 292 if (!validateInteractively(event)) |
297 m_isSubmittingOrPreparingForSubmission = false; | 293 return; |
298 return false; | |
299 } | |
300 | 294 |
301 StringPairVector controlNamesAndValues; | 295 StringPairVector controlNamesAndValues; |
302 getTextFieldValues(controlNamesAndValues); | 296 getTextFieldValues(controlNamesAndValues); |
303 RefPtr<FormState> formState = FormState::create(this, controlNamesAndValues,
&document(), NotSubmittedByJavaScript); | 297 RefPtr<FormState> formState = FormState::create(this, controlNamesAndValues,
&document(), NotSubmittedByJavaScript); |
304 frame->loader().client()->dispatchWillSendSubmitEvent(formState.release()); | 298 frame->loader().client()->dispatchWillSendSubmitEvent(formState.release()); |
305 | 299 |
306 if (dispatchEvent(Event::createCancelableBubble(EventTypeNames::submit))) | 300 if (!dispatchEvent(Event::createCancelableBubble(EventTypeNames::submit))) |
307 m_shouldSubmit = true; | 301 return; |
308 | 302 |
309 m_isSubmittingOrPreparingForSubmission = false; | 303 submit(event, true, true, NotSubmittedByJavaScript); |
310 | |
311 if (m_shouldSubmit) | |
312 submit(event, true, true, NotSubmittedByJavaScript); | |
313 | |
314 return m_shouldSubmit; | |
315 } | 304 } |
316 | 305 |
317 void HTMLFormElement::submit() | 306 void HTMLFormElement::submit() |
318 { | 307 { |
319 submit(0, false, true, NotSubmittedByJavaScript); | 308 submit(0, false, true, NotSubmittedByJavaScript); |
320 } | 309 } |
321 | 310 |
322 void HTMLFormElement::submitFromJavaScript() | 311 void HTMLFormElement::submitFromJavaScript() |
323 { | 312 { |
324 submit(0, false, UserGestureIndicator::processingUserGesture(), SubmittedByJ
avaScript); | 313 submit(0, false, UserGestureIndicator::processingUserGesture(), SubmittedByJ
avaScript); |
(...skipping 26 matching lines...) Expand all Loading... |
351 toHTMLDialogElement(node)->closeDialog(formSubmission->result()); | 340 toHTMLDialogElement(node)->closeDialog(formSubmission->result()); |
352 return; | 341 return; |
353 } | 342 } |
354 } | 343 } |
355 } | 344 } |
356 | 345 |
357 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce
ssingUserGesture, FormSubmissionTrigger formSubmissionTrigger) | 346 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce
ssingUserGesture, FormSubmissionTrigger formSubmissionTrigger) |
358 { | 347 { |
359 FrameView* view = document().view(); | 348 FrameView* view = document().view(); |
360 Frame* frame = document().frame(); | 349 Frame* frame = document().frame(); |
361 if (!view || !frame || !frame->page()) | 350 if (!view || !frame || !frame->page() || m_isSubmitting) |
362 return; | 351 return; |
363 | 352 |
364 if (m_isSubmittingOrPreparingForSubmission) { | 353 m_isSubmitting = true; |
365 m_shouldSubmit = true; | |
366 return; | |
367 } | |
368 | |
369 m_isSubmittingOrPreparingForSubmission = true; | |
370 m_wasUserSubmitted = processingUserGesture; | 354 m_wasUserSubmitted = processingUserGesture; |
371 | 355 |
372 RefPtr<HTMLFormControlElement> firstSuccessfulSubmitButton; | 356 RefPtr<HTMLFormControlElement> firstSuccessfulSubmitButton; |
373 bool needButtonActivation = activateSubmitButton; // do we need to activate
a submit button? | 357 bool needButtonActivation = activateSubmitButton; // do we need to activate
a submit button? |
374 | 358 |
375 const Vector<FormAssociatedElement*>& elements = associatedElements(); | 359 const Vector<FormAssociatedElement*>& elements = associatedElements(); |
376 for (unsigned i = 0; i < elements.size(); ++i) { | 360 for (unsigned i = 0; i < elements.size(); ++i) { |
377 FormAssociatedElement* associatedElement = elements[i]; | 361 FormAssociatedElement* associatedElement = elements[i]; |
378 if (!associatedElement->isFormControlElement()) | 362 if (!associatedElement->isFormControlElement()) |
379 continue; | 363 continue; |
(...skipping 12 matching lines...) Expand all Loading... |
392 RefPtr<FormSubmission> formSubmission = FormSubmission::create(this, m_attri
butes, event, formSubmissionTrigger); | 376 RefPtr<FormSubmission> formSubmission = FormSubmission::create(this, m_attri
butes, event, formSubmissionTrigger); |
393 EventQueueScope scopeForDialogClose; // Delay dispatching 'close' to dialog
until done submitting. | 377 EventQueueScope scopeForDialogClose; // Delay dispatching 'close' to dialog
until done submitting. |
394 if (formSubmission->method() == FormSubmission::DialogMethod) | 378 if (formSubmission->method() == FormSubmission::DialogMethod) |
395 submitDialog(formSubmission.release()); | 379 submitDialog(formSubmission.release()); |
396 else | 380 else |
397 scheduleFormSubmission(formSubmission.release()); | 381 scheduleFormSubmission(formSubmission.release()); |
398 | 382 |
399 if (needButtonActivation && firstSuccessfulSubmitButton) | 383 if (needButtonActivation && firstSuccessfulSubmitButton) |
400 firstSuccessfulSubmitButton->setActivatedSubmit(false); | 384 firstSuccessfulSubmitButton->setActivatedSubmit(false); |
401 | 385 |
402 m_shouldSubmit = false; | 386 m_isSubmitting = false; |
403 m_isSubmittingOrPreparingForSubmission = false; | |
404 } | 387 } |
405 | 388 |
406 void HTMLFormElement::scheduleFormSubmission(PassRefPtr<FormSubmission> submissi
on) | 389 void HTMLFormElement::scheduleFormSubmission(PassRefPtr<FormSubmission> submissi
on) |
407 { | 390 { |
408 ASSERT(submission->method() == FormSubmission::PostMethod || submission->met
hod() == FormSubmission::GetMethod); | 391 ASSERT(submission->method() == FormSubmission::PostMethod || submission->met
hod() == FormSubmission::GetMethod); |
409 ASSERT(submission->data()); | 392 ASSERT(submission->data()); |
410 ASSERT(submission->state()); | 393 ASSERT(submission->state()); |
411 if (submission->action().isEmpty()) | 394 if (submission->action().isEmpty()) |
412 return; | 395 return; |
413 if (document().isSandboxed(SandboxForms)) { | 396 if (document().isSandboxed(SandboxForms)) { |
(...skipping 10 matching lines...) Expand all Loading... |
424 } | 407 } |
425 | 408 |
426 Frame* targetFrame = document().frame()->loader().findFrameForNavigation(sub
mission->target(), submission->state()->sourceDocument()); | 409 Frame* targetFrame = document().frame()->loader().findFrameForNavigation(sub
mission->target(), submission->state()->sourceDocument()); |
427 if (!targetFrame) { | 410 if (!targetFrame) { |
428 if (!DOMWindow::allowPopUp(document().frame()) && !UserGestureIndicator:
:processingUserGesture()) | 411 if (!DOMWindow::allowPopUp(document().frame()) && !UserGestureIndicator:
:processingUserGesture()) |
429 return; | 412 return; |
430 targetFrame = document().frame(); | 413 targetFrame = document().frame(); |
431 } else { | 414 } else { |
432 submission->clearTarget(); | 415 submission->clearTarget(); |
433 } | 416 } |
| 417 |
434 if (!targetFrame->page()) | 418 if (!targetFrame->page()) |
435 return; | 419 return; |
436 | 420 |
437 submission->setReferrer(Referrer(document().outgoingReferrer(), document().r
eferrerPolicy())); | 421 submission->setReferrer(Referrer(document().outgoingReferrer(), document().r
eferrerPolicy())); |
438 submission->setOrigin(document().outgoingOrigin()); | 422 submission->setOrigin(document().outgoingOrigin()); |
439 | 423 |
440 targetFrame->navigationScheduler().scheduleFormSubmission(submission); | 424 targetFrame->navigationScheduler().scheduleFormSubmission(submission); |
441 } | 425 } |
442 | 426 |
443 void HTMLFormElement::reset() | 427 void HTMLFormElement::reset() |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 } | 801 } |
818 | 802 |
819 void HTMLFormElement::setDemoted(bool demoted) | 803 void HTMLFormElement::setDemoted(bool demoted) |
820 { | 804 { |
821 if (demoted) | 805 if (demoted) |
822 UseCounter::count(document(), UseCounter::DemotedFormElement); | 806 UseCounter::count(document(), UseCounter::DemotedFormElement); |
823 m_wasDemoted = demoted; | 807 m_wasDemoted = demoted; |
824 } | 808 } |
825 | 809 |
826 } // namespace | 810 } // namespace |
OLD | NEW |