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