⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 99403 in webkit


Ignore:
Timestamp:
Nov 7, 2011, 3:39:32 AM (15 years ago)
Author:
keishi@webkit.org
Message:

Change ColorChooser from singleton to ordinary object
https://bugs.webkit.org/show_bug.cgi?id=71644

Reviewed by Kent Tamura.

Source/WebCore:

Changing WebCore::ColorChooser from a singleton to an ordinary object can broaden how browsers implement the color chooser interface.

  • WebCore.exp.in:
  • html/ColorInputType.cpp:

(WebCore::ColorInputType::~ColorInputType):
(WebCore::ColorInputType::setValue): If a chooser exists, calls Chrome::setSelectedColorInColorChooser
(WebCore::ColorInputType::handleDOMActivateEvent):
(WebCore::ColorInputType::detach):
(WebCore::ColorInputType::didCleanup): Called after cleanup is complete.
(WebCore::ColorInputType::cleanupColorChooser): Renamed from cleanupColorChooserIfCurrentClient.

  • html/ColorInputType.h:
  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::selectColorInColorChooser):

  • html/HTMLInputElement.h:
  • loader/EmptyClients.h:

(WebCore::EmptyChromeClient::cleanupColorChooser): Added colorChooser argument because there are many WebCore::ColorChoosers now.
(WebCore::EmptyChromeClient::setSelectedColorInColorChooser): Ditto.

  • page/Chrome.cpp:

(WebCore::Chrome::cleanupColorChooser): Added colorChooser argument because there are many WebCore::ColorChoosers now.
(WebCore::Chrome::setSelectedColorInColorChooser): Ditto.

  • page/Chrome.h:
  • page/ChromeClient.h:
  • platform/ColorChooser.cpp:

(WebCore::ColorChooserClient::~ColorChooserClient):
(WebCore::ColorChooserClient::newColorChooser): Creates a new color chooser that is connected to itself.
(WebCore::ColorChooserClient::discardChooser): Discards the connected color chooser.
(WebCore::ColorChooser::ColorChooser): ColorChooser is RefCounted.
(WebCore::ColorChooser::create): Creates a ColorChooser that is connected to the given ColorChooserClient.
(WebCore::ColorChooser::~ColorChooser):
(WebCore::ColorChooser::didChooseColor): Called from WebKit side when user chose a color. Calls ColorChooserClient::didChooseColor
(WebCore::ColorChooser::didCleanup): Called from WebKit side when user color chooser was cleaned up. Calls ColorChooserClient::didCleanup

  • platform/ColorChooser.h:

(WebCore::ColorChooserClient::chooser): Returns the current ColorChooser.
(WebCore::ColorChooser::disconnectClient): Disconnects the ColorChooserClient.

  • testing/Internals.cpp:

(WebCore::Internals::selectColorInColorChooser): Added element argument. This calls didChooseColor on the ColorChooser of that element.

  • testing/Internals.h:
  • testing/Internals.idl: Removed connectColorChooserClient and updated selectColorInColorChooser.

