bug 674373 pt 4 - pass device-to-CSS pixel ratio to LookAndFeel code when requesting a font style. r=roc
authorJonathan Kew <jkew@mozilla.com>
Sat, 29 Sep 2012 12:35:08 +0100
changeset 114923 4e8929729b4caefbccbd752c27a34be60f8b71f3
parent 114922 466d49964ff1084d25487b811989272813450d79
child 114924 550641381dfaf0e8144e4aec9e458dfd8c125aeb
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs674373
milestone18.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 674373 pt 4 - pass device-to-CSS pixel ratio to LookAndFeel code when requesting a font style. r=roc
layout/style/nsRuleNode.cpp
widget/LookAndFeel.h
widget/android/nsLookAndFeel.cpp
widget/android/nsLookAndFeel.h
widget/cocoa/nsLookAndFeel.h
widget/cocoa/nsLookAndFeel.mm
widget/gonk/nsLookAndFeel.cpp
widget/gonk/nsLookAndFeel.h
widget/gtk2/nsLookAndFeel.cpp
widget/gtk2/nsLookAndFeel.h
widget/qt/nsLookAndFeel.cpp
widget/qt/nsLookAndFeel.h
widget/windows/nsLookAndFeel.cpp
widget/windows/nsLookAndFeel.h
widget/xpwidgets/nsXPLookAndFeel.cpp
widget/xpwidgets/nsXPLookAndFeel.h
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -2976,17 +2976,19 @@ nsRuleNode::SetFont(nsPresContext* aPres
 
   // Fall back to defaultVariableFont.
   nsFont systemFont = *defaultVariableFont;
   const nsCSSValue* systemFontValue = aRuleData->ValueForSystemFont();
   if (eCSSUnit_Enumerated == systemFontValue->GetUnit()) {
     gfxFontStyle fontStyle;
     LookAndFeel::FontID fontID =
       (LookAndFeel::FontID)systemFontValue->GetIntValue();
-    if (LookAndFeel::GetFont(fontID, systemFont.name, fontStyle)) {
+    float devPerCSS = (float)nsPresContext::AppUnitsPerCSSPixel() /
+                      aPresContext->AppUnitsPerDevPixel();
+    if (LookAndFeel::GetFont(fontID, systemFont.name, fontStyle, devPerCSS)) {
       systemFont.style = fontStyle.style;
       systemFont.systemFont = fontStyle.systemFont;
       systemFont.variant = NS_FONT_VARIANT_NORMAL;
       systemFont.weight = fontStyle.weight;
       systemFont.stretch = fontStyle.stretch;
       systemFont.decorations = NS_FONT_DECORATION_NONE;
       systemFont.size = NSFloatPixelsToAppUnits(fontStyle.size,
                                                 aPresContext->DeviceContext()->
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
@@ -486,18 +486,20 @@ public:
   /**
    * Retrieve the name and style of a system-theme font.  Returns true
    * if the system theme specifies this font, false if a default should
    * be used.  In the latter case neither aName nor aStyle is modified.
    *
    * @param aID    Which system-theme font is wanted.
    * @param aName  The name of the font to use.
    * @param aStyle Styling to apply to the font.
+   * @param aDevPixPerCSSPixel  Ratio of device pixels to CSS pixels
    */
-  static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle);
+  static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle,
+                      float aDevPixPerCSSPixel);
 
   /**
    * GetPasswordCharacter() returns a unicode character which should be used
    * for a masked character in password editor.  E.g., '*'.
    */
   static PRUnichar GetPasswordCharacter();
 
   /**
--- a/widget/android/nsLookAndFeel.cpp
+++ b/widget/android/nsLookAndFeel.cpp
@@ -441,17 +441,18 @@ nsLookAndFeel::GetFloatImpl(FloatID aID,
             break;
     }
     return rv;
 }
 
 /*virtual*/
 bool
 nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
-                           gfxFontStyle& aFontStyle)
+                           gfxFontStyle& aFontStyle,
+                           float aDevPixPerCSSPixel)
 {
     aFontName.AssignLiteral("\"Droid Sans\"");
     aFontStyle.style = NS_FONT_STYLE_NORMAL;
     aFontStyle.weight = NS_FONT_WEIGHT_NORMAL;
     aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
     aFontStyle.size = 9.0 * 96.0f / 72.0f;
     aFontStyle.systemFont = true;
     return true;
--- a/widget/android/nsLookAndFeel.h
+++ b/widget/android/nsLookAndFeel.h
@@ -12,17 +12,18 @@ class nsLookAndFeel: public nsXPLookAndF
 {
 public:
     nsLookAndFeel();
     virtual ~nsLookAndFeel();
 
     virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
     virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
     virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
-    virtual bool GetFontImpl(FontID aID, nsString& aName, gfxFontStyle& aStyle);
+    virtual bool GetFontImpl(FontID aID, nsString& aName, gfxFontStyle& aStyle,
+                             float aDevPixPerCSSPixel);
     virtual bool GetEchoPasswordImpl();
     virtual uint32_t GetPasswordMaskDelayImpl();
     virtual PRUnichar GetPasswordCharacterImpl();
 
 protected:
     static bool mInitializedSystemColors;
     static mozilla::AndroidSystemColors mSystemColors;
     static bool mInitializedShowPassword;
--- a/widget/cocoa/nsLookAndFeel.h
+++ b/widget/cocoa/nsLookAndFeel.h
@@ -11,17 +11,18 @@ class nsLookAndFeel: public nsXPLookAndF
 public:
   nsLookAndFeel();
   virtual ~nsLookAndFeel();
 
   virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
   virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
   virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
   virtual bool GetFontImpl(FontID aID, nsString& aFontName,
-                           gfxFontStyle& aFontStyle);
+                           gfxFontStyle& aFontStyle,
+                           float aDevPixPerCSSPixel);
   virtual PRUnichar GetPasswordCharacterImpl()
   {
     // unicode value for the bullet character, used for password textfields.
     return 0x2022;
   }
 
 protected:
 
--- a/widget/cocoa/nsLookAndFeel.mm
+++ b/widget/cocoa/nsLookAndFeel.mm
@@ -443,24 +443,25 @@ nsLookAndFeel::GetFloatImpl(FloatID aID,
 static void GetStringForNSString(const NSString *aSrc, nsAString& aDest)
 {
     aDest.SetLength([aSrc length]);
     [aSrc getCharacters:aDest.BeginWriting()];
 }
 
 bool
 nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName,
-                           gfxFontStyle &aFontStyle)
+                           gfxFontStyle &aFontStyle,
+                           float aDevPixPerCSSPixel)
 {
     // hack for now
     if (aID == eFont_Window || aID == eFont_Document) {
         aFontStyle.style      = NS_FONT_STYLE_NORMAL;
         aFontStyle.weight     = NS_FONT_WEIGHT_NORMAL;
         aFontStyle.stretch    = NS_FONT_STRETCH_NORMAL;
-        aFontStyle.size       = 14;
+        aFontStyle.size       = 14 * aDevPixPerCSSPixel;
         aFontStyle.systemFont = true;
 
         aFontName.AssignLiteral("sans-serif");
         return true;
     }
 
 /* possibilities, see NSFont Class Reference:
     [NSFont boldSystemFontOfSize:     0.0]
@@ -547,14 +548,15 @@ nsLookAndFeel::GetFontImpl(FontID aID, n
     aFontStyle.style =
         (traits & NSFontItalicTrait) ?  NS_FONT_STYLE_ITALIC : NS_FONT_STYLE_NORMAL;
     aFontStyle.weight =
         (traits & NSFontBoldTrait) ? NS_FONT_WEIGHT_BOLD : NS_FONT_WEIGHT_NORMAL;
     aFontStyle.stretch =
         (traits & NSFontExpandedTrait) ?
             NS_FONT_STRETCH_EXPANDED : (traits & NSFontCondensedTrait) ?
                 NS_FONT_STRETCH_CONDENSED : NS_FONT_STRETCH_NORMAL;
-    aFontStyle.size = [font pointSize];
+    // convert size from css pixels to device pixels
+    aFontStyle.size = [font pointSize] * aDevPixPerCSSPixel;
     aFontStyle.systemFont = true;
 
     GetStringForNSString([font familyName], aFontName);
     return true;
 }
--- a/widget/gonk/nsLookAndFeel.cpp
+++ b/widget/gonk/nsLookAndFeel.cpp
@@ -370,17 +370,18 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
     }
 
     return rv;
 }
 
 /*virtual*/
 bool
 nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
-                           gfxFontStyle& aFontStyle)
+                           gfxFontStyle& aFontStyle,
+                           float aDevPixPerCSSPixel)
 {
     aFontName.AssignLiteral("\"Droid Sans\"");
     aFontStyle.style = NS_FONT_STYLE_NORMAL;
     aFontStyle.weight = NS_FONT_WEIGHT_NORMAL;
     aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
     aFontStyle.size = 9.0 * 96.0f / 72.0f;
     aFontStyle.systemFont = true;
     return true;
--- a/widget/gonk/nsLookAndFeel.h
+++ b/widget/gonk/nsLookAndFeel.h
@@ -20,17 +20,18 @@
 #include "nsXPLookAndFeel.h"
 
 class nsLookAndFeel : public nsXPLookAndFeel
 {
 public:
     nsLookAndFeel();
     virtual ~nsLookAndFeel();
 
-    virtual bool GetFontImpl(FontID aID, nsString& aName, gfxFontStyle& aStyle);
+    virtual bool GetFontImpl(FontID aID, nsString& aName, gfxFontStyle& aStyle,
+                             float aDevPixPerCSSPixel);
     virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
     virtual bool GetEchoPasswordImpl();
 
 protected:
     virtual nsresult NativeGetColor(ColorID aID, nscolor &aColor);
 };
 
 #endif
--- a/widget/gtk2/nsLookAndFeel.cpp
+++ b/widget/gtk2/nsLookAndFeel.cpp
@@ -716,17 +716,18 @@ GetSystemFontInfo(LookAndFeel::FontID /*
     aFontStyle->systemFont = true;
     aFontName->AssignLiteral("\"Sans\"");
 }
 
 #endif // not MOZ_PANGO
 
 bool
 nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
-                           gfxFontStyle& aFontStyle)
+                           gfxFontStyle& aFontStyle,
+                           float aDevPixPerCSSPixel)
 {
   nsString *cachedFontName = NULL;
   gfxFontStyle *cachedFontStyle = NULL;
   bool *isCached = NULL;
 
   switch (aID) {
     case eFont_Menu:         // css2
     case eFont_PullDownMenu: // css3
--- a/widget/gtk2/nsLookAndFeel.h
+++ b/widget/gtk2/nsLookAndFeel.h
@@ -18,17 +18,18 @@ class nsLookAndFeel: public nsXPLookAndF
 public:
     nsLookAndFeel();
     virtual ~nsLookAndFeel();
 
     virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
     virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
     virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
     virtual bool GetFontImpl(FontID aID, nsString& aFontName,
-                             gfxFontStyle& aFontStyle);
+                             gfxFontStyle& aFontStyle,
+                             float aDevPixPerCSSPixel);
 
     virtual void RefreshImpl();
     virtual PRUnichar GetPasswordCharacterImpl();
     virtual bool GetEchoPasswordImpl();
 
 protected:
     struct _GtkStyle *mStyle;
 
--- a/widget/qt/nsLookAndFeel.cpp
+++ b/widget/qt/nsLookAndFeel.cpp
@@ -449,17 +449,18 @@ GetSystemFontInfo(const char *aClassName
     aFontStyle->size = qFont.pixelSize();
   } else {
     aFontStyle->size = qFont.pointSizeF() * 96.0f / 72.0f;
   }
 }
 
 bool
 nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
-                           gfxFontStyle& aFontStyle)
+                           gfxFontStyle& aFontStyle,
+                           float aDevPixPerCSSPixel)
 {
   const char *className = NULL;
   nsString *cachedFontName = NULL;
   gfxFontStyle *cachedFontStyle = NULL;
   bool *isCached = NULL;
 
   switch (aID) {
     case eFont_Menu:         // css2
--- a/widget/qt/nsLookAndFeel.h
+++ b/widget/qt/nsLookAndFeel.h
@@ -13,17 +13,18 @@ class nsLookAndFeel: public nsXPLookAndF
 public:
     nsLookAndFeel();
     virtual ~nsLookAndFeel();
 
     virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
     virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
     virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
     virtual bool GetFontImpl(FontID aID, nsString& aFontName,
-                             gfxFontStyle& aFontStyle);
+                             gfxFontStyle& aFontStyle,
+                             float aDevPixPerCSSPixel);
     virtual void RefreshImpl();
 
 private:
     bool mDefaultFontCached;
     bool mButtonFontCached;
     bool mFieldFontCached;
     bool mMenuFontCached;
     nsString mDefaultFontName;
--- a/widget/windows/nsLookAndFeel.cpp
+++ b/widget/windows/nsLookAndFeel.cpp
@@ -595,17 +595,18 @@ GetSysFontInfo(HDC aHDC, LookAndFeel::Fo
   memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*sizeof(PRUnichar));
   aFontName = name;
 
   return true;
 }
 
 bool
 nsLookAndFeel::GetFontImpl(FontID anID, nsString &aFontName,
-                           gfxFontStyle &aFontStyle)
+                           gfxFontStyle &aFontStyle,
+                           float aDevPixPerCSSPixel)
 {
   HDC tdc = GetDC(NULL);
   bool status = GetSysFontInfo(tdc, anID, aFontName, aFontStyle);
   ReleaseDC(NULL, tdc);
   return status;
 }
 
 /* virtual */
--- a/widget/windows/nsLookAndFeel.h
+++ b/widget/windows/nsLookAndFeel.h
@@ -25,13 +25,14 @@ class nsLookAndFeel: public nsXPLookAndF
 public:
   nsLookAndFeel();
   virtual ~nsLookAndFeel();
 
   virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
   virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
   virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
   virtual bool GetFontImpl(FontID aID, nsString& aFontName,
-                           gfxFontStyle& aFontStyle);
+                           gfxFontStyle& aFontStyle,
+                           float aDevPixPerCSSPixel);
   virtual PRUnichar GetPasswordCharacterImpl();
 };
 
 #endif
