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, 2008, 2010 Apple Inc. All rights reserv ed. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed. |
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) | 7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 wrap = NoWrap; | 182 wrap = NoWrap; |
183 else | 183 else |
184 wrap = SoftWrap; | 184 wrap = SoftWrap; |
185 if (wrap != m_wrap) { | 185 if (wrap != m_wrap) { |
186 m_wrap = wrap; | 186 m_wrap = wrap; |
187 if (renderer()) | 187 if (renderer()) |
188 renderer()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalid ation(); | 188 renderer()->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalid ation(); |
189 } | 189 } |
190 } else if (name == accesskeyAttr) { | 190 } else if (name == accesskeyAttr) { |
191 // ignore for the moment | 191 // ignore for the moment |
192 } else if (name == maxlengthAttr) | 192 } else if (name == maxlengthAttr) { |
193 setNeedsValidityCheck(); | 193 setNeedsValidityCheck(); |
194 else | 194 } else if (name == minlengthAttr) { |
195 setNeedsValidityCheck(); | |
196 } else | |
195 HTMLTextFormControlElement::parseAttribute(name, value); | 197 HTMLTextFormControlElement::parseAttribute(name, value); |
196 } | 198 } |
197 | 199 |
198 RenderObject* HTMLTextAreaElement::createRenderer(RenderStyle*) | 200 RenderObject* HTMLTextAreaElement::createRenderer(RenderStyle*) |
199 { | 201 { |
200 return new RenderTextControlMultiLine(this); | 202 return new RenderTextControlMultiLine(this); |
201 } | 203 } |
202 | 204 |
203 bool HTMLTextAreaElement::appendFormData(FormDataList& encoding, bool) | 205 bool HTMLTextAreaElement::appendFormData(FormDataList& encoding, bool) |
204 { | 206 { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 setNonDirtyValue(value); | 446 setNonDirtyValue(value); |
445 } | 447 } |
446 | 448 |
447 int HTMLTextAreaElement::maxLength() const | 449 int HTMLTextAreaElement::maxLength() const |
448 { | 450 { |
449 bool ok; | 451 bool ok; |
450 int value = getAttribute(maxlengthAttr).toInt(&ok); | 452 int value = getAttribute(maxlengthAttr).toInt(&ok); |
451 return ok && value >= 0 ? value : -1; | 453 return ok && value >= 0 ? value : -1; |
452 } | 454 } |
453 | 455 |
456 int HTMLTextAreaElement::minLength() const | |
457 { | |
458 bool ok; | |
459 int value = getAttribute(minlengthAttr).string().toInt(&ok); | |
460 return ok && value >= 0 ? value : -1; | |
461 } | |
462 | |
454 void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionState& exceptionSt ate) | 463 void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionState& exceptionSt ate) |
455 { | 464 { |
465 int min = minLength(); | |
456 if (newValue < 0) | 466 if (newValue < 0) |
457 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is not positive or 0."); | 467 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is not positive or 0."); |
468 else if (min >= 0 && newValue < min) | |
469 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is less than minlength" + String::number(min) + "."); | |
458 else | 470 else |
459 setIntegralAttribute(maxlengthAttr, newValue); | 471 setIntegralAttribute(maxlengthAttr, newValue); |
460 } | 472 } |
461 | 473 |
474 void HTMLTextAreaElement::setMinLength(int newValue, ExceptionState& exceptionSt ate) | |
475 { | |
476 int max = maxLength(); | |
477 if (newValue < 0) | |
478 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is not positive or 0."); | |
479 else if (max >= 0 && newValue > max) | |
480 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is more than maxlength" + String::number(max) + "."); | |
481 else | |
482 setIntegralAttribute(minlengthAttr, newValue); | |
483 } | |
484 | |
462 String HTMLTextAreaElement::suggestedValue() const | 485 String HTMLTextAreaElement::suggestedValue() const |
463 { | 486 { |
464 return m_suggestedValue; | 487 return m_suggestedValue; |
465 } | 488 } |
466 | 489 |
467 void HTMLTextAreaElement::setSuggestedValue(const String& value) | 490 void HTMLTextAreaElement::setSuggestedValue(const String& value) |
468 { | 491 { |
469 m_suggestedValue = value; | 492 m_suggestedValue = value; |
470 | 493 |
471 if (!value.isNull()) | 494 if (!value.isNull()) |
(...skipping 11 matching lines...) Expand all Loading... | |
483 | 506 |
484 if (customError()) | 507 if (customError()) |
485 return customValidationMessage(); | 508 return customValidationMessage(); |
486 | 509 |
487 if (valueMissing()) | 510 if (valueMissing()) |
488 return locale().queryString(blink::WebLocalizedString::ValidationValueMi ssing); | 511 return locale().queryString(blink::WebLocalizedString::ValidationValueMi ssing); |
489 | 512 |
490 if (tooLong()) | 513 if (tooLong()) |
491 return locale().validationMessageTooLongText(computeLengthForSubmission( value()), maxLength()); | 514 return locale().validationMessageTooLongText(computeLengthForSubmission( value()), maxLength()); |
492 | 515 |
516 if (tooShort()) | |
517 return "Too short"; // DO NOT CHECK IN!!! | |
keishi
2014/10/06 03:58:23
Ditto.
Bartek Nowierski
2014/10/06 13:18:16
Acknowledged.
| |
518 // TODO(bartekn): Add a localized message for tooShort(). | |
519 // return locale().validationMessageTooShortText(computeLengthForSubmiss ion(value()), minLength()); | |
keishi
2014/10/06 03:58:23
Ditto.
Bartek Nowierski
2014/10/06 13:18:16
Acknowledged.
| |
520 | |
493 return String(); | 521 return String(); |
494 } | 522 } |
495 | 523 |
496 bool HTMLTextAreaElement::valueMissing() const | 524 bool HTMLTextAreaElement::valueMissing() const |
497 { | 525 { |
498 // We should not call value() for performance. | 526 // We should not call value() for performance. |
499 return willValidate() && valueMissing(0); | 527 return willValidate() && valueMissing(0); |
500 } | 528 } |
501 | 529 |
502 bool HTMLTextAreaElement::valueMissing(const String* value) const | 530 bool HTMLTextAreaElement::valueMissing(const String* value) const |
503 { | 531 { |
504 return isRequiredFormControl() && !isDisabledOrReadOnly() && (value ? *value : this->value()).isEmpty(); | 532 return isRequiredFormControl() && !isDisabledOrReadOnly() && (value ? *value : this->value()).isEmpty(); |
505 } | 533 } |
506 | 534 |
507 bool HTMLTextAreaElement::tooLong() const | 535 bool HTMLTextAreaElement::tooLong() const |
508 { | 536 { |
509 // We should not call value() for performance. | 537 // We should not call value() for performance. |
510 return willValidate() && tooLong(0, CheckDirtyFlag); | 538 return willValidate() && tooLong(0, CheckDirtyFlag); |
511 } | 539 } |
512 | 540 |
541 bool HTMLTextAreaElement::tooShort() const | |
542 { | |
543 // We should not call value() for performance. | |
544 return willValidate() && tooShort(0, CheckDirtyFlag); | |
545 } | |
546 | |
513 bool HTMLTextAreaElement::tooLong(const String* value, NeedsToCheckDirtyFlag che ck) const | 547 bool HTMLTextAreaElement::tooLong(const String* value, NeedsToCheckDirtyFlag che ck) const |
514 { | 548 { |
515 // Return false for the default value or value set by script even if it is | 549 // Return false for the default value or value set by script even if it is |
516 // longer than maxLength. | 550 // longer than maxLength. |
517 if (check == CheckDirtyFlag && !lastChangeWasUserEdit()) | 551 if (check == CheckDirtyFlag && !lastChangeWasUserEdit()) |
518 return false; | 552 return false; |
519 | 553 |
520 int max = maxLength(); | 554 int max = maxLength(); |
521 if (max < 0) | 555 if (max < 0) |
522 return false; | 556 return false; |
523 return computeLengthForSubmission(value ? *value : this->value()) > static_c ast<unsigned>(max); | 557 return computeLengthForSubmission(value ? *value : this->value()) > static_c ast<unsigned>(max); |
524 } | 558 } |
525 | 559 |
560 bool HTMLTextAreaElement::tooShort(const String* value, NeedsToCheckDirtyFlag ch eck) const | |
561 { | |
562 // Return false for the default value or value set by script even if it is | |
563 // shorter than minLength. | |
564 if (check == CheckDirtyFlag && !lastChangeWasUserEdit()) | |
565 return false; | |
566 | |
567 int min = minLength(); | |
568 if (min <= 0) | |
569 return false; | |
570 // An empty string is excluded from minlength check. | |
571 unsigned len = computeLengthForSubmission(value ? *value : this->value()); | |
572 return len > 0 && len < static_cast<unsigned>(min); | |
573 } | |
574 | |
526 bool HTMLTextAreaElement::isValidValue(const String& candidate) const | 575 bool HTMLTextAreaElement::isValidValue(const String& candidate) const |
527 { | 576 { |
528 return !valueMissing(&candidate) && !tooLong(&candidate, IgnoreDirtyFlag); | 577 return !valueMissing(&candidate) && !tooLong(&candidate, IgnoreDirtyFlag) && !tooShort(&candidate, IgnoreDirtyFlag); |
529 } | 578 } |
530 | 579 |
531 void HTMLTextAreaElement::accessKeyAction(bool) | 580 void HTMLTextAreaElement::accessKeyAction(bool) |
532 { | 581 { |
533 focus(); | 582 focus(); |
534 } | 583 } |
535 | 584 |
536 void HTMLTextAreaElement::setCols(int cols) | 585 void HTMLTextAreaElement::setCols(int cols) |
537 { | 586 { |
538 setIntegralAttribute(colsAttr, cols); | 587 setIntegralAttribute(colsAttr, cols); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 { | 625 { |
577 return true; | 626 return true; |
578 } | 627 } |
579 | 628 |
580 bool HTMLTextAreaElement::supportsAutofocus() const | 629 bool HTMLTextAreaElement::supportsAutofocus() const |
581 { | 630 { |
582 return true; | 631 return true; |
583 } | 632 } |
584 | 633 |
585 } | 634 } |
OLD | NEW |