Bug 518378: buttons and list boxes in content document are unreasonably large, r=dbaron
authorMark Finkle <mfinkle@mozilla.com>
Sat, 26 Sep 2009 20:21:32 -0400
changeset 33211 f616aec6cce4895789355d4f55e45bc381fa5fac
parent 33210 9ed976f3d466adfd367bc63fdcd11d83e2887d82
child 33212 a519afcff3b37bdb899e46da7cf132875e44c14a
push idunknown
push userunknown
push dateunknown
reviewersdbaron
bugs518378
milestone1.9.3a1pre
Bug 518378: buttons and list boxes in content document are unreasonably large, r=dbaron
gfx/src/thebes/nsSystemFontsGTK2.cpp
gfx/src/thebes/nsSystemFontsQt.cpp
gfx/thebes/public/gfxPlatformGtk.h
gfx/thebes/public/gfxQtPlatform.h
gfx/thebes/src/gfxPangoFonts.cpp
gfx/thebes/src/gfxPlatformGtk.cpp
gfx/thebes/src/gfxQtPlatform.cpp
--- a/gfx/src/thebes/nsSystemFontsGTK2.cpp
+++ b/gfx/src/thebes/nsSystemFontsGTK2.cpp
@@ -216,17 +216,17 @@ nsSystemFontsGTK2::GetSystemFontInfo(Gtk
     aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
 
     float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;
 
     // |size| is now either pixels or pango-points (not Mozilla-points!)
 
     if (!MOZ_pango_font_description_get_size_is_absolute(desc)) {
         // |size| is in pango-points, so convert to pixels.
-        size *= float(gfxPlatform::GetDPI()) / POINTS_PER_INCH_FLOAT;
+        size *= float(gfxPlatformGtk::GetPlatformDPI()) / POINTS_PER_INCH_FLOAT;
     }
 
     // |size| is now pixels
 
     aFontStyle->size = size;
   
     pango_font_description_free(desc);
 
--- a/gfx/src/thebes/nsSystemFontsQt.cpp
+++ b/gfx/src/thebes/nsSystemFontsQt.cpp
@@ -74,17 +74,17 @@ nsSystemFontsQt::GetSystemFontInfo(const
     aFontStyle->style = FONT_STYLE_NORMAL;
     aFontStyle->systemFont = PR_TRUE;
     NS_NAMED_LITERAL_STRING(quote, "\"");
     nsString family((PRUnichar*)qFont.family().data());
     *aFontName = quote + family + quote;
     aFontStyle->weight = qFont.weight();
     // FIXME: Set aFontStyle->stretch correctly!
     aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
-    aFontStyle->size = qFont.pointSizeF() * float(gfxPlatform::GetDPI()) / 72.0f;
+    aFontStyle->size = qFont.pointSizeF() * float(gfxQtPlatform::GetPlatformDPI()) / 72.0f;
     return NS_OK;
 }
 
 
 nsresult
 nsSystemFontsQt::GetSystemFont(nsSystemFontID anID, nsString *aFontName,
                                  gfxFontStyle *aFontStyle) const
 {
--- a/gfx/thebes/public/gfxPlatformGtk.h
+++ b/gfx/thebes/public/gfxPlatformGtk.h
@@ -124,18 +124,27 @@ public:
 #ifndef MOZ_PANGO
     FT_Library GetFTLibrary();
 #endif
 
     void SetGdkDrawable(gfxASurface *target,
                         GdkDrawable *drawable);
     GdkDrawable *GetGdkDrawable(gfxASurface *target);
 
+    static PRInt32 GetPlatformDPI() {
+        if (sPlatformDPI < 0) {
+            gfxPlatformGtk::GetPlatform()->InitDisplayCaps();
+        }
+        NS_ASSERTION(sPlatformDPI > 0, "Something is wrong");
+        return sPlatformDPI;
+    }
+
 protected:
     void InitDisplayCaps();
 
+    static PRInt32 sPlatformDPI;
     static gfxFontconfigUtils *sFontconfigUtils;
 
 private:
     virtual qcms_profile *GetPlatformCMSOutputProfile();
 };
 
 #endif /* GFX_PLATFORM_GTK_H */
--- a/gfx/thebes/public/gfxQtPlatform.h
+++ b/gfx/thebes/public/gfxQtPlatform.h
@@ -80,19 +80,21 @@ public:
     FontFamily *FindFontFamily(const nsAString& aName);
     FontEntry *FindFontEntry(const nsAString& aFamilyName, const gfxFontStyle& aFontStyle);
     already_AddRefed<gfxFont> FindFontForChar(PRUint32 aCh, gfxFont *aFont);
     PRBool GetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> > *aFontEntryList);
     void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> >& aFontEntryList);
 
     FT_Library GetFTLibrary();
 
