| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return elements()->item(index); | 179 return elements()->item(index); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void HTMLFormElement::submitImplicitly(Event* event, bool fromImplicitSubmission
Trigger) | 182 void HTMLFormElement::submitImplicitly(Event* event, bool fromImplicitSubmission
Trigger) |
| 183 { | 183 { |
| 184 int submissionTriggerCount = 0; | 184 int submissionTriggerCount = 0; |
| 185 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 185 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
| 186 FormAssociatedElement* formAssociatedElement = m_associatedElements[i]; | 186 FormAssociatedElement* formAssociatedElement = m_associatedElements[i]; |
| 187 if (!formAssociatedElement->isFormControlElement()) | 187 if (!formAssociatedElement->isFormControlElement()) |
| 188 continue; | 188 continue; |
| 189 HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement
*>(formAssociatedElement); | 189 HTMLFormControlElement* control = toHTMLFormControlElement(formAssociate
dElement); |
| 190 if (formElement->isSuccessfulSubmitButton()) { | 190 if (control->isSuccessfulSubmitButton()) { |
| 191 if (formElement->renderer()) { | 191 if (control->renderer()) { |
| 192 formElement->dispatchSimulatedClick(event); | 192 control->dispatchSimulatedClick(event); |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 } else if (formElement->canTriggerImplicitSubmission()) | 195 } else if (control->canTriggerImplicitSubmission()) |
| 196 ++submissionTriggerCount; | 196 ++submissionTriggerCount; |
| 197 } | 197 } |
| 198 if (fromImplicitSubmissionTrigger && submissionTriggerCount == 1) | 198 if (fromImplicitSubmissionTrigger && submissionTriggerCount == 1) |
| 199 prepareForSubmission(event); | 199 prepareForSubmission(event); |
| 200 } | 200 } |
| 201 | 201 |
| 202 static inline HTMLFormControlElement* submitElementFromEvent(const Event* event) | 202 static inline HTMLFormControlElement* submitElementFromEvent(const Event* event) |
| 203 { | 203 { |
| 204 for (Node* node = event->target()->toNode(); node; node = node->parentNode()
) { | 204 for (Node* node = event->target()->toNode(); node; node = node->parentNode()
) { |
| 205 if (node->isElementNode() && toElement(node)->isFormControlElement()) | 205 if (node->isElementNode() && toElement(node)->isFormControlElement()) |
| 206 return static_cast<HTMLFormControlElement*>(node); | 206 return toHTMLFormControlElement(node); |
| 207 } | 207 } |
| 208 return 0; | 208 return 0; |
| 209 } | 209 } |
| 210 | 210 |
| 211 bool HTMLFormElement::validateInteractively(Event* event) | 211 bool HTMLFormElement::validateInteractively(Event* event) |
| 212 { | 212 { |
| 213 ASSERT(event); | 213 ASSERT(event); |
| 214 if (!document()->page() || noValidate()) | 214 if (!document()->page() || noValidate()) |
| 215 return true; | 215 return true; |
| 216 | 216 |
| 217 HTMLFormControlElement* submitElement = submitElementFromEvent(event); | 217 HTMLFormControlElement* submitElement = submitElementFromEvent(event); |
| 218 if (submitElement && submitElement->formNoValidate()) | 218 if (submitElement && submitElement->formNoValidate()) |
| 219 return true; | 219 return true; |
| 220 | 220 |
| 221 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 221 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
| 222 if (m_associatedElements[i]->isFormControlElement()) | 222 if (m_associatedElements[i]->isFormControlElement()) |
| 223 static_cast<HTMLFormControlElement*>(m_associatedElements[i])->hideV
isibleValidationMessage(); | 223 toHTMLFormControlElement(m_associatedElements[i])->hideVisibleValida
tionMessage(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 Vector<RefPtr<FormAssociatedElement> > unhandledInvalidControls; | 226 Vector<RefPtr<FormAssociatedElement> > unhandledInvalidControls; |
| 227 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls)) | 227 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls)) |
| 228 return true; | 228 return true; |
| 229 // Because the form has invalid controls, we abort the form submission and | 229 // Because the form has invalid controls, we abort the form submission and |
| 230 // show a validation message on a focusable form control. | 230 // show a validation message on a focusable form control. |
| 231 | 231 |
| 232 // Needs to update layout now because we'd like to call isFocusable(), which | 232 // Needs to update layout now because we'd like to call isFocusable(), which |
| 233 // has !renderer()->needsLayout() assertion. | 233 // has !renderer()->needsLayout() assertion. |
| 234 document()->updateLayoutIgnorePendingStylesheets(); | 234 document()->updateLayoutIgnorePendingStylesheets(); |
| 235 | 235 |
| 236 RefPtr<HTMLFormElement> protector(this); | 236 RefPtr<HTMLFormElement> protector(this); |
| 237 // Focus on the first focusable control and show a validation message. | 237 // Focus on the first focusable control and show a validation message. |
| 238 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { | 238 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { |
| 239 FormAssociatedElement* unhandledAssociatedElement = unhandledInvalidCont
rols[i].get(); | 239 FormAssociatedElement* unhandledAssociatedElement = unhandledInvalidCont
rols[i].get(); |
| 240 HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); | 240 HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); |
| 241 if (unhandled->isFocusable() && unhandled->inDocument()) { | 241 if (unhandled->isFocusable() && unhandled->inDocument()) { |
| 242 unhandled->scrollIntoViewIfNeeded(false); | 242 unhandled->scrollIntoViewIfNeeded(false); |
| 243 unhandled->focus(); | 243 unhandled->focus(); |
| 244 if (unhandled->isFormControlElement()) | 244 if (unhandled->isFormControlElement()) |
| 245 static_cast<HTMLFormControlElement*>(unhandled)->updateVisibleVa
lidationMessage(); | 245 toHTMLFormControlElement(unhandled)->updateVisibleValidationMess
age(); |
| 246 break; | 246 break; |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 // Warn about all of unfocusable controls. | 249 // Warn about all of unfocusable controls. |
| 250 if (document()->frame()) { | 250 if (document()->frame()) { |
| 251 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { | 251 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { |
| 252 FormAssociatedElement* unhandledAssociatedElement = unhandledInvalid
Controls[i].get(); | 252 FormAssociatedElement* unhandledAssociatedElement = unhandledInvalid
Controls[i].get(); |
| 253 HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); | 253 HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); |
| 254 if (unhandled->isFocusable() && unhandled->inDocument()) | 254 if (unhandled->isFocusable() && unhandled->inDocument()) |
| 255 continue; | 255 continue; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 m_wasUserSubmitted = processingUserGesture; | 337 m_wasUserSubmitted = processingUserGesture; |
| 338 | 338 |
| 339 HTMLFormControlElement* firstSuccessfulSubmitButton = 0; | 339 HTMLFormControlElement* firstSuccessfulSubmitButton = 0; |
| 340 bool needButtonActivation = activateSubmitButton; // do we need to activate
a submit button? | 340 bool needButtonActivation = activateSubmitButton; // do we need to activate
a submit button? |
| 341 | 341 |
| 342 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 342 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
| 343 FormAssociatedElement* associatedElement = m_associatedElements[i]; | 343 FormAssociatedElement* associatedElement = m_associatedElements[i]; |
| 344 if (!associatedElement->isFormControlElement()) | 344 if (!associatedElement->isFormControlElement()) |
| 345 continue; | 345 continue; |
| 346 if (needButtonActivation) { | 346 if (needButtonActivation) { |
| 347 HTMLFormControlElement* control = static_cast<HTMLFormControlElement
*>(associatedElement); | 347 HTMLFormControlElement* control = toHTMLFormControlElement(associate
dElement); |
| 348 if (control->isActivatedSubmit()) | 348 if (control->isActivatedSubmit()) |
| 349 needButtonActivation = false; | 349 needButtonActivation = false; |
| 350 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu
bmitButton()) | 350 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu
bmitButton()) |
| 351 firstSuccessfulSubmitButton = control; | 351 firstSuccessfulSubmitButton = control; |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 if (needButtonActivation && firstSuccessfulSubmitButton) | 355 if (needButtonActivation && firstSuccessfulSubmitButton) |
| 356 firstSuccessfulSubmitButton->setActivatedSubmit(true); | 356 firstSuccessfulSubmitButton->setActivatedSubmit(true); |
| 357 | 357 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 372 | 372 |
| 373 m_isInResetFunction = true; | 373 m_isInResetFunction = true; |
| 374 | 374 |
| 375 if (!dispatchEvent(Event::create(eventNames().resetEvent, true, true))) { | 375 if (!dispatchEvent(Event::create(eventNames().resetEvent, true, true))) { |
| 376 m_isInResetFunction = false; | 376 m_isInResetFunction = false; |
| 377 return; | 377 return; |
| 378 } | 378 } |
| 379 | 379 |
| 380 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 380 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
| 381 if (m_associatedElements[i]->isFormControlElement()) | 381 if (m_associatedElements[i]->isFormControlElement()) |
| 382 static_cast<HTMLFormControlElement*>(m_associatedElements[i])->reset
(); | 382 toHTMLFormControlElement(m_associatedElements[i])->reset(); |
| 383 } | 383 } |
| 384 | 384 |
| 385 m_isInResetFunction = false; | 385 m_isInResetFunction = false; |
| 386 } | 386 } |
| 387 | 387 |
| 388 void HTMLFormElement::requestAutocomplete() | 388 void HTMLFormElement::requestAutocomplete() |
| 389 { | 389 { |
| 390 Frame* frame = document()->frame(); | 390 Frame* frame = document()->frame(); |
| 391 if (!frame) | 391 if (!frame) |
| 392 return; | 392 return; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 bool HTMLFormElement::wasUserSubmitted() const | 618 bool HTMLFormElement::wasUserSubmitted() const |
| 619 { | 619 { |
| 620 return m_wasUserSubmitted; | 620 return m_wasUserSubmitted; |
| 621 } | 621 } |
| 622 | 622 |
| 623 HTMLFormControlElement* HTMLFormElement::defaultButton() const | 623 HTMLFormControlElement* HTMLFormElement::defaultButton() const |
| 624 { | 624 { |
| 625 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 625 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
| 626 if (!m_associatedElements[i]->isFormControlElement()) | 626 if (!m_associatedElements[i]->isFormControlElement()) |
| 627 continue; | 627 continue; |
| 628 HTMLFormControlElement* control = static_cast<HTMLFormControlElement*>(m
_associatedElements[i]); | 628 HTMLFormControlElement* control = toHTMLFormControlElement(m_associatedE
lements[i]); |
| 629 if (control->isSuccessfulSubmitButton()) | 629 if (control->isSuccessfulSubmitButton()) |
| 630 return control; | 630 return control; |
| 631 } | 631 } |
| 632 | 632 |
| 633 return 0; | 633 return 0; |
| 634 } | 634 } |
| 635 | 635 |
| 636 bool HTMLFormElement::checkValidity() | 636 bool HTMLFormElement::checkValidity() |
| 637 { | 637 { |
| 638 Vector<RefPtr<FormAssociatedElement> > controls; | 638 Vector<RefPtr<FormAssociatedElement> > controls; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 649 RefPtr<HTMLFormElement> protector(this); | 649 RefPtr<HTMLFormElement> protector(this); |
| 650 // Copy m_associatedElements because event handlers called from | 650 // Copy m_associatedElements because event handlers called from |
| 651 // HTMLFormControlElement::checkValidity() might change m_associatedElements
. | 651 // HTMLFormControlElement::checkValidity() might change m_associatedElements
. |
| 652 Vector<RefPtr<FormAssociatedElement> > elements; | 652 Vector<RefPtr<FormAssociatedElement> > elements; |
| 653 elements.reserveCapacity(m_associatedElements.size()); | 653 elements.reserveCapacity(m_associatedElements.size()); |
| 654 for (unsigned i = 0; i < m_associatedElements.size(); ++i) | 654 for (unsigned i = 0; i < m_associatedElements.size(); ++i) |
| 655 elements.append(m_associatedElements[i]); | 655 elements.append(m_associatedElements[i]); |
| 656 bool hasInvalidControls = false; | 656 bool hasInvalidControls = false; |
| 657 for (unsigned i = 0; i < elements.size(); ++i) { | 657 for (unsigned i = 0; i < elements.size(); ++i) { |
| 658 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ | 658 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ |
| 659 HTMLFormControlElement* control = static_cast<HTMLFormControlElement
*>(elements[i].get()); | 659 HTMLFormControlElement* control = toHTMLFormControlElement(elements[
i].get()); |
| 660 if (!control->checkValidity(unhandledInvalidControls, dispatchEvents
) && control->form() == this) | 660 if (!control->checkValidity(unhandledInvalidControls, dispatchEvents
) && control->form() == this) |
| 661 hasInvalidControls = true; | 661 hasInvalidControls = true; |
| 662 } | 662 } |
| 663 } | 663 } |
| 664 return hasInvalidControls; | 664 return hasInvalidControls; |
| 665 } | 665 } |
| 666 | 666 |
| 667 HTMLFormControlElement* HTMLFormElement::elementForAlias(const AtomicString& ali
as) | 667 Node* HTMLFormElement::elementForAlias(const AtomicString& alias) |
| 668 { | 668 { |
| 669 if (alias.isEmpty() || !m_elementAliases) | 669 if (alias.isEmpty() || !m_elementAliases) |
| 670 return 0; | 670 return 0; |
| 671 return m_elementAliases->get(alias.impl()); | 671 return m_elementAliases->get(alias.impl()); |
| 672 } | 672 } |
| 673 | 673 |
| 674 void HTMLFormElement::addElementAlias(HTMLFormControlElement* element, const Ato
micString& alias) | 674 void HTMLFormElement::addElementAlias(Node* element, const AtomicString& alias) |
| 675 { | 675 { |
| 676 if (alias.isEmpty()) | 676 if (alias.isEmpty()) |
| 677 return; | 677 return; |
| 678 if (!m_elementAliases) | 678 if (!m_elementAliases) |
| 679 m_elementAliases = adoptPtr(new AliasMap); | 679 m_elementAliases = adoptPtr(new AliasMap); |
| 680 m_elementAliases->set(alias.impl(), element); | 680 m_elementAliases->set(alias.impl(), element); |
| 681 } | 681 } |
| 682 | 682 |
| 683 void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<N
ode> >& namedItems) | 683 void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<N
ode> >& namedItems) |
| 684 { | 684 { |
| 685 elements()->namedItems(name, namedItems); | 685 elements()->namedItems(name, namedItems); |
| 686 | 686 |
| 687 HTMLFormControlElement* aliasElement = elementForAlias(name); | 687 Node* aliasElement = elementForAlias(name); |
| 688 if (aliasElement) { | 688 if (aliasElement) { |
| 689 if (namedItems.find(aliasElement) == notFound) { | 689 if (namedItems.find(aliasElement) == notFound) { |
| 690 // We have seen it before but it is gone now. Still, we need to retu
rn it. | 690 // We have seen it before but it is gone now. Still, we need to retu
rn it. |
| 691 // FIXME: The above comment is not clear enough; it does not say why
we need to do this. | 691 // FIXME: The above comment is not clear enough; it does not say why
we need to do this. |
| 692 namedItems.append(aliasElement); | 692 namedItems.append(aliasElement); |
| 693 } | 693 } |
| 694 } | 694 } |
| 695 if (namedItems.size() && namedItems.first() != aliasElement) | 695 if (namedItems.size() && namedItems.first() != aliasElement) |
| 696 addElementAlias(static_cast<HTMLFormControlElement*>(namedItems.first().
get()), name); | 696 addElementAlias(namedItems.first().get(), name); |
| 697 } | 697 } |
| 698 | 698 |
| 699 bool HTMLFormElement::shouldAutocomplete() const | 699 bool HTMLFormElement::shouldAutocomplete() const |
| 700 { | 700 { |
| 701 return !equalIgnoringCase(fastGetAttribute(autocompleteAttr), "off"); | 701 return !equalIgnoringCase(fastGetAttribute(autocompleteAttr), "off"); |
| 702 } | 702 } |
| 703 | 703 |
| 704 void HTMLFormElement::finishParsingChildren() | 704 void HTMLFormElement::finishParsingChildren() |
| 705 { | 705 { |
| 706 HTMLElement::finishParsingChildren(); | 706 HTMLElement::finishParsingChildren(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 735 returnValue1Enabled = true; | 735 returnValue1Enabled = true; |
| 736 returnValue1 = elements.at(0); | 736 returnValue1 = elements.at(0); |
| 737 return; | 737 return; |
| 738 } | 738 } |
| 739 | 739 |
| 740 returnValue0Enabled = true; | 740 returnValue0Enabled = true; |
| 741 returnValue0 = NamedNodesCollection::create(elements); | 741 returnValue0 = NamedNodesCollection::create(elements); |
| 742 } | 742 } |
| 743 | 743 |
| 744 } // namespace | 744 } // namespace |
| OLD | NEW |