/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <gtk/gtk.h>
#ifdef MOZ_X11 # include "X11UndefineNone.h" #endif
#ifdefined(ACTIVATE_GTK3_COLOR_PICKER) int nsColorPicker::convertGdkRgbaComponent(gdouble color_component) { // GdkRGBA value is in range [0.0..1.0]. We need something in range [0..255] return color_component * 255 + 0.5;
}
return result;
} #else int nsColorPicker::convertGdkColorComponent(guint16 color_component) { // GdkColor value is in range [0..65535]. We need something in range [0..255] return (color_component * 255 + 127) / 65535;
}
nsresult nsColorPicker::OpenNative() { // Don't attempt to open a real color-picker in headless mode. if (gfxPlatform::IsHeadless()) { return NS_ERROR_NOT_AVAILABLE;
}
auto maybeColor = HTMLInputElement::ParseSimpleColor(mInitialColor); if (maybeColor.isNothing()) { return NS_ERROR_FAILURE;
}
nscolor color = maybeColor.value();
// Setting the default colors will put them into "Custom" colors list. for (const nsString& defaultColor : mDefaultColors) { if (auto color = HTMLInputElement::ParseSimpleColor(defaultColor)) {
GdkRGBA color_rgba = convertToRgbaColor(*color);
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(color_chooser), &color_rgba);
}
}
// The initial color needs to be set last.
GdkRGBA color_rgba = convertToRgbaColor(color);
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(color_chooser), &color_rgba);
void nsColorPicker::Done(GtkWidget* color_chooser, gint response) { switch (response) { case GTK_RESPONSE_OK: case GTK_RESPONSE_ACCEPT: #ifdefined(ACTIVATE_GTK3_COLOR_PICKER)
GdkRGBA color;
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(color_chooser), &color);
SetColor(&color); #else
ReadValueFromColorSelection(WidgetGetColorSelection(color_chooser)); #endif break; case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CLOSE: case GTK_RESPONSE_DELETE_EVENT:
mColor = mInitialColor; break; default:
NS_WARNING("Unexpected response"); break;
}
// A "response" signal won't be sent again but "destroy" will be.
g_signal_handlers_disconnect_by_func(color_chooser, FuncToGpointer(OnDestroy), this);
gtk_widget_destroy(color_chooser); if (mCallback) {
mCallback->Done(mColor);
mCallback = nullptr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.