Diff
Modified: trunk/Source/WebCore/ChangeLog (103167 => 103168)
--- trunk/Source/WebCore/ChangeLog 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/ChangeLog 2011-12-18 07:03:20 UTC (rev 103168)
@@ -1,3 +1,39 @@
+2011-12-17 Keishi Hattori <kei...@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 <s...@webkit.org>
Make PlatformTouchEvent inherit from PlatformEvent
Modified: trunk/Source/WebCore/html/ColorInputType.cpp (103167 => 103168)
--- trunk/Source/WebCore/html/ColorInputType.cpp 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/html/ColorInputType.cpp 2011-12-18 07:03:20 UTC (rev 103168)
@@ -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 @@
ColorInputType::~ColorInputType()
{
- cleanupColorChooser();
+ endColorChooser();
}
bool ColorInputType::isColorControl() const
@@ -126,9 +128,8 @@
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 @@
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 @@
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 @@
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
Modified: trunk/Source/WebCore/html/ColorInputType.h (103167 => 103168)
--- trunk/Source/WebCore/html/ColorInputType.h 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/html/ColorInputType.h 2011-12-18 07:03:20 UTC (rev 103168)
@@ -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 @@
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 @@
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
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (103167 => 103168)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-12-18 07:03:20 UTC (rev 103168)
@@ -57,7 +57,6 @@
#include <wtf/StdLibExtras.h>
#if ENABLE(INPUT_COLOR)
-#include "ColorChooser.h"
#include "ColorInputType.h"
#endif
@@ -1542,10 +1541,7 @@
{
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
Modified: trunk/Source/WebCore/loader/EmptyClients.h (103167 => 103168)
--- trunk/Source/WebCore/loader/EmptyClients.h 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/loader/EmptyClients.h 2011-12-18 07:03:20 UTC (rev 103168)
@@ -50,6 +50,10 @@
#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 @@
#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>) { }
Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (103167 => 103168)
--- trunk/Source/WebCore/loader/FrameLoader.cpp 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp 2011-12-18 07:03:20 UTC (rev 103168)
@@ -103,11 +103,6 @@
#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
Modified: trunk/Source/WebCore/page/Chrome.cpp (103167 => 103168)
--- trunk/Source/WebCore/page/Chrome.cpp 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/page/Chrome.cpp 2011-12-18 07:03:20 UTC (rev 103168)
@@ -458,20 +458,10 @@
#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);
+ return m_client->createColorChooser(client, initialColor);
}
-
-void Chrome::cleanupColorChooser(ColorChooser* colorChooser)
-{
- m_client->cleanupColorChooser(colorChooser);
-}
-
-void Chrome::setSelectedColorInColorChooser(ColorChooser* colorChooser, const Color& color)
-{
- m_client->setSelectedColorInColorChooser(colorChooser, color);
-}
#endif
void Chrome::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> fileChooser)
Modified: trunk/Source/WebCore/page/Chrome.h (103167 => 103168)
--- trunk/Source/WebCore/page/Chrome.h 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/page/Chrome.h 2011-12-18 07:03:20 UTC (rev 103168)
@@ -38,6 +38,7 @@
class ChromeClient;
#if ENABLE(INPUT_COLOR)
class ColorChooser;
+ class ColorChooserClient;
#endif
class FileChooser;
class FileIconLoader;
@@ -153,9 +154,7 @@
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>);
Modified: trunk/Source/WebCore/page/ChromeClient.h (103167 => 103168)
--- trunk/Source/WebCore/page/ChromeClient.h 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/page/ChromeClient.h 2011-12-18 07:03:20 UTC (rev 103168)
@@ -73,6 +73,7 @@
#if ENABLE(INPUT_COLOR)
class ColorChooser;
+ class ColorChooserClient;
#endif
class ChromeClient {
@@ -219,9 +220,7 @@
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;
Modified: trunk/Source/WebCore/platform/ColorChooser.h (103167 => 103168)
--- trunk/Source/WebCore/platform/ColorChooser.h 2011-12-18 06:09:11 UTC (rev 103167)
+++ trunk/Source/WebCore/platform/ColorChooser.h 2011-12-18 07:03:20 UTC (rev 103168)
@@ -30,47 +30,20 @@
#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(); }
+ virtual ~ColorChooser() { }
-protected:
- ColorChooser* newColorChooser();
- void discardChooser();
-
-private:
- RefPtr<ColorChooser> m_chooser;
+ virtual void setSelectedColor(const Color&) { }
+ virtual void endChooser() { }
};
-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*);
-
- ColorChooserClient* m_client;
-};
-
} // namespace WebCore
#endif // ENABLE(INPUT_COLOR)
Added: trunk/Source/WebCore/platform/ColorChooserClient.h (0 => 103168)
--- trunk/Source/WebCore/platform/ColorChooserClient.h (rev 0)
+++ trunk/Source/WebCore/platform/ColorChooserClient.h 2011-12-18 07:03:20 UTC (rev 103168)
@@ -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