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

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

Issue 2037553002: INPUT pattern attribute: Enable "unicode" flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment about |mutable|, remove unnecessary #include Created 4 years, 6 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/forms/BaseTextInputType.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 * 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.
11 * 11 *
12 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details. 15 * Library General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Library General Public License 17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to 18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA. 20 * Boston, MA 02110-1301, USA.
21 * 21 *
22 */ 22 */
23 23
24 #include "core/html/forms/BaseTextInputType.h" 24 #include "core/html/forms/BaseTextInputType.h"
25 25
26 #include "bindings/core/v8/ScriptRegexp.h" 26 #include "bindings/core/v8/ScriptRegexp.h"
27 #include "core/HTMLNames.h" 27 #include "core/HTMLNames.h"
28 #include "core/html/HTMLInputElement.h" 28 #include "core/html/HTMLInputElement.h"
29 #include "core/inspector/ConsoleMessage.h"
29 30
30 namespace blink { 31 namespace blink {
31 32
32 using namespace HTMLNames; 33 using namespace HTMLNames;
33 34
35 BaseTextInputType::BaseTextInputType(HTMLInputElement& element)
36 : TextFieldInputType(element)
37 {
38 }
39
40 BaseTextInputType::~BaseTextInputType()
41 {
42 }
43
34 int BaseTextInputType::maxLength() const 44 int BaseTextInputType::maxLength() const
35 { 45 {
36 return element().maxLength(); 46 return element().maxLength();
37 } 47 }
38 48
39 int BaseTextInputType::minLength() const 49 int BaseTextInputType::minLength() const
40 { 50 {
41 return element().minLength(); 51 return element().minLength();
42 } 52 }
43 53
(...skipping 26 matching lines...) Expand all
70 unsigned len = value.length(); 80 unsigned len = value.length();
71 return len > 0 && len < static_cast<unsigned>(min); 81 return len > 0 && len < static_cast<unsigned>(min);
72 } 82 }
73 83
74 bool BaseTextInputType::patternMismatch(const String& value) const 84 bool BaseTextInputType::patternMismatch(const String& value) const
75 { 85 {
76 const AtomicString& rawPattern = element().fastGetAttribute(patternAttr); 86 const AtomicString& rawPattern = element().fastGetAttribute(patternAttr);
77 // Empty values can't be mismatched 87 // Empty values can't be mismatched
78 if (rawPattern.isNull() || value.isEmpty()) 88 if (rawPattern.isNull() || value.isEmpty())
79 return false; 89 return false;
80 bool rawPatternIsValid = ScriptRegexp(rawPattern, TextCaseSensitive).isValid (); 90 if (!m_regexp || m_patternForRegexp != rawPattern) {
81 bool rawUnicodePatternIsValid = ScriptRegexp(rawPattern, TextCaseSensitive, MultilineDisabled, ScriptRegexp::UTF16).isValid(); 91 std::unique_ptr<ScriptRegexp> rawRegexp(new ScriptRegexp(rawPattern, Tex tCaseSensitive, MultilineDisabled, ScriptRegexp::UTF16));
82 if (rawPatternIsValid != rawUnicodePatternIsValid) 92 if (!rawRegexp->isValid()) {
83 UseCounter::count(element().document(), UseCounter::PatternAttributeUnic odeFlagIsIncompatible); 93 element().document().addConsoleMessage(ConsoleMessage::create(Render ingMessageSource, ErrorMessageLevel,
84 if (!rawPatternIsValid) 94 String::format("Pattern attribute value %s is not a valid regula r expression: %s",
85 return false; 95 rawPattern.utf8().data(),
96 rawRegexp->exceptionMessage().utf8().data())));
97 m_regexp.reset(rawRegexp.release());
98 m_patternForRegexp = rawPattern;
99 return false;
100 }
101 String pattern = "^(?:" + rawPattern + ")$";
102 m_regexp.reset(new ScriptRegexp(pattern, TextCaseSensitive, MultilineDis abled, ScriptRegexp::UTF16));
103 m_patternForRegexp = rawPattern;
104 }
86 105
87 String pattern = "^(?:" + rawPattern + ")$";
88 int matchLength = 0; 106 int matchLength = 0;
89 int valueLength = value.length(); 107 int valueLength = value.length();
90 int matchOffset = ScriptRegexp(pattern, TextCaseSensitive).match(value, 0, & matchLength); 108 int matchOffset = m_regexp->match(value, 0, &matchLength);
91 bool bmpMismatched = matchOffset != 0 || matchLength != valueLength; 109 bool mismatched = matchOffset != 0 || matchLength != valueLength;
92 matchLength = 0; 110 return mismatched;
93 matchOffset = ScriptRegexp(pattern, TextCaseSensitive, MultilineDisabled, Sc riptRegexp::UTF16).match(value, 0, &matchLength);
94 bool utf16Mismatched = matchOffset != 0 || matchLength != valueLength;
95 if (bmpMismatched != utf16Mismatched)
96 UseCounter::count(element().document(), UseCounter::PatternAttributeUnic odeFlagIsIncompatible);
97 return bmpMismatched;
98 } 111 }
99 112
100 bool BaseTextInputType::supportsPlaceholder() const 113 bool BaseTextInputType::supportsPlaceholder() const
101 { 114 {
102 return true; 115 return true;
103 } 116 }
104 117
105 bool BaseTextInputType::supportsSelectionAPI() const 118 bool BaseTextInputType::supportsSelectionAPI() const
106 { 119 {
107 return true; 120 return true;
108 } 121 }
109 122
110 bool BaseTextInputType::supportsAutocapitalize() const 123 bool BaseTextInputType::supportsAutocapitalize() const
111 { 124 {
112 return true; 125 return true;
113 } 126 }
114 127
115 } // namespace blink 128 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/forms/BaseTextInputType.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698