Bug 703133: Flush layout data asynchronously on charset changes. r=bz

This commit is contained in:
Kyle Huey 2012-01-11 21:58:44 +01:00
parent ca0ce519e1
commit 4e6806ed48
2 changed files with 42 additions and 6 deletions

View File

@ -119,6 +119,31 @@
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)
{
@ -1072,7 +1097,15 @@ nsPresContext::DestroyImageLoaders()
}
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);
@ -1112,10 +1145,9 @@ nsPresContext::Observe(nsISupports* aSubject,
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");

View File

@ -1009,8 +1009,12 @@ protected:
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();