Changeset 116915 in webkit
- Timestamp:
- May 13, 2012 9:22:44 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r116914 r116915 1 2012-05-13 Yoshifumi Inoue <yosin@chromium.org> 2 3 [Forms] Move ValidityState methods implementation to another place 4 https://bugs.webkit.org/show_bug.cgi?id=86058 5 6 Reviewed by Kent Tamura. 7 8 This patch changes ValidityState class for limiting scope of 9 number/range input type related methods for introducing decimal 10 arithmetic. 11 12 Methods related to validation are moved from ValidateState to 13 input, select and textarea elements with virtual method based 14 dispatching via FormAssociateElement instead of tag name 15 dispatching so far for code simplification. 16 17 No new tests. This patch doesn't change behavior. 18 19 * html/FormAssociatedElement.cpp: 20 (WebCore::FormAssociatedElement::customError): Added. Called from ValidateState. Returns custom error mssage in member variable. 21 (WebCore::FormAssociatedElement::patternMismatch): Added. Called from ValidateState. This is default implementation. 22 (WebCore::FormAssociatedElement::rangeOverflow): Added. Called from ValidateState. This is default implementation. 23 (WebCore::FormAssociatedElement::rangeUnderflow): Added. Called from ValidateState. This is default implementation. 24 (WebCore::FormAssociatedElement::stepMismatch): Added. Called from ValidateState. This is default implementation. 25 (WebCore::FormAssociatedElement::tooLong): Added. Called from ValidateState. This is default implementation. 26 (WebCore::FormAssociatedElement::typeMismatch): Added. Called from ValidateState. This is default implementation. 27 (WebCore::FormAssociatedElement::valid): Added. Called from ValidateState. This is default implementation. 28 (WebCore::FormAssociatedElement::valueMissing): Added. Called from ValidateState. This is default implementation. 29 (WebCore::FormAssociatedElement::customValidationMessage): Added. Called from ValidateState. This is default implementation. 30 (WebCore::FormAssociatedElement::validationMessage): Added. Called from ValidateState. This is default implementation. 31 (WebCore::FormAssociatedElement::setCustomValidity): Added. set custom error message. 32 * html/FormAssociatedElement.h: 33 (FormAssociatedElement): Added new instance value m_customValidationMessage. 34 * html/HTMLFormControlElement.cpp: 35 (WebCore::HTMLFormControlElement::validationMessage): Removed. Note: HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement implement this method. 36 (WebCore::HTMLFormControlElement::setCustomValidity): Changed. Calls base class setCustomValidity. 37 * html/HTMLFormControlElement.h: 38 (HTMLFormControlElement): 39 * html/HTMLInputElement.cpp: 40 (WebCore::HTMLInputElement::isValidValue): Call m_inputType methods instead of HTMLInputElement's. 41 (WebCore::HTMLInputElement::tooLong): Call m_inputType methods instead of HTMLInputElement's. 42 (WebCore): 43 (WebCore::HTMLInputElement::typeMismatch): Move implementation to InputType. 44 (WebCore::HTMLInputElement::valueMissing): Move implementation to InputType. 45 (WebCore::HTMLInputElement::patternMismatch): Move implementation to InputType. 46 (WebCore::HTMLInputElement::rangeUnderflow): Move implementation to InputType. 47 (WebCore::HTMLInputElement::rangeOverflow): Move implementation to InputType. 48 (WebCore::HTMLInputElement::validationMessage): Move implementation to InputType. 49 (WebCore::HTMLInputElement::stepMismatch): Move implementation to InputType. 50 (WebCore::HTMLInputElement::isInRange): Call m_inputType methods instead of HTMLInputElement's. 51 (WebCore::HTMLInputElement::isOutOfRange): Call m_inputType methods instead of HTMLInputElement's. 52 * html/HTMLInputElement.h: 53 (HTMLInputElement): Make tooLong method private. 54 * html/HTMLObjectElement.h: Add "virtual" and "OVERRIDE". 55 * html/HTMLSelectElement.cpp: 56 (WebCore::HTMLSelectElement::validationMessage): Added. Implementation for HTMLSelectElement. 57 (WebCore::HTMLSelectElement::valueMissing): Added. Implementation for HTMLSelectElement. 58 * html/HTMLSelectElement.h: 59 (HTMLSelectElement): Added entries for newly added methods. 60 * html/HTMLTextAreaElement.cpp: 61 (WebCore::HTMLTextAreaElement::validationMessage): Added. Implementation for HTMLTextAreaElement. 62 (WebCore::HTMLTextAreaElement::valueMissing): Added. Implementation for HTMLTextAreaElement. 63 (WebCore::HTMLTextAreaElement::tooLong): Added. Implementation for HTMLTextAreaElement. 64 * html/HTMLTextAreaElement.h: 65 (HTMLTextAreaElement): Added entries for newly added methods. Change tooLong and valueMissing private. 66 * html/InputType.cpp: 67 (WebCore::InputType::stepMismatch): Change method signature. 68 (WebCore::InputType::alignValueForStep): Changed for calling InputClass instead of HTMLINputElement. 69 (WebCore::InputType::stepUpFromRenderer): Added. Moved from HTMLInputElement. 70 (WebCore::InputType::validationMessage): Added. Moved from HTMLInputElement. 71 * html/InputType.h: 72 (InputType): Added entries for newly added methods and update methods signature. 73 * html/ValidityState.cpp: Move actual implementation to FormAssociatedElement and derived classes for localizing implementation change of elements and input types. 74 (WebCore::ValidityState::validationMessage): Changed to call FormAssociatedElement's method. 75 (WebCore::ValidityState::valueMissing): Changed to call FormAssociatedElement's method. 76 (WebCore::ValidityState::typeMismatch): Changed to call FormAssociatedElement's method. 77 (WebCore::ValidityState::patternMismatch): Changed to call FormAssociatedElement's method. 78 (WebCore::ValidityState::tooLong): Changed to call FormAssociatedElement's method. 79 (WebCore::ValidityState::rangeUnderflow): Changed to call FormAssociatedElement's method. 80 (WebCore::ValidityState::rangeOverflow): Changed to call FormAssociatedElement's method. 81 (WebCore::ValidityState::stepMismatch): Changed to call FormAssociatedElement's method. 82 (WebCore::ValidityState::customError): Changed to call FormAssociatedElement's method. 83 (WebCore::ValidityState::valid): 84 * html/ValidityState.h: 85 (ValidityState): Remove custom validation message related things. 86 1 87 2012-05-13 Mike Lawther <mikelawther@chromium.org> 2 88 -
trunk/Source/WebCore/html/FormAssociatedElement.cpp
r116756 r116915 158 158 } 159 159 160 bool FormAssociatedElement::customError() const 161 { 162 const HTMLElement* element = toHTMLElement(this); 163 return element->willValidate() && !m_customValidationMessage.isEmpty(); 164 } 165 166 bool FormAssociatedElement::patternMismatch() const 167 { 168 return false; 169 } 170 171 bool FormAssociatedElement::rangeOverflow() const 172 { 173 return false; 174 } 175 176 bool FormAssociatedElement::rangeUnderflow() const 177 { 178 return false; 179 } 180 181 bool FormAssociatedElement::stepMismatch() const 182 { 183 return false; 184 } 185 186 bool FormAssociatedElement::tooLong() const 187 { 188 return false; 189 } 190 191 bool FormAssociatedElement::typeMismatch() const 192 { 193 return false; 194 } 195 196 bool FormAssociatedElement::valid() const 197 { 198 bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() 199 || tooLong() || patternMismatch() || valueMissing() || customError(); 200 return !someError; 201 } 202 203 bool FormAssociatedElement::valueMissing() const 204 { 205 return false; 206 } 207 208 String FormAssociatedElement::customValidationMessage() const 209 { 210 return m_customValidationMessage; 211 } 212 213 String FormAssociatedElement::validationMessage() const 214 { 215 return customError() ? m_customValidationMessage : String(); 216 } 217 218 void FormAssociatedElement::setCustomValidity(const String& error) 219 { 220 m_customValidationMessage = error; 221 } 222 160 223 const HTMLElement* toHTMLElement(const FormAssociatedElement* associatedElement) 161 224 { -
trunk/Source/WebCore/html/FormAssociatedElement.h
r116756 r116915 61 61 void formRemovedFromTree(const Node* formRoot); 62 62 63 // ValidityState attribute implementations 64 bool customError() const; 65 66 // Override functions for patterMismatch, rangeOverflow, rangerUnderflow, 67 // stepMismatch, tooLong and valueMissing must call willValidate method. 68 virtual bool patternMismatch() const; 69 virtual bool rangeOverflow() const; 70 virtual bool rangeUnderflow() const; 71 virtual bool stepMismatch() const; 72 virtual bool tooLong() const; 73 virtual bool typeMismatch() const; 74 virtual bool valueMissing() const; 75 virtual String validationMessage() const; 76 bool valid() const; 77 virtual void setCustomValidity(const String&); 78 63 79 protected: 64 80 FormAssociatedElement(); … … 77 93 virtual void didChangeForm(); 78 94 95 String customValidationMessage() const; 96 79 97 private: 80 98 virtual const AtomicString& formControlName() const = 0; … … 85 103 HTMLFormElement* m_form; 86 104 OwnPtr<ValidityState> m_validityState; 105 String m_customValidationMessage; 87 106 }; 88 107 -
trunk/Source/WebCore/html/HTMLFormControlElement.cpp
r116756 r116915 398 398 } 399 399 400 String HTMLFormControlElement::validationMessage()401 {402 return validity()->validationMessage();403 }404 405 400 void HTMLFormControlElement::updateVisibleValidationMessage() 406 401 { … … 485 480 void HTMLFormControlElement::setCustomValidity(const String& error) 486 481 { 487 validity()->setCustomErrorMessage(error); 482 FormAssociatedElement::setCustomValidity(error); 483 setNeedsValidityCheck(); 488 484 } 489 485 -
trunk/Source/WebCore/html/HTMLFormControlElement.h
r116756 r116915 96 96 97 97 virtual bool willValidate() const; 98 String validationMessage();99 98 void updateVisibleValidationMessage(); 100 99 void hideVisibleValidationMessage(); … … 102 101 // This must be called when a validation constraint or control value is changed. 103 102 void setNeedsValidityCheck(); 104 v oid setCustomValidity(const String&);103 virtual void setCustomValidity(const String&) OVERRIDE; 105 104 106 105 bool readOnly() const { return m_readOnly; } -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r116908 r116915 192 192 } 193 193 return !m_inputType->typeMismatchFor(value) 194 && ! stepMismatch(value)195 && ! rangeUnderflow(value)196 && ! rangeOverflow(value)194 && !m_inputType->stepMismatch(value) 195 && !m_inputType->rangeUnderflow(value) 196 && !m_inputType->rangeOverflow(value) 197 197 && !tooLong(value, IgnoreDirtyFlag) 198 && !patternMismatch(value) 199 && !valueMissing(value); 198 && !m_inputType->patternMismatch(value) 199 && !m_inputType->valueMissing(value); 200 } 201 202 bool HTMLInputElement::tooLong() const 203 { 204 return willValidate() && tooLong(value(), CheckDirtyFlag); 200 205 } 201 206 202 207 bool HTMLInputElement::typeMismatch() const 203 208 { 204 return m_inputType->typeMismatch();205 } 206 207 bool HTMLInputElement::valueMissing( const String& value) const208 { 209 return m_inputType->valueMissing(value);210 } 211 212 bool HTMLInputElement::patternMismatch( const String& value) const213 { 214 return m_inputType->patternMismatch(value);209 return willValidate() && m_inputType->typeMismatch(); 210 } 211 212 bool HTMLInputElement::valueMissing() const 213 { 214 return willValidate() && m_inputType->valueMissing(value()); 215 } 216 217 bool HTMLInputElement::patternMismatch() const 218 { 219 return willValidate() && m_inputType->patternMismatch(value()); 215 220 } 216 221 … … 233 238 } 234 239 235 bool HTMLInputElement::rangeUnderflow(const String& value) const 236 { 237 return m_inputType->rangeUnderflow(value); 238 } 239 240 bool HTMLInputElement::rangeOverflow(const String& value) const 241 { 242 return m_inputType->rangeOverflow(value); 240 bool HTMLInputElement::rangeUnderflow() const 241 { 242 return willValidate() && m_inputType->rangeUnderflow(value()); 243 } 244 245 bool HTMLInputElement::rangeOverflow() const 246 { 247 return willValidate() && m_inputType->rangeOverflow(value()); 248 } 249 250 String HTMLInputElement::validationMessage() const 251 { 252 if (!willValidate()) 253 return String(); 254 255 if (customError()) 256 return customValidationMessage(); 257 258 return m_inputType->validationMessage(); 243 259 } 244 260 … … 253 269 } 254 270 255 bool HTMLInputElement::stepMismatch(const String& value) const 256 { 257 double step; 258 if (!getAllowedValueStep(&step)) 259 return false; 260 return m_inputType->stepMismatch(value, step); 261 } 262 263 String HTMLInputElement::minimumString() const 264 { 265 return m_inputType->serialize(minimum()); 266 } 267 268 String HTMLInputElement::maximumString() const 269 { 270 return m_inputType->serialize(maximum()); 271 } 272 273 String HTMLInputElement::stepBaseString() const 274 { 275 return m_inputType->serialize(m_inputType->stepBase()); 276 } 277 278 String HTMLInputElement::stepString() const 279 { 280 double step; 281 if (!getAllowedValueStep(&step)) { 282 // stepString() should be called only if stepMismatch() can be true. 283 ASSERT_NOT_REACHED(); 284 return String(); 285 } 286 return serializeForNumberType(step / m_inputType->stepScaleFactor()); 287 } 288 289 String HTMLInputElement::typeMismatchText() const 290 { 291 return m_inputType->typeMismatchText(); 292 } 293 294 String HTMLInputElement::valueMissingText() const 295 { 296 return m_inputType->valueMissingText(); 271 bool HTMLInputElement::stepMismatch() const 272 { 273 return willValidate() && m_inputType->stepMismatch(value()); 297 274 } 298 275 … … 1276 1253 bool HTMLInputElement::isInRange() const 1277 1254 { 1278 return m_inputType->supportsRangeLimitation() && ! rangeUnderflow(value()) && !rangeOverflow(value());1255 return m_inputType->supportsRangeLimitation() && !m_inputType->rangeUnderflow(value()) && !m_inputType->rangeOverflow(value()); 1279 1256 } 1280 1257 1281 1258 bool HTMLInputElement::isOutOfRange() const 1282 1259 { 1283 return m_inputType->supportsRangeLimitation() && ( rangeUnderflow(value()) ||rangeOverflow(value()));1260 return m_inputType->supportsRangeLimitation() && (m_inputType->rangeUnderflow(value()) || m_inputType->rangeOverflow(value())); 1284 1261 } 1285 1262 -
trunk/Source/WebCore/html/HTMLInputElement.h
r116756 r116915 49 49 50 50 // For ValidityState 51 bool typeMismatch() const; 52 // valueMissing() ignores the specified string value for CHECKBOX and RADIO. 53 bool valueMissing(const String&) const; 54 bool patternMismatch(const String&) const; 55 bool tooLong(const String&, NeedsToCheckDirtyFlag) const; 56 bool rangeUnderflow(const String&) const; 57 bool rangeOverflow(const String&) const; 51 virtual bool patternMismatch() const OVERRIDE; 52 virtual bool rangeUnderflow() const OVERRIDE; 53 virtual bool rangeOverflow() const; 54 virtual bool stepMismatch() const OVERRIDE; 55 virtual bool tooLong() const OVERRIDE; 56 virtual bool typeMismatch() const OVERRIDE; 57 virtual bool valueMissing() const OVERRIDE; 58 virtual String validationMessage() const OVERRIDE; 59 58 60 // Returns the minimum value for type=date, number, or range. Don't call this for other types. 59 61 double minimum() const; … … 64 66 // Returns false if there is no "allowed value step." 65 67 bool getAllowedValueStep(double*) const; 66 67 // For ValidityState.68 bool stepMismatch(const String&) const;69 String minimumString() const;70 String maximumString() const;71 String stepBaseString() const;72 String stepString() const;73 String typeMismatchText() const;74 String valueMissingText() const;75 68 76 69 // Implementations of HTMLInputElement::stepUp() and stepDown(). … … 326 319 bool supportsMaxLength() const { return isTextType(); } 327 320 bool isTextType() const; 321 bool tooLong(const String&, NeedsToCheckDirtyFlag) const; 328 322 329 323 virtual bool supportsPlaceholder() const; -
trunk/Source/WebCore/html/HTMLObjectElement.h
r116756 r116915 55 55 // Implementations of constraint validation API. 56 56 // Note that the object elements are always barred from constraint validation. 57 String validationMessage(){ return String(); }57 virtual String validationMessage() const OVERRIDE { return String(); } 58 58 bool checkValidity() { return true; } 59 v oid setCustomValidity(const String&){ }59 virtual void setCustomValidity(const String&) OVERRIDE { } 60 60 61 61 using TreeShared<ContainerNode>::ref; -
trunk/Source/WebCore/html/HTMLSelectElement.cpp
r116864 r116915 42 42 #include "HTMLOptionsCollection.h" 43 43 #include "KeyboardEvent.h" 44 #include "LocalizedStrings.h" 44 45 #include "MouseEvent.h" 45 46 #include "NodeRenderingContext.h" … … 146 147 } 147 148 149 String HTMLSelectElement::validationMessage() const 150 { 151 if (!willValidate()) 152 return String(); 153 154 if (customError()) 155 return customValidationMessage(); 156 157 return valueMissing() ? validationMessageValueMissingForSelectText() : String(); 158 } 159 148 160 bool HTMLSelectElement::valueMissing() const 149 161 { 162 if (!willValidate()) 163 return false; 164 150 165 if (!isRequiredFormControl()) 151 166 return false; -
trunk/Source/WebCore/html/HTMLSelectElement.h
r116756 r116915 47 47 48 48 // For ValidityState 49 bool valueMissing() const; 49 virtual String validationMessage() const OVERRIDE; 50 virtual bool valueMissing() const OVERRIDE; 50 51 51 52 unsigned length() const; -
trunk/Source/WebCore/html/HTMLTextAreaElement.cpp
r116756 r116915 38 38 #include "Frame.h" 39 39 #include "HTMLNames.h" 40 #include "LocalizedStrings.h" 40 41 #include "RenderTextControlMultiLine.h" 41 42 #include "ShadowRoot.h" … … 424 425 } 425 426 427 String HTMLTextAreaElement::validationMessage() const 428 { 429 if (!willValidate()) 430 return String(); 431 432 if (customError()) 433 return customValidationMessage(); 434 435 if (valueMissing()) 436 return validationMessageValueMissingText(); 437 438 if (tooLong()) 439 return validationMessageTooLongText(numGraphemeClusters(value()), maxLength()); 440 441 return String(); 442 } 443 444 bool HTMLTextAreaElement::valueMissing() const 445 { 446 return willValidate() && valueMissing(value()); 447 } 448 449 bool HTMLTextAreaElement::tooLong() const 450 { 451 return willValidate() && tooLong(value(), CheckDirtyFlag); 452 } 453 426 454 bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const 427 455 { -
trunk/Source/WebCore/html/HTMLTextAreaElement.h
r116756 r116915 48 48 virtual int maxLength() const; 49 49 void setMaxLength(int, ExceptionCode&); 50 bool valueMissing(const String& value) const { return isRequiredFormControl() && !disabled() && !readOnly() && value.isEmpty(); } 51 bool tooLong(const String&, NeedsToCheckDirtyFlag) const; 50 // For ValidityState 51 virtual String validationMessage() const OVERRIDE; 52 virtual bool valueMissing() const OVERRIDE; 53 virtual bool tooLong() const OVERRIDE; 52 54 bool isValidValue(const String&) const; 53 55 … … 109 111 virtual bool shouldUseInputMethod(); 110 112 113 bool valueMissing(const String& value) const { return isRequiredFormControl() && !disabled() && !readOnly() && value.isEmpty(); } 114 bool tooLong(const String&, NeedsToCheckDirtyFlag) const; 115 111 116 int m_rows; 112 117 int m_cols; -
trunk/Source/WebCore/html/InputType.cpp
r116756 r116915 284 284 } 285 285 286 bool InputType::stepMismatch(const String& value) const 287 { 288 double step; 289 if (!getAllowedValueStep(&step)) 290 return false; 291 return stepMismatch(value, step); 292 } 293 286 294 bool InputType::stepMismatch(const String&, double) const 287 295 { … … 337 345 { 338 346 return validationMessageValueMissingText(); 347 } 348 349 String InputType::validationMessage() const 350 { 351 const String value = element()->value(); 352 353 // The order of the following checks is meaningful. e.g. We'd like to show the 354 // valueMissing message even if the control has other validation errors. 355 if (valueMissing(value)) 356 return valueMissingText(); 357 358 if (typeMismatch()) 359 return typeMismatchText(); 360 361 if (patternMismatch(value)) 362 return validationMessagePatternMismatchText(); 363 364 if (element()->tooLong()) 365 return validationMessageTooLongText(numGraphemeClusters(value), element()->maxLength()); 366 367 if (rangeUnderflow(value)) 368 return validationMessageRangeUnderflowText(serialize(minimum())); 369 370 if (rangeOverflow(value)) 371 return validationMessageRangeOverflowText(serialize(maximum())); 372 373 if (stepMismatch(value)) { 374 String stepString; 375 double step; 376 if (getAllowedValueStep(&step)) 377 stepString = serializeForNumberType(step / stepScaleFactor()); 378 return validationMessageStepMismatchText(serialize(stepBase()), stepString); 379 } 380 381 return String(); 339 382 } 340 383 … … 871 914 double base = stepBaseWithDecimalPlaces(&baseDecimalPlaces); 872 915 baseDecimalPlaces = min(baseDecimalPlaces, 16u); 873 if ( element()->stepMismatch(element()->value())) {916 if (stepMismatch(element()->value())) { 874 917 double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, currentDecimalPlaces))); 875 918 newValue = round(newValue * scale) / scale; … … 1024 1067 else { 1025 1068 ExceptionCode ec; 1026 if ( element()->stepMismatch(element()->value())) {1069 if (stepMismatch(element()->value())) { 1027 1070 ASSERT(step); 1028 1071 double newValue; -
trunk/Source/WebCore/html/InputType.h
r116756 r116915 141 141 142 142 // Validation functions 143 143 virtual String validationMessage() const; 144 144 virtual bool supportsValidation() const; 145 145 virtual bool typeMismatchFor(const String&) const; … … 158 158 virtual double maximum() const; 159 159 virtual bool sizeShouldIncludeDecoration(int defaultSize, int& preferredSize) const; 160 bool stepMismatch(const String&) const; 160 161 virtual bool stepMismatch(const String&, double step) const; 161 162 virtual double stepBase() const; -
trunk/Source/WebCore/html/ValidityState.cpp
r116756 r116915 39 39 String ValidityState::validationMessage() const 40 40 { 41 if (!toHTMLElement(m_control)->willValidate()) 42 return String(); 43 44 if (customError()) 45 return m_customErrorMessage; 46 HTMLElement* element = toHTMLElement(m_control); 47 bool isInputElement = element->isFormControlElement() && element->hasTagName(inputTag); 48 bool isTextAreaElement = element->isFormControlElement() && element->hasTagName(textareaTag); 49 // The order of the following checks is meaningful. e.g. We'd like to show the 50 // valueMissing message even if the control has other validation errors. 51 if (valueMissing()) { 52 if (element->hasTagName(selectTag)) 53 return validationMessageValueMissingForSelectText(); 54 if (isInputElement) 55 return static_cast<HTMLInputElement*>(element)->valueMissingText(); 56 return validationMessageValueMissingText(); 57 } 58 if (typeMismatch()) { 59 if (isInputElement) 60 return static_cast<HTMLInputElement*>(element)->typeMismatchText(); 61 return validationMessageTypeMismatchText(); 62 } 63 if (patternMismatch()) 64 return validationMessagePatternMismatchText(); 65 if (tooLong()) { 66 if (!isInputElement && !isTextAreaElement) { 67 ASSERT_NOT_REACHED(); 68 return String(); 69 } 70 HTMLTextFormControlElement* text = static_cast<HTMLTextFormControlElement*>(element); 71 return validationMessageTooLongText(numGraphemeClusters(text->value()), text->maxLength()); 72 } 73 if (rangeUnderflow()) { 74 if (!isInputElement) { 75 ASSERT_NOT_REACHED(); 76 return String(); 77 } 78 return validationMessageRangeUnderflowText(static_cast<HTMLInputElement*>(element)->minimumString()); 79 } 80 if (rangeOverflow()) { 81 if (!isInputElement) { 82 ASSERT_NOT_REACHED(); 83 return String(); 84 } 85 return validationMessageRangeOverflowText(static_cast<HTMLInputElement*>(element)->maximumString()); 86 } 87 if (stepMismatch()) { 88 if (!isInputElement) { 89 ASSERT_NOT_REACHED(); 90 return String(); 91 } 92 HTMLInputElement* input = static_cast<HTMLInputElement*>(element); 93 return validationMessageStepMismatchText(input->stepBaseString(), input->stepString()); 94 } 95 96 return String(); 97 } 98 99 void ValidityState::setCustomErrorMessage(const String& message) 100 { 101 m_customErrorMessage = message; 102 if (m_control->isFormControlElement()) 103 static_cast<HTMLFormControlElement*>(m_control)->setNeedsValidityCheck(); 41 return m_control->validationMessage(); 104 42 } 105 43 106 44 bool ValidityState::valueMissing() const 107 45 { 108 HTMLElement* element = toHTMLElement(m_control); 109 if (!element->willValidate()) 110 return false; 111 112 if (element->hasTagName(inputTag)) { 113 HTMLInputElement* input = static_cast<HTMLInputElement*>(element); 114 return input->valueMissing(input->value()); 115 } 116 if (element->hasTagName(textareaTag)) { 117 HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(element); 118 return textArea->valueMissing(textArea->value()); 119 } 120 if (element->hasTagName(selectTag)) 121 return toHTMLSelectElement(element)->valueMissing(); 122 return false; 46 return m_control->valueMissing(); 123 47 } 124 48 125 49 bool ValidityState::typeMismatch() const 126 50 { 127 HTMLElement* element = toHTMLElement(m_control); 128 if (!element->willValidate()) 129 return false; 130 131 if (!element->hasTagName(inputTag)) 132 return false; 133 return static_cast<HTMLInputElement*>(element)->typeMismatch(); 51 return m_control->typeMismatch(); 134 52 } 135 53 136 54 bool ValidityState::patternMismatch() const 137 55 { 138 HTMLElement* element = toHTMLElement(m_control); 139 if (!element->willValidate()) 140 return false; 141 142 if (!element->hasTagName(inputTag)) 143 return false; 144 HTMLInputElement* input = static_cast<HTMLInputElement*>(element); 145 return input->patternMismatch(input->value()); 56 return m_control->patternMismatch(); 146 57 } 147 58 148 59 bool ValidityState::tooLong() const 149 60 { 150 HTMLElement* element = toHTMLElement(m_control); 151 if (!element->willValidate()) 152 return false; 153 154 if (element->hasTagName(inputTag)) { 155 HTMLInputElement* input = static_cast<HTMLInputElement*>(element); 156 return input->tooLong(input->value(), HTMLTextFormControlElement::CheckDirtyFlag); 157 } 158 if (element->hasTagName(textareaTag)) { 159 HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(element); 160 return textArea->tooLong(textArea->value(), HTMLTextFormControlElement::CheckDirtyFlag); 161 } 162 return false; 61 return m_control->tooLong(); 163 62 } 164 63 165 64 bool ValidityState::rangeUnderflow() const 166 65 { 167 HTMLElement* element = toHTMLElement(m_control); 168 if (!element->willValidate()) 169 return false; 170 171 if (!element->hasTagName(inputTag)) 172 return false; 173 HTMLInputElement* input = static_cast<HTMLInputElement*>(element); 174 return input->rangeUnderflow(input->value()); 66 return m_control->rangeUnderflow(); 175 67 } 176 68 177 69 bool ValidityState::rangeOverflow() const 178 70 { 179 HTMLElement* element = toHTMLElement(m_control); 180 if (!element->willValidate()) 181 return false; 182 183 if (!element->hasTagName(inputTag)) 184 return false; 185 HTMLInputElement* input = static_cast<HTMLInputElement*>(element); 186 return input->rangeOverflow(input->value()); 71 return m_control->rangeOverflow(); 187 72 } 188 73 189 74 bool ValidityState::stepMismatch() const 190 75 { 191 HTMLElement* element = toHTMLElement(m_control); 192 if (!element->willValidate()) 193 return false; 194 195 if (!element->hasTagName(inputTag)) 196 return false; 197 HTMLInputElement* input = static_cast<HTMLInputElement*>(element); 198 return input->stepMismatch(input->value()); 76 return m_control->stepMismatch(); 199 77 } 200 78 201 79 bool ValidityState::customError() const 202 80 { 203 HTMLElement* element = toHTMLElement(m_control); 204 return element->willValidate() && !m_customErrorMessage.isEmpty(); 81 return m_control->customError(); 205 82 } 206 83 207 84 bool ValidityState::valid() const 208 85 { 209 bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() 210 || tooLong() || patternMismatch() || valueMissing() || customError(); 211 return !someError; 86 return m_control->valid(); 212 87 } 213 88 -
trunk/Source/WebCore/html/ValidityState.h
r116756 r116915 58 58 ValidityState(FormAssociatedElement* control) : m_control(control) { } 59 59 60 static bool isValidColorString(const String&);61 static bool isValidEmailAddress(const String&);62 63 60 FormAssociatedElement* m_control; 64 String m_customErrorMessage;65 61 }; 66 62
Note: See TracChangeset
for help on using the changeset viewer.