зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1526294 - Should not need a pres context to get a system font. r=jfkthame
The only caller wants CSS pixels, no need to go back and forth. This is the last dependency on the pres context, I think, from the style system font code. Differential Revision: https://phabricator.services.mozilla.com/D19147
This commit is contained in:
Родитель
1649231cef
Коммит
323b5be77a
|
@ -166,8 +166,7 @@ class gfxMacPlatformFontList : public gfxPlatformFontList {
|
|||
// lookup the system font for a particular system font type and set
|
||||
// the name and style characteristics
|
||||
void LookupSystemFont(mozilla::LookAndFeel::FontID aSystemFontID,
|
||||
nsACString& aSystemFontName, gfxFontStyle& aFontStyle,
|
||||
float aDevPixPerCSSPixel);
|
||||
nsACString& aSystemFontName, gfxFontStyle& aFontStyle);
|
||||
|
||||
// Values for the entryType field in FontFamilyListEntry records passed
|
||||
// from chrome to content process.
|
||||
|
|
|
@ -1466,8 +1466,8 @@ bool gfxMacPlatformFontList::FindAndAddFamilies(const nsACString& aFamily,
|
|||
}
|
||||
|
||||
void gfxMacPlatformFontList::LookupSystemFont(LookAndFeel::FontID aSystemFontID,
|
||||
nsACString& aSystemFontName, gfxFontStyle& aFontStyle,
|
||||
float aDevPixPerCSSPixel) {
|
||||
nsACString& aSystemFontName,
|
||||
gfxFontStyle& aFontStyle) {
|
||||
// code moved here from widget/cocoa/nsLookAndFeel.mm
|
||||
NSFont* font = nullptr;
|
||||
char* systemFontName = nullptr;
|
||||
|
@ -1528,8 +1528,7 @@ void gfxMacPlatformFontList::LookupSystemFont(LookAndFeel::FontID aSystemFontID,
|
|||
(traits & NSFontExpandedTrait)
|
||||
? FontStretch::Expanded()
|
||||
: (traits & NSFontCondensedTrait) ? FontStretch::Condensed() : FontStretch::Normal();
|
||||
// convert size from css pixels to device pixels
|
||||
aFontStyle.size = [font pointSize] * aDevPixPerCSSPixel;
|
||||
aFontStyle.size = [font pointSize];
|
||||
aFontStyle.systemFont = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -321,10 +321,9 @@ void gfxPlatformMac::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
|
|||
|
||||
/*static*/ void gfxPlatformMac::LookupSystemFont(
|
||||
mozilla::LookAndFeel::FontID aSystemFontID, nsACString& aSystemFontName,
|
||||
gfxFontStyle& aFontStyle, float aDevPixPerCSSPixel) {
|
||||
gfxFontStyle& aFontStyle) {
|
||||
gfxMacPlatformFontList* pfl = gfxMacPlatformFontList::PlatformFontList();
|
||||
return pfl->LookupSystemFont(aSystemFontID, aSystemFontName, aFontStyle,
|
||||
aDevPixPerCSSPixel);
|
||||
return pfl->LookupSystemFont(aSystemFontID, aSystemFontName, aFontStyle);
|
||||
}
|
||||
|
||||
uint32_t gfxPlatformMac::ReadAntiAliasingThreshold() {
|
||||
|
|
|
@ -53,8 +53,7 @@ class gfxPlatformMac : public gfxPlatform {
|
|||
// the name and style characteristics
|
||||
static void LookupSystemFont(mozilla::LookAndFeel::FontID aSystemFontID,
|
||||
nsACString& aSystemFontName,
|
||||
gfxFontStyle& aFontStyle,
|
||||
float aDevPixPerCSSPixel);
|
||||
gfxFontStyle& aFontStyle);
|
||||
|
||||
virtual bool SupportsApzWheelInput() const override { return true; }
|
||||
|
||||
|
|
|
@ -9688,13 +9688,10 @@ already_AddRefed<nsFontMetrics> nsLayoutUtils::GetMetricsFor(
|
|||
|
||||
/* static */ void nsLayoutUtils::ComputeSystemFont(
|
||||
nsFont* aSystemFont, LookAndFeel::FontID aFontID,
|
||||
const nsPresContext* aPresContext, const nsFont* aDefaultVariableFont) {
|
||||
const nsFont* aDefaultVariableFont) {
|
||||
gfxFontStyle fontStyle;
|
||||
float devPerCSS =
|
||||
(float)AppUnitsPerCSSPixel() /
|
||||
aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
|
||||
nsAutoString systemFontName;
|
||||
if (LookAndFeel::GetFont(aFontID, systemFontName, fontStyle, devPerCSS)) {
|
||||
if (LookAndFeel::GetFont(aFontID, systemFontName, fontStyle)) {
|
||||
systemFontName.Trim("\"'");
|
||||
aSystemFont->fontlist =
|
||||
FontFamilyList(NS_ConvertUTF16toUTF8(systemFontName), eUnquotedName);
|
||||
|
@ -9703,9 +9700,7 @@ already_AddRefed<nsFontMetrics> nsLayoutUtils::GetMetricsFor(
|
|||
aSystemFont->systemFont = fontStyle.systemFont;
|
||||
aSystemFont->weight = fontStyle.weight;
|
||||
aSystemFont->stretch = fontStyle.stretch;
|
||||
aSystemFont->size = NSFloatPixelsToAppUnits(
|
||||
fontStyle.size,
|
||||
aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
|
||||
aSystemFont->size = CSSPixel::ToAppUnits(fontStyle.size);
|
||||
// aSystemFont->langGroup = fontStyle.langGroup;
|
||||
aSystemFont->sizeAdjust = fontStyle.sizeAdjust;
|
||||
|
||||
|
|
|
@ -2972,7 +2972,6 @@ class nsLayoutUtils {
|
|||
|
||||
static void ComputeSystemFont(nsFont* aSystemFont,
|
||||
mozilla::LookAndFeel::FontID aFontID,
|
||||
const nsPresContext* aPresContext,
|
||||
const nsFont* aDefaultVariableFont);
|
||||
|
||||
static void ComputeFontFeatures(const nsCSSValuePairList* aFeaturesList,
|
||||
|
|
|
@ -1029,8 +1029,7 @@ void Gecko_nsFont_InitSystem(nsFont* aDest, int32_t aFontId,
|
|||
LookAndFeel::FontID fontID = static_cast<LookAndFeel::FontID>(aFontId);
|
||||
|
||||
AutoWriteLock guard(*sServoFFILock);
|
||||
nsLayoutUtils::ComputeSystemFont(aDest, fontID, aPresContext,
|
||||
defaultVariableFont);
|
||||
nsLayoutUtils::ComputeSystemFont(aDest, fontID, defaultVariableFont);
|
||||
}
|
||||
|
||||
void Gecko_nsFont_Destroy(nsFont* aDest) { aDest->~nsFont(); }
|
||||
|
|
|
@ -650,13 +650,13 @@ class LookAndFeel {
|
|||
* if the system theme specifies this font, false if a default should
|
||||
* be used. In the latter case neither aName nor aStyle is modified.
|
||||
*
|
||||
* Size of the font should be in CSS pixels, not device pixels.
|
||||
*
|
||||
* @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,
|
||||
float aDevPixPerCSSPixel);
|
||||
static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle);
|
||||
|
||||
/**
|
||||
* GetPasswordCharacter() returns a unicode character which should be used
|
||||
|
|
|
@ -432,13 +432,12 @@ nsresult nsLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
|
|||
|
||||
/*virtual*/
|
||||
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle,
|
||||
float aDevPixPerCSSPixel) {
|
||||
gfxFontStyle& aFontStyle) {
|
||||
aFontName.AssignLiteral("\"Roboto\"");
|
||||
aFontStyle.style = FontSlantStyle::Normal();
|
||||
aFontStyle.weight = FontWeight::Normal();
|
||||
aFontStyle.stretch = FontStretch::Normal();
|
||||
aFontStyle.size = 9.0 * 96.0f / 72.0f * aDevPixPerCSSPixel;
|
||||
aFontStyle.size = 9.0 * 96.0f / 72.0f;
|
||||
aFontStyle.systemFont = true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
|
||||
virtual nsresult GetIntImpl(IntID aID, int32_t& aResult) override;
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float& aResult) override;
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aName, gfxFontStyle& aStyle,
|
||||
float aDevPixPerCSSPixel) override;
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aName,
|
||||
gfxFontStyle& aStyle) override;
|
||||
virtual bool GetEchoPasswordImpl() override;
|
||||
virtual uint32_t GetPasswordMaskDelayImpl() override;
|
||||
virtual char16_t GetPasswordCharacterImpl() override;
|
||||
|
|
|
@ -18,8 +18,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
virtual nsresult GetIntImpl(IntID aID, int32_t& aResult) override;
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float& aResult) override;
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle,
|
||||
float aDevPixPerCSSPixel) override;
|
||||
gfxFontStyle& aFontStyle) override;
|
||||
|
||||
virtual char16_t GetPasswordCharacterImpl() override {
|
||||
// unicode value for the bullet character, used for password textfields.
|
||||
|
|
|
@ -628,8 +628,7 @@ bool nsLookAndFeel::SystemWantsDarkTheme() {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle,
|
||||
float aDevPixPerCSSPixel) {
|
||||
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
// hack for now
|
||||
|
@ -637,7 +636,7 @@ bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& a
|
|||
aFontStyle.style = mozilla::FontSlantStyle::Normal();
|
||||
aFontStyle.weight = mozilla::FontWeight::Normal();
|
||||
aFontStyle.stretch = mozilla::FontStretch::Normal();
|
||||
aFontStyle.size = 14 * aDevPixPerCSSPixel;
|
||||
aFontStyle.size = 14;
|
||||
aFontStyle.systemFont = true;
|
||||
|
||||
aFontName.AssignLiteral("sans-serif");
|
||||
|
@ -645,7 +644,7 @@ bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& a
|
|||
}
|
||||
|
||||
nsAutoCString name;
|
||||
gfxPlatformMac::LookupSystemFont(aID, name, aFontStyle, aDevPixPerCSSPixel);
|
||||
gfxPlatformMac::LookupSystemFont(aID, name, aFontStyle);
|
||||
aFontName.Append(NS_ConvertUTF8toUTF16(name));
|
||||
|
||||
return true;
|
||||
|
|
|
@ -767,18 +767,15 @@ static void GetSystemFontInfo(GtkStyleContext* aStyle, nsString* aFontName,
|
|||
// |size| is in pango-points, so convert to pixels.
|
||||
size *= float(gfxPlatformGtk::GetFontScaleDPI()) / POINTS_PER_INCH_FLOAT;
|
||||
}
|
||||
// |size| is now pixels but not scaled for the hidpi displays,
|
||||
// this needs to be done in GetFontImpl where the aDevPixPerCSSPixel
|
||||
// parameter is provided.
|
||||
|
||||
// |size| is now pixels but not scaled for the hidpi displays,
|
||||
aFontStyle->size = size;
|
||||
|
||||
pango_font_description_free(desc);
|
||||
}
|
||||
|
||||
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle,
|
||||
float aDevPixPerCSSPixel) {
|
||||
gfxFontStyle& aFontStyle) {
|
||||
switch (aID) {
|
||||
case eFont_Menu: // css2
|
||||
case eFont_PullDownMenu: // css3
|
||||
|
@ -815,17 +812,17 @@ bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
|
|||
aFontStyle = mDefaultFontStyle;
|
||||
break;
|
||||
}
|
||||
|
||||
// Scale the font for the current monitor
|
||||
double scaleFactor = nsIWidget::DefaultScaleOverride();
|
||||
if (scaleFactor > 0) {
|
||||
aFontStyle.size *=
|
||||
mozilla::widget::ScreenHelperGTK::GetGTKMonitorScaleFactor();
|
||||
widget::ScreenHelperGTK::GetGTKMonitorScaleFactor() / scaleFactor;
|
||||
} else {
|
||||
// Remove effect of font scale because it has been already applied in
|
||||
// GetSystemFontInfo
|
||||
aFontStyle.size *=
|
||||
aDevPixPerCSSPixel / gfxPlatformGtk::GetFontScaleFactor();
|
||||
// Convert gdk pixels to CSS pixels.
|
||||
aFontStyle.size /= gfxPlatformGtk::GetFontScaleFactor();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
virtual nsresult GetIntImpl(IntID aID, int32_t &aResult) override;
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float &aResult) override;
|
||||
virtual bool GetFontImpl(FontID aID, nsString &aFontName,
|
||||
gfxFontStyle &aFontStyle,
|
||||
float aDevPixPerCSSPixel) override;
|
||||
gfxFontStyle &aFontStyle) override;
|
||||
|
||||
virtual char16_t GetPasswordCharacterImpl() override;
|
||||
virtual bool GetEchoPasswordImpl() override;
|
||||
|
|
|
@ -28,8 +28,7 @@ class HeadlessLookAndFeel : public nsXPLookAndFeel {
|
|||
virtual nsresult GetIntImpl(IntID aID, int32_t &aResult) override;
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float &aResult) override;
|
||||
virtual bool GetFontImpl(FontID aID, nsString &aFontName,
|
||||
gfxFontStyle &aFontStyle,
|
||||
float aDevPixPerCSSPixel) override;
|
||||
gfxFontStyle &aFontStyle) override;
|
||||
|
||||
virtual void RefreshImpl() override;
|
||||
virtual char16_t GetPasswordCharacterImpl() override;
|
||||
|
|
|
@ -327,13 +327,12 @@ nsresult HeadlessLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
|
|||
}
|
||||
|
||||
bool HeadlessLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle,
|
||||
float aDevPixPerCSSPixel) {
|
||||
gfxFontStyle& aFontStyle) {
|
||||
// Default to san-serif for everything.
|
||||
aFontStyle.style = FontSlantStyle::Normal();
|
||||
aFontStyle.weight = FontWeight::Normal();
|
||||
aFontStyle.stretch = FontStretch::Normal();
|
||||
aFontStyle.size = 14 * aDevPixPerCSSPixel;
|
||||
aFontStyle.size = 14;
|
||||
aFontStyle.systemFont = true;
|
||||
|
||||
aFontName.AssignLiteral("sans-serif");
|
||||
|
|
|
@ -985,10 +985,8 @@ nsresult LookAndFeel::GetFloat(FloatID aID, float* aResult) {
|
|||
}
|
||||
|
||||
// static
|
||||
bool LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle,
|
||||
float aDevPixPerCSSPixel) {
|
||||
return nsLookAndFeel::GetInstance()->GetFontImpl(aID, aName, aStyle,
|
||||
aDevPixPerCSSPixel);
|
||||
bool LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle) {
|
||||
return nsLookAndFeel::GetInstance()->GetFontImpl(aID, aName, aStyle);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -60,8 +60,8 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {
|
|||
|
||||
// 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,
|
||||
float aDevPixPerCSSPixel) = 0;
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aName,
|
||||
gfxFontStyle& aStyle) = 0;
|
||||
|
||||
virtual void RefreshImpl();
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
virtual nsresult NativeGetColor(const 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, float aDevPixPerCSSPixel);
|
||||
bool GetFontImpl(FontID aID, nsString &aFontName,
|
||||
gfxFontStyle &aFontStyle) override;
|
||||
virtual char16_t GetPasswordCharacterImpl() {
|
||||
// unicode value for the bullet character, used for password textfields.
|
||||
return 0x2022;
|
||||
|
|
|
@ -372,14 +372,13 @@ nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult) {
|
|||
return res;
|
||||
}
|
||||
|
||||
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName, gfxFontStyle &aFontStyle,
|
||||
float aDevPixPerCSSPixel) {
|
||||
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName, gfxFontStyle &aFontStyle) {
|
||||
// hack for now
|
||||
if (aID == eFont_Window || aID == eFont_Document) {
|
||||
aFontStyle.style = FontSlantStyle::Normal();
|
||||
aFontStyle.weight = FontWeight::Normal();
|
||||
aFontStyle.stretch = FontStretch::Normal();
|
||||
aFontStyle.size = 14 * aDevPixPerCSSPixel;
|
||||
aFontStyle.size = 14;
|
||||
aFontStyle.systemFont = true;
|
||||
|
||||
aFontName.AssignLiteral("sans-serif");
|
||||
|
|
|
@ -742,8 +742,7 @@ static bool GetSysFontInfo(HDC aHDC, LookAndFeel::FontID anID,
|
|||
}
|
||||
|
||||
bool nsLookAndFeel::GetFontImpl(FontID anID, nsString &aFontName,
|
||||
gfxFontStyle &aFontStyle,
|
||||
float aDevPixPerCSSPixel) {
|
||||
gfxFontStyle &aFontStyle) {
|
||||
CachedSystemFont &cacheSlot = mSystemFontCache[anID];
|
||||
|
||||
bool status;
|
||||
|
@ -765,9 +764,6 @@ bool nsLookAndFeel::GetFontImpl(FontID anID, nsString &aFontName,
|
|||
cacheSlot.mFontStyle = aFontStyle;
|
||||
}
|
||||
}
|
||||
// now convert the logical font size from GetSysFontInfo into device pixels
|
||||
// for layout
|
||||
aFontStyle.size *= aDevPixPerCSSPixel;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,8 +54,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
|
||||
nsresult GetIntImpl(IntID aID, int32_t& aResult) override;
|
||||
nsresult GetFloatImpl(FloatID aID, float& aResult) override;
|
||||
bool GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle,
|
||||
float aDevPixPerCSSPixel) override;
|
||||
bool GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle) override;
|
||||
char16_t GetPasswordCharacterImpl() override;
|
||||
|
||||
nsTArray<LookAndFeelInt> GetIntCacheImpl() override;
|
||||
|
|
Загрузка…
Ссылка в новой задаче