Bug 703133: Flush layout data asynchronously on charset changes. r=bz
authorKyle Huey <khuey@kylehuey.com>
Wed, 11 Jan 2012 21:58:44 +0100
changeset 84272 7c7d2a8db7ffd00d817249c1cfd3939465418894
parent 84271 d85920b5691b773138f861841d582dd70457c3b6
child 84273 8ffdb4c7404a88ee124e0f5461a9ce563bc49ee1
child 84661 19c77c1b12e54addce1f6cd96f364838e928c4a7
child 89030 bc3f0f7c0a073aa8a690ddf6db5cb9f603bb6a2a
child 105552 91c7d8b9c9e96bed8c5f867ccd98fed385638c48
push id21835
push userkhuey@mozilla.com
push dateWed, 11 Jan 2012 20:59:34 +0000
treeherdermozilla-central@7c7d2a8db7ff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs703133
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 703133: Flush layout data asynchronously on charset changes. r=bz
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -114,16 +114,41 @@
 //needed for resetting of image service color
 #include "nsLayoutCID.h"
 
 #include "nsCSSParser.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
+namespace {
+
+class CharSetChangingRunnable : public nsRunnable
+{
+public:
+  CharSetChangingRunnable(nsPresContext* aPresContext,
+                          const nsCString& aCharSet)
+    : mPresContext(aPresContext),
+      mCharSet(aCharSet)
+  {
+  }
+
+  NS_IMETHOD Run()
+  {
+    mPresContext->DoChangeCharSet(mCharSet);
+    return NS_OK;
+  }
+
+private:
+  nsRefPtr<nsPresContext> mPresContext;
+  nsCString mCharSet;
+};
+
+} // anonymous namespace
+
 static nscolor
 MakeColorPref(const nsString& aColor)
 {
   nscolor color;
   nsCSSParser parser;
   nsresult rv =
     parser.ParseColorString(aColor, nsnull, 0, &color);
   if (NS_FAILED(rv)) {
@@ -1067,17 +1092,25 @@ nsPresContext::DestroyImageLoaders()
   // want those pointers to outlive the destruction of the frame arena.
   for (PRUint32 i = 0; i < IMAGE_LOAD_TYPE_COUNT; ++i) {
     mImageLoaders[i].Enumerate(destroy_loads, nsnull);
     mImageLoaders[i].Clear();
   }
 }
 
 void
-nsPresContext::UpdateCharSet(const nsAFlatCString& aCharSet)
+nsPresContext::DoChangeCharSet(const nsCString& aCharSet)
+{
+  UpdateCharSet(aCharSet);
+  mDeviceContext->FlushFontCache();
+  RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
+}
+
+void
+nsPresContext::UpdateCharSet(const nsCString& aCharSet)
 {
   if (mLangService) {
     NS_IF_RELEASE(mLanguage);
     mLanguage = mLangService->LookupCharSet(aCharSet.get()).get();  // addrefs
     // this will be a language group (or script) code rather than a true language code
 
     // bug 39570: moved from nsLanguageAtomService::LookupCharSet()
     if (mLanguage == nsGkAtoms::Unicode) {
@@ -1107,20 +1140,19 @@ nsPresContext::UpdateCharSet(const nsAFl
 }
 
 NS_IMETHODIMP
 nsPresContext::Observe(nsISupports* aSubject, 
                         const char* aTopic,
                         const PRUnichar* aData)
 {
   if (!nsCRT::strcmp(aTopic, "charset")) {
-    UpdateCharSet(NS_LossyConvertUTF16toASCII(aData));
-    mDeviceContext->FlushFontCache();
-    RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
-    return NS_OK;
+    nsRefPtr<CharSetChangingRunnable> runnable =
+      new CharSetChangingRunnable(this, NS_LossyConvertUTF16toASCII(aData));
+    return NS_DispatchToCurrentThread(runnable);
   }
 
   NS_WARNING("unrecognized topic in nsPresContext::Observe");
   return NS_ERROR_FAILURE;
 }
 
 static nsPresContext*
 GetParentPresContext(nsPresContext* aPresContext)
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -1004,18 +1004,22 @@ protected:
   static NS_HIDDEN_(int) PrefChangedCallback(const char*, void*);
 
   NS_HIDDEN_(void) UpdateAfterPreferencesChanged();
   static NS_HIDDEN_(void) PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure);
 
   NS_HIDDEN_(void) GetUserPreferences();
   NS_HIDDEN_(void) GetFontPreferences();
 
-  NS_HIDDEN_(void) UpdateCharSet(const nsAFlatCString& aCharSet);
+  NS_HIDDEN_(void) UpdateCharSet(const nsCString& aCharSet);
 
+public:
+  void DoChangeCharSet(const nsCString& aCharSet);
+
+protected:
   void InvalidateThebesLayers();
   void AppUnitsPerDevPixelChanged();
 
   bool MayHavePaintEventListener();
 
   void HandleRebuildUserFontSet() {
     mPostedFlushUserFontSet = false;
     FlushUserFontSet();