Refactor input type color WebCore part
authorkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2011 07:03:20 +0000 (07:03 +0000)
committerkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2011 07:03:20 +0000 (07:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=74591

Reviewed by Kent Tamura.

Changing ColorChooser to address issues raised in Bug 65897.
Chrome::createColorChooser will return a WebCore::ColorChooser instance
so the WebCore side (ColorInputType) and call the WebKit side. We pass the ColorChooserClient as an argument
to Chrome::createColorChooser so the WebKit side can call callbacks, didEndChooser and didChooseColor.

* html/ColorInputType.cpp:
(WebCore::ColorInputType::~ColorInputType):
(WebCore::ColorInputType::setValue):
(WebCore::ColorInputType::handleDOMActivateEvent): Calls createColorChooser to open the color chooser.
(WebCore::ColorInputType::detach):
(WebCore::ColorInputType::didEndChooser): Release the ColorChooser object.
(WebCore::ColorInputType::endColorChooser):
(WebCore::ColorInputType::updateColorSwatch): Added argument so it will compile again.
* html/ColorInputType.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::selectColorInColorChooser):
* loader/EmptyClients.h:
(WebCore::EmptyChromeClient::createColorChooser):
* loader/FrameLoader.cpp:
* page/Chrome.cpp:
(WebCore::Chrome::createColorChooser): Opens the color chooser. Returns a ColorChooser PassOwnPtr.
* page/Chrome.h:
* page/ChromeClient.h:
* platform/ColorChooser.h:
(WebCore::ColorChooser::~ColorChooser):
(WebCore::ColorChooser::setSelectedColor):
(WebCore::ColorChooser::endChooser):
* platform/ColorChooserClient.h: Added.

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

Source/WebCore/ChangeLog
Source/WebCore/html/ColorInputType.cpp
Source/WebCore/html/ColorInputType.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/loader/EmptyClients.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/page/Chrome.cpp
Source/WebCore/page/Chrome.h
Source/WebCore/page/ChromeClient.h
Source/WebCore/platform/ColorChooser.h
Source/WebCore/platform/ColorChooserClient.h [new file with mode: 0644]

index cca303d..929d50e 100644 (file)
@@ -1,3 +1,39 @@
+2011-12-17  Keishi Hattori  <keishi@webkit.org>
+
+        Refactor input type color WebCore part
+        https://bugs.webkit.org/show_bug.cgi?id=74591
+
+        Reviewed by Kent Tamura.
+
+        Changing ColorChooser to address issues raised in Bug 65897.
+        Chrome::createColorChooser will return a WebCore::ColorChooser instance
+        so the WebCore side (ColorInputType) and call the WebKit side. We pass the ColorChooserClient as an argument
+        to Chrome::createColorChooser so the WebKit side can call callbacks, didEndChooser and didChooseColor.
+
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::~ColorInputType):
+        (WebCore::ColorInputType::setValue):
+        (WebCore::ColorInputType::handleDOMActivateEvent): Calls createColorChooser to open the color chooser.
+        (WebCore::ColorInputType::detach):
+        (WebCore::ColorInputType::didEndChooser): Release the ColorChooser object.
+        (WebCore::ColorInputType::endColorChooser):
+        (WebCore::ColorInputType::updateColorSwatch): Added argument so it will compile again.
+        * html/ColorInputType.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::selectColorInColorChooser):
+        * loader/EmptyClients.h:
+        (WebCore::EmptyChromeClient::createColorChooser):
+        * loader/FrameLoader.cpp:
+        * page/Chrome.cpp:
+        (WebCore::Chrome::createColorChooser): Opens the color chooser. Returns a ColorChooser PassOwnPtr.
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        * platform/ColorChooser.h:
+        (WebCore::ColorChooser::~ColorChooser):
+        (WebCore::ColorChooser::setSelectedColor):
+        (WebCore::ColorChooser::endChooser):
+        * platform/ColorChooserClient.h: Added.
+
 2011-12-17  Sam Weinig  <sam@webkit.org>
 
         Make PlatformTouchEvent inherit from PlatformEvent
index 57ee577..d7bd81f 100644 (file)
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "ColorInputType.h"
 
+#include "CSSPropertyNames.h"
 #include "Chrome.h"
 #include "Color.h"
 #include "HTMLDivElement.h"
@@ -38,6 +39,7 @@
 #include "MouseEvent.h"
 #include "ScriptController.h"
 #include "ShadowRoot.h"
+
 #include <wtf/PassOwnPtr.h>
 #include <wtf/text/WTFString.h>
 
@@ -66,7 +68,7 @@ PassOwnPtr<InputType> ColorInputType::create(HTMLInputElement* element)
 
 ColorInputType::~ColorInputType()
 {
-    cleanupColorChooser();
+    endColorChooser();
 }
 
 bool ColorInputType::isColorControl() const
