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 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 if (!elements[i]->isFormControlElement()) | 709 if (!elements[i]->isFormControlElement()) |
709 continue; | 710 continue; |
710 HTMLFormControlElement* control = toHTMLFormControlElement(elements[i]); | 711 HTMLFormControlElement* control = toHTMLFormControlElement(elements[i]); |
711 if (control->isSuccessfulSubmitButton()) | 712 if (control->isSuccessfulSubmitButton()) |
712 return control; | 713 return control; |
713 } | 714 } |
714 | 715 |
715 return 0; | 716 return 0; |
716 } | 717 } |
717 | 718 |
718 void HTMLFormElement::setNeedsValidityCheck() | 719 void HTMLFormElement::setNeedsValidityCheck(ValidityRecalcReason reason, bool is
Valid) |
719 { | 720 { |
720 // For now unconditionally order style recalculation, which triggers | 721 bool formWasInvalid = m_invalidControlsCount > 0; |
721 // validity recalculation. In the near future, implement validity cache and | 722 switch (reason) { |
722 // recalculate style only if it changed. | 723 case ElementRemoval: |
723 pseudoStateChanged(CSSSelector::PseudoValid); | 724 if (!isValid) |
724 pseudoStateChanged(CSSSelector::PseudoInvalid); | 725 --m_invalidControlsCount; |
| 726 break; |
| 727 case ElementAddition: |
| 728 if (!isValid) |
| 729 ++m_invalidControlsCount; |
| 730 break; |
| 731 case ElementModification: |
| 732 if (isValid) |
| 733 --m_invalidControlsCount; |
| 734 else |
| 735 ++m_invalidControlsCount; |
| 736 break; |
| 737 } |
| 738 if (formWasInvalid && !m_invalidControlsCount) |
| 739 pseudoStateChanged(CSSSelector::PseudoValid); |
| 740 if (!formWasInvalid && m_invalidControlsCount) |
| 741 pseudoStateChanged(CSSSelector::PseudoInvalid); |
725 } | 742 } |
726 | 743 |
727 bool HTMLFormElement::checkValidity() | 744 bool HTMLFormElement::checkValidity() |
728 { | 745 { |
729 return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchInva
lidEvent); | 746 return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchInva
lidEvent); |
730 } | 747 } |
731 | 748 |
732 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R
efPtrWillBeMember<HTMLFormControlElement>>* unhandledInvalidControls, CheckValid
ityEventBehavior eventBehavior) | 749 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R
efPtrWillBeMember<HTMLFormControlElement>>* unhandledInvalidControls, CheckValid
ityEventBehavior eventBehavior) |
733 { | 750 { |
| 751 if (!unhandledInvalidControls && eventBehavior == CheckValidityDispatchNoEve
nt) |
| 752 return m_invalidControlsCount; |
| 753 |
734 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); | 754 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); |
735 // Copy associatedElements because event handlers called from | 755 // Copy associatedElements because event handlers called from |
736 // HTMLFormControlElement::checkValidity() might change associatedElements. | 756 // HTMLFormControlElement::checkValidity() might change associatedElements. |
737 const FormAssociatedElement::List& associatedElements = this->associatedElem
ents(); | 757 const FormAssociatedElement::List& associatedElements = this->associatedElem
ents(); |
738 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement>> elements; | 758 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement>> elements; |
739 elements.reserveCapacity(associatedElements.size()); | 759 elements.reserveCapacity(associatedElements.size()); |
740 for (unsigned i = 0; i < associatedElements.size(); ++i) | 760 for (unsigned i = 0; i < associatedElements.size(); ++i) |
741 elements.append(associatedElements[i]); | 761 elements.append(associatedElements[i]); |
742 bool hasInvalidControls = false; | 762 int invalidControlsCount = 0; |
743 for (unsigned i = 0; i < elements.size(); ++i) { | 763 for (unsigned i = 0; i < elements.size(); ++i) { |
744 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ | 764 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ |
745 HTMLFormControlElement* control = toHTMLFormControlElement(elements[
i].get()); | 765 HTMLFormControlElement* control = toHTMLFormControlElement(elements[
i].get()); |
746 if (!control->checkValidity(unhandledInvalidControls, eventBehavior)
&& control->formOwner() == this) | 766 if (!control->checkValidity(unhandledInvalidControls, eventBehavior)
&& control->formOwner() == this) |
747 hasInvalidControls = true; | 767 ++invalidControlsCount; |
748 } | 768 } |
749 } | 769 } |
750 return hasInvalidControls; | 770 if (eventBehavior == CheckValidityDispatchNoEvent) |
| 771 ASSERT(invalidControlsCount == m_invalidControlsCount); |
| 772 return invalidControlsCount; |
751 } | 773 } |
752 | 774 |
753 bool HTMLFormElement::reportValidity() | 775 bool HTMLFormElement::reportValidity() |
754 { | 776 { |
755 return validateInteractively(); | 777 return validateInteractively(); |
756 } | 778 } |
757 | 779 |
758 Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName) | 780 Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName) |
759 { | 781 { |
760 if (pastName.isEmpty() || !m_pastNamesMap) | 782 if (pastName.isEmpty() || !m_pastNamesMap) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 } | 878 } |
857 | 879 |
858 void HTMLFormElement::setDemoted(bool demoted) | 880 void HTMLFormElement::setDemoted(bool demoted) |
859 { | 881 { |
860 if (demoted) | 882 if (demoted) |
861 UseCounter::count(document(), UseCounter::DemotedFormElement); | 883 UseCounter::count(document(), UseCounter::DemotedFormElement); |
862 m_wasDemoted = demoted; | 884 m_wasDemoted = demoted; |
863 } | 885 } |
864 | 886 |
865 } // namespace | 887 } // namespace |
OLD | NEW |