+    static PRInt32 GetPlatformDPI() {
+        return 96;
+    }
+
 protected:
-    void InitDisplayCaps();
-
     static gfxFontconfigUtils *sFontconfigUtils;
 
 private:
     virtual qcms_profile *GetPlatformCMSOutputProfile();
 };
 
 #endif /* GFX_PLATFORM_QT_H */
 
--- a/gfx/thebes/src/gfxPangoFonts.cpp
+++ b/gfx/thebes/src/gfxPangoFonts.cpp
@@ -782,17 +782,17 @@ gfx_pango_fc_font_describe(PangoFont *fo
     gfxPangoFcFont *self = GFX_PANGO_FC_FONT(font);
     PangoFcFont *fcFont = &self->parent_instance;
     PangoFontDescription *result =
         pango_font_description_copy(fcFont->description);
 
     gfxFcFont *gfxFont = gfxPangoFcFont::GfxFont(self);
     if (gfxFont) {
         double pixelsize = gfxFont->GetStyle()->size;
-        double dpi = gfxPlatform::GetDPI();
+        double dpi = gfxPlatformGtk::GetPlatformDPI();
         gint size = moz_pango_units_from_double(pixelsize * dpi / 72.0);
         pango_font_description_set_size(result, size);
     }
     return result;
 }
 
 static PangoFontDescription *
 gfx_pango_fc_font_describe_absolute(PangoFont *font)
@@ -1779,18 +1779,18 @@ gfx_pango_font_map_load_fontset(PangoFon
     return gfxPangoFontset::NewFontset(fontGroup, language);
 }
 
 static double
 gfx_pango_font_map_get_resolution(PangoFcFontMap *fcfontmap,
                                   PangoContext *context)
 {
     // This merely enables the FC_SIZE field of the pattern to be accurate.
-    // We use gfxPlatform::GetDPI() much of the time...
-    return gfxPlatform::GetDPI();
+    // We use gfxPlatformGtk::GetPlatformDPI() much of the time...
+    return gfxPlatformGtk::GetPlatformDPI();
 }
 
 #ifdef MOZ_WIDGET_GTK2
 static void ApplyGdkScreenFontOptions(FcPattern *aPattern);
 #endif
 
 // Apply user settings and defaults to pattern in preparation for matching.
 static void
--- a/gfx/thebes/src/gfxPlatformGtk.cpp
+++ b/gfx/thebes/src/gfxPlatformGtk.cpp
@@ -93,16 +93,17 @@
 
 #ifdef MOZ_PLATFORM_HILDON
 #include "nsCOMPtr.h"
 #include "nsILocalFile.h"
 #include "nsILineInputStream.h"
 #include "nsNetUtil.h"
 #endif
 
+PRInt32 gfxPlatformGtk::sPlatformDPI = -1;
 gfxFontconfigUtils *gfxPlatformGtk::sFontconfigUtils = nsnull;
 
 #ifndef MOZ_PANGO
 typedef nsDataHashtable<nsStringHashKey, nsRefPtr<FontFamily> > FontTable;
 typedef nsDataHashtable<nsCStringHashKey, nsTArray<nsRefPtr<FontEntry> > > PrefFontTable;
 static FontTable *gPlatformFonts = NULL;
 static FontTable *gPlatformFontAliases = NULL;
 static PrefFontTable *gPrefFonts = NULL;
