Add methods to ColorChooserClient so the color chooser can show suggestions
authorkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Jul 2012 11:03:38 +0000 (11:03 +0000)
committerkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Jul 2012 11:03:38 +0000 (11:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=92114

Reviewed by Kent Tamura.

Added methods to ColorChooserClient so the color chooser can ask the
client for suggestions and current color.

No new tests. The methods are not used yet.

* html/ColorInputType.cpp:
(WebCore::ColorInputType::currentColor): Returns what color the color
chooser should display.
(WebCore):
(WebCore::ColorInputType::shouldShowSuggestions): Returns if the UI for
suggestions should be shown.
(WebCore::ColorInputType::suggestions): Returns a list of colors to be
suggested to the user.
* html/ColorInputType.h:
(ColorInputType):
* html/HTMLInputElement.h:
(HTMLInputElement): Made dataList() public.
* platform/ColorChooserClient.h:
(ColorChooserClient):

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

Source/WebCore/ChangeLog
Source/WebCore/html/ColorInputType.cpp
Source/WebCore/html/ColorInputType.h
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/platform/ColorChooserClient.h

index 7f96295..d92cc3b 100644 (file)
@@ -1,3 +1,30 @@
+2012-07-25  Keishi Hattori  <keishi@webkit.org>
+
+        Add methods to ColorChooserClient so the color chooser can show suggestions
+        https://bugs.webkit.org/show_bug.cgi?id=92114
+
+        Reviewed by Kent Tamura.
+
+        Added methods to ColorChooserClient so the color chooser can ask the
+        client for suggestions and current color.
+
+        No new tests. The methods are not used yet.
+
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::currentColor): Returns what color the color
+        chooser should display.
+        (WebCore):
+        (WebCore::ColorInputType::shouldShowSuggestions): Returns if the UI for
+        suggestions should be shown.
+        (WebCore::ColorInputType::suggestions): Returns a list of colors to be
+        suggested to the user.
+        * html/ColorInputType.h:
+        (ColorInputType):
+        * html/HTMLInputElement.h:
+        (HTMLInputElement): Made dataList() public.
+        * platform/ColorChooserClient.h:
+        (ColorChooserClient):
+
 2012-07-25  Kentaro Hara  <haraken@chromium.org>
 
         Replace int with long in test IDL files
index ea2151c..abca6ac 100644 (file)
 #include "Chrome.h"
 #include "Color.h"
 #include "ElementShadow.h"
+#include "HTMLDataListElement.h"
 #include "HTMLDivElement.h"
 #include "HTMLInputElement.h"
+#include "HTMLOptionElement.h"
 #include "MouseEvent.h"
 #include "RenderObject.h"
 #include "RenderView.h"
@@ -50,6 +52,8 @@
 
 namespace WebCore {
 
+using namespace HTMLNames;
+
 static bool isValidColorString(const String& value)
 {
     if (value.isEmpty())
@@ -204,6 +208,38 @@ IntRect ColorInputType::elementRectRelativeToWindow() const
     return pixelSnappedIntRect(renderer->view()->frameView()->contentsToWindow(renderer->absoluteBoundingBoxRect()));
 }
 
+Color ColorInputType::currentColor()
+{
+    return valueAsColor();
+}
+
+bool ColorInputType::shouldShowSuggestions() const
+{
+#if ENABLE(DATALIST_ELEMENT)
+    return element()->fastHasAttribute(listAttr);
+#endif
+}
+
+Vector<Color> ColorInputType::suggestions() const
+{
+    Vector<Color> suggestions;
+#if ENABLE(DATALIST_ELEMENT)
+    HTMLDataListElement* dataList = element()->dataList();
+    if (dataList) {
+        RefPtr<HTMLCollection> options = dataList->options();
+        for (unsigned i = 0; HTMLOptionElement* option = static_cast<HTMLOptionElement*>(options->item(i)); i++) {
+            if (!element()->isValidValue(option->value()))
+                continue;
+            Color color(option->value());
+            if (!color.isValid())
+                continue;
+            suggestions.append(color);
+        }
+    }
+#endif
+    return suggestions;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INPUT_TYPE_COLOR)
index e03cb22..c0aeda7 100644 (file)
@@ -47,6 +47,9 @@ public:
     virtual void didChooseColor(const Color&) OVERRIDE;
     virtual void didEndChooser() OVERRIDE;
     virtual IntRect elementRectRelativeToWindow() const OVERRIDE;
+    virtual Color currentColor() OVERRIDE;
+    virtual bool shouldShowSuggestions() const OVERRIDE;
+    virtual Vector<Color> suggestions() const OVERRIDE;
 
 private:
     ColorInputType(HTMLInputElement* element) : BaseClickableWithKeyInputType(element) { }
index 3fd66c9..15260b9 100644 (file)
@@ -236,6 +236,7 @@ public:
 
 #if ENABLE(DATALIST_ELEMENT)
     HTMLElement* list() const;
+    HTMLDataListElement* dataList() const;
     void listAttributeTargetChanged();
 #endif
 
@@ -363,7 +364,6 @@ private:
     virtual void subtreeHasChanged();
 
 #if ENABLE(DATALIST_ELEMENT)
-    HTMLDataListElement* dataList() const;
     void resetListAttributeTargetObserver();
 #endif
     void parseMaxLengthAttribute(const Attribute&);
index b39c037..8baced3 100644 (file)
@@ -7,6 +7,7 @@
 #include "IntRect.h"
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -19,6 +20,9 @@ public:
     virtual void didChooseColor(const Color&) = 0;
     virtual void didEndChooser() = 0;
     virtual IntRect elementRectRelativeToWindow() const = 0;
+    virtual Color currentColor() = 0;
+    virtual bool shouldShowSuggestions() const = 0;
+    virtual Vector<Color> suggestions() const = 0;
 };
 
 } // namespace WebCore