summaryrefslogtreecommitdiff
path: root/firefox-1.5-theme-change.patch
blob: 375f06f340ba42eb7ec18f200a6aaf9f1e659349 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
Index: layout/base/nsPresContext.cpp
===================================================================
RCS file: /cvsroot/mozilla/layout/base/nsPresContext.cpp,v
retrieving revision 3.288.12.2.4.1
diff -d -u -p -r3.288.12.2.4.1 nsPresContext.cpp
--- layout/base/nsPresContext.cpp	21 Apr 2006 23:30:50 -0000	3.288.12.2.4.1
+++ layout/base/nsPresContext.cpp	26 Sep 2006 19:26:40 -0000
@@ -73,6 +73,9 @@
 #include "nsIDOMDocument.h"
 #include "nsAutoPtr.h"
 #include "nsEventStateManager.h"
+#include "nsIEventQueue.h"
+#include "nsIEventQueueService.h"
+
 #ifdef IBMBIDI
 #include "nsBidiPresUtils.h"
 #endif // IBMBIDI
@@ -267,6 +270,7 @@ nsPresContext::~nsPresContext()
   NS_IF_RELEASE(mDeviceContext);
   NS_IF_RELEASE(mLookAndFeel);
   NS_IF_RELEASE(mLangGroup);
+  NS_IF_RELEASE(mEventQueueService);
 }
 
 NS_IMPL_ISUPPORTS2(nsPresContext, nsPresContext, nsIObserver)
@@ -285,6 +289,17 @@ static const char* const kGenericFont[] 
   ".fantasy."
 };
 
