1/*
2   Copyright (C) 2011 Samsung Electronics
3   Copyright (C) 2012 Intel Corporation. All rights reserved.
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22#include "ewk_color_picker.h"
23
24#include "WKColorPickerResultListener.h"
25#include "WKString.h"
26#include "ewk_color_picker_private.h"
27#include <wtf/text/CString.h>
28#include <wtf/text/WTFString.h>
29
30using namespace WebCore;
31
32#if ENABLE(INPUT_TYPE_COLOR)
33EwkColorPicker::EwkColorPicker(WKColorPickerResultListenerRef colorPickerListener, const Color& initialColor)
34    : m_colorPickerListener(colorPickerListener)
35    , m_color(initialColor)
36{
37}
38
39void EwkColorPicker::setColor(const Color& color)
40{
41    WKRetainPtr<WKStringRef> colorString(AdoptWK, WKStringCreateWithUTF8CString(color.serialized().utf8().data()));
42    WKColorPickerResultListenerSetColor(m_colorPickerListener.get(), colorString.get());
43}
44
45const Color& EwkColorPicker::color() const
46{
47    return m_color;
48}
49#endif
50
51Eina_Bool ewk_color_picker_color_set(Ewk_Color_Picker* colorPicker, int r, int g, int b, int a)
52{
53#if ENABLE(INPUT_TYPE_COLOR)
54    EINA_SAFETY_ON_NULL_RETURN_VAL(colorPicker, false);
55
56    colorPicker->setColor(Color(r, g, b, a));
57
58    return true;
59#else
60    UNUSED_PARAM(colorPicker);
61    UNUSED_PARAM(r);
62    UNUSED_PARAM(g);
63    UNUSED_PARAM(b);
64    UNUSED_PARAM(a);
65    return false;
66#endif
67}
68
69Eina_Bool ewk_color_picker_color_get(const Ewk_Color_Picker* colorPicker, int* r, int* g, int* b, int* a)
70{
71#if ENABLE(INPUT_TYPE_COLOR)
72    EINA_SAFETY_ON_NULL_RETURN_VAL(colorPicker, false);
73    EINA_SAFETY_ON_NULL_RETURN_VAL(r, false);
74    EINA_SAFETY_ON_NULL_RETURN_VAL(g, false);
75    EINA_SAFETY_ON_NULL_RETURN_VAL(b, false);
76    EINA_SAFETY_ON_NULL_RETURN_VAL(a, false);
77
78    const Color& color = colorPicker->color();
79    *r = color.red();
80    *g = color.green();
81    *b = color.blue();
82    *a = color.alpha();
83
84    return true;
85#else
86    UNUSED_PARAM(colorPicker);
87    UNUSED_PARAM(r);
88    UNUSED_PARAM(g);
89    UNUSED_PARAM(b);
90    UNUSED_PARAM(a);
91    return false;
92#endif
93}
94