| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 #endif | 71 #endif |
| 72 , m_associatedElementsAreDirty(false) | 72 , m_associatedElementsAreDirty(false) |
| 73 , m_imageElementsAreDirty(false) | 73 , m_imageElementsAreDirty(false) |
| 74 , m_hasElementsAssociatedByParser(false) | 74 , m_hasElementsAssociatedByParser(false) |
| 75 , m_didFinishParsingChildren(false) | 75 , m_didFinishParsingChildren(false) |
| 76 , m_wasUserSubmitted(false) | 76 , m_wasUserSubmitted(false) |
| 77 , m_isSubmittingOrInUserJSSubmitEvent(false) | 77 , m_isSubmittingOrInUserJSSubmitEvent(false) |
| 78 , m_shouldSubmit(false) | 78 , m_shouldSubmit(false) |
| 79 , m_isInResetFunction(false) | 79 , m_isInResetFunction(false) |
| 80 , m_wasDemoted(false) | 80 , m_wasDemoted(false) |
| 81 , m_invalidControlsCount(0) |
| 81 , m_pendingAutocompleteEventsQueue(GenericEventQueue::create(this)) | 82 , m_pendingAutocompleteEventsQueue(GenericEventQueue::create(this)) |
| 82 { | 83 { |
| 83 } | 84 } |
| 84 | 85 |
| 85 PassRefPtrWillBeRawPtr<HTMLFormElement> HTMLFormElement::create(Document& docume
nt) | 86 PassRefPtrWillBeRawPtr<HTMLFormElement> HTMLFormElement::create(Document& docume
nt) |
| 86 { | 87 { |
| 87 UseCounter::count(document, UseCounter::FormElement); | 88 UseCounter::count(document, UseCounter::FormElement); |
| 88 return adoptRefWillBeNoop(new HTMLFormElement(document)); | 89 return adoptRefWillBeNoop(new HTMLFormElement(document)); |
| 89 } | 90 } |
| 90 | 91 |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 if (!elements[i]->isFormControlElement()) | 711 if (!elements[i]->isFormControlElement()) |
| 711 continue; | 712 continue; |
| 712 HTMLFormControlElement* control = toHTMLFormControlElement(elements[i]); | 713 HTMLFormControlElement* control = toHTMLFormControlElement(elements[i]); |
| 713 if (control->isSuccessfulSubmitButton()) | 714 if (control->isSuccessfulSubmitButton()) |
| 714 return control; | 715 return control; |
| 715 } | 716 } |
| 716 | 717 |
| 717 return 0; | 718 return 0; |
| 718 } | 719 } |
| 719 | 720 |
| 720 void HTMLFormElement::setNeedsValidityCheck() | 721 void HTMLFormElement::setNeedsValidityCheck(ValidityRecalcReason reason, bool is
Valid) |
| 721 { | 722 { |
| 722 // For now unconditionally order style recalculation, which triggers | 723 bool formWasInvalid = m_invalidControlsCount > 0; |
| 723 // validity recalculation. In the near future, implement validity cache and | 724 switch (reason) { |
| 724 // recalculate style only if it changed. | 725 case ElementRemoval: |
| 725 pseudoStateChanged(CSSSelector::PseudoValid); | 726 if (!isValid) |
| 726 pseudoStateChanged(CSSSelector::PseudoInvalid); | 727 --m_invalidControlsCount; |
| 728 break; |
| 729 case ElementAddition: |
| 730 if (!isValid) |
| 731 ++m_invalidControlsCount; |
| 732 break; |
| 733 case ElementModification: |
| 734 if (isValid) |
| 735 --m_invalidControlsCount; |
| 736 else |
| 737 ++m_invalidControlsCount; |
| 738 break; |
| 739 } |
| 740 if (formWasInvalid && !m_invalidControlsCount) |
| 741 pseudoStateChanged(CSSSelector::PseudoValid); |
| 742 if (!formWasInvalid && m_invalidControlsCount) |
| 743 pseudoStateChanged(CSSSelector::PseudoInvalid); |
| 727 } | 744 } |
| 728 | 745 |
| 729 bool HTMLFormElement::checkValidity() | 746 bool HTMLFormElement::checkValidity() |
| 730 { | 747 { |
| 731 return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchInva
lidEvent); | 748 return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchInva
lidEvent); |
| 732 } | 749 } |
| 733 | 750 |
| 734 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R
efPtrWillBeMember<HTMLFormControlElement> >* unhandledInvalidControls, CheckVali
dityEventBehavior eventBehavior) | 751 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R
efPtrWillBeMember<HTMLFormControlElement> >* unhandledInvalidControls, CheckVali
dityEventBehavior eventBehavior) |
| 735 { | 752 { |
| 753 if (!unhandledInvalidControls && eventBehavior == CheckValidityDispatchNoEve
nt) |
| 754 return m_invalidControlsCount; |
| 755 |
| 736 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); | 756 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); |
| 737 // Copy associatedElements because event handlers called from | 757 // Copy associatedElements because event handlers called from |
| 738 // HTMLFormControlElement::checkValidity() might change associatedElements. | 758 // HTMLFormControlElement::checkValidity() might change associatedElements. |
| 739 const FormAssociatedElement::List& associatedElements = this->associatedElem
ents(); | 759 const FormAssociatedElement::List& associatedElements = this->associatedElem
ents(); |
| 740 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > elements; | 760 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > elements; |
| 741 elements.reserveCapacity(associatedElements.size()); | 761 elements.reserveCapacity(associatedElements.size()); |
| 742 for (unsigned i = 0; i < associatedElements.size(); ++i) | 762 for (unsigned i = 0; i < associatedElements.size(); ++i) |
| 743 elements.append(associatedElements[i]); | 763 elements.append(associatedElements[i]); |
| 744 bool hasInvalidControls = false; | 764 int invalidControlsCount = 0; |
| 745 for (unsigned i = 0; i < elements.size(); ++i) { | 765 for (unsigned i = 0; i < elements.size(); ++i) { |
| 746 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ | 766 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ |
| 747 HTMLFormControlElement* control = toHTMLFormControlElement(elements[
i].get()); | 767 HTMLFormControlElement* control = toHTMLFormControlElement(elements[
i].get()); |
| 748 if (!control->checkValidity(unhandledInvalidControls, eventBehavior)
&& control->formOwner() == this) | 768 if (!control->checkValidity(unhandledInvalidControls, eventBehavior)
&& control->formOwner() == this) |
| 749 hasInvalidControls = true; | 769 ++invalidControlsCount; |
| 750 } | 770 } |
| 751 } | 771 } |
| 752 return hasInvalidControls; | 772 if (eventBehavior == CheckValidityDispatchNoEvent) |
| 773 ASSERT(invalidControlsCount == m_invalidControlsCount); |
| 774 return invalidControlsCount; |
| 753 } | 775 } |
| 754 | 776 |
| 755 bool HTMLFormElement::reportValidity() | 777 bool HTMLFormElement::reportValidity() |
| 756 { | 778 { |
| 757 return validateInteractively(); | 779 return validateInteractively(); |
| 758 } | 780 } |
| 759 | 781 |
| 760 Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName) | 782 Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName) |
| 761 { | 783 { |
| 762 if (pastName.isEmpty() || !m_pastNamesMap) | 784 if (pastName.isEmpty() || !m_pastNamesMap) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 } | 881 } |
| 860 | 882 |
| 861 void HTMLFormElement::setDemoted(bool demoted) | 883 void HTMLFormElement::setDemoted(bool demoted) |
| 862 { | 884 { |
| 863 if (demoted) | 885 if (demoted) |
| 864 UseCounter::count(document(), UseCounter::DemotedFormElement); | 886 UseCounter::count(document(), UseCounter::DemotedFormElement); |
| 865 m_wasDemoted = demoted; | 887 m_wasDemoted = demoted; |
| 866 } | 888 } |
| 867 | 889 |
| 868 } // namespace | 890 } // namespace |
| OLD | NEW |