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

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

Issue 660783002: Implement reportValidity() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Apply tkent's comments Created 6 years, 2 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
« no previous file with comments | « Source/core/html/HTMLFormControlElement.h ('k') | Source/core/html/HTMLFormElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 479
480 ValidationMessageClient* HTMLFormControlElement::validationMessageClient() const 480 ValidationMessageClient* HTMLFormControlElement::validationMessageClient() const
481 { 481 {
482 Page* page = document().page(); 482 Page* page = document().page();
483 if (!page) 483 if (!page)
484 return 0; 484 return 0;
485 485
486 return &page->validationMessageClient(); 486 return &page->validationMessageClient();
487 } 487 }
488 488
489 bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<F ormAssociatedElement> >* unhandledInvalidControls, CheckValidityEventBehavior ev entBehavior) 489 bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<H TMLFormControlElement> >* unhandledInvalidControls, CheckValidityEventBehavior e ventBehavior)
490 { 490 {
491 if (!willValidate() || isValidElement()) 491 if (!willValidate() || isValidElement())
492 return true; 492 return true;
493 if (eventBehavior != CheckValidityDispatchInvalidEvent) 493 if (eventBehavior != CheckValidityDispatchInvalidEvent)
494 return false; 494 return false;
495 // An event handler can deref this object. 495 // An event handler can deref this object.
496 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this); 496 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this);
497 RefPtrWillBeRawPtr<Document> originalDocument(document()); 497 RefPtrWillBeRawPtr<Document> originalDocument(document());
498 bool needsDefaultAction = dispatchEvent(Event::createCancelable(EventTypeNam es::invalid)); 498 bool needsDefaultAction = dispatchEvent(Event::createCancelable(EventTypeNam es::invalid));
499 if (needsDefaultAction && unhandledInvalidControls && inDocument() && origin alDocument == document()) 499 if (needsDefaultAction && unhandledInvalidControls && inDocument() && origin alDocument == document())
500 unhandledInvalidControls->append(this); 500 unhandledInvalidControls->append(this);
501 return false; 501 return false;
502 } 502 }
503 503
504 void HTMLFormControlElement::showValidationMessage()
505 {
506 scrollIntoViewIfNeeded(false);
507 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this);
508 focus();
509 updateVisibleValidationMessage();
510 }
511
512 bool HTMLFormControlElement::reportValidity()
513 {
514 WillBeHeapVector<RefPtrWillBeMember<HTMLFormControlElement> > unhandledInval idControls;
515 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this);
tkent 2014/10/22 05:41:37 Ah, I found |unhandledInvalidControls[0] kept a re
Bartek Nowierski 2014/10/22 06:17:08 Done.
516 bool isValid = checkValidity(&unhandledInvalidControls, CheckValidityDispatc hInvalidEvent);
517 if (isValid || unhandledInvalidControls.isEmpty())
518 return isValid;
519 ASSERT(unhandledInvalidControls.size() == 1);
520 ASSERT(unhandledInvalidControls[0].get() == this);
521 // Update layout now vefore calling isFocusable(), which has
tkent 2014/10/22 05:41:37 vefore -> before
Bartek Nowierski 2014/10/22 06:17:08 Done.
522 // !renderer()->needsLayout() assertion.
523 document().updateLayoutIgnorePendingStylesheets();
524 if (isFocusable()) {
525 showValidationMessage();
526 return false;
527 }
528 if (document().frame()) {
529 String message("An invalid form control with name='%name' is not focusab le.");
530 message.replace("%name", name());
531 document().addConsoleMessage(ConsoleMessage::create(RenderingMessageSour ce, ErrorMessageLevel, message));
532 }
533 return false;
534 }
535
504 bool HTMLFormControlElement::matchesValidityPseudoClasses() const 536 bool HTMLFormControlElement::matchesValidityPseudoClasses() const
505 { 537 {
506 return willValidate(); 538 return willValidate();
507 } 539 }
508 540
509 bool HTMLFormControlElement::isValidElement() 541 bool HTMLFormControlElement::isValidElement()
510 { 542 {
511 // If the following assertion fails, setNeedsValidityCheck() is not called 543 // If the following assertion fails, setNeedsValidityCheck() is not called
512 // correctly when something which changes validity is updated. 544 // correctly when something which changes validity is updated.
513 ASSERT(m_isValid == valid()); 545 ASSERT(m_isValid == valid());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 606
575 void HTMLFormControlElement::setFocus(bool flag) 607 void HTMLFormControlElement::setFocus(bool flag)
576 { 608 {
577 LabelableElement::setFocus(flag); 609 LabelableElement::setFocus(flag);
578 610
579 if (!flag && wasChangedSinceLastFormControlChangeEvent()) 611 if (!flag && wasChangedSinceLastFormControlChangeEvent())
580 dispatchFormControlChangeEvent(); 612 dispatchFormControlChangeEvent();
581 } 613 }
582 614
583 } // namespace blink 615 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/HTMLFormControlElement.h ('k') | Source/core/html/HTMLFormElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698