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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // With Oilpan, either removedFrom is called or the document and | 87 // With Oilpan, either removedFrom is called or the document and |
88 // form controller are dead as well and there is no need to remove | 88 // form controller are dead as well and there is no need to remove |
89 // this form element from it. | 89 // this form element from it. |
90 document().formController().willDeleteForm(this); | 90 document().formController().willDeleteForm(this); |
91 #endif | 91 #endif |
92 } | 92 } |
93 | 93 |
94 void HTMLFormElement::trace(Visitor* visitor) | 94 void HTMLFormElement::trace(Visitor* visitor) |
95 { | 95 { |
96 #if ENABLE(OILPAN) | 96 #if ENABLE(OILPAN) |
| 97 visitor->trace(m_pastNamesMap); |
97 visitor->trace(m_associatedElements); | 98 visitor->trace(m_associatedElements); |
98 #endif | 99 #endif |
99 HTMLElement::trace(visitor); | 100 HTMLElement::trace(visitor); |
100 } | 101 } |
101 | 102 |
102 bool HTMLFormElement::rendererIsNeeded(const RenderStyle& style) | 103 bool HTMLFormElement::rendererIsNeeded(const RenderStyle& style) |
103 { | 104 { |
104 if (!m_wasDemoted) | 105 if (!m_wasDemoted) |
105 return HTMLElement::rendererIsNeeded(style); | 106 return HTMLElement::rendererIsNeeded(style); |
106 | 107 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > unhandledInvali
dControls; | 263 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > unhandledInvali
dControls; |
263 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls)) | 264 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls)) |
264 return true; | 265 return true; |
265 // Because the form has invalid controls, we abort the form submission and | 266 // Because the form has invalid controls, we abort the form submission and |
266 // show a validation message on a focusable form control. | 267 // show a validation message on a focusable form control. |
267 | 268 |
268 // Needs to update layout now because we'd like to call isFocusable(), which | 269 // Needs to update layout now because we'd like to call isFocusable(), which |
269 // has !renderer()->needsLayout() assertion. | 270 // has !renderer()->needsLayout() assertion. |
270 document().updateLayoutIgnorePendingStylesheets(); | 271 document().updateLayoutIgnorePendingStylesheets(); |
271 | 272 |
272 RefPtr<HTMLFormElement> protector(this); | 273 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); |
273 // Focus on the first focusable control and show a validation message. | 274 // Focus on the first focusable control and show a validation message. |
274 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { | 275 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { |
275 FormAssociatedElement* unhandledAssociatedElement = unhandledInvalidCont
rols[i].get(); | 276 FormAssociatedElement* unhandledAssociatedElement = unhandledInvalidCont
rols[i].get(); |
276 HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); | 277 HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); |
277 if (unhandled->isFocusable() && unhandled->inDocument()) { | 278 if (unhandled->isFocusable() && unhandled->inDocument()) { |
278 unhandled->scrollIntoViewIfNeeded(false); | 279 unhandled->scrollIntoViewIfNeeded(false); |
279 unhandled->focus(); | 280 unhandled->focus(); |
280 if (unhandled->isFormControlElement()) | 281 if (unhandled->isFormControlElement()) |
281 toHTMLFormControlElement(unhandled)->updateVisibleValidationMess
age(); | 282 toHTMLFormControlElement(unhandled)->updateVisibleValidationMess
age(); |
282 break; | 283 break; |
283 } | 284 } |
284 } | 285 } |
285 // Warn about all of unfocusable controls. | 286 // Warn about all of unfocusable controls. |
286 if (document().frame()) { | 287 if (document().frame()) { |
287 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { | 288 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { |
288 FormAssociatedElement* unhandledAssociatedElement = unhandledInvalid
Controls[i].get(); | 289 FormAssociatedElement* unhandledAssociatedElement = unhandledInvalid
Controls[i].get(); |
289 HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); | 290 HTMLElement* unhandled = toHTMLElement(unhandledAssociatedElement); |
290 if (unhandled->isFocusable() && unhandled->inDocument()) | 291 if (unhandled->isFocusable() && unhandled->inDocument()) |
291 continue; | 292 continue; |
292 String message("An invalid form control with name='%name' is not foc
usable."); | 293 String message("An invalid form control with name='%name' is not foc
usable."); |
293 message.replace("%name", unhandledAssociatedElement->name()); | 294 message.replace("%name", unhandledAssociatedElement->name()); |
294 document().addConsoleMessage(RenderingMessageSource, ErrorMessageLev
el, message); | 295 document().addConsoleMessage(RenderingMessageSource, ErrorMessageLev
el, message); |
295 } | 296 } |
296 } | 297 } |
297 return false; | 298 return false; |
298 } | 299 } |
299 | 300 |
300 void HTMLFormElement::prepareForSubmission(Event* event) | 301 void HTMLFormElement::prepareForSubmission(Event* event) |
301 { | 302 { |
302 RefPtr<HTMLFormElement> protector(this); | 303 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); |
303 LocalFrame* frame = document().frame(); | 304 LocalFrame* frame = document().frame(); |
304 if (!frame) | 305 if (!frame) |
305 return; | 306 return; |
306 | 307 |
307 // Interactive validation must be done before dispatching the submit event. | 308 // Interactive validation must be done before dispatching the submit event. |
308 if (!validateInteractively(event)) | 309 if (!validateInteractively(event)) |
309 return; | 310 return; |
310 | 311 |
311 frame->loader().client()->dispatchWillSendSubmitEvent(this); | 312 frame->loader().client()->dispatchWillSendSubmitEvent(this); |
312 | 313 |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 return 0; | 649 return 0; |
649 } | 650 } |
650 | 651 |
651 bool HTMLFormElement::checkValidity() | 652 bool HTMLFormElement::checkValidity() |
652 { | 653 { |
653 return !checkInvalidControlsAndCollectUnhandled(0); | 654 return !checkInvalidControlsAndCollectUnhandled(0); |
654 } | 655 } |
655 | 656 |
656 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R
efPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls) | 657 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R
efPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls) |
657 { | 658 { |
658 RefPtr<HTMLFormElement> protector(this); | 659 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); |
659 // Copy associatedElements because event handlers called from | 660 // Copy associatedElements because event handlers called from |
660 // HTMLFormControlElement::checkValidity() might change associatedElements. | 661 // HTMLFormControlElement::checkValidity() might change associatedElements. |
661 const FormAssociatedElement::List& associatedElements = this->associatedElem
ents(); | 662 const FormAssociatedElement::List& associatedElements = this->associatedElem
ents(); |
662 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > elements; | 663 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > elements; |
663 elements.reserveCapacity(associatedElements.size()); | 664 elements.reserveCapacity(associatedElements.size()); |
664 for (unsigned i = 0; i < associatedElements.size(); ++i) | 665 for (unsigned i = 0; i < associatedElements.size(); ++i) |
665 elements.append(associatedElements[i]); | 666 elements.append(associatedElements[i]); |
666 bool hasInvalidControls = false; | 667 bool hasInvalidControls = false; |
667 for (unsigned i = 0; i < elements.size(); ++i) { | 668 for (unsigned i = 0; i < elements.size(); ++i) { |
668 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ | 669 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ |
(...skipping 23 matching lines...) Expand all Loading... |
692 } | 693 } |
693 #endif | 694 #endif |
694 return element; | 695 return element; |
695 } | 696 } |
696 | 697 |
697 void HTMLFormElement::addToPastNamesMap(Element* element, const AtomicString& pa
stName) | 698 void HTMLFormElement::addToPastNamesMap(Element* element, const AtomicString& pa
stName) |
698 { | 699 { |
699 if (pastName.isEmpty()) | 700 if (pastName.isEmpty()) |
700 return; | 701 return; |
701 if (!m_pastNamesMap) | 702 if (!m_pastNamesMap) |
702 m_pastNamesMap = adoptPtr(new PastNamesMap); | 703 m_pastNamesMap = adoptPtrWillBeNoop(new PastNamesMap); |
703 m_pastNamesMap->set(pastName, element); | 704 m_pastNamesMap->set(pastName, element); |
704 } | 705 } |
705 | 706 |
706 void HTMLFormElement::removeFromPastNamesMap(HTMLElement& element) | 707 void HTMLFormElement::removeFromPastNamesMap(HTMLElement& element) |
707 { | 708 { |
708 if (!m_pastNamesMap) | 709 if (!m_pastNamesMap) |
709 return; | 710 return; |
710 PastNamesMap::iterator end = m_pastNamesMap->end(); | 711 PastNamesMap::iterator end = m_pastNamesMap->end(); |
711 for (PastNamesMap::iterator it = m_pastNamesMap->begin(); it != end; ++it) { | 712 for (PastNamesMap::iterator it = m_pastNamesMap->begin(); it != end; ++it) { |
712 if (it->value == &element) { | 713 if (it->value.get() == &element) { |
713 it->value = 0; | 714 it->value = nullptr; |
714 // Keep looping. Single element can have multiple names. | 715 // Keep looping. Single element can have multiple names. |
715 } | 716 } |
716 } | 717 } |
717 } | 718 } |
718 | 719 |
719 void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<E
lement> >& namedItems) | 720 void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<E
lement> >& namedItems) |
720 { | 721 { |
721 // http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#do
m-form-nameditem | 722 // http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#do
m-form-nameditem |
722 elements()->namedItems(name, namedItems); | 723 elements()->namedItems(name, namedItems); |
723 | 724 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 } | 779 } |
779 | 780 |
780 void HTMLFormElement::setDemoted(bool demoted) | 781 void HTMLFormElement::setDemoted(bool demoted) |
781 { | 782 { |
782 if (demoted) | 783 if (demoted) |
783 UseCounter::count(document(), UseCounter::DemotedFormElement); | 784 UseCounter::count(document(), UseCounter::DemotedFormElement); |
784 m_wasDemoted = demoted; | 785 m_wasDemoted = demoted; |
785 } | 786 } |
786 | 787 |
787 } // namespace | 788 } // namespace |
OLD | NEW |