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 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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/layout/LayoutView.h" | 34 #include "core/layout/LayoutView.h" |
35 #include "core/layout/style/LayoutStyle.h" | 35 #include "core/layout/style/ComputedStyle.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 CSSToLengthConversionData::FontSizes::FontSizes(float em, float rem, const Font*
font) | 39 CSSToLengthConversionData::FontSizes::FontSizes(float em, float rem, const Font*
font) |
40 : m_em(em) | 40 : m_em(em) |
41 , m_rem(rem) | 41 , m_rem(rem) |
42 , m_font(font) | 42 , m_font(font) |
43 { | 43 { |
44 // FIXME: Improve RAII of StyleResolverState to use const Font&. | 44 // FIXME: Improve RAII of StyleResolverState to use const Font&. |
45 ASSERT(m_font); | 45 ASSERT(m_font); |
46 } | 46 } |
47 | 47 |
48 CSSToLengthConversionData::FontSizes::FontSizes(const LayoutStyle* style, const
LayoutStyle* rootStyle) | 48 CSSToLengthConversionData::FontSizes::FontSizes(const ComputedStyle* style, cons
t ComputedStyle* rootStyle) |
49 : FontSizes(style->computedFontSize(), rootStyle ? rootStyle->computedFontSi
ze() : 1.0f, &style->font()) | 49 : FontSizes(style->computedFontSize(), rootStyle ? rootStyle->computedFontSi
ze() : 1.0f, &style->font()) |
50 { | 50 { |
51 } | 51 } |
52 | 52 |
53 float CSSToLengthConversionData::FontSizes::ex() const | 53 float CSSToLengthConversionData::FontSizes::ex() const |
54 { | 54 { |
55 ASSERT(m_font); | 55 ASSERT(m_font); |
56 // FIXME: We have a bug right now where the zoom will be applied twice to EX
units. | 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 | 57 // We really need to compute EX using fontMetrics for the original specified
Size and not use |
58 // our actual constructed rendering font. | 58 // our actual constructed rendering font. |
59 if (!m_font->fontMetrics().hasXHeight()) | 59 if (!m_font->fontMetrics().hasXHeight()) |
60 return m_em / 2.0f; | 60 return m_em / 2.0f; |
61 return m_font->fontMetrics().xHeight(); | 61 return m_font->fontMetrics().xHeight(); |
62 } | 62 } |
63 | 63 |
64 float CSSToLengthConversionData::FontSizes::ch() const | 64 float CSSToLengthConversionData::FontSizes::ch() const |
65 { | 65 { |
66 ASSERT(m_font); | 66 ASSERT(m_font); |
67 return m_font->fontMetrics().zeroWidth(); | 67 return m_font->fontMetrics().zeroWidth(); |
68 } | 68 } |
69 | 69 |
70 CSSToLengthConversionData::ViewportSize::ViewportSize(const LayoutView* layoutVi
ew) | 70 CSSToLengthConversionData::ViewportSize::ViewportSize(const LayoutView* layoutVi
ew) |
71 : m_width(layoutView ? layoutView->layoutViewportWidth() : 0) | 71 : m_width(layoutView ? layoutView->layoutViewportWidth() : 0) |
72 , m_height(layoutView ? layoutView->layoutViewportHeight() : 0) | 72 , m_height(layoutView ? layoutView->layoutViewportHeight() : 0) |
73 { | 73 { |
74 } | 74 } |
75 | 75 |
76 CSSToLengthConversionData::CSSToLengthConversionData(const LayoutStyle* style, c
onst FontSizes& fontSizes, const ViewportSize& viewportSize, float zoom) | 76 CSSToLengthConversionData::CSSToLengthConversionData(const ComputedStyle* style,
const FontSizes& fontSizes, const ViewportSize& viewportSize, float zoom) |
77 : m_style(style) | 77 : m_style(style) |
78 , m_fontSizes(fontSizes) | 78 , m_fontSizes(fontSizes) |
79 , m_viewportSize(viewportSize) | 79 , m_viewportSize(viewportSize) |
80 , m_zoom(clampTo<float>(zoom, std::numeric_limits<float>::denorm_min())) | 80 , m_zoom(clampTo<float>(zoom, std::numeric_limits<float>::denorm_min())) |
81 { | 81 { |
82 ASSERT(m_style); | 82 ASSERT(m_style); |
83 } | 83 } |
84 | 84 |
85 CSSToLengthConversionData::CSSToLengthConversionData(const LayoutStyle* style, c
onst LayoutStyle* rootStyle, const LayoutView* layoutView, float zoom) | 85 CSSToLengthConversionData::CSSToLengthConversionData(const ComputedStyle* style,
const ComputedStyle* rootStyle, const LayoutView* layoutView, float zoom) |
86 : CSSToLengthConversionData(style, FontSizes(style, rootStyle), ViewportSize
(layoutView), zoom) | 86 : CSSToLengthConversionData(style, FontSizes(style, rootStyle), ViewportSize
(layoutView), zoom) |
87 { | 87 { |
88 } | 88 } |
89 | 89 |
90 double CSSToLengthConversionData::viewportWidthPercent() const | 90 double CSSToLengthConversionData::viewportWidthPercent() const |
91 { | 91 { |
92 m_style->setHasViewportUnits(); | 92 m_style->setHasViewportUnits(); |
93 return m_viewportSize.width() / 100; | 93 return m_viewportSize.width() / 100; |
94 } | 94 } |
95 double CSSToLengthConversionData::viewportHeightPercent() const | 95 double CSSToLengthConversionData::viewportHeightPercent() const |
96 { | 96 { |
97 m_style->setHasViewportUnits(); | 97 m_style->setHasViewportUnits(); |
98 return m_viewportSize.height() / 100; | 98 return m_viewportSize.height() / 100; |
99 } | 99 } |
100 double CSSToLengthConversionData::viewportMinPercent() const | 100 double CSSToLengthConversionData::viewportMinPercent() const |
101 { | 101 { |
102 m_style->setHasViewportUnits(); | 102 m_style->setHasViewportUnits(); |
103 return std::min(m_viewportSize.width(), m_viewportSize.height()) / 100; | 103 return std::min(m_viewportSize.width(), m_viewportSize.height()) / 100; |
104 } | 104 } |
105 double CSSToLengthConversionData::viewportMaxPercent() const | 105 double CSSToLengthConversionData::viewportMaxPercent() const |
106 { | 106 { |
107 m_style->setHasViewportUnits(); | 107 m_style->setHasViewportUnits(); |
108 return std::max(m_viewportSize.width(), m_viewportSize.height()) / 100; | 108 return std::max(m_viewportSize.width(), m_viewportSize.height()) / 100; |
109 } | 109 } |
110 | 110 |
111 } // namespace blink | 111 } // namespace blink |
OLD | NEW |