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

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

Issue 2368193002: Introduce HTMLInputElement::m_hasDirtyValue. (Closed)
Patch Set: Fix Windows build Created 4 years, 2 months 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
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLInputElement.h ('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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // get rather sluggish when a text field has a larger number of characters than 95 // get rather sluggish when a text field has a larger number of characters than
96 // this, even when just clicking in the text field. 96 // this, even when just clicking in the text field.
97 const int HTMLInputElement::maximumLength = 524288; 97 const int HTMLInputElement::maximumLength = 524288;
98 const int defaultSize = 20; 98 const int defaultSize = 20;
99 99
100 HTMLInputElement::HTMLInputElement(Document& document, HTMLFormElement* form, bo ol createdByParser) 100 HTMLInputElement::HTMLInputElement(Document& document, HTMLFormElement* form, bo ol createdByParser)
101 : HTMLTextFormControlElement(inputTag, document, form) 101 : HTMLTextFormControlElement(inputTag, document, form)
102 , m_size(defaultSize) 102 , m_size(defaultSize)
103 , m_maxLength(maximumLength) 103 , m_maxLength(maximumLength)
104 , m_minLength(-1) 104 , m_minLength(-1)
105 , m_hasDirtyValue(false)
105 , m_isChecked(false) 106 , m_isChecked(false)
106 , m_dirtyCheckedness(false) 107 , m_dirtyCheckedness(false)
107 , m_isIndeterminate(false) 108 , m_isIndeterminate(false)
108 , m_isActivatedSubmit(false) 109 , m_isActivatedSubmit(false)
109 , m_autocomplete(Uninitialized) 110 , m_autocomplete(Uninitialized)
110 , m_hasNonEmptyList(false) 111 , m_hasNonEmptyList(false)
111 , m_stateRestored(false) 112 , m_stateRestored(false)
112 , m_parsingInProgress(createdByParser) 113 , m_parsingInProgress(createdByParser)
113 , m_valueAttributeWasUpdatedAfterParsing(false) 114 , m_valueAttributeWasUpdatedAfterParsing(false)
114 , m_canReceiveDroppedFiles(false) 115 , m_canReceiveDroppedFiles(false)
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 m_inputTypeView = m_inputType->createView(); 448 m_inputTypeView = m_inputType->createView();
448 m_inputTypeView->createShadowSubtree(); 449 m_inputTypeView->createShadowSubtree();
449 450
450 setNeedsWillValidateCheck(); 451 setNeedsWillValidateCheck();
451 452
452 bool willStoreValue = m_inputType->storesValueSeparateFromAttribute(); 453 bool willStoreValue = m_inputType->storesValueSeparateFromAttribute();
453 454
454 if (didStoreValue && !willStoreValue && hasDirtyValue()) { 455 if (didStoreValue && !willStoreValue && hasDirtyValue()) {
455 setAttribute(valueAttr, AtomicString(m_valueIfDirty)); 456 setAttribute(valueAttr, AtomicString(m_valueIfDirty));
456 m_valueIfDirty = String(); 457 m_valueIfDirty = String();
458 m_hasDirtyValue = false;
457 } 459 }
458 if (!didStoreValue && willStoreValue) { 460 if (!didStoreValue && willStoreValue) {
459 AtomicString valueString = fastGetAttribute(valueAttr); 461 AtomicString valueString = fastGetAttribute(valueAttr);
460 m_inputType->warnIfValueIsInvalid(valueString); 462 m_inputType->warnIfValueIsInvalid(valueString);
461 m_valueIfDirty = sanitizeValue(valueString); 463 m_valueIfDirty = sanitizeValue(valueString);
464 m_hasDirtyValue = !m_valueIfDirty.isNull();
462 } else { 465 } else {
463 if (!hasDirtyValue()) 466 if (!hasDirtyValue())
464 m_inputType->warnIfValueIsInvalid(fastGetAttribute(valueAttr).getStr ing()); 467 m_inputType->warnIfValueIsInvalid(fastGetAttribute(valueAttr).getStr ing());
465 updateValueIfNeeded(); 468 updateValueIfNeeded();
466 } 469 }
467 470
468 m_needsToUpdateViewValue = true; 471 m_needsToUpdateViewValue = true;
469 m_inputTypeView->updateView(); 472 m_inputTypeView->updateView();
470 473
471 if (didRespectHeightAndWidth != m_inputType->shouldRespectHeightAndWidthAttr ibutes()) { 474 if (didRespectHeightAndWidth != m_inputType->shouldRespectHeightAndWidthAttr ibutes()) {
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 bool HTMLInputElement::sizeShouldIncludeDecoration(int& preferredSize) const 927 bool HTMLInputElement::sizeShouldIncludeDecoration(int& preferredSize) const
925 { 928 {
926 return m_inputTypeView->sizeShouldIncludeDecoration(defaultSize, preferredSi ze); 929 return m_inputTypeView->sizeShouldIncludeDecoration(defaultSize, preferredSi ze);
927 } 930 }
928 931
929 void HTMLInputElement::copyNonAttributePropertiesFromElement(const Element& sour ce) 932 void HTMLInputElement::copyNonAttributePropertiesFromElement(const Element& sour ce)
930 { 933 {
931 const HTMLInputElement& sourceElement = static_cast<const HTMLInputElement&> (source); 934 const HTMLInputElement& sourceElement = static_cast<const HTMLInputElement&> (source);
932 935
933 m_valueIfDirty = sourceElement.m_valueIfDirty; 936 m_valueIfDirty = sourceElement.m_valueIfDirty;
937 m_hasDirtyValue = sourceElement.m_hasDirtyValue;
934 setChecked(sourceElement.m_isChecked); 938 setChecked(sourceElement.m_isChecked);
935 m_dirtyCheckedness = sourceElement.m_dirtyCheckedness; 939 m_dirtyCheckedness = sourceElement.m_dirtyCheckedness;
936 m_isIndeterminate = sourceElement.m_isIndeterminate; 940 m_isIndeterminate = sourceElement.m_isIndeterminate;
937 941
938 HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source); 942 HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source);
939 943
940 m_needsToUpdateViewValue = true; 944 m_needsToUpdateViewValue = true;
941 m_inputTypeView->updateView(); 945 m_inputTypeView->updateView();
942 } 946 }
943 947
944 String HTMLInputElement::value() const 948 String HTMLInputElement::value() const
945 { 949 {
946 String value; 950 String value;
947 if (m_inputType->getTypeSpecificValue(value)) 951 if (m_inputType->getTypeSpecificValue(value))
948 return value; 952 return value;
949 953
950 value = m_valueIfDirty; 954 if (hasDirtyValue())
951 if (!value.isNull()) 955 return m_valueIfDirty;
952 return value;
953 956
954 AtomicString valueString = fastGetAttribute(valueAttr); 957 AtomicString valueString = fastGetAttribute(valueAttr);
955 value = sanitizeValue(valueString); 958 value = sanitizeValue(valueString);
956 if (!value.isNull()) 959 if (!value.isNull())
957 return value; 960 return value;
958 961
959 return m_inputType->fallbackValue(); 962 return m_inputType->fallbackValue();
960 } 963 }
961 964
962 String HTMLInputElement::valueWithDefault() const 965 String HTMLInputElement::valueWithDefault() const
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1042
1040 if (!valueChanged) 1043 if (!valueChanged)
1041 return; 1044 return;
1042 1045
1043 notifyFormStateChanged(); 1046 notifyFormStateChanged();
1044 } 1047 }
1045 1048
1046 void HTMLInputElement::setValueInternal(const String& sanitizedValue, TextFieldE ventBehavior eventBehavior) 1049 void HTMLInputElement::setValueInternal(const String& sanitizedValue, TextFieldE ventBehavior eventBehavior)
1047 { 1050 {
1048 m_valueIfDirty = sanitizedValue; 1051 m_valueIfDirty = sanitizedValue;
1052 m_hasDirtyValue = !m_valueIfDirty.isNull();
1049 setNeedsValidityCheck(); 1053 setNeedsValidityCheck();
1050 if (m_inputType->isSteppable()) { 1054 if (m_inputType->isSteppable()) {
1051 pseudoStateChanged(CSSSelector::PseudoInRange); 1055 pseudoStateChanged(CSSSelector::PseudoInRange);
1052 pseudoStateChanged(CSSSelector::PseudoOutOfRange); 1056 pseudoStateChanged(CSSSelector::PseudoOutOfRange);
1053 } 1057 }
1054 if (document().focusedElement() == this) 1058 if (document().focusedElement() == this)
1055 document().frameHost()->chromeClient().didUpdateTextOfFocusedElementByNo nUserInput(*document().frame()); 1059 document().frameHost()->chromeClient().didUpdateTextOfFocusedElementByNo nUserInput(*document().frame());
1056 } 1060 }
1057 1061
1062 bool HTMLInputElement::hasDirtyValue() const
1063 {
1064 DCHECK_EQ(!m_hasDirtyValue, m_valueIfDirty.isNull());
1065 return m_hasDirtyValue;
1066 }
1067
1058 void HTMLInputElement::updateView() 1068 void HTMLInputElement::updateView()
1059 { 1069 {
1060 m_inputTypeView->updateView(); 1070 m_inputTypeView->updateView();
1061 } 1071 }
1062 1072
1063 double HTMLInputElement::valueAsDate(bool& isNull) const 1073 double HTMLInputElement::valueAsDate(bool& isNull) const
1064 { 1074 {
1065 double date = m_inputType->valueAsDate(); 1075 double date = m_inputType->valueAsDate();
1066 isNull = !std::isfinite(date); 1076 isNull = !std::isfinite(date);
1067 return date; 1077 return date;
(...skipping 23 matching lines...) Expand all
1091 void HTMLInputElement::setValueFromRenderer(const String& value) 1101 void HTMLInputElement::setValueFromRenderer(const String& value)
1092 { 1102 {
1093 // File upload controls will never use this. 1103 // File upload controls will never use this.
1094 DCHECK_NE(type(), InputTypeNames::file); 1104 DCHECK_NE(type(), InputTypeNames::file);
1095 1105
1096 m_suggestedValue = String(); 1106 m_suggestedValue = String();
1097 1107
1098 // Renderer and our event handler are responsible for sanitizing values. 1108 // Renderer and our event handler are responsible for sanitizing values.
1099 DCHECK(value == m_inputType->sanitizeUserInputValue(value) || m_inputType->s anitizeUserInputValue(value).isEmpty()); 1109 DCHECK(value == m_inputType->sanitizeUserInputValue(value) || m_inputType->s anitizeUserInputValue(value).isEmpty());
1100 1110
1111 DCHECK(!value.isNull());
1101 m_valueIfDirty = value; 1112 m_valueIfDirty = value;
1113 m_hasDirtyValue = true;
1102 m_needsToUpdateViewValue = false; 1114 m_needsToUpdateViewValue = false;
1103 1115
1104 // Input event is fired by the Node::defaultEventHandler for editable contro ls. 1116 // Input event is fired by the Node::defaultEventHandler for editable contro ls.
1105 if (!isTextField()) 1117 if (!isTextField())
1106 dispatchInputEvent(); 1118 dispatchInputEvent();
1107 notifyFormStateChanged(); 1119 notifyFormStateChanged();
1108 1120
1109 setNeedsValidityCheck(); 1121 setNeedsValidityCheck();
1110 1122
1111 // Clear autofill flag (and yellow background) on user edit. 1123 // Clear autofill flag (and yellow background) on user edit.
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 { 1926 {
1915 return m_inputTypeView->hasFallbackContent(); 1927 return m_inputTypeView->hasFallbackContent();
1916 } 1928 }
1917 1929
1918 void HTMLInputElement::setFilesFromPaths(const Vector<String>& paths) 1930 void HTMLInputElement::setFilesFromPaths(const Vector<String>& paths)
1919 { 1931 {
1920 return m_inputType->setFilesFromPaths(paths); 1932 return m_inputType->setFilesFromPaths(paths);
1921 } 1933 }
1922 1934
1923 } // namespace blink 1935 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLInputElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698