input color: onchange event is not fired when changing color from color chooser
authorkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Aug 2011 08:08:29 +0000 (08:08 +0000)
committerkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Aug 2011 08:08:29 +0000 (08:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66848

Reviewed by Kent Tamura.

Source/WebCore:

Test: fast/forms/color/input-color-onchange-event.html

* WebCore.exp.in: Added calls used in Internals.cpp.
* html/ColorInputType.cpp:
(WebCore::ColorInputType::colorSelected): Dispatch change event.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::connectToColorChooser): Added. Called from Internals::connectColorChooserClient.
* html/HTMLInputElement.h:
* testing/Internals.cpp:
(WebCore::Internals::connectColorChooserClient): Added. Connects element as client to color chooser.
(WebCore::Internals::selectColorInColorChooser): Added. Simulate color selection in color chooser.
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* fast/forms/color/input-color-onchange-event-expected.txt: Added.
* fast/forms/color/input-color-onchange-event.html: Added. Tests if change event is fired when user selects color from color chooser.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@94158 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/color/input-color-onchange-event-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/color/input-color-onchange-event.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/html/ColorInputType.cpp
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index a621dc7..5ac3e77 100644 (file)
@@ -1,3 +1,13 @@
+2011-08-31  Keishi Hattori  <keishi@webkit.org>
+
+        input color: onchange event is not fired when changing color from color chooser
+        https://bugs.webkit.org/show_bug.cgi?id=66848
+
+        Reviewed by Kent Tamura.
+
+        * fast/forms/color/input-color-onchange-event-expected.txt: Added.
+        * fast/forms/color/input-color-onchange-event.html: Added. Tests if change event is fired when user selects color from color chooser.
+
 2011-08-31  Philippe Normand  <pnormand@igalia.com>
 
         Unreviewed, GTK rebaseline after r94147.
diff --git a/LayoutTests/fast/forms/color/input-color-onchange-event-expected.txt b/LayoutTests/fast/forms/color/input-color-onchange-event-expected.txt
new file mode 100644 (file)
index 0000000..a1cd685
--- /dev/null
@@ -0,0 +1,8 @@
+Test if change event fires properly when color chooser changes. Bug 66848
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+value changed to #ff0000
+PASS input.value is "#ff0000"
+
diff --git a/LayoutTests/fast/forms/color/input-color-onchange-event.html b/LayoutTests/fast/forms/color/input-color-onchange-event.html
new file mode 100644 (file)
index 0000000..704aced
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../fast/js/resources/js-test-style.css">
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description('Test if change event fires properly when color chooser changes. Bug 66848');
+
+var input = document.createElement('input');
+input.type = 'color';
+input.value = '#000000';
+input.onchange = function() {
+    debug("value changed to " + input.value);
+    finishJSTest();
+};
+if (!internals.connectColorChooserClient(input))
+    testFailed("Could not connect ColorChooserClient.");
+internals.selectColorInColorChooser('#ff0000');
+// input.onchange should be called
+internals.selectColorInColorChooser('#ff0000');
+// input.onchange should not be called
+shouldBe('input.value', '"#ff0000"');
+</script>
+</body>
+</html>
index 3d786d2..64eba66 100644 (file)
@@ -1,3 +1,24 @@
+2011-08-31  Keishi Hattori  <keishi@webkit.org>
+
+        input color: onchange event is not fired when changing color from color chooser
+        https://bugs.webkit.org/show_bug.cgi?id=66848
+
+        Reviewed by Kent Tamura.
+
+        Test: fast/forms/color/input-color-onchange-event.html
+
+        * WebCore.exp.in: Added calls used in Internals.cpp.
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::colorSelected): Dispatch change event.
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::connectToColorChooser): Added. Called from Internals::connectColorChooserClient.
+        * html/HTMLInputElement.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::connectColorChooserClient): Added. Connects element as client to color chooser.
+        (WebCore::Internals::selectColorInColorChooser): Added. Simulate color selection in color chooser.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2011-08-31  Kentaro Hara  <haraken@google.com>
 
         Implement Web IDL Constructor extended attribute in IDLParser.pm and CodeGeneratorV8.pm.
index 597ba3b..ef16ea5 100644 (file)
@@ -1922,4 +1922,6 @@ __ZN7WebCore14ResourceHandle24setDefaultStorageSessionEPK21__CFURLStorageSession
 #if ENABLE(INPUT_COLOR)
 __ZN7WebCore12ColorChooser7chooserEv
 __ZNK7WebCore12ColorChooser13colorSelectedERKNS_5ColorE