@@ -126,9 +128,8 @@ void ColorInputType::setValue(const String& value, bool valueChanged, bool sendC
         return;
 
     updateColorSwatch();
-    Chrome* chrome = this->chrome();
-    if (chrome && chooser())
-        chrome->setSelectedColorInColorChooser(chooser(), valueAsColor());
+    if (m_chooser)
+        m_chooser->setSelectedColor(valueAsColor());
 }
 
 void ColorInputType::handleDOMActivateEvent(Event* event)
@@ -139,14 +140,16 @@ void ColorInputType::handleDOMActivateEvent(Event* event)
     if (!ScriptController::processingUserGesture())
         return;
 
-    if (Chrome* chrome = this->chrome())
-        chrome->openColorChooser(newColorChooser(), valueAsColor());
+    Chrome* chrome = this->chrome();
+    if (chrome && !m_chooser)
+        m_chooser = chrome->createColorChooser(this, valueAsColor());
+
     event->setDefaultHandled();
 }
 
 void ColorInputType::detach()
 {
-    cleanupColorChooser();
+    endColorChooser();
 }
 
 void ColorInputType::didChooseColor(const Color& color)
@@ -158,17 +161,15 @@ void ColorInputType::didChooseColor(const Color& color)
     element()->dispatchFormControlChangeEvent();
 }
 
-void ColorInputType::didCleanup()
+void ColorInputType::didEndChooser()
 {
-    discardChooser();
+    m_chooser.clear();
 }
 
-void ColorInputType::cleanupColorChooser()
+void ColorInputType::endColorChooser()
 {
-    Chrome* chrome = this->chrome();
-    if (chrome && chooser())
-        chrome->cleanupColorChooser(chooser());
-    discardChooser();
+    if (m_chooser)
+        m_chooser->endChooser();
 }
 
 void ColorInputType::updateColorSwatch()
@@ -177,8 +178,7 @@ void ColorInputType::updateColorSwatch()
     if (!colorSwatch)
         return;
 
-    ExceptionCode ec;
-    colorSwatch->style()->setProperty("background-color", element()->value(), ec);
+    colorSwatch->style()->setProperty(CSSPropertyBackgroundColor, element()->value(), false, ASSERT_NO_EXCEPTION);
 }
 
 HTMLElement* ColorInputType::shadowColorSwatch() const
index 4b233d3..eb0fd09 100644 (file)
@@ -31,7 +31,7 @@
 #ifndef ColorInputType_h
 #define ColorInputType_h
 
-#include "ColorChooser.h"
+#include "ColorChooserClient.h"
 #include "InputType.h"
 
 #if ENABLE(INPUT_COLOR)
@@ -43,6 +43,10 @@ public:
     static PassOwnPtr<InputType> create(HTMLInputElement*);
     virtual ~ColorInputType();
 
+    // ColorChooserClient implementation.
+    virtual void didChooseColor(const Color&) OVERRIDE;
+    virtual void didEndChooser() OVERRIDE;
+
 private:
     ColorInputType(HTMLInputElement* element) : InputType(element) { }
     virtual bool isColorControl() const;
@@ -56,13 +60,11 @@ private:
     virtual void handleDOMActivateEvent(Event*);
     virtual void detach();
 
-    // ColorChooserClient implementation.
-    virtual void didChooseColor(const Color&) OVERRIDE;
-    virtual void didCleanup() OVERRIDE;
-
-    void cleanupColorChooser();
+    void endColorChooser();
     void updateColorSwatch();
     HTMLElement* shadowColorSwatch() const;
+
+    OwnPtr<ColorChooser> m_chooser;
 };
 
 } // namespace WebCore
index b61774e..7e03ec6 100644 (file)
@@ -57,7 +57,6 @@
 #include <wtf/StdLibExtras.h>
 
 #if ENABLE(INPUT_COLOR)
-#include "ColorChooser.h"
 #include "ColorInputType.h"
 #endif
 
@@ -1542,10 +1541,7 @@ void HTMLInputElement::selectColorInColorChooser(const Color& color)
 {
     if (!m_inputType->isColorControl())
         return;
-    RefPtr<ColorChooser> chooser = static_cast<ColorInputType*>(m_inputType.get())->chooser();
-    if (!chooser)
-        return;
-    chooser->didChooseColor(color);
+    static_cast<ColorInputType*>(m_inputType.get())->didChooseColor(color);
 }
 #endif
     
index f970c94..a7ddfc6 100644 (file)
 #include <v8.h>
 #endif
 
