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

Unified 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, 7 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/forms/BaseTextInputType.cpp
diff --git a/third_party/WebKit/Source/core/html/forms/BaseTextInputType.cpp b/third_party/WebKit/Source/core/html/forms/BaseTextInputType.cpp
index 4cf599322bd59de5e26e42074709b8f8560eb99c..a2856b8c9fe789268630f1698f74322f699fabed 100644
--- a/third_party/WebKit/Source/core/html/forms/BaseTextInputType.cpp
+++ b/third_party/WebKit/Source/core/html/forms/BaseTextInputType.cpp
@@ -26,11 +26,21 @@
#include "bindings/core/v8/ScriptRegexp.h"
#include "core/HTMLNames.h"
#include "core/html/HTMLInputElement.h"
+#include "core/inspector/ConsoleMessage.h"
namespace blink {
using namespace HTMLNames;
+BaseTextInputType::BaseTextInputType(HTMLInputElement& element)
+ : TextFieldInputType(element)
+{
+}
+
+BaseTextInputType::~BaseTextInputType()
+{
+}
+
int BaseTextInputType::maxLength() const
{
return element().maxLength();
@@ -77,24 +87,27 @@ bool BaseTextInputType::patternMismatch(const String& value) const
// Empty values can't be mismatched
if (rawPattern.isNull() || value.isEmpty())
return false;
- bool rawPatternIsValid = ScriptRegexp(rawPattern, TextCaseSensitive).isValid();
- bool rawUnicodePatternIsValid = ScriptRegexp(rawPattern, TextCaseSensitive, MultilineDisabled, ScriptRegexp::UTF16).isValid();
- if (rawPatternIsValid != rawUnicodePatternIsValid)
- UseCounter::count(element().document(), UseCounter::PatternAttributeUnicodeFlagIsIncompatible);
- if (!rawPatternIsValid)
- return false;
+ if (!m_regexp || m_patternForRegexp != rawPattern) {
+ std::unique_ptr<ScriptRegexp> rawRegexp(new ScriptRegexp(rawPattern, TextCaseSensitive, MultilineDisabled, ScriptRegexp::UTF16));
+ if (!rawRegexp->isValid()) {
+ element().document().addConsoleMessage(ConsoleMessage::create(RenderingMessageSource, ErrorMessageLevel,
+ String::format("Pattern attribute value %s is not a valid regular expression: %s",
+ rawPattern.utf8().data(),
+ rawRegexp->exceptionMessage().utf8().data())));
+ m_regexp.reset(rawRegexp.release());
+ m_patternForRegexp = rawPattern;
+ return false;
+ }
+ String pattern = "^(?:" + rawPattern + ")$";
+ m_regexp.reset(new ScriptRegexp(pattern, TextCaseSensitive, MultilineDisabled, ScriptRegexp::UTF16));
+ m_patternForRegexp = rawPattern;
+ }
- String pattern = "^(?:" + rawPattern + ")$";
int matchLength = 0;
int valueLength = value.length();
- int matchOffset = ScriptRegexp(pattern, TextCaseSensitive).match(value, 0, &matchLength);
- bool bmpMismatched = matchOffset != 0 || matchLength != valueLength;
- matchLength = 0;
- matchOffset = ScriptRegexp(pattern, TextCaseSensitive, MultilineDisabled, ScriptRegexp::UTF16).match(value, 0, &matchLength);
- bool utf16Mismatched = matchOffset != 0 || matchLength != valueLength;
- if (bmpMismatched != utf16Mismatched)
- UseCounter::count(element().document(), UseCounter::PatternAttributeUnicodeFlagIsIncompatible);
- return bmpMismatched;
+ int matchOffset = m_regexp->match(value, 0, &matchLength);
+ bool mismatched = matchOffset != 0 || matchLength != valueLength;
+ return mismatched;
}
bool BaseTextInputType::supportsPlaceholder() const
« 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