1/*
2 * Copyright (C) 2015 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21#include "WebKitColorChooser.h"
22
23#include "WebKitColorChooserRequestPrivate.h"
24#include "WebKitWebViewPrivate.h"
25#include <WebCore/Color.h>
26#include <WebCore/IntRect.h>
27
28namespace WebKit {
29using namespace WebCore;
30
31Ref<WebKitColorChooser> WebKitColorChooser::create(WebPageProxy& page, const WebCore::Color& initialColor, const WebCore::IntRect& rect)
32{
33 return adoptRef(*new WebKitColorChooser(page, initialColor, rect));
34}
35
36WebKitColorChooser::WebKitColorChooser(WebPageProxy& page, const Color& initialColor, const IntRect& rect)
37 : WebColorPickerGtk(page, initialColor, rect)
38 , m_elementRect(rect)
39{
40}
41
42WebKitColorChooser::~WebKitColorChooser()
43{
44 endPicker();
45}
46
47void WebKitColorChooser::endPicker()
48{
49 if (!m_request) {
50 WebColorPickerGtk::endPicker();
51 return;
52 }
53
54 webkit_color_chooser_request_finish(m_request.get());
55}
56
57void WebKitColorChooser::colorChooserRequestFinished(WebKitColorChooserRequest*, WebKitColorChooser* colorChooser)
58{
59 colorChooser->m_request = nullptr;
60}
61
62void WebKitColorChooser::colorChooserRequestRGBAChanged(WebKitColorChooserRequest* request, GParamSpec*, WebKitColorChooser* colorChooser)
63{
64 GdkRGBA rgba;
65 webkit_color_chooser_request_get_rgba(request, &rgba);
66 colorChooser->didChooseColor(rgba);
67}
68
69void WebKitColorChooser::showColorPicker(const Color& color)
70{
71 m_initialColor = color;
72 GRefPtr<WebKitColorChooserRequest> request = adoptGRef(webkitColorChooserRequestCreate(this));
73 g_signal_connect(request.get(), "notify::rgba", G_CALLBACK(WebKitColorChooser::colorChooserRequestRGBAChanged), this);
74 g_signal_connect(request.get(), "finished", G_CALLBACK(WebKitColorChooser::colorChooserRequestFinished), this);
75
76 if (webkitWebViewEmitRunColorChooser(WEBKIT_WEB_VIEW(m_webView), request.get()))
77 m_request = request;
78 else
79 WebColorPickerGtk::showColorPicker(color);
80}
81
82} // namespace WebKit
83