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

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

Issue 365223004: Have the form control element directly handle validation message updating. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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/forms/ValidationMessage.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 14 matching lines...) Expand all
25 #include "config.h" 25 #include "config.h"
26 #include "core/html/HTMLFormControlElement.h" 26 #include "core/html/HTMLFormControlElement.h"
27 27
28 #include "core/events/Event.h" 28 #include "core/events/Event.h"
29 #include "core/html/HTMLDataListElement.h" 29 #include "core/html/HTMLDataListElement.h"
30 #include "core/html/HTMLFieldSetElement.h" 30 #include "core/html/HTMLFieldSetElement.h"
31 #include "core/html/HTMLFormElement.h" 31 #include "core/html/HTMLFormElement.h"
32 #include "core/html/HTMLInputElement.h" 32 #include "core/html/HTMLInputElement.h"
33 #include "core/html/HTMLLegendElement.h" 33 #include "core/html/HTMLLegendElement.h"
34 #include "core/html/ValidityState.h" 34 #include "core/html/ValidityState.h"
35 #include "core/html/forms/ValidationMessage.h"
36 #include "core/frame/UseCounter.h" 35 #include "core/frame/UseCounter.h"
36 #include "core/page/Page.h"
37 #include "core/page/ValidationMessageClient.h"
37 #include "core/rendering/RenderBox.h" 38 #include "core/rendering/RenderBox.h"
38 #include "core/rendering/RenderTheme.h" 39 #include "core/rendering/RenderTheme.h"
39 #include "wtf/Vector.h" 40 #include "wtf/Vector.h"
40 41
41 namespace WebCore { 42 namespace WebCore {
42 43
43 using namespace HTMLNames; 44 using namespace HTMLNames;
44 45
45 HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName, Doc ument& document, HTMLFormElement* form) 46 HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName, Doc ument& document, HTMLFormElement* form)
46 : LabelableElement(tagName, document) 47 : LabelableElement(tagName, document)
47 , m_disabled(false) 48 , m_disabled(false)
48 , m_isAutofilled(false) 49 , m_isAutofilled(false)
49 , m_isReadOnly(false) 50 , m_isReadOnly(false)
50 , m_isRequired(false) 51 , m_isRequired(false)
52 , m_hasValidationMessage(false)
51 , m_ancestorDisabledState(AncestorDisabledStateUnknown) 53 , m_ancestorDisabledState(AncestorDisabledStateUnknown)
52 , m_dataListAncestorState(Unknown) 54 , m_dataListAncestorState(Unknown)
53 , m_willValidateInitialized(false) 55 , m_willValidateInitialized(false)
54 , m_willValidate(true) 56 , m_willValidate(true)
55 , m_isValid(true) 57 , m_isValid(true)
56 , m_wasChangedSinceLastFormControlChangeEvent(false) 58 , m_wasChangedSinceLastFormControlChangeEvent(false)
57 , m_wasFocusedByMouse(false) 59 , m_wasFocusedByMouse(false)
58 { 60 {
59 setHasCustomStyleCallbacks(); 61 setHasCustomStyleCallbacks();
60 associateByParser(form); 62 associateByParser(form);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 m_dataListAncestorState = Unknown; 248 m_dataListAncestorState = Unknown;
247 setNeedsWillValidateCheck(); 249 setNeedsWillValidateCheck();
248 HTMLElement::insertedInto(insertionPoint); 250 HTMLElement::insertedInto(insertionPoint);
249 FormAssociatedElement::insertedInto(insertionPoint); 251 FormAssociatedElement::insertedInto(insertionPoint);
250 return InsertionDone; 252 return InsertionDone;
251 } 253 }
252 254
253 void HTMLFormControlElement::removedFrom(ContainerNode* insertionPoint) 255 void HTMLFormControlElement::removedFrom(ContainerNode* insertionPoint)
254 { 256 {
255 hideVisibleValidationMessage(); 257 hideVisibleValidationMessage();
256 m_validationMessage = nullptr; 258 m_hasValidationMessage = false;
257 m_ancestorDisabledState = AncestorDisabledStateUnknown; 259 m_ancestorDisabledState = AncestorDisabledStateUnknown;
258 m_dataListAncestorState = Unknown; 260 m_dataListAncestorState = Unknown;
259 HTMLElement::removedFrom(insertionPoint); 261 HTMLElement::removedFrom(insertionPoint);
260 FormAssociatedElement::removedFrom(insertionPoint); 262 FormAssociatedElement::removedFrom(insertionPoint);
261 } 263 }
262 264
263 void HTMLFormControlElement::setChangedSinceLastFormControlChangeEvent(bool chan ged) 265 void HTMLFormControlElement::setChangedSinceLastFormControlChangeEvent(bool chan ged)
264 { 266 {
265 m_wasChangedSinceLastFormControlChangeEvent = changed; 267 m_wasChangedSinceLastFormControlChangeEvent = changed;
266 } 268 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 406 }
405 407
406 void HTMLFormControlElement::updateVisibleValidationMessage() 408 void HTMLFormControlElement::updateVisibleValidationMessage()
407 { 409 {
408 Page* page = document().page(); 410 Page* page = document().page();
409 if (!page) 411 if (!page)
410 return; 412 return;
411 String message; 413 String message;
412 if (renderer() && willValidate()) 414 if (renderer() && willValidate())
413 message = validationMessage().stripWhiteSpace(); 415 message = validationMessage().stripWhiteSpace();
414 if (!m_validationMessage) 416
415 m_validationMessage = ValidationMessage::create(this); 417 m_hasValidationMessage = true;
416 m_validationMessage->updateValidationMessage(message); 418 ValidationMessageClient* client = &page->validationMessageClient();
419 if (!client)
420 return;
421 if (message.isEmpty())
422 client->hideValidationMessage(*this);
423 else
424 client->showValidationMessage(*this, message);
417 } 425 }
418 426
419 void HTMLFormControlElement::hideVisibleValidationMessage() 427 void HTMLFormControlElement::hideVisibleValidationMessage()
420 { 428 {
421 if (m_validationMessage) 429 if (ValidationMessageClient* client = validationMessageClient())
422 m_validationMessage->requestToHideMessage(); 430 client->hideValidationMessage(*this);
431 }
432
433 bool HTMLFormControlElement::isValidationMessageVisible() const
434 {
435 ValidationMessageClient* client = validationMessageClient();
436 if (!client)
437 return false;
438
439 return client->isValidationMessageVisible(*this);
440 }
441
442 ValidationMessageClient* HTMLFormControlElement::validationMessageClient() const
443 {
444 if (!m_hasValidationMessage)
tkent 2014/07/04 07:43:30 Checking this in validationMessageClient() is weir
sof 2014/07/04 07:45:33 Yeah, I was just compressing some checks by moving
sof 2014/07/04 07:50:19 Done now.
445 return 0;
446
447 Page* page = document().page();
448 if (!page)
449 return 0;
450
451 return &page->validationMessageClient();
423 } 452 }
424 453
425 bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<F ormAssociatedElement> >* unhandledInvalidControls) 454 bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<F ormAssociatedElement> >* unhandledInvalidControls)
426 { 455 {
427 if (!willValidate() || isValidFormControlElement()) 456 if (!willValidate() || isValidFormControlElement())
428 return true; 457 return true;
429 // An event handler can deref this object. 458 // An event handler can deref this object.
430 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this); 459 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this);
431 RefPtrWillBeRawPtr<Document> originalDocument(document()); 460 RefPtrWillBeRawPtr<Document> originalDocument(document());
432 bool needsDefaultAction = dispatchEvent(Event::createCancelable(EventTypeNam es::invalid)); 461 bool needsDefaultAction = dispatchEvent(Event::createCancelable(EventTypeNam es::invalid));
(...skipping 13 matching lines...) Expand all
446 void HTMLFormControlElement::setNeedsValidityCheck() 475 void HTMLFormControlElement::setNeedsValidityCheck()
447 { 476 {
448 bool newIsValid = valid(); 477 bool newIsValid = valid();
449 if (willValidate() && newIsValid != m_isValid) { 478 if (willValidate() && newIsValid != m_isValid) {
450 // Update style for pseudo classes such as :valid :invalid. 479 // Update style for pseudo classes such as :valid :invalid.
451 setNeedsStyleRecalc(SubtreeStyleChange); 480 setNeedsStyleRecalc(SubtreeStyleChange);
452 } 481 }
453 m_isValid = newIsValid; 482 m_isValid = newIsValid;
454 483
455 // Updates only if this control already has a validation message. 484 // Updates only if this control already has a validation message.
456 if (m_validationMessage && m_validationMessage->isVisible()) { 485 if (isValidationMessageVisible()) {
457 // Calls updateVisibleValidationMessage() even if m_isValid is not 486 // Calls updateVisibleValidationMessage() even if m_isValid is not
458 // changed because a validation message can be chagned. 487 // changed because a validation message can be changed.
459 updateVisibleValidationMessage(); 488 updateVisibleValidationMessage();
460 } 489 }
461 } 490 }
462 491
463 void HTMLFormControlElement::setCustomValidity(const String& error) 492 void HTMLFormControlElement::setCustomValidity(const String& error)
464 { 493 {
465 FormAssociatedElement::setCustomValidity(error); 494 FormAssociatedElement::setCustomValidity(error);
466 setNeedsValidityCheck(); 495 setNeedsValidityCheck();
467 } 496 }
468 497
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 531
503 void HTMLFormControlElement::setFocus(bool flag) 532 void HTMLFormControlElement::setFocus(bool flag)
504 { 533 {
505 LabelableElement::setFocus(flag); 534 LabelableElement::setFocus(flag);
506 535
507 if (!flag && wasChangedSinceLastFormControlChangeEvent()) 536 if (!flag && wasChangedSinceLastFormControlChangeEvent())
508 dispatchFormControlChangeEvent(); 537 dispatchFormControlChangeEvent();
509 } 538 }
510 539
511 } // namespace Webcore 540 } // namespace Webcore
OLDNEW
« no previous file with comments | « Source/core/html/HTMLFormControlElement.h ('k') | Source/core/html/forms/ValidationMessage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698