| 1 | /* |
| 2 | * This file is part of the WebKit project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Michelangelo De Simone <micdesim@gmail.com> |
| 5 | * Copyright (C) 2010 Google Inc. All rights reserved. |
| 6 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Library General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Library General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Library General Public License |
| 19 | * along with this library; see the file COPYING.LIB. If not, write to |
| 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | * Boston, MA 02110-1301, USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "config.h" |
| 26 | #include "BaseTextInputType.h" |
| 27 | |
| 28 | #include "HTMLInputElement.h" |
| 29 | #include "HTMLNames.h" |
| 30 | #include <JavaScriptCore/RegularExpression.h> |
| 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | using namespace HTMLNames; |
| 35 | |
| 36 | bool BaseTextInputType::isTextType() const |
| 37 | { |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | bool BaseTextInputType::patternMismatch(const String& value) const |
| 42 | { |
| 43 | ASSERT(element()); |
| 44 | // FIXME: We should execute RegExp parser first to check validity instead of creating an actual RegularExpression. |
| 45 | // https://bugs.webkit.org/show_bug.cgi?id=183361 |
| 46 | const AtomicString& rawPattern = element()->attributeWithoutSynchronization(patternAttr); |
| 47 | if (rawPattern.isNull() || value.isEmpty() || !JSC::Yarr::RegularExpression(rawPattern, JSC::Yarr::TextCaseSensitive, JSC::Yarr::MultilineDisabled, JSC::Yarr::UnicodeAwareMode).isValid()) |
| 48 | return false; |
| 49 | String pattern = "^(?:" + rawPattern + ")$" ; |
| 50 | int matchLength = 0; |
| 51 | int valueLength = value.length(); |
| 52 | int matchOffset = JSC::Yarr::RegularExpression(pattern, JSC::Yarr::TextCaseSensitive, JSC::Yarr::MultilineDisabled, JSC::Yarr::UnicodeAwareMode).match(value, 0, &matchLength); |
| 53 | return matchOffset || matchLength != valueLength; |
| 54 | } |
| 55 | |
| 56 | bool BaseTextInputType::supportsPlaceholder() const |
| 57 | { |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | bool BaseTextInputType::supportsSelectionAPI() const |
| 62 | { |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | } // namespace WebCore |
| 67 | |