1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsColorPicker_h__
7 #define nsColorPicker_h__
12 #include "nsIColorPicker.h"
15 // Enable Gtk3 system color picker.
16 #define ACTIVATE_GTK3_COLOR_PICKER 1
20 class nsColorPicker final
: public nsIColorPicker
{
23 NS_DECL_NSICOLORPICKER
25 nsColorPicker() = default;
28 ~nsColorPicker() = default;
30 static nsString
ToHexString(int n
);
32 static void OnResponse(GtkWidget
* dialog
, gint response_id
,
34 static void OnDestroy(GtkWidget
* dialog
, gpointer user_data
);
36 #if defined(ACTIVATE_GTK3_COLOR_PICKER)
37 static void OnColorChanged(GtkColorChooser
* color_chooser
, GdkRGBA
* color
,
40 static int convertGdkRgbaComponent(gdouble color_component
);
41 static gdouble
convertToGdkRgbaComponent(int color_component
);
42 static GdkRGBA
convertToRgbaColor(nscolor color
);
44 void Update(GdkRGBA
* color
);
45 void SetColor(const GdkRGBA
* color
);
47 static void OnColorChanged(GtkColorSelection
* colorselection
,
50 // Conversion functions for color
51 static int convertGdkColorComponent(guint16 color_component
);
52 static guint16
convertToGdkColorComponent(int color_component
);
53 static GdkColor
convertToGdkColor(nscolor color
);
55 static GtkColorSelection
* WidgetGetColorSelection(GtkWidget
* widget
);
57 void Update(GtkColorSelection
* colorselection
);
58 void ReadValueFromColorSelection(GtkColorSelection
* colorselection
);
61 void Done(GtkWidget
* dialog
, gint response_id
);
63 nsCOMPtr
<nsIWidget
> mParentWidget
;
64 nsCOMPtr
<nsIColorPickerShownCallback
> mCallback
;
67 nsString mInitialColor
;
68 nsTArray
<nsString
> mDefaultColors
;
71 #endif // nsColorPicker_h__