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 ? rootStyle->computedFontSi
ze() : 1.0f, &style->font()) |
| 50 { |
| 51 } |
| 52 |
| 53 float CSSToLengthConversionData::FontSizes::ex() const |
| 54 { |
| 55 ASSERT(m_font); |
| 56 // FIXME: We have a bug right now where the zoom will be applied twice to EX
units. |
| 57 // We really need to compute EX using fontMetrics for the original specified
Size and not use |
| 58 // our actual constructed rendering font. |
| 59 if (!m_font->fontMetrics().hasXHeight()) |
| 60 return m_em / 2.0f; |
| 61 return m_font->fontMetrics().xHeight(); |
| 62 } |
| 63 |
| 64 float CSSToLengthConversionData::FontSizes::ch() const |
| 65 { |
| 66 ASSERT(m_font); |
| 67 return m_font->fontMetrics().zeroWidth(); |
| 68 } |
| 69 |
| 70 CSSToLengthConversionData::ViewportSize::ViewportSize(const RenderView* renderVi
ew) |
| 71 : m_width(renderView ? renderView->layoutViewportWidth() : 0) |
| 72 , m_height(renderView ? renderView->layoutViewportHeight() : 0) |
| 73 { |
| 74 } |
| 75 |
| 76 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c
onst FontSizes& fontSizes, const ViewportSize& viewportSize, float zoom) |
40 : m_style(style) | 77 : m_style(style) |
41 , m_rootStyle(rootStyle) | 78 , m_fontSizes(fontSizes) |
42 , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) | 79 , m_viewportSize(viewportSize) |
43 , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0) | |
44 , m_zoom(zoom) | 80 , m_zoom(zoom) |
45 , m_useEffectiveZoom(false) | |
46 , m_computingFontSize(computingFontSize) | |
47 { | 81 { |
| 82 ASSERT(m_style); |
48 ASSERT(zoom > 0); | 83 ASSERT(zoom > 0); |
49 } | 84 } |
50 | 85 |
51 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c
onst RenderStyle* rootStyle, const RenderView* renderView, bool computingFontSiz
e) | 86 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c
onst RenderStyle* rootStyle, const RenderView* renderView, float zoom) |
52 : m_style(style) | 87 : 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 { | 88 { |
59 } | 89 } |
60 | 90 |
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 | 91 double CSSToLengthConversionData::viewportWidthPercent() const |
81 { | 92 { |
82 m_style->setHasViewportUnits(); | 93 m_style->setHasViewportUnits(); |
83 return m_viewportWidth / 100; | 94 return m_viewportSize.width() / 100; |
84 } | 95 } |
85 double CSSToLengthConversionData::viewportHeightPercent() const | 96 double CSSToLengthConversionData::viewportHeightPercent() const |
86 { | 97 { |
87 m_style->setHasViewportUnits(); | 98 m_style->setHasViewportUnits(); |
88 return m_viewportHeight / 100; | 99 return m_viewportSize.height() / 100; |
89 } | 100 } |
90 double CSSToLengthConversionData::viewportMinPercent() const | 101 double CSSToLengthConversionData::viewportMinPercent() const |
91 { | 102 { |
92 m_style->setHasViewportUnits(); | 103 m_style->setHasViewportUnits(); |
93 return std::min(m_viewportWidth, m_viewportHeight) / 100; | 104 return std::min(m_viewportSize.width(), m_viewportSize.height()) / 100; |
94 } | 105 } |
95 double CSSToLengthConversionData::viewportMaxPercent() const | 106 double CSSToLengthConversionData::viewportMaxPercent() const |
96 { | 107 { |
97 m_style->setHasViewportUnits(); | 108 m_style->setHasViewportUnits(); |
98 return std::max(m_viewportWidth, m_viewportHeight) / 100; | 109 return std::max(m_viewportSize.width(), m_viewportSize.height()) / 100; |
99 } | 110 } |
100 | 111 |
101 } // namespace blink | 112 } // namespace blink |
OLD | NEW |