Source/WebCore/ChangeLog

112011-08-05 Keishi Hattori <keishi@webkit.org>
22
 3 Implement <input type=color> UI behavior WebCore part
 4 https://bugs.webkit.org/show_bug.cgi?id=62619
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * WebCore.exp.in: Added __ZN7WebCore12ColorChooser7chooserEv and
 9 __ZNK7WebCore12ColorChooser13colorSelectedERKNS_5ColorE
 10 * WebCore.xcodeproj/project.pbxproj: Added ColorChooser.{h,cpp}
 11 * html/ColorInputType.cpp:
 12 (WebCore::ColorInputType::~ColorInputType): Added. Close color chooser. ex. when type attribute changes.
 13 (WebCore::ColorInputType::valueAsColor): Added.
 14 (WebCore::ColorInputType::setValueAsColor): Added.
 15 (WebCore::ColorInputType::valueChanged): Update selected color in color chooser too.
 16 (WebCore::ColorInputType::handleClickEvent): Opens color chooser.
 17 (WebCore::ColorInputType::handleDOMActivateEvent): Called when element.click(). Open color chooser only
 18 when it was initiated by a user interaction.
 19 (WebCore::ColorInputType::detach): Close color chooser. Called when input element or its ancestors have "display:none"
 20 or is removed from DOM.
 21 (WebCore::ColorInputType::colorSelected): Callback from color chooser.
 22 (WebCore::ColorInputType::closeColorChooserIfClientIsInDocument): Close color chooser if element is in
 23 document. Called when the page navigates away.
 24 (WebCore::ColorInputType::closeColorChooserIfCurrentClient): Close color chooser if this input type is the current client of ColorChooser.
 25 * html/ColorInputType.h:
 26 * html/FileInputType.cpp:
 27 * html/FileInputType.h:
 28 * html/HTMLInputElement.cpp:
 29 (WebCore::HTMLInputElement::detach): Calls InputType::detach
 30 * html/InputType.cpp:
 31 (WebCore::InputType::chrome): Added. Used in FileInputType and ColorInputType.
 32 (WebCore::InputType::detach): ColorInputType overrides this.
 33 * html/InputType.h:
 34 * loader/EmptyClients.h:
 35 (WebCore::EmptyChromeClient::openColorChooser): Added.
 36 (WebCore::EmptyChromeClient::closeColorChooser): Added.
 37 (WebCore::EmptyChromeClient::setSelectedColorInColorChooser): Added.
 38 * loader/FrameLoader.cpp:
 39 (WebCore::FrameLoader::transitionToCommitted): Close color chooser when
 40 navigating away from the page.
 41 * page/Chrome.cpp:
 42 (WebCore::Chrome::openColorChooser): Added. Opens the color chooser.
 43 (WebCore::Chrome::closeColorChooser): Added. Tries to close the color chooser. Might not close if the
 44 listener of the color chooser is another part of the browser or another render process.
 45 (WebCore::Chrome::setSelectedColorInColorChooser): Added. Sets the selected color in the color chooser.
 46 Again, might not be executed if the listener of the color chooser is another part of the browser or another render process.
 47 * page/Chrome.h:
 48 * page/ChromeClient.h:
 49 * platform/ColorChooser.cpp: Added.
 50 (WebCore::ColorChooserClient::~ColorChooserClient): Disconnects itself from the ColorChooser.
 51 (WebCore::ColorChooser::chooser): Get shared instance of ColorChooser.
 52 (WebCore::ColorChooser::chooser): Get shared instance of ColorChooser.
 53 (WebCore::ColorChooser::connectClient): Connects a ColorChooserClient that receives the colorSelected callbacks.
 54 (WebCore::ColorChooser::disconnectClient): Disconnects the connectClient.
 55 (WebCore::ColorChooser::closeColorChooserIfClientIsInDocument): Close the color chooser if the client is
 56 inside the document.
 57 (WebCore::ColorChooser::colorSelected): Called from color chooser listener.
 58 * platform/ColorChooser.h: Added.
 59 (WebCore::ColorChooser::client): Added. Returns the current connected client.
 60 (WebCore::ColorChooser::ColorChooser): Added.
 61
 622011-08-05 Keishi Hattori <keishi@webkit.org>
 63
