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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_pendingAutocompleteEventsQueue(GenericEventQueue::create(this)) 80 , m_pendingAutocompleteEventsQueue(GenericEventQueue::create(this))
81 { 81 {
82 } 82 }
83 83
84 PassRefPtrWillBeRawPtr<HTMLFormElement> HTMLFormElement::create(Document& docume nt) 84 RawPtr<HTMLFormElement> HTMLFormElement::create(Document& document)
85 { 85 {
86 UseCounter::count(document, UseCounter::FormElement); 86 UseCounter::count(document, UseCounter::FormElement);
87 return adoptRefWillBeNoop(new HTMLFormElement(document)); 87 return (new HTMLFormElement(document));
88 } 88 }
89 89
90 HTMLFormElement::~HTMLFormElement() 90 HTMLFormElement::~HTMLFormElement()
91 { 91 {
92 #if !ENABLE(OILPAN) 92 #if !ENABLE(OILPAN)
93 // With Oilpan, either removedFrom is called or the document and 93 // With Oilpan, either removedFrom is called or the document and
94 // form controller are dead as well and there is no need to remove 94 // form controller are dead as well and there is no need to remove
95 // this form element from it. 95 // this form element from it.
96 document().formController().willDeleteForm(this); 96 document().formController().willDeleteForm(this);
97 #endif 97 #endif
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 notifyFormRemovedFromTree(elements, root); 175 notifyFormRemovedFromTree(elements, root);
176 } else { 176 } else {
177 FormAssociatedElement::List elements; 177 FormAssociatedElement::List elements;
178 collectAssociatedElements(NodeTraversal::highestAncestorOrSelf(*inse rtionPoint), elements); 178 collectAssociatedElements(NodeTraversal::highestAncestorOrSelf(*inse rtionPoint), elements);
179 notifyFormRemovedFromTree(elements, root); 179 notifyFormRemovedFromTree(elements, root);
180 collectAssociatedElements(root, elements); 180 collectAssociatedElements(root, elements);
181 notifyFormRemovedFromTree(elements, root); 181 notifyFormRemovedFromTree(elements, root);
182 } 182 }
183 183
184 if (!m_imageElementsAreDirty) { 184 if (!m_imageElementsAreDirty) {
185 WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>> images(imageE lements()); 185 HeapVector<Member<HTMLImageElement>> images(imageElements());
186 notifyFormRemovedFromTree(images, root); 186 notifyFormRemovedFromTree(images, root);
187 } else { 187 } else {
188 WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>> images; 188 HeapVector<Member<HTMLImageElement>> images;
189 collectImageElements(NodeTraversal::highestAncestorOrSelf(*insertion Point), images); 189 collectImageElements(NodeTraversal::highestAncestorOrSelf(*insertion Point), images);
190 notifyFormRemovedFromTree(images, root); 190 notifyFormRemovedFromTree(images, root);
191 collectImageElements(root, images); 191 collectImageElements(root, images);
192 notifyFormRemovedFromTree(images, root); 192 notifyFormRemovedFromTree(images, root);
193 } 193 }
194 } 194 }
195 #if ENABLE(OILPAN) 195 #if ENABLE(OILPAN)
196 document().formController().willDeleteForm(this); 196 document().formController().willDeleteForm(this);
197 #endif 197 #endif
198 HTMLElement::removedFrom(insertionPoint); 198 HTMLElement::removedFrom(insertionPoint);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 264 }
265 265
266 bool HTMLFormElement::validateInteractively() 266 bool HTMLFormElement::validateInteractively()
267 { 267 {
268 const FormAssociatedElement::List& elements = associatedElements(); 268 const FormAssociatedElement::List& elements = associatedElements();
269 for (unsigned i = 0; i < elements.size(); ++i) { 269 for (unsigned i = 0; i < elements.size(); ++i) {
270 if (elements[i]->isFormControlElement()) 270 if (elements[i]->isFormControlElement())
271 toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage( ); 271 toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage( );
272 } 272 }
273 273
274 WillBeHeapVector<RefPtrWillBeMember<HTMLFormControlElement>> unhandledInvali dControls; 274 HeapVector<Member<HTMLFormControlElement>> unhandledInvalidControls;
275 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls, Chec kValidityDispatchInvalidEvent)) 275 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls, Chec kValidityDispatchInvalidEvent))
276 return true; 276 return true;
277 // Because the form has invalid controls, we abort the form submission and 277 // Because the form has invalid controls, we abort the form submission and
278 // show a validation message on a focusable form control. 278 // show a validation message on a focusable form control.
279 279
280 // Needs to update layout now because we'd like to call isFocusable(), which 280 // Needs to update layout now because we'd like to call isFocusable(), which
281 // has !layoutObject()->needsLayout() assertion. 281 // has !layoutObject()->needsLayout() assertion.
282 document().updateLayoutIgnorePendingStylesheets(); 282 document().updateLayoutIgnorePendingStylesheets();
283 283
284 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); 284 RawPtr<HTMLFormElement> protector(this);
285 // Focus on the first focusable control and show a validation message. 285 // Focus on the first focusable control and show a validation message.
286 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { 286 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) {
287 HTMLFormControlElement* unhandled = unhandledInvalidControls[i].get(); 287 HTMLFormControlElement* unhandled = unhandledInvalidControls[i].get();
288 if (unhandled->isFocusable()) { 288 if (unhandled->isFocusable()) {
289 unhandled->showValidationMessage(); 289 unhandled->showValidationMessage();
290 break; 290 break;
291 } 291 }
292 } 292 }
293 // Warn about all of unfocusable controls. 293 // Warn about all of unfocusable controls.
294 if (document().frame()) { 294 if (document().frame()) {
295 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { 295 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) {
296 HTMLFormControlElement* unhandled = unhandledInvalidControls[i].get( ); 296 HTMLFormControlElement* unhandled = unhandledInvalidControls[i].get( );
297 if (unhandled->isFocusable()) 297 if (unhandled->isFocusable())
298 continue; 298 continue;
299 String message("An invalid form control with name='%name' is not foc usable."); 299 String message("An invalid form control with name='%name' is not foc usable.");
300 message.replace("%name", unhandled->name()); 300 message.replace("%name", unhandled->name());
301 document().addConsoleMessage(ConsoleMessage::create(RenderingMessage Source, ErrorMessageLevel, message)); 301 document().addConsoleMessage(ConsoleMessage::create(RenderingMessage Source, ErrorMessageLevel, message));
302 } 302 }
303 } 303 }
304 return false; 304 return false;
305 } 305 }
306 306
307 void HTMLFormElement::prepareForSubmission(Event* event) 307 void HTMLFormElement::prepareForSubmission(Event* event)
308 { 308 {
309 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); 309 RawPtr<HTMLFormElement> protector(this);
310 LocalFrame* frame = document().frame(); 310 LocalFrame* frame = document().frame();
311 if (!frame || m_isSubmittingOrInUserJSSubmitEvent) 311 if (!frame || m_isSubmittingOrInUserJSSubmitEvent)
312 return; 312 return;
313 313
314 bool skipValidation = !document().page() || noValidate(); 314 bool skipValidation = !document().page() || noValidate();
315 ASSERT(event); 315 ASSERT(event);
316 HTMLFormControlElement* submitElement = submitElementFromEvent(event); 316 HTMLFormControlElement* submitElement = submitElementFromEvent(event);
317 if (submitElement && submitElement->formNoValidate()) 317 if (submitElement && submitElement->formNoValidate())
318 skipValidation = true; 318 skipValidation = true;
319 319
(...skipping 13 matching lines...) Expand all
333 333
334 if (m_shouldSubmit) 334 if (m_shouldSubmit)
335 submit(event, true, true); 335 submit(event, true, true);
336 } 336 }
337 337
338 void HTMLFormElement::submitFromJavaScript() 338 void HTMLFormElement::submitFromJavaScript()
339 { 339 {
340 submit(0, false, UserGestureIndicator::processingUserGesture()); 340 submit(0, false, UserGestureIndicator::processingUserGesture());
341 } 341 }
342 342
343 void HTMLFormElement::submitDialog(PassRefPtrWillBeRawPtr<FormSubmission> formSu bmission) 343 void HTMLFormElement::submitDialog(RawPtr<FormSubmission> formSubmission)
344 { 344 {
345 for (Node* node = this; node; node = node->parentOrShadowHostNode()) { 345 for (Node* node = this; node; node = node->parentOrShadowHostNode()) {
346 if (isHTMLDialogElement(*node)) { 346 if (isHTMLDialogElement(*node)) {
347 toHTMLDialogElement(*node).closeDialog(formSubmission->result()); 347 toHTMLDialogElement(*node).closeDialog(formSubmission->result());
348 return; 348 return;
349 } 349 }
350 } 350 }
351 } 351 }
352 352
353 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce ssingUserGesture) 353 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce ssingUserGesture)
354 { 354 {
355 FrameView* view = document().view(); 355 FrameView* view = document().view();
356 LocalFrame* frame = document().frame(); 356 LocalFrame* frame = document().frame();
357 if (!view || !frame || !frame->page()) 357 if (!view || !frame || !frame->page())
358 return; 358 return;
359 359
360 if (m_isSubmittingOrInUserJSSubmitEvent) { 360 if (m_isSubmittingOrInUserJSSubmitEvent) {
361 m_shouldSubmit = true; 361 m_shouldSubmit = true;
362 return; 362 return;
363 } 363 }
364 364
365 m_isSubmittingOrInUserJSSubmitEvent = true; 365 m_isSubmittingOrInUserJSSubmitEvent = true;
366 m_wasUserSubmitted = processingUserGesture; 366 m_wasUserSubmitted = processingUserGesture;
367 367
368 RefPtrWillBeRawPtr<HTMLFormControlElement> firstSuccessfulSubmitButton = nul lptr; 368 RawPtr<HTMLFormControlElement> firstSuccessfulSubmitButton = nullptr;
369 bool needButtonActivation = activateSubmitButton; // do we need to activate a submit button? 369 bool needButtonActivation = activateSubmitButton; // do we need to activate a submit button?
370 370
371 const FormAssociatedElement::List& elements = associatedElements(); 371 const FormAssociatedElement::List& elements = associatedElements();
372 for (unsigned i = 0; i < elements.size(); ++i) { 372 for (unsigned i = 0; i < elements.size(); ++i) {
373 FormAssociatedElement* associatedElement = elements[i]; 373 FormAssociatedElement* associatedElement = elements[i];
374 if (!associatedElement->isFormControlElement()) 374 if (!associatedElement->isFormControlElement())
375 continue; 375 continue;
376 if (needButtonActivation) { 376 if (needButtonActivation) {
377 HTMLFormControlElement* control = toHTMLFormControlElement(associate dElement); 377 HTMLFormControlElement* control = toHTMLFormControlElement(associate dElement);
378 if (control->isActivatedSubmit()) 378 if (control->isActivatedSubmit())
379 needButtonActivation = false; 379 needButtonActivation = false;
380 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu bmitButton()) 380 else if (firstSuccessfulSubmitButton == 0 && control->isSuccessfulSu bmitButton())
381 firstSuccessfulSubmitButton = control; 381 firstSuccessfulSubmitButton = control;
382 } 382 }
383 } 383 }
384 384
385 if (needButtonActivation && firstSuccessfulSubmitButton) 385 if (needButtonActivation && firstSuccessfulSubmitButton)
386 firstSuccessfulSubmitButton->setActivatedSubmit(true); 386 firstSuccessfulSubmitButton->setActivatedSubmit(true);
387 387
388 RefPtrWillBeRawPtr<FormSubmission> formSubmission = FormSubmission::create(t his, m_attributes, event); 388 RawPtr<FormSubmission> formSubmission = FormSubmission::create(this, m_attri butes, event);
389 EventQueueScope scopeForDialogClose; // Delay dispatching 'close' to dialog until done submitting. 389 EventQueueScope scopeForDialogClose; // Delay dispatching 'close' to dialog until done submitting.
390 if (formSubmission->method() == FormSubmission::DialogMethod) 390 if (formSubmission->method() == FormSubmission::DialogMethod)
391 submitDialog(formSubmission.release()); 391 submitDialog(formSubmission.release());
392 else 392 else
393 scheduleFormSubmission(formSubmission.release()); 393 scheduleFormSubmission(formSubmission.release());
394 394
395 if (needButtonActivation && firstSuccessfulSubmitButton) 395 if (needButtonActivation && firstSuccessfulSubmitButton)
396 firstSuccessfulSubmitButton->setActivatedSubmit(false); 396 firstSuccessfulSubmitButton->setActivatedSubmit(false);
397 397
398 m_shouldSubmit = false; 398 m_shouldSubmit = false;
399 m_isSubmittingOrInUserJSSubmitEvent = false; 399 m_isSubmittingOrInUserJSSubmitEvent = false;
400 } 400 }
401 401
402 void HTMLFormElement::scheduleFormSubmission(PassRefPtrWillBeRawPtr<FormSubmissi on> submission) 402 void HTMLFormElement::scheduleFormSubmission(RawPtr<FormSubmission> submission)
403 { 403 {
404 ASSERT(submission->method() == FormSubmission::PostMethod || submission->met hod() == FormSubmission::GetMethod); 404 ASSERT(submission->method() == FormSubmission::PostMethod || submission->met hod() == FormSubmission::GetMethod);
405 ASSERT(submission->data()); 405 ASSERT(submission->data());
406 ASSERT(submission->form()); 406 ASSERT(submission->form());
407 if (submission->action().isEmpty()) 407 if (submission->action().isEmpty())
408 return; 408 return;
409 if (document().isSandboxed(SandboxForms)) { 409 if (document().isSandboxed(SandboxForms)) {
410 // FIXME: This message should be moved off the console once a solution t o https://bugs.webkit.org/show_bug.cgi?id=103274 exists. 410 // FIXME: This message should be moved off the console once a solution t o https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
411 document().addConsoleMessage(ConsoleMessage::create(SecurityMessageSourc e, ErrorMessageLevel, "Blocked form submission to '" + submission->action().elid edString() + "' because the form's frame is sandboxed and the 'allow-forms' perm ission is not set.")); 411 document().addConsoleMessage(ConsoleMessage::create(SecurityMessageSourc e, ErrorMessageLevel, "Blocked form submission to '" + submission->action().elid edString() + "' because the form's frame is sandboxed and the 'allow-forms' perm ission is not set."));
412 return; 412 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 if (!errorMessage.isEmpty()) { 475 if (!errorMessage.isEmpty()) {
476 document().addConsoleMessage(ConsoleMessage::create(RenderingMessageSour ce, LogMessageLevel, errorMessage)); 476 document().addConsoleMessage(ConsoleMessage::create(RenderingMessageSour ce, LogMessageLevel, errorMessage));
477 finishRequestAutocomplete(AutocompleteResultErrorDisabled); 477 finishRequestAutocomplete(AutocompleteResultErrorDisabled);
478 } else { 478 } else {
479 document().frame()->loader().client()->didRequestAutocomplete(this); 479 document().frame()->loader().client()->didRequestAutocomplete(this);
480 } 480 }
481 } 481 }
482 482
483 void HTMLFormElement::finishRequestAutocomplete(AutocompleteResult result) 483 void HTMLFormElement::finishRequestAutocomplete(AutocompleteResult result)
484 { 484 {
485 RefPtrWillBeRawPtr<Event> event = nullptr; 485 RawPtr<Event> event = nullptr;
486 if (result == AutocompleteResultSuccess) 486 if (result == AutocompleteResultSuccess)
487 event = Event::createBubble(EventTypeNames::autocomplete); 487 event = Event::createBubble(EventTypeNames::autocomplete);
488 else if (result == AutocompleteResultErrorDisabled) 488 else if (result == AutocompleteResultErrorDisabled)
489 event = AutocompleteErrorEvent::create("disabled"); 489 event = AutocompleteErrorEvent::create("disabled");
490 else if (result == AutocompleteResultErrorCancel) 490 else if (result == AutocompleteResultErrorCancel)
491 event = AutocompleteErrorEvent::create("cancel"); 491 event = AutocompleteErrorEvent::create("cancel");
492 else if (result == AutocompleteResultErrorInvalid) 492 else if (result == AutocompleteResultErrorInvalid)
493 event = AutocompleteErrorEvent::create("invalid"); 493 event = AutocompleteErrorEvent::create("invalid");
494 else 494 else
495 ASSERT_NOT_REACHED(); 495 ASSERT_NOT_REACHED();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 #endif 569 #endif
570 570
571 void HTMLFormElement::didAssociateByParser() 571 void HTMLFormElement::didAssociateByParser()
572 { 572 {
573 if (!m_didFinishParsingChildren) 573 if (!m_didFinishParsingChildren)
574 return; 574 return;
575 m_hasElementsAssociatedByParser = true; 575 m_hasElementsAssociatedByParser = true;
576 UseCounter::count(document(), UseCounter::FormAssociationByParser); 576 UseCounter::count(document(), UseCounter::FormAssociationByParser);
577 } 577 }
578 578
579 PassRefPtrWillBeRawPtr<HTMLFormControlsCollection> HTMLFormElement::elements() 579 RawPtr<HTMLFormControlsCollection> HTMLFormElement::elements()
580 { 580 {
581 return ensureCachedCollection<HTMLFormControlsCollection>(FormControls); 581 return ensureCachedCollection<HTMLFormControlsCollection>(FormControls);
582 } 582 }
583 583
584 void HTMLFormElement::collectAssociatedElements(Node& root, FormAssociatedElemen t::List& elements) const 584 void HTMLFormElement::collectAssociatedElements(Node& root, FormAssociatedElemen t::List& elements) const
585 { 585 {
586 elements.clear(); 586 elements.clear();
587 for (HTMLElement& element : Traversal<HTMLElement>::startsAfter(root)) { 587 for (HTMLElement& element : Traversal<HTMLElement>::startsAfter(root)) {
588 FormAssociatedElement* associatedElement = 0; 588 FormAssociatedElement* associatedElement = 0;
589 if (element.isFormControlElement()) 589 if (element.isFormControlElement())
(...skipping 18 matching lines...) Expand all
608 if (m_hasElementsAssociatedByParser) 608 if (m_hasElementsAssociatedByParser)
609 scope = &NodeTraversal::highestAncestorOrSelf(*mutableThis); 609 scope = &NodeTraversal::highestAncestorOrSelf(*mutableThis);
610 if (inDocument() && treeScope().idTargetObserverRegistry().hasObservers(fast GetAttribute(idAttr))) 610 if (inDocument() && treeScope().idTargetObserverRegistry().hasObservers(fast GetAttribute(idAttr)))
611 scope = &treeScope().rootNode(); 611 scope = &treeScope().rootNode();
612 ASSERT(scope); 612 ASSERT(scope);
613 collectAssociatedElements(*scope, mutableThis->m_associatedElements); 613 collectAssociatedElements(*scope, mutableThis->m_associatedElements);
614 mutableThis->m_associatedElementsAreDirty = false; 614 mutableThis->m_associatedElementsAreDirty = false;
615 return m_associatedElements; 615 return m_associatedElements;
616 } 616 }
617 617
618 void HTMLFormElement::collectImageElements(Node& root, WillBeHeapVector<RawPtrWi llBeMember<HTMLImageElement>>& elements) 618 void HTMLFormElement::collectImageElements(Node& root, HeapVector<Member<HTMLIma geElement>>& elements)
619 { 619 {
620 elements.clear(); 620 elements.clear();
621 for (HTMLImageElement& image : Traversal<HTMLImageElement>::startsAfter(root )) { 621 for (HTMLImageElement& image : Traversal<HTMLImageElement>::startsAfter(root )) {
622 if (image.formOwner() == this) 622 if (image.formOwner() == this)
623 elements.append(&image); 623 elements.append(&image);
624 } 624 }
625 } 625 }
626 626
627 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>& HTMLFormElement::i mageElements() 627 const HeapVector<Member<HTMLImageElement>>& HTMLFormElement::imageElements()
628 { 628 {
629 if (!m_imageElementsAreDirty) 629 if (!m_imageElementsAreDirty)
630 return m_imageElements; 630 return m_imageElements;
631 collectImageElements(m_hasElementsAssociatedByParser ? NodeTraversal::highes tAncestorOrSelf(*this) : *this, m_imageElements); 631 collectImageElements(m_hasElementsAssociatedByParser ? NodeTraversal::highes tAncestorOrSelf(*this) : *this, m_imageElements);
632 m_imageElementsAreDirty = false; 632 m_imageElementsAreDirty = false;
633 return m_imageElements; 633 return m_imageElements;
634 } 634 }
635 635
636 String HTMLFormElement::name() const 636 String HTMLFormElement::name() const
637 { 637 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } 683 }
684 684
685 return 0; 685 return 0;
686 } 686 }
687 687
688 bool HTMLFormElement::checkValidity() 688 bool HTMLFormElement::checkValidity()
689 { 689 {
690 return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchInva lidEvent); 690 return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchInva lidEvent);
691 } 691 }
692 692
693 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R efPtrWillBeMember<HTMLFormControlElement>>* unhandledInvalidControls, CheckValid ityEventBehavior eventBehavior) 693 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(HeapVector<Member< HTMLFormControlElement>>* unhandledInvalidControls, CheckValidityEventBehavior e ventBehavior)
694 { 694 {
695 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); 695 RawPtr<HTMLFormElement> protector(this);
696 // Copy associatedElements because event handlers called from 696 // Copy associatedElements because event handlers called from
697 // HTMLFormControlElement::checkValidity() might change associatedElements. 697 // HTMLFormControlElement::checkValidity() might change associatedElements.
698 const FormAssociatedElement::List& associatedElements = this->associatedElem ents(); 698 const FormAssociatedElement::List& associatedElements = this->associatedElem ents();
699 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement>> elements; 699 HeapVector<Member<FormAssociatedElement>> elements;
700 elements.reserveCapacity(associatedElements.size()); 700 elements.reserveCapacity(associatedElements.size());
701 for (unsigned i = 0; i < associatedElements.size(); ++i) 701 for (unsigned i = 0; i < associatedElements.size(); ++i)
702 elements.append(associatedElements[i]); 702 elements.append(associatedElements[i]);
703 int invalidControlsCount = 0; 703 int invalidControlsCount = 0;
704 for (unsigned i = 0; i < elements.size(); ++i) { 704 for (unsigned i = 0; i < elements.size(); ++i) {
705 if (elements[i]->form() == this && elements[i]->isFormControlElement()) { 705 if (elements[i]->form() == this && elements[i]->isFormControlElement()) {
706 HTMLFormControlElement* control = toHTMLFormControlElement(elements[ i].get()); 706 HTMLFormControlElement* control = toHTMLFormControlElement(elements[ i].get());
707 if (control->isSubmittableElement() && !control->checkValidity(unhan dledInvalidControls, eventBehavior) && control->formOwner() == this) { 707 if (control->isSubmittableElement() && !control->checkValidity(unhan dledInvalidControls, eventBehavior) && control->formOwner() == this) {
708 ++invalidControlsCount; 708 ++invalidControlsCount;
709 if (!unhandledInvalidControls && eventBehavior == CheckValidityD ispatchNoEvent) 709 if (!unhandledInvalidControls && eventBehavior == CheckValidityD ispatchNoEvent)
(...skipping 27 matching lines...) Expand all
737 } 737 }
738 #endif 738 #endif
739 return element; 739 return element;
740 } 740 }
741 741
742 void HTMLFormElement::addToPastNamesMap(Element* element, const AtomicString& pa stName) 742 void HTMLFormElement::addToPastNamesMap(Element* element, const AtomicString& pa stName)
743 { 743 {
744 if (pastName.isEmpty()) 744 if (pastName.isEmpty())
745 return; 745 return;
746 if (!m_pastNamesMap) 746 if (!m_pastNamesMap)
747 m_pastNamesMap = adoptPtrWillBeNoop(new PastNamesMap); 747 m_pastNamesMap = (new PastNamesMap);
748 m_pastNamesMap->set(pastName, element); 748 m_pastNamesMap->set(pastName, element);
749 } 749 }
750 750
751 void HTMLFormElement::removeFromPastNamesMap(HTMLElement& element) 751 void HTMLFormElement::removeFromPastNamesMap(HTMLElement& element)
752 { 752 {
753 if (!m_pastNamesMap) 753 if (!m_pastNamesMap)
754 return; 754 return;
755 for (auto& it : *m_pastNamesMap) { 755 for (auto& it : *m_pastNamesMap) {
756 if (it.value == &element) { 756 if (it.value == &element) {
757 it.value = nullptr; 757 it.value = nullptr;
758 // Keep looping. Single element can have multiple names. 758 // Keep looping. Single element can have multiple names.
759 } 759 }
760 } 760 }
761 } 761 }
762 762
763 void HTMLFormElement::getNamedElements(const AtomicString& name, WillBeHeapVecto r<RefPtrWillBeMember<Element>>& namedItems) 763 void HTMLFormElement::getNamedElements(const AtomicString& name, HeapVector<Memb er<Element>>& namedItems)
764 { 764 {
765 // http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#do m-form-nameditem 765 // http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#do m-form-nameditem
766 elements()->namedItems(name, namedItems); 766 elements()->namedItems(name, namedItems);
767 767
768 Element* elementFromPast = elementFromPastNamesMap(name); 768 Element* elementFromPast = elementFromPastNamesMap(name);
769 if (namedItems.size() && namedItems.first() != elementFromPast) { 769 if (namedItems.size() && namedItems.first() != elementFromPast) {
770 addToPastNamesMap(namedItems.first().get(), name); 770 addToPastNamesMap(namedItems.first().get(), name);
771 } else if (elementFromPast && namedItems.isEmpty()) { 771 } else if (elementFromPast && namedItems.isEmpty()) {
772 namedItems.append(elementFromPast); 772 namedItems.append(elementFromPast);
773 UseCounter::count(document(), UseCounter::FormNameAccessForPastNamesMap) ; 773 UseCounter::count(document(), UseCounter::FormNameAccessForPastNamesMap) ;
(...skipping 17 matching lines...) Expand all
791 m_wasDemoted = static_cast<const HTMLFormElement&>(source).m_wasDemoted; 791 m_wasDemoted = static_cast<const HTMLFormElement&>(source).m_wasDemoted;
792 HTMLElement::copyNonAttributePropertiesFromElement(source); 792 HTMLElement::copyNonAttributePropertiesFromElement(source);
793 } 793 }
794 794
795 void HTMLFormElement::anonymousNamedGetter(const AtomicString& name, RadioNodeLi stOrElement& returnValue) 795 void HTMLFormElement::anonymousNamedGetter(const AtomicString& name, RadioNodeLi stOrElement& returnValue)
796 { 796 {
797 // Call getNamedElements twice, first time check if it has a value 797 // Call getNamedElements twice, first time check if it has a value
798 // and let HTMLFormElement update its cache. 798 // and let HTMLFormElement update its cache.
799 // See issue: 867404 799 // See issue: 867404
800 { 800 {
801 WillBeHeapVector<RefPtrWillBeMember<Element>> elements; 801 HeapVector<Member<Element>> elements;
802 getNamedElements(name, elements); 802 getNamedElements(name, elements);
803 if (elements.isEmpty()) 803 if (elements.isEmpty())
804 return; 804 return;
805 } 805 }
806 806
807 // Second call may return different results from the first call, 807 // Second call may return different results from the first call,
808 // but if the first the size cannot be zero. 808 // but if the first the size cannot be zero.
809 WillBeHeapVector<RefPtrWillBeMember<Element>> elements; 809 HeapVector<Member<Element>> elements;
810 getNamedElements(name, elements); 810 getNamedElements(name, elements);
811 ASSERT(!elements.isEmpty()); 811 ASSERT(!elements.isEmpty());
812 812
813 bool onlyMatchImg = !elements.isEmpty() && isHTMLImageElement(*elements.firs t()); 813 bool onlyMatchImg = !elements.isEmpty() && isHTMLImageElement(*elements.firs t());
814 if (onlyMatchImg) { 814 if (onlyMatchImg) {
815 UseCounter::count(document(), UseCounter::FormNameAccessForImageElement) ; 815 UseCounter::count(document(), UseCounter::FormNameAccessForImageElement) ;
816 // The following code has performance impact, but it should be small 816 // The following code has performance impact, but it should be small
817 // because <img> access via <form> name getter is rarely used. 817 // because <img> access via <form> name getter is rarely used.
818 for (auto& element : elements) { 818 for (auto& element : elements) {
819 if (isHTMLImageElement(*element) && !element->isDescendantOf(this)) { 819 if (isHTMLImageElement(*element) && !element->isDescendantOf(this)) {
(...skipping 11 matching lines...) Expand all
831 } 831 }
832 832
833 void HTMLFormElement::setDemoted(bool demoted) 833 void HTMLFormElement::setDemoted(bool demoted)
834 { 834 {
835 if (demoted) 835 if (demoted)
836 UseCounter::count(document(), UseCounter::DemotedFormElement); 836 UseCounter::count(document(), UseCounter::DemotedFormElement);
837 m_wasDemoted = demoted; 837 m_wasDemoted = demoted;
838 } 838 }
839 839
840 } // namespace blink 840 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698