2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2002-04-27 20:26:10 +04:00
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2001-12-10 20:37:36 +03:00
|
|
|
|
2012-02-21 03:19:48 +04:00
|
|
|
// for strtod()
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-12-10 20:37:36 +03:00
|
|
|
#include "nsLookAndFeel.h"
|
2012-02-21 03:19:48 +04:00
|
|
|
|
2009-01-03 10:37:52 +03:00
|
|
|
#include <gtk/gtk.h>
|
2012-02-21 03:19:48 +04:00
|
|
|
#include <gdk/gdk.h>
|
|
|
|
|
|
|
|
#include <pango/pango.h>
|
|
|
|
#include <pango/pango-fontmap.h>
|
|
|
|
|
|
|
|
#include <fontconfig/fontconfig.h>
|
|
|
|
#include "gfxPlatformGtk.h"
|
2018-04-13 22:34:37 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2019-02-22 22:32:14 +03:00
|
|
|
#include "mozilla/RelativeLuminanceUtils.h"
|
2019-08-27 00:02:43 +03:00
|
|
|
#include "mozilla/StaticPrefs_layout.h"
|
2017-03-09 14:29:44 +03:00
|
|
|
#include "ScreenHelperGTK.h"
|
2001-12-10 20:37:36 +03:00
|
|
|
|
2006-05-02 03:23:33 +04:00
|
|
|
#include "gtkdrawing.h"
|
2011-03-31 16:26:49 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "gfxFontConstants.h"
|
2015-04-29 23:29:34 +03:00
|
|
|
#include "WidgetUtils.h"
|
2017-11-20 16:29:49 +03:00
|
|
|
#include "nsWindow.h"
|
2015-01-21 07:53:00 +03:00
|
|
|
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2006-05-02 03:23:33 +04:00
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
#include <cairo-gobject.h>
|
2016-06-07 07:11:51 +03:00
|
|
|
#include "WidgetStyleCache.h"
|
2016-08-05 16:21:00 +03:00
|
|
|
#include "prenv.h"
|
2018-06-29 21:23:03 +03:00
|
|
|
#include "nsCSSColorUtils.h"
|
2016-03-18 12:49:46 +03:00
|
|
|
|
2018-04-26 15:59:55 +03:00
|
|
|
using namespace mozilla;
|
2012-02-21 03:19:48 +04:00
|
|
|
using mozilla::LookAndFeel;
|
|
|
|
|
2019-10-08 11:53:40 +03:00
|
|
|
#undef LOG
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
# include "mozilla/Logging.h"
|
|
|
|
# include "nsTArray.h"
|
|
|
|
# include "Units.h"
|
|
|
|
extern mozilla::LazyLogModule gWidgetLog;
|
|
|
|
# define LOG(args) MOZ_LOG(gWidgetLog, mozilla::LogLevel::Debug, args)
|
|
|
|
#else
|
|
|
|
# define LOG(args)
|
|
|
|
#endif /* MOZ_LOGGING */
|
|
|
|
|
2001-12-10 20:37:36 +03:00
|
|
|
#define GDK_COLOR_TO_NS_RGB(c) \
|
|
|
|
((nscolor)NS_RGB(c.red >> 8, c.green >> 8, c.blue >> 8))
|
2013-05-30 03:26:40 +04:00
|
|
|
#define GDK_RGBA_TO_NS_RGBA(c) \
|
|
|
|
((nscolor)NS_RGBA((int)((c).red * 255), (int)((c).green * 255), \
|
|
|
|
(int)((c).blue * 255), (int)((c).alpha * 255)))
|
2001-12-10 20:37:36 +03:00
|
|
|
|
2017-08-25 11:30:28 +03:00
|
|
|
#if !GTK_CHECK_VERSION(3, 12, 0)
|
|
|
|
# define GTK_STATE_FLAG_LINK (static_cast<GtkStateFlags>(1 << 9))
|
|
|
|
#endif
|
|
|
|
|
2019-03-16 18:17:49 +03:00
|
|
|
nsLookAndFeel::nsLookAndFeel() = default;
|
2001-12-10 20:37:36 +03:00
|
|
|
|
|
|
|
nsLookAndFeel::~nsLookAndFeel() {}
|
|
|
|
|
2017-01-03 03:08:07 +03:00
|
|
|
// Modifies color |*aDest| as if a pattern of color |aSource| was painted with
|
|
|
|
// CAIRO_OPERATOR_OVER to a surface with color |*aDest|.
|
|
|
|
static void ApplyColorOver(const GdkRGBA& aSource, GdkRGBA* aDest) {
|
|
|
|
gdouble sourceCoef = aSource.alpha;
|
|
|
|
gdouble destCoef = aDest->alpha * (1.0 - sourceCoef);
|
|
|
|
gdouble resultAlpha = sourceCoef + destCoef;
|
|
|
|
if (resultAlpha != 0.0) { // don't divide by zero
|
|
|
|
destCoef /= resultAlpha;
|
|
|
|
sourceCoef /= resultAlpha;
|
|
|
|
aDest->red = sourceCoef * aSource.red + destCoef * aDest->red;
|
|
|
|
aDest->green = sourceCoef * aSource.green + destCoef * aDest->green;
|
|
|
|
aDest->blue = sourceCoef * aSource.blue + destCoef * aDest->blue;
|
2017-01-03 22:43:20 +03:00
|
|
|
aDest->alpha = resultAlpha;
|
2017-01-03 03:08:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
static void GetLightAndDarkness(const GdkRGBA& aColor, double* aLightness,
|
|
|
|
double* aDarkness) {
|
|
|
|
double sum = aColor.red + aColor.green + aColor.blue;
|
|
|
|
*aLightness = sum * aColor.alpha;
|
|
|
|
*aDarkness = (3.0 - sum) * aColor.alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool GetGradientColors(const GValue* aValue, GdkRGBA* aLightColor,
|
|
|
|
GdkRGBA* aDarkColor) {
|
|
|
|
if (!G_TYPE_CHECK_VALUE_TYPE(aValue, CAIRO_GOBJECT_TYPE_PATTERN))
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
auto pattern = static_cast<cairo_pattern_t*>(g_value_get_boxed(aValue));
|
2016-03-29 07:50:47 +03:00
|
|
|
if (!pattern) return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
// Just picking the lightest and darkest colors as simple samples rather
|
|
|
|
// than trying to blend, which could get messy if there are many stops.
|
|
|
|
if (CAIRO_STATUS_SUCCESS !=
|
|
|
|
cairo_pattern_get_color_stop_rgba(pattern, 0, nullptr, &aDarkColor->red,
|
|
|
|
&aDarkColor->green, &aDarkColor->blue,
|
|
|
|
&aDarkColor->alpha))
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
double maxLightness, maxDarkness;
|
|
|
|
GetLightAndDarkness(*aDarkColor, &maxLightness, &maxDarkness);
|
|
|
|
*aLightColor = *aDarkColor;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
GdkRGBA stop;
|
|
|
|
for (int index = 1;
|
|
|
|
CAIRO_STATUS_SUCCESS ==
|
|
|
|
cairo_pattern_get_color_stop_rgba(pattern, index, nullptr, &stop.red,
|
|
|
|
&stop.green, &stop.blue, &stop.alpha);
|
|
|
|
++index) {
|
|
|
|
double lightness, darkness;
|
|
|
|
GetLightAndDarkness(stop, &lightness, &darkness);
|
|
|
|
if (lightness > maxLightness) {
|
|
|
|
maxLightness = lightness;
|
|
|
|
*aLightColor = stop;
|
|
|
|
}
|
|
|
|
if (darkness > maxDarkness) {
|
|
|
|
maxDarkness = darkness;
|
|
|
|
*aDarkColor = stop;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2016-03-18 12:49:46 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool GetUnicoBorderGradientColors(GtkStyleContext* aContext,
|
|
|
|
GdkRGBA* aLightColor,
|
|
|
|
GdkRGBA* aDarkColor) {
|
|
|
|
// Ubuntu 12.04 has GTK engine Unico-1.0.2, which overrides render_frame,
|
|
|
|
// providing its own border code. Ubuntu 14.04 has
|
|
|
|
// Unico-1.0.3+14.04.20140109, which does not override render_frame, and
|
|
|
|
// so does not need special attention. The earlier Unico can be detected
|
|
|
|
// by the -unico-border-gradient style property it registers.
|
|
|
|
// gtk_style_properties_lookup_property() is checked first to avoid the
|
|
|
|
// warning from gtk_style_context_get_property() when the property does
|
|
|
|
// not exist. (gtk_render_frame() of GTK+ 3.16 no longer uses the
|
|
|
|
// engine.)
|
|
|
|
const char* propertyName = "-unico-border-gradient";
|
|
|
|
if (!gtk_style_properties_lookup_property(propertyName, nullptr, nullptr))
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
// -unico-border-gradient is used only when the CSS node's engine is Unico.
|
|
|
|
GtkThemingEngine* engine;
|
|
|
|
GtkStateFlags state = gtk_style_context_get_state(aContext);
|
|
|
|
gtk_style_context_get(aContext, state, "engine", &engine, nullptr);
|
|
|
|
if (strcmp(g_type_name(G_TYPE_FROM_INSTANCE(engine)), "UnicoEngine") != 0)
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
// draw_border() of Unico engine uses -unico-border-gradient
|
|
|
|
// in preference to border-color.
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
gtk_style_context_get_property(aContext, propertyName, state, &value);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
bool result = GetGradientColors(&value, aLightColor, aDarkColor);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-18 12:49:46 +03:00
|
|
|
g_value_unset(&value);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:07:48 +03:00
|
|
|
// Sets |aLightColor| and |aDarkColor| to colors from |aContext|. Returns
|
|
|
|
// true if |aContext| uses these colors to render a visible border.
|
|
|
|
// If returning false, then the colors returned are a fallback from the
|
|
|
|
// border-color value even though |aContext| does not use these colors to
|
|
|
|
// render a border.
|
2016-03-18 12:49:46 +03:00
|
|
|
static bool GetBorderColors(GtkStyleContext* aContext, GdkRGBA* aLightColor,
|
|
|
|
GdkRGBA* aDarkColor) {
|
2016-11-21 08:07:48 +03:00
|
|
|
// Determine whether the border on this style context is visible.
|
2016-03-18 12:49:46 +03:00
|
|
|
GtkStateFlags state = gtk_style_context_get_state(aContext);
|
2016-11-21 08:07:48 +03:00
|
|
|
GtkBorderStyle borderStyle;
|
|
|
|
gtk_style_context_get(aContext, state, GTK_STYLE_PROPERTY_BORDER_STYLE,
|
|
|
|
&borderStyle, nullptr);
|
|
|
|
bool visible = borderStyle != GTK_BORDER_STYLE_NONE &&
|
|
|
|
borderStyle != GTK_BORDER_STYLE_HIDDEN;
|
|
|
|
if (visible) {
|
|
|
|
// GTK has an initial value of zero for border-widths, and so themes
|
|
|
|
// need to explicitly set border-widths to make borders visible.
|
|
|
|
GtkBorder border;
|
2018-04-13 14:41:27 +03:00
|
|
|
gtk_style_context_get_border(aContext, state, &border);
|
2016-11-21 08:07:48 +03:00
|
|
|
visible = border.top != 0 || border.right != 0 || border.bottom != 0 ||
|
|
|
|
border.left != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visible &&
|
|
|
|
GetUnicoBorderGradientColors(aContext, aLightColor, aDarkColor))
|
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-21 08:07:48 +03:00
|
|
|
// The initial value for the border-color is the foreground color, and so
|
|
|
|
// this will usually return a color distinct from the background even if
|
|
|
|
// there is no visible border detected.
|
2016-03-18 12:49:46 +03:00
|
|
|
gtk_style_context_get_border_color(aContext, state, aDarkColor);
|
|
|
|
// TODO GTK3 - update aLightColor
|
|
|
|
// for GTK_BORDER_STYLE_INSET/OUTSET/GROVE/RIDGE border styles.
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=978172#c25
|
|
|
|
*aLightColor = *aDarkColor;
|
2016-11-21 08:07:48 +03:00
|
|
|
return visible;
|
2016-03-18 12:49:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool GetBorderColors(GtkStyleContext* aContext, nscolor* aLightColor,
|
|
|
|
nscolor* aDarkColor) {
|
|
|
|
GdkRGBA lightColor, darkColor;
|
2016-11-21 08:07:48 +03:00
|
|
|
bool ret = GetBorderColors(aContext, &lightColor, &darkColor);
|
2016-03-18 12:49:46 +03:00
|
|
|
*aLightColor = GDK_RGBA_TO_NS_RGBA(lightColor);
|
|
|
|
*aDarkColor = GDK_RGBA_TO_NS_RGBA(darkColor);
|
2016-11-21 08:07:48 +03:00
|
|
|
return ret;
|
2016-03-18 12:49:46 +03:00
|
|
|
}
|
|
|
|
|
2018-06-29 21:23:03 +03:00
|
|
|
// Finds ideal cell highlight colors used for unfocused+selected cells distinct
|
|
|
|
// from both Highlight, used as focused+selected background, and the listbox
|
|
|
|
// background which is assumed to be similar to -moz-field
|
|
|
|
nsresult nsLookAndFeel::InitCellHighlightColors() {
|
|
|
|
// NS_SUFFICIENT_LUMINOSITY_DIFFERENCE is the a11y standard for text
|
|
|
|
// on a background. Use 20% of that standard since we have a background
|
|
|
|
// on top of another background
|
|
|
|
int32_t minLuminosityDifference = NS_SUFFICIENT_LUMINOSITY_DIFFERENCE / 5;
|
|
|
|
int32_t backLuminosityDifference =
|
|
|
|
NS_LUMINOSITY_DIFFERENCE(mMozWindowBackground, mMozFieldBackground);
|
|
|
|
if (backLuminosityDifference >= minLuminosityDifference) {
|
|
|
|
mMozCellHighlightBackground = mMozWindowBackground;
|
|
|
|
mMozCellHighlightText = mMozWindowText;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t hue, sat, luminance;
|
|
|
|
uint8_t alpha;
|
|
|
|
mMozCellHighlightBackground = mMozFieldBackground;
|
|
|
|
mMozCellHighlightText = mMozFieldText;
|
|
|
|
|
|
|
|
NS_RGB2HSV(mMozCellHighlightBackground, hue, sat, luminance, alpha);
|
|
|
|
|
|
|
|
uint16_t step = 30;
|
|
|
|
// Lighten the color if the color is very dark
|
|
|
|
if (luminance <= step) {
|
|
|
|
luminance += step;
|
|
|
|
}
|
|
|
|
// Darken it if it is very light
|
|
|
|
else if (luminance >= 255 - step) {
|
|
|
|
luminance -= step;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-06-29 21:23:03 +03:00
|
|
|
// Otherwise, compute what works best depending on the text luminance.
|
2018-11-30 13:46:48 +03:00
|
|
|
else {
|
2018-06-29 21:23:03 +03:00
|
|
|
uint16_t textHue, textSat, textLuminance;
|
|
|
|
uint8_t textAlpha;
|
|
|
|
NS_RGB2HSV(mMozCellHighlightText, textHue, textSat, textLuminance,
|
|
|
|
textAlpha);
|
|
|
|
// Text is darker than background, use a lighter shade
|
|
|
|
if (textLuminance < luminance) {
|
|
|
|
luminance += step;
|
|
|
|
}
|
|
|
|
// Otherwise, use a darker shade
|
|
|
|
else {
|
|
|
|
luminance -= step;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-06-29 21:23:03 +03:00
|
|
|
NS_HSV2RGB(mMozCellHighlightBackground, hue, sat, luminance, alpha);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-10-11 00:12:47 +03:00
|
|
|
void nsLookAndFeel::NativeInit() { EnsureInit(); }
|
|
|
|
|
|
|
|
void nsLookAndFeel::RefreshImpl() {
|
|
|
|
nsXPLookAndFeel::RefreshImpl();
|
|
|
|
moz_gtk_refresh();
|
|
|
|
|
|
|
|
mDefaultFontCached = false;
|
|
|
|
mButtonFontCached = false;
|
|
|
|
mFieldFontCached = false;
|
|
|
|
mMenuFontCached = false;
|
|
|
|
|
|
|
|
mInitialized = false;
|
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
|
2017-03-30 16:03:50 +03:00
|
|
|
EnsureInit();
|
|
|
|
|
2002-04-27 20:26:10 +04:00
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
|
|
|
switch (aID) {
|
2004-01-31 01:57:07 +03:00
|
|
|
// These colors don't seem to be used for anything anymore in Mozilla
|
|
|
|
// (except here at least TextSelectBackground and TextSelectForeground)
|
|
|
|
// The CSS2 colors below are used.
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::WindowBackground:
|
|
|
|
case ColorID::WidgetBackground:
|
|
|
|
case ColorID::TextBackground:
|
|
|
|
case ColorID::Activecaption: // active window caption background
|
|
|
|
case ColorID::Appworkspace: // MDI background color
|
|
|
|
case ColorID::Background: // desktop background
|
|
|
|
case ColorID::Window:
|
|
|
|
case ColorID::Windowframe:
|
|
|
|
case ColorID::MozDialog:
|
|
|
|
case ColorID::MozCombobox:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMozWindowBackground;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::WindowForeground:
|
|
|
|
case ColorID::WidgetForeground:
|
|
|
|
case ColorID::TextForeground:
|
|
|
|
case ColorID::Captiontext: // text in active window caption, size box, and
|
2013-05-30 03:26:40 +04:00
|
|
|
// scrollbar arrow box (!)
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Windowtext:
|
|
|
|
case ColorID::MozDialogtext:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMozWindowText;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::WidgetSelectBackground:
|
|
|
|
case ColorID::TextSelectBackground:
|
|
|
|
case ColorID::IMESelectedRawTextBackground:
|
|
|
|
case ColorID::IMESelectedConvertedTextBackground:
|
|
|
|
case ColorID::MozDragtargetzone:
|
|
|
|
case ColorID::MozHtmlCellhighlight:
|
|
|
|
case ColorID::Highlight: // preference selected item,
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mTextSelectedBackground;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::WidgetSelectForeground:
|
|
|
|
case ColorID::TextSelectForeground:
|
|
|
|
case ColorID::IMESelectedRawTextForeground:
|
|
|
|
case ColorID::IMESelectedConvertedTextForeground:
|
|
|
|
case ColorID::Highlighttext:
|
|
|
|
case ColorID::MozHtmlCellhighlighttext:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mTextSelectedText;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozCellhighlight:
|
2018-06-29 21:23:03 +03:00
|
|
|
aColor = mMozCellHighlightBackground;
|
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozCellhighlighttext:
|
2018-06-29 21:23:03 +03:00
|
|
|
aColor = mMozCellHighlightText;
|
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Widget3DHighlight:
|
2002-04-27 20:26:10 +04:00
|
|
|
aColor = NS_RGB(0xa0, 0xa0, 0xa0);
|
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Widget3DShadow:
|
2002-04-27 20:26:10 +04:00
|
|
|
aColor = NS_RGB(0x40, 0x40, 0x40);
|
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::IMERawInputBackground:
|
|
|
|
case ColorID::IMEConvertedTextBackground:
|
2005-09-17 15:34:27 +04:00
|
|
|
aColor = NS_TRANSPARENT;
|
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::IMERawInputForeground:
|
|
|
|
case ColorID::IMEConvertedTextForeground:
|
2005-09-17 15:34:27 +04:00
|
|
|
aColor = NS_SAME_AS_FOREGROUND_COLOR;
|
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::IMERawInputUnderline:
|
|
|
|
case ColorID::IMEConvertedTextUnderline:
|
2005-09-17 15:34:27 +04:00
|
|
|
aColor = NS_SAME_AS_FOREGROUND_COLOR;
|
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::IMESelectedRawTextUnderline:
|
|
|
|
case ColorID::IMESelectedConvertedTextUnderline:
|
2005-09-17 15:34:27 +04:00
|
|
|
aColor = NS_TRANSPARENT;
|
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::SpellCheckerUnderline:
|
2017-09-19 23:00:28 +03:00
|
|
|
aColor = NS_RGB(0xff, 0, 0);
|
|
|
|
break;
|
2002-04-27 20:26:10 +04:00
|
|
|
|
2013-05-30 03:26:40 +04:00
|
|
|
// css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Activeborder:
|
2013-05-30 03:26:40 +04:00
|
|
|
// active window border
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMozWindowActiveBorder;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Inactiveborder:
|
2013-05-30 03:26:40 +04:00
|
|
|
// inactive window border
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMozWindowInactiveBorder;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Graytext: // disabled text in windows, menus, etc.
|
|
|
|
case ColorID::Inactivecaptiontext: // text in inactive window caption
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMenuTextInactive;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Inactivecaption:
|
2013-05-30 03:26:40 +04:00
|
|
|
// inactive window caption
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMozWindowInactiveCaption;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Infobackground:
|
2002-04-27 20:26:10 +04:00
|
|
|
// tooltip background color
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mInfoBackground;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Infotext:
|
2002-04-27 20:26:10 +04:00
|
|
|
// tooltip text color
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mInfoText;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Menu:
|
2002-04-27 20:26:10 +04:00
|
|
|
// menu background
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMenuBackground;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Menutext:
|
2002-04-27 20:26:10 +04:00
|
|
|
// menu text
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMenuText;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Scrollbar:
|
2002-04-27 20:26:10 +04:00
|
|
|
// scrollbar gray area
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMozScrollbar;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Threedlightshadow:
|
2014-11-27 06:08:00 +03:00
|
|
|
// 3-D highlighted inner edge color
|
|
|
|
// always same as background in GTK code
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Threedface:
|
|
|
|
case ColorID::Buttonface:
|
2002-04-27 20:26:10 +04:00
|
|
|
// 3-D face color
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMozWindowBackground;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Buttontext:
|
2002-04-27 20:26:10 +04:00
|
|
|
// text on push buttons
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mButtonText;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Buttonhighlight:
|
2002-04-27 20:26:10 +04:00
|
|
|
// 3-D highlighted edge color
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Threedhighlight:
|
2002-04-27 20:26:10 +04:00
|
|
|
// 3-D highlighted outer edge color
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mFrameOuterLightBorder;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Buttonshadow:
|
2002-04-27 20:26:10 +04:00
|
|
|
// 3-D shadow edge color
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Threedshadow:
|
2002-04-27 20:26:10 +04:00
|
|
|
// 3-D shadow inner edge color
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mFrameInnerDarkBorder;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::Threeddarkshadow:
|
2013-05-30 03:26:40 +04:00
|
|
|
// Hardcode to black
|
2016-01-22 18:58:49 +03:00
|
|
|
aColor = NS_RGB(0x00, 0x00, 0x00);
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
|
|
|
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozEventreerow:
|
|
|
|
case ColorID::MozField:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMozFieldBackground;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozFieldtext:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMozFieldText;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozButtondefault:
|
2016-11-23 04:00:00 +03:00
|
|
|
// default button border color
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mButtonDefault;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozButtonhoverface:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mButtonHoverFace;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozButtonhovertext:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mButtonHoverText;
|
2013-05-30 03:26:40 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozGtkButtonactivetext:
|
2019-05-24 11:51:48 +03:00
|
|
|
aColor = mButtonActiveText;
|
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozMenuhover:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMenuHover;
|
2004-10-26 05:45:28 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozMenuhovertext:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMenuHoverText;
|
2004-10-26 05:45:28 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozOddtreerow:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mOddCellBackground;
|
2008-04-12 16:13:32 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozNativehyperlinktext:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mNativeHyperLinkText;
|
2008-07-11 22:34:53 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozComboboxtext:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mComboBoxText;
|
2009-01-16 11:18:49 +03:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozMenubartext:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMenuBarText;
|
2009-06-15 01:58:14 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozMenubarhovertext:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mMenuBarHoverText;
|
2009-06-15 01:58:14 +04:00
|
|
|
break;
|
2019-05-26 16:10:00 +03:00
|
|
|
case ColorID::MozGtkInfoBarText:
|
2017-11-07 12:14:52 +03:00
|
|
|
aColor = mInfoBarText;
|
2015-08-19 22:42:17 +03:00
|
|
|
break;
|
2002-04-27 20:26:10 +04:00
|
|
|
default:
|
|
|
|
/* default color is BLACK */
|
|
|
|
aColor = 0;
|
|
|
|
res = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2001-12-10 20:37:36 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t CheckWidgetStyle(GtkWidget* aWidget, const char* aStyle,
|
|
|
|
int32_t aResult) {
|
2011-10-03 11:56:21 +04:00
|
|
|
gboolean value = FALSE;
|
2013-10-08 22:47:37 +04:00
|
|
|
gtk_widget_style_get(aWidget, aStyle, &value, nullptr);
|
2011-09-09 06:27:13 +04:00
|
|
|
return value ? aResult : 0;
|
2006-05-02 03:23:33 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t ConvertGTKStepperStyleToMozillaScrollArrowStyle(
|
|
|
|
GtkWidget* aWidget) {
|
2011-09-09 06:27:13 +04:00
|
|
|
if (!aWidget) return mozilla::LookAndFeel::eScrollArrowStyle_Single;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-05-02 03:23:33 +04:00
|
|
|
return CheckWidgetStyle(aWidget, "has-backward-stepper",
|
2011-09-09 06:27:13 +04:00
|
|
|
mozilla::LookAndFeel::eScrollArrow_StartBackward) |
|
2006-05-02 03:23:33 +04:00
|
|
|
CheckWidgetStyle(aWidget, "has-forward-stepper",
|
2011-09-09 06:27:13 +04:00
|
|
|
mozilla::LookAndFeel::eScrollArrow_EndForward) |
|
2006-05-02 03:23:33 +04:00
|
|
|
CheckWidgetStyle(aWidget, "has-secondary-backward-stepper",
|
2011-09-09 06:27:13 +04:00
|
|
|
mozilla::LookAndFeel::eScrollArrow_EndBackward) |
|
2006-05-02 03:23:33 +04:00
|
|
|
CheckWidgetStyle(aWidget, "has-secondary-forward-stepper",
|
2011-09-09 06:27:13 +04:00
|
|
|
mozilla::LookAndFeel::eScrollArrow_StartForward);
|
2006-05-02 03:23:33 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
|
2002-04-27 20:26:10 +04:00
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
2017-12-19 13:38:59 +03:00
|
|
|
// Set these before they can get overrided in the nsXPLookAndFeel.
|
2006-07-20 02:13:18 +04:00
|
|
|
switch (aID) {
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_ScrollButtonLeftMouseButtonAction:
|
|
|
|
aResult = 0;
|
2006-07-20 02:13:18 +04:00
|
|
|
return NS_OK;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_ScrollButtonMiddleMouseButtonAction:
|
|
|
|
aResult = 1;
|
2006-07-20 02:13:18 +04:00
|
|
|
return NS_OK;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_ScrollButtonRightMouseButtonAction:
|
|
|
|
aResult = 2;
|
2006-07-20 02:13:18 +04:00
|
|
|
return NS_OK;
|
2008-01-01 13:21:28 +03:00
|
|
|
default:
|
|
|
|
break;
|
2006-07-20 02:13:18 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
|
2002-04-27 20:26:10 +04:00
|
|
|
if (NS_SUCCEEDED(res)) return res;
|
|
|
|
res = NS_OK;
|
2006-07-20 02:13:18 +04:00
|
|
|
|
2017-03-30 16:03:50 +03:00
|
|
|
// We use delayed initialization by EnsureInit() here
|
|
|
|
// to make sure mozilla::Preferences is available (Bug 115807).
|
|
|
|
// eIntID_UseAccessibilityTheme is requested before user preferences
|
|
|
|
// are read, and so EnsureInit(), which depends on preference values,
|
|
|
|
// is deliberately delayed until required.
|
2002-04-27 20:26:10 +04:00
|
|
|
switch (aID) {
|
2019-04-30 11:24:16 +03:00
|
|
|
case eIntID_CaretBlinkTime:
|
|
|
|
EnsureInit();
|
|
|
|
aResult = mCaretBlinkTime;
|
2006-04-20 00:03:30 +04:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_CaretWidth:
|
|
|
|
aResult = 1;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_ShowCaretDuringSelection:
|
|
|
|
aResult = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_SelectTextfieldsOnKeyFocus: {
|
2005-02-18 09:13:33 +03:00
|
|
|
GtkWidget* entry;
|
|
|
|
GtkSettings* settings;
|
|
|
|
gboolean select_on_focus;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2005-02-18 09:13:33 +03:00
|
|
|
entry = gtk_entry_new();
|
2011-05-16 13:07:37 +04:00
|
|
|
g_object_ref_sink(entry);
|
2005-02-18 09:13:33 +03:00
|
|
|
settings = gtk_widget_get_settings(entry);
|
2013-10-08 22:47:37 +04:00
|
|
|
g_object_get(settings, "gtk-entry-select-on-focus", &select_on_focus,
|
|
|
|
nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2005-02-18 09:13:33 +03:00
|
|
|
if (select_on_focus)
|
2011-09-09 06:27:13 +04:00
|
|
|
aResult = 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
else
|
2011-09-09 06:27:13 +04:00
|
|
|
aResult = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2005-02-18 09:13:33 +03:00
|
|
|
gtk_widget_destroy(entry);
|
2011-05-16 13:07:37 +04:00
|
|
|
g_object_unref(entry);
|
2003-05-02 22:20:38 +04:00
|
|
|
} break;
|
2014-08-10 13:05:51 +04:00
|
|
|
case eIntID_ScrollToClick: {
|
|
|
|
GtkSettings* settings;
|
|
|
|
gboolean warps_slider = FALSE;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-10 13:05:51 +04:00
|
|
|
settings = gtk_settings_get_default();
|
|
|
|
if (g_object_class_find_property(G_OBJECT_GET_CLASS(settings),
|
|
|
|
"gtk-primary-button-warps-slider")) {
|
|
|
|
g_object_get(settings, "gtk-primary-button-warps-slider", &warps_slider,
|
2013-10-08 22:47:37 +04:00
|
|
|
nullptr);
|
2006-04-20 00:03:30 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-04-27 20:26:10 +04:00
|
|
|
if (warps_slider)
|
2011-09-09 06:27:13 +04:00
|
|
|
aResult = 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
else
|
2011-09-09 06:27:13 +04:00
|
|
|
aResult = 0;
|
2002-04-27 20:26:10 +04:00
|
|
|
} break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_SubmenuDelay: {
|
2005-02-18 09:13:33 +03:00
|
|
|
GtkSettings* settings;
|
2006-04-20 00:03:30 +04:00
|
|
|
gint delay;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-07-27 08:42:14 +03:00
|
|
|
settings = gtk_settings_get_default();
|
2013-10-08 22:47:37 +04:00
|
|
|
g_object_get(settings, "gtk-menu-popup-delay", &delay, nullptr);
|
2012-08-22 19:56:38 +04:00
|
|
|
aResult = (int32_t)delay;
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-12-16 13:18:48 +04:00
|
|
|
case eIntID_TooltipDelay: {
|
|
|
|
aResult = 500;
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_MenusCanOverlapOSBar:
|
2002-04-27 20:26:10 +04:00
|
|
|
// we want XUL popups to be able to overlap the task bar.
|
2011-09-09 06:27:13 +04:00
|
|
|
aResult = 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_SkipNavigatingDisabledMenuItem:
|
|
|
|
aResult = 1;
|
2006-03-17 06:55:10 +03:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_DragThresholdX:
|
|
|
|
case eIntID_DragThresholdY: {
|
2003-05-02 22:20:38 +04:00
|
|
|
GtkWidget* box = gtk_hbox_new(FALSE, 5);
|
|
|
|
gint threshold = 0;
|
|
|
|
g_object_get(gtk_widget_get_settings(box), "gtk-dnd-drag-threshold",
|
|
|
|
&threshold, nullptr);
|
2011-05-16 13:07:37 +04:00
|
|
|
g_object_ref_sink(box);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
aResult = threshold;
|
2003-05-02 22:20:38 +04:00
|
|
|
} break;
|
2017-03-27 21:32:29 +03:00
|
|
|
case eIntID_ScrollArrowStyle: {
|
|
|
|
GtkWidget* scrollbar = GetWidget(MOZ_GTK_SCROLLBAR_HORIZONTAL);
|
|
|
|
aResult = ConvertGTKStepperStyleToMozillaScrollArrowStyle(scrollbar);
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
2017-03-27 21:32:29 +03:00
|
|
|
}
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_ScrollSliderStyle:
|
|
|
|
aResult = eScrollThumbStyle_Proportional;
|
2002-04-27 20:26:10 +04:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_TreeOpenDelay:
|
|
|
|
aResult = 1000;
|
2003-03-17 02:26:31 +03:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_TreeCloseDelay:
|
|
|
|
aResult = 1000;
|
2003-03-17 02:26:31 +03:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_TreeLazyScrollDelay:
|
|
|
|
aResult = 150;
|
2003-03-17 02:26:31 +03:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_TreeScrollDelay:
|
|
|
|
aResult = 100;
|
2003-03-17 02:26:31 +03:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_TreeScrollLinesMax:
|
|
|
|
aResult = 3;
|
2003-03-17 02:26:31 +03:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_DWMCompositor:
|
|
|
|
case eIntID_WindowsClassic:
|
|
|
|
case eIntID_WindowsDefaultTheme:
|
|
|
|
case eIntID_WindowsThemeIdentifier:
|
2013-07-01 20:02:29 +04:00
|
|
|
case eIntID_OperatingSystemVersionIdentifier:
|
2011-09-09 06:27:13 +04:00
|
|
|
aResult = 0;
|
2009-10-05 05:31:25 +04:00
|
|
|
res = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_TouchEnabled:
|
2015-04-29 23:29:34 +03:00
|
|
|
aResult = mozilla::widget::WidgetUtils::IsTouchDeviceSupportPresent();
|
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_MacGraphiteTheme:
|
|
|
|
aResult = 0;
|
2008-09-17 20:23:58 +04:00
|
|
|
res = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
break;
|
2013-03-18 17:24:54 +04:00
|
|
|
case eIntID_AlertNotificationOrigin:
|
|
|
|
aResult = NS_ALERT_TOP;
|
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_IMERawInputUnderlineStyle:
|
|
|
|
case eIntID_IMEConvertedTextUnderlineStyle:
|
|
|
|
aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
|
2007-08-17 00:35:18 +04:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_IMESelectedRawTextUnderlineStyle:
|
|
|
|
case eIntID_IMESelectedConvertedTextUnderline:
|
|
|
|
aResult = NS_STYLE_TEXT_DECORATION_STYLE_NONE;
|
2007-08-17 00:35:18 +04:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_SpellCheckerUnderlineStyle:
|
|
|
|
aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
|
2009-04-03 11:26:28 +04:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eIntID_MenuBarDrag:
|
2017-03-30 16:03:50 +03:00
|
|
|
EnsureInit();
|
2017-11-07 12:14:52 +03:00
|
|
|
aResult = mMenuSupportsDrag;
|
2010-07-17 12:11:54 +04:00
|
|
|
break;
|
2011-11-18 03:41:35 +04:00
|
|
|
case eIntID_ScrollbarButtonAutoRepeatBehavior:
|
|
|
|
aResult = 1;
|
|
|
|
break;
|
2013-04-09 23:44:01 +04:00
|
|
|
case eIntID_SwipeAnimationEnabled:
|
|
|
|
aResult = 0;
|
|
|
|
break;
|
2015-08-04 23:41:00 +03:00
|
|
|
case eIntID_ContextMenuOffsetVertical:
|
|
|
|
case eIntID_ContextMenuOffsetHorizontal:
|
|
|
|
aResult = 2;
|
|
|
|
break;
|
2017-10-17 22:17:32 +03:00
|
|
|
case eIntID_GTKCSDAvailable:
|
|
|
|
EnsureInit();
|
2017-11-07 12:14:52 +03:00
|
|
|
aResult = mCSDAvailable;
|
2017-10-17 22:17:32 +03:00
|
|
|
break;
|
2019-01-17 15:44:49 +03:00
|
|
|
case eIntID_GTKCSDHideTitlebarByDefault:
|
|
|
|
EnsureInit();
|
|
|
|
aResult = mCSDHideTitlebarByDefault;
|
|
|
|
break;
|
2017-10-17 22:17:32 +03:00
|
|
|
case eIntID_GTKCSDMaximizeButton:
|
|
|
|
EnsureInit();
|
2017-11-07 12:14:52 +03:00
|
|
|
aResult = mCSDMaximizeButton;
|
2017-10-17 22:17:32 +03:00
|
|
|
break;
|
|
|
|
case eIntID_GTKCSDMinimizeButton:
|
|
|
|
EnsureInit();
|
2017-11-07 12:14:52 +03:00
|
|
|
aResult = mCSDMinimizeButton;
|
2017-10-17 22:17:32 +03:00
|
|
|
break;
|
|
|
|
case eIntID_GTKCSDCloseButton:
|
|
|
|
EnsureInit();
|
2017-11-07 12:14:52 +03:00
|
|
|
aResult = mCSDCloseButton;
|
2017-10-17 22:17:32 +03:00
|
|
|
break;
|
2019-02-22 17:01:50 +03:00
|
|
|
case eIntID_GTKCSDTransparentBackground: {
|
|
|
|
// Enable transparent titlebar corners for titlebar mode.
|
|
|
|
GdkScreen* screen = gdk_screen_get_default();
|
|
|
|
aResult = gdk_screen_is_composited(screen)
|
|
|
|
? (nsWindow::GetSystemCSDSupportLevel() !=
|
|
|
|
nsWindow::CSD_SUPPORT_NONE)
|
|
|
|
: false;
|
2018-09-25 14:53:04 +03:00
|
|
|
break;
|
2019-02-22 17:01:50 +03:00
|
|
|
}
|
2019-01-18 16:52:29 +03:00
|
|
|
case eIntID_GTKCSDReversedPlacement:
|
|
|
|
EnsureInit();
|
|
|
|
aResult = mCSDReversedPlacement;
|
|
|
|
break;
|
2018-07-27 08:42:14 +03:00
|
|
|
case eIntID_PrefersReducedMotion: {
|
|
|
|
GtkSettings* settings;
|
|
|
|
gboolean enableAnimations;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-07-27 08:42:14 +03:00
|
|
|
settings = gtk_settings_get_default();
|
|
|
|
g_object_get(settings, "gtk-enable-animations", &enableAnimations,
|
|
|
|
nullptr);
|
|
|
|
aResult = enableAnimations ? 0 : 1;
|
|
|
|
break;
|
|
|
|
}
|
2019-02-21 11:12:35 +03:00
|
|
|
case eIntID_SystemUsesDarkTheme: {
|
2019-06-10 12:43:27 +03:00
|
|
|
EnsureInit();
|
|
|
|
aResult = mSystemUsesDarkTheme;
|
|
|
|
break;
|
2019-02-21 11:12:35 +03:00
|
|
|
}
|
2002-04-27 20:26:10 +04:00
|
|
|
default:
|
2011-09-09 06:27:13 +04:00
|
|
|
aResult = 0;
|
2002-04-27 20:26:10 +04:00
|
|
|
res = NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-12-10 20:37:36 +03:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
nsresult nsLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
|
2002-04-27 20:26:10 +04:00
|
|
|
nsresult res = NS_OK;
|
2011-09-09 06:27:13 +04:00
|
|
|
res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
|
2002-04-27 20:26:10 +04:00
|
|
|
if (NS_SUCCEEDED(res)) return res;
|
|
|
|
res = NS_OK;
|
|
|
|
|
|
|
|
switch (aID) {
|
2011-09-09 06:27:13 +04:00
|
|
|
case eFloatID_IMEUnderlineRelativeSize:
|
|
|
|
aResult = 1.0f;
|
2005-09-17 15:34:27 +04:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eFloatID_SpellCheckerUnderlineRelativeSize:
|
|
|
|
aResult = 1.0f;
|
2009-04-03 11:26:28 +04:00
|
|
|
break;
|
2011-09-09 06:27:13 +04:00
|
|
|
case eFloatID_CaretAspectRatio:
|
2017-03-30 16:03:50 +03:00
|
|
|
EnsureInit();
|
2017-11-07 12:14:52 +03:00
|
|
|
aResult = mCaretRatio;
|
2008-06-23 12:50:52 +04:00
|
|
|
break;
|
2002-04-27 20:26:10 +04:00
|
|
|
default:
|
2011-09-09 06:27:13 +04:00
|
|
|
aResult = -1.0;
|
2002-04-27 20:26:10 +04:00
|
|
|
res = NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-12-10 20:37:36 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-09-04 09:29:04 +03:00
|
|
|
static void GetSystemFontInfo(GtkStyleContext* aStyle, nsString* aFontName,
|
2012-02-21 03:19:48 +04:00
|
|
|
gfxFontStyle* aFontStyle) {
|
2018-04-23 17:52:20 +03:00
|
|
|
aFontStyle->style = FontSlantStyle::Normal();
|
2012-02-21 03:19:48 +04:00
|
|
|
|
2017-09-04 12:33:21 +03:00
|
|
|
// As in
|
|
|
|
// https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?h=3.22.19#n10333
|
2012-02-21 03:19:48 +04:00
|
|
|
PangoFontDescription* desc;
|
2017-09-04 09:29:04 +03:00
|
|
|
gtk_style_context_get(aStyle, gtk_style_context_get_state(aStyle), "font",
|
2017-09-04 12:33:21 +03:00
|
|
|
&desc, nullptr);
|
2012-02-21 03:19:48 +04:00
|
|
|
|
|
|
|
aFontStyle->systemFont = true;
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(quote, "\"");
|
|
|
|
NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
|
|
|
|
*aFontName = quote + family + quote;
|
|
|
|
|
2018-04-26 15:59:55 +03:00
|
|
|
aFontStyle->weight = FontWeight(pango_font_description_get_weight(desc));
|
2012-02-21 03:19:48 +04:00
|
|
|
|
|
|
|
// FIXME: Set aFontStyle->stretch correctly!
|
2018-04-23 17:52:20 +03:00
|
|
|
aFontStyle->stretch = FontStretch::Normal();
|
2012-02-21 03:19:48 +04:00
|
|
|
|
|
|
|
float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;
|
|
|
|
|
|
|
|
// |size| is now either pixels or pango-points (not Mozilla-points!)
|
|
|
|
|
|
|
|
if (!pango_font_description_get_size_is_absolute(desc)) {
|
|
|
|
// |size| is in pango-points, so convert to pixels.
|
2017-06-14 11:54:21 +03:00
|
|
|
size *= float(gfxPlatformGtk::GetFontScaleDPI()) / POINTS_PER_INCH_FLOAT;
|
2012-02-21 03:19:48 +04:00
|
|
|
}
|
|
|
|
|
2019-02-08 16:22:11 +03:00
|
|
|
// |size| is now pixels but not scaled for the hidpi displays,
|
2012-02-21 03:19:48 +04:00
|
|
|
aFontStyle->size = size;
|
|
|
|
|
|
|
|
pango_font_description_free(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
|
2019-02-08 16:22:11 +03:00
|
|
|
gfxFontStyle& aFontStyle) {
|
2012-02-21 03:19:48 +04:00
|
|
|
switch (aID) {
|
|
|
|
case eFont_Menu: // css2
|
|
|
|
case eFont_PullDownMenu: // css3
|
2017-09-04 09:29:04 +03:00
|
|
|
aFontName = mMenuFontName;
|
|
|
|
aFontStyle = mMenuFontStyle;
|
2018-01-18 13:52:59 +03:00
|
|
|
break;
|
2012-02-21 03:19:48 +04:00
|
|
|
|
|
|
|
case eFont_Field: // css3
|
|
|
|
case eFont_List: // css3
|
2017-09-04 09:29:04 +03:00
|
|
|
aFontName = mFieldFontName;
|
|
|
|
aFontStyle = mFieldFontStyle;
|
2018-01-18 13:52:59 +03:00
|
|
|
break;
|
2012-02-21 03:19:48 +04:00
|
|
|
|
|
|
|
case eFont_Button: // css3
|
2017-09-04 09:29:04 +03:00
|
|
|
aFontName = mButtonFontName;
|
|
|
|
aFontStyle = mButtonFontStyle;
|
2018-01-18 13:52:59 +03:00
|
|
|
break;
|
2012-02-21 03:19:48 +04:00
|
|
|
|
|
|
|
case eFont_Caption: // css2
|
|
|
|
case eFont_Icon: // css2
|
|
|
|
case eFont_MessageBox: // css2
|
|
|
|
case eFont_SmallCaption: // css2
|
|
|
|
case eFont_StatusBar: // css2
|
|
|
|
case eFont_Window: // css3
|
|
|
|
case eFont_Document: // css3
|
|
|
|
case eFont_Workspace: // css3
|
|
|
|
case eFont_Desktop: // css3
|
|
|
|
case eFont_Info: // css3
|
|
|
|
case eFont_Dialog: // css3
|
|
|
|
case eFont_Tooltips: // moz
|
|
|
|
case eFont_Widget: // moz
|
2017-09-04 09:29:04 +03:00
|
|
|
default:
|
|
|
|
aFontName = mDefaultFontName;
|
|
|
|
aFontStyle = mDefaultFontStyle;
|
2018-01-18 13:52:59 +03:00
|
|
|
break;
|
|
|
|
}
|
2019-02-08 16:22:11 +03:00
|
|
|
|
2018-01-18 13:52:59 +03:00
|
|
|
// Scale the font for the current monitor
|
2019-08-27 00:02:43 +03:00
|
|
|
double scaleFactor = StaticPrefs::layout_css_devPixelsPerPx();
|
2018-01-18 13:52:59 +03:00
|
|
|
if (scaleFactor > 0) {
|
2018-02-22 12:41:30 +03:00
|
|
|
aFontStyle.size *=
|
2019-02-08 16:22:11 +03:00
|
|
|
widget::ScreenHelperGTK::GetGTKMonitorScaleFactor() / scaleFactor;
|
2018-01-18 13:52:59 +03:00
|
|
|
} else {
|
2019-02-08 16:22:11 +03:00
|
|
|
// Convert gdk pixels to CSS pixels.
|
|
|
|
aFontStyle.size /= gfxPlatformGtk::GetFontScaleFactor();
|
2012-02-21 03:19:48 +04:00
|
|
|
}
|
2019-02-08 16:22:11 +03:00
|
|
|
|
2018-01-18 13:52:59 +03:00
|
|
|
return true;
|
2012-02-21 03:19:48 +04:00
|
|
|
}
|
|
|
|
|
2019-05-28 09:51:36 +03:00
|
|
|
// Check color contrast according to
|
|
|
|
// https://www.w3.org/TR/AERT/#color-contrast
|
|
|
|
static bool HasGoodContrastVisibility(GdkRGBA& aColor1, GdkRGBA& aColor2) {
|
|
|
|
int32_t luminosityDifference = NS_LUMINOSITY_DIFFERENCE(
|
|
|
|
GDK_RGBA_TO_NS_RGBA(aColor1), GDK_RGBA_TO_NS_RGBA(aColor2));
|
|
|
|
if (luminosityDifference < NS_SUFFICIENT_LUMINOSITY_DIFFERENCE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double colorDifference = std::abs(aColor1.red - aColor2.red) +
|
|
|
|
std::abs(aColor1.green - aColor2.green) +
|
|
|
|
std::abs(aColor1.blue - aColor2.blue);
|
|
|
|
return (colorDifference * 255.0 > 500.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the foreground/background colors match with default white/black
|
|
|
|
// html page colors.
|
|
|
|
static bool IsGtkThemeCompatibleWithHTMLColors() {
|
|
|
|
GdkRGBA white = {1.0, 1.0, 1.0};
|
|
|
|
GdkRGBA black = {0.0, 0.0, 0.0};
|
|
|
|
|
|
|
|
GtkStyleContext* style = GetStyleContext(MOZ_GTK_WINDOW);
|
|
|
|
|
|
|
|
GdkRGBA textColor;
|
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &textColor);
|
|
|
|
|
|
|
|
// Theme text color and default white html page background
|
|
|
|
if (!HasGoodContrastVisibility(textColor, white)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkRGBA backgroundColor;
|
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL,
|
|
|
|
&backgroundColor);
|
|
|
|
|
|
|
|
// Theme background color and default white html page background
|
|
|
|
if (HasGoodContrastVisibility(backgroundColor, white)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Theme background color and default black text color
|
|
|
|
return HasGoodContrastVisibility(backgroundColor, black);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ConfigureContentGtkTheme() {
|
2019-10-08 11:53:40 +03:00
|
|
|
LOG(("ConfigureContentGtkTheme\n"));
|
|
|
|
|
2019-05-28 09:51:36 +03:00
|
|
|
GtkSettings* settings = gtk_settings_get_for_screen(gdk_screen_get_default());
|
|
|
|
nsAutoCString contentThemeName;
|
|
|
|
mozilla::Preferences::GetCString("widget.content.gtk-theme-override",
|
|
|
|
contentThemeName);
|
|
|
|
if (!contentThemeName.IsEmpty()) {
|
2019-10-08 11:53:40 +03:00
|
|
|
LOG(
|
|
|
|
(" widget.content.gtk-theme-override is set to %s, setting by "
|
|
|
|
"gtk-theme-name\n",
|
|
|
|
contentThemeName.get()));
|
2019-05-28 09:51:36 +03:00
|
|
|
g_object_set(settings, "gtk-theme-name", contentThemeName.get(), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dark theme is active but user explicitly enables it so we're done now.
|
|
|
|
if (mozilla::Preferences::GetBool("widget.content.allow-gtk-dark-theme",
|
|
|
|
false)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to disable 'gtk-application-prefer-dark-theme' first...
|
2019-05-23 10:12:58 +03:00
|
|
|
const gchar* dark_theme_setting = "gtk-application-prefer-dark-theme";
|
|
|
|
gboolean darkThemeDefault;
|
|
|
|
g_object_get(settings, dark_theme_setting, &darkThemeDefault, nullptr);
|
|
|
|
if (darkThemeDefault) {
|
2019-10-08 11:53:40 +03:00
|
|
|
LOG((" disabling gtk-application-prefer-dark-theme\n"));
|
2019-05-28 09:51:36 +03:00
|
|
|
g_object_set(settings, dark_theme_setting, FALSE, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ...and use a default Gtk theme as a fallback.
|
|
|
|
if (contentThemeName.IsEmpty() && !IsGtkThemeCompatibleWithHTMLColors()) {
|
2019-10-08 11:53:40 +03:00
|
|
|
LOG((" Non-compatible drark theme, default to Adwaita\n"));
|
2019-05-28 09:51:36 +03:00
|
|
|
g_object_set(settings, "gtk-theme-name", "Adwaita", nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 16:03:50 +03:00
|
|
|
void nsLookAndFeel::EnsureInit() {
|
2013-05-30 03:26:40 +04:00
|
|
|
GdkColor colorValue;
|
|
|
|
GdkColor* colorValuePtr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-06-10 12:43:27 +03:00
|
|
|
if (mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-24 19:09:55 +04:00
|
|
|
|
2017-04-04 23:30:12 +03:00
|
|
|
// Gtk manages a screen's CSS in the settings object so we
|
|
|
|
// ask Gtk to create it explicitly. Otherwise we may end up
|
2014-02-24 19:09:55 +04:00
|
|
|
// with wrong color theme, see Bug 972382
|
2019-06-10 12:43:27 +03:00
|
|
|
GdkScreen* screen = gdk_screen_get_default();
|
|
|
|
if (MOZ_UNLIKELY(!screen)) {
|
|
|
|
NS_WARNING("EnsureInit: No screen");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GtkSettings* settings = gtk_settings_get_for_screen(screen);
|
2019-03-16 18:17:49 +03:00
|
|
|
if (MOZ_UNLIKELY(!settings)) {
|
|
|
|
NS_WARNING("EnsureInit: No settings");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-10 12:43:27 +03:00
|
|
|
mInitialized = true;
|
|
|
|
|
|
|
|
// gtk does non threadsafe refcounting
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
GdkRGBA color;
|
|
|
|
GtkStyleContext* style;
|
|
|
|
|
|
|
|
// It seems GTK doesn't have an API to query if the current theme is
|
|
|
|
// "light" or "dark", so we synthesize it from the CSS2 Window/WindowText
|
|
|
|
// colors instead, by comparing their luminosity.
|
|
|
|
GdkRGBA bg, fg;
|
|
|
|
style = GetStyleContext(MOZ_GTK_WINDOW);
|
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &bg);
|
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &fg);
|
|
|
|
mSystemUsesDarkTheme =
|
|
|
|
(RelativeLuminanceUtils::Compute(GDK_RGBA_TO_NS_RGBA(bg)) <
|
|
|
|
RelativeLuminanceUtils::Compute(GDK_RGBA_TO_NS_RGBA(fg)));
|
|
|
|
|
2013-05-30 03:26:40 +04:00
|
|
|
if (XRE_IsContentProcess()) {
|
2019-10-08 11:53:40 +03:00
|
|
|
LOG(("nsLookAndFeel::EnsureInit() [%p] Content process\n", (void*)this));
|
2019-05-28 09:51:36 +03:00
|
|
|
// Dark themes interacts poorly with widget styling (see bug 1216658).
|
|
|
|
// We disable dark themes by default for web content
|
|
|
|
// but allow user to overide it by prefs.
|
|
|
|
ConfigureContentGtkTheme();
|
2019-10-08 11:53:40 +03:00
|
|
|
} else {
|
|
|
|
LOG(("nsLookAndFeel::EnsureInit() [%p] Crome process\n", (void*)this));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-09-04 09:29:04 +03:00
|
|
|
// The label is not added to a parent widget, but shared for constructing
|
|
|
|
// different style contexts. The node hierarchy is constructed only on
|
|
|
|
// the label style context.
|
|
|
|
GtkWidget* labelWidget = gtk_label_new("M");
|
|
|
|
g_object_ref_sink(labelWidget);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-30 03:26:40 +04:00
|
|
|
// Scrollbar colors
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMozScrollbar = GDK_RGBA_TO_NS_RGBA(color);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-30 03:26:40 +04:00
|
|
|
// Window colors
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_WINDOW);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMozWindowBackground = GDK_RGBA_TO_NS_RGBA(color);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMozWindowText = GDK_RGBA_TO_NS_RGBA(color);
|
2017-09-19 23:00:28 +03:00
|
|
|
gtk_style_context_get_border_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMozWindowActiveBorder = GDK_RGBA_TO_NS_RGBA(color);
|
2016-12-01 13:09:00 +03:00
|
|
|
gtk_style_context_get_border_color(style, GTK_STATE_FLAG_INSENSITIVE, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMozWindowInactiveBorder = GDK_RGBA_TO_NS_RGBA(color);
|
2016-12-01 13:09:00 +03:00
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_INSENSITIVE,
|
2018-11-30 13:46:48 +03:00
|
|
|
&color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMozWindowInactiveCaption = GDK_RGBA_TO_NS_RGBA(color);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_WINDOW_CONTAINER);
|
2018-11-30 13:46:48 +03:00
|
|
|
{
|
2017-09-04 09:29:04 +03:00
|
|
|
GtkStyleContext* labelStyle = CreateStyleForWidget(labelWidget, style);
|
|
|
|
GetSystemFontInfo(labelStyle, &mDefaultFontName, &mDefaultFontStyle);
|
|
|
|
g_object_unref(labelStyle);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2013-05-30 03:26:40 +04:00
|
|
|
|
|
|
|
// tooltip foreground and background
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_TOOLTIP);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mInfoBackground = GDK_RGBA_TO_NS_RGBA(color);
|
2016-11-24 05:14:58 +03:00
|
|
|
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL);
|
2016-11-24 05:14:58 +03:00
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mInfoText = GDK_RGBA_TO_NS_RGBA(color);
|
2013-05-30 03:26:40 +04:00
|
|
|
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_MENUITEM);
|
2016-12-01 13:09:00 +03:00
|
|
|
{
|
|
|
|
GtkStyleContext* accelStyle =
|
|
|
|
CreateStyleForWidget(gtk_accel_label_new("M"), style);
|
2017-09-04 09:29:04 +03:00
|
|
|
|
|
|
|
GetSystemFontInfo(accelStyle, &mMenuFontName, &mMenuFontStyle);
|
|
|
|
|
2016-12-01 13:09:00 +03:00
|
|
|
gtk_style_context_get_color(accelStyle, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMenuText = GDK_RGBA_TO_NS_RGBA(color);
|
2016-12-01 13:09:00 +03:00
|
|
|
gtk_style_context_get_color(accelStyle, GTK_STATE_FLAG_INSENSITIVE, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMenuTextInactive = GDK_RGBA_TO_NS_RGBA(color);
|
2016-12-01 13:09:00 +03:00
|
|
|
g_object_unref(accelStyle);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_MENUPOPUP);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMenuBackground = GDK_RGBA_TO_NS_RGBA(color);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_MENUITEM);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_PRELIGHT,
|
2018-11-30 13:46:48 +03:00
|
|
|
&color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMenuHover = GDK_RGBA_TO_NS_RGBA(color);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMenuHoverText = GDK_RGBA_TO_NS_RGBA(color);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-04-27 20:26:10 +04:00
|
|
|
GtkWidget* parent = gtk_fixed_new();
|
|
|
|
GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP);
|
2008-04-12 16:13:32 +04:00
|
|
|
GtkWidget* treeView = gtk_tree_view_new();
|
2008-07-11 22:34:53 +04:00
|
|
|
GtkWidget* linkButton = gtk_link_button_new("http://example.com/");
|
2009-06-15 01:58:14 +04:00
|
|
|
GtkWidget* menuBar = gtk_menu_bar_new();
|
2016-05-09 05:17:00 +03:00
|
|
|
GtkWidget* menuBarItem = gtk_menu_item_new();
|
2010-04-02 06:09:05 +04:00
|
|
|
GtkWidget* entry = gtk_entry_new();
|
2015-10-30 11:08:00 +03:00
|
|
|
GtkWidget* textView = gtk_text_view_new();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-04-12 16:13:32 +04:00
|
|
|
gtk_container_add(GTK_CONTAINER(parent), treeView);
|
2008-07-11 22:34:53 +04:00
|
|
|
gtk_container_add(GTK_CONTAINER(parent), linkButton);
|
2009-06-15 01:58:14 +04:00
|
|
|
gtk_container_add(GTK_CONTAINER(parent), menuBar);
|
2016-05-09 05:17:00 +03:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), menuBarItem);
|
2002-04-27 20:26:10 +04:00
|
|
|
gtk_container_add(GTK_CONTAINER(window), parent);
|
2010-04-02 06:09:05 +04:00
|
|
|
gtk_container_add(GTK_CONTAINER(parent), entry);
|
2015-10-30 11:08:00 +03:00
|
|
|
gtk_container_add(GTK_CONTAINER(parent), textView);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-30 11:08:00 +03:00
|
|
|
// Text colors
|
2017-01-03 03:08:07 +03:00
|
|
|
GdkRGBA bgColor;
|
|
|
|
// If the text window background is translucent, then the background of
|
|
|
|
// the textview root node is visible.
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_TEXT_VIEW);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL,
|
2017-01-03 03:08:07 +03:00
|
|
|
&bgColor);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_TEXT_VIEW_TEXT);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-01-03 03:08:07 +03:00
|
|
|
ApplyColorOver(color, &bgColor);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMozFieldBackground = GDK_RGBA_TO_NS_RGBA(bgColor);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMozFieldText = GDK_RGBA_TO_NS_RGBA(color);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-30 11:08:00 +03:00
|
|
|
// Selected text and background
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_background_color(
|
2018-11-30 13:46:48 +03:00
|
|
|
style,
|
2015-10-30 11:08:00 +03:00
|
|
|
static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED |
|
|
|
|
GTK_STATE_FLAG_SELECTED),
|
2018-11-30 13:46:48 +03:00
|
|
|
&color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mTextSelectedBackground = GDK_RGBA_TO_NS_RGBA(color);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_color(
|
2018-11-30 13:46:48 +03:00
|
|
|
style,
|
2015-10-30 11:08:00 +03:00
|
|
|
static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED |
|
|
|
|
GTK_STATE_FLAG_SELECTED),
|
2018-11-30 13:46:48 +03:00
|
|
|
&color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mTextSelectedText = GDK_RGBA_TO_NS_RGBA(color);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-01 13:09:00 +03:00
|
|
|
// Button text color
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_BUTTON);
|
2018-11-30 13:46:48 +03:00
|
|
|
{
|
2017-09-04 09:29:04 +03:00
|
|
|
GtkStyleContext* labelStyle = CreateStyleForWidget(labelWidget, style);
|
|
|
|
GetSystemFontInfo(labelStyle, &mButtonFontName, &mButtonFontStyle);
|
|
|
|
g_object_unref(labelStyle);
|
2016-12-01 13:09:00 +03:00
|
|
|
}
|
2013-05-30 03:26:40 +04:00
|
|
|
|
2019-05-24 11:51:48 +03:00
|
|
|
gtk_style_context_get_border_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
|
|
|
mButtonDefault = GDK_RGBA_TO_NS_RGBA(color);
|
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
|
|
|
mButtonText = GDK_RGBA_TO_NS_RGBA(color);
|
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
|
|
|
|
mButtonHoverText = GDK_RGBA_TO_NS_RGBA(color);
|
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_ACTIVE, &color);
|
|
|
|
mButtonActiveText = GDK_RGBA_TO_NS_RGBA(color);
|
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_PRELIGHT,
|
|
|
|
&color);
|
|
|
|
mButtonHoverFace = GDK_RGBA_TO_NS_RGBA(color);
|
|
|
|
|
2015-05-05 16:08:00 +03:00
|
|
|
// Combobox text color
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_COMBOBOX_ENTRY_TEXTAREA);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mComboBoxText = GDK_RGBA_TO_NS_RGBA(color);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-19 13:38:59 +03:00
|
|
|
// Menubar text and hover text colors
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_MENUBARITEM);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMenuBarText = GDK_RGBA_TO_NS_RGBA(color);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mMenuBarHoverText = GDK_RGBA_TO_NS_RGBA(color);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-30 03:26:40 +04:00
|
|
|
// GTK's guide to fancy odd row background colors:
|
|
|
|
// 1) Check if a theme explicitly defines an odd row color
|
|
|
|
// 2) If not, check if it defines an even row color, and darken it
|
|
|
|
// slightly by a hardcoded value (gtkstyle.c)
|
|
|
|
// 3) If neither are defined, take the base background color and
|
|
|
|
// darken that by a hardcoded value
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_TREEVIEW);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-30 03:26:40 +04:00
|
|
|
// Get odd row background color
|
|
|
|
gtk_style_context_save(style);
|
|
|
|
gtk_style_context_add_region(style, GTK_STYLE_REGION_ROW, GTK_REGION_ODD);
|
|
|
|
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mOddCellBackground = GDK_RGBA_TO_NS_RGBA(color);
|
2013-05-30 03:26:40 +04:00
|
|
|
gtk_style_context_restore(style);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-06-29 21:23:03 +03:00
|
|
|
// Compute cell highlight colors
|
|
|
|
InitCellHighlightColors();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-21 08:07:48 +03:00
|
|
|
// GtkFrame has a "border" subnode on which Adwaita draws the border.
|
|
|
|
// Some themes do not draw on this node but draw a border on the widget
|
|
|
|
// root node, so check the root node if no border is found on the border
|
|
|
|
// node.
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_FRAME_BORDER);
|
2016-11-21 08:07:48 +03:00
|
|
|
bool themeUsesColors =
|
2017-11-07 12:14:52 +03:00
|
|
|
GetBorderColors(style, &mFrameOuterLightBorder, &mFrameInnerDarkBorder);
|
2016-11-21 08:07:48 +03:00
|
|
|
if (!themeUsesColors) {
|
2017-09-05 00:16:01 +03:00
|
|
|
style = GetStyleContext(MOZ_GTK_FRAME);
|
2017-11-07 12:14:52 +03:00
|
|
|
GetBorderColors(style, &mFrameOuterLightBorder, &mFrameInnerDarkBorder);
|
2016-11-21 08:07:48 +03:00
|
|
|
}
|
2016-07-25 17:32:12 +03:00
|
|
|
|
2015-08-19 22:42:17 +03:00
|
|
|
// GtkInfoBar
|
2016-07-19 07:03:00 +03:00
|
|
|
// TODO - Use WidgetCache for it?
|
2015-09-29 20:32:00 +03:00
|
|
|
GtkWidget* infoBar = gtk_info_bar_new();
|
|
|
|
GtkWidget* infoBarContent =
|
|
|
|
gtk_info_bar_get_content_area(GTK_INFO_BAR(infoBar));
|
|
|
|
GtkWidget* infoBarLabel = gtk_label_new(nullptr);
|
|
|
|
gtk_container_add(GTK_CONTAINER(parent), infoBar);
|
|
|
|
gtk_container_add(GTK_CONTAINER(infoBarContent), infoBarLabel);
|
|
|
|
style = gtk_widget_get_style_context(infoBarLabel);
|
2015-08-19 22:42:17 +03:00
|
|
|
gtk_style_context_add_class(style, GTK_STYLE_CLASS_INFO);
|
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mInfoBarText = GDK_RGBA_TO_NS_RGBA(color);
|
2013-05-30 03:26:40 +04:00
|
|
|
// Some themes have a unified menu bar, and support window dragging on it
|
|
|
|
gboolean supports_menubar_drag = FALSE;
|
|
|
|
GParamSpec* param_spec = gtk_widget_class_find_style_property(
|
|
|
|
GTK_WIDGET_GET_CLASS(menuBar), "window-dragging");
|
|
|
|
if (param_spec) {
|
|
|
|
if (g_type_is_a(G_PARAM_SPEC_VALUE_TYPE(param_spec), G_TYPE_BOOLEAN)) {
|
|
|
|
gtk_widget_style_get(menuBar, "window-dragging", &supports_menubar_drag,
|
2013-10-08 22:47:37 +04:00
|
|
|
nullptr);
|
2013-05-30 03:26:40 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-11-07 12:14:52 +03:00
|
|
|
mMenuSupportsDrag = supports_menubar_drag;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-25 11:30:28 +03:00
|
|
|
if (gtk_check_version(3, 12, 0) == nullptr) {
|
|
|
|
// TODO: It returns wrong color for themes which
|
|
|
|
// sets link color for GtkLabel only as we query
|
|
|
|
// GtkLinkButton style here.
|
|
|
|
style = gtk_widget_get_style_context(linkButton);
|
|
|
|
gtk_style_context_get_color(style, GTK_STATE_FLAG_LINK, &color);
|
2017-11-07 12:14:52 +03:00
|
|
|
mNativeHyperLinkText = GDK_RGBA_TO_NS_RGBA(color);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-08-25 11:30:28 +03:00
|
|
|
colorValuePtr = nullptr;
|
|
|
|
gtk_widget_style_get(linkButton, "link-color", &colorValuePtr, nullptr);
|
|
|
|
if (colorValuePtr) {
|
|
|
|
colorValue = *colorValuePtr; // we can't pass deref pointers to
|
|
|
|
// GDK_COLOR_TO_NS_RGB
|
2017-11-07 12:14:52 +03:00
|
|
|
mNativeHyperLinkText = GDK_COLOR_TO_NS_RGB(colorValue);
|
2017-08-25 11:30:28 +03:00
|
|
|
gdk_color_free(colorValuePtr);
|
2017-09-04 08:36:17 +03:00
|
|
|
} else {
|
2017-11-07 12:14:52 +03:00
|
|
|
mNativeHyperLinkText = NS_RGB(0x00, 0x00, 0xEE);
|
2008-07-11 22:34:53 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2006-10-24 00:48:05 +04:00
|
|
|
// invisible character styles
|
|
|
|
guint value;
|
2013-10-08 22:47:37 +04:00
|
|
|
g_object_get(entry, "invisible-char", &value, nullptr);
|
2017-11-07 12:14:52 +03:00
|
|
|
mInvisibleCharacter = char16_t(value);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-06-23 12:50:52 +04:00
|
|
|
// caret styles
|
2017-08-25 11:30:28 +03:00
|
|
|
gtk_widget_style_get(entry, "cursor-aspect-ratio", &mCaretRatio, nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-04-30 11:24:16 +03:00
|
|
|
gint blink_time;
|
|
|
|
gboolean blink;
|
|
|
|
g_object_get(settings, "gtk-cursor-blink-time", &blink_time,
|
|
|
|
"gtk-cursor-blink", &blink, nullptr);
|
|
|
|
mCaretBlinkTime = blink ? (int32_t)blink_time : 0;
|
|
|
|
|
2017-09-04 09:29:04 +03:00
|
|
|
GetSystemFontInfo(gtk_widget_get_style_context(entry), &mFieldFontName,
|
|
|
|
&mFieldFontStyle);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-04-02 06:09:05 +04:00
|
|
|
gtk_widget_destroy(window);
|
2017-09-04 09:29:04 +03:00
|
|
|
g_object_unref(labelWidget);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-22 15:22:38 +03:00
|
|
|
mCSDAvailable =
|
|
|
|
nsWindow::GetSystemCSDSupportLevel() != nsWindow::CSD_SUPPORT_NONE;
|
2019-01-17 15:44:49 +03:00
|
|
|
mCSDHideTitlebarByDefault = nsWindow::HideTitlebarByDefault();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-23 23:28:37 +03:00
|
|
|
mCSDCloseButton = false;
|
|
|
|
mCSDMinimizeButton = false;
|
|
|
|
mCSDMaximizeButton = false;
|
2008-07-11 22:34:53 +04:00
|
|
|
|
2006-10-24 00:48:05 +04:00
|
|
|
// We need to initialize whole CSD config explicitly because it's queried
|
2008-06-23 12:50:52 +04:00
|
|
|
// as -moz-gtk* media features.
|
2017-09-04 09:29:04 +03:00
|
|
|
WidgetNodeType buttonLayout[TOOLBAR_BUTTONS];
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-01-18 16:52:29 +03:00
|
|
|
int activeButtons = GetGtkHeaderBarButtonLayout(buttonLayout, TOOLBAR_BUTTONS,
|
|
|
|
&mCSDReversedPlacement);
|
2018-02-23 23:28:37 +03:00
|
|
|
for (int i = 0; i < activeButtons; i++) {
|
|
|
|
switch (buttonLayout[i]) {
|
|
|
|
case MOZ_GTK_HEADER_BAR_BUTTON_MINIMIZE:
|
|
|
|
mCSDMinimizeButton = true;
|
|
|
|
break;
|
|
|
|
case MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE:
|
|
|
|
mCSDMaximizeButton = true;
|
|
|
|
break;
|
|
|
|
case MOZ_GTK_HEADER_BAR_BUTTON_CLOSE:
|
|
|
|
mCSDCloseButton = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2006-10-24 00:48:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// virtual
|
2011-09-09 06:27:13 +04:00
|
|
|
char16_t nsLookAndFeel::GetPasswordCharacterImpl() {
|
2017-03-30 16:03:50 +03:00
|
|
|
EnsureInit();
|
2017-11-07 12:14:52 +03:00
|
|
|
return mInvisibleCharacter;
|
2001-12-10 20:37:36 +03:00
|
|
|
}
|
2004-09-17 10:27:01 +04:00
|
|
|
|
2011-09-28 00:18:51 +04:00
|
|
|
bool nsLookAndFeel::GetEchoPasswordImpl() { return false; }
|