Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: Source/core/html/HTMLFormElement.cpp

Issue 270823004: Oilpan: Prepare to move FormAssociatedElement to Oilpan heap, part 2. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 HTMLFormElement::~HTMLFormElement() 84 HTMLFormElement::~HTMLFormElement()
85 { 85 {
86 #if !ENABLE(OILPAN) 86 #if !ENABLE(OILPAN)
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)
95 {
96 #if ENABLE(OILPAN)
97 visitor->trace(m_associatedElements);
98 #endif
99 HTMLElement::trace(visitor);
100 }
101
94 bool HTMLFormElement::rendererIsNeeded(const RenderStyle& style) 102 bool HTMLFormElement::rendererIsNeeded(const RenderStyle& style)
95 { 103 {
96 if (!m_wasDemoted) 104 if (!m_wasDemoted)
97 return HTMLElement::rendererIsNeeded(style); 105 return HTMLElement::rendererIsNeeded(style);
98 106
99 ContainerNode* node = parentNode(); 107 ContainerNode* node = parentNode();
100 if (!node || !node->renderer()) 108 if (!node || !node->renderer())
101 return HTMLElement::rendererIsNeeded(style); 109 return HTMLElement::rendererIsNeeded(style);
102 RenderObject* parentRenderer = node->renderer(); 110 RenderObject* parentRenderer = node->renderer();
103 // FIXME: Shouldn't we also check for table caption (see |formIsTablePart| b elow). 111 // FIXME: Shouldn't we also check for table caption (see |formIsTablePart| b elow).
(...skipping 18 matching lines...) Expand all
122 130
123 Node::InsertionNotificationRequest HTMLFormElement::insertedInto(ContainerNode* insertionPoint) 131 Node::InsertionNotificationRequest HTMLFormElement::insertedInto(ContainerNode* insertionPoint)
124 { 132 {
125 HTMLElement::insertedInto(insertionPoint); 133 HTMLElement::insertedInto(insertionPoint);
126 if (insertionPoint->inDocument()) 134 if (insertionPoint->inDocument())
127 this->document().didAssociateFormControl(this); 135 this->document().didAssociateFormControl(this);
128 return InsertionDone; 136 return InsertionDone;
129 } 137 }
130 138
131 template<class T> 139 template<class T>
132 void notifyFormRemovedFromTree(const Vector<T*>& elements, Node& root) 140 void notifyFormRemovedFromTree(const T& elements, Node& root)
133 { 141 {
134 size_t size = elements.size(); 142 size_t size = elements.size();
135 for (size_t i = 0; i < size; ++i) 143 for (size_t i = 0; i < size; ++i)
136 elements[i]->formRemovedFromTree(root); 144 elements[i]->formRemovedFromTree(root);
137 ASSERT(elements.size() == size); 145 ASSERT(elements.size() == size);
138 } 146 }
139 147
140 void HTMLFormElement::removedFrom(ContainerNode* insertionPoint) 148 void HTMLFormElement::removedFrom(ContainerNode* insertionPoint)
141 { 149 {
142 // We don't need to take care of form association by 'form' content 150 // We don't need to take care of form association by 'form' content
143 // attribute becuse IdTargetObserver handles it. 151 // attribute becuse IdTargetObserver handles it.
144 if (m_hasElementsAssociatedByParser) { 152 if (m_hasElementsAssociatedByParser) {
145 Node& root = highestAncestorOrSelf(); 153 Node& root = highestAncestorOrSelf();
146 if (!m_associatedElementsAreDirty) { 154 if (!m_associatedElementsAreDirty) {
147 Vector<FormAssociatedElement*> elements(associatedElements()); 155 FormAssociatedElement::List elements(associatedElements());
148 notifyFormRemovedFromTree(elements, root); 156 notifyFormRemovedFromTree(elements, root);
149 } else { 157 } else {
150 Vector<FormAssociatedElement*> elements; 158 FormAssociatedElement::List elements;
151 collectAssociatedElements(insertionPoint->highestAncestorOrSelf(), e lements); 159 collectAssociatedElements(insertionPoint->highestAncestorOrSelf(), e lements);
152 notifyFormRemovedFromTree(elements, root); 160 notifyFormRemovedFromTree(elements, root);
153 collectAssociatedElements(root, elements); 161 collectAssociatedElements(root, elements);
154 notifyFormRemovedFromTree(elements, root); 162 notifyFormRemovedFromTree(elements, root);
155 } 163 }
156 164
157 if (!m_imageElementsAreDirty) { 165 if (!m_imageElementsAreDirty) {
158 Vector<HTMLImageElement*> images(imageElements()); 166 Vector<HTMLImageElement*> images(imageElements());
159 notifyFormRemovedFromTree(images, root); 167 notifyFormRemovedFromTree(images, root);
160 } else { 168 } else {
(...skipping 15 matching lines...) Expand all
176 Node* targetNode = event->target()->toNode(); 184 Node* targetNode = event->target()->toNode();
177 if (event->eventPhase() != Event::CAPTURING_PHASE && targetNode && targetNod e != this && (event->type() == EventTypeNames::submit || event->type() == EventT ypeNames::reset)) { 185 if (event->eventPhase() != Event::CAPTURING_PHASE && targetNode && targetNod e != this && (event->type() == EventTypeNames::submit || event->type() == EventT ypeNames::reset)) {
178 event->stopPropagation(); 186 event->stopPropagation();
179 return; 187 return;
180 } 188 }
181 HTMLElement::handleLocalEvents(event); 189 HTMLElement::handleLocalEvents(event);
182 } 190 }
183 191
184 unsigned HTMLFormElement::length() const 192 unsigned HTMLFormElement::length() const
185 { 193 {
186 const Vector<FormAssociatedElement*>& elements = associatedElements(); 194 const FormAssociatedElement::List& elements = associatedElements();
187 unsigned len = 0; 195 unsigned len = 0;
188 for (unsigned i = 0; i < elements.size(); ++i) { 196 for (unsigned i = 0; i < elements.size(); ++i) {
189 if (elements[i]->isEnumeratable()) 197 if (elements[i]->isEnumeratable())
190 ++len; 198 ++len;
191 } 199 }
192 return len; 200 return len;
193 } 201 }
194 202
195 Element* HTMLFormElement::item(unsigned index) 203 Element* HTMLFormElement::item(unsigned index)
196 { 204 {
197 return elements()->item(index); 205 return elements()->item(index);
198 } 206 }
199 207
200 void HTMLFormElement::submitImplicitly(Event* event, bool fromImplicitSubmission Trigger) 208 void HTMLFormElement::submitImplicitly(Event* event, bool fromImplicitSubmission Trigger)
201 { 209 {
202 int submissionTriggerCount = 0; 210 int submissionTriggerCount = 0;
203 bool seenDefaultButton = false; 211 bool seenDefaultButton = false;
204 const Vector<FormAssociatedElement*>& elements = associatedElements(); 212 const FormAssociatedElement::List& elements = associatedElements();
205 for (unsigned i = 0; i < elements.size(); ++i) { 213 for (unsigned i = 0; i < elements.size(); ++i) {
206 FormAssociatedElement* formAssociatedElement = elements[i]; 214 FormAssociatedElement* formAssociatedElement = elements[i];
207 if (!formAssociatedElement->isFormControlElement()) 215 if (!formAssociatedElement->isFormControlElement())
208 continue; 216 continue;
209 HTMLFormControlElement* control = toHTMLFormControlElement(formAssociate dElement); 217 HTMLFormControlElement* control = toHTMLFormControlElement(formAssociate dElement);
210 if (!seenDefaultButton && control->canBeSuccessfulSubmitButton()) { 218 if (!seenDefaultButton && control->canBeSuccessfulSubmitButton()) {
211 if (fromImplicitSubmissionTrigger) 219 if (fromImplicitSubmissionTrigger)
212 seenDefaultButton = true; 220 seenDefaultButton = true;
213 if (control->isSuccessfulSubmitButton()) { 221 if (control->isSuccessfulSubmitButton()) {
214 control->dispatchSimulatedClick(event); 222 control->dispatchSimulatedClick(event);
(...skipping 23 matching lines...) Expand all
238 bool HTMLFormElement::validateInteractively(Event* event) 246 bool HTMLFormElement::validateInteractively(Event* event)
239 { 247 {
240 ASSERT(event); 248 ASSERT(event);
241 if (!document().page() || noValidate()) 249 if (!document().page() || noValidate())
242 return true; 250 return true;
243 251
244 HTMLFormControlElement* submitElement = submitElementFromEvent(event); 252 HTMLFormControlElement* submitElement = submitElementFromEvent(event);
245 if (submitElement && submitElement->formNoValidate()) 253 if (submitElement && submitElement->formNoValidate())
246 return true; 254 return true;
247 255
248 const Vector<FormAssociatedElement*>& elements = associatedElements(); 256 const FormAssociatedElement::List& elements = associatedElements();
249 for (unsigned i = 0; i < elements.size(); ++i) { 257 for (unsigned i = 0; i < elements.size(); ++i) {
250 if (elements[i]->isFormControlElement()) 258 if (elements[i]->isFormControlElement())
251 toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage( ); 259 toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage( );
252 } 260 }
253 261
254 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > unhandledInvali dControls; 262 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > unhandledInvali dControls;
255 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls)) 263 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls))
256 return true; 264 return true;
257 // Because the form has invalid controls, we abort the form submission and 265 // Because the form has invalid controls, we abort the form submission and
258 // show a validation message on a focusable form control. 266 // show a validation message on a focusable form control.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 FrameView* view = document().view(); 339 FrameView* view = document().view();
332 LocalFrame* frame = document().frame(); 340 LocalFrame* frame = document().frame();
333 if (!view || !frame || !frame->page()) 341 if (!view || !frame || !frame->page())
334 return; 342 return;
335 343
336 m_wasUserSubmitted = processingUserGesture; 344 m_wasUserSubmitted = processingUserGesture;
337 345
338 RefPtr<HTMLFormControlElement> firstSuccessfulSubmitButton; 346 RefPtr<HTMLFormControlElement> firstSuccessfulSubmitButton;
339 bool needButtonActivation = activateSubmitButton; // do we need to activate a submit button? 347 bool needButtonActivation = activateSubmitButton; // do we need to activate a submit button?
340 348
341 const Vector<FormAssociatedElement*>& elements = associatedElements(); 349 const FormAssociatedElement::List& elements = associatedElements();
342 for (unsigned i = 0; i < elements.size(); ++i) { 350 for (unsigned i = 0; i < elements.size(); ++i) {
343 FormAssociatedElement* associatedElement = elements[i]; 351 FormAssociatedElement* associatedElement = elements[i];
344 if (!associatedElement->isFormControlElement()) 352 if (!associatedElement->isFormControlElement())
345 continue; 353 continue;
346 if (needButtonActivation) { 354 if (needButtonActivation) {
347 HTMLFormControlElement* control = toHTMLFormControlElement(associate dElement); 355 HTMLFormControlElement* control = toHTMLFormControlElement(associate dElement);
348 if (control->isActivatedSubmit()) 356 if (control->isActivatedSubmit())
349 needButtonActivation = false; 357 needButtonActivation = false;
350 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu bmitButton()) 358 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu bmitButton())
351 firstSuccessfulSubmitButton = control; 359 firstSuccessfulSubmitButton = control;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 if (m_isInResetFunction || !frame) 417 if (m_isInResetFunction || !frame)
410 return; 418 return;
411 419
412 m_isInResetFunction = true; 420 m_isInResetFunction = true;
413 421
414 if (!dispatchEvent(Event::createCancelableBubble(EventTypeNames::reset))) { 422 if (!dispatchEvent(Event::createCancelableBubble(EventTypeNames::reset))) {
415 m_isInResetFunction = false; 423 m_isInResetFunction = false;
416 return; 424 return;
417 } 425 }
418 426
419 const Vector<FormAssociatedElement*>& elements = associatedElements(); 427 const FormAssociatedElement::List& elements = associatedElements();
420 for (unsigned i = 0; i < elements.size(); ++i) { 428 for (unsigned i = 0; i < elements.size(); ++i) {
421 if (elements[i]->isFormControlElement()) 429 if (elements[i]->isFormControlElement())
422 toHTMLFormControlElement(elements[i])->reset(); 430 toHTMLFormControlElement(elements[i])->reset();
423 } 431 }
424 432
425 m_isInResetFunction = false; 433 m_isInResetFunction = false;
426 } 434 }
427 435
428 void HTMLFormElement::requestAutocomplete(const Dictionary& details) 436 void HTMLFormElement::requestAutocomplete(const Dictionary& details)
429 { 437 {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 return; 537 return;
530 m_hasElementsAssociatedByParser = true; 538 m_hasElementsAssociatedByParser = true;
531 UseCounter::count(document(), UseCounter::FormAssociationByParser); 539 UseCounter::count(document(), UseCounter::FormAssociationByParser);
532 } 540 }
533 541
534 PassRefPtr<HTMLCollection> HTMLFormElement::elements() 542 PassRefPtr<HTMLCollection> HTMLFormElement::elements()
535 { 543 {
536 return ensureCachedHTMLCollection(FormControls); 544 return ensureCachedHTMLCollection(FormControls);
537 } 545 }
538 546
539 void HTMLFormElement::collectAssociatedElements(Node& root, Vector<FormAssociate dElement*>& elements) const 547 void HTMLFormElement::collectAssociatedElements(Node& root, FormAssociatedElemen t::List& elements) const
540 { 548 {
541 elements.clear(); 549 elements.clear();
542 for (HTMLElement* element = Traversal<HTMLElement>::firstWithin(root); eleme nt; element = Traversal<HTMLElement>::next(*element)) { 550 for (HTMLElement* element = Traversal<HTMLElement>::firstWithin(root); eleme nt; element = Traversal<HTMLElement>::next(*element)) {
543 FormAssociatedElement* associatedElement = 0; 551 FormAssociatedElement* associatedElement = 0;
544 if (element->isFormControlElement()) 552 if (element->isFormControlElement())
545 associatedElement = toHTMLFormControlElement(element); 553 associatedElement = toHTMLFormControlElement(element);
546 else if (isHTMLObjectElement(*element)) 554 else if (isHTMLObjectElement(*element))
547 associatedElement = toHTMLObjectElement(element); 555 associatedElement = toHTMLObjectElement(element);
548 else 556 else
549 continue; 557 continue;
550 if (associatedElement->form()== this) 558 if (associatedElement->form()== this)
551 elements.append(associatedElement); 559 elements.append(associatedElement);
552 } 560 }
553 } 561 }
554 562
555 // This function should be const conceptually. However we update some fields 563 // This function should be const conceptually. However we update some fields
556 // because of lazy evaluation. 564 // because of lazy evaluation.
557 const Vector<FormAssociatedElement*>& HTMLFormElement::associatedElements() cons t 565 const FormAssociatedElement::List& HTMLFormElement::associatedElements() const
558 { 566 {
559 if (!m_associatedElementsAreDirty) 567 if (!m_associatedElementsAreDirty)
560 return m_associatedElements; 568 return m_associatedElements;
561 HTMLFormElement* mutableThis = const_cast<HTMLFormElement*>(this); 569 HTMLFormElement* mutableThis = const_cast<HTMLFormElement*>(this);
562 Node* scope = mutableThis; 570 Node* scope = mutableThis;
563 if (m_hasElementsAssociatedByParser) 571 if (m_hasElementsAssociatedByParser)
564 scope = &highestAncestorOrSelf(); 572 scope = &highestAncestorOrSelf();
565 if (inDocument() && treeScope().idTargetObserverRegistry().hasObservers(fast GetAttribute(idAttr))) 573 if (inDocument() && treeScope().idTargetObserverRegistry().hasObservers(fast GetAttribute(idAttr)))
566 scope = &treeScope().rootNode(); 574 scope = &treeScope().rootNode();
567 ASSERT(scope); 575 ASSERT(scope);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 setAttribute(methodAttr, value); 629 setAttribute(methodAttr, value);
622 } 630 }
623 631
624 bool HTMLFormElement::wasUserSubmitted() const 632 bool HTMLFormElement::wasUserSubmitted() const
625 { 633 {
626 return m_wasUserSubmitted; 634 return m_wasUserSubmitted;
627 } 635 }
628 636
629 HTMLFormControlElement* HTMLFormElement::defaultButton() const 637 HTMLFormControlElement* HTMLFormElement::defaultButton() const
630 { 638 {
631 const Vector<FormAssociatedElement*>& elements = associatedElements(); 639 const FormAssociatedElement::List& elements = associatedElements();
632 for (unsigned i = 0; i < elements.size(); ++i) { 640 for (unsigned i = 0; i < elements.size(); ++i) {
633 if (!elements[i]->isFormControlElement()) 641 if (!elements[i]->isFormControlElement())
634 continue; 642 continue;
635 HTMLFormControlElement* control = toHTMLFormControlElement(elements[i]); 643 HTMLFormControlElement* control = toHTMLFormControlElement(elements[i]);
636 if (control->isSuccessfulSubmitButton()) 644 if (control->isSuccessfulSubmitButton())
637 return control; 645 return control;
638 } 646 }
639 647
640 return 0; 648 return 0;
641 } 649 }
642 650
643 bool HTMLFormElement::checkValidity() 651 bool HTMLFormElement::checkValidity()
644 { 652 {
645 return !checkInvalidControlsAndCollectUnhandled(0); 653 return !checkInvalidControlsAndCollectUnhandled(0);
646 } 654 }
647 655
648 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R efPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls) 656 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R efPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls)
649 { 657 {
650 RefPtr<HTMLFormElement> protector(this); 658 RefPtr<HTMLFormElement> protector(this);
651 // Copy associatedElements because event handlers called from 659 // Copy associatedElements because event handlers called from
652 // HTMLFormControlElement::checkValidity() might change associatedElements. 660 // HTMLFormControlElement::checkValidity() might change associatedElements.
653 const Vector<FormAssociatedElement*>& associatedElements = this->associatedE lements(); 661 const FormAssociatedElement::List& associatedElements = this->associatedElem ents();
654 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > elements; 662 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > elements;
655 elements.reserveCapacity(associatedElements.size()); 663 elements.reserveCapacity(associatedElements.size());
656 for (unsigned i = 0; i < associatedElements.size(); ++i) 664 for (unsigned i = 0; i < associatedElements.size(); ++i)
657 elements.append(associatedElements[i]); 665 elements.append(associatedElements[i]);
658 bool hasInvalidControls = false; 666 bool hasInvalidControls = false;
659 for (unsigned i = 0; i < elements.size(); ++i) { 667 for (unsigned i = 0; i < elements.size(); ++i) {
660 if (elements[i]->form() == this && elements[i]->isFormControlElement()) { 668 if (elements[i]->form() == this && elements[i]->isFormControlElement()) {
661 HTMLFormControlElement* control = toHTMLFormControlElement(elements[ i].get()); 669 HTMLFormControlElement* control = toHTMLFormControlElement(elements[ i].get());
662 if (!control->checkValidity(unhandledInvalidControls) && control->fo rmOwner() == this) 670 if (!control->checkValidity(unhandledInvalidControls) && control->fo rmOwner() == this)
663 hasInvalidControls = true; 671 hasInvalidControls = true;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 } 778 }
771 779
772 void HTMLFormElement::setDemoted(bool demoted) 780 void HTMLFormElement::setDemoted(bool demoted)
773 { 781 {
774 if (demoted) 782 if (demoted)
775 UseCounter::count(document(), UseCounter::DemotedFormElement); 783 UseCounter::count(document(), UseCounter::DemotedFormElement);
776 m_wasDemoted = demoted; 784 m_wasDemoted = demoted;
777 } 785 }
778 786
779 } // namespace 787 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698