Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: Source/core/html/HTMLInputElement.cpp

Issue 84693008: Improve HTMLInputElement exception messages. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/fast/forms/week/week-setrangetext-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
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 * Copyright (C) 2010 Google Inc. All rights reserved. 8 * Copyright (C) 2010 Google Inc. All rights reserved.
9 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 9 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
10 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 10 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
(...skipping 14 matching lines...) Expand all
25 * Boston, MA 02110-1301, USA. 25 * Boston, MA 02110-1301, USA.
26 * 26 *
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 #include "core/html/HTMLInputElement.h" 30 #include "core/html/HTMLInputElement.h"
31 31
32 #include "CSSPropertyNames.h" 32 #include "CSSPropertyNames.h"
33 #include "HTMLNames.h" 33 #include "HTMLNames.h"
34 #include "RuntimeEnabledFeatures.h" 34 #include "RuntimeEnabledFeatures.h"
35 #include "bindings/v8/ExceptionMessages.h"
35 #include "bindings/v8/ExceptionState.h" 36 #include "bindings/v8/ExceptionState.h"
36 #include "bindings/v8/ScriptEventListener.h" 37 #include "bindings/v8/ScriptEventListener.h"
37 #include "core/accessibility/AXObjectCache.h" 38 #include "core/accessibility/AXObjectCache.h"
38 #include "core/dom/Document.h" 39 #include "core/dom/Document.h"
39 #include "core/dom/ExceptionCode.h" 40 #include "core/dom/ExceptionCode.h"
40 #include "core/dom/IdTargetObserver.h" 41 #include "core/dom/IdTargetObserver.h"
41 #include "core/dom/shadow/ElementShadow.h" 42 #include "core/dom/shadow/ElementShadow.h"
42 #include "core/dom/shadow/InsertionPoint.h" 43 #include "core/dom/shadow/InsertionPoint.h"
43 #include "core/dom/shadow/ShadowRoot.h" 44 #include "core/dom/shadow/ShadowRoot.h"
44 #include "core/editing/FrameSelection.h" 45 #include "core/editing/FrameSelection.h"
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 } 518 }
518 519
519 bool HTMLInputElement::canHaveSelection() const 520 bool HTMLInputElement::canHaveSelection() const
520 { 521 {
521 return isTextField(); 522 return isTextField();
522 } 523 }
523 524
524 int HTMLInputElement::selectionStartForBinding(ExceptionState& exceptionState) c onst 525 int HTMLInputElement::selectionStartForBinding(ExceptionState& exceptionState) c onst
525 { 526 {
526 if (!canHaveSelection()) { 527 if (!canHaveSelection()) {
527 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 528 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToGet("selectionStart", "HTMLInputElement", "The input element's type ('" + m_inputType->formControlType() + "') does not support selection."));
528 return 0; 529 return 0;
529 } 530 }
530 return HTMLTextFormControlElement::selectionStart(); 531 return HTMLTextFormControlElement::selectionStart();
531 } 532 }
532 533
533 int HTMLInputElement::selectionEndForBinding(ExceptionState& exceptionState) con st 534 int HTMLInputElement::selectionEndForBinding(ExceptionState& exceptionState) con st
534 { 535 {
535 if (!canHaveSelection()) { 536 if (!canHaveSelection()) {
536 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 537 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToGet("selectionEnd", "HTMLInputElement", "The input element's type ('" + m _inputType->formControlType() + "') does not support selection."));
537 return 0; 538 return 0;
538 } 539 }
539 return HTMLTextFormControlElement::selectionEnd(); 540 return HTMLTextFormControlElement::selectionEnd();
540 } 541 }
541 542
542 String HTMLInputElement::selectionDirectionForBinding(ExceptionState& exceptionS tate) const 543 String HTMLInputElement::selectionDirectionForBinding(ExceptionState& exceptionS tate) const
543 { 544 {
544 if (!canHaveSelection()) { 545 if (!canHaveSelection()) {
545 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 546 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToGet("selectionDirection", "HTMLInputElement", "The input element's type ( '" + m_inputType->formControlType() + "') does not support selection."));
546 return String(); 547 return String();
547 } 548 }
548 return HTMLTextFormControlElement::selectionDirection(); 549 return HTMLTextFormControlElement::selectionDirection();
549 } 550 }
550 551
551 void HTMLInputElement::setSelectionStartForBinding(int start, ExceptionState& ex ceptionState) 552 void HTMLInputElement::setSelectionStartForBinding(int start, ExceptionState& ex ceptionState)
552 { 553 {
553 if (!canHaveSelection()) { 554 if (!canHaveSelection()) {
554 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 555 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToSet("selectionStart", "HTMLInputElement", "The input element's type ('" + m_inputType->formControlType() + "') does not support selection."));
555 return; 556 return;
556 } 557 }
557 HTMLTextFormControlElement::setSelectionStart(start); 558 HTMLTextFormControlElement::setSelectionStart(start);
558 } 559 }
559 560
560 void HTMLInputElement::setSelectionEndForBinding(int end, ExceptionState& except ionState) 561 void HTMLInputElement::setSelectionEndForBinding(int end, ExceptionState& except ionState)
561 { 562 {
562 if (!canHaveSelection()) { 563 if (!canHaveSelection()) {
563 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 564 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToSet("selectionEnd", "HTMLInputElement", "The input element's type ('" + m _inputType->formControlType() + "') does not support selection."));
564 return; 565 return;
565 } 566 }
566 HTMLTextFormControlElement::setSelectionEnd(end); 567 HTMLTextFormControlElement::setSelectionEnd(end);
567 } 568 }
568 569
569 void HTMLInputElement::setSelectionDirectionForBinding(const String& direction, ExceptionState& exceptionState) 570 void HTMLInputElement::setSelectionDirectionForBinding(const String& direction, ExceptionState& exceptionState)
570 { 571 {
571 if (!canHaveSelection()) { 572 if (!canHaveSelection()) {
572 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 573 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToSet("selectionDirection", "HTMLInputElement", "The input element's type ( '" + m_inputType->formControlType() + "') does not support selection."));
573 return; 574 return;
574 } 575 }
575 HTMLTextFormControlElement::setSelectionDirection(direction); 576 HTMLTextFormControlElement::setSelectionDirection(direction);
576 } 577 }
577 578
578 void HTMLInputElement::setSelectionRangeForBinding(int start, int end, Exception State& exceptionState) 579 void HTMLInputElement::setSelectionRangeForBinding(int start, int end, Exception State& exceptionState)
579 { 580 {
580 if (!canHaveSelection()) { 581 if (!canHaveSelection()) {
581 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 582 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToSet("selectionRange", "HTMLInputElement", "The input element's type ('" + m_inputType->formControlType() + "') does not support selection."));
582 return; 583 return;
583 } 584 }
584 HTMLTextFormControlElement::setSelectionRange(start, end); 585 HTMLTextFormControlElement::setSelectionRange(start, end);
585 } 586 }
586 587
587 void HTMLInputElement::setSelectionRangeForBinding(int start, int end, const Str ing& direction, ExceptionState& exceptionState) 588 void HTMLInputElement::setSelectionRangeForBinding(int start, int end, const Str ing& direction, ExceptionState& exceptionState)
588 { 589 {
589 if (!canHaveSelection()) { 590 if (!canHaveSelection()) {
590 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 591 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToSet("selectionRange", "HTMLInputElement", "The input element's type ('" + m_inputType->formControlType() + "') does not support selection."));
591 return; 592 return;
592 } 593 }
593 HTMLTextFormControlElement::setSelectionRange(start, end, direction); 594 HTMLTextFormControlElement::setSelectionRange(start, end, direction);
594 } 595 }
595 596
596 void HTMLInputElement::accessKeyAction(bool sendMouseEvents) 597 void HTMLInputElement::accessKeyAction(bool sendMouseEvents)
597 { 598 {
598 m_inputType->accessKeyAction(sendMouseEvents); 599 m_inputType->accessKeyAction(sendMouseEvents);
599 } 600 }
600 601
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 setSelectionRange(max, max); 995 setSelectionRange(max, max);
995 else 996 else
996 cacheSelectionInResponseToSetValue(max); 997 cacheSelectionInResponseToSetValue(max);
997 998
998 dispatchInputEvent(); 999 dispatchInputEvent();
999 } 1000 }
1000 1001
1001 void HTMLInputElement::setValue(const String& value, ExceptionState& exceptionSt ate, TextFieldEventBehavior eventBehavior) 1002 void HTMLInputElement::setValue(const String& value, ExceptionState& exceptionSt ate, TextFieldEventBehavior eventBehavior)
1002 { 1003 {
1003 if (isFileUpload() && !value.isEmpty()) { 1004 if (isFileUpload() && !value.isEmpty()) {
1004 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 1005 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToSet("value", "HTMLInputElement", "This input element accepts a filename, which may only be programatically set to the empty string."));
1005 return; 1006 return;
1006 } 1007 }
1007 setValue(value, eventBehavior); 1008 setValue(value, eventBehavior);
1008 } 1009 }
1009 1010
1010 void HTMLInputElement::setValue(const String& value, TextFieldEventBehavior even tBehavior) 1011 void HTMLInputElement::setValue(const String& value, TextFieldEventBehavior even tBehavior)
1011 { 1012 {
1012 if (!m_inputType->canSetValue(value)) 1013 if (!m_inputType->canSetValue(value))
1013 return; 1014 return;
1014 1015
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 } 1051 }
1051 1052
1052 double HTMLInputElement::valueAsNumber() const 1053 double HTMLInputElement::valueAsNumber() const
1053 { 1054 {
1054 return m_inputType->valueAsDouble(); 1055 return m_inputType->valueAsDouble();
1055 } 1056 }
1056 1057
1057 void HTMLInputElement::setValueAsNumber(double newValue, ExceptionState& excepti onState, TextFieldEventBehavior eventBehavior) 1058 void HTMLInputElement::setValueAsNumber(double newValue, ExceptionState& excepti onState, TextFieldEventBehavior eventBehavior)
1058 { 1059 {
1059 if (!std::isfinite(newValue)) { 1060 if (!std::isfinite(newValue)) {
1060 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); 1061 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::f ailedToSet("valueAsNumber", "HTMLInputElement", ExceptionMessages::notAFiniteNum ber(newValue)));
1061 return; 1062 return;
1062 } 1063 }
1063 m_inputType->setValueAsDouble(newValue, eventBehavior, exceptionState); 1064 m_inputType->setValueAsDouble(newValue, eventBehavior, exceptionState);
1064 } 1065 }
1065 1066
1066 void HTMLInputElement::setValueFromRenderer(const String& value) 1067 void HTMLInputElement::setValueFromRenderer(const String& value)
1067 { 1068 {
1068 // File upload controls will never use this. 1069 // File upload controls will never use this.
1069 ASSERT(!isFileUpload()); 1070 ASSERT(!isFileUpload());
1070 1071
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 } 1286 }
1286 1287
1287 int HTMLInputElement::maxLength() const 1288 int HTMLInputElement::maxLength() const
1288 { 1289 {
1289 return m_maxLength; 1290 return m_maxLength;
1290 } 1291 }
1291 1292
1292 void HTMLInputElement::setMaxLength(int maxLength, ExceptionState& exceptionStat e) 1293 void HTMLInputElement::setMaxLength(int maxLength, ExceptionState& exceptionStat e)
1293 { 1294 {
1294 if (maxLength < 0) 1295 if (maxLength < 0)
1295 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError); 1296 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::fail edToSet("maxLength", "HTMLInputElement", "The value provided (" + String::number (maxLength) + ") is negative."));
1296 else 1297 else
1297 setIntegralAttribute(maxlengthAttr, maxLength); 1298 setIntegralAttribute(maxlengthAttr, maxLength);
1298 } 1299 }
1299 1300
1300 bool HTMLInputElement::multiple() const 1301 bool HTMLInputElement::multiple() const
1301 { 1302 {
1302 return fastHasAttribute(multipleAttr); 1303 return fastHasAttribute(multipleAttr);
1303 } 1304 }
1304 1305
1305 void HTMLInputElement::setSize(unsigned size) 1306 void HTMLInputElement::setSize(unsigned size)
1306 { 1307 {
1307 setUnsignedIntegralAttribute(sizeAttr, size); 1308 setUnsignedIntegralAttribute(sizeAttr, size);
1308 } 1309 }
1309 1310
1310 void HTMLInputElement::setSize(unsigned size, ExceptionState& exceptionState) 1311 void HTMLInputElement::setSize(unsigned size, ExceptionState& exceptionState)
1311 { 1312 {
1312 if (!size) 1313 if (!size)
1313 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError); 1314 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::fail edToSet("size", "HTMLInputElement", "The value provided is 0, which is an invali d size."));
1314 else 1315 else
1315 setSize(size); 1316 setSize(size);
1316 } 1317 }
1317 1318
1318 KURL HTMLInputElement::src() const 1319 KURL HTMLInputElement::src() const
1319 { 1320 {
1320 return document().completeURL(fastGetAttribute(srcAttr)); 1321 return document().completeURL(fastGetAttribute(srcAttr));
1321 } 1322 }
1322 1323
1323 FileList* HTMLInputElement::files() 1324 FileList* HTMLInputElement::files()
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 } 1787 }
1787 1788
1788 void ListAttributeTargetObserver::idTargetChanged() 1789 void ListAttributeTargetObserver::idTargetChanged()
1789 { 1790 {
1790 m_element->listAttributeTargetChanged(); 1791 m_element->listAttributeTargetChanged();
1791 } 1792 }
1792 1793
1793 void HTMLInputElement::setRangeText(const String& replacement, ExceptionState& e xceptionState) 1794 void HTMLInputElement::setRangeText(const String& replacement, ExceptionState& e xceptionState)
1794 { 1795 {
1795 if (!m_inputType->supportsSelectionAPI()) { 1796 if (!m_inputType->supportsSelectionAPI()) {
1796 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 1797 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToExecute("setRangeText", "HTMLInputElement", "The input element's type ('" + m_inputType->formControlType() + "') does not support selection."));
1797 return; 1798 return;
1798 } 1799 }
1799 1800
1800 HTMLTextFormControlElement::setRangeText(replacement, exceptionState); 1801 HTMLTextFormControlElement::setRangeText(replacement, exceptionState);
1801 } 1802 }
1802 1803
1803 void HTMLInputElement::setRangeText(const String& replacement, unsigned start, u nsigned end, const String& selectionMode, ExceptionState& exceptionState) 1804 void HTMLInputElement::setRangeText(const String& replacement, unsigned start, u nsigned end, const String& selectionMode, ExceptionState& exceptionState)
1804 { 1805 {
1805 if (!m_inputType->supportsSelectionAPI()) { 1806 if (!m_inputType->supportsSelectionAPI()) {
1806 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro r); 1807 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToExecute("setRangeText", "HTMLInputElement", "The input element's type ('" + m_inputType->formControlType() + "') does not support selection."));
1807 return; 1808 return;
1808 } 1809 }
1809 1810
1810 HTMLTextFormControlElement::setRangeText(replacement, start, end, selectionM ode, exceptionState); 1811 HTMLTextFormControlElement::setRangeText(replacement, start, end, selectionM ode, exceptionState);
1811 } 1812 }
1812 1813
1813 bool HTMLInputElement::setupDateTimeChooserParameters(DateTimeChooserParameters& parameters) 1814 bool HTMLInputElement::setupDateTimeChooserParameters(DateTimeChooserParameters& parameters)
1814 { 1815 {
1815 if (!document().view()) 1816 if (!document().view())
1816 return false; 1817 return false;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1865 } 1866 }
1866 1867
1867 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 1868 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
1868 PassRefPtr<RenderStyle> HTMLInputElement::customStyleForRenderer() 1869 PassRefPtr<RenderStyle> HTMLInputElement::customStyleForRenderer()
1869 { 1870 {
1870 return m_inputTypeView->customStyleForRenderer(originalStyleForRenderer()); 1871 return m_inputTypeView->customStyleForRenderer(originalStyleForRenderer());
1871 } 1872 }
1872 #endif 1873 #endif
1873 1874
1874 } // namespace 1875 } // namespace
OLDNEW
« no previous file with comments | « LayoutTests/fast/forms/week/week-setrangetext-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698