From d015d63bf13c970df4ce8b4d56ea83b88e786a2e Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Fri, 7 Sep 2001 02:28:10 +0000 Subject: [PATCH] Make getComputedStyle remove the extra default font that we add to the end of the font-family list so it returns the original computed value. b=94078 r=hyatt sr=jst git-svn-id: svn://10.0.0.236/trunk@102506 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/style/src/nsComputedDOMStyle.cpp | 26 ++++++++++++++++++- .../html/style/src/nsROCSSPrimitiveValue.h | 2 +- mozilla/layout/style/nsComputedDOMStyle.cpp | 26 ++++++++++++++++++- mozilla/layout/style/nsROCSSPrimitiveValue.h | 2 +- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/mozilla/content/html/style/src/nsComputedDOMStyle.cpp b/mozilla/content/html/style/src/nsComputedDOMStyle.cpp index d6ff0d1f759..2c531c8550b 100644 --- a/mozilla/content/html/style/src/nsComputedDOMStyle.cpp +++ b/mozilla/content/html/style/src/nsComputedDOMStyle.cpp @@ -845,7 +845,31 @@ nsComputedDOMStyle::GetFontFamily(nsIFrame *aFrame, GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); if(font) { - val->SetString(font->mFont.name); + nsCOMPtr presShell=do_QueryReferent(mPresShellWeak); + NS_ASSERTION(presShell, "pres shell is required"); + nsCOMPtr presContext; + presShell->GetPresContext(getter_AddRefs(presContext)); + NS_ASSERTION(presContext, "pres context is required"); + + if (font->mFlags & NS_STYLE_FONT_USE_FIXED) { + const nsString& fontName = font->mFixedFont.name; + const nsFont& defaultFont = presContext->GetDefaultFixedFontDeprecated(); + PRInt32 lendiff = fontName.Length() - defaultFont.name.Length(); + if (lendiff > 0) { + val->SetString(Substring(fontName, 0, lendiff-1)); // -1 removes comma + } else { + val->SetString(fontName); + } + } else { + const nsString& fontName = font->mFont.name; + const nsFont& defaultFont = presContext->GetDefaultFontDeprecated(); + PRInt32 lendiff = fontName.Length() - defaultFont.name.Length(); + if (lendiff > 0) { + val->SetString(Substring(fontName, 0, lendiff-1)); // -1 removes comma + } else { + val->SetString(fontName); + } + } } else { val->SetString(""); diff --git a/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h index b00dc45179a..bc3f26d48ce 100644 --- a/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h +++ b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h @@ -58,7 +58,7 @@ public: mType = CSS_STRING; } - void SetString(const nsString& aString) + void SetString(const nsAString& aString) { mString.Assign(aString); mType = CSS_STRING; diff --git a/mozilla/layout/style/nsComputedDOMStyle.cpp b/mozilla/layout/style/nsComputedDOMStyle.cpp index d6ff0d1f759..2c531c8550b 100644 --- a/mozilla/layout/style/nsComputedDOMStyle.cpp +++ b/mozilla/layout/style/nsComputedDOMStyle.cpp @@ -845,7 +845,31 @@ nsComputedDOMStyle::GetFontFamily(nsIFrame *aFrame, GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); if(font) { - val->SetString(font->mFont.name); + nsCOMPtr presShell=do_QueryReferent(mPresShellWeak); + NS_ASSERTION(presShell, "pres shell is required"); + nsCOMPtr presContext; + presShell->GetPresContext(getter_AddRefs(presContext)); + NS_ASSERTION(presContext, "pres context is required"); + + if (font->mFlags & NS_STYLE_FONT_USE_FIXED) { + const nsString& fontName = font->mFixedFont.name; + const nsFont& defaultFont = presContext->GetDefaultFixedFontDeprecated(); + PRInt32 lendiff = fontName.Length() - defaultFont.name.Length(); + if (lendiff > 0) { + val->SetString(Substring(fontName, 0, lendiff-1)); // -1 removes comma + } else { + val->SetString(fontName); + } + } else { + const nsString& fontName = font->mFont.name; + const nsFont& defaultFont = presContext->GetDefaultFontDeprecated(); + PRInt32 lendiff = fontName.Length() - defaultFont.name.Length(); + if (lendiff > 0) { + val->SetString(Substring(fontName, 0, lendiff-1)); // -1 removes comma + } else { + val->SetString(fontName); + } + } } else { val->SetString(""); diff --git a/mozilla/layout/style/nsROCSSPrimitiveValue.h b/mozilla/layout/style/nsROCSSPrimitiveValue.h index b00dc45179a..bc3f26d48ce 100644 --- a/mozilla/layout/style/nsROCSSPrimitiveValue.h +++ b/mozilla/layout/style/nsROCSSPrimitiveValue.h @@ -58,7 +58,7 @@ public: mType = CSS_STRING; } - void SetString(const nsString& aString) + void SetString(const nsAString& aString) { mString.Assign(aString); mType = CSS_STRING;