summaryrefslogtreecommitdiffstats
path: root/WebCore/html/ValidityState.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/html/ValidityState.cpp')
-rw-r--r--WebCore/html/ValidityState.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/WebCore/html/ValidityState.cpp b/WebCore/html/ValidityState.cpp
index 86227d4..5bf8382 100644
--- a/WebCore/html/ValidityState.cpp
+++ b/WebCore/html/ValidityState.cpp
@@ -23,14 +23,57 @@
#include "config.h"
#include "ValidityState.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
+#include "KURL.h"
+
namespace WebCore {
+using namespace HTMLNames;
+
ValidityState::ValidityState(HTMLFormControlElement* parent)
: m_control(parent)
{
ASSERT(parent);
}
+bool ValidityState::typeMismatch()
+{
+ if (!control()->hasTagName(inputTag))
+ return false;
+
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(control());
+ String value = input->value();
+
+ if (value.isEmpty())
+ return false;
+
+ switch (input->inputType()) {
+ case HTMLInputElement::COLOR:
+ return !isValidColorString(value);
+ case HTMLInputElement::NUMBER:
+ return !HTMLInputElement::formStringToDouble(value, 0);
+ case HTMLInputElement::URL:
+ return !KURL(KURL(), value).isValid();
+ default:
+ return false;
+ }
+}
+
+bool ValidityState::rangeUnderflow()
+{
+ if (!control()->hasTagName(inputTag))
+ return false;
+ return static_cast<HTMLInputElement*>(control())->rangeUnderflow();
+}
+
+bool ValidityState::rangeOverflow()
+{
+ if (!control()->hasTagName(inputTag))
+ return false;
+ return static_cast<HTMLInputElement*>(control())->rangeOverflow();
+}
+
bool ValidityState::valid()
{
bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() ||
@@ -39,4 +82,17 @@ bool ValidityState::valid()
return !someError;
}
+bool ValidityState::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();
+}
+
} // namespace