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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return elements()->item(index); | 177 return elements()->item(index); |
178 } | 178 } |
179 | 179 |
180 void HTMLFormElement::submitImplicitly(Event* event, bool fromImplicitSubmission
Trigger) | 180 void HTMLFormElement::submitImplicitly(Event* event, bool fromImplicitSubmission
Trigger) |
181 { | 181 { |
182 int submissionTriggerCount = 0; | 182 int submissionTriggerCount = 0; |
183 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 183 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
184 FormAssociatedElement* formAssociatedElement = m_associatedElements[i]; | 184 FormAssociatedElement* formAssociatedElement = m_associatedElements[i]; |
185 if (!formAssociatedElement->isFormControlElement()) | 185 if (!formAssociatedElement->isFormControlElement()) |
186 continue; | 186 continue; |
187 HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement
*>(formAssociatedElement); | 187 Handle<HTMLFormControlElement> formElement(static_cast<HTMLFormControlEl
ement*>(formAssociatedElement)); |
188 if (formElement->isSuccessfulSubmitButton()) { | 188 if (formElement->isSuccessfulSubmitButton()) { |
189 if (formElement->renderer()) { | 189 if (formElement->renderer()) { |
190 formElement->dispatchSimulatedClick(event); | 190 formElement->dispatchSimulatedClick(event); |
191 return; | 191 return; |
192 } | 192 } |
193 } else if (formElement->canTriggerImplicitSubmission()) | 193 } else if (formElement->canTriggerImplicitSubmission()) |
194 ++submissionTriggerCount; | 194 ++submissionTriggerCount; |
195 } | 195 } |
196 if (fromImplicitSubmissionTrigger && submissionTriggerCount == 1) | 196 if (fromImplicitSubmissionTrigger && submissionTriggerCount == 1) |
197 prepareForSubmission(event); | 197 prepareForSubmission(event); |
198 } | 198 } |
199 | 199 |
200 static inline HTMLFormControlElement* submitElementFromEvent(const Event* event) | 200 static inline Result<HTMLFormControlElement> submitElementFromEvent(const Event*
event) |
201 { | 201 { |
202 for (Node* node = event->target()->toNode(); node; node = node->parentNode()
) { | 202 for (Node* node = event->target()->toNode(); node; node = node->parentNode()
) { |
203 if (node->isElementNode() && toElement(node)->isFormControlElement()) | 203 if (node->isElementNode() && toElement(node)->isFormControlElement()) |
204 return static_cast<HTMLFormControlElement*>(node); | 204 return Handle<HTMLFormControlElement>(static_cast<HTMLFormControlEle
ment*>(node)); |
205 } | 205 } |
206 return 0; | 206 return nullptr; |
207 } | 207 } |
208 | 208 |
209 bool HTMLFormElement::validateInteractively(Event* event) | 209 bool HTMLFormElement::validateInteractively(Event* event) |
210 { | 210 { |
211 ASSERT(event); | 211 ASSERT(event); |
212 if (!document()->page() || !document()->page()->settings()->interactiveFormV
alidationEnabled() || noValidate()) | 212 if (!document()->page() || !document()->page()->settings()->interactiveFormV
alidationEnabled() || noValidate()) |
213 return true; | 213 return true; |
214 | 214 |
215 HTMLFormControlElement* submitElement = submitElementFromEvent(event); | 215 Handle<HTMLFormControlElement> submitElement = submitElementFromEvent(event)
; |
216 if (submitElement && submitElement->formNoValidate()) | 216 if (submitElement && submitElement->formNoValidate()) |
217 return true; | 217 return true; |
218 | 218 |
219 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 219 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
220 if (m_associatedElements[i]->isFormControlElement()) | 220 if (m_associatedElements[i]->isFormControlElement()) |
221 static_cast<HTMLFormControlElement*>(m_associatedElements[i])->hideV
isibleValidationMessage(); | 221 static_cast<HTMLFormControlElement*>(m_associatedElements[i])->hideV
isibleValidationMessage(); |
222 } | 222 } |
223 | 223 |
224 Vector<RefPtr<FormAssociatedElement> > unhandledInvalidControls; | 224 Vector<RefPtr<FormAssociatedElement> > unhandledInvalidControls; |
225 if (!checkInvalidControlsAndCollectUnhandled(unhandledInvalidControls)) | 225 if (!checkInvalidControlsAndCollectUnhandled(unhandledInvalidControls)) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 { | 304 { |
305 ASSERT_ARG(fieldNamesAndValues, fieldNamesAndValues.isEmpty()); | 305 ASSERT_ARG(fieldNamesAndValues, fieldNamesAndValues.isEmpty()); |
306 | 306 |
307 fieldNamesAndValues.reserveCapacity(m_associatedElements.size()); | 307 fieldNamesAndValues.reserveCapacity(m_associatedElements.size()); |
308 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 308 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
309 FormAssociatedElement* control = m_associatedElements[i]; | 309 FormAssociatedElement* control = m_associatedElements[i]; |
310 HTMLElement* element = toHTMLElement(control); | 310 HTMLElement* element = toHTMLElement(control); |
311 if (!element->hasLocalName(inputTag)) | 311 if (!element->hasLocalName(inputTag)) |
312 continue; | 312 continue; |
313 | 313 |
314 HTMLInputElement* input = static_cast<HTMLInputElement*>(control); | 314 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(control)); |
315 if (!input->isTextField()) | 315 if (!input->isTextField()) |
316 continue; | 316 continue; |
317 | 317 |
318 fieldNamesAndValues.append(make_pair(input->name().string(), input->valu
e())); | 318 fieldNamesAndValues.append(make_pair(input->name().string(), input->valu
e())); |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce
ssingUserGesture, FormSubmissionTrigger formSubmissionTrigger) | 322 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce
ssingUserGesture, FormSubmissionTrigger formSubmissionTrigger) |
323 { | 323 { |
324 FrameView* view = document()->view(); | 324 FrameView* view = document()->view(); |
325 Frame* frame = document()->frame(); | 325 Frame* frame = document()->frame(); |
326 if (!view || !frame) | 326 if (!view || !frame) |
327 return; | 327 return; |
328 | 328 |
329 if (m_isSubmittingOrPreparingForSubmission) { | 329 if (m_isSubmittingOrPreparingForSubmission) { |
330 m_shouldSubmit = true; | 330 m_shouldSubmit = true; |
331 return; | 331 return; |
332 } | 332 } |
333 | 333 |
334 m_isSubmittingOrPreparingForSubmission = true; | 334 m_isSubmittingOrPreparingForSubmission = true; |
335 m_wasUserSubmitted = processingUserGesture; | 335 m_wasUserSubmitted = processingUserGesture; |
336 | 336 |
337 HTMLFormControlElement* firstSuccessfulSubmitButton = 0; | 337 Handle<HTMLFormControlElement> firstSuccessfulSubmitButton; |
338 bool needButtonActivation = activateSubmitButton; // do we need to activate
a submit button? | 338 bool needButtonActivation = activateSubmitButton; // do we need to activate
a submit button? |
339 | 339 |
340 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 340 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
341 FormAssociatedElement* associatedElement = m_associatedElements[i]; | 341 FormAssociatedElement* associatedElement = m_associatedElements[i]; |
342 if (!associatedElement->isFormControlElement()) | 342 if (!associatedElement->isFormControlElement()) |
343 continue; | 343 continue; |
344 if (needButtonActivation) { | 344 if (needButtonActivation) { |
345 HTMLFormControlElement* control = static_cast<HTMLFormControlElement
*>(associatedElement); | 345 Handle<HTMLFormControlElement> control(static_cast<HTMLFormControlEl
ement*>(associatedElement)); |
346 if (control->isActivatedSubmit()) | 346 if (control->isActivatedSubmit()) |
347 needButtonActivation = false; | 347 needButtonActivation = false; |
348 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu
bmitButton()) | 348 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu
bmitButton()) |
349 firstSuccessfulSubmitButton = control; | 349 firstSuccessfulSubmitButton = control; |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 if (needButtonActivation && firstSuccessfulSubmitButton) | 353 if (needButtonActivation && firstSuccessfulSubmitButton) |
354 firstSuccessfulSubmitButton->setActivatedSubmit(true); | 354 firstSuccessfulSubmitButton->setActivatedSubmit(true); |
355 | 355 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 String HTMLFormElement::target() const | 612 String HTMLFormElement::target() const |
613 { | 613 { |
614 return getAttribute(targetAttr); | 614 return getAttribute(targetAttr); |
615 } | 615 } |
616 | 616 |
617 bool HTMLFormElement::wasUserSubmitted() const | 617 bool HTMLFormElement::wasUserSubmitted() const |
618 { | 618 { |
619 return m_wasUserSubmitted; | 619 return m_wasUserSubmitted; |
620 } | 620 } |
621 | 621 |
622 HTMLFormControlElement* HTMLFormElement::defaultButton() const | 622 Result<HTMLFormControlElement> HTMLFormElement::defaultButton() const |
623 { | 623 { |
624 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { | 624 for (unsigned i = 0; i < m_associatedElements.size(); ++i) { |
625 if (!m_associatedElements[i]->isFormControlElement()) | 625 if (!m_associatedElements[i]->isFormControlElement()) |
626 continue; | 626 continue; |
627 HTMLFormControlElement* control = static_cast<HTMLFormControlElement*>(m
_associatedElements[i]); | 627 Handle<HTMLFormControlElement> control(static_cast<HTMLFormControlElemen
t*>(m_associatedElements[i])); |
628 if (control->isSuccessfulSubmitButton()) | 628 if (control->isSuccessfulSubmitButton()) |
629 return control; | 629 return control; |
630 } | 630 } |
631 | 631 |
632 return 0; | 632 return nullptr; |
633 } | 633 } |
634 | 634 |
635 bool HTMLFormElement::checkValidity() | 635 bool HTMLFormElement::checkValidity() |
636 { | 636 { |
637 Vector<RefPtr<FormAssociatedElement> > controls; | 637 Vector<RefPtr<FormAssociatedElement> > controls; |
638 return !checkInvalidControlsAndCollectUnhandled(controls); | 638 return !checkInvalidControlsAndCollectUnhandled(controls); |
639 } | 639 } |
640 | 640 |
641 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<Form
AssociatedElement> >& unhandledInvalidControls) | 641 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<Form
AssociatedElement> >& unhandledInvalidControls) |
642 { | 642 { |
643 RefPtr<HTMLFormElement> protector(this); | 643 RefPtr<HTMLFormElement> protector(this); |
644 // Copy m_associatedElements because event handlers called from | 644 // Copy m_associatedElements because event handlers called from |
645 // HTMLFormControlElement::checkValidity() might change m_associatedElements
. | 645 // HTMLFormControlElement::checkValidity() might change m_associatedElements
. |
646 Vector<RefPtr<FormAssociatedElement> > elements; | 646 Vector<RefPtr<FormAssociatedElement> > elements; |
647 elements.reserveCapacity(m_associatedElements.size()); | 647 elements.reserveCapacity(m_associatedElements.size()); |
648 for (unsigned i = 0; i < m_associatedElements.size(); ++i) | 648 for (unsigned i = 0; i < m_associatedElements.size(); ++i) |
649 elements.append(m_associatedElements[i]); | 649 elements.append(m_associatedElements[i]); |
650 bool hasInvalidControls = false; | 650 bool hasInvalidControls = false; |
651 for (unsigned i = 0; i < elements.size(); ++i) { | 651 for (unsigned i = 0; i < elements.size(); ++i) { |
652 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ | 652 if (elements[i]->form() == this && elements[i]->isFormControlElement())
{ |
653 HTMLFormControlElement* control = static_cast<HTMLFormControlElement
*>(elements[i].get()); | 653 Handle<HTMLFormControlElement> control(static_cast<HTMLFormControlEl
ement*>(elements[i].get())); |
654 if (!control->checkValidity(&unhandledInvalidControls) && control->f
orm() == this) | 654 if (!control->checkValidity(&unhandledInvalidControls) && control->f
orm() == this) |
655 hasInvalidControls = true; | 655 hasInvalidControls = true; |
656 } | 656 } |
657 } | 657 } |
658 return hasInvalidControls; | 658 return hasInvalidControls; |
659 } | 659 } |
660 | 660 |
661 HTMLFormControlElement* HTMLFormElement::elementForAlias(const AtomicString& ali
as) | 661 Result<HTMLFormControlElement> HTMLFormElement::elementForAlias(const AtomicStri
ng& alias) |
662 { | 662 { |
663 if (alias.isEmpty() || !m_elementAliases) | 663 if (alias.isEmpty() || !m_elementAliases) |
664 return 0; | 664 return nullptr; |
665 return m_elementAliases->get(alias.impl()).get(); | 665 return m_elementAliases->get(alias.impl()); |
666 } | 666 } |
667 | 667 |
668 void HTMLFormElement::addElementAlias(HTMLFormControlElement* element, const Ato
micString& alias) | 668 void HTMLFormElement::addElementAlias(Handle<HTMLFormControlElement> element, co
nst AtomicString& alias) |
669 { | 669 { |
670 if (alias.isEmpty()) | 670 if (alias.isEmpty()) |
671 return; | 671 return; |
672 if (!m_elementAliases) | 672 if (!m_elementAliases) |
673 m_elementAliases = adoptPtr(new AliasMap); | 673 m_elementAliases = adoptPtr(new AliasMap); |
674 m_elementAliases->set(alias.impl(), element); | 674 m_elementAliases->set(alias.impl(), element); |
675 } | 675 } |
676 | 676 |
677 void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<N
ode> >& namedItems) | 677 void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<N
ode> >& namedItems) |
678 { | 678 { |
679 elements()->namedItems(name, namedItems); | 679 elements()->namedItems(name, namedItems); |
680 | 680 |
681 HTMLFormControlElement* aliasElement = elementForAlias(name); | 681 Handle<HTMLFormControlElement> aliasElement = elementForAlias(name); |
682 if (aliasElement) { | 682 if (aliasElement) { |
683 if (namedItems.find(aliasElement) == notFound) { | 683 if (namedItems.find(aliasElement.passRefPtr()) == notFound) { |
684 // We have seen it before but it is gone now. Still, we need to retu
rn it. | 684 // We have seen it before but it is gone now. Still, we need to retu
rn it. |
685 // FIXME: The above comment is not clear enough; it does not say why
we need to do this. | 685 // FIXME: The above comment is not clear enough; it does not say why
we need to do this. |
686 namedItems.append(aliasElement); | 686 namedItems.append(aliasElement.passRefPtr()); |
687 } | 687 } |
688 } | 688 } |
689 if (namedItems.size() && namedItems.first() != aliasElement) | 689 if (namedItems.size() && namedItems.first().get() != aliasElement.raw()) |
690 addElementAlias(static_cast<HTMLFormControlElement*>(namedItems.first().
get()), name); | 690 addElementAlias(Handle<HTMLFormControlElement>(static_cast<HTMLFormContr
olElement*>(namedItems.first().get())), name); |
691 } | 691 } |
692 | 692 |
693 bool HTMLFormElement::shouldAutocomplete() const | 693 bool HTMLFormElement::shouldAutocomplete() const |
694 { | 694 { |
695 return !equalIgnoringCase(fastGetAttribute(autocompleteAttr), "off"); | 695 return !equalIgnoringCase(fastGetAttribute(autocompleteAttr), "off"); |
696 } | 696 } |
697 | 697 |
698 void HTMLFormElement::finishParsingChildren() | 698 void HTMLFormElement::finishParsingChildren() |
699 { | 699 { |
700 HTMLElement::finishParsingChildren(); | 700 HTMLElement::finishParsingChildren(); |
701 document()->formController()->restoreControlStateIn(*this); | 701 document()->formController()->restoreControlStateIn(*this); |
702 } | 702 } |
703 | 703 |
704 void HTMLFormElement::copyNonAttributePropertiesFromElement(const Element& sourc
e) | 704 void HTMLFormElement::copyNonAttributePropertiesFromElement(const Element& sourc
e) |
705 { | 705 { |
706 m_wasDemoted = static_cast<const HTMLFormElement&>(source).m_wasDemoted; | 706 m_wasDemoted = static_cast<const HTMLFormElement&>(source).m_wasDemoted; |
707 HTMLElement::copyNonAttributePropertiesFromElement(source); | 707 HTMLElement::copyNonAttributePropertiesFromElement(source); |
708 } | 708 } |
709 | 709 |
710 } // namespace | 710 } // namespace |
OLD | NEW |