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/. */ 5 6 #ifndef nsColorPicker_h__ 7 #define nsColorPicker_h__ 8 9 #include <gtk/gtk.h> 10 11 #include "nsCOMPtr.h" 12 #include "nsIColorPicker.h" 13 #include "nsString.h" 14 15 // Don't activate the GTK3 color picker for now, because it is missing a few 16 // things, mainly the ability to let the user select a color on the screen. 17 // See bug 1198256. 18 #undef ACTIVATE_GTK3_COLOR_PICKER 19 20 class nsIWidget; 21 22 class nsColorPicker final : public nsIColorPicker { 23 public: 24 NS_DECL_ISUPPORTS 25 NS_DECL_NSICOLORPICKER 26 27 nsColorPicker() = default; 28 29 private: 30 ~nsColorPicker() = default; 31 32 static nsString ToHexString(int n); 33 34 static void OnResponse(GtkWidget* dialog, gint response_id, 35 gpointer user_data); 36 static void OnDestroy(GtkWidget* dialog, gpointer user_data); 37 38 #if defined(ACTIVATE_GTK3_COLOR_PICKER) 39 static void OnColorChanged(GtkColorChooser* color_chooser, GdkRGBA* color, 40 gpointer user_data); 41 42 static int convertGdkRgbaComponent(gdouble color_component); 43 static gdouble convertToGdkRgbaComponent(int color_component); 44 static GdkRGBA convertToRgbaColor(nscolor color); 45 46 void Update(GdkRGBA* color); 47 void SetColor(const GdkRGBA* color); 48 #else 49 static void OnColorChanged(GtkColorSelection* colorselection, 50 gpointer user_data); 51 52 // Conversion functions for color 53 static int convertGdkColorComponent(guint16 color_component); 54 static guint16 convertToGdkColorComponent(int color_component); 55 static GdkColor convertToGdkColor(nscolor color); 56 57 static GtkColorSelection* WidgetGetColorSelection(GtkWidget* widget); 58 59 void Update(GtkColorSelection* colorselection); 60 void ReadValueFromColorSelection(GtkColorSelection* colorselection); 61 #endif 62 63 void Done(GtkWidget* dialog, gint response_id); 64 65 nsCOMPtr<nsIWidget> mParentWidget; 66 nsCOMPtr<nsIColorPickerShownCallback> mCallback; 67 nsString mTitle; 68 nsString mColor; 69 nsString mInitialColor; 70 }; 71 72 #endif // nsColorPicker_h__ 73