--- a/widget/xpwidgets/nsXPLookAndFeel.cpp
+++ b/widget/xpwidgets/nsXPLookAndFeel.cpp
@@ -707,19 +707,21 @@ LookAndFeel::GetInt(IntID aID, int32_t* 
 nsresult
 LookAndFeel::GetFloat(FloatID aID, float* aResult)
 {
   return nsLookAndFeel::GetInstance()->GetFloatImpl(aID, *aResult);
 }
 
 // static
 bool
-LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle)
+LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle,
+                     float aDevPixPerCSSPixel)
 {
-  return nsLookAndFeel::GetInstance()->GetFontImpl(aID, aName, aStyle);
+  return nsLookAndFeel::GetInstance()->GetFontImpl(aID, aName, aStyle,
+                                                   aDevPixPerCSSPixel);
 }
 
 // static
 PRUnichar
 LookAndFeel::GetPasswordCharacter()
 {
   return nsLookAndFeel::GetInstance()->GetPasswordCharacterImpl();
 }
--- a/widget/xpwidgets/nsXPLookAndFeel.h
+++ b/widget/xpwidgets/nsXPLookAndFeel.h
@@ -54,17 +54,18 @@ public:
   //
   nsresult GetColorImpl(ColorID aID, nscolor &aResult);
   virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
   virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
 
   // This one is different: there are no override prefs (fixme?), so
   // there is no XP implementation, only per-system impls.
   virtual bool GetFontImpl(FontID aID, nsString& aName,
-                           gfxFontStyle& aStyle) = 0;
+                           gfxFontStyle& aStyle,
+                           float aDevPixPerCSSPixel) = 0;
 
   virtual void RefreshImpl();
 
   virtual PRUnichar GetPasswordCharacterImpl()
   {
     return PRUnichar('*');
   }