@@ -525,52 +526,59 @@ gfxPlatformGtk::CreateFontGroup(const ns
     return new gfxFT2FontGroup(aFamilies, aStyle);
 }
 
 #endif
 
 void
 gfxPlatformGtk::InitDisplayCaps()
 {
+    GdkScreen *screen = gdk_screen_get_default();
+    gtk_settings_get_for_screen(screen); // Make sure init is run so we have a resolution
+    gfxPlatformGtk::sPlatformDPI = PRInt32(round(gdk_screen_get_resolution(screen)));
+
+    if (gfxPlatformGtk::sPlatformDPI <= 0) {
+        // Fall back to something sane
+        gfxPlatformGtk::sPlatformDPI = 96;
+    }
+
 #if defined(MOZ_PLATFORM_HILDON)
     // Check the cached value
     if (gfxPlatform::sDPI == -1) {
         nsresult rv;
         nsCOMPtr<nsILocalFile> file;
         rv = NS_NewLocalFile(NS_LITERAL_STRING("/proc/component_version"),
                              PR_TRUE, getter_AddRefs(file));
         if (NS_SUCCEEDED(rv)) {
             nsCOMPtr<nsIInputStream> fileStream;
-            NS_NewLocalFileInputStream(getter_AddRefs(fileStream), file);                
+            NS_NewLocalFileInputStream(getter_AddRefs(fileStream), file);
             nsCOMPtr<nsILineInputStream> lineStream = do_QueryInterface(fileStream);
             
             // Extract the product code from the component_version file
             nsCAutoString buffer;
             PRBool isMore = PR_TRUE;
-            if (NS_SUCCEEDED(lineStream->ReadLine(buffer, &isMore))) {
+            if (lineStream && NS_SUCCEEDED(lineStream->ReadLine(buffer, &isMore))) {
                 if (StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-51"))) {
                     gfxPlatform::sDPI = 265; // It's an N900
                 }
                 else if (StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-44")) ||
                          StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-48")) ||
                          StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-34"))) {
                     gfxPlatform::sDPI = 225; // It's an N810/N800
                 }
             }
         }
     }
 #else
-    GdkScreen *screen = gdk_screen_get_default();
-    gtk_settings_get_for_screen(screen); // Make sure init is run so we have a resolution
-    gfxPlatform::sDPI = PRInt32(round(gdk_screen_get_resolution(screen)));
+    gfxPlatform::sDPI = gfxPlatformGtk::sPlatformDPI;
 #endif
 
-    if (gfxPlatform::sDPI <= 0.0) {
+    if (gfxPlatform::sDPI <= 0) {
         // Fall back to something sane
-        gfxPlatform::sDPI = 96.0;
+        gfxPlatform::sDPI = 96;
     } else {
         // Minimum DPI is 96
         gfxPlatform::sDPI = PR_MAX(sDPI, 96);
     }
 }
 
 qcms_profile *
 gfxPlatformGtk::GetPlatformCMSOutputProfile()
--- a/gfx/thebes/src/gfxQtPlatform.cpp
+++ b/gfx/thebes/src/gfxQtPlatform.cpp
@@ -358,19 +358,16 @@ gfxQtPlatform::GetPlatformCMSOutputProfi
 }
 
 FT_Library
 gfxQtPlatform::GetFTLibrary()
 {
     return gPlatformFTLibrary;
 }
 
-void gfxQtPlatform::InitDisplayCaps()
-{ }
-
 FontFamily *
 gfxQtPlatform::FindFontFamily(const nsAString& aName)
 {
     nsAutoString name(aName);
     ToLowerCase(name);
 
     nsRefPtr<FontFamily> ff;
     if (!gPlatformFonts->Get(name, &ff)) {