Implement <input type=color> UI behavior WebCore part
authorkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Aug 2011 13:45:21 +0000 (13:45 +0000)
committerkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Aug 2011 13:45:21 +0000 (13:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=62619

Reviewed by Kent Tamura.

* WebCore.exp.in: Added __ZN7WebCore12ColorChooser7chooserEv and
__ZNK7WebCore12ColorChooser13colorSelectedERKNS_5ColorE
* WebCore.xcodeproj/project.pbxproj: Added ColorChooser.{h,cpp}
* html/ColorInputType.cpp:
(WebCore::ColorInputType::~ColorInputType): Added. Close color chooser. ex. when type attribute changes.
(WebCore::ColorInputType::valueAsColor): Added.
(WebCore::ColorInputType::setValueAsColor): Added.
(WebCore::ColorInputType::valueChanged): Update selected color in color chooser too.
(WebCore::ColorInputType::handleClickEvent): Opens color chooser.
(WebCore::ColorInputType::handleDOMActivateEvent): Called when element.click(). Open color chooser only
when it was initiated by a user interaction.
(WebCore::ColorInputType::detach): Close color chooser. Called when input element or its ancestors have "display:none"
or is removed from DOM.
(WebCore::ColorInputType::colorSelected): Callback from color chooser.
(WebCore::ColorInputType::closeColorChooserIfClientIsInDocument): Close color chooser if element is in
document. Called when the page navigates away.
(WebCore::ColorInputType::closeColorChooserIfCurrentClient): Close color chooser if this input type is the current client of ColorChooser.
* html/ColorInputType.h:
* html/FileInputType.cpp:
* html/FileInputType.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::detach): Calls InputType::detach
* html/InputType.cpp:
(WebCore::InputType::chrome): Added. Used in FileInputType and ColorInputType.
(WebCore::InputType::detach): ColorInputType overrides this.
* html/InputType.h:
* loader/EmptyClients.h:
(WebCore::EmptyChromeClient::openColorChooser): Added.
(WebCore::EmptyChromeClient::closeColorChooser): Added.
(WebCore::EmptyChromeClient::setSelectedColorInColorChooser): Added.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::transitionToCommitted): Close color chooser when
navigating away from the page.
* page/Chrome.cpp:
(WebCore::Chrome::openColorChooser): Added. Opens the color chooser.
(WebCore::Chrome::closeColorChooser): Added. Tries to close the color chooser. Might not close if the
listener of the color chooser is another part of the browser or another render process.
(WebCore::Chrome::setSelectedColorInColorChooser): Added. Sets the selected color in the color chooser.
Again, might not be executed if the listener of the color chooser is another part of the browser or another render process.
* page/Chrome.h:
* page/ChromeClient.h:
* platform/ColorChooser.cpp: Added.
(WebCore::ColorChooserClient::~ColorChooserClient): Disconnects itself from the ColorChooser.
(WebCore::ColorChooser::chooser): Get shared instance of ColorChooser.
(WebCore::ColorChooser::chooser): Get shared instance of ColorChooser.
(WebCore::ColorChooser::connectClient): Connects a ColorChooserClient that receives the colorSelected callbacks.
(WebCore::ColorChooser::disconnectClient): Disconnects the connectClient.
(WebCore::ColorChooser::closeColorChooserIfClientIsInDocument): Close the color chooser if the client is
inside the document.
(WebCore::ColorChooser::colorSelected): Called from color chooser listener.
* platform/ColorChooser.h: Added.
(WebCore::ColorChooser::client): Added. Returns the current connected client.
(WebCore::ColorChooser::ColorChooser): Added.

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/ColorInputType.cpp
Source/WebCore/html/ColorInputType.h
Source/WebCore/html/FileInputType.cpp
Source/WebCore/html/FileInputType.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/InputType.cpp
Source/WebCore/html/InputType.h
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.cpp [new file with mode: 0644]
Source/WebCore/platform/ColorChooser.h [new file with mode: 0644]