+// Set to true when LookAndFeelChanged needs to be called.  This is used
+// because the look and feel is a service, so there's no need to notify it from
+// more than one prescontext.
+static PRBool sLookAndFeelChanged;
+
+// Set to true when ThemeChanged needs to be called on mTheme.  This is used
+// because mTheme is a service, so there's no need to notify it from more than
+// one prescontext.
+static PRBool sThemeChanged;
+
+
 void
 nsPresContext::GetFontPreferences()
 {
@@ -709,6 +724,9 @@ nsPresContext::Init(nsIDeviceContext* aD
                                        this);
 #endif
 
+  rv = CallGetService(NS_EVENTQUEUESERVICE_CONTRACTID, &mEventQueueService);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   // Initialize our state from the user preferences
   GetUserPreferences();
 
@@ -1180,33 +1198,126 @@ nsPresContext::GetTheme()
 void
 nsPresContext::ThemeChanged()
 {
+  if (!mPendingThemeChanged) {
+    sLookAndFeelChanged = PR_TRUE;
+    sThemeChanged = PR_TRUE;
+
+    nsCOMPtr<nsIEventQueue> eventQ;
+    mEventQueueService->
+      GetSpecialEventQueue(nsIEventQueueService::UI_THREAD_EVENT_QUEUE,
+                           getter_AddRefs(eventQ));
+    if (!eventQ) {
+      return;
+    }
+
+    PLEvent* evt = new PLEvent();
+    if (!evt) {
+      return;
+    }
+
+    PL_InitEvent(evt, this, nsPresContext::ThemeChangedInternal,
+                 nsPresContext::DestroyThemeChangeEvt);
+
+    // After this point, event destruction will release |this|
+    NS_ADDREF_THIS();
+
+    nsresult rv = eventQ->PostEvent(evt);
+    if (NS_FAILED(rv)) {
+      PL_DestroyEvent(evt);
+    } else {
+      mPendingThemeChanged = PR_TRUE;
+    }
+  }    
+}
+
+void* PR_CALLBACK
+nsPresContext::ThemeChangedInternal(PLEvent *aEvent)
+{
+  nsPresContext* pc = NS_STATIC_CAST(nsPresContext*, aEvent->owner);
+
+  pc->mPendingThemeChanged = PR_FALSE;
+
   // Tell the theme that it changed, so it can flush any handles to stale theme
   // data.
-  if (mTheme)
-    mTheme->ThemeChanged();
+  if (pc->mTheme && sThemeChanged) {
+    pc->mTheme->ThemeChanged();
+    sThemeChanged = PR_FALSE;
+  }
 
   // Clear all cached nsILookAndFeel colors.
-  if (mLookAndFeel)
-    mLookAndFeel->LookAndFeelChanged();
+  if (pc->mLookAndFeel && sLookAndFeelChanged) {
+    pc->mLookAndFeel->LookAndFeelChanged();
+    sLookAndFeelChanged = PR_FALSE;
+  }
 
   // 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();
+  pc->ClearStyleDataAndReflow();
+
+  return nsnull;
+}
+
+
+void PR_CALLBACK
+nsPresContext::DestroyThemeChangeEvt(PLEvent* aEvent)
+{
+  nsPresContext* pc = NS_STATIC_CAST(nsPresContext*, aEvent->owner);
+  NS_RELEASE(pc);
+  delete aEvent;
 }
 
 void
 nsPresContext::SysColorChanged()
 {
-  if (mLookAndFeel) {
+  if (!mPendingSysColorChanged) {
+    sLookAndFeelChanged = PR_TRUE;
+
+    nsCOMPtr<nsIEventQueue> eventQ;
+    mEventQueueService->
+      GetSpecialEventQueue(nsIEventQueueService::UI_THREAD_EVENT_QUEUE,
+                           getter_AddRefs(eventQ));
+    if (!eventQ) {
+      return;
+    }
+
+    PLEvent* evt = new PLEvent();
+    if (!evt) {
+      return;
+    }
+
+    PL_InitEvent(evt, this, nsPresContext::SysColorChangedInternal,
+                 nsPresContext::DestroySysColorChangeEvt);
+
+    // After this point, event destruction will release |this|
+    NS_ADDREF_THIS();
+
+    nsresult rv = eventQ->PostEvent(evt);
+    if (NS_FAILED(rv)) {
+      PL_DestroyEvent(evt);
+    } else {
+      mPendingSysColorChanged = PR_TRUE;
+    }
+  }
+}
+
+void* PR_CALLBACK
+nsPresContext::SysColorChangedInternal(PLEvent *aEvent)
+{
+  nsPresContext* pc = NS_STATIC_CAST(nsPresContext*, aEvent->owner);
+
+  pc->mPendingSysColorChanged = PR_FALSE;
+  
+  if (pc->mLookAndFeel && sLookAndFeelChanged) {
      // Don't use the cached values for the system colors
-    mLookAndFeel->LookAndFeelChanged();
+    pc->mLookAndFeel->LookAndFeelChanged();
+    sLookAndFeelChanged = PR_FALSE;
   }
-   
+
   // Reset default background and foreground colors for the document since
   // they may be using system colors
-  GetDocumentColorPreferences();
+  pc->GetDocumentColorPreferences();
 
   // Clear out all of the style data since it may contain RGB values
   // which originated from system colors.
@@ -1222,7 +1333,17 @@ nsPresContext::SysColorChanged()
   // data without reflowing/updating views will lead to incorrect change hints
   // later, because when generating change hints, any style structs which have
   // been cleared and not reread are assumed to not be used at all.
-  ClearStyleDataAndReflow();
+  pc->ClearStyleDataAndReflow();
+
+  return nsnull;
+}
+
+void PR_CALLBACK
+nsPresContext::DestroySysColorChangeEvt(PLEvent* aEvent)
+{
+  nsPresContext* pc = NS_STATIC_CAST(nsPresContext*, aEvent->owner);
+  NS_RELEASE(pc);
+  delete aEvent;
 }
 
 void
Index: layout/base/nsPresContext.h
===================================================================
RCS file: /cvsroot/mozilla/layout/base/nsPresContext.h,v
retrieving revision 3.150.4.2
diff -d -u -p -r3.150.4.2 nsPresContext.h
--- layout/base/nsPresContext.h	29 Aug 2005 16:15:39 -0000	3.150.4.2
+++ layout/base/nsPresContext.h	26 Sep 2006 19:26:40 -0000
@@ -56,6 +56,7 @@
 #include "nsCRT.h"
 #include "nsIPrintSettings.h"
 #include "nsPropertyTable.h"
+#include "plevent.h"
 #ifdef IBMBIDI
 class nsBidiPresUtils;
 #endif // IBMBIDI
@@ -76,6 +77,7 @@ class nsIAtom;
 class nsIEventStateManager;
 class nsIURI;
 class nsILookAndFeel;
+class nsIEventQueueService;
 class nsICSSPseudoComparator;
 class nsIAtom;
 struct nsStyleStruct;
@@ -627,6 +629,14 @@ public:
   const nscoord* GetBorderWidthTable() { return mBorderWidthTable; }
 
 protected:
+  static NS_HIDDEN_(void*) PR_CALLBACK ThemeChangedInternal(PLEvent* aEvent);
+  static NS_HIDDEN_(void*) PR_CALLBACK SysColorChangedInternal(PLEvent* aEvent);
+  static NS_HIDDEN_(void) PR_CALLBACK DestroyThemeChangeEvt(PLEvent* aEvent);
+  static NS_HIDDEN_(void) PR_CALLBACK DestroySysColorChangeEvt(PLEvent* aEvent);
+
+  friend void* PR_CALLBACK ThemeChangedInternal(PLEvent* aEvent);
+  friend void* PR_CALLBACK SysColorChangedInternal(PLEvent* aEvent);
+
   NS_HIDDEN_(void) SetImgAnimations(nsIContent *aParent, PRUint16 aMode);
   NS_HIDDEN_(void) GetDocumentColorPreferences();
 
@@ -654,6 +664,7 @@ protected:
                                         // from gfx back to layout.
   nsIEventStateManager* mEventManager;  // [STRONG]
   nsILookAndFeel*       mLookAndFeel;   // [STRONG]
+  nsIEventQueueService *mEventQueueService; // [STRONG]
   nsIAtom*              mMedium;        // initialized by subclass ctors;
                                         // weak pointer to static atom
 
@@ -724,6 +735,8 @@ protected:
   unsigned              mCanPaginatedScroll : 1;
   unsigned              mDoScaledTwips : 1;
   unsigned              mEnableJapaneseTransform : 1;
+  unsigned              mPendingSysColorChanged : 1;
+  unsigned              mPendingThemeChanged : 1;
 #ifdef IBMBIDI
   unsigned              mIsVisual : 1;
   unsigned              mIsBidiSystem : 1;
bgstack15