LayoutTests:

  • fast/forms/color/input-color-onchange-event.html: Changed to match the changes to window.internals object
Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r99402 r99403  
     12011-11-07  Keishi Hattori  <keishi@webkit.org>
     2
     3        Change ColorChooser from singleton to ordinary object
     4        https://bugs.webkit.org/show_bug.cgi?id=71644
     5
     6        Reviewed by Kent Tamura.
     7
     8        * fast/forms/color/input-color-onchange-event.html: Changed to match the changes to window.internals object
     9
    1102011-11-07  Alexander Pavlov  <apavlov@chromium.org>
    211
  • trunk/LayoutTests/fast/forms/color/input-color-onchange-event.html

    r97881 r99403  
    88<div id="console"></div>
    99<script>
    10 description('Test if change event fires properly when color chooser changes. Bug 66848');
     10description('Test if change event fires properly when color chooser changes. Bug 66848 <br> To manually test this, click on the input color element in the top left corner and change the value from the color chooser. See if the number of "value changed" messages matches the number of times you changed the color.');
    1111
    1212var input = document.createElement('input');
    1313input.type = 'color';
    1414input.value = '#000000';
     15document.body.appendChild(input);
     16
     17input.style.position = 'absolute';
     18input.style.left = '0';
     19input.style.top = '0';
     20input.style.width = '20px';
     21input.style.height = '20px';
     22
    1523input.onchange = function() {
    1624    debug("value changed to " + input.value);
    17     finishJSTest();
    1825};
    19 if (!internals.connectColorChooserClient(input))
    20     testFailed("Could not connect ColorChooserClient.");
    21 internals.selectColorInColorChooser('#ff0000');
     26
     27eventSender.mouseMoveTo(10, 10);
     28eventSender.mouseDown();
     29eventSender.mouseUp();
     30
    2231// input.onchange should be called
    23 internals.selectColorInColorChooser('#ff0000');
     32internals.selectColorInColorChooser(input, '#ff0000');
    2433// input.onchange should not be called
     34internals.selectColorInColorChooser(input, '#ff0000');
     35
    2536shouldBe('input.value', '"#ff0000"');
    2637</script>
  • trunk/Source/WebCore/ChangeLog

    r99401 r99403  
     12011-11-07  Keishi Hattori  <keishi@webkit.org>
     2
     3        Change ColorChooser from singleton to ordinary object
     4        https://bugs.webkit.org/show_bug.cgi?id=71644
     5
     6        Reviewed by Kent Tamura.
     7
     8        Changing WebCore::ColorChooser from a singleton to an ordinary object can broaden how browsers implement the color chooser interface.
     9
     10        * WebCore.exp.in:
     11        * html/ColorInputType.cpp:
     12        (WebCore::ColorInputType::~ColorInputType):
     13        (WebCore::ColorInputType::setValue): If a chooser exists, calls Chrome::setSelectedColorInColorChooser
     14        (WebCore::ColorInputType::handleDOMActivateEvent):
     15        (WebCore::ColorInputType::detach):
     16        (WebCore::ColorInputType::didCleanup): Called after cleanup is complete.
     17        (WebCore::ColorInputType::cleanupColorChooser): Renamed from cleanupColorChooserIfCurrentClient.
     18        * html/ColorInputType.h:
     19        * html/HTMLInputElement.cpp:
     20        (WebCore::HTMLInputElement::selectColorInColorChooser):
     21        * html/HTMLInputElement.h:
     22        * loader/EmptyClients.h:
     23        (WebCore::EmptyChromeClient::cleanupColorChooser): Added colorChooser argument because there are many WebCore::ColorChoosers now.
     24        (WebCore::EmptyChromeClient::setSelectedColorInColorChooser): Ditto.
     25        * page/Chrome.cpp:
     26        (WebCore::Chrome::cleanupColorChooser): Added colorChooser argument because there are many WebCore::ColorChoosers now.
     27        (WebCore::Chrome::setSelectedColorInColorChooser): Ditto.
     28        * page/Chrome.h:
     29        * page/ChromeClient.h:
     30        * platform/ColorChooser.cpp:
     31        (WebCore::ColorChooserClient::~ColorChooserClient):
     32        (WebCore::ColorChooserClient::newColorChooser): Creates a new color chooser that is connected to itself.
     33        (WebCore::ColorChooserClient::discardChooser): Discards the connected color chooser.
     34        (WebCore::ColorChooser::ColorChooser): ColorChooser is RefCounted.
     35        (WebCore::ColorChooser::create): Creates a ColorChooser that is connected to the given ColorChooserClient.
     36        (WebCore::ColorChooser::~ColorChooser):
     37        (WebCore::ColorChooser::didChooseColor): Called from WebKit side when user chose a color. Calls ColorChooserClient::didChooseColor
     38        (WebCore::ColorChooser::didCleanup): Called from WebKit side when user color chooser was cleaned up. Calls ColorChooserClient::didCleanup
     39        * platform/ColorChooser.h:
     40        (WebCore::ColorChooserClient::chooser): Returns the current ColorChooser.
     41        (WebCore::ColorChooser::disconnectClient): Disconnects the ColorChooserClient.
     42        * testing/Internals.cpp:
     43        (WebCore::Internals::selectColorInColorChooser): Added element argument. This calls didChooseColor on the ColorChooser of that element.
     44        * testing/Internals.h:
     45        * testing/Internals.idl: Removed connectColorChooserClient and updated selectColorInColorChooser.
     46
    1472011-11-07  Alexander Pavlov  <apavlov@chromium.org>
    248
  • trunk/Source/WebCore/WebCore.exp.in

    r99347 r99403  
    19801980
    19811981#if ENABLE(INPUT_COLOR)
    1982 __ZN7WebCore12ColorChooser7chooserEv
    1983 __ZNK7WebCore12ColorChooser13didChooseColorERKNS_5ColorE
    19841982__ZN7WebCore5ColorC1ERKN3WTF6StringE
    1985 __ZN7WebCore16HTMLInputElement21connectToColorChooserEv
     1983__ZN7WebCore16HTMLInputElement25selectColorInColorChooserERKNS_5ColorE
    19861984#endif
    19871985
  • trunk/Source/WebCore/html/ColorInputType.cpp

    r99395 r99403  
    6767ColorInputType::~ColorInputType()
    6868{
    69     cleanupColorChooserIfCurrentClient();
     69    cleanupColorChooser();
    7070}
    7171
     
    127127
    128128    updateColorSwatch();
    129     if (ColorChooser::chooser()->client() == this) {
    130         if (Chrome* chrome = this->chrome())
    131             chrome->setSelectedColorInColorChooser(valueAsColor());
    132     }
     129    Chrome* chrome = this->chrome();
     130    if (chrome && chooser())
     131        chrome->setSelectedColorInColorChooser(chooser(), valueAsColor());
    133132}
    134133
     
    141140        return;
    142141
    143     if (Chrome* chrome = this->chrome()) {
    144         ColorChooser::chooser()->connectClient(this);
    145         chrome->openColorChooser(ColorChooser::chooser(), valueAsColor());
    146     }
     142    if (Chrome* chrome = this->chrome())
     143        chrome->openColorChooser(newColorChooser(), valueAsColor());
    147144    event->setDefaultHandled();
    148145}
     
    150147void ColorInputType::detach()
    151148{
    152     cleanupColorChooserIfCurrentClient();
     149    cleanupColorChooser();
    153150}
    154151
     
    162159}
    163160
    164 bool ColorInputType::isColorInputType() const
     161void ColorInputType::didCleanup()
    165162{
    166     return true;
     163    discardChooser();
    167164}
    168165
    169 void ColorInputType::cleanupColorChooserIfCurrentClient() const
     166void ColorInputType::cleanupColorChooser()
    170167{
    171     if (ColorChooser::chooser()->client() != this)
    172         return;
    173     if (Chrome* chrome = this->chrome())
    174         chrome->cleanupColorChooser();
     168    Chrome* chrome = this->chrome();
     169    if (chrome && chooser())
     170        chrome->cleanupColorChooser(chooser());
     171    discardChooser();
    175172}
    176173
  • trunk/Source/WebCore/html/ColorInputType.h

    r99395 r99403  
    5858
    5959    // ColorChooserClient implementation.
    60     virtual void didChooseColor(const Color&);
    61     virtual bool isColorInputType() const;
     60    virtual void didChooseColor(const Color&) OVERRIDE;
     61    virtual void didCleanup() OVERRIDE;
    6262
    63     void cleanupColorChooserIfCurrentClient() const;
     63    void cleanupColorChooser();
    6464    void updateColorSwatch();
    6565    HTMLElement* shadowColorSwatch() const;
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r99369 r99403  
    15381538
    15391539#if ENABLE(INPUT_COLOR)
    1540 bool HTMLInputElement::connectToColorChooser()
     1540void HTMLInputElement::selectColorInColorChooser(const Color& color)
    15411541{
    15421542    if (!m_inputType->isColorControl())
    1543         return false;
    1544     ColorChooser::chooser()->connectClient(static_cast<ColorInputType*>(m_inputType.get()));
    1545     return true;
     1543        return;
     1544    RefPtr<ColorChooser> chooser = static_cast<ColorInputType*>(m_inputType.get())->chooser();
     1545    if (!chooser)
     1546        return;
     1547    chooser->didChooseColor(color);
    15461548}
    15471549#endif
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r99369 r99403  
    234234#if ENABLE(INPUT_COLOR)
    235235    // For test purposes.
    236     bool connectToColorChooser();
     236    void selectColorInColorChooser(const Color&);
    237237#endif
    238238
  • trunk/Source/WebCore/loader/EmptyClients.h

    r99096 r99403  
    198198#if ENABLE(INPUT_COLOR)
    199199    void openColorChooser(ColorChooser*, const Color&) { }
    200     void cleanupColorChooser() { }
    201     void setSelectedColorInColorChooser(const Color&) { }
     200    void cleanupColorChooser(ColorChooser*) { }
     201    void setSelectedColorInColorChooser(ColorChooser*, const Color&) { }
    202202#endif
    203203
  • trunk/Source/WebCore/page/Chrome.cpp

    r98472 r99403  
    464464}
    465465
    466 void Chrome::cleanupColorChooser()
    467 {
    468     m_client->cleanupColorChooser();
    469 }
    470 
    471 void Chrome::setSelectedColorInColorChooser(const Color& color)
    472 {
    473     m_client->setSelectedColorInColorChooser(color);
     466void Chrome::cleanupColorChooser(ColorChooser* colorChooser)
     467{
     468    m_client->cleanupColorChooser(colorChooser);
     469}
     470
     471void Chrome::setSelectedColorInColorChooser(ColorChooser* colorChooser, const Color& color)
     472{
     473    m_client->setSelectedColorInColorChooser(colorChooser, color);
    474474}
    475475#endif
  • trunk/Source/WebCore/page/Chrome.h

    r98472 r99403  
    158158#if ENABLE(INPUT_COLOR)
    159159        void openColorChooser(ColorChooser*, const Color&);
    160         void cleanupColorChooser();
    161         void setSelectedColorInColorChooser(const Color&);
     160        void cleanupColorChooser(ColorChooser*);
     161        void setSelectedColorInColorChooser(ColorChooser*, const Color&);
    162162#endif
    163163
  • trunk/Source/WebCore/page/ChromeClient.h

    r98852 r99403  
    229229#if ENABLE(INPUT_COLOR)
    230230        virtual void openColorChooser(ColorChooser*, const Color&) = 0;
    231         virtual void cleanupColorChooser() = 0;
    232         virtual void setSelectedColorInColorChooser(const Color&) = 0;
     231        virtual void cleanupColorChooser(ColorChooser*) = 0;
     232        virtual void setSelectedColorInColorChooser(ColorChooser*, const Color&) = 0;
    233233#endif
    234234
  • trunk/Source/WebCore/platform/ColorChooser.cpp

    r95901 r99403  
    3939ColorChooserClient::~ColorChooserClient()
    4040{
    41     ColorChooser::chooser()->disconnectClient(this);
     41    discardChooser();
    4242}
    4343
    44 static ColorChooser* staticChooser = 0;
     44ColorChooser* ColorChooserClient::newColorChooser()
     45{
     46    discardChooser();
    4547
    46 ColorChooser* ColorChooser::chooser()
    47 {
    48     if (!staticChooser)
    49         staticChooser = adoptPtr(new ColorChooser()).leakPtr();
    50     return staticChooser;
     48    m_chooser = ColorChooser::create(this);
     49    return m_chooser.get();
    5150}
    5251
    53 void ColorChooser::connectClient(ColorChooserClient* client)
     52void ColorChooserClient::discardChooser()
    5453{
    55     if (client != m_client)
    56         m_client = client;
     54    if (m_chooser)
     55        m_chooser->disconnectClient();
     56    m_chooser.clear();
    5757}
    5858
    59 void ColorChooser::disconnectClient(ColorChooserClient* client)
     59inline ColorChooser::ColorChooser(ColorChooserClient* client)
     60    : m_client(client)
    6061{
    61     if (client == m_client)
    62         m_client = 0;
    6362}
    6463
    65 void ColorChooser::didChooseColor(const Color& color) const
     64PassRefPtr<ColorChooser> ColorChooser::create(ColorChooserClient* client)
     65{
     66    return adoptRef(new ColorChooser(client));
     67}
     68
     69ColorChooser::~ColorChooser()
     70{
     71}
     72
     73void ColorChooser::didChooseColor(const Color& color)
    6674{
    6775    if (m_client)
     
    6977}
    7078
     79void ColorChooser::didCleanup()
     80{
     81    if (m_client)
     82        m_client->didCleanup();
     83}
     84
    7185}
    7286
  • trunk/Source/WebCore/platform/ColorChooser.h

    r95901 r99403  
    3232
    3333#include "Color.h"
     34#include <wtf/RefCounted.h>
     35#include <wtf/RefPtr.h>
    3436
    3537#if ENABLE(INPUT_COLOR)
     
    4345    virtual ~ColorChooserClient();
    4446    virtual void didChooseColor(const Color&) = 0;
    45     virtual bool isColorInputType() const { return false; }
     47    virtual void didCleanup() = 0;
     48    ColorChooser* chooser() { return m_chooser.get(); }
     49
     50protected:
     51    ColorChooser* newColorChooser();
     52    void discardChooser();
     53
     54private:
     55    RefPtr<ColorChooser> m_chooser;
    4656};
    4757
    48 class ColorChooser {
     58class ColorChooser : public RefCounted<ColorChooser> {
    4959public:
    50     static ColorChooser* chooser();
     60    static PassRefPtr<ColorChooser> create(ColorChooserClient*);
     61    ~ColorChooser();
    5162
    52     ColorChooserClient* client() const { return m_client; };
    53     void connectClient(ColorChooserClient*);
    54     void disconnectClient(ColorChooserClient*);
     63    void disconnectClient() { m_client = 0; }
    5564
    56     void didChooseColor(const Color&) const;
     65    void didChooseColor(const Color&);
     66    void didCleanup();
    5767
    5868private:
    59     ColorChooser()
    60         : m_client(0)
    61     { }
     69    ColorChooser(ColorChooserClient*);
    6270
    6371    ColorChooserClient* m_client;
  • trunk/Source/WebCore/testing/Internals.cpp

    r98990 r99403  
    175175
    176176#if ENABLE(INPUT_COLOR)
    177 bool Internals::connectColorChooserClient(Element* element)
     177void Internals::selectColorInColorChooser(Element* element, const String& colorValue)
    178178{
    179179    if (!element->hasTagName(HTMLNames::inputTag))
    180         return false;
     180        return;
    181181    HTMLInputElement* inputElement = element->toInputElement();
    182182    if (!inputElement)
    183         return false;
    184     return inputElement->connectToColorChooser();
    185 }
    186 
    187 void Internals::selectColorInColorChooser(const String& colorValue)
    188 {
    189     ColorChooser::chooser()->colorSelected(Color(colorValue));
     183        return;
     184    inputElement->selectColorInColorChooser(Color(colorValue));
    190185}
    191186#endif
  • trunk/Source/WebCore/testing/Internals.h

    r98990 r99403  
    6161
    6262#if ENABLE(INPUT_COLOR)
    63     bool connectColorChooserClient(Element*);
    64     void selectColorInColorChooser(const String& colorValue);
     63    void selectColorInColorChooser(Element*, const String& colorValue);
    6564#endif
    6665
  • trunk/Source/WebCore/testing/Internals.idl

    r98990 r99403  
    4040
    4141#if defined(ENABLE_INPUT_COLOR) && ENABLE_INPUT_COLOR
    42         boolean connectColorChooserClient(in Element element);
    43         void selectColorInColorChooser(in DOMString colorValue);
     42        void selectColorInColorChooser(in Element element, in DOMString colorValue);
    4443#endif
    4544
Note: See TracChangeset for help on using the changeset viewer.