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

Side by Side Diff: Source/core/html/forms/EmailInputType.cpp

Issue 27746003: Have InputType factories take an HTMLInputElement reference in parameter (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/html/forms/EmailInputType.h ('k') | Source/core/html/forms/FileInputType.h » ('j') | 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 * This file is part of the WebKit project. 2 * This file is part of the WebKit project.
3 * 3 *
4 * Copyright (C) 2009 Michelangelo De Simone <micdesim@gmail.com> 4 * Copyright (C) 2009 Michelangelo De Simone <micdesim@gmail.com>
5 * Copyright (C) 2010 Google Inc. All rights reserved. 5 * Copyright (C) 2010 Google Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return false; 126 return false;
127 127
128 DEFINE_STATIC_LOCAL(const RegularExpression, regExp, (emailPattern, TextCase Insensitive)); 128 DEFINE_STATIC_LOCAL(const RegularExpression, regExp, (emailPattern, TextCase Insensitive));
129 129
130 int matchLength; 130 int matchLength;
131 int matchOffset = regExp.match(address, 0, &matchLength); 131 int matchOffset = regExp.match(address, 0, &matchLength);
132 132
133 return !matchOffset && matchLength == addressLength; 133 return !matchOffset && matchLength == addressLength;
134 } 134 }
135 135
136 PassRefPtr<InputType> EmailInputType::create(HTMLInputElement* element) 136 PassRefPtr<InputType> EmailInputType::create(HTMLInputElement& element)
137 { 137 {
138 return adoptRef(new EmailInputType(element)); 138 return adoptRef(new EmailInputType(element));
139 } 139 }
140 140
141 void EmailInputType::countUsage() 141 void EmailInputType::countUsage()
142 { 142 {
143 observeFeatureIfVisible(UseCounter::InputTypeEmail); 143 observeFeatureIfVisible(UseCounter::InputTypeEmail);
144 } 144 }
145 145
146 const AtomicString& EmailInputType::formControlType() const 146 const AtomicString& EmailInputType::formControlType() const
147 { 147 {
148 return InputTypeNames::email(); 148 return InputTypeNames::email();
149 } 149 }
150 150
151 // The return value is an invalid email address string if the specified string 151 // The return value is an invalid email address string if the specified string
152 // contains an invalid email address. Otherwise, null string is returned. 152 // contains an invalid email address. Otherwise, null string is returned.
153 // If an empty string is returned, it means empty address is specified. 153 // If an empty string is returned, it means empty address is specified.
154 // e.g. "foo@example.com,,bar@example.com" for multiple case. 154 // e.g. "foo@example.com,,bar@example.com" for multiple case.
155 String EmailInputType::findInvalidAddress(const String& value) const 155 String EmailInputType::findInvalidAddress(const String& value) const
156 { 156 {
157 if (value.isEmpty()) 157 if (value.isEmpty())
158 return String(); 158 return String();
159 if (!element()->multiple()) 159 if (!element().multiple())
160 return isValidEmailAddress(value) ? String() : value; 160 return isValidEmailAddress(value) ? String() : value;
161 Vector<String> addresses; 161 Vector<String> addresses;
162 value.split(',', true, addresses); 162 value.split(',', true, addresses);
163 for (unsigned i = 0; i < addresses.size(); ++i) { 163 for (unsigned i = 0; i < addresses.size(); ++i) {
164 String stripped = stripLeadingAndTrailingHTMLSpaces(addresses[i]); 164 String stripped = stripLeadingAndTrailingHTMLSpaces(addresses[i]);
165 if (!isValidEmailAddress(stripped)) 165 if (!isValidEmailAddress(stripped))
166 return stripped; 166 return stripped;
167 } 167 }
168 return String(); 168 return String();
169 } 169 }
170 170
171 bool EmailInputType::typeMismatchFor(const String& value) const 171 bool EmailInputType::typeMismatchFor(const String& value) const
172 { 172 {
173 return !findInvalidAddress(value).isNull(); 173 return !findInvalidAddress(value).isNull();
174 } 174 }
175 175
176 bool EmailInputType::typeMismatch() const 176 bool EmailInputType::typeMismatch() const
177 { 177 {
178 return typeMismatchFor(element()->value()); 178 return typeMismatchFor(element().value());
179 } 179 }
180 180
181 String EmailInputType::typeMismatchText() const 181 String EmailInputType::typeMismatchText() const
182 { 182 {
183 String invalidAddress = findInvalidAddress(element()->value()); 183 String invalidAddress = findInvalidAddress(element().value());
184 ASSERT(!invalidAddress.isNull()); 184 ASSERT(!invalidAddress.isNull());
185 if (invalidAddress.isEmpty()) 185 if (invalidAddress.isEmpty())
186 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rEmailEmpty); 186 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rEmailEmpty);
187 String atSign = String("@"); 187 String atSign = String("@");
188 size_t atIndex = invalidAddress.find('@'); 188 size_t atIndex = invalidAddress.find('@');
189 if (atIndex == kNotFound) 189 if (atIndex == kNotFound)
190 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rEmailNoAtSign, atSign, invalidAddress); 190 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rEmailNoAtSign, atSign, invalidAddress);
191 // We check validity against an ASCII value because of difficulty to check 191 // We check validity against an ASCII value because of difficulty to check
192 // invalid characters. However we should show Unicode value. 192 // invalid characters. However we should show Unicode value.
193 String unicodeAddress = convertEmailAddressToUnicode(invalidAddress); 193 String unicodeAddress = convertEmailAddressToUnicode(invalidAddress);
(...skipping 11 matching lines...) Expand all
205 invalidCharIndex = domain.find(isInvalidDomainCharacter); 205 invalidCharIndex = domain.find(isInvalidDomainCharacter);
206 if (invalidCharIndex != kNotFound) { 206 if (invalidCharIndex != kNotFound) {
207 unsigned charLength = U_IS_LEAD(domain[invalidCharIndex]) ? 2 : 1; 207 unsigned charLength = U_IS_LEAD(domain[invalidCharIndex]) ? 2 : 1;
208 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rEmailInvalidDomain, atSign, domain.substring(invalidCharIndex, charLength)); 208 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rEmailInvalidDomain, atSign, domain.substring(invalidCharIndex, charLength));
209 } 209 }
210 if (!checkValidDotUsage(domain)) { 210 if (!checkValidDotUsage(domain)) {
211 size_t atIndexInUnicode = unicodeAddress.find('@'); 211 size_t atIndexInUnicode = unicodeAddress.find('@');
212 ASSERT(atIndexInUnicode != kNotFound); 212 ASSERT(atIndexInUnicode != kNotFound);
213 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rEmailInvalidDots, String("."), unicodeAddress.substring(atIndexInUnicode + 1)); 213 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rEmailInvalidDots, String("."), unicodeAddress.substring(atIndexInUnicode + 1));
214 } 214 }
215 if (element()->multiple()) 215 if (element().multiple())
216 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rMultipleEmail); 216 return locale().queryString(WebLocalizedString::ValidationTypeMismatchFo rMultipleEmail);
217 return locale().queryString(WebLocalizedString::ValidationTypeMismatchForEma il); 217 return locale().queryString(WebLocalizedString::ValidationTypeMismatchForEma il);
218 } 218 }
219 219
220 bool EmailInputType::isEmailField() const 220 bool EmailInputType::isEmailField() const
221 { 221 {
222 return true; 222 return true;
223 } 223 }
224 224
225 bool EmailInputType::supportsSelectionAPI() const 225 bool EmailInputType::supportsSelectionAPI() const
226 { 226 {
227 return false; 227 return false;
228 } 228 }
229 229
230 String EmailInputType::sanitizeValue(const String& proposedValue) const 230 String EmailInputType::sanitizeValue(const String& proposedValue) const
231 { 231 {
232 String noLineBreakValue = proposedValue.removeCharacters(isHTMLLineBreak); 232 String noLineBreakValue = proposedValue.removeCharacters(isHTMLLineBreak);
233 if (!element()->multiple()) 233 if (!element().multiple())
234 return stripLeadingAndTrailingHTMLSpaces(noLineBreakValue); 234 return stripLeadingAndTrailingHTMLSpaces(noLineBreakValue);
235 Vector<String> addresses; 235 Vector<String> addresses;
236 noLineBreakValue.split(',', true, addresses); 236 noLineBreakValue.split(',', true, addresses);
237 StringBuilder strippedValue; 237 StringBuilder strippedValue;
238 for (size_t i = 0; i < addresses.size(); ++i) { 238 for (size_t i = 0; i < addresses.size(); ++i) {
239 if (i > 0) 239 if (i > 0)
240 strippedValue.append(","); 240 strippedValue.append(",");
241 strippedValue.append(stripLeadingAndTrailingHTMLSpaces(addresses[i])); 241 strippedValue.append(stripLeadingAndTrailingHTMLSpaces(addresses[i]));
242 } 242 }
243 return strippedValue.toString(); 243 return strippedValue.toString();
244 } 244 }
245 245
246 String EmailInputType::convertFromVisibleValue(const String& visibleValue) const 246 String EmailInputType::convertFromVisibleValue(const String& visibleValue) const
247 { 247 {
248 String sanitizedValue = sanitizeValue(visibleValue); 248 String sanitizedValue = sanitizeValue(visibleValue);
249 if (!element()->multiple()) 249 if (!element().multiple())
250 return convertEmailAddressToASCII(sanitizedValue); 250 return convertEmailAddressToASCII(sanitizedValue);
251 Vector<String> addresses; 251 Vector<String> addresses;
252 sanitizedValue.split(',', true, addresses); 252 sanitizedValue.split(',', true, addresses);
253 StringBuilder builder; 253 StringBuilder builder;
254 builder.reserveCapacity(sanitizedValue.length()); 254 builder.reserveCapacity(sanitizedValue.length());
255 for (size_t i = 0; i < addresses.size(); ++i) { 255 for (size_t i = 0; i < addresses.size(); ++i) {
256 if (i > 0) 256 if (i > 0)
257 builder.append(","); 257 builder.append(",");
258 builder.append(convertEmailAddressToASCII(addresses[i])); 258 builder.append(convertEmailAddressToASCII(addresses[i]));
259 } 259 }
260 return builder.toString(); 260 return builder.toString();
261 } 261 }
262 262
263 String EmailInputType::visibleValue() const 263 String EmailInputType::visibleValue() const
264 { 264 {
265 String value = element()->value(); 265 String value = element().value();
266 if (!element()->multiple()) 266 if (!element().multiple())
267 return convertEmailAddressToUnicode(value); 267 return convertEmailAddressToUnicode(value);
268 268
269 Vector<String> addresses; 269 Vector<String> addresses;
270 value.split(',', true, addresses); 270 value.split(',', true, addresses);
271 StringBuilder builder; 271 StringBuilder builder;
272 builder.reserveCapacity(value.length()); 272 builder.reserveCapacity(value.length());
273 for (size_t i = 0; i < addresses.size(); ++i) { 273 for (size_t i = 0; i < addresses.size(); ++i) {
274 if (i > 0) 274 if (i > 0)
275 builder.append(","); 275 builder.append(",");
276 builder.append(convertEmailAddressToUnicode(addresses[i])); 276 builder.append(convertEmailAddressToUnicode(addresses[i]));
277 } 277 }
278 return builder.toString(); 278 return builder.toString();
279 } 279 }
280 280
281 } // namespace WebCore 281 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/forms/EmailInputType.h ('k') | Source/core/html/forms/FileInputType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698