Chromium Code Reviews| 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); | |
|
tkent
2014/10/15 00:50:25
should use parseHTMLInteger() like HTMLInputElemen
Bartek Nowierski
2014/10/16 04:55:14
Good point! I'll change it for both minLength and
| |
| 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, ExceptionMessages::inde xExceedsMinimumBound("maxLength", newValue, 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, ExceptionMessages::inde xExceedsMaximumBound("minLength", newValue, 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 locale().validationMessageTooShortText(computeLengthForSubmission (value()), minLength()); | |
| 518 | |
| 493 return String(); | 519 return String(); |
| 494 } | 520 } |
| 495 | 521 |
| 496 bool HTMLTextAreaElement::valueMissing() const | 522 bool HTMLTextAreaElement::valueMissing() const |
| 497 { | 523 { |
| 498 // We should not call value() for performance. | 524 // We should not call value() for performance. |
| 499 return willValidate() && valueMissing(0); | 525 return willValidate() && valueMissing(0); |
| 500 } | 526 } |
| 501 | 527 |
| 502 bool HTMLTextAreaElement::valueMissing(const String* value) const | 528 bool HTMLTextAreaElement::valueMissing(const String* value) const |
| 503 { | 529 { |
| 504 return isRequiredFormControl() && !isDisabledOrReadOnly() && (value ? *value : this->value()).isEmpty(); | 530 return isRequiredFormControl() && !isDisabledOrReadOnly() && (value ? *value : this->value()).isEmpty(); |
| 505 } | 531 } |
| 506 | 532 |
| 507 bool HTMLTextAreaElement::tooLong() const | 533 bool HTMLTextAreaElement::tooLong() const |
| 508 { | 534 { |
| 509 // We should not call value() for performance. | 535 // We should not call value() for performance. |
| 510 return willValidate() && tooLong(0, CheckDirtyFlag); | 536 return willValidate() && tooLong(0, CheckDirtyFlag); |
| 511 } | 537 } |
| 512 | 538 |
| 539 bool HTMLTextAreaElement::tooShort() const | |
| 540 { | |
| 541 // We should not call value() for performance. | |
| 542 return willValidate() && tooShort(0, CheckDirtyFlag); | |
| 543 } | |
| 544 | |
| 513 bool HTMLTextAreaElement::tooLong(const String* value, NeedsToCheckDirtyFlag che ck) const | 545 bool HTMLTextAreaElement::tooLong(const String* value, NeedsToCheckDirtyFlag che ck) const |
| 514 { | 546 { |
| 515 // Return false for the default value or value set by script even if it is | 547 // Return false for the default value or value set by script even if it is |
| 516 // longer than maxLength. | 548 // longer than maxLength. |
| 517 if (check == CheckDirtyFlag && !lastChangeWasUserEdit()) | 549 if (check == CheckDirtyFlag && !lastChangeWasUserEdit()) |
| 518 return false; | 550 return false; |
| 519 | 551 |
| 520 int max = maxLength(); | 552 int max = maxLength(); |
| 521 if (max < 0) | 553 if (max < 0) |
| 522 return false; | 554 return false; |
| 523 return computeLengthForSubmission(value ? *value : this->value()) > static_c ast<unsigned>(max); | 555 return computeLengthForSubmission(value ? *value : this->value()) > static_c ast<unsigned>(max); |
| 524 } | 556 } |
| 525 | 557 |
| 558 bool HTMLTextAreaElement::tooShort(const String* value, NeedsToCheckDirtyFlag ch eck) const | |
| 559 { | |
| 560 // Return false for the default value or value set by script even if it is | |
| 561 // shorter than minLength. | |
| 562 if (check == CheckDirtyFlag && !lastChangeWasUserEdit()) | |
| 563 return false; | |
| 564 | |
| 565 int min = minLength(); | |
| 566 if (min <= 0) | |
| 567 return false; | |
| 568 // An empty string is excluded from minlength check. | |
| 569 unsigned len = computeLengthForSubmission(value ? *value : this->value()); | |
| 570 return len > 0 && len < static_cast<unsigned>(min); | |
| 571 } | |
| 572 | |
| 526 bool HTMLTextAreaElement::isValidValue(const String& candidate) const | 573 bool HTMLTextAreaElement::isValidValue(const String& candidate) const |
| 527 { | 574 { |
| 528 return !valueMissing(&candidate) && !tooLong(&candidate, IgnoreDirtyFlag); | 575 return !valueMissing(&candidate) && !tooLong(&candidate, IgnoreDirtyFlag) && !tooShort(&candidate, IgnoreDirtyFlag); |
| 529 } | 576 } |
| 530 | 577 |
| 531 void HTMLTextAreaElement::accessKeyAction(bool) | 578 void HTMLTextAreaElement::accessKeyAction(bool) |
| 532 { | 579 { |
| 533 focus(); | 580 focus(); |
| 534 } | 581 } |
| 535 | 582 |
| 536 void HTMLTextAreaElement::setCols(int cols) | 583 void HTMLTextAreaElement::setCols(int cols) |
| 537 { | 584 { |
| 538 setIntegralAttribute(colsAttr, cols); | 585 setIntegralAttribute(colsAttr, cols); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 { | 623 { |
| 577 return true; | 624 return true; |
| 578 } | 625 } |
| 579 | 626 |
| 580 bool HTMLTextAreaElement::supportsAutofocus() const | 627 bool HTMLTextAreaElement::supportsAutofocus() const |
| 581 { | 628 { |
| 582 return true; | 629 return true; |
| 583 } | 630 } |
| 584 | 631 |
| 585 } | 632 } |
| OLD | NEW |