From 0f41ccc84245dd69cf38f554964d82d979917c3d Mon Sep 17 00:00:00 2001 From: Igor Oliveira Date: Sun, 10 Dec 2017 18:16:59 -0200 Subject: [PATCH] Bug 23104: Add a default line height compensation Many fonts have issues with their vertical metrics. they are used to influence the height of ascenders and depth of descenders. Gecko uses it to calculate the line height (font height + ascender + descender), however because of that idiosyncratic behavior across multiple operating systems, it can be used to identify the user's OS. The solution proposed in the patch uses a default factor to be multiplied with the font size, simulating the concept of ascender and descender. This way all operating systems will have the same line height only and only if the frame is outside the chrome. --- layout/generic/ReflowInput.cpp | 17 ++++++++--- tbb-tests/mochitest.ini | 1 + tbb-tests/test_tor_bug23104.html | 51 ++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 tbb-tests/test_tor_bug23104.html diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp index bbc88e5fd74ce..ef47c8498b18b 100644 --- a/layout/generic/ReflowInput.cpp +++ b/layout/generic/ReflowInput.cpp @@ -31,6 +31,7 @@ #include #include "mozilla/dom/HTMLInputElement.h" #include "nsGridContainerFrame.h" +#include "nsContentUtils.h" using namespace mozilla; using namespace mozilla::css; @@ -2781,7 +2782,8 @@ void ReflowInput::CalculateBlockSideMargins(LayoutFrameType aFrameType) { // For risk management, we use preference to control the behavior, and // eNoExternalLeading is the old behavior. -static nscoord GetNormalLineHeight(nsFontMetrics* aFontMetrics) { +static nscoord GetNormalLineHeight(nsIContent* aContent, + nsFontMetrics* aFontMetrics) { MOZ_ASSERT(nullptr != aFontMetrics, "no font metrics"); nscoord normalLineHeight; @@ -2789,6 +2791,12 @@ static nscoord GetNormalLineHeight(nsFontMetrics* aFontMetrics) { nscoord externalLeading = aFontMetrics->ExternalLeading(); nscoord internalLeading = aFontMetrics->InternalLeading(); nscoord emHeight = aFontMetrics->EmHeight(); + + if (nsContentUtils::ShouldResistFingerprinting() && + !aContent->IsInChromeDocument()) { + return NSToCoordRound(emHeight * NORMAL_LINE_HEIGHT_FACTOR); + } + switch (GetNormalLineHeightCalcControl()) { case eIncludeExternalLeading: normalLineHeight = emHeight + internalLeading + externalLeading; @@ -2806,7 +2814,8 @@ static nscoord GetNormalLineHeight(nsFontMetrics* aFontMetrics) { return normalLineHeight; } -static inline nscoord ComputeLineHeight(ComputedStyle* aComputedStyle, +static inline nscoord ComputeLineHeight(nsIContent* aContent, + ComputedStyle* aComputedStyle, nsPresContext* aPresContext, nscoord aBlockBSize, float aFontSizeInflation) { @@ -2834,7 +2843,7 @@ static inline nscoord ComputeLineHeight(ComputedStyle* aComputedStyle, RefPtr fm = nsLayoutUtils::GetFontMetricsForComputedStyle( aComputedStyle, aPresContext, aFontSizeInflation); - return GetNormalLineHeight(fm); + return GetNormalLineHeight(aContent, fm); } nscoord ReflowInput::CalcLineHeight() const { @@ -2856,7 +2865,7 @@ nscoord ReflowInput::CalcLineHeight(nsIContent* aContent, float aFontSizeInflation) { MOZ_ASSERT(aComputedStyle, "Must have a ComputedStyle"); - nscoord lineHeight = ComputeLineHeight(aComputedStyle, aPresContext, + nscoord lineHeight = ComputeLineHeight(aContent, aComputedStyle, aPresContext, aBlockBSize, aFontSizeInflation); NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up"); diff --git a/tbb-tests/mochitest.ini b/tbb-tests/mochitest.ini index cc5172733bbed..842233827d6d8 100644 --- a/tbb-tests/mochitest.ini +++ b/tbb-tests/mochitest.ini @@ -1,3 +1,4 @@ [DEFAULT] [test_tor_bug2874.html] +[test_tor_bug23104.html] diff --git a/tbb-tests/test_tor_bug23104.html b/tbb-tests/test_tor_bug23104.html new file mode 100644 index 0000000000000..ae73a34460372 --- /dev/null +++ b/tbb-tests/test_tor_bug23104.html @@ -0,0 +1,51 @@ + + + + + Test for Tor Bug #23104: CSS line-height reveals the platform Tor browser is running + + + + + +Test1 +كلمة +ação + + + -- GitLab