index 95cf4ac..84293fd 100644 (file)
@@ -1,3 +1,64 @@
+2011-08-05  Keishi Hattori  <keishi@webkit.org>
+
+        Implement <input type=color> UI behavior WebCore part
+        https://bugs.webkit.org/show_bug.cgi?id=62619
+
+        Reviewed by Kent Tamura.
+
+        * WebCore.exp.in: Added __ZN7WebCore12ColorChooser7chooserEv and
+        __ZNK7WebCore12ColorChooser13colorSelectedERKNS_5ColorE
+        * WebCore.xcodeproj/project.pbxproj: Added ColorChooser.{h,cpp}
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::~ColorInputType): Added. Close color chooser. ex. when type attribute changes.
+        (WebCore::ColorInputType::valueAsColor): Added.
+        (WebCore::ColorInputType::setValueAsColor): Added.
+        (WebCore::ColorInputType::valueChanged): Update selected color in color chooser too.
+        (WebCore::ColorInputType::handleClickEvent): Opens color chooser.
+        (WebCore::ColorInputType::handleDOMActivateEvent): Called when element.click(). Open color chooser only
+        when it was initiated by a user interaction.
+        (WebCore::ColorInputType::detach): Close color chooser. Called when input element or its ancestors have "display:none"
+        or is removed from DOM.
+        (WebCore::ColorInputType::colorSelected): Callback from color chooser.
+        (WebCore::ColorInputType::closeColorChooserIfClientIsInDocument): Close color chooser if element is in
+        document. Called when the page navigates away.
+        (WebCore::ColorInputType::closeColorChooserIfCurrentClient): Close color chooser if this input type is the current client of ColorChooser.
+        * html/ColorInputType.h:
+        * html/FileInputType.cpp:
+        * html/FileInputType.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::detach): Calls InputType::detach
+        * html/InputType.cpp:
+        (WebCore::InputType::chrome): Added. Used in FileInputType and ColorInputType.
+        (WebCore::InputType::detach): ColorInputType overrides this.
+        * html/InputType.h:
+        * loader/EmptyClients.h:
+        (WebCore::EmptyChromeClient::openColorChooser): Added.
+        (WebCore::EmptyChromeClient::closeColorChooser): Added.
+        (WebCore::EmptyChromeClient::setSelectedColorInColorChooser): Added.
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::transitionToCommitted): Close color chooser when
+        navigating away from the page.
+        * page/Chrome.cpp:
+        (WebCore::Chrome::openColorChooser): Added. Opens the color chooser.
+        (WebCore::Chrome::closeColorChooser): Added. Tries to close the color chooser. Might not close if the
+        listener of the color chooser is another part of the browser or another render process.
+        (WebCore::Chrome::setSelectedColorInColorChooser): Added. Sets the selected color in the color chooser.
+        Again, might not be executed if the listener of the color chooser is another part of the browser or another render process.
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        * platform/ColorChooser.cpp: Added.
+        (WebCore::ColorChooserClient::~ColorChooserClient): Disconnects itself from the ColorChooser.
+        (WebCore::ColorChooser::chooser): Get shared instance of ColorChooser.
+        (WebCore::ColorChooser::chooser): Get shared instance of ColorChooser.
+        (WebCore::ColorChooser::connectClient): Connects a ColorChooserClient that receives the colorSelected callbacks.
+        (WebCore::ColorChooser::disconnectClient): Disconnects the connectClient.
+        (WebCore::ColorChooser::closeColorChooserIfClientIsInDocument): Close the color chooser if the client is
+        inside the document.
+        (WebCore::ColorChooser::colorSelected): Called from color chooser listener.
+        * platform/ColorChooser.h: Added.
+        (WebCore::ColorChooser::client): Added. Returns the current connected client.
+        (WebCore::ColorChooser::ColorChooser): Added.
+
 2011-08-05  Yury Semikhatsky  <yurys@chromium.org>
 
         Web Inspector: check that detaching frame has been attached before removing it from the console selector
