Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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/css/MediaValues.h" | |
| 34 #include "core/rendering/RenderView.h" | 35 #include "core/rendering/RenderView.h" |
| 35 #include "core/rendering/style/RenderStyle.h" | 36 #include "core/rendering/style/RenderStyle.h" |
| 36 | 37 |
| 37 namespace WebCore { | 38 namespace WebCore { |
| 38 | 39 |
| 39 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, const RenderView* renderView, float zoom, bool comp utingFontSize) | 40 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, const RenderView* renderView, float zoom, bool comp utingFontSize) |
| 40 : m_style(style) | 41 : m_style(style) |
| 41 , m_rootStyle(rootStyle) | 42 , m_rootStyle(rootStyle) |
| 43 , m_mediaValues(0) | |
| 42 , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) | 44 , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) |
| 43 , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0) | 45 , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0) |
| 44 , m_zoom(zoom) | 46 , m_zoom(zoom) |
| 45 , m_useEffectiveZoom(false) | 47 , m_useEffectiveZoom(false) |
| 46 , m_computingFontSize(computingFontSize) | 48 , m_computingFontSize(computingFontSize) |
| 47 { | 49 { |
| 48 ASSERT(zoom > 0); | 50 ASSERT(zoom > 0); |
| 49 } | 51 } |
| 50 | 52 |
| 53 CSSToLengthConversionData::CSSToLengthConversionData(const MediaValues* mediaVal ues, float zoom, bool computingFontSize) | |
|
esprehn
2014/04/08 17:40:39
This should be a reference
| |
| 54 : m_style(0) | |
| 55 , m_rootStyle(0) | |
| 56 , m_mediaValues(mediaValues) | |
| 57 , m_viewportWidth(mediaValues ? mediaValues->viewportWidth() : 0) | |
| 58 , m_viewportHeight(mediaValues ? mediaValues->viewportHeight() : 0) | |
|
esprehn
2014/04/08 17:40:39
These null checks make no sense, you ASSERT(mediaV
| |
| 59 , m_zoom(zoom) | |
| 60 , m_useEffectiveZoom(false) | |
| 61 , m_computingFontSize(computingFontSize) | |
| 62 { | |
| 63 ASSERT(zoom > 0); | |
| 64 ASSERT(mediaValues); | |
| 65 } | |
| 66 | |
| 51 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, const RenderView* renderView, bool computingFontSiz e) | 67 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, const RenderView* renderView, bool computingFontSiz e) |
| 52 : m_style(style) | 68 : m_style(style) |
| 53 , m_rootStyle(rootStyle) | 69 , m_rootStyle(rootStyle) |
| 70 , m_mediaValues(0) | |
| 54 , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) | 71 , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) |
| 55 , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0) | 72 , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0) |
| 56 , m_useEffectiveZoom(true) | 73 , m_useEffectiveZoom(true) |
| 57 , m_computingFontSize(computingFontSize) | 74 , m_computingFontSize(computingFontSize) |
| 58 { | 75 { |
| 59 } | 76 } |
| 60 | 77 |
| 61 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, float viewportWidth, float viewportHeight, float zo om, bool computingFontSize) | 78 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, float viewportWidth, float viewportHeight, float zo om, bool computingFontSize) |
| 62 : m_style(style) | 79 : m_style(style) |
| 63 , m_rootStyle(rootStyle) | 80 , m_rootStyle(rootStyle) |
| 81 , m_mediaValues(0) | |
| 64 , m_viewportWidth(viewportWidth) | 82 , m_viewportWidth(viewportWidth) |
| 65 , m_viewportHeight(viewportHeight) | 83 , m_viewportHeight(viewportHeight) |
| 66 , m_zoom(zoom) | 84 , m_zoom(zoom) |
| 67 , m_useEffectiveZoom(false) | 85 , m_useEffectiveZoom(false) |
| 68 , m_computingFontSize(computingFontSize) | 86 , m_computingFontSize(computingFontSize) |
| 69 { | 87 { |
| 70 ASSERT(zoom > 0); | 88 ASSERT(zoom > 0); |
| 71 } | 89 } |
| 72 | 90 |
| 73 float CSSToLengthConversionData::zoom() const | 91 float CSSToLengthConversionData::zoom() const |
| 74 { | 92 { |
| 75 if (m_useEffectiveZoom) | 93 if (m_useEffectiveZoom) |
| 76 return m_style ? m_style->effectiveZoom() : 1; | 94 return m_style ? m_style->effectiveZoom() : 1; |
| 77 return m_zoom; | 95 return m_zoom; |
| 78 } | 96 } |
| 79 | 97 |
| 80 double CSSToLengthConversionData::viewportWidthPercent() const | 98 double CSSToLengthConversionData::viewportWidthPercent() const |
| 81 { | 99 { |
| 82 m_style->setHasViewportUnits(); | 100 // When this is called off main thread, the RenderStyle hasViewportUnits fla g will not be set |
| 101 if (m_style) | |
| 102 m_style->setHasViewportUnits(); | |
| 83 return m_viewportWidth / 100; | 103 return m_viewportWidth / 100; |
| 84 } | 104 } |
| 85 double CSSToLengthConversionData::viewportHeightPercent() const | 105 double CSSToLengthConversionData::viewportHeightPercent() const |
| 86 { | 106 { |
| 87 m_style->setHasViewportUnits(); | 107 // When this is called off main thread, the RenderStyle hasViewportUnits fla g will not be set |
|
eseidel
2014/04/08 16:51:28
Accessors shouldn't mutate things as a side-effect
| |
| 108 if (m_style) | |
| 109 m_style->setHasViewportUnits(); | |
| 88 return m_viewportHeight / 100; | 110 return m_viewportHeight / 100; |
| 89 } | 111 } |
| 90 double CSSToLengthConversionData::viewportMinPercent() const | 112 double CSSToLengthConversionData::viewportMinPercent() const |
| 91 { | 113 { |
| 92 m_style->setHasViewportUnits(); | 114 // When this is called off main thread, the RenderStyle hasViewportUnits fla g will not be set |
| 115 if (m_style) | |
| 116 m_style->setHasViewportUnits(); | |
| 93 return std::min(m_viewportWidth, m_viewportHeight) / 100; | 117 return std::min(m_viewportWidth, m_viewportHeight) / 100; |
| 94 } | 118 } |
| 95 double CSSToLengthConversionData::viewportMaxPercent() const | 119 double CSSToLengthConversionData::viewportMaxPercent() const |
| 96 { | 120 { |
| 97 m_style->setHasViewportUnits(); | 121 // When this is called off main thread, the RenderStyle hasViewportUnits fla g will not be set |
| 122 if (m_style) | |
| 123 m_style->setHasViewportUnits(); | |
| 98 return std::max(m_viewportWidth, m_viewportHeight) / 100; | 124 return std::max(m_viewportWidth, m_viewportHeight) / 100; |
| 99 } | 125 } |
| 100 | 126 |
| 127 bool CSSToLengthConversionData::computingFontSize() const | |
| 128 { | |
| 129 return m_computingFontSize; | |
| 130 } | |
| 131 | |
| 132 double CSSToLengthConversionData::fontSpecifiedSize() const | |
| 133 { | |
| 134 if (m_style) | |
| 135 return m_style->fontDescription().specifiedSize(); | |
| 136 ASSERT(m_mediaValues); | |
| 137 return m_mediaValues->defaultFontSize(); | |
| 138 } | |
| 139 | |
| 140 double CSSToLengthConversionData::fontComputedSize() const | |
| 141 { | |
| 142 if (m_style) | |
| 143 return m_style->fontDescription().computedSize(); | |
| 144 ASSERT(m_mediaValues); | |
| 145 return m_mediaValues->computedFontSize(); | |
| 146 } | |
| 147 | |
| 148 double CSSToLengthConversionData::rootFontSpecifiedSize() const | |
| 149 { | |
| 150 if (m_rootStyle) | |
| 151 return m_rootStyle->fontDescription().specifiedSize(); | |
| 152 ASSERT(m_mediaValues); | |
| 153 return m_mediaValues->defaultFontSize(); | |
| 154 } | |
| 155 | |
| 156 double CSSToLengthConversionData::rootFontComputedSize() const | |
| 157 { | |
| 158 if (m_rootStyle) | |
| 159 return m_rootStyle->fontDescription().computedSize(); | |
| 160 ASSERT(m_mediaValues); | |
| 161 return m_mediaValues->computedFontSize(); | |
| 162 } | |
| 163 | |
| 164 bool CSSToLengthConversionData::hasXHeight() const | |
| 165 { | |
| 166 if (m_style) | |
| 167 return m_style->fontMetrics().hasXHeight(); | |
| 168 ASSERT(m_mediaValues); | |
| 169 return m_mediaValues->hasXHeight(); | |
| 170 } | |
| 171 | |
| 172 double CSSToLengthConversionData::xHeight() const | |
| 173 { | |
| 174 if (m_style) | |
| 175 return m_style->fontMetrics().xHeight(); | |
| 176 ASSERT(m_mediaValues); | |
| 177 return m_mediaValues->xHeight(); | |
| 178 } | |
| 179 | |
| 180 double CSSToLengthConversionData::zeroWidth() const | |
| 181 { | |
| 182 if (m_style) | |
| 183 return m_style->fontMetrics().zeroWidth(); | |
| 184 ASSERT(m_mediaValues); | |
| 185 return m_mediaValues->zeroWidth(); | |
| 186 } | |
| 187 | |
| 101 } // namespace WebCore | 188 } // namespace WebCore |
| OLD | NEW |