Changeset 56385 in webkit
- Timestamp:
- Mar 23, 2010 4:07:45 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r56383 r56385 1 2010-03-23 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Adam Barth. 4 5 Add checks if setNeedsWillValidateCheck() and 6 setNeedsValidityCheck() are called correctly. 7 https://bugs.webkit.org/show_bug.cgi?id=34924 8 9 Introduce HTMLFormControlElement::m_willValidate and 10 m_isValid. They are the caches of willValidate() and 11 isValidFormControlElement(). setNeedsWillValidateCheck() updates 12 m_willValidate and setNeedsValidityCheck() updates m_isValid. 13 14 willValidate() and isValidFormControlElement() have assertions to 15 check m_willvalidate or m_isValid has the correct state. If 16 setNeedsWillValidateCheck() or setNeedsValidityCheck() is needed 17 to be called and is not called, these assertions fail. 18 19 * html/HTMLButtonElement.h: 20 (WebCore::HTMLButtonElement::recalcWillValidate): 21 * html/HTMLFieldSetElement.h: 22 (WebCore::HTMLFieldSetElement::recalcWillValidate): 23 * html/HTMLFormControlElement.cpp: 24 (WebCore::HTMLFormControlElement::HTMLFormControlElement): 25 (WebCore::HTMLFormControlElement::parseMappedAttribute): 26 (WebCore::HTMLFormControlElement::recalcWillValidate): 27 (WebCore::HTMLFormControlElement::willValidate): 28 (WebCore::HTMLFormControlElement::setNeedsWillValidateCheck): 29 (WebCore::HTMLFormControlElement::validationMessage): 30 (WebCore::HTMLFormControlElement::isValidFormControlElement): 31 (WebCore::HTMLFormControlElement::setNeedsValidityCheck): 32 * html/HTMLFormControlElement.h: 33 * html/HTMLInputElement.cpp: 34 (WebCore::HTMLInputElement::setInputType): 35 (WebCore::HTMLInputElement::parseMappedAttribute): 36 (WebCore::HTMLInputElement::setValue): 37 (WebCore::HTMLInputElement::recalcWillValidate): 38 * html/HTMLInputElement.h: 39 * html/HTMLTextAreaElement.cpp: 40 (WebCore::HTMLTextAreaElement::setNonDirtyValue): 41 1 42 2010-03-22 Pavel Feldman <pfeldman@chromium.org> 2 43 -
trunk/WebCore/html/HTMLButtonElement.h
r46062 r56385 58 58 void setValue(const String&); 59 59 60 virtual bool willValidate() const { return false; }61 62 60 private: 63 61 enum Type { SUBMIT, RESET, BUTTON }; 64 62 virtual bool isOptionalFormControl() const { return true; } 63 virtual bool recalcWillValidate() const { return false; } 65 64 66 65 Type m_type; -
trunk/WebCore/html/HTMLFieldSetElement.h
r48106 r56385 48 48 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); 49 49 virtual const AtomicString& formControlType() const; 50 51 virtual bool willValidate() const { return false; }50 private: 51 virtual bool recalcWillValidate() const { return false; } 52 52 }; 53 53 -
trunk/WebCore/html/HTMLFormControlElement.cpp
r55980 r56385 58 58 , m_required(false) 59 59 , m_valueMatchesRenderer(false) 60 , m_willValidate(false) 61 , m_isValid(true) 60 62 { 61 63 if (!m_form) … … 91 93 void HTMLFormControlElement::parseMappedAttribute(MappedAttribute *attr) 92 94 { 93 bool oldWillValidate = willValidate();94 95 if (attr->name() == nameAttr) 95 96 m_hasName = !attr->isEmpty(); … … 113 114 bool oldRequired = m_required; 114 115 m_required = !attr->isNull(); 115 if (oldRequired != m_required) 116 setNeedsStyleRecalc(); 116 if (oldRequired != m_required) { 117 setNeedsValidityCheck(); 118 setNeedsStyleRecalc(); // Updates for :required :optional classes. 119 } 117 120 } else 118 121 HTMLElement::parseMappedAttribute(attr); 119 if (oldWillValidate != willValidate()) 120 setNeedsWillValidateCheck(); 122 setNeedsWillValidateCheck(); 121 123 } 122 124 … … 300 302 } 301 303 304 bool HTMLFormControlElement::recalcWillValidate() const 305 { 306 // FIXME: Check if the control does not have a datalist element as an ancestor. 307 return m_form && m_hasName && !m_disabled && !m_readOnly; 308 } 309 302 310 bool HTMLFormControlElement::willValidate() const 303 311 { 304 // FIXME: Implementation shall be completed with these checks: 305 // The control does not have a repetition template as an ancestor. 306 // The control does not have a datalist element as an ancestor. 307 // The control is not an output element. 308 return m_form && m_hasName && !m_disabled && !m_readOnly; 309 } 310 311 String HTMLFormControlElement::validationMessage() 312 { 313 return validity()->validationMessage(); 312 // If the following assertion fails, setNeedsWillValidateCheck() is not 313 // called correctly when something which changes recalcWillValidate() result 314 // is updated. 315 ASSERT(m_willValidate == recalcWillValidate()); 316 return m_willValidate; 314 317 } 315 318 316 319 void HTMLFormControlElement::setNeedsWillValidateCheck() 317 320 { 321 bool newWillValidate = recalcWillValidate(); 322 if (m_willValidate == newWillValidate) 323 return; 324 m_willValidate = newWillValidate; 318 325 setNeedsStyleRecalc(); 319 326 // FIXME: Show/hide a validation message. 327 } 328 329 String HTMLFormControlElement::validationMessage() 330 { 331 return validity()->validationMessage(); 320 332 } 321 333 … … 330 342 } 331 343 344 bool HTMLFormControlElement::isValidFormControlElement() 345 { 346 // If the following assertion fails, setNeedsValidityCheck() is not called 347 // correctly when something which changes validity is updated. 348 ASSERT(m_isValid == validity()->valid()); 349 return m_isValid; 350 } 351 332 352 void HTMLFormControlElement::setNeedsValidityCheck() 333 353 { 334 if (willValidate()) { 354 bool newIsValid = validity()->valid(); 355 if (willValidate() && newIsValid != m_isValid) { 335 356 // Update style for pseudo classes such as :valid :invalid. 336 357 setNeedsStyleRecalc(); 337 358 } 359 m_isValid = newIsValid; 338 360 // FIXME: show/hide a validation message. 339 361 } … … 368 390 { 369 391 return isSuccessfulSubmitButton() && m_form && m_form->defaultButton() == this; 370 }371 372 bool HTMLFormControlElement::isValidFormControlElement()373 {374 return validity()->valid();375 392 } 376 393 -
trunk/WebCore/html/HTMLFormControlElement.h
r55980 r56385 107 107 virtual short tabIndex() const; 108 108 109 virtualbool willValidate() const;109 bool willValidate() const; 110 110 String validationMessage(); 111 111 bool checkValidity(); … … 126 126 // This must be called any time the result of willValidate() has changed. 127 127 void setNeedsWillValidateCheck(); 128 virtual bool recalcWillValidate() const; 128 129 129 130 private: … … 139 140 bool m_required : 1; 140 141 bool m_valueMatchesRenderer : 1; 142 bool m_willValidate : 1; 143 // Cache of validity()->valid(). 144 // "candidate for constraint validation" doesn't affect to m_isValid. 145 bool m_isValid : 1; 141 146 }; 142 147 -
trunk/WebCore/html/HTMLInputElement.cpp
r56284 r56385 806 806 // field's value to something like /etc/passwd and then change it to a file field. 807 807 if (inputType() != newType) { 808 bool oldWillValidate = willValidate();809 808 if (newType == FILE && m_haveType) 810 809 // Set the attribute back to the old value. … … 863 862 } 864 863 864 setNeedsWillValidateCheck(); 865 865 setNeedsValidityCheck(); 866 if (oldWillValidate != willValidate())867 setNeedsWillValidateCheck();868 866 InputElement::notifyFormStateChanged(this); 869 867 } … … 1147 1145 setNeedsStyleRecalc(); 1148 1146 else if (attr->name() == minAttr 1149 || attr->name() == maxAttr 1150 || attr->name() == multipleAttr 1147 || attr->name() == maxAttr) { 1148 if (inputType() == RANGE) { 1149 // Sanitize the value. 1150 setValue(value()); 1151 setNeedsStyleRecalc(); 1152 } 1153 setNeedsValidityCheck(); 1154 } else if (attr->name() == multipleAttr 1151 1155 || attr->name() == patternAttr 1152 1156 || attr->name() == precisionAttr … … 1574 1578 setFormControlValueMatchesRenderer(false); 1575 1579 if (storesValueSeparateFromAttribute()) { 1576 if (inputType() == FILE) 1580 if (inputType() == FILE) { 1577 1581 m_fileList->clear(); 1578 else { 1582 setNeedsValidityCheck(); 1583 } else { 1579 1584 m_data.setValue(sanitizeValue(value)); 1585 // setNeedsValidityCheck() needs to be called after updating the value, 1586 // before style recalc. 1587 setNeedsValidityCheck(); 1580 1588 if (isTextField()) { 1581 1589 updatePlaceholderVisibility(false); … … 1587 1595 renderer()->updateFromElement(); 1588 1596 setNeedsStyleRecalc(); 1589 } else 1597 } else { 1590 1598 setAttribute(valueAttr, sanitizeValue(value)); 1599 setNeedsValidityCheck(); 1600 } 1591 1601 1592 1602 if (isTextField()) { … … 1605 1615 1606 1616 InputElement::notifyFormStateChanged(this); 1607 setNeedsValidityCheck();1608 1617 } 1609 1618 … … 2631 2640 } 2632 2641 2633 bool HTMLInputElement::willValidate() const 2634 { 2635 // FIXME: This shall check for new WF2 input types too 2636 return HTMLFormControlElementWithState::willValidate() && inputType() != HIDDEN && 2637 inputType() != BUTTON && inputType() != RESET; 2642 bool HTMLInputElement::recalcWillValidate() const 2643 { 2644 return HTMLFormControlElementWithState::recalcWillValidate() 2645 && inputType() != HIDDEN && inputType() != BUTTON && inputType() != RESET; 2638 2646 } 2639 2647 -
trunk/WebCore/html/HTMLInputElement.h
r56284 r56385 262 262 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; 263 263 264 virtual bool willValidate() const;265 266 264 // Converts the specified string to a floating number. 267 265 // If the conversion fails, the return value is false. Take care that leading or trailing unnecessary characters make failures. This returns false for an empty string input. … … 296 294 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); } 297 295 virtual bool isRequiredFormControl() const; 296 virtual bool recalcWillValidate() const; 298 297 299 298 PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex(); -
trunk/WebCore/html/HTMLTextAreaElement.cpp
r54695 r56385 292 292 293 293 m_value = normalizedValue; 294 setNeedsValidityCheck(); 294 295 m_isDirty = false; 295 296 setFormControlValueMatchesRenderer(true); … … 306 307 } 307 308 308 setNeedsValidityCheck();309 309 notifyFormStateChanged(this); 310 310 }
Note: See TracChangeset
for help on using the changeset viewer.