index b412998..1c7fe44 100644 (file)
@@ -1945,3 +1945,8 @@ __ZNK7WebCore13ResourceErrorcvP7NSErrorEv
 __ZN7WebCore12SchedulePairC1EP9NSRunLoopPK10__CFString
 __ZN7WebCore14ResourceHandle12releaseProxyEv
 #endif
+
+#if ENABLE(INPUT_COLOR)
+__ZN7WebCore12ColorChooser7chooserEv
+__ZNK7WebCore12ColorChooser13colorSelectedERKNS_5ColorE
+#endif
index 8d03595..2164073 100644 (file)
                C0F2A44113869AAB0066C534 /* preprocessor.pm in Headers */ = {isa = PBXBuildFile; fileRef = C0F2A43F13869A280066C534 /* preprocessor.pm */; settings = {ATTRIBUTES = (Private, ); }; };
                C105DA620F3AA68F001DD44F /* TextEncodingDetectorICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */; };
                C105DA640F3AA6B8001DD44F /* TextEncodingDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */; };
+               C330A22213EC196B0000B45B /* ColorChooser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C330A22013EC196B0000B45B /* ColorChooser.cpp */; };
+               C330A22313EC196B0000B45B /* ColorChooser.h in Headers */ = {isa = PBXBuildFile; fileRef = C330A22113EC196B0000B45B /* ColorChooser.h */; settings = {ATTRIBUTES = (Private, ); }; };
                C50B561612119D23008B46E0 /* GroupSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C50B561412119D23008B46E0 /* GroupSettings.cpp */; };
                C50B561712119D23008B46E0 /* GroupSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = C50B561512119D23008B46E0 /* GroupSettings.h */; settings = {ATTRIBUTES = (Private, ); }; };
                C50D0E820FF4272900AC2644 /* StorageNamespace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C50D0E800FF4272900AC2644 /* StorageNamespace.cpp */; };
                C0F2A43F13869A280066C534 /* preprocessor.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = preprocessor.pm; path = scripts/preprocessor.pm; sourceTree = "<group>"; };
                C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEncodingDetectorICU.cpp; sourceTree = "<group>"; };
                C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEncodingDetector.h; sourceTree = "<group>"; };
+               C330A22013EC196B0000B45B /* ColorChooser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorChooser.cpp; sourceTree = "<group>"; };
+               C330A22113EC196B0000B45B /* ColorChooser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorChooser.h; sourceTree = "<group>"; };
                C50B561412119D23008B46E0 /* GroupSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GroupSettings.cpp; sourceTree = "<group>"; };
                C50B561512119D23008B46E0 /* GroupSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupSettings.h; sourceTree = "<group>"; };
                C50D0E800FF4272900AC2644 /* StorageNamespace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageNamespace.cpp; sourceTree = "<group>"; };
                                89D08D9D12228451001241DF /* AsyncFileSystem.h */,
                                89D08D9E12228451001241DF /* AsyncFileSystemCallbacks.h */,
                                51E1ECB10C91C55600DC255B /* AutodrainedPool.h */,
+                               C330A22013EC196B0000B45B /* ColorChooser.cpp */,
+                               C330A22113EC196B0000B45B /* ColorChooser.h */,
                                BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
                                41D015C90F4B5C71004A662F /* ContentType.cpp */,
                                41D015C80F4B5C71004A662F /* ContentType.h */,
                                93C441F00F813A1A00C1A634 /* CollectionCache.h in Headers */,
                                93C442000F813AE100C1A634 /* CollectionType.h in Headers */,
                                B27535670B053814002CE64F /* Color.h in Headers */,
+                               C330A22313EC196B0000B45B /* ColorChooser.h in Headers */,
                                B22279630D00BF220071B782 /* ColorDistance.h in Headers */,
                                F55B3DB41251F12D003EF269 /* ColorInputType.h in Headers */,
                                EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */,
                                93C441EF0F813A1A00C1A634 /* CollectionCache.cpp in Sources */,
                                B27535660B053814002CE64F /* Color.cpp in Sources */,
                                0FCF33240F2B9715004B6795 /* ColorCG.cpp in Sources */,
