Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Unified Diff: Source/core/css/CSSToLengthConversionData.cpp

Issue 705783002: Decouple font unit conversion in computeLengthDouble from RenderStyle. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Forgot to remove ASSERT(rootStyle). Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/CSSToLengthConversionData.h ('k') | Source/core/css/resolver/StyleBuilderConverter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSToLengthConversionData.cpp
diff --git a/Source/core/css/CSSToLengthConversionData.cpp b/Source/core/css/CSSToLengthConversionData.cpp
index c2871410fd3451c546d513f50ba2765746113fed..2e97cb814f3669646715e8894d83a4b31483e9a5 100644
--- a/Source/core/css/CSSToLengthConversionData.cpp
+++ b/Source/core/css/CSSToLengthConversionData.cpp
@@ -36,66 +36,77 @@
namespace blink {
-CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const RenderStyle* rootStyle, const RenderView* renderView, float zoom, bool computingFontSize)
- : m_style(style)
- , m_rootStyle(rootStyle)
- , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0)
- , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0)
- , m_zoom(zoom)
- , m_useEffectiveZoom(false)
- , m_computingFontSize(computingFontSize)
+CSSToLengthConversionData::FontSizes::FontSizes(float em, float rem, const Font* font)
+ : m_em(em)
+ , m_rem(rem)
+ , m_font(font)
{
- ASSERT(zoom > 0);
+ // FIXME: Improve RAII of StyleResolverState to use const Font&.
+ ASSERT(m_font);
}
-CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const RenderStyle* rootStyle, const RenderView* renderView, bool computingFontSize)
- : m_style(style)
- , m_rootStyle(rootStyle)
- , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0)
- , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0)
- , m_useEffectiveZoom(true)
- , m_computingFontSize(computingFontSize)
+CSSToLengthConversionData::FontSizes::FontSizes(const RenderStyle* style, const RenderStyle* rootStyle)
+ : FontSizes(style->computedFontSize(), rootStyle ? rootStyle->computedFontSize() : 1.0f, &style->font())
+{
+}
+
+float CSSToLengthConversionData::FontSizes::ex() const
+{
+ ASSERT(m_font);
+ // FIXME: We have a bug right now where the zoom will be applied twice to EX units.
+ // We really need to compute EX using fontMetrics for the original specifiedSize and not use
+ // our actual constructed rendering font.
+ if (!m_font->fontMetrics().hasXHeight())
+ return m_em / 2.0f;
+ return m_font->fontMetrics().xHeight();
+}
+
+float CSSToLengthConversionData::FontSizes::ch() const
+{
+ ASSERT(m_font);
+ return m_font->fontMetrics().zeroWidth();
+}
+
+CSSToLengthConversionData::ViewportSize::ViewportSize(const RenderView* renderView)
+ : m_width(renderView ? renderView->layoutViewportWidth() : 0)
+ , m_height(renderView ? renderView->layoutViewportHeight() : 0)
{
}
-CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const RenderStyle* rootStyle, float viewportWidth, float viewportHeight, float zoom, bool computingFontSize)
+CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const FontSizes& fontSizes, const ViewportSize& viewportSize, float zoom)
: m_style(style)
- , m_rootStyle(rootStyle)
- , m_viewportWidth(viewportWidth)
- , m_viewportHeight(viewportHeight)
+ , m_fontSizes(fontSizes)
+ , m_viewportSize(viewportSize)
, m_zoom(zoom)
- , m_useEffectiveZoom(false)
- , m_computingFontSize(computingFontSize)
{
+ ASSERT(m_style);
ASSERT(zoom > 0);
}
-float CSSToLengthConversionData::zoom() const
+CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const RenderStyle* rootStyle, const RenderView* renderView, float zoom)
+ : CSSToLengthConversionData(style, FontSizes(style, rootStyle), ViewportSize(renderView), zoom)
{
- if (m_useEffectiveZoom)
- return m_style ? m_style->effectiveZoom() : 1;
- return m_zoom;
}
double CSSToLengthConversionData::viewportWidthPercent() const
{
m_style->setHasViewportUnits();
- return m_viewportWidth / 100;
+ return m_viewportSize.width() / 100;
}
double CSSToLengthConversionData::viewportHeightPercent() const
{
m_style->setHasViewportUnits();
- return m_viewportHeight / 100;
+ return m_viewportSize.height() / 100;
}
double CSSToLengthConversionData::viewportMinPercent() const
{
m_style->setHasViewportUnits();
- return std::min(m_viewportWidth, m_viewportHeight) / 100;
+ return std::min(m_viewportSize.width(), m_viewportSize.height()) / 100;
}
double CSSToLengthConversionData::viewportMaxPercent() const
{
m_style->setHasViewportUnits();
- return std::max(m_viewportWidth, m_viewportHeight) / 100;
+ return std::max(m_viewportSize.width(), m_viewportSize.height()) / 100;
}
} // namespace blink
« no previous file with comments | « Source/core/css/CSSToLengthConversionData.h ('k') | Source/core/css/resolver/StyleBuilderConverter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698