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

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

Issue 2556043002: Avoid WTF::Vector::at() and operator[] in core/html. (Closed)
Patch Set: _ Created 4 years 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 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
6 * reserved. 6 * reserved.
7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (event.eventPhase() != Event::kCapturingPhase && targetNode && 187 if (event.eventPhase() != Event::kCapturingPhase && targetNode &&
188 targetNode != this && (event.type() == EventTypeNames::submit || 188 targetNode != this && (event.type() == EventTypeNames::submit ||
189 event.type() == EventTypeNames::reset)) { 189 event.type() == EventTypeNames::reset)) {
190 event.stopPropagation(); 190 event.stopPropagation();
191 return; 191 return;
192 } 192 }
193 HTMLElement::handleLocalEvents(event); 193 HTMLElement::handleLocalEvents(event);
194 } 194 }
195 195
196 unsigned HTMLFormElement::length() const { 196 unsigned HTMLFormElement::length() const {
197 const ListedElement::List& elements = listedElements();
198 unsigned len = 0; 197 unsigned len = 0;
199 for (unsigned i = 0; i < elements.size(); ++i) { 198 for (const auto& element : listedElements()) {
200 if (elements[i]->isEnumeratable()) 199 if (element->isEnumeratable())
201 ++len; 200 ++len;
202 } 201 }
203 return len; 202 return len;
204 } 203 }
205 204
206 HTMLElement* HTMLFormElement::item(unsigned index) { 205 HTMLElement* HTMLFormElement::item(unsigned index) {
207 return elements()->item(index); 206 return elements()->item(index);
208 } 207 }
209 208
210 void HTMLFormElement::submitImplicitly(Event* event, 209 void HTMLFormElement::submitImplicitly(Event* event,
211 bool fromImplicitSubmissionTrigger) { 210 bool fromImplicitSubmissionTrigger) {
212 int submissionTriggerCount = 0; 211 int submissionTriggerCount = 0;
213 bool seenDefaultButton = false; 212 bool seenDefaultButton = false;
214 const ListedElement::List& elements = listedElements(); 213 for (const auto& element : listedElements()) {
215 for (unsigned i = 0; i < elements.size(); ++i) { 214 if (!element->isFormControlElement())
216 ListedElement* ListedElement = elements[i];
217 if (!ListedElement->isFormControlElement())
218 continue; 215 continue;
219 HTMLFormControlElement* control = toHTMLFormControlElement(ListedElement); 216 HTMLFormControlElement* control = toHTMLFormControlElement(element);
220 if (!seenDefaultButton && control->canBeSuccessfulSubmitButton()) { 217 if (!seenDefaultButton && control->canBeSuccessfulSubmitButton()) {
221 if (fromImplicitSubmissionTrigger) 218 if (fromImplicitSubmissionTrigger)
222 seenDefaultButton = true; 219 seenDefaultButton = true;
223 if (control->isSuccessfulSubmitButton()) { 220 if (control->isSuccessfulSubmitButton()) {
224 control->dispatchSimulatedClick(event); 221 control->dispatchSimulatedClick(event);
225 return; 222 return;
226 } 223 }
227 if (fromImplicitSubmissionTrigger) { 224 if (fromImplicitSubmissionTrigger) {
228 // Default (submit) button is not activated; no implicit submission. 225 // Default (submit) button is not activated; no implicit submission.
229 return; 226 return;
230 } 227 }
231 } else if (control->canTriggerImplicitSubmission()) { 228 } else if (control->canTriggerImplicitSubmission()) {
232 ++submissionTriggerCount; 229 ++submissionTriggerCount;
233 } 230 }
234 } 231 }
235 if (fromImplicitSubmissionTrigger && submissionTriggerCount == 1) 232 if (fromImplicitSubmissionTrigger && submissionTriggerCount == 1)
236 prepareForSubmission(event, nullptr); 233 prepareForSubmission(event, nullptr);
237 } 234 }
238 235
239 bool HTMLFormElement::validateInteractively() { 236 bool HTMLFormElement::validateInteractively() {
240 UseCounter::count(document(), UseCounter::FormValidationStarted); 237 UseCounter::count(document(), UseCounter::FormValidationStarted);
241 const ListedElement::List& elements = listedElements(); 238 for (const auto& element : listedElements()) {
242 for (unsigned i = 0; i < elements.size(); ++i) { 239 if (element->isFormControlElement())
243 if (elements[i]->isFormControlElement()) 240 toHTMLFormControlElement(element)->hideVisibleValidationMessage();
244 toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage();
245 } 241 }
246 242
247 HeapVector<Member<HTMLFormControlElement>> unhandledInvalidControls; 243 HeapVector<Member<HTMLFormControlElement>> unhandledInvalidControls;
248 if (!checkInvalidControlsAndCollectUnhandled( 244 if (!checkInvalidControlsAndCollectUnhandled(
249 &unhandledInvalidControls, CheckValidityDispatchInvalidEvent)) 245 &unhandledInvalidControls, CheckValidityDispatchInvalidEvent))
250 return true; 246 return true;
251 UseCounter::count(document(), UseCounter::FormValidationAbortedSubmission); 247 UseCounter::count(document(), UseCounter::FormValidationAbortedSubmission);
252 // Because the form has invalid controls, we abort the form submission and 248 // Because the form has invalid controls, we abort the form submission and
253 // show a validation message on a focusable form control. 249 // show a validation message on a focusable form control.
254 250
255 // Needs to update layout now because we'd like to call isFocusable(), which 251 // Needs to update layout now because we'd like to call isFocusable(), which
256 // has !layoutObject()->needsLayout() assertion. 252 // has !layoutObject()->needsLayout() assertion.
257 document().updateStyleAndLayoutIgnorePendingStylesheets(); 253 document().updateStyleAndLayoutIgnorePendingStylesheets();
258 254
259 // Focus on the first focusable control and show a validation message. 255 // Focus on the first focusable control and show a validation message.
260 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { 256 for (const auto& unhandled : unhandledInvalidControls) {
261 HTMLFormControlElement* unhandled = unhandledInvalidControls[i].get();
262 if (unhandled->isFocusable()) { 257 if (unhandled->isFocusable()) {
263 unhandled->showValidationMessage(); 258 unhandled->showValidationMessage();
264 UseCounter::count(document(), UseCounter::FormValidationShowedMessage); 259 UseCounter::count(document(), UseCounter::FormValidationShowedMessage);
265 break; 260 break;
266 } 261 }
267 } 262 }
268 // Warn about all of unfocusable controls. 263 // Warn about all of unfocusable controls.
269 if (document().frame()) { 264 if (document().frame()) {
270 for (unsigned i = 0; i < unhandledInvalidControls.size(); ++i) { 265 for (const auto& unhandled : unhandledInvalidControls) {
271 HTMLFormControlElement* unhandled = unhandledInvalidControls[i].get();
272 if (unhandled->isFocusable()) 266 if (unhandled->isFocusable())
273 continue; 267 continue;
274 String message( 268 String message(
275 "An invalid form control with name='%name' is not focusable."); 269 "An invalid form control with name='%name' is not focusable.");
276 message.replace("%name", unhandled->name()); 270 message.replace("%name", unhandled->name());
277 document().addConsoleMessage(ConsoleMessage::create( 271 document().addConsoleMessage(ConsoleMessage::create(
278 RenderingMessageSource, ErrorMessageLevel, message)); 272 RenderingMessageSource, ErrorMessageLevel, message));
279 } 273 }
280 } 274 }
281 return false; 275 return false;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 return; 458 return;
465 459
466 m_isInResetFunction = true; 460 m_isInResetFunction = true;
467 461
468 if (dispatchEvent(Event::createCancelableBubble(EventTypeNames::reset)) != 462 if (dispatchEvent(Event::createCancelableBubble(EventTypeNames::reset)) !=
469 DispatchEventResult::NotCanceled) { 463 DispatchEventResult::NotCanceled) {
470 m_isInResetFunction = false; 464 m_isInResetFunction = false;
471 return; 465 return;
472 } 466 }
473 467
474 const ListedElement::List& elements = listedElements(); 468 for (const auto& element : listedElements()) {
475 for (unsigned i = 0; i < elements.size(); ++i) { 469 if (element->isFormControlElement())
476 if (elements[i]->isFormControlElement()) 470 toHTMLFormControlElement(element)->reset();
477 toHTMLFormControlElement(elements[i])->reset();
478 } 471 }
479 472
480 m_isInResetFunction = false; 473 m_isInResetFunction = false;
481 } 474 }
482 475
483 void HTMLFormElement::parseAttribute(const QualifiedName& name, 476 void HTMLFormElement::parseAttribute(const QualifiedName& name,
484 const AtomicString& oldValue, 477 const AtomicString& oldValue,
485 const AtomicString& value) { 478 const AtomicString& value) {
486 if (name == actionAttr) { 479 if (name == actionAttr) {
487 m_attributes.parseAction(value); 480 m_attributes.parseAction(value);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 } 650 }
658 651
659 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled( 652 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(
660 HeapVector<Member<HTMLFormControlElement>>* unhandledInvalidControls, 653 HeapVector<Member<HTMLFormControlElement>>* unhandledInvalidControls,
661 CheckValidityEventBehavior eventBehavior) { 654 CheckValidityEventBehavior eventBehavior) {
662 // Copy listedElements because event handlers called from 655 // Copy listedElements because event handlers called from
663 // HTMLFormControlElement::checkValidity() might change listedElements. 656 // HTMLFormControlElement::checkValidity() might change listedElements.
664 const ListedElement::List& listedElements = this->listedElements(); 657 const ListedElement::List& listedElements = this->listedElements();
665 HeapVector<Member<ListedElement>> elements; 658 HeapVector<Member<ListedElement>> elements;
666 elements.reserveCapacity(listedElements.size()); 659 elements.reserveCapacity(listedElements.size());
667 for (unsigned i = 0; i < listedElements.size(); ++i) 660 for (const auto& element : listedElements)
668 elements.append(listedElements[i]); 661 elements.append(element);
669 int invalidControlsCount = 0; 662 int invalidControlsCount = 0;
670 for (unsigned i = 0; i < elements.size(); ++i) { 663 for (const auto& element : elements) {
671 if (elements[i]->form() == this && elements[i]->isFormControlElement()) { 664 if (element->form() == this && element->isFormControlElement()) {
672 HTMLFormControlElement* control = 665 HTMLFormControlElement* control = toHTMLFormControlElement(element);
673 toHTMLFormControlElement(elements[i].get());
674 if (control->isSubmittableElement() && 666 if (control->isSubmittableElement() &&
675 !control->checkValidity(unhandledInvalidControls, eventBehavior) && 667 !control->checkValidity(unhandledInvalidControls, eventBehavior) &&
676 control->formOwner() == this) { 668 control->formOwner() == this) {
677 ++invalidControlsCount; 669 ++invalidControlsCount;
678 if (!unhandledInvalidControls && 670 if (!unhandledInvalidControls &&
679 eventBehavior == CheckValidityDispatchNoEvent) 671 eventBehavior == CheckValidityDispatchNoEvent)
680 return true; 672 return true;
681 } 673 }
682 } 674 }
683 } 675 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 for (const auto& control : listedElements()) { 804 for (const auto& control : listedElements()) {
813 if (!control->isFormControlElement()) 805 if (!control->isFormControlElement())
814 continue; 806 continue;
815 if (toHTMLFormControlElement(control)->canBeSuccessfulSubmitButton()) 807 if (toHTMLFormControlElement(control)->canBeSuccessfulSubmitButton())
816 toHTMLFormControlElement(control)->pseudoStateChanged( 808 toHTMLFormControlElement(control)->pseudoStateChanged(
817 CSSSelector::PseudoDefault); 809 CSSSelector::PseudoDefault);
818 } 810 }
819 } 811 }
820 812
821 } // namespace blink 813 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698