summaryrefslogtreecommitdiffstats
path: root/WebCore/html/ColorInputType.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/html/ColorInputType.cpp')
-rw-r--r--WebCore/html/ColorInputType.cpp40
1 files changed, 40 insertions, 0 deletions
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