+                               C330A22213EC196B0000B45B /* ColorChooser.cpp in Sources */,
                                1ABA76C911D20E47004C201C /* ColorData.cpp in Sources */,
                                B22279620D00BF220071B782 /* ColorDistance.cpp in Sources */,
                                F55B3DB31251F12D003EF269 /* ColorInputType.cpp in Sources */,
index ea46a66..02f83b1 100644 (file)
 #include "config.h"
 #include "ColorInputType.h"
 
+#include "Chrome.h"
 #include "Color.h"
 #include "HTMLDivElement.h"
 #include "HTMLInputElement.h"
+#include "MouseEvent.h"
+#include "ScriptController.h"
 #include "ShadowRoot.h"
 #include <wtf/PassOwnPtr.h>
 #include <wtf/text/WTFString.h>
@@ -61,6 +64,11 @@ PassOwnPtr<InputType> ColorInputType::create(HTMLInputElement* element)
     return adoptPtr(new ColorInputType(element));
 }
 
+ColorInputType::~ColorInputType()
+{
+    closeColorChooserIfCurrentClient();
+}    
+
 bool ColorInputType::isColorControl() const
 {
     return true;
@@ -92,6 +100,16 @@ String ColorInputType::sanitizeValue(const String& proposedValue)
     return proposedValue.lower();
 }
 
+Color ColorInputType::valueAsColor() const
+{
+    return Color(element()->value());
+}
+
+void ColorInputType::setValueAsColor(const Color& color) const
+{
+    element()->setValue(color.serialized(), true);
+}
+
 void ColorInputType::createShadowSubtree()
 {
     Document* document = element()->document();
@@ -111,6 +129,58 @@ void ColorInputType::createShadowSubtree()
 void ColorInputType::valueChanged()
 {
     updateColorSwatch();
+    if (ColorChooser::chooser()->client() == this) {
+        if (Chrome* chrome = this->chrome())
+            chrome->setSelectedColorInColorChooser(valueAsColor());
+    }
+}
+
+void ColorInputType::handleClickEvent(MouseEvent* event)
+{
+    if (event->isSimulated())
+        return;
+
+    if (element()->disabled() || element()->readOnly())
+        return;
+
+    if (Chrome* chrome = this->chrome()) {
+        ColorChooser::chooser()->connectClient(this);
+        chrome->openColorChooser(ColorChooser::chooser(), valueAsColor());
+    }
+    event->setDefaultHandled();
+}
+
+void ColorInputType::handleDOMActivateEvent(Event* event)
+{
+    if (element()->disabled() || element()->readOnly() || !element()->renderer())
+        return;
+
+    if (!ScriptController::processingUserGesture())
+        return;
+
+    if (Chrome* chrome = this->chrome()) {
+        ColorChooser::chooser()->connectClient(this);
+        chrome->openColorChooser(ColorChooser::chooser(), valueAsColor());
+    }
+    event->setDefaultHandled();
+}
+
+void ColorInputType::detach()
+{
+    closeColorChooserIfCurrentClient();
+}
+
+void ColorInputType::colorSelected(const Color& color)
+{
+    if (element()->disabled() || element()->readOnly())
+        return;
+    setValueAsColor(color);
+}
+
+void ColorInputType::closeColorChooserIfClientIsInDocument(Document* document)
+{
+    if (element()->document() == document)
+        closeColorChooserIfCurrentClient();
 }
 
 void ColorInputType::updateColorSwatch()
@@ -129,6 +199,14 @@ HTMLElement* ColorInputType::shadowColorSwatch() const
     return shadow ? toHTMLElement(shadow->firstChild()->firstChild()) : 0;
 }
 
+void ColorInputType::closeColorChooserIfCurrentClient()
+{
+    if (ColorChooser::chooser()->client() == this) {
+        if (Chrome* chrome = this->chrome())
+            chrome->closeColorChooser();
+    }
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INPUT_COLOR)
index d34084f..0c6739e 100644 (file)
 #ifndef ColorInputType_h
 #define ColorInputType_h
 
-#include "BaseButtonInputType.h"
+#include "ColorChooser.h"
+#include "InputType.h"
 
 #if ENABLE(INPUT_COLOR)
 
 namespace WebCore {
 
-class ColorInputType : public InputType {
+class ColorInputType : public InputType, private ColorChooserClient {
 public:
     static PassOwnPtr<InputType> create(HTMLInputElement*);
 
 private:
     ColorInputType(HTMLInputElement* element) : InputType(element) { }
+    virtual ~ColorInputType();
     virtual bool isColorControl() const;
     virtual const AtomicString& formControlType() const;
     virtual bool supportsRequired() const;
     virtual String fallbackValue();
     virtual String sanitizeValue(const String&);
+    virtual Color valueAsColor() const;
+    virtual void setValueAsColor(const Color&) const;
     virtual void createShadowSubtree();
     virtual void valueChanged();
+    virtual void handleClickEvent(MouseEvent*);
+    virtual void handleDOMActivateEvent(Event*);
+    virtual void detach();
+
+    // ColorChooserClient implementation.
+    virtual void colorSelected(const Color&);
+    virtual void closeColorChooserIfClientIsInDocument(Document*);
 
     void updateColorSwatch();
     HTMLElement* shadowColorSwatch() const;
+    void closeColorChooserIfCurrentClient() const;
 };
 
 } // namespace WebCore
index 5f224e7..5d5ca39 100644 (file)
@@ -33,7 +33,6 @@
 #include "HTMLNames.h"
 #include "Icon.h"
 #include "LocalizedStrings.h"
-#include "Page.h"
 #include "RenderFileUploadControl.h"
 #include "ScriptController.h"
 #include "ShadowRoot.h"
@@ -333,13 +332,6 @@ void FileInputType::updateRendering(PassRefPtr<Icon> icon)
         element()->renderer()->repaint();
 }
 
-Chrome* FileInputType::chrome() const
-{
-    if (Page* page = element()->document()->page())
-        return page->chrome();
-    return 0;
-}
-
 void FileInputType::receiveDroppedFiles(const Vector<String>& paths)
 {
     HTMLInputElement* input = element();
index aacbd21..9eaa72e 100644 (file)
@@ -39,7 +39,6 @@
 
 namespace WebCore {
 
-class Chrome;
 class FileList;
 
 class FileInputType : public BaseButtonInputType, private FileChooserClient, private FileIconLoaderClient {
@@ -77,7 +76,6 @@ private:
     void receiveDropForDirectoryUpload(const Vector<String>&);
 #endif
     void requestIcon(const Vector<String>&);
-    Chrome* chrome() const;
 
     RefPtr<FileList> m_fileList;
     RefPtr<Icon> m_icon;
index ad49423..3ed15cb 100644 (file)
@@ -880,6 +880,7 @@ void HTMLInputElement::detach()
 {
     HTMLTextFormControlElement::detach();
     setFormControlValueMatchesRenderer(false);
+    m_inputType->detach();
 }
 
 String HTMLInputElement::altText() const
index 6092460..6c34dc4 100644 (file)
@@ -48,6 +48,7 @@
 #include "LocalizedStrings.h"
 #include "MonthInputType.h"
 #include "NumberInputType.h"
+#include "Page.h"
 #include "PasswordInputType.h"
 #include "RadioInputType.h"
 #include "RangeInputType.h"
@@ -395,6 +396,13 @@ void InputType::dispatchSimulatedClickIfActive(KeyboardEvent* event) const
     event->setDefaultHandled();
 }
 
+Chrome* InputType::chrome() const
+{
+    if (Page* page = element()->document()->page())
+        return page->chrome();
+    return 0;
+}
+
 bool InputType::canSetStringValue() const
 {
     return true;
@@ -423,6 +431,10 @@ void InputType::attach()
 {
 }
 
+void InputType::detach()
+{
+}
+
 void InputType::altAttributeChanged()
 {
 }
index 2df0ef5..511f95b 100644 (file)
@@ -41,6 +41,8 @@
 namespace WebCore {
 
 class BeforeTextInsertedEvent;
+class Chrome;
+class Color;
 class DateComponents;
 class Event;
 class FileList;
@@ -91,7 +93,7 @@ public:
 
 #if ENABLE(INPUT_COLOR)
     virtual bool isColorControl() const;
-#endif // ENABLE(INPUT_COLOR)
+#endif
     virtual bool isCheckbox() const;
     virtual bool isEmailField() const;
     virtual bool isFileUpload() const;
@@ -205,6 +207,7 @@ public:
     virtual bool rendererIsNeeded();
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
     virtual void attach();
+    virtual void detach();
     virtual void minOrMaxAttributeChanged();
     virtual void altAttributeChanged();
     virtual void srcAttributeChanged();
@@ -260,6 +263,7 @@ protected:
     void dispatchSimulatedClickIfActive(KeyboardEvent*) const;
     // We can't make this a static const data member because VC++ doesn't like it.
     static double defaultStepBase() { return 0.0; }
+    Chrome* chrome() const;
 
 private:
     // Raw pointer because the HTMLInputElement object owns this InputType object.
index b409756..8c7fc53 100644 (file)
@@ -196,6 +196,12 @@ public:
     virtual void enumerateChosenDirectory(FileChooser*) { }
 #endif
 
+#if ENABLE(INPUT_COLOR)
+    void openColorChooser(ColorChooser*, const Color&) { }
+    void closeColorChooser() { }
+    void setSelectedColorInColorChooser(const Color&) { }
+#endif
+
     virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) { }
     virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*) { }
 
index 6a49e46..71eaed1 100644 (file)
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
+#if ENABLE(INPUT_COLOR)
+#include "ColorChooser.h"
+#endif
+
 #if ENABLE(SHARED_WORKERS)
 #include "SharedWorkerRepository.h"
 #endif
@@ -1816,6 +1820,11 @@ void FrameLoader::transitionToCommitted(PassRefPtr<CachedPage> cachedPage)
     if (m_frame->view())
         m_frame->view()->scrollAnimator()->cancelAnimations();
 
+#if ENABLE(INPUT_COLOR)
+    if (m_frame->document())
+        ColorChooser::chooser()->closeColorChooserIfClientIsInDocument(m_frame->document());
+#endif
+
     m_client->setCopiesOnScroll();
     history()->updateForCommit();
 
index 484ca81..5c7cb14 100644 (file)
 #include "StorageNamespace.h"
 #endif
 
+#if ENABLE(INPUT_COLOR)
+#include "ColorChooser.h"
+#endif
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -467,6 +471,23 @@ void Chrome::enumerateChosenDirectory(FileChooser* fileChooser)
 }
 #endif
 
+#if ENABLE(INPUT_COLOR)
+void Chrome::openColorChooser(ColorChooser* colorChooser, const Color& initialColor)
+{
+    m_client->openColorChooser(colorChooser, initialColor);
+}
+
+void Chrome::closeColorChooser()
+{
+    m_client->closeColorChooser();
+}
+
+void Chrome::setSelectedColorInColorChooser(const Color& color)
+{
+    m_client->setSelectedColorInColorChooser(color);
+}
+#endif
+
 void Chrome::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> fileChooser)
 {
     m_client->runOpenPanel(frame, fileChooser);
index 12b9f54..2ed6e72 100644 (file)
@@ -36,6 +36,9 @@ class NSView;
 namespace WebCore {
 
     class ChromeClient;
+#if ENABLE(INPUT_COLOR)
+    class ColorChooser;
+#endif
     class FileChooser;
     class FileIconLoader;
     class FloatRect;
@@ -154,6 +157,12 @@ namespace WebCore {
         void requestGeolocationPermissionForFrame(Frame*, Geolocation*);
         void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*);
 
+#if ENABLE(INPUT_COLOR)
+        void openColorChooser(ColorChooser*, const Color&);
+        void closeColorChooser();
+        void setSelectedColorInColorChooser(const Color&);
+#endif
+
         void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
         void loadIconForFiles(const Vector<String>&, FileIconLoader*);
 #if ENABLE(DIRECTORY_UPLOAD)
index d5e6d7b..17f7906 100644 (file)
@@ -71,6 +71,10 @@ namespace WebCore {
     class GraphicsLayer;
 #endif
 
+#if ENABLE(INPUT_COLOR)
+    class ColorChooser;
+#endif
+
 #if ENABLE(NOTIFICATIONS)
     class NotificationPresenter;
 #endif
@@ -231,6 +235,12 @@ namespace WebCore {
         virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*) = 0;
         virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*) = 0;
 
+#if ENABLE(INPUT_COLOR)
+        virtual void openColorChooser(ColorChooser*, const Color&) = 0;
+        virtual void closeColorChooser() = 0;
+        virtual void setSelectedColorInColorChooser(const Color&) = 0;
+#endif
+
         virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0;
         // Asynchronous request to load an icon for specified filenames.
         virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*) = 0;
diff --git a/Source/WebCore/platform/ColorChooser.cpp b/Source/WebCore/platform/ColorChooser.cpp
new file mode 100644 (file)
index 0000000..a431d6e
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "config.h"
+#include "ColorChooser.h"
+
+#if ENABLE(INPUT_COLOR)
+
+namespace WebCore {
+
+ColorChooserClient::~ColorChooserClient()
+{
+    ColorChooser::chooser()->disconnectClient(this);
+}
+
+static ColorChooser* staticChooser = 0;
+
+ColorChooser* ColorChooser::chooser()
+{
+    if (!staticChooser)
+        staticChooser = new ColorChooser();
+    return staticChooser;
+}
+
+void ColorChooser::connectClient(ColorChooserClient* client)
+{
+    if (client != m_client)
+        m_client = client;
+}
+
+void ColorChooser::disconnectClient(ColorChooserClient* client)
+{
+    if (client == m_client)
+        m_client = 0;
+}
+
+void ColorChooser::closeColorChooserIfClientIsInDocument(Document* document)
+{
+    if (m_client)
+        m_client->closeColorChooserIfClientIsInDocument(document);
+}
+
+void ColorChooser::colorSelected(const Color& color) const
+{
+    if (m_client)
+        m_client->colorSelected(color);
+}
+
+}
+
+#endif // ENABLE(INPUT_COLOR)
diff --git a/Source/WebCore/platform/ColorChooser.h b/Source/WebCore/platform/ColorChooser.h
new file mode 100644 (file)
index 0000000..e1ec5f1
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef ColorChooser_h
+#define ColorChooser_h
+
+#include "Color.h"
+#include "Document.h"
+
+#if ENABLE(INPUT_COLOR)
+
+namespace WebCore {
+
+class ColorChooser;
+
+class ColorChooserClient {
+public:
+    virtual ~ColorChooserClient();
+    virtual void colorSelected(const Color&) = 0;
+    virtual void closeColorChooserIfClientIsInDocument(Document*) = 0;
+};
+
+class ColorChooser {
+public:
+    static ColorChooser* chooser();
+
+    ColorChooserClient* client() const { return m_client; };
+    void connectClient(ColorChooserClient*);
+    void disconnectClient(ColorChooserClient*);
+    void closeColorChooserIfClientIsInDocument(Document*);
+
+    void colorSelected(const Color&) const;
+
+private:
+    ColorChooser()
+        : m_client(0)
+    { }
+
+    ColorChooserClient* m_client;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(INPUT_COLOR)
+
+#endif // ColorChooser_h