| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 (message.isEmpty()) |
| 420 client->hideValidationMessage(*this); |
| 421 else |
| 422 client->showValidationMessage(*this, message); |
| 417 } | 423 } |
| 418 | 424 |
| 419 void HTMLFormControlElement::hideVisibleValidationMessage() | 425 void HTMLFormControlElement::hideVisibleValidationMessage() |
| 420 { | 426 { |
| 421 if (m_validationMessage) | 427 if (!m_hasValidationMessage) |
| 422 m_validationMessage->requestToHideMessage(); | 428 return; |
| 429 |
| 430 if (ValidationMessageClient* client = validationMessageClient()) |
| 431 client->hideValidationMessage(*this); |
| 432 } |
| 433 |
| 434 bool HTMLFormControlElement::isValidationMessageVisible() const |
| 435 { |
| 436 if (!m_hasValidationMessage) |
| 437 return false; |
| 438 |
| 439 ValidationMessageClient* client = validationMessageClient(); |
| 440 if (!client) |
| 441 return false; |
| 442 |
| 443 return client->isValidationMessageVisible(*this); |
| 444 } |
| 445 |
| 446 ValidationMessageClient* HTMLFormControlElement::validationMessageClient() const |
| 447 { |
| 448 Page* page = document().page(); |
| 449 if (!page) |
| 450 return 0; |
| 451 |
| 452 return &page->validationMessageClient(); |
| 423 } | 453 } |
| 424 | 454 |
| 425 bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<F
ormAssociatedElement> >* unhandledInvalidControls) | 455 bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<F
ormAssociatedElement> >* unhandledInvalidControls) |
| 426 { | 456 { |
| 427 if (!willValidate() || isValidFormControlElement()) | 457 if (!willValidate() || isValidFormControlElement()) |
| 428 return true; | 458 return true; |
| 429 // An event handler can deref this object. | 459 // An event handler can deref this object. |
| 430 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this); | 460 RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this); |
| 431 RefPtrWillBeRawPtr<Document> originalDocument(document()); | 461 RefPtrWillBeRawPtr<Document> originalDocument(document()); |
| 432 bool needsDefaultAction = dispatchEvent(Event::createCancelable(EventTypeNam
es::invalid)); | 462 bool needsDefaultAction = dispatchEvent(Event::createCancelable(EventTypeNam
es::invalid)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 446 void HTMLFormControlElement::setNeedsValidityCheck() | 476 void HTMLFormControlElement::setNeedsValidityCheck() |
| 447 { | 477 { |
| 448 bool newIsValid = valid(); | 478 bool newIsValid = valid(); |
| 449 if (willValidate() && newIsValid != m_isValid) { | 479 if (willValidate() && newIsValid != m_isValid) { |
| 450 // Update style for pseudo classes such as :valid :invalid. | 480 // Update style for pseudo classes such as :valid :invalid. |
| 451 setNeedsStyleRecalc(SubtreeStyleChange); | 481 setNeedsStyleRecalc(SubtreeStyleChange); |
| 452 } | 482 } |
| 453 m_isValid = newIsValid; | 483 m_isValid = newIsValid; |
| 454 | 484 |
| 455 // Updates only if this control already has a validation message. | 485 // Updates only if this control already has a validation message. |
| 456 if (m_validationMessage && m_validationMessage->isVisible()) { | 486 if (isValidationMessageVisible()) { |
| 457 // Calls updateVisibleValidationMessage() even if m_isValid is not | 487 // Calls updateVisibleValidationMessage() even if m_isValid is not |
| 458 // changed because a validation message can be chagned. | 488 // changed because a validation message can be changed. |
| 459 updateVisibleValidationMessage(); | 489 updateVisibleValidationMessage(); |
| 460 } | 490 } |
| 461 } | 491 } |
| 462 | 492 |
| 463 void HTMLFormControlElement::setCustomValidity(const String& error) | 493 void HTMLFormControlElement::setCustomValidity(const String& error) |
| 464 { | 494 { |
| 465 FormAssociatedElement::setCustomValidity(error); | 495 FormAssociatedElement::setCustomValidity(error); |
| 466 setNeedsValidityCheck(); | 496 setNeedsValidityCheck(); |
| 467 } | 497 } |
| 468 | 498 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 532 |
| 503 void HTMLFormControlElement::setFocus(bool flag) | 533 void HTMLFormControlElement::setFocus(bool flag) |
| 504 { | 534 { |
| 505 LabelableElement::setFocus(flag); | 535 LabelableElement::setFocus(flag); |
| 506 | 536 |
| 507 if (!flag && wasChangedSinceLastFormControlChangeEvent()) | 537 if (!flag && wasChangedSinceLastFormControlChangeEvent()) |
| 508 dispatchFormControlChangeEvent(); | 538 dispatchFormControlChangeEvent(); |
| 509 } | 539 } |
| 510 | 540 |
| 511 } // namespace Webcore | 541 } // namespace Webcore |
| OLD | NEW |