Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/css/MediaValuesCached.h" | |
| 7 | |
| 8 #include "core/css/CSSHelper.h" | |
| 9 #include "core/css/CSSPrimitiveValue.h" | |
| 10 | |
| 11 namespace WebCore { | |
| 12 | |
| 13 PassRefPtr<MediaValues> MediaValuesCached::create(MediaValuesInitializer& initia lizer) | |
| 14 { | |
| 15 return adoptRef(new MediaValuesCached(initializer)); | |
| 16 } | |
| 17 | |
| 18 PassRefPtr<MediaValues> MediaValuesCached::create(LocalFrame* frame, RenderStyle * style) | |
| 19 { | |
| 20 return adoptRef(new MediaValuesCached(frame, style)); | |
| 21 } | |
| 22 | |
| 23 MediaValuesCached::MediaValuesCached(LocalFrame* frame, RenderStyle* style) | |
| 24 { | |
| 25 ASSERT(frame && style); | |
| 26 m_viewportWidth = calculateViewportWidth(frame, style); | |
| 27 m_viewportHeight = calculateViewportHeight(frame, style); | |
| 28 m_deviceWidth = calculateDeviceWidth(frame); | |
| 29 m_deviceHeight = calculateDeviceHeight(frame); | |
| 30 m_devicePixelRatio = calculateDevicePixelRatio(frame); | |
| 31 m_colorBitsPerComponent = calculateColorBitsPerComponent(frame); | |
| 32 m_monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(frame); | |
| 33 m_pointer = calculateLeastCapablePrimaryPointerDeviceType(frame); | |
| 34 m_defaultFontSize = calculateDefaultFontSize(style); | |
| 35 m_computedFontSize = calculateComputedFontSize(style); | |
| 36 m_hasXHeight = calculateHasXHeight(style); | |
| 37 m_xHeight = calculateXHeight(style); | |
| 38 m_zeroWidth = calculateZeroWidth(style); | |
| 39 m_threeDEnabled = calculateThreeDEnabled(frame); | |
| 40 m_scanMediaType = calculateScanMediaType(frame); | |
| 41 m_screenMediaType = calculateScreenMediaType(frame); | |
| 42 m_printMediaType = calculatePrintMediaType(frame); | |
| 43 m_strictMode = calculateStrictMode(frame); | |
| 44 } | |
| 45 | |
| 46 MediaValuesCached::MediaValuesCached(MediaValuesInitializer& initializer) | |
| 47 : m_viewportWidth(initializer.viewportWidth) | |
| 48 , m_viewportHeight(initializer.viewportHeight) | |
| 49 , m_deviceWidth(initializer.deviceWidth) | |
| 50 , m_deviceHeight(initializer.deviceHeight) | |
| 51 , m_devicePixelRatio(initializer.devicePixelRatio) | |
| 52 , m_colorBitsPerComponent(initializer.colorBitsPerComponent) | |
| 53 , m_monochromeBitsPerComponent(initializer.monochromeBitsPerComponent) | |
| 54 , m_pointer(initializer.pointer) | |
| 55 , m_defaultFontSize(initializer.defaultFontSize) | |
| 56 , m_computedFontSize(initializer.computedFontSize) | |
| 57 , m_hasXHeight(initializer.hasXHeight) | |
| 58 , m_xHeight(initializer.xHeight) | |
| 59 , m_zeroWidth(initializer.zeroWidth) | |
| 60 , m_threeDEnabled(initializer.threeDEnabled) | |
| 61 , m_scanMediaType(initializer.scanMediaType) | |
| 62 , m_screenMediaType(initializer.screenMediaType) | |
| 63 , m_printMediaType(initializer.printMediaType) | |
| 64 , m_strictMode(initializer.strictMode) | |
| 65 { | |
| 66 } | |
| 67 | |
| 68 PassRefPtr<MediaValues> MediaValuesCached::copy() const | |
| 69 { | |
| 70 MediaValuesInitializer initializer; | |
| 71 initializer.viewportWidth = m_viewportWidth; | |
| 72 initializer.viewportHeight = m_viewportHeight; | |
| 73 initializer.deviceWidth = m_deviceWidth; | |
| 74 initializer.deviceHeight = m_deviceHeight; | |
| 75 initializer.devicePixelRatio = m_devicePixelRatio; | |
| 76 initializer.colorBitsPerComponent = m_colorBitsPerComponent; | |
| 77 initializer.monochromeBitsPerComponent = m_monochromeBitsPerComponent; | |
| 78 initializer.pointer = m_pointer; | |
| 79 initializer.defaultFontSize = m_defaultFontSize; | |
| 80 initializer.computedFontSize = m_computedFontSize; | |
| 81 initializer.hasXHeight = m_hasXHeight; | |
| 82 initializer.xHeight = m_xHeight; | |
| 83 initializer.zeroWidth = m_zeroWidth; | |
| 84 initializer.threeDEnabled = m_threeDEnabled; | |
| 85 initializer.scanMediaType = m_scanMediaType; | |
| 86 initializer.screenMediaType = m_screenMediaType; | |
| 87 initializer.printMediaType = m_printMediaType; | |
| 88 initializer.strictMode = m_strictMode; | |
| 89 | |
| 90 return adoptRef(new MediaValuesCached(initializer)); | |
| 91 } | |
| 92 | |
| 93 bool MediaValuesCached::computeLength(CSSPrimitiveValue& primitiveValue, int& re sult) const | |
| 94 { | |
| 95 unsigned short type = primitiveValue.primitiveType(); | |
| 96 double value = primitiveValue.getDoubleValue(); | |
| 97 | |
| 98 // We're running in a background thread, so RenderStyle is not available. | |
| 99 // Nevertheless, we can evaluate lengths using cached values. | |
| 100 // The logic here is duplicated from CSSPrimitiveValue::computeLengthDouble for performance reasons. | |
|
eseidel
2014/04/14 23:10:13
Why? Can't we share code? Have them both call a
| |
| 101 int factor = 0; | |
| 102 switch (type) { | |
| 103 case CSSPrimitiveValue::CSS_EMS: | |
| 104 case CSSPrimitiveValue::CSS_REMS: | |
| 105 factor = m_defaultFontSize; | |
| 106 break; | |
| 107 case CSSPrimitiveValue::CSS_PX: | |
| 108 factor = 1; | |
| 109 break; | |
| 110 case CSSPrimitiveValue::CSS_EXS: | |
| 111 // FIXME: We have a bug right now where the zoom will be applied twice t o EX units. | |
| 112 // We really need to compute EX using fontMetrics for the original speci fiedSize and not use | |
| 113 // our actual constructed rendering font. | |
| 114 if (m_hasXHeight) | |
| 115 factor = m_xHeight; | |
| 116 else | |
| 117 factor = m_defaultFontSize / 2.0; | |
| 118 break; | |
| 119 case CSSPrimitiveValue::CSS_CHS: | |
| 120 factor = m_zeroWidth; | |
| 121 break; | |
| 122 case CSSPrimitiveValue::CSS_VW: | |
| 123 factor = m_viewportWidth / 100; | |
| 124 break; | |
| 125 case CSSPrimitiveValue::CSS_VH: | |
| 126 factor = m_viewportHeight / 100; | |
| 127 break; | |
| 128 case CSSPrimitiveValue::CSS_VMIN: | |
| 129 factor = std::min(m_viewportWidth, m_viewportHeight) / 100; | |
| 130 break; | |
| 131 case CSSPrimitiveValue::CSS_VMAX: | |
| 132 factor = std::max(m_viewportWidth, m_viewportHeight) / 100; | |
| 133 break; | |
| 134 case CSSPrimitiveValue::CSS_CM: | |
| 135 factor = cssPixelsPerCentimeter; | |
| 136 break; | |
| 137 case CSSPrimitiveValue::CSS_MM: | |
| 138 factor = cssPixelsPerMillimeter; | |
| 139 break; | |
| 140 case CSSPrimitiveValue::CSS_IN: | |
| 141 factor = cssPixelsPerInch; | |
| 142 break; | |
| 143 case CSSPrimitiveValue::CSS_PT: | |
| 144 factor = cssPixelsPerPoint; | |
| 145 break; | |
| 146 case CSSPrimitiveValue::CSS_PC: | |
| 147 factor = cssPixelsPerPica; | |
| 148 break; | |
| 149 default: | |
| 150 return false; | |
| 151 } | |
| 152 | |
| 153 ASSERT(factor > 0); | |
| 154 result = roundForImpreciseConversion<int>(value*factor); | |
| 155 return true; | |
| 156 } | |
| 157 | |
| 158 bool MediaValuesCached::isSafeToSendToAnotherThread() const | |
| 159 { | |
| 160 return hasOneRef(); | |
| 161 } | |
| 162 | |
| 163 int MediaValuesCached::viewportWidth() const | |
| 164 { | |
| 165 return m_viewportWidth; | |
| 166 } | |
| 167 | |
| 168 int MediaValuesCached::viewportHeight() const | |
| 169 { | |
| 170 return m_viewportHeight; | |
| 171 } | |
| 172 | |
| 173 int MediaValuesCached::deviceWidth() const | |
| 174 { | |
| 175 return m_deviceWidth; | |
| 176 } | |
| 177 | |
| 178 int MediaValuesCached::deviceHeight() const | |
| 179 { | |
| 180 return m_deviceHeight; | |
| 181 } | |
| 182 | |
| 183 float MediaValuesCached::devicePixelRatio() const | |
| 184 { | |
| 185 return m_devicePixelRatio; | |
| 186 } | |
| 187 | |
| 188 int MediaValuesCached::colorBitsPerComponent() const | |
| 189 { | |
| 190 return m_colorBitsPerComponent; | |
| 191 } | |
| 192 | |
| 193 int MediaValuesCached::monochromeBitsPerComponent() const | |
| 194 { | |
| 195 return m_monochromeBitsPerComponent; | |
| 196 } | |
| 197 | |
| 198 MediaValues::PointerDeviceType MediaValuesCached::pointer() const | |
| 199 { | |
| 200 return m_pointer; | |
| 201 } | |
| 202 | |
| 203 bool MediaValuesCached::threeDEnabled() const | |
| 204 { | |
| 205 return m_threeDEnabled; | |
| 206 } | |
| 207 | |
| 208 bool MediaValuesCached::scanMediaType() const | |
| 209 { | |
| 210 return m_scanMediaType; | |
| 211 } | |
| 212 | |
| 213 bool MediaValuesCached::screenMediaType() const | |
| 214 { | |
| 215 return m_screenMediaType; | |
| 216 } | |
| 217 | |
| 218 bool MediaValuesCached::printMediaType() const | |
| 219 { | |
| 220 return m_printMediaType; | |
| 221 } | |
| 222 | |
| 223 bool MediaValuesCached::strictMode() const | |
| 224 { | |
| 225 return m_strictMode; | |
| 226 } | |
| 227 | |
| 228 Document* MediaValuesCached::document() const | |
| 229 { | |
| 230 return 0; | |
| 231 } | |
| 232 | |
| 233 bool MediaValuesCached::hasValues() const | |
| 234 { | |
| 235 return true; | |
| 236 } | |
| 237 | |
| 238 } // namespace | |
| OLD | NEW |