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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #endif | 58 #endif |
59 | 59 |
60 using namespace std; | 60 using namespace std; |
61 | 61 |
62 namespace WebCore { | 62 namespace WebCore { |
63 | 63 |
64 using namespace HTMLNames; | 64 using namespace HTMLNames; |
65 | 65 |
66 HTMLFormElement::HTMLFormElement(const QualifiedName& tagName, Document* documen
t) | 66 HTMLFormElement::HTMLFormElement(const QualifiedName& tagName, Document* documen
t) |
67 : HTMLElement(tagName, document) | 67 : HTMLElement(tagName, document) |
68 , m_submissionTrigger(NotSubmittedByJavaScript) | 68 , m_wasUserSubmitted(false) |
69 , m_autocomplete(true) | 69 , m_autocomplete(true) |
70 , m_insubmit(false) | 70 , m_insubmit(false) |
71 , m_doingsubmit(false) | 71 , m_doingsubmit(false) |
72 , m_inreset(false) | 72 , m_inreset(false) |
73 , m_malformed(false) | 73 , m_malformed(false) |
74 , m_demoted(false) | 74 , m_demoted(false) |
75 { | 75 { |
76 ASSERT(hasTagName(formTag)); | 76 ASSERT(hasTagName(formTag)); |
77 } | 77 } |
78 | 78 |
(...skipping 20 matching lines...) Expand all Loading... |
99 | 99 |
100 bool HTMLFormElement::formWouldHaveSecureSubmission(const String& url) | 100 bool HTMLFormElement::formWouldHaveSecureSubmission(const String& url) |
101 { | 101 { |
102 return document()->completeURL(url).protocolIs("https"); | 102 return document()->completeURL(url).protocolIs("https"); |
103 } | 103 } |
104 | 104 |
105 bool HTMLFormElement::rendererIsNeeded(RenderStyle* style) | 105 bool HTMLFormElement::rendererIsNeeded(RenderStyle* style) |
106 { | 106 { |
107 if (!isDemoted()) | 107 if (!isDemoted()) |
108 return HTMLElement::rendererIsNeeded(style); | 108 return HTMLElement::rendererIsNeeded(style); |
109 | 109 |
110 Node* node = parentNode(); | 110 Node* node = parentNode(); |
111 RenderObject* parentRenderer = node->renderer(); | 111 RenderObject* parentRenderer = node->renderer(); |
112 bool parentIsTableElementPart = (parentRenderer->isTable() && node->hasTagNa
me(tableTag)) | 112 bool parentIsTableElementPart = (parentRenderer->isTable() && node->hasTagNa
me(tableTag)) |
113 || (parentRenderer->isTableRow() && node->hasTagName(trTag)) | 113 || (parentRenderer->isTableRow() && node->hasTagName(trTag)) |
114 || (parentRenderer->isTableSection() && node->hasTagName(tbodyTag)) | 114 || (parentRenderer->isTableSection() && node->hasTagName(tbodyTag)) |
115 || (parentRenderer->isTableCol() && node->hasTagName(colTag)) | 115 || (parentRenderer->isTableCol() && node->hasTagName(colTag)) |
116 || (parentRenderer->isTableCell() && node->hasTagName(trTag)); | 116 || (parentRenderer->isTableCell() && node->hasTagName(trTag)); |
117 | 117 |
118 if (!parentIsTableElementPart) | 118 if (!parentIsTableElementPart) |
119 return true; | 119 return true; |
120 | 120 |
121 EDisplay display = style->display(); | 121 EDisplay display = style->display(); |
122 bool formIsTablePart = display == TABLE || display == INLINE_TABLE || displa
y == TABLE_ROW_GROUP | 122 bool formIsTablePart = display == TABLE || display == INLINE_TABLE || displa
y == TABLE_ROW_GROUP |
123 || display == TABLE_HEADER_GROUP || display == TABLE_FOOTER_GROUP || dis
play == TABLE_ROW | 123 || display == TABLE_HEADER_GROUP || display == TABLE_FOOTER_GROUP || dis
play == TABLE_ROW |
124 || display == TABLE_COLUMN_GROUP || display == TABLE_COLUMN || display =
= TABLE_CELL | 124 || display == TABLE_COLUMN_GROUP || display == TABLE_COLUMN || display =
= TABLE_CELL |
125 || display == TABLE_CAPTION; | 125 || display == TABLE_CAPTION; |
126 | 126 |
127 return formIsTablePart; | 127 return formIsTablePart; |
128 } | 128 } |
129 | 129 |
130 void HTMLFormElement::insertedIntoDocument() | 130 void HTMLFormElement::insertedIntoDocument() |
131 { | 131 { |
132 if (document()->isHTMLDocument()) | 132 if (document()->isHTMLDocument()) |
133 static_cast<HTMLDocument*>(document())->addNamedItem(m_name); | 133 static_cast<HTMLDocument*>(document())->addNamedItem(m_name); |
134 | 134 |
135 HTMLElement::insertedIntoDocument(); | 135 HTMLElement::insertedIntoDocument(); |
136 } | 136 } |
137 | 137 |
138 void HTMLFormElement::removedFromDocument() | 138 void HTMLFormElement::removedFromDocument() |
139 { | 139 { |
140 if (document()->isHTMLDocument()) | 140 if (document()->isHTMLDocument()) |
141 static_cast<HTMLDocument*>(document())->removeNamedItem(m_name); | 141 static_cast<HTMLDocument*>(document())->removeNamedItem(m_name); |
142 | 142 |
143 HTMLElement::removedFromDocument(); | 143 HTMLElement::removedFromDocument(); |
144 } | 144 } |
145 | 145 |
146 void HTMLFormElement::handleLocalEvents(Event* event) | 146 void HTMLFormElement::handleLocalEvents(Event* event) |
147 { | 147 { |
148 Node* targetNode = event->target()->toNode(); | 148 Node* targetNode = event->target()->toNode(); |
149 if (event->eventPhase() != Event::CAPTURING_PHASE && targetNode && targetNod
e != this && (event->type() == eventNames().submitEvent || event->type() == even
tNames().resetEvent)) { | 149 if (event->eventPhase() != Event::CAPTURING_PHASE && targetNode && targetNod
e != this && (event->type() == eventNames().submitEvent || event->type() == even
tNames().resetEvent)) { |
150 event->stopPropagation(); | 150 event->stopPropagation(); |
151 return; | 151 return; |
152 } | 152 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 return false; | 256 return false; |
257 | 257 |
258 frame->loader()->client()->dispatchWillSendSubmitEvent(this); | 258 frame->loader()->client()->dispatchWillSendSubmitEvent(this); |
259 | 259 |
260 if (dispatchEvent(Event::create(eventNames().submitEvent, true, true)) && !m
_doingsubmit) | 260 if (dispatchEvent(Event::create(eventNames().submitEvent, true, true)) && !m
_doingsubmit) |
261 m_doingsubmit = true; | 261 m_doingsubmit = true; |
262 | 262 |
263 m_insubmit = false; | 263 m_insubmit = false; |
264 | 264 |
265 if (m_doingsubmit) | 265 if (m_doingsubmit) |
266 submit(event, true, false, NotSubmittedByJavaScript); | 266 submit(event, true, true, NotSubmittedByJavaScript); |
267 | 267 |
268 return m_doingsubmit; | 268 return m_doingsubmit; |
269 } | 269 } |
270 | 270 |
271 void HTMLFormElement::submit(Frame* javaScriptActiveFrame) | 271 void HTMLFormElement::submit(Frame* javaScriptActiveFrame) |
272 { | 272 { |
273 if (javaScriptActiveFrame) | 273 if (javaScriptActiveFrame) |
274 submit(0, false, !javaScriptActiveFrame->script()->anyPageIsProcessingUs
erGesture(), SubmittedByJavaScript); | 274 submit(0, false, javaScriptActiveFrame->script()->anyPageIsProcessingUse
rGesture(), SubmittedByJavaScript); |
275 else | 275 else |
276 submit(0, false, false, NotSubmittedByJavaScript); | 276 submit(0, false, true, NotSubmittedByJavaScript); |
277 } | 277 } |
278 | 278 |
279 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool lockH
istory, FormSubmissionTrigger formSubmissionTrigger) | 279 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce
ssingUserGesture, FormSubmissionTrigger formSubmissionTrigger) |
280 { | 280 { |
281 FrameView* view = document()->view(); | 281 FrameView* view = document()->view(); |
282 Frame* frame = document()->frame(); | 282 Frame* frame = document()->frame(); |
283 if (!view || !frame) | 283 if (!view || !frame) |
284 return; | 284 return; |
285 | 285 |
286 if (m_insubmit) { | 286 if (m_insubmit) { |
287 m_doingsubmit = true; | 287 m_doingsubmit = true; |
288 return; | 288 return; |
289 } | 289 } |
290 | 290 |
291 m_insubmit = true; | 291 m_insubmit = true; |
292 m_submissionTrigger = formSubmissionTrigger; | 292 m_wasUserSubmitted = processingUserGesture; |
293 | 293 |
294 HTMLFormControlElement* firstSuccessfulSubmitButton = 0; | 294 HTMLFormControlElement* firstSuccessfulSubmitButton = 0; |
295 bool needButtonActivation = activateSubmitButton; // do we need to activate
a submit button? | 295 bool needButtonActivation = activateSubmitButton; // do we need to activate
a submit button? |
296 | 296 |
297 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 297 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
298 HTMLFormControlElement* control = m_associatedElements[i]; | 298 HTMLFormControlElement* control = m_associatedElements[i]; |
299 if (needButtonActivation) { | 299 if (needButtonActivation) { |
300 if (control->isActivatedSubmit()) | 300 if (control->isActivatedSubmit()) |
301 needButtonActivation = false; | 301 needButtonActivation = false; |
302 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu
bmitButton()) | 302 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu
bmitButton()) |
303 firstSuccessfulSubmitButton = control; | 303 firstSuccessfulSubmitButton = control; |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 if (needButtonActivation && firstSuccessfulSubmitButton) | 307 if (needButtonActivation && firstSuccessfulSubmitButton) |
308 firstSuccessfulSubmitButton->setActivatedSubmit(true); | 308 firstSuccessfulSubmitButton->setActivatedSubmit(true); |
309 | 309 |
310 frame->loader()->submitForm(FormSubmission::create(this, m_attributes, event
, lockHistory, formSubmissionTrigger)); | 310 frame->loader()->submitForm(FormSubmission::create(this, m_attributes, event
, !processingUserGesture, formSubmissionTrigger)); |
311 | 311 |
312 if (needButtonActivation && firstSuccessfulSubmitButton) | 312 if (needButtonActivation && firstSuccessfulSubmitButton) |
313 firstSuccessfulSubmitButton->setActivatedSubmit(false); | 313 firstSuccessfulSubmitButton->setActivatedSubmit(false); |
314 | 314 |
315 m_doingsubmit = m_insubmit = false; | 315 m_doingsubmit = m_insubmit = false; |
316 } | 316 } |
317 | 317 |
318 void HTMLFormElement::reset() | 318 void HTMLFormElement::reset() |
319 { | 319 { |
320 Frame* frame = document()->frame(); | 320 Frame* frame = document()->frame(); |
321 if (m_inreset || !frame) | 321 if (m_inreset || !frame) |
322 return; | 322 return; |
323 | 323 |
324 m_inreset = true; | 324 m_inreset = true; |
(...skipping 23 matching lines...) Expand all Loading... |
348 m_attributes.parseEncodingType(attr->value()); | 348 m_attributes.parseEncodingType(attr->value()); |
349 else if (attr->name() == accept_charsetAttr) | 349 else if (attr->name() == accept_charsetAttr) |
350 // space separated list of charsets the server | 350 // space separated list of charsets the server |
351 // accepts - see rfc2045 | 351 // accepts - see rfc2045 |
352 m_attributes.setAcceptCharset(attr->value()); | 352 m_attributes.setAcceptCharset(attr->value()); |
353 else if (attr->name() == acceptAttr) { | 353 else if (attr->name() == acceptAttr) { |
354 // ignore this one for the moment... | 354 // ignore this one for the moment... |
355 } else if (attr->name() == autocompleteAttr) { | 355 } else if (attr->name() == autocompleteAttr) { |
356 m_autocomplete = !equalIgnoringCase(attr->value(), "off"); | 356 m_autocomplete = !equalIgnoringCase(attr->value(), "off"); |
357 if (!m_autocomplete) | 357 if (!m_autocomplete) |
358 document()->registerForDocumentActivationCallbacks(this); | 358 document()->registerForDocumentActivationCallbacks(this); |
359 else | 359 else |
360 document()->unregisterForDocumentActivationCallbacks(this); | 360 document()->unregisterForDocumentActivationCallbacks(this); |
361 } else if (attr->name() == onsubmitAttr) | 361 } else if (attr->name() == onsubmitAttr) |
362 setAttributeEventListener(eventNames().submitEvent, createAttributeEvent
Listener(this, attr)); | 362 setAttributeEventListener(eventNames().submitEvent, createAttributeEvent
Listener(this, attr)); |
363 else if (attr->name() == onresetAttr) | 363 else if (attr->name() == onresetAttr) |
364 setAttributeEventListener(eventNames().resetEvent, createAttributeEventL
istener(this, attr)); | 364 setAttributeEventListener(eventNames().resetEvent, createAttributeEventL
istener(this, attr)); |
365 else if (attr->name() == nameAttr) { | 365 else if (attr->name() == nameAttr) { |
366 const AtomicString& newName = attr->value(); | 366 const AtomicString& newName = attr->value(); |
367 if (inDocument() && document()->isHTMLDocument()) { | 367 if (inDocument() && document()->isHTMLDocument()) { |
368 HTMLDocument* document = static_cast<HTMLDocument*>(this->document()
); | 368 HTMLDocument* document = static_cast<HTMLDocument*>(this->document()
); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 void HTMLFormElement::setMethod(const String &value) | 475 void HTMLFormElement::setMethod(const String &value) |
476 { | 476 { |
477 setAttribute(methodAttr, value); | 477 setAttribute(methodAttr, value); |
478 } | 478 } |
479 | 479 |
480 String HTMLFormElement::target() const | 480 String HTMLFormElement::target() const |
481 { | 481 { |
482 return getAttribute(targetAttr); | 482 return getAttribute(targetAttr); |
483 } | 483 } |
484 | 484 |
485 FormSubmissionTrigger HTMLFormElement::submissionTrigger() const | 485 bool HTMLFormElement::wasUserSubmitted() const |
486 { | 486 { |
487 return m_submissionTrigger; | 487 return m_wasUserSubmitted; |
488 } | 488 } |
489 | 489 |
490 HTMLFormControlElement* HTMLFormElement::defaultButton() const | 490 HTMLFormControlElement* HTMLFormElement::defaultButton() const |
491 { | 491 { |
492 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 492 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
493 HTMLFormControlElement* control = m_associatedElements[i]; | 493 HTMLFormControlElement* control = m_associatedElements[i]; |
494 if (control->isSuccessfulSubmitButton()) | 494 if (control->isSuccessfulSubmitButton()) |
495 return control; | 495 return control; |
496 } | 496 } |
497 | 497 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 found = true; | 549 found = true; |
550 break; | 550 break; |
551 } | 551 } |
552 } | 552 } |
553 if (!found) | 553 if (!found) |
554 // we have seen it before but it is gone now. still, we need to retu
rn it. | 554 // we have seen it before but it is gone now. still, we need to retu
rn it. |
555 namedItems.append(aliasElem.get()); | 555 namedItems.append(aliasElem.get()); |
556 } | 556 } |
557 // name has been accessed, remember it | 557 // name has been accessed, remember it |
558 if (namedItems.size() && aliasElem != namedItems.first()) | 558 if (namedItems.size() && aliasElem != namedItems.first()) |
559 addElementAlias(static_cast<HTMLFormControlElement*>(namedItems.first().
get()), name); | 559 addElementAlias(static_cast<HTMLFormControlElement*>(namedItems.first().
get()), name); |
560 } | 560 } |
561 | 561 |
562 void HTMLFormElement::documentDidBecomeActive() | 562 void HTMLFormElement::documentDidBecomeActive() |
563 { | 563 { |
564 ASSERT(!m_autocomplete); | 564 ASSERT(!m_autocomplete); |
565 | 565 |
566 for (unsigned i = 0; i < m_associatedElements.size(); ++i) | 566 for (unsigned i = 0; i < m_associatedElements.size(); ++i) |
567 m_associatedElements[i]->reset(); | 567 m_associatedElements[i]->reset(); |
568 } | 568 } |
569 | 569 |
570 void HTMLFormElement::willMoveToNewOwnerDocument() | 570 void HTMLFormElement::willMoveToNewOwnerDocument() |
571 { | 571 { |
572 if (!m_autocomplete) | 572 if (!m_autocomplete) |
573 document()->unregisterForDocumentActivationCallbacks(this); | 573 document()->unregisterForDocumentActivationCallbacks(this); |
574 HTMLElement::willMoveToNewOwnerDocument(); | 574 HTMLElement::willMoveToNewOwnerDocument(); |
575 } | 575 } |
576 | 576 |
577 void HTMLFormElement::didMoveToNewOwnerDocument() | 577 void HTMLFormElement::didMoveToNewOwnerDocument() |
578 { | 578 { |
579 if (!m_autocomplete) | 579 if (!m_autocomplete) |
580 document()->registerForDocumentActivationCallbacks(this); | 580 document()->registerForDocumentActivationCallbacks(this); |
581 HTMLElement::didMoveToNewOwnerDocument(); | 581 HTMLElement::didMoveToNewOwnerDocument(); |
582 } | 582 } |
583 | 583 |
584 } // namespace | 584 } // namespace |
OLD | NEW |