Chromium Code Reviews| Index: Source/core/css/CSSToLengthConversionData.cpp |
| diff --git a/Source/core/css/CSSToLengthConversionData.cpp b/Source/core/css/CSSToLengthConversionData.cpp |
| index 66583963904254f4ca9df0d03dd9e102bba52212..8b9d5277d6721f10689bba911d45c6652bcacb24 100644 |
| --- a/Source/core/css/CSSToLengthConversionData.cpp |
| +++ b/Source/core/css/CSSToLengthConversionData.cpp |
| @@ -31,6 +31,7 @@ |
| #include "config.h" |
| #include "core/css/CSSToLengthConversionData.h" |
| +#include "core/css/MediaValues.h" |
| #include "core/rendering/RenderView.h" |
| #include "core/rendering/style/RenderStyle.h" |
| @@ -39,6 +40,7 @@ namespace WebCore { |
| CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const RenderStyle* rootStyle, const RenderView* renderView, float zoom, bool computingFontSize) |
| : m_style(style) |
| , m_rootStyle(rootStyle) |
| + , m_mediaValues(0) |
| , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) |
| , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0) |
| , m_zoom(zoom) |
| @@ -48,9 +50,24 @@ CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c |
| ASSERT(zoom > 0); |
| } |
| +CSSToLengthConversionData::CSSToLengthConversionData(const MediaValues* mediaValues, float zoom, bool computingFontSize) |
|
esprehn
2014/04/08 17:40:39
This should be a reference
|
| + : m_style(0) |
| + , m_rootStyle(0) |
| + , m_mediaValues(mediaValues) |
| + , m_viewportWidth(mediaValues ? mediaValues->viewportWidth() : 0) |
| + , m_viewportHeight(mediaValues ? mediaValues->viewportHeight() : 0) |
|
esprehn
2014/04/08 17:40:39
These null checks make no sense, you ASSERT(mediaV
|
| + , m_zoom(zoom) |
| + , m_useEffectiveZoom(false) |
| + , m_computingFontSize(computingFontSize) |
| +{ |
| + ASSERT(zoom > 0); |
| + ASSERT(mediaValues); |
| +} |
| + |
| CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const RenderStyle* rootStyle, const RenderView* renderView, bool computingFontSize) |
| : m_style(style) |
| , m_rootStyle(rootStyle) |
| + , m_mediaValues(0) |
| , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) |
| , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0) |
| , m_useEffectiveZoom(true) |
| @@ -61,6 +78,7 @@ CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c |
| CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const RenderStyle* rootStyle, float viewportWidth, float viewportHeight, float zoom, bool computingFontSize) |
| : m_style(style) |
| , m_rootStyle(rootStyle) |
| + , m_mediaValues(0) |
| , m_viewportWidth(viewportWidth) |
| , m_viewportHeight(viewportHeight) |
| , m_zoom(zoom) |
| @@ -79,23 +97,92 @@ float CSSToLengthConversionData::zoom() const |
| double CSSToLengthConversionData::viewportWidthPercent() const |
| { |
| - m_style->setHasViewportUnits(); |
| + // When this is called off main thread, the RenderStyle hasViewportUnits flag will not be set |
| + if (m_style) |
| + m_style->setHasViewportUnits(); |
| return m_viewportWidth / 100; |
| } |
| double CSSToLengthConversionData::viewportHeightPercent() const |
| { |
| - m_style->setHasViewportUnits(); |
|
eseidel
2014/04/08 16:51:28
Accessors shouldn't mutate things as a side-effect
|
| + // When this is called off main thread, the RenderStyle hasViewportUnits flag will not be set |
| + if (m_style) |
| + m_style->setHasViewportUnits(); |
| return m_viewportHeight / 100; |
| } |
| double CSSToLengthConversionData::viewportMinPercent() const |
| { |
| - m_style->setHasViewportUnits(); |
| + // When this is called off main thread, the RenderStyle hasViewportUnits flag will not be set |
| + if (m_style) |
| + m_style->setHasViewportUnits(); |
| return std::min(m_viewportWidth, m_viewportHeight) / 100; |
| } |
| double CSSToLengthConversionData::viewportMaxPercent() const |
| { |
| - m_style->setHasViewportUnits(); |
| + // When this is called off main thread, the RenderStyle hasViewportUnits flag will not be set |
| + if (m_style) |
| + m_style->setHasViewportUnits(); |
| return std::max(m_viewportWidth, m_viewportHeight) / 100; |
| } |
| +bool CSSToLengthConversionData::computingFontSize() const |
| +{ |
| + return m_computingFontSize; |
| +} |
| + |
| +double CSSToLengthConversionData::fontSpecifiedSize() const |
| +{ |
| + if (m_style) |
| + return m_style->fontDescription().specifiedSize(); |
| + ASSERT(m_mediaValues); |
| + return m_mediaValues->defaultFontSize(); |
| +} |
| + |
| +double CSSToLengthConversionData::fontComputedSize() const |
| +{ |
| + if (m_style) |
| + return m_style->fontDescription().computedSize(); |
| + ASSERT(m_mediaValues); |
| + return m_mediaValues->computedFontSize(); |
| +} |
| + |
| +double CSSToLengthConversionData::rootFontSpecifiedSize() const |
| +{ |
| + if (m_rootStyle) |
| + return m_rootStyle->fontDescription().specifiedSize(); |
| + ASSERT(m_mediaValues); |
| + return m_mediaValues->defaultFontSize(); |
| +} |
| + |
| +double CSSToLengthConversionData::rootFontComputedSize() const |
| +{ |
| + if (m_rootStyle) |
| + return m_rootStyle->fontDescription().computedSize(); |
| + ASSERT(m_mediaValues); |
| + return m_mediaValues->computedFontSize(); |
| +} |
| + |
| +bool CSSToLengthConversionData::hasXHeight() const |
| +{ |
| + if (m_style) |
| + return m_style->fontMetrics().hasXHeight(); |
| + ASSERT(m_mediaValues); |
| + return m_mediaValues->hasXHeight(); |
| +} |
| + |
| +double CSSToLengthConversionData::xHeight() const |
| +{ |
| + if (m_style) |
| + return m_style->fontMetrics().xHeight(); |
| + ASSERT(m_mediaValues); |
| + return m_mediaValues->xHeight(); |
| +} |
| + |
| +double CSSToLengthConversionData::zeroWidth() const |
| +{ |
| + if (m_style) |
| + return m_style->fontMetrics().zeroWidth(); |
| + ASSERT(m_mediaValues); |
| + return m_mediaValues->zeroWidth(); |
| +} |
| + |
| } // namespace WebCore |