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