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

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

Issue 460343004: Fix update of validity cache value, so that it reflects the correct state of any FormControlElement. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: +Review comments Created 6 years, 3 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/HTMLInputElement.cpp » ('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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 , m_disabled(false) 51 , m_disabled(false)
52 , m_isAutofilled(false) 52 , m_isAutofilled(false)
53 , m_isReadOnly(false) 53 , m_isReadOnly(false)
54 , m_isRequired(false) 54 , m_isRequired(false)
55 , m_hasValidationMessage(false) 55 , m_hasValidationMessage(false)
56 , m_ancestorDisabledState(AncestorDisabledStateUnknown) 56 , m_ancestorDisabledState(AncestorDisabledStateUnknown)
57 , m_dataListAncestorState(Unknown) 57 , m_dataListAncestorState(Unknown)
58 , m_willValidateInitialized(false) 58 , m_willValidateInitialized(false)
59 , m_willValidate(true) 59 , m_willValidate(true)
60 , m_isValid(true) 60 , m_isValid(true)
61 , m_validityIsDirty(true)
61 , m_wasChangedSinceLastFormControlChangeEvent(false) 62 , m_wasChangedSinceLastFormControlChangeEvent(false)
62 , m_wasFocusedByMouse(false) 63 , m_wasFocusedByMouse(false)
63 { 64 {
64 setHasCustomStyleCallbacks(); 65 setHasCustomStyleCallbacks();
65 associateByParser(form); 66 associateByParser(form);
66 } 67 }
67 68
68 HTMLFormControlElement::~HTMLFormControlElement() 69 HTMLFormControlElement::~HTMLFormControlElement()
69 { 70 {
70 #if !ENABLE(OILPAN) 71 #if !ENABLE(OILPAN)
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this); 467 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this);
467 RefPtrWillBeRawPtr<Document> originalDocument(document()); 468 RefPtrWillBeRawPtr<Document> originalDocument(document());
468 bool needsDefaultAction = dispatchEvent(Event::createCancelable(EventTypeNam es::invalid)); 469 bool needsDefaultAction = dispatchEvent(Event::createCancelable(EventTypeNam es::invalid));
469 if (needsDefaultAction && unhandledInvalidControls && inDocument() && origin alDocument == document()) 470 if (needsDefaultAction && unhandledInvalidControls && inDocument() && origin alDocument == document())
470 unhandledInvalidControls->append(this); 471 unhandledInvalidControls->append(this);
471 return false; 472 return false;
472 } 473 }
473 474
474 bool HTMLFormControlElement::isValidFormControlElement() 475 bool HTMLFormControlElement::isValidFormControlElement()
475 { 476 {
476 // If the following assertion fails, setNeedsValidityCheck() is not called 477 if (m_validityIsDirty) {
477 // correctly when something which changes validity is updated. 478 m_isValid = valid();
478 ASSERT(m_isValid == valid()); 479 m_validityIsDirty = false;
480 }
481 ASSERT(!m_validityIsDirty);
tkent 2014/09/04 04:49:36 This assertion doesn't make sense. I meant: if (m
spartha 2014/09/04 05:20:57 Done.
479 return m_isValid; 482 return m_isValid;
480 } 483 }
481 484
482 void HTMLFormControlElement::setNeedsValidityCheck() 485 void HTMLFormControlElement::setNeedsValidityCheck()
483 { 486 {
484 bool newIsValid = valid(); 487 if (!m_validityIsDirty && willValidate()) {
485 if (willValidate() && newIsValid != m_isValid) {
486 // Update style for pseudo classes such as :valid :invalid. 488 // Update style for pseudo classes such as :valid :invalid.
487 setNeedsStyleRecalc(SubtreeStyleChange); 489 setNeedsStyleRecalc(SubtreeStyleChange);
490 m_validityIsDirty = true;
488 } 491 }
489 m_isValid = newIsValid;
490 492
491 // Updates only if this control already has a validation message. 493 // Updates only if this control already has a validation message.
492 if (isValidationMessageVisible()) { 494 if (isValidationMessageVisible()) {
493 // Calls updateVisibleValidationMessage() even if m_isValid is not 495 // Calls updateVisibleValidationMessage() even if m_isValid is not
494 // changed because a validation message can be changed. 496 // changed because a validation message can be changed.
495 updateVisibleValidationMessage(); 497 updateVisibleValidationMessage();
496 } 498 }
497 } 499 }
498 500
499 void HTMLFormControlElement::setCustomValidity(const String& error) 501 void HTMLFormControlElement::setCustomValidity(const String& error)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 540
539 void HTMLFormControlElement::setFocus(bool flag) 541 void HTMLFormControlElement::setFocus(bool flag)
540 { 542 {
541 LabelableElement::setFocus(flag); 543 LabelableElement::setFocus(flag);
542 544
543 if (!flag && wasChangedSinceLastFormControlChangeEvent()) 545 if (!flag && wasChangedSinceLastFormControlChangeEvent())
544 dispatchFormControlChangeEvent(); 546 dispatchFormControlChangeEvent();
545 } 547 }
546 548
547 } // namespace Webcore 549 } // namespace Webcore
OLDNEW
« no previous file with comments | « Source/core/html/HTMLFormControlElement.h ('k') | Source/core/html/HTMLInputElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698