Bug 238854 [gtk2] Changing GNOME2 theme doesn't apply until restarting Mozilla

r=bryner, sr=dbaron, patch=ginn.chen@sun.com
This commit is contained in:
kyle.yuan%sun.com 2004-09-17 06:27:01 +00:00
Родитель 692a07c765
Коммит faef6bd540
9 изменённых файлов: 96 добавлений и 16 удалений

Просмотреть файл

@ -672,15 +672,21 @@ int nsDeviceContextGTK::prefChanged(const char *aPref, void *aClosure)
// If this pref changes, we have to clear our cache of stored system
// fonts.
if (gSystemFonts) {
delete gSystemFonts;
gSystemFonts = nsnull;
}
ClearCachedSystemFonts();
}
return 0;
}
void nsDeviceContextGTK::ClearCachedSystemFonts()
{
//clear our cache of stored system fonts
if (gSystemFonts) {
delete gSystemFonts;
gSystemFonts = nsnull;
}
}
#define DEFAULT_TWIP_FONT_SIZE 240
nsSystemFontsGTK::nsSystemFontsGTK(float aPixelsToTwips)

Просмотреть файл

@ -87,6 +87,7 @@ public:
NS_IMETHOD GetDepth(PRUint32& aDepth);
static int prefChanged(const char *aPref, void *aClosure);
static void ClearCachedSystemFonts();
protected:
nsresult SetDPI(PRInt32 aPrefDPI);

Просмотреть файл

@ -39,6 +39,7 @@
#include "nsNativeThemeGTK.h"
#include "nsThemeConstants.h"
#include "nsDrawingSurfaceGTK.h"
#include "nsDeviceContextGTK.h"
#include "gtkdrawing.h"
#include "nsIObserverService.h"
@ -644,6 +645,8 @@ nsNativeThemeGTK::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType,
NS_IMETHODIMP
nsNativeThemeGTK::ThemeChanged()
{
nsDeviceContextGTK::ClearCachedSystemFonts();
memset(mDisabledWidgetTypes, 0, sizeof(mDisabledWidgetTypes));
return NS_OK;
}

Просмотреть файл

@ -1146,9 +1146,12 @@ nsPresContext::ThemeChanged()
// Clear all cached nsILookAndFeel colors.
if (mLookAndFeel)
mLookAndFeel->LookAndFeelChanged();
if (mShell)
mShell->ReconstructStyleData();
// We have to clear style data because the assumption of style rule
// immutability has been violated since any style rule that uses
// system colors or fonts (and probably -moz-appearance as well) has
// changed.
nsPresContext::ClearStyleDataAndReflow();
}
void

Просмотреть файл

@ -1146,9 +1146,12 @@ nsPresContext::ThemeChanged()
// Clear all cached nsILookAndFeel colors.
if (mLookAndFeel)
mLookAndFeel->LookAndFeelChanged();
if (mShell)
mShell->ReconstructStyleData();
// We have to clear style data because the assumption of style rule
// immutability has been violated since any style rule that uses
// system colors or fonts (and probably -moz-appearance as well) has
// changed.
nsPresContext::ClearStyleDataAndReflow();
}
void

Просмотреть файл

@ -61,11 +61,7 @@ PRBool nsLookAndFeel::sColorsInitialized = PR_FALSE;
//-------------------------------------------------------------------------
nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
{
mWidget = gtk_invisible_new();
gtk_object_ref(GTK_OBJECT(mWidget));
gtk_object_sink(GTK_OBJECT(mWidget));
gtk_widget_ensure_style(mWidget);
mStyle = gtk_widget_get_style(mWidget);
InitWidget();
if (!sColorsInitialized)
InitColors();
@ -522,3 +518,27 @@ nsLookAndFeel::InitColors()
gtk_widget_destroy(window);
}
void
nsLookAndFeel::InitWidget()
{
mWidget = gtk_invisible_new();
gtk_object_ref(GTK_OBJECT(mWidget));
gtk_object_sink(GTK_OBJECT(mWidget));
gtk_widget_ensure_style(mWidget);
mStyle = gtk_widget_get_style(mWidget);
}
NS_IMETHODIMP
nsLookAndFeel::LookAndFeelChanged()
{
nsXPLookAndFeel::LookAndFeelChanged();
if (mWidget)
gtk_widget_unref(mWidget);
InitWidget();
InitColors();
return NS_OK;
}

Просмотреть файл

@ -51,6 +51,7 @@ public:
nsresult NativeGetColor(const nsColorID aID, nscolor &aColor);
NS_IMETHOD GetMetric(const nsMetricID aID, PRInt32 & aMetric);
NS_IMETHOD GetMetric(const nsMetricFloatID aID, float & aMetric);
NS_IMETHOD LookAndFeelChanged();
protected:
GtkStyle *mStyle;
@ -69,6 +70,7 @@ protected:
static nscolor sButtonInnerDarkBorder;
static void InitColors();
inline void InitWidget();
};
#endif

Просмотреть файл

@ -137,6 +137,9 @@ static gboolean window_state_event_cb (GtkWidget *widget,
GdkEventWindowState *event);
static gboolean property_notify_event_cb (GtkWidget *widget,
GdkEventProperty *event);
static void style_set_cb (GtkWidget *widget,
GtkStyle *previous_style,
gpointer data);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@ -1718,6 +1721,32 @@ nsWindow::OnWindowStateEvent(GtkWidget *aWidget, GdkEventWindowState *aEvent)
DispatchEvent(&event, status);
}
void
nsWindow::ThemeChanged()
{
nsGUIEvent event(NS_THEMECHANGED, this);
nsEventStatus status = nsEventStatus_eIgnore;
DispatchEvent(&event, status);
if (!mDrawingarea)
return;
// Dispatch NS_THEMECHANGED to all child windows
GList *children =
gdk_window_peek_children(mDrawingarea->inner_window);
while (children) {
GdkWindow *gdkWin = GDK_WINDOW(children->data);
nsWindow *win = (nsWindow*) g_object_get_data(G_OBJECT(gdkWin),
"nsWindow");
if (win && win != this) // guard against infinite recursion
win->ThemeChanged();
children = children->next;
}
}
gboolean
nsWindow::OnDragMotionEvent(GtkWidget *aWidget,
GdkDragContext *aDragContext,
@ -2216,6 +2245,8 @@ nsWindow::NativeCreate(nsIWidget *aParent,
G_CALLBACK(window_state_event_cb), NULL);
g_signal_connect(G_OBJECT(mShell), "property_notify_event",
G_CALLBACK(property_notify_event_cb), NULL);
g_signal_connect(G_OBJECT(mShell), "style_set",
G_CALLBACK(style_set_cb), NULL);
}
if (mContainer) {
@ -3720,6 +3751,15 @@ property_notify_event_cb (GtkWidget *widget, GdkEventProperty *event)
return FALSE;
}
/* static */
void
style_set_cb (GtkWidget *widget, GtkStyle *previous_style, gpointer data)
{
nsWindow *window = get_window_for_gtk_widget(widget);
if (window)
window->ThemeChanged();
}
//////////////////////////////////////////////////////////////////////
// These are all of our drag and drop operations

Просмотреть файл

@ -246,6 +246,8 @@ public:
void SetNonXEmbedPluginFocus(void);
void LoseNonXEmbedPluginFocus(void);
void ThemeChanged(void);
Window mOldFocusWindow;
static guint32 mLastButtonPressTime;