+#if ENABLE(INPUT_COLOR)
+#include "ColorChooser.h"
+#endif
+
 /*
  This file holds empty Client stubs for use by WebCore.
  Viewless element needs to create a dummy Page->Frame->FrameView tree for use in parsing or executing JavaScript.
@@ -193,9 +197,7 @@ public:
 #endif
 
 #if ENABLE(INPUT_COLOR)
-    void openColorChooser(ColorChooser*, const Color&) { }
-    void cleanupColorChooser(ColorChooser*) { }
-    void setSelectedColorInColorChooser(ColorChooser*, const Color&) { }
+    virtual PassOwnPtr<ColorChooser> createColorChooser(ColorChooserClient*, const Color&) { return nullptr; }
 #endif
 
     virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) { }
index ff4ea51..2943cdd 100644 (file)
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
-#if ENABLE(INPUT_COLOR)
-#include "ColorChooser.h"
-#include "ColorInputType.h"
-#endif
-
 #if ENABLE(SHARED_WORKERS)
 #include "SharedWorkerRepository.h"
 #endif
index a98c7d2..45bbc0c 100644 (file)
@@ -458,19 +458,9 @@ void Chrome::enumerateChosenDirectory(FileChooser* fileChooser)
 #endif
 
 #if ENABLE(INPUT_COLOR)
-void Chrome::openColorChooser(ColorChooser* colorChooser, const Color& initialColor)
+PassOwnPtr<ColorChooser> Chrome::createColorChooser(ColorChooserClient* client, const Color& initialColor)
 {
-    m_client->openColorChooser(colorChooser, initialColor);
-}
-
-void Chrome::cleanupColorChooser(ColorChooser* colorChooser)
-{
-    m_client->cleanupColorChooser(colorChooser);
-}
-
-void Chrome::setSelectedColorInColorChooser(ColorChooser* colorChooser, const Color& color)
-{
-    m_client->setSelectedColorInColorChooser(colorChooser, color);
+    return m_client->createColorChooser(client, initialColor);
 }
 #endif
 
index 57aadf5..0cec293 100644 (file)
@@ -38,6 +38,7 @@ namespace WebCore {
     class ChromeClient;
 #if ENABLE(INPUT_COLOR)
     class ColorChooser;
+    class ColorChooserClient;
 #endif
     class FileChooser;
     class FileIconLoader;
@@ -153,9 +154,7 @@ namespace WebCore {
         void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*);
 
 #if ENABLE(INPUT_COLOR)
-        void openColorChooser(ColorChooser*, const Color&);
-        void cleanupColorChooser(ColorChooser*);
-        void setSelectedColorInColorChooser(ColorChooser*, const Color&);
+        PassOwnPtr<ColorChooser> createColorChooser(ColorChooserClient*, const Color& initialColor);
 #endif
 
         void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
index 6d484f2..d311414 100644 (file)
@@ -73,6 +73,7 @@ namespace WebCore {
 
 #if ENABLE(INPUT_COLOR)
     class ColorChooser;
+    class ColorChooserClient;
 #endif
 
     class ChromeClient {
@@ -219,9 +220,7 @@ namespace WebCore {
         virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*) = 0;
 
 #if ENABLE(INPUT_COLOR)
-        virtual void openColorChooser(ColorChooser*, const Color&) = 0;
-        virtual void cleanupColorChooser(ColorChooser*) = 0;
-        virtual void setSelectedColorInColorChooser(ColorChooser*, const Color&) = 0;
+        virtual PassOwnPtr<ColorChooser> createColorChooser(ColorChooserClient*, const Color&) = 0;
 #endif
 
         virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0;
index ba11134..1baa988 100644 (file)
 #ifndef ColorChooser_h
 #define ColorChooser_h
 
-#include "Color.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-
 #if ENABLE(INPUT_COLOR)
 
 namespace WebCore {
 
-class ColorChooser;
+class Color;
 
-class ColorChooserClient {
+class ColorChooser {
 public:
-    virtual ~ColorChooserClient();
-    virtual void didChooseColor(const Color&) = 0;
-    virtual void didCleanup() = 0;
-    ColorChooser* chooser() { return m_chooser.get(); }
-
-protected:
-    ColorChooser* newColorChooser();
-    void discardChooser();
-
-private:
-    RefPtr<ColorChooser> m_chooser;
-};
-
-class ColorChooser : public RefCounted<ColorChooser> {
-public:
-    static PassRefPtr<ColorChooser> create(ColorChooserClient*);
-    ~ColorChooser();
-
-    void disconnectClient() { m_client = 0; }
-
-    void didChooseColor(const Color&);
-    void didCleanup();
-
-private:
-    ColorChooser(ColorChooserClient*);
+    virtual ~ColorChooser() { }
 
-    ColorChooserClient* m_client;
+    virtual void setSelectedColor(const Color&) { }
+    virtual void endChooser() { }
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/platform/ColorChooserClient.h b/Source/WebCore/platform/ColorChooserClient.h
new file mode 100644 (file)
index 0000000..e5ea2fd
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef ColorChooserClient_h
+#define ColorChooserClient_h
+
+#if ENABLE(INPUT_COLOR)
+
+#include "ColorChooser.h"
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class Color;
+
+class ColorChooserClient {
+public:
+    virtual void didChooseColor(const Color&) = 0;
+    virtual void didEndChooser() = 0;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(INPUT_COLOR)
+
+#endif // ColorChooserClient_h