+__ZN7WebCore5ColorC1ERKN3WTF6StringE
+__ZN7WebCore16HTMLInputElement21connectToColorChooserEv
 #endif
index 8dad2c3..c4ec798 100644 (file)
@@ -167,10 +167,11 @@ void ColorInputType::detach()
 
 void ColorInputType::colorSelected(const Color& color)
 {
-    if (element()->disabled() || element()->readOnly())
+    if (element()->disabled() || element()->readOnly() || color == valueAsColor())
         return;
     element()->setValueFromRenderer(color.serialized());
     updateColorSwatch();
+    element()->dispatchFormControlChangeEvent();
 }
 
 bool ColorInputType::isColorInputType() const
index dd1f13a..c13fe1e 100644 (file)
 #include <wtf/MathExtras.h>
 #include <wtf/StdLibExtras.h>
 
+#if ENABLE(INPUT_COLOR)
+#include "ColorChooser.h"
+#include "ColorInputType.h"
+#endif
+
 using namespace std;
 
 namespace WebCore {
@@ -1471,6 +1476,16 @@ bool HTMLInputElement::recalcWillValidate() const
     return m_inputType->supportsValidation() && HTMLTextFormControlElement::recalcWillValidate();
 }
 
+#if ENABLE(INPUT_COLOR)
+bool HTMLInputElement::connectToColorChooser()
+{
+    if (!m_inputType->isColorControl())
+        return false;
+    ColorChooser::chooser()->connectClient(static_cast<ColorInputType*>(m_inputType.get()));
+    return true;
+}
+#endif
+    
 #if ENABLE(DATALIST)
 
 HTMLElement* HTMLInputElement::list() const
index 37f84eb..68e89be 100644 (file)
@@ -228,6 +228,11 @@ public:
     bool isConformToInputMask(const String&) const;
 #endif
 
+#if ENABLE(INPUT_COLOR)
+    // For test purposes.
+    bool connectToColorChooser();
+#endif
+
     static const int maximumLength;
 
 protected:
index d2e149f..e44b5f7 100644 (file)
 #include "ShadowContentElement.h"
 #include "ShadowRoot.h"
 
+#if ENABLE(INPUT_COLOR)
+#include "ColorChooser.h"
+#endif
+
 namespace WebCore {
 
 const char* Internals::internalsId = "internals";
@@ -163,6 +167,23 @@ void Internals::disableMemoryCache(bool disabled)
     WebCore::memoryCache()->setDisabled(disabled);
 }
 
+#if ENABLE(INPUT_COLOR)
+bool Internals::connectColorChooserClient(Element* element)
+{
+    if (!element->hasTagName(HTMLNames::inputTag))
+        return false;
+    HTMLInputElement* inputElement = element->toInputElement();
+    if (!inputElement)
+        return false;
+    return inputElement->connectToColorChooser();
+}
+
+void Internals::selectColorInColorChooser(const String& colorValue)
+{
+    ColorChooser::chooser()->colorSelected(Color(colorValue));
+}
+#endif
+
 #if ENABLE(INSPECTOR)
 void Internals::setInspectorResourcesDataSizeLimits(Document* document, int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode& ec)
 {
index 8149245..59249e3 100644 (file)
@@ -60,6 +60,11 @@ public:
     Element* getElementByIdInShadowRoot(Node* shadowRoot, const String& id, ExceptionCode&);
     void disableMemoryCache(bool disabled);
 
+#if ENABLE(INPUT_COLOR)
+    bool connectColorChooserClient(Element*);
+    void selectColorInColorChooser(const String& colorValue);
+#endif
+
 #if ENABLE(INSPECTOR)
     void setInspectorResourcesDataSizeLimits(Document*, int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode&);
 #else
index 6f33a3b..2de3fc4 100644 (file)
@@ -39,6 +39,11 @@ module window {
         Element getElementByIdInShadowRoot(in Node shadowRoot, in DOMString id) raises(DOMException);
         void disableMemoryCache(in boolean disabled);
 
+#if defined(ENABLE_INPUT_COLOR) && ENABLE_INPUT_COLOR
+        boolean connectColorChooserClient(in Element element);
+        void selectColorInColorChooser(in DOMString colorValue);
+#endif
+
         void setInspectorResourcesDataSizeLimits(in Document document, in long maximumResourcesContentSize, in long maximumSingleResourceContentSize) raises(DOMException);
 
         ClientRect boundingBox(in Element element) raises(DOMException);