364 Sort WebCore.xcodeproj
465 Accomplished using sort-Xcode-project-file.
566

Source/WebCore/WebCore.exp.in

@@__ZNK7WebCore13ResourceErrorcvP7NSErrorEv
19451945__ZN7WebCore12SchedulePairC1EP9NSRunLoopPK10__CFString
19461946__ZN7WebCore14ResourceHandle12releaseProxyEv
19471947#endif
 1948
 1949#if ENABLE(INPUT_COLOR)
 1950__ZN7WebCore12ColorChooser7chooserEv
 1951__ZNK7WebCore12ColorChooser13colorSelectedERKNS_5ColorE
 1952#endif

Source/WebCore/WebCore.xcodeproj/project.pbxproj

53335333 C0F2A44113869AAB0066C534 /* preprocessor.pm in Headers */ = {isa = PBXBuildFile; fileRef = C0F2A43F13869A280066C534 /* preprocessor.pm */; settings = {ATTRIBUTES = (Private, ); }; };
53345334 C105DA620F3AA68F001DD44F /* TextEncodingDetectorICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */; };
53355335 C105DA640F3AA6B8001DD44F /* TextEncodingDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */; };
 5336 C330A22213EC196B0000B45B /* ColorChooser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C330A22013EC196B0000B45B /* ColorChooser.cpp */; };
 5337 C330A22313EC196B0000B45B /* ColorChooser.h in Headers */ = {isa = PBXBuildFile; fileRef = C330A22113EC196B0000B45B /* ColorChooser.h */; settings = {ATTRIBUTES = (Private, ); }; };
53365338 C50B561612119D23008B46E0 /* GroupSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C50B561412119D23008B46E0 /* GroupSettings.cpp */; };
53375339 C50B561712119D23008B46E0 /* GroupSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = C50B561512119D23008B46E0 /* GroupSettings.h */; settings = {ATTRIBUTES = (Private, ); }; };
53385340 C50D0E820FF4272900AC2644 /* StorageNamespace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C50D0E800FF4272900AC2644 /* StorageNamespace.cpp */; };

1204112043 C0F2A43F13869A280066C534 /* preprocessor.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = preprocessor.pm; path = scripts/preprocessor.pm; sourceTree = "<group>"; };
1204212044 C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEncodingDetectorICU.cpp; sourceTree = "<group>"; };
1204312045 C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEncodingDetector.h; sourceTree = "<group>"; };
 12046 C330A22013EC196B0000B45B /* ColorChooser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorChooser.cpp; sourceTree = "<group>"; };
 12047 C330A22113EC196B0000B45B /* ColorChooser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorChooser.h; sourceTree = "<group>"; };
1204412048 C50B561412119D23008B46E0 /* GroupSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GroupSettings.cpp; sourceTree = "<group>"; };
1204512049 C50B561512119D23008B46E0 /* GroupSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupSettings.h; sourceTree = "<group>"; };
1204612050 C50D0E800FF4272900AC2644 /* StorageNamespace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageNamespace.cpp; sourceTree = "<group>"; };

1903219036 89D08D9D12228451001241DF /* AsyncFileSystem.h */,
1903319037 89D08D9E12228451001241DF /* AsyncFileSystemCallbacks.h */,
1903419038 51E1ECB10C91C55600DC255B /* AutodrainedPool.h */,
 19039 C330A22013EC196B0000B45B /* ColorChooser.cpp */,
 19040 C330A22113EC196B0000B45B /* ColorChooser.h */,
1903519041 BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
1903619042 41D015C90F4B5C71004A662F /* ContentType.cpp */,
1903719043 41D015C80F4B5C71004A662F /* ContentType.h */,

2052820534 93C441F00F813A1A00C1A634 /* CollectionCache.h in Headers */,
2052920535 93C442000F813AE100C1A634 /* CollectionType.h in Headers */,
2053020536 B27535670B053814002CE64F /* Color.h in Headers */,
 20537 C330A22313EC196B0000B45B /* ColorChooser.h in Headers */,
2053120538 B22279630D00BF220071B782 /* ColorDistance.h in Headers */,
2053220539 F55B3DB41251F12D003EF269 /* ColorInputType.h in Headers */,
2053320540 EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */,

2381623823 93C441EF0F813A1A00C1A634 /* CollectionCache.cpp in Sources */,
2381723824 B27535660B053814002CE64F /* Color.cpp in Sources */,
2381823825 0FCF33240F2B9715004B6795 /* ColorCG.cpp in Sources */,
 23826 C330A22213EC196B0000B45B /* ColorChooser.cpp in Sources */,
2381923827 1ABA76C911D20E47004C201C /* ColorData.cpp in Sources */,
2382023828 B22279620D00BF220071B782 /* ColorDistance.cpp in Sources */,
2382123829 F55B3DB31251F12D003EF269 /* ColorInputType.cpp in Sources */,

Source/WebCore/html/ColorInputType.cpp

3131#include "config.h"
3232#include "ColorInputType.h"
3333
 34#include "Chrome.h"
3435#include "Color.h"
3536#include "HTMLDivElement.h"
3637#include "HTMLInputElement.h"
 38#include "MouseEvent.h"
 39#include "ScriptController.h"
3740#include "ShadowRoot.h"
3841#include <wtf/PassOwnPtr.h>
3942#include <wtf/text/WTFString.h>

@@PassOwnPtr<InputType> ColorInputType::create(HTMLInputElement* element)
6164 return adoptPtr(new ColorInputType(element));
6265}
6366
 67ColorInputType::~ColorInputType()
 68{
 69 closeColorChooserIfCurrentClient();
 70}
 71
6472bool ColorInputType::isColorControl() const
6573{
6674 return true;

@@String ColorInputType::sanitizeValue(const String& proposedValue)
92100 return proposedValue.lower();
93101}
94102
 103Color ColorInputType::valueAsColor() const
 104{
 105 return Color(element()->value());
 106}
 107
 108void ColorInputType::setValueAsColor(const Color& color) const
 109{
 110 element()->setValue(color.serialized(), true);
 111}
 112
95113void ColorInputType::createShadowSubtree()
96114{
97115 Document* document = element()->document();

@@void ColorInputType::createShadowSubtree()
111129void ColorInputType::valueChanged()
112130{
113131 updateColorSwatch();
 132 if (ColorChooser::chooser()->client() == this) {
 133 if (Chrome* chrome = this->chrome())
 134 chrome->setSelectedColorInColorChooser(valueAsColor());
 135 }
 136}
 137
 138void ColorInputType::handleClickEvent(MouseEvent* event)
 139{
 140 if (event->isSimulated())
 141 return;
 142
 143 if (element()->disabled() || element()->readOnly())
 144 return;
 145
 146 if (Chrome* chrome = this->chrome()) {
 147 ColorChooser::chooser()->connectClient(this);
 148 chrome->openColorChooser(ColorChooser::chooser(), valueAsColor());
 149 }
 150 event->setDefaultHandled();
 151}
 152
 153void ColorInputType::handleDOMActivateEvent(Event* event)
 154{
 155 if (element()->disabled() || element()->readOnly() || !element()->renderer())
 156 return;
 157
 158 if (!ScriptController::processingUserGesture())
 159 return;
 160
 161 if (Chrome* chrome = this->chrome()) {
 162 ColorChooser::chooser()->connectClient(this);
 163 chrome->openColorChooser(ColorChooser::chooser(), valueAsColor());
 164 }
 165 event->setDefaultHandled();
 166}
 167
 168void ColorInputType::detach()
 169{
 170 closeColorChooserIfCurrentClient();
 171}
 172
 173void ColorInputType::colorSelected(const Color& color)
 174{
 175 if (element()->disabled() || element()->readOnly())
 176 return;
 177 setValueAsColor(color);
 178}
 179
 180void ColorInputType::closeColorChooserIfClientIsInDocument(Document* document)
 181{
 182 if (element()->document() == document)
 183 closeColorChooserIfCurrentClient();
114184}
115185
116186void ColorInputType::updateColorSwatch()

@@HTMLElement* ColorInputType::shadowColorSwatch() const
129199 return shadow ? toHTMLElement(shadow->firstChild()->firstChild()) : 0;
130200}
131201
 202void ColorInputType::closeColorChooserIfCurrentClient()
 203{
 204 if (ColorChooser::chooser()->client() == this) {
 205 if (Chrome* chrome = this->chrome())
 206 chrome->closeColorChooser();
 207 }
 208}
 209
132210} // namespace WebCore
133211
134212#endif // ENABLE(INPUT_COLOR)

Source/WebCore/html/ColorInputType.h

3131#ifndef ColorInputType_h
3232#define ColorInputType_h
3333
34 #include "BaseButtonInputType.h"
 34#include "ColorChooser.h"
 35#include "InputType.h"
3536
3637#if ENABLE(INPUT_COLOR)
3738
3839namespace WebCore {
3940
40 class ColorInputType : public InputType {
 41class ColorInputType : public InputType, private ColorChooserClient {
4142public:
4243 static PassOwnPtr<InputType> create(HTMLInputElement*);
4344
4445private:
4546 ColorInputType(HTMLInputElement* element) : InputType(element) { }
 47 virtual ~ColorInputType();
4648 virtual bool isColorControl() const;
4749 virtual const AtomicString& formControlType() const;
4850 virtual bool supportsRequired() const;
4951 virtual String fallbackValue();
5052 virtual String sanitizeValue(const String&);
 53 virtual Color valueAsColor() const;
 54 virtual void setValueAsColor(const Color&) const;
5155 virtual void createShadowSubtree();
5256 virtual void valueChanged();
 57 virtual void handleClickEvent(MouseEvent*);
 58 virtual void handleDOMActivateEvent(Event*);
 59 virtual void detach();
 60
 61 // ColorChooserClient implementation.
 62 virtual void colorSelected(const Color&);
 63 virtual void closeColorChooserIfClientIsInDocument(Document*);
5364
5465 void updateColorSwatch();
5566 HTMLElement* shadowColorSwatch() const;
 67 void closeColorChooserIfCurrentClient() const;
5668};
5769
5870} // namespace WebCore

Source/WebCore/html/FileInputType.cpp

3333#include "HTMLNames.h"
3434#include "Icon.h"
3535#include "LocalizedStrings.h"
36 #include "Page.h"
3736#include "RenderFileUploadControl.h"
3837#include "ScriptController.h"
3938#include "ShadowRoot.h"

@@void FileInputType::updateRendering(PassRefPtr<Icon> icon)
333332 element()->renderer()->repaint();
334333}
335334
336 Chrome* FileInputType::chrome() const
337 {
338  if (Page* page = element()->document()->page())
339  return page->chrome();
340  return 0;
341 }
342 
343335void FileInputType::receiveDroppedFiles(const Vector<String>& paths)
344336{
345337 HTMLInputElement* input = element();

Source/WebCore/html/FileInputType.h

3939
4040namespace WebCore {
4141
42 class Chrome;
4342class FileList;
4443
4544class FileInputType : public BaseButtonInputType, private FileChooserClient, private FileIconLoaderClient {

@@private:
7776 void receiveDropForDirectoryUpload(const Vector<String>&);
7877#endif
7978 void requestIcon(const Vector<String>&);
80  Chrome* chrome() const;
8179
8280 RefPtr<FileList> m_fileList;
8381 RefPtr<Icon> m_icon;

Source/WebCore/html/HTMLInputElement.cpp

@@void HTMLInputElement::detach()
880880{
881881 HTMLTextFormControlElement::detach();
882882 setFormControlValueMatchesRenderer(false);
 883 m_inputType->detach();
883884}
884885
885886String HTMLInputElement::altText() const

Source/WebCore/html/InputType.cpp

4848#include "LocalizedStrings.h"
4949#include "MonthInputType.h"
5050#include "NumberInputType.h"
 51#include "Page.h"
5152#include "PasswordInputType.h"
5253#include "RadioInputType.h"
5354#include "RangeInputType.h"

@@void InputType::dispatchSimulatedClickIfActive(KeyboardEvent* event) const
395396 event->setDefaultHandled();
396397}
397398
 399Chrome* InputType::chrome() const
 400{
 401 if (Page* page = element()->document()->page())
 402 return page->chrome();
 403 return 0;
 404}
 405
398406bool InputType::canSetStringValue() const
399407{
400408 return true;

@@void InputType::attach()
423431{
424432}
425433
 434void InputType::detach()
 435{
 436}
 437
426438void InputType::altAttributeChanged()
427439{
428440}

Source/WebCore/html/InputType.h

4141namespace WebCore {
4242
4343class BeforeTextInsertedEvent;
 44class Chrome;
 45class Color;
4446class DateComponents;
4547class Event;
4648class FileList;

@@public:
9193
9294#if ENABLE(INPUT_COLOR)
9395 virtual bool isColorControl() const;
94 #endif // ENABLE(INPUT_COLOR)
 96#endif
9597 virtual bool isCheckbox() const;
9698 virtual bool isEmailField() const;
9799 virtual bool isFileUpload() const;

@@public:
205207 virtual bool rendererIsNeeded();
206208 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
207209 virtual void attach();
 210 virtual void detach();
208211 virtual void minOrMaxAttributeChanged();
209212 virtual void altAttributeChanged();
210213 virtual void srcAttributeChanged();

@@protected:
260263 void dispatchSimulatedClickIfActive(KeyboardEvent*) const;
261264 // We can't make this a static const data member because VC++ doesn't like it.
262265 static double defaultStepBase() { return 0.0; }
 266 Chrome* chrome() const;
263267
264268private:
265269 // Raw pointer because the HTMLInputElement object owns this InputType object.

Source/WebCore/loader/EmptyClients.h

@@public:
196196 virtual void enumerateChosenDirectory(FileChooser*) { }
197197#endif
198198
 199#if ENABLE(INPUT_COLOR)
 200 void openColorChooser(ColorChooser*, const Color&) { }
 201 void closeColorChooser() { }
 202 void setSelectedColorInColorChooser(const Color&) { }
 203#endif
 204
199205 virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) { }
200206 virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*) { }
201207

Source/WebCore/loader/FrameLoader.cpp

100100#include <wtf/text/CString.h>
101101#include <wtf/text/WTFString.h>
102102
 103#if ENABLE(INPUT_COLOR)
 104#include "ColorChooser.h"
 105#endif
 106
103107#if ENABLE(SHARED_WORKERS)
104108#include "SharedWorkerRepository.h"
105109#endif

@@void FrameLoader::transitionToCommitted(PassRefPtr<CachedPage> cachedPage)
18161820 if (m_frame->view())
18171821 m_frame->view()->scrollAnimator()->cancelAnimations();
18181822
 1823#if ENABLE(INPUT_COLOR)
 1824 if (m_frame->document())
 1825 ColorChooser::chooser()->closeColorChooserIfClientIsInDocument(m_frame->document());
 1826#endif
 1827
18191828 m_client->setCopiesOnScroll();
18201829 history()->updateForCommit();
18211830

Source/WebCore/page/Chrome.cpp

5252#include "StorageNamespace.h"
5353#endif
5454
 55#if ENABLE(INPUT_COLOR)
 56#include "ColorChooser.h"
 57#endif
 58
5559namespace WebCore {
5660
5761using namespace HTMLNames;

@@void Chrome::enumerateChosenDirectory(FileChooser* fileChooser)
467471}
468472#endif
469473
 474#if ENABLE(INPUT_COLOR)
 475void Chrome::openColorChooser(ColorChooser* colorChooser, const Color& initialColor)
 476{
 477 m_client->openColorChooser(colorChooser, initialColor);
 478}
 479
 480void Chrome::closeColorChooser()
 481{
 482 m_client->closeColorChooser();
 483}
 484
 485void Chrome::setSelectedColorInColorChooser(const Color& color)
 486{
 487 m_client->setSelectedColorInColorChooser(color);
 488}
 489#endif
 490
470491void Chrome::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> fileChooser)
471492{
472493 m_client->runOpenPanel(frame, fileChooser);

Source/WebCore/page/Chrome.h

@@class NSView;
3636namespace WebCore {
3737
3838 class ChromeClient;
 39#if ENABLE(INPUT_COLOR)
 40 class ColorChooser;
 41#endif
3942 class FileChooser;
4043 class FileIconLoader;
4144 class FloatRect;

@@namespace WebCore {
154157 void requestGeolocationPermissionForFrame(Frame*, Geolocation*);
155158 void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*);
156159
 160#if ENABLE(INPUT_COLOR)
 161 void openColorChooser(ColorChooser*, const Color&);
 162 void closeColorChooser();
 163 void setSelectedColorInColorChooser(const Color&);
 164#endif
 165
157166 void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
158167 void loadIconForFiles(const Vector<String>&, FileIconLoader*);
159168#if ENABLE(DIRECTORY_UPLOAD)

Source/WebCore/page/ChromeClient.h

@@namespace WebCore {
7171 class GraphicsLayer;
7272#endif
7373
 74#if ENABLE(INPUT_COLOR)
 75 class ColorChooser;
 76#endif
 77
7478#if ENABLE(NOTIFICATIONS)
7579 class NotificationPresenter;
7680#endif

@@namespace WebCore {
231235 virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*) = 0;
232236 virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*) = 0;
233237
 238#if ENABLE(INPUT_COLOR)
 239 virtual void openColorChooser(ColorChooser*, const Color&) = 0;
 240 virtual void closeColorChooser() = 0;
 241 virtual void setSelectedColorInColorChooser(const Color&) = 0;
 242#endif
 243
234244 virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0;
235245 // Asynchronous request to load an icon for specified filenames.
236246 virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*) = 0;

Source/WebCore/platform/ColorChooser.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 14 * its contributors may be used to endorse or promote products derived
 15 * from this software without specific prior written permission.
 16 *
 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 *
 28 */
 29
 30#include "config.h"
 31#include "ColorChooser.h"
 32
 33#if ENABLE(INPUT_COLOR)
 34
 35namespace WebCore {
 36
 37ColorChooserClient::~ColorChooserClient()
 38{
 39 ColorChooser::chooser()->disconnectClient(this);
 40}
 41
 42static ColorChooser* staticChooser = 0;
 43
 44ColorChooser* ColorChooser::chooser()
 45{
 46 if (!staticChooser)
 47 staticChooser = new ColorChooser();
 48 return staticChooser;
 49}
 50
 51void ColorChooser::connectClient(ColorChooserClient* client)
 52{
 53 if (client != m_client)
 54 m_client = client;
 55}
 56
 57void ColorChooser::disconnectClient(ColorChooserClient* client)
 58{
 59 if (client == m_client)
 60 m_client = 0;
 61}
 62
 63void ColorChooser::closeColorChooserIfClientIsInDocument(Document* document)
 64{
 65 if (m_client)
 66 m_client->closeColorChooserIfClientIsInDocument(document);
 67}
 68
 69void ColorChooser::colorSelected(const Color& color) const
 70{
 71 if (m_client)
 72 m_client->colorSelected(color);
 73}
 74
 75}
 76
 77#endif // ENABLE(INPUT_COLOR)

Source/WebCore/platform/ColorChooser.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 14 * its contributors may be used to endorse or promote products derived
 15 * from this software without specific prior written permission.
 16 *
 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 *
 28 */
 29
 30#ifndef ColorChooser_h
 31#define ColorChooser_h
 32
 33#include "Color.h"
 34#include "Document.h"
 35
 36#if ENABLE(INPUT_COLOR)
 37
 38namespace WebCore {
 39
 40class ColorChooser;
 41
 42class ColorChooserClient {
 43public:
 44 virtual ~ColorChooserClient();
 45 virtual void colorSelected(const Color&) = 0;
 46 virtual void closeColorChooserIfClientIsInDocument(Document*) = 0;
 47};
 48
 49class ColorChooser {
 50public:
 51 static ColorChooser* chooser();
 52
 53 ColorChooserClient* client() const { return m_client; };
 54 void connectClient(ColorChooserClient*);
 55 void disconnectClient(ColorChooserClient*);
 56 void closeColorChooserIfClientIsInDocument(Document*);
 57
 58 void colorSelected(const Color&) const;
 59
 60private:
 61 ColorChooser()
 62 : m_client(0)
 63 { }
 64
 65 ColorChooserClient* m_client;
 66};
 67
 68} // namespace WebCore
 69
 70#endif // ENABLE(INPUT_COLOR)
 71
 72#endif // ColorChooser_h