[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
tkent at chromium.org
tkent at chromium.org
Wed Dec 22 14:27:33 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 99c09d4c047f6e1a94f01a1285075ad0362a12e2
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Sat Oct 9 13:27:33 2010 +0000
Refactor HTMLInputElement: Move typeMismatch(), valueMissing(),
isRequiredFormControl(), and recalcWillValidate()
https://bugs.webkit.org/show_bug.cgi?id=47405
Reviewed by Dimitri Glazkov.
Also make checkedRadioButtons() an inline member function of
HTMLInputElement in order that RadioInputType can use it.
* html/BaseDateAndTimeInputType.cpp:
(WebCore::BaseDateAndTimeInputType::typeMismatchFor):
(WebCore::BaseDateAndTimeInputType::typeMismatch):
* html/BaseDateAndTimeInputType.h:
* html/ButtonInputType.cpp:
(WebCore::ButtonInputType::supportsValidation):
* html/ButtonInputType.h:
* html/CheckboxInputType.cpp:
(WebCore::CheckboxInputType::valueMissing):
* html/CheckboxInputType.h:
* html/ColorInputType.cpp:
(WebCore::isValidColorString):
(WebCore::ColorInputType::typeMismatchFor):
(WebCore::ColorInputType::typeMismatch):
(WebCore::ColorInputType::supportsRequired):
* html/ColorInputType.h:
* html/EmailInputType.cpp:
(WebCore::isValidEmailAddress):
(WebCore::EmailInputType::typeMismatchFor):
(WebCore::EmailInputType::typeMismatch):
* html/EmailInputType.h:
* html/FileInputType.cpp:
(WebCore::FileInputType::valueMissing):
* html/FileInputType.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::updateCheckedRadioButtons):
(WebCore::HTMLInputElement::isValidValue):
(WebCore::HTMLInputElement::typeMismatch):
(WebCore::HTMLInputElement::valueMissing):
(WebCore::HTMLInputElement::isKeyboardFocusable):
(WebCore::HTMLInputElement::updateType):
(WebCore::HTMLInputElement::parseMappedAttribute):
(WebCore::HTMLInputElement::setChecked):
(WebCore::HTMLInputElement::preDispatchEventHandler):
(WebCore::HTMLInputElement::isRequiredFormControl):
(WebCore::HTMLInputElement::recalcWillValidate):
* html/HTMLInputElement.h:
(WebCore::HTMLInputElement::checkedRadioButtons):
* html/HiddenInputType.cpp:
(WebCore::HiddenInputType::supportsValidation):
* html/HiddenInputType.h:
* html/ImageInputType.cpp:
(WebCore::ImageInputType::supportsValidation):
* html/ImageInputType.h:
* html/InputType.cpp:
(WebCore::InputType::supportsValidation):
(WebCore::InputType::typeMismatchFor):
(WebCore::InputType::typeMismatch):
(WebCore::InputType::supportsRequired):
(WebCore::InputType::valueMissing):
* html/InputType.h:
* html/IsIndexInputType.cpp:
(WebCore::IsIndexInputType::supportsRequired):
* html/IsIndexInputType.h:
* html/NumberInputType.cpp:
(WebCore::NumberInputType::typeMismatchFor):
(WebCore::NumberInputType::typeMismatch):
* html/NumberInputType.h:
* html/RadioInputType.cpp:
(WebCore::RadioInputType::valueMissing):
* html/RadioInputType.h:
* html/ResetInputType.cpp:
(WebCore::ResetInputType::supportsValidation):
* html/ResetInputType.h:
* html/SubmitInputType.cpp:
(WebCore::SubmitInputType::supportsValidation):
* html/SubmitInputType.h:
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::valueMissing):
* html/TextFieldInputType.h:
* html/URLInputType.cpp:
(WebCore::URLInputType::typeMismatchFor):
(WebCore::URLInputType::typeMismatch):
* html/URLInputType.h:
* html/ValidityState.cpp:
(WebCore::ValidityState::typeMismatch):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69445 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index cc4da63..f8d2265 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,91 @@
+2010-10-09 Kent Tamura <tkent at chromium.org>
+
+ Reviewed by Dimitri Glazkov.
+
+ Refactor HTMLInputElement: Move typeMismatch(), valueMissing(),
+ isRequiredFormControl(), and recalcWillValidate()
+ https://bugs.webkit.org/show_bug.cgi?id=47405
+
+ Also make checkedRadioButtons() an inline member function of
+ HTMLInputElement in order that RadioInputType can use it.
+
+ * html/BaseDateAndTimeInputType.cpp:
+ (WebCore::BaseDateAndTimeInputType::typeMismatchFor):
+ (WebCore::BaseDateAndTimeInputType::typeMismatch):
+ * html/BaseDateAndTimeInputType.h:
+ * html/ButtonInputType.cpp:
+ (WebCore::ButtonInputType::supportsValidation):
+ * html/ButtonInputType.h:
+ * html/CheckboxInputType.cpp:
+ (WebCore::CheckboxInputType::valueMissing):
+ * html/CheckboxInputType.h:
+ * html/ColorInputType.cpp:
+ (WebCore::isValidColorString):
+ (WebCore::ColorInputType::typeMismatchFor):
+ (WebCore::ColorInputType::typeMismatch):
+ (WebCore::ColorInputType::supportsRequired):
+ * html/ColorInputType.h:
+ * html/EmailInputType.cpp:
+ (WebCore::isValidEmailAddress):
+ (WebCore::EmailInputType::typeMismatchFor):
+ (WebCore::EmailInputType::typeMismatch):
+ * html/EmailInputType.h:
+ * html/FileInputType.cpp:
+ (WebCore::FileInputType::valueMissing):
+ * html/FileInputType.h:
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::updateCheckedRadioButtons):
+ (WebCore::HTMLInputElement::isValidValue):
+ (WebCore::HTMLInputElement::typeMismatch):
+ (WebCore::HTMLInputElement::valueMissing):
+ (WebCore::HTMLInputElement::isKeyboardFocusable):
+ (WebCore::HTMLInputElement::updateType):
+ (WebCore::HTMLInputElement::parseMappedAttribute):
+ (WebCore::HTMLInputElement::setChecked):
+ (WebCore::HTMLInputElement::preDispatchEventHandler):
+ (WebCore::HTMLInputElement::isRequiredFormControl):
+ (WebCore::HTMLInputElement::recalcWillValidate):
+ * html/HTMLInputElement.h:
+ (WebCore::HTMLInputElement::checkedRadioButtons):
+ * html/HiddenInputType.cpp:
+ (WebCore::HiddenInputType::supportsValidation):
+ * html/HiddenInputType.h:
+ * html/ImageInputType.cpp:
+ (WebCore::ImageInputType::supportsValidation):
+ * html/ImageInputType.h:
+ * html/InputType.cpp:
+ (WebCore::InputType::supportsValidation):
+ (WebCore::InputType::typeMismatchFor):
+ (WebCore::InputType::typeMismatch):
+ (WebCore::InputType::supportsRequired):
+ (WebCore::InputType::valueMissing):
+ * html/InputType.h:
+ * html/IsIndexInputType.cpp:
+ (WebCore::IsIndexInputType::supportsRequired):
+ * html/IsIndexInputType.h:
+ * html/NumberInputType.cpp:
+ (WebCore::NumberInputType::typeMismatchFor):
+ (WebCore::NumberInputType::typeMismatch):
+ * html/NumberInputType.h:
+ * html/RadioInputType.cpp:
+ (WebCore::RadioInputType::valueMissing):
+ * html/RadioInputType.h:
+ * html/ResetInputType.cpp:
+ (WebCore::ResetInputType::supportsValidation):
+ * html/ResetInputType.h:
+ * html/SubmitInputType.cpp:
+ (WebCore::SubmitInputType::supportsValidation):
+ * html/SubmitInputType.h:
+ * html/TextFieldInputType.cpp:
+ (WebCore::TextFieldInputType::valueMissing):
+ * html/TextFieldInputType.h:
+ * html/URLInputType.cpp:
+ (WebCore::URLInputType::typeMismatchFor):
+ (WebCore::URLInputType::typeMismatch):
+ * html/URLInputType.h:
+ * html/ValidityState.cpp:
+ (WebCore::ValidityState::typeMismatch):
+
2010-10-09 Pratik Solanki <psolanki at apple.com>
Reviewed by Dan Bernstein.
diff --git a/WebCore/html/BaseDateAndTimeInputType.cpp b/WebCore/html/BaseDateAndTimeInputType.cpp
index 5b91b01..e1126d4 100644
--- a/WebCore/html/BaseDateAndTimeInputType.cpp
+++ b/WebCore/html/BaseDateAndTimeInputType.cpp
@@ -67,6 +67,16 @@ void BaseDateAndTimeInputType::setValueAsNumber(double newValue, ExceptionCode&)
element()->setValue(serialize(newValue));
}
+bool BaseDateAndTimeInputType::typeMismatchFor(const String& value) const
+{
+ return !value.isEmpty() && !parseToDateComponents(value, 0);
+}
+
+bool BaseDateAndTimeInputType::typeMismatch() const
+{
+ return typeMismatchFor(element()->value());
+}
+
bool BaseDateAndTimeInputType::rangeUnderflow(const String& value) const
{
const double nan = numeric_limits<double>::quiet_NaN();
diff --git a/WebCore/html/BaseDateAndTimeInputType.h b/WebCore/html/BaseDateAndTimeInputType.h
index 2214737..83c1e93 100644
--- a/WebCore/html/BaseDateAndTimeInputType.h
+++ b/WebCore/html/BaseDateAndTimeInputType.h
@@ -51,6 +51,8 @@ private:
virtual void setValueAsDate(double, ExceptionCode&) const;
virtual double valueAsNumber() const;
virtual void setValueAsNumber(double, ExceptionCode&) const;
+ virtual bool typeMismatchFor(const String&) const;
+ virtual bool typeMismatch() const;
virtual bool rangeUnderflow(const String&) const;
virtual bool rangeOverflow(const String&) const;
virtual bool stepMismatch(const String&, double) const;
diff --git a/WebCore/html/ButtonInputType.cpp b/WebCore/html/ButtonInputType.cpp
index 7f56970..deaf30f 100644
--- a/WebCore/html/ButtonInputType.cpp
+++ b/WebCore/html/ButtonInputType.cpp
@@ -45,4 +45,9 @@ const AtomicString& ButtonInputType::formControlType() const
return InputTypeNames::button();
}
+bool ButtonInputType::supportsValidation() const
+{
+ return false;
+}
+
} // namespace WebCore
diff --git a/WebCore/html/ButtonInputType.h b/WebCore/html/ButtonInputType.h
index 99b3574..7efbad2 100644
--- a/WebCore/html/ButtonInputType.h
+++ b/WebCore/html/ButtonInputType.h
@@ -42,6 +42,7 @@ public:
private:
ButtonInputType(HTMLInputElement* element) : InputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool supportsValidation() const;
};
} // namespace WebCore
diff --git a/WebCore/html/CheckboxInputType.cpp b/WebCore/html/CheckboxInputType.cpp
index 1c7ea4b..572dde0 100644
--- a/WebCore/html/CheckboxInputType.cpp
+++ b/WebCore/html/CheckboxInputType.cpp
@@ -31,6 +31,7 @@
#include "config.h"
#include "CheckboxInputType.h"
+#include "HTMLInputElement.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
@@ -45,4 +46,9 @@ const AtomicString& CheckboxInputType::formControlType() const
return InputTypeNames::checkbox();
}
+bool CheckboxInputType::valueMissing(const String&) const
+{
+ return !element()->checked();
+}
+
} // namespace WebCore
diff --git a/WebCore/html/CheckboxInputType.h b/WebCore/html/CheckboxInputType.h
index 6a152e9..e041a07 100644
--- a/WebCore/html/CheckboxInputType.h
+++ b/WebCore/html/CheckboxInputType.h
@@ -42,6 +42,7 @@ public:
private:
CheckboxInputType(HTMLInputElement* element) : InputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool valueMissing(const String&) const;
};
} // namespace WebCore
diff --git a/WebCore/html/ColorInputType.cpp b/WebCore/html/ColorInputType.cpp
index c68acea..56bfd08 100644
--- a/WebCore/html/ColorInputType.cpp
+++ b/WebCore/html/ColorInputType.cpp
@@ -31,10 +31,28 @@
#include "config.h"
#include "ColorInputType.h"
+#include "Color.h"
+#include "HTMLInputElement.h"
#include <wtf/PassOwnPtr.h>
+#include <wtf/text/WTFString.h>
namespace WebCore {
+static bool isValidColorString(const String& value)
+{
+ if (value.isEmpty())
+ return false;
+ if (value[0] == '#') {
+ // We don't accept #rgb and #aarrggbb formats.
+ if (value.length() != 7)
+ return false;
+ }
+ // This accepts named colors such as "white".
+ // FIXME: Reject named colors, accept only #rrggbb.
+ Color color(value);
+ return color.isValid() && !color.hasAlpha();
+}
+
PassOwnPtr<InputType> ColorInputType::create(HTMLInputElement* element)
{
return adoptPtr(new ColorInputType(element));
@@ -45,4 +63,26 @@ const AtomicString& ColorInputType::formControlType() const
return InputTypeNames::color();
}
+bool ColorInputType::typeMismatchFor(const String& value) const
+{
+ // FIXME: Should not accept an empty value. Remove it when we implement value
+ // sanitization for type=color.
+ if (value.isEmpty())
+ return false;
+ return !isValidColorString(value);
+}
+
+bool ColorInputType::typeMismatch() const
+{
+ // FIXME: Should return false. We don't implement value sanitization for
+ // type=color yet.
+ String value = element()->value();
+ return !value.isEmpty() && !isValidColorString(value);
+}
+
+bool ColorInputType::supportsRequired() const
+{
+ return false;
+}
+
} // namespace WebCore
diff --git a/WebCore/html/ColorInputType.h b/WebCore/html/ColorInputType.h
index 7259346..ea3798b 100644
--- a/WebCore/html/ColorInputType.h
+++ b/WebCore/html/ColorInputType.h
@@ -42,6 +42,9 @@ public:
private:
ColorInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool typeMismatchFor(const String&) const;
+ virtual bool typeMismatch() const;
+ virtual bool supportsRequired() const;
};
} // namespace WebCore
diff --git a/WebCore/html/EmailInputType.cpp b/WebCore/html/EmailInputType.cpp
index 4472310..78bda9c 100644
--- a/WebCore/html/EmailInputType.cpp
+++ b/WebCore/html/EmailInputType.cpp
@@ -1,40 +1,54 @@
/*
+ * This file is part of the WebKit project.
+ *
+ * Copyright (C) 2009 Michelangelo De Simone <micdesim at gmail.com>
* Copyright (C) 2010 Google Inc. All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
*
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "EmailInputType.h"
+#include "HTMLInputElement.h"
+#include "RegularExpression.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
+static const char emailPattern[] =
+ "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+" // local part
+ "@"
+ "[a-z0-9-]+(\\.[a-z0-9-]+)+"; // domain part
+
+static bool isValidEmailAddress(const String& address)
+{
+ int addressLength = address.length();
+ if (!addressLength)
+ return false;
+
+ DEFINE_STATIC_LOCAL(const RegularExpression, regExp, (emailPattern, TextCaseInsensitive));
+
+ int matchLength;
+ int matchOffset = regExp.match(address, 0, &matchLength);
+
+ return !matchOffset && matchLength == addressLength;
+}
+
PassOwnPtr<InputType> EmailInputType::create(HTMLInputElement* element)
{
return adoptPtr(new EmailInputType(element));
@@ -45,4 +59,24 @@ const AtomicString& EmailInputType::formControlType() const
return InputTypeNames::email();
}
+bool EmailInputType::typeMismatchFor(const String& value) const
+{
+ if (value.isEmpty())
+ return false;
+ if (!element()->multiple())
+ return !isValidEmailAddress(value);
+ Vector<String> addresses;
+ value.split(',', addresses);
+ for (unsigned i = 0; i < addresses.size(); ++i) {
+ if (!isValidEmailAddress(addresses[i]))
+ return true;
+ }
+ return false;
+}
+
+bool EmailInputType::typeMismatch() const
+{
+ return typeMismatchFor(element()->value());
+}
+
} // namespace WebCore
diff --git a/WebCore/html/EmailInputType.h b/WebCore/html/EmailInputType.h
index bbf6f73..b77a9ad 100644
--- a/WebCore/html/EmailInputType.h
+++ b/WebCore/html/EmailInputType.h
@@ -42,6 +42,8 @@ public:
private:
EmailInputType(HTMLInputElement* element) : BaseTextInputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool typeMismatchFor(const String&) const;
+ virtual bool typeMismatch() const;
};
} // namespace WebCore
diff --git a/WebCore/html/FileInputType.cpp b/WebCore/html/FileInputType.cpp
index 0e08362..6cb17f2 100644
--- a/WebCore/html/FileInputType.cpp
+++ b/WebCore/html/FileInputType.cpp
@@ -32,6 +32,7 @@
#include "FileInputType.h"
#include <wtf/PassOwnPtr.h>
+#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -45,4 +46,9 @@ const AtomicString& FileInputType::formControlType() const
return InputTypeNames::file();
}
+bool FileInputType::valueMissing(const String& value) const
+{
+ return value.isEmpty();
+}
+
} // namespace WebCore
diff --git a/WebCore/html/FileInputType.h b/WebCore/html/FileInputType.h
index cebfab7..2cbfe67 100644
--- a/WebCore/html/FileInputType.h
+++ b/WebCore/html/FileInputType.h
@@ -42,6 +42,7 @@ public:
private:
FileInputType(HTMLInputElement* element) : InputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool valueMissing(const String&) const;
};
} // namespace WebCore
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp
index 4d5cd64..378dde4 100644
--- a/WebCore/html/HTMLInputElement.cpp
+++ b/WebCore/html/HTMLInputElement.cpp
@@ -56,7 +56,6 @@
#include "LocalizedStrings.h"
#include "MouseEvent.h"
#include "Page.h"
-#include "RegularExpression.h"
#include "RenderButton.h"
#include "RenderFileUploadControl.h"
#include "RenderImage.h"
@@ -82,44 +81,12 @@ using namespace HTMLNames;
const int maxSavedResults = 256;
-static const char emailPattern[] =
- "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+" // local part
- "@"
- "[a-z0-9-]+(\\.[a-z0-9-]+)+"; // domain part
-
static bool isNumberCharacter(UChar ch)
{
return ch == '+' || ch == '-' || ch == '.' || ch == 'e' || ch == 'E'
|| (ch >= '0' && ch <= '9');
}
-static bool isValidColorString(const String& value)
-{
- if (value.isEmpty())
- return false;
- if (value[0] == '#') {
- // We don't accept #rgb and #aarrggbb formats.
- if (value.length() != 7)
- return false;
- }
- Color color(value); // This accepts named colors such as "white".
- return color.isValid() && !color.hasAlpha();
-}
-
-static bool isValidEmailAddress(const String& address)
-{
- int addressLength = address.length();
- if (!addressLength)
- return false;
-
- DEFINE_STATIC_LOCAL(const RegularExpression, regExp, (emailPattern, TextCaseInsensitive));
-
- int matchLength;
- int matchOffset = regExp.match(address, 0, &matchLength);
-
- return !matchOffset && matchLength == addressLength;
-}
-
HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
: HTMLTextFormControlElement(tagName, document, form)
, m_xPos(0)
@@ -169,17 +136,10 @@ bool HTMLInputElement::autoComplete() const
return HTMLTextFormControlElement::autoComplete();
}
-static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement* element)
-{
- if (HTMLFormElement* form = element->form())
- return form->checkedRadioButtons();
- return element->document()->checkedRadioButtons();
-}
-
void HTMLInputElement::updateCheckedRadioButtons()
{
if (attached() && checked())
- checkedRadioButtons(this).addButton(this);
+ checkedRadioButtons().addButton(this);
if (form()) {
const Vector<HTMLFormControlElement*>& controls = form()->associatedElements();
@@ -220,7 +180,7 @@ bool HTMLInputElement::isValidValue(const String& value) const
ASSERT_NOT_REACHED();
return false;
}
- return !typeMismatch(value)
+ return !m_inputType->typeMismatchFor(value)
&& !stepMismatch(value)
&& !rangeUnderflow(value)
&& !rangeOverflow(value)
@@ -229,93 +189,16 @@ bool HTMLInputElement::isValidValue(const String& value) const
&& !valueMissing(value);
}
-bool HTMLInputElement::typeMismatch(const String& value) const
+bool HTMLInputElement::typeMismatch() const
{
- switch (deprecatedInputType()) {
- case COLOR:
- return !isValidColorString(value);
- case NUMBER:
- ASSERT(parseToDoubleForNumberType(value, 0));
- return false;
- case URL:
- return !KURL(KURL(), value).isValid();
- case EMAIL: {
- if (!multiple())
- return !isValidEmailAddress(value);
- Vector<String> addresses;
- value.split(',', addresses);
- for (unsigned i = 0; i < addresses.size(); ++i) {
- if (!isValidEmailAddress(addresses[i]))
- return true;
- }
- return false;
- }
- case DATE:
- case DATETIME:
- case DATETIMELOCAL:
- case MONTH:
- case TIME:
- case WEEK:
- return !m_inputType->parseToDateComponents(value, 0);
- case BUTTON:
- case CHECKBOX:
- case FILE:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case PASSWORD:
- case RADIO:
- case RANGE:
- case RESET:
- case SEARCH:
- case SUBMIT:
- case TELEPHONE:
- case TEXT:
- return false;
- }
- ASSERT_NOT_REACHED();
- return false;
+ return m_inputType->typeMismatch();
}
bool HTMLInputElement::valueMissing(const String& value) const
{
if (!isRequiredFormControl() || readOnly() || disabled())
return false;
-
- switch (deprecatedInputType()) {
- case DATE:
- case DATETIME:
- case DATETIMELOCAL:
- case EMAIL:
- case FILE:
- case MONTH:
- case NUMBER:
- case PASSWORD:
- case SEARCH:
- case TELEPHONE:
- case TEXT:
- case TIME:
- case URL:
- case WEEK:
- return value.isEmpty();
- case CHECKBOX:
- return !checked();
- case RADIO:
- return !checkedRadioButtons(this).checkedButtonForGroup(name());
- case COLOR:
- return false;
- case BUTTON:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case RANGE:
- case RESET:
- case SUBMIT:
- break;
- }
-
- ASSERT_NOT_REACHED();
- return false;
+ return m_inputType->valueMissing(value);
}
bool HTMLInputElement::patternMismatch(const String& value) const
@@ -466,7 +349,7 @@ bool HTMLInputElement::isKeyboardFocusable(KeyboardEvent* event) const
}
// Allow keyboard focus if we're checked or if nothing in the group is checked.
- return checked() || !checkedRadioButtons(this).checkedButtonForGroup(name());
+ return checked() || !checkedRadioButtons().checkedButtonForGroup(name());
}
return true;
@@ -577,7 +460,7 @@ void HTMLInputElement::updateType()
// Useful in case we were called from inside parseMappedAttribute.
setAttribute(typeAttr, type());
else {
- checkedRadioButtons(this).removeButton(this);
+ checkedRadioButtons().removeButton(this);
if (newType == FILE && !m_fileList)
m_fileList = FileList::create();
@@ -627,7 +510,7 @@ void HTMLInputElement::updateType()
updateFocusAppearance(true);
}
- checkedRadioButtons(this).addButton(this);
+ checkedRadioButtons().addButton(this);
}
setNeedsValidityCheck();
@@ -795,9 +678,9 @@ bool HTMLInputElement::mapToEntry(const QualifiedName& attrName, MappedAttribute
void HTMLInputElement::parseMappedAttribute(Attribute* attr)
{
if (attr->name() == nameAttr) {
- checkedRadioButtons(this).removeButton(this);
+ checkedRadioButtons().removeButton(this);
m_data.setName(attr->value());
- checkedRadioButtons(this).addButton(this);
+ checkedRadioButtons().addButton(this);
HTMLFormControlElementWithState::parseMappedAttribute(attr);
} else if (attr->name() == autocompleteAttr) {
if (equalIgnoringCase(attr->value(), "off")) {
@@ -1142,7 +1025,7 @@ void HTMLInputElement::setChecked(bool nowChecked, bool sendChangeEvent)
if (checked() == nowChecked)
return;
- checkedRadioButtons(this).removeButton(this);
+ checkedRadioButtons().removeButton(this);
m_useDefaultChecked = false;
m_checked = nowChecked;
@@ -1481,7 +1364,7 @@ void* HTMLInputElement::preDispatchEventHandler(Event* evt)
// We really want radio groups to end up in sane states, i.e., to have something checked.
// Therefore if nothing is currently selected, we won't allow this action to be "undone", since
// we want some object in the radio group to actually get selected.
- HTMLInputElement* currRadio = checkedRadioButtons(this).checkedButtonForGroup(name());
+ HTMLInputElement* currRadio = checkedRadioButtons().checkedButtonForGroup(name());
if (currRadio) {
// We have a radio button selected that is not us. Cache it in our result field and ref it so
// that it can't be destroyed.
@@ -2072,40 +1955,7 @@ void HTMLInputElement::unregisterForActivationCallbackIfNeeded()
bool HTMLInputElement::isRequiredFormControl() const
{
- if (!required())
- return false;
-
- switch (deprecatedInputType()) {
- case CHECKBOX:
- case DATE:
- case DATETIME:
- case DATETIMELOCAL:
- case EMAIL:
- case FILE:
- case MONTH:
- case NUMBER:
- case PASSWORD:
- case RADIO:
- case SEARCH:
- case TELEPHONE:
- case TEXT:
- case TIME:
- case URL:
- case WEEK:
- return true;
- case BUTTON:
- case COLOR:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case RANGE:
- case RESET:
- case SUBMIT:
- return false;
- }
-
- ASSERT_NOT_REACHED();
- return false;
+ return m_inputType->supportsRequired() && required();
}
void HTMLInputElement::cacheSelection(int start, int end)
@@ -2165,36 +2015,7 @@ void HTMLInputElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) cons
bool HTMLInputElement::recalcWillValidate() const
{
- switch (deprecatedInputType()) {
- case CHECKBOX:
- case COLOR:
- case DATE:
- case DATETIME:
- case DATETIMELOCAL:
- case EMAIL:
- case FILE:
- case ISINDEX:
- case MONTH:
- case NUMBER:
- case PASSWORD:
- case RADIO:
- case RANGE:
- case SEARCH:
- case TELEPHONE:
- case TEXT:
- case TIME:
- case URL:
- case WEEK:
- return HTMLFormControlElementWithState::recalcWillValidate();
- case BUTTON:
- case HIDDEN:
- case IMAGE:
- case RESET:
- case SUBMIT:
- return false;
- }
- ASSERT_NOT_REACHED();
- return false;
+ return m_inputType->supportsValidation() && HTMLFormControlElementWithState::recalcWillValidate();
}
#if ENABLE(DATALIST)
diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h
index e4e0340..e584a78 100644
--- a/WebCore/html/HTMLInputElement.h
+++ b/WebCore/html/HTMLInputElement.h
@@ -25,6 +25,7 @@
#define HTMLInputElement_h
#include "HTMLFormControlElement.h"
+#include "HTMLFormElement.h"
#include "InputElement.h"
#include <wtf/OwnPtr.h>
@@ -49,7 +50,7 @@ public:
bool autoComplete() const;
// For ValidityState
- bool typeMismatch(const String&) const;
+ bool typeMismatch() const;
// valueMissing() ignores the specified string value for CHECKBOX and RADIO.
bool valueMissing(const String&) const;
bool patternMismatch(const String&) const;
@@ -195,6 +196,13 @@ public:
void setWapInputFormat(String& mask);
#endif
+ inline CheckedRadioButtons& checkedRadioButtons() const
+ {
+ if (HTMLFormElement* formElement = form())
+ return formElement->checkedRadioButtons();
+ return document()->checkedRadioButtons();
+ }
+
protected:
HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
diff --git a/WebCore/html/HiddenInputType.cpp b/WebCore/html/HiddenInputType.cpp
index d97fe3a..76742ae 100644
--- a/WebCore/html/HiddenInputType.cpp
+++ b/WebCore/html/HiddenInputType.cpp
@@ -44,4 +44,9 @@ const AtomicString& HiddenInputType::formControlType() const {
return InputTypeNames::hidden();
}
+bool HiddenInputType::supportsValidation() const
+{
+ return false;
+}
+
} // namespace WebCore
diff --git a/WebCore/html/HiddenInputType.h b/WebCore/html/HiddenInputType.h
index 564f99e..cc49f98 100644
--- a/WebCore/html/HiddenInputType.h
+++ b/WebCore/html/HiddenInputType.h
@@ -42,6 +42,7 @@ public:
private:
HiddenInputType(HTMLInputElement* element) : InputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool supportsValidation() const;
};
} // namespace WebCore
diff --git a/WebCore/html/ImageInputType.cpp b/WebCore/html/ImageInputType.cpp
index 78b3981..604b052 100644
--- a/WebCore/html/ImageInputType.cpp
+++ b/WebCore/html/ImageInputType.cpp
@@ -45,4 +45,9 @@ const AtomicString& ImageInputType::formControlType() const
return InputTypeNames::image();
}
+bool ImageInputType::supportsValidation() const
+{
+ return false;
+}
+
} // namespace WebCore
diff --git a/WebCore/html/ImageInputType.h b/WebCore/html/ImageInputType.h
index 00ac77b..be308b3 100644
--- a/WebCore/html/ImageInputType.h
+++ b/WebCore/html/ImageInputType.h
@@ -42,6 +42,7 @@ public:
private:
ImageInputType(HTMLInputElement* element) : InputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool supportsValidation() const;
};
} // namespace WebCore
diff --git a/WebCore/html/InputType.cpp b/WebCore/html/InputType.cpp
index 0619a15..1b2303a 100644
--- a/WebCore/html/InputType.cpp
+++ b/WebCore/html/InputType.cpp
@@ -142,6 +142,32 @@ void InputType::setValueAsNumber(double, ExceptionCode& ec) const
ec = INVALID_STATE_ERR;
}
+bool InputType::supportsValidation() const
+{
+ return true;
+}
+
+bool InputType::typeMismatchFor(const String&) const
+{
+ return false;
+}
+
+bool InputType::typeMismatch() const
+{
+ return false;
+}
+
+bool InputType::supportsRequired() const
+{
+ // Almost all validatable types support @required.
+ return supportsValidation();
+}
+
+bool InputType::valueMissing(const String&) const
+{
+ return false;
+}
+
bool InputType::patternMismatch(const String&) const
{
return false;
diff --git a/WebCore/html/InputType.h b/WebCore/html/InputType.h
index 49b2ad0..953b123 100644
--- a/WebCore/html/InputType.h
+++ b/WebCore/html/InputType.h
@@ -57,6 +57,14 @@ public:
// Validation-related functions
+ virtual bool supportsValidation() const;
+ virtual bool typeMismatchFor(const String&) const;
+ // Type check for the current input value. We do nothing for some types
+ // though typeMismatchFor() does something for them because of value
+ // sanitization.
+ virtual bool typeMismatch() const;
+ virtual bool supportsRequired() const;
+ virtual bool valueMissing(const String&) const;
virtual bool patternMismatch(const String&) const;
virtual bool rangeUnderflow(const String&) const;
virtual bool rangeOverflow(const String&) const;
diff --git a/WebCore/html/IsIndexInputType.cpp b/WebCore/html/IsIndexInputType.cpp
index 80e0617..c3cff41 100644
--- a/WebCore/html/IsIndexInputType.cpp
+++ b/WebCore/html/IsIndexInputType.cpp
@@ -45,4 +45,9 @@ const AtomicString& IsIndexInputType::formControlType() const
return emptyAtom;
}
+bool IsIndexInputType::supportsRequired() const
+{
+ return false;
+}
+
} // namespace WebCore
diff --git a/WebCore/html/IsIndexInputType.h b/WebCore/html/IsIndexInputType.h
index 93a1c08..2d4e193 100644
--- a/WebCore/html/IsIndexInputType.h
+++ b/WebCore/html/IsIndexInputType.h
@@ -43,6 +43,7 @@ public:
private:
IsIndexInputType(HTMLInputElement* element) : TextFieldInputType(element) { };
virtual const AtomicString& formControlType() const;
+ virtual bool supportsRequired() const;
};
} // namespace WebCore
diff --git a/WebCore/html/NumberInputType.cpp b/WebCore/html/NumberInputType.cpp
index 4beda5a..a4e118c 100644
--- a/WebCore/html/NumberInputType.cpp
+++ b/WebCore/html/NumberInputType.cpp
@@ -72,6 +72,17 @@ void NumberInputType::setValueAsNumber(double newValue, ExceptionCode&) const
element()->setValue(serialize(newValue));
}
+bool NumberInputType::typeMismatchFor(const String& value) const
+{
+ return !value.isEmpty() && !parseToDoubleForNumberType(value, 0);
+}
+
+bool NumberInputType::typeMismatch() const
+{
+ ASSERT(!typeMismatchFor(element()->value()));
+ return false;
+}
+
bool NumberInputType::rangeUnderflow(const String& value) const
{
const double nan = numeric_limits<double>::quiet_NaN();
diff --git a/WebCore/html/NumberInputType.h b/WebCore/html/NumberInputType.h
index 49e5e7c..262955e 100644
--- a/WebCore/html/NumberInputType.h
+++ b/WebCore/html/NumberInputType.h
@@ -44,6 +44,8 @@ private:
virtual const AtomicString& formControlType() const;
virtual double valueAsNumber() const;
virtual void setValueAsNumber(double, ExceptionCode&) const;
+ virtual bool typeMismatchFor(const String&) const;
+ virtual bool typeMismatch() const;
virtual bool rangeUnderflow(const String&) const;
virtual bool rangeOverflow(const String&) const;
virtual double minimum() const;
diff --git a/WebCore/html/RadioInputType.cpp b/WebCore/html/RadioInputType.cpp
index a1c8d04..5df4bbc 100644
--- a/WebCore/html/RadioInputType.cpp
+++ b/WebCore/html/RadioInputType.cpp
@@ -31,6 +31,7 @@
#include "config.h"
#include "RadioInputType.h"
+#include "HTMLInputElement.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
@@ -45,4 +46,9 @@ const AtomicString& RadioInputType::formControlType() const
return InputTypeNames::radio();
}
+bool RadioInputType::valueMissing(const String&) const
+{
+ return !element()->checkedRadioButtons().checkedButtonForGroup(element()->name());
+}
+
} // namespace WebCore
diff --git a/WebCore/html/RadioInputType.h b/WebCore/html/RadioInputType.h
index 180c6dd..2ff2c41 100644
--- a/WebCore/html/RadioInputType.h
+++ b/WebCore/html/RadioInputType.h
@@ -42,6 +42,7 @@ public:
private:
RadioInputType(HTMLInputElement* element) : InputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool valueMissing(const String&) const;
};
} // namespace WebCore
diff --git a/WebCore/html/ResetInputType.cpp b/WebCore/html/ResetInputType.cpp
index 8b18a8d..1db7592 100644
--- a/WebCore/html/ResetInputType.cpp
+++ b/WebCore/html/ResetInputType.cpp
@@ -45,4 +45,9 @@ const AtomicString& ResetInputType::formControlType() const
return InputTypeNames::reset();
}
+bool ResetInputType::supportsValidation() const
+{
+ return false;
+}
+
} // namespace WebCore
diff --git a/WebCore/html/ResetInputType.h b/WebCore/html/ResetInputType.h
index e0d8997..3f883a3 100644
--- a/WebCore/html/ResetInputType.h
+++ b/WebCore/html/ResetInputType.h
@@ -42,6 +42,7 @@ public:
private:
ResetInputType(HTMLInputElement* element) : InputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool supportsValidation() const;
};
} // namespace WebCore
diff --git a/WebCore/html/SubmitInputType.cpp b/WebCore/html/SubmitInputType.cpp
index dd13e6b..65934f9 100644
--- a/WebCore/html/SubmitInputType.cpp
+++ b/WebCore/html/SubmitInputType.cpp
@@ -45,4 +45,9 @@ const AtomicString& SubmitInputType::formControlType() const
return InputTypeNames::submit();
}
+bool SubmitInputType::supportsValidation() const
+{
+ return false;
+}
+
} // namespace WebCore
diff --git a/WebCore/html/SubmitInputType.h b/WebCore/html/SubmitInputType.h
index 7ea448e..83fa5e5 100644
--- a/WebCore/html/SubmitInputType.h
+++ b/WebCore/html/SubmitInputType.h
@@ -42,6 +42,7 @@ public:
private:
SubmitInputType(HTMLInputElement* element) : InputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool supportsValidation() const;
};
} // namespace WebCore
diff --git a/WebCore/html/TextFieldInputType.cpp b/WebCore/html/TextFieldInputType.cpp
index e681b40..82382ef 100644
--- a/WebCore/html/TextFieldInputType.cpp
+++ b/WebCore/html/TextFieldInputType.cpp
@@ -31,6 +31,8 @@
#include "config.h"
#include "TextFieldInputType.h"
+#include <wtf/text/WTFString.h>
+
namespace WebCore {
bool TextFieldInputType::isTextField() const
@@ -38,4 +40,9 @@ bool TextFieldInputType::isTextField() const
return true;
}
+bool TextFieldInputType::valueMissing(const String& value) const
+{
+ return value.isEmpty();
+}
+
} // namespace WebCore
diff --git a/WebCore/html/TextFieldInputType.h b/WebCore/html/TextFieldInputType.h
index fb33a01..9108c42 100644
--- a/WebCore/html/TextFieldInputType.h
+++ b/WebCore/html/TextFieldInputType.h
@@ -41,6 +41,7 @@ class TextFieldInputType : public InputType {
protected:
TextFieldInputType(HTMLInputElement* element) : InputType(element) { }
virtual bool isTextField() const;
+ virtual bool valueMissing(const String&) const;
};
} // namespace WebCore
diff --git a/WebCore/html/URLInputType.cpp b/WebCore/html/URLInputType.cpp
index 2afdcde..517ffad 100644
--- a/WebCore/html/URLInputType.cpp
+++ b/WebCore/html/URLInputType.cpp
@@ -31,6 +31,8 @@
#include "config.h"
#include "URLInputType.h"
+#include "HTMLInputElement.h"
+#include "KURL.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
@@ -45,4 +47,14 @@ const AtomicString& URLInputType::formControlType() const
return InputTypeNames::url();
}
+bool URLInputType::typeMismatchFor(const String& value) const
+{
+ return !value.isEmpty() && !KURL(KURL(), value).isValid();
+}
+
+bool URLInputType::typeMismatch() const
+{
+ return typeMismatchFor(element()->value());
+}
+
} // namespace WebCore
diff --git a/WebCore/html/URLInputType.h b/WebCore/html/URLInputType.h
index 85d4f9f..82ab1b7 100644
--- a/WebCore/html/URLInputType.h
+++ b/WebCore/html/URLInputType.h
@@ -42,6 +42,8 @@ public:
private:
URLInputType(HTMLInputElement* element) : BaseTextInputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool typeMismatchFor(const String&) const;
+ virtual bool typeMismatch() const;
};
} // namespace WebCore
diff --git a/WebCore/html/ValidityState.cpp b/WebCore/html/ValidityState.cpp
index f18469e..57fb438 100644
--- a/WebCore/html/ValidityState.cpp
+++ b/WebCore/html/ValidityState.cpp
@@ -83,12 +83,7 @@ bool ValidityState::typeMismatch() const
{
if (!m_control->hasTagName(inputTag))
return false;
-
- HTMLInputElement* input = static_cast<HTMLInputElement*>(m_control);
- String value = input->value();
- if (value.isEmpty())
- return false;
- return input->typeMismatch(value);
+ return static_cast<HTMLInputElement*>(m_control)->typeMismatch();
}
bool ValidityState::patternMismatch() const
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list