| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/css/CSSToLengthConversionData.h" | 32 #include "core/css/CSSToLengthConversionData.h" |
| 33 | 33 |
| 34 #include "core/rendering/RenderView.h" | 34 #include "core/rendering/RenderView.h" |
| 35 #include "core/rendering/style/RenderStyle.h" | 35 #include "core/rendering/style/RenderStyle.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c
onst RenderStyle* rootStyle, const RenderView* renderView, float zoom, bool comp
utingFontSize) | 39 CSSToLengthConversionData::FontSizes::FontSizes(float em, float rem, const Font*
font) |
| 40 : m_em(em) |
| 41 , m_rem(rem) |
| 42 , m_font(font) |
| 43 { |
| 44 // FIXME: Improve RAII of StyleResolverState to use const Font&. |
| 45 ASSERT(m_font); |
| 46 } |
| 47 |
| 48 CSSToLengthConversionData::FontSizes::FontSizes(const RenderStyle* style, const
RenderStyle* rootStyle) |
| 49 : FontSizes(style->computedFontSize(), rootStyle->computedFontSize(), &style
->font()) |
| 50 { |
| 51 ASSERT(rootStyle); |
| 52 } |
| 53 |
| 54 float CSSToLengthConversionData::FontSizes::ex() const |
| 55 { |
| 56 ASSERT(m_font); |
| 57 // FIXME: We have a bug right now where the zoom will be applied twice to EX
units. |
| 58 // We really need to compute EX using fontMetrics for the original specified
Size and not use |
| 59 // our actual constructed rendering font. |
| 60 if (!m_font->fontMetrics().hasXHeight()) |
| 61 return m_em / 2.0f; |
| 62 return m_font->fontMetrics().xHeight(); |
| 63 } |
| 64 |
| 65 float CSSToLengthConversionData::FontSizes::ch() const |
| 66 { |
| 67 ASSERT(m_font); |
| 68 return m_font->fontMetrics().zeroWidth(); |
| 69 } |
| 70 |
| 71 CSSToLengthConversionData::ViewportSize::ViewportSize(const RenderView* renderVi
ew) |
| 72 : m_width(renderView ? renderView->layoutViewportWidth() : 0) |
| 73 , m_height(renderView ? renderView->layoutViewportHeight() : 0) |
| 74 { |
| 75 } |
| 76 |
| 77 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c
onst FontSizes& fontSizes, const ViewportSize& viewportSize, float zoom) |
| 40 : m_style(style) | 78 : m_style(style) |
| 41 , m_rootStyle(rootStyle) | 79 , m_fontSizes(fontSizes) |
| 42 , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) | 80 , m_viewportSize(viewportSize) |
| 43 , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0) | |
| 44 , m_zoom(zoom) | 81 , m_zoom(zoom) |
| 45 , m_useEffectiveZoom(false) | |
| 46 , m_computingFontSize(computingFontSize) | |
| 47 { | 82 { |
| 83 ASSERT(m_style); |
| 48 ASSERT(zoom > 0); | 84 ASSERT(zoom > 0); |
| 49 } | 85 } |
| 50 | 86 |
| 51 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c
onst RenderStyle* rootStyle, const RenderView* renderView, bool computingFontSiz
e) | 87 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c
onst RenderStyle* rootStyle, const RenderView* renderView, float zoom) |
| 52 : m_style(style) | 88 : CSSToLengthConversionData(style, FontSizes(style, rootStyle), ViewportSize
(renderView), zoom) |
| 53 , m_rootStyle(rootStyle) | |
| 54 , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) | |
| 55 , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0) | |
| 56 , m_useEffectiveZoom(true) | |
| 57 , m_computingFontSize(computingFontSize) | |
| 58 { | 89 { |
| 59 } | 90 } |
| 60 | 91 |
| 61 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c
onst RenderStyle* rootStyle, float viewportWidth, float viewportHeight, float zo
om, bool computingFontSize) | |
| 62 : m_style(style) | |
| 63 , m_rootStyle(rootStyle) | |
| 64 , m_viewportWidth(viewportWidth) | |
| 65 , m_viewportHeight(viewportHeight) | |
| 66 , m_zoom(zoom) | |
| 67 , m_useEffectiveZoom(false) | |
| 68 , m_computingFontSize(computingFontSize) | |
| 69 { | |
| 70 ASSERT(zoom > 0); | |
| 71 } | |
| 72 | |
| 73 float CSSToLengthConversionData::zoom() const | |
| 74 { | |
| 75 if (m_useEffectiveZoom) | |
| 76 return m_style ? m_style->effectiveZoom() : 1; | |
| 77 return m_zoom; | |
| 78 } | |
| 79 | |
| 80 double CSSToLengthConversionData::viewportWidthPercent() const | 92 double CSSToLengthConversionData::viewportWidthPercent() const |
| 81 { | 93 { |
| 82 m_style->setHasViewportUnits(); | 94 m_style->setHasViewportUnits(); |
| 83 return m_viewportWidth / 100; | 95 return m_viewportSize.width() / 100; |
| 84 } | 96 } |
| 85 double CSSToLengthConversionData::viewportHeightPercent() const | 97 double CSSToLengthConversionData::viewportHeightPercent() const |
| 86 { | 98 { |
| 87 m_style->setHasViewportUnits(); | 99 m_style->setHasViewportUnits(); |
| 88 return m_viewportHeight / 100; | 100 return m_viewportSize.height() / 100; |
| 89 } | 101 } |
| 90 double CSSToLengthConversionData::viewportMinPercent() const | 102 double CSSToLengthConversionData::viewportMinPercent() const |
| 91 { | 103 { |
| 92 m_style->setHasViewportUnits(); | 104 m_style->setHasViewportUnits(); |
| 93 return std::min(m_viewportWidth, m_viewportHeight) / 100; | 105 return std::min(m_viewportSize.width(), m_viewportSize.height()) / 100; |
| 94 } | 106 } |
| 95 double CSSToLengthConversionData::viewportMaxPercent() const | 107 double CSSToLengthConversionData::viewportMaxPercent() const |
| 96 { | 108 { |
| 97 m_style->setHasViewportUnits(); | 109 m_style->setHasViewportUnits(); |
| 98 return std::max(m_viewportWidth, m_viewportHeight) / 100; | 110 return std::max(m_viewportSize.width(), m_viewportSize.height()) / 100; |
| 99 } | 111 } |
| 100 | 112 |
| 101 } // namespace blink | 113 } // namespace blink |
| OLD | NEW |