Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/css/MediaValuesCached.h" | 6 #include "core/css/MediaValuesCached.h" |
| 7 | 7 |
| 8 #include "core/css/CSSHelper.h" | |
| 9 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 10 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/html/imports/HTMLImportsController.h" | |
| 11 #include "core/rendering/RenderObject.h" | 11 #include "core/rendering/RenderObject.h" |
| 12 | 12 |
| 13 namespace WebCore { | 13 namespace WebCore { |
| 14 | 14 |
| 15 PassRefPtr<MediaValues> MediaValuesCached::create(MediaValuesCachedData& data) | 15 PassRefPtr<MediaValues> MediaValuesCached::create(MediaValuesCachedData& data) |
| 16 { | 16 { |
| 17 return adoptRef(new MediaValuesCached(data)); | 17 return adoptRef(new MediaValuesCached(data)); |
| 18 } | 18 } |
| 19 | 19 |
| 20 PassRefPtr<MediaValues> MediaValuesCached::create(Document& document) | 20 PassRefPtr<MediaValues> MediaValuesCached::create(Document& document) |
| 21 { | 21 { |
| 22 Document* executingDocument = getExecutingDocument(document); | 22 Document* executingDocument = document.importsController() ? document.import sController()->master() : &document; |
| 23 return MediaValuesCached::create(executingDocument->frame(), executingDocume nt->renderer()->style()); | 23 ASSERT(executingDocument); |
| 24 return MediaValuesCached::create(executingDocument->frame()); | |
| 24 } | 25 } |
| 25 | 26 |
| 26 PassRefPtr<MediaValues> MediaValuesCached::create(LocalFrame* frame, RenderStyle * style) | 27 PassRefPtr<MediaValues> MediaValuesCached::create(LocalFrame* frame) |
| 27 { | 28 { |
| 28 return adoptRef(new MediaValuesCached(frame, style)); | 29 return adoptRef(new MediaValuesCached(frame)); |
| 29 } | 30 } |
| 30 | 31 |
| 31 MediaValuesCached::MediaValuesCached(LocalFrame* frame, RenderStyle* style) | 32 MediaValuesCached::MediaValuesCached(LocalFrame* frame) |
| 32 { | 33 { |
| 33 ASSERT(frame && style); | |
| 34 ASSERT(isMainThread()); | 34 ASSERT(isMainThread()); |
| 35 // In case that frame is missing (e.g. for images that their document does n ot have a frame) | |
| 36 // We simply leave the MediaValues object with the default MediaValuesCached Data values. | |
| 37 if (!frame) | |
|
eseidel
2014/04/18 20:41:33
I'm not sure you wnat this. I would just ASSERT(f
| |
| 38 return; | |
| 35 m_data.viewportWidth = calculateViewportWidth(frame); | 39 m_data.viewportWidth = calculateViewportWidth(frame); |
| 36 m_data.viewportHeight = calculateViewportHeight(frame); | 40 m_data.viewportHeight = calculateViewportHeight(frame); |
| 37 m_data.deviceWidth = calculateDeviceWidth(frame); | 41 m_data.deviceWidth = calculateDeviceWidth(frame); |
| 38 m_data.deviceHeight = calculateDeviceHeight(frame); | 42 m_data.deviceHeight = calculateDeviceHeight(frame); |
| 39 m_data.devicePixelRatio = calculateDevicePixelRatio(frame); | 43 m_data.devicePixelRatio = calculateDevicePixelRatio(frame); |
| 40 m_data.colorBitsPerComponent = calculateColorBitsPerComponent(frame); | 44 m_data.colorBitsPerComponent = calculateColorBitsPerComponent(frame); |
| 41 m_data.monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(fram e); | 45 m_data.monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(fram e); |
| 42 m_data.pointer = calculateLeastCapablePrimaryPointerDeviceType(frame); | 46 m_data.pointer = calculateLeastCapablePrimaryPointerDeviceType(frame); |
| 43 m_data.defaultFontSize = calculateDefaultFontSize(style); | 47 m_data.defaultFontSize = calculateDefaultFontSize(frame); |
| 44 m_data.computedFontSize = calculateComputedFontSize(style); | |
| 45 m_data.threeDEnabled = calculateThreeDEnabled(frame); | 48 m_data.threeDEnabled = calculateThreeDEnabled(frame); |
| 46 m_data.scanMediaType = calculateScanMediaType(frame); | 49 m_data.scanMediaType = calculateScanMediaType(frame); |
| 47 m_data.screenMediaType = calculateScreenMediaType(frame); | 50 m_data.screenMediaType = calculateScreenMediaType(frame); |
| 48 m_data.printMediaType = calculatePrintMediaType(frame); | 51 m_data.printMediaType = calculatePrintMediaType(frame); |
| 49 m_data.strictMode = calculateStrictMode(frame); | 52 m_data.strictMode = calculateStrictMode(frame); |
| 50 } | 53 } |
| 51 | 54 |
| 52 MediaValuesCached::MediaValuesCached(const MediaValuesCachedData& data) | 55 MediaValuesCached::MediaValuesCached(const MediaValuesCachedData& data) |
| 53 : m_data(data) | 56 : m_data(data) |
| 54 { | 57 { |
| 55 } | 58 } |
| 56 | 59 |
| 57 PassRefPtr<MediaValues> MediaValuesCached::copy() const | 60 PassRefPtr<MediaValues> MediaValuesCached::copy() const |
| 58 { | 61 { |
| 59 return adoptRef(new MediaValuesCached(m_data)); | 62 return adoptRef(new MediaValuesCached(m_data)); |
| 60 } | 63 } |
| 61 | 64 |
| 62 bool MediaValuesCached::computeLength(double value, unsigned short type, int& re sult) const | 65 bool MediaValuesCached::computeLength(double value, unsigned short type, int& re sult) const |
| 63 { | 66 { |
| 64 // We're running in a background thread, so RenderStyle is not available. | 67 return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_dat a.viewportWidth, m_data.viewportHeight, result); |
| 65 // Nevertheless, we can evaluate lengths using cached values. | |
| 66 // | |
| 67 // The logic in this function is duplicated from CSSPrimitiveValue::computeL engthDouble | |
| 68 // because MediaValues::computeLength needs nearly identical logic, but we h aven't found a way to make | |
| 69 // CSSPrimitiveValue::computeLengthDouble more generic (to solve both cases) without hurting performance. | |
| 70 | |
| 71 // FIXME - Unite the logic here with CSSPrimitiveValue is a performant way. | |
| 72 int factor = 0; | |
| 73 switch (type) { | |
| 74 case CSSPrimitiveValue::CSS_EMS: | |
| 75 case CSSPrimitiveValue::CSS_REMS: | |
| 76 factor = m_data.defaultFontSize; | |
| 77 break; | |
| 78 case CSSPrimitiveValue::CSS_PX: | |
| 79 factor = 1; | |
| 80 break; | |
| 81 case CSSPrimitiveValue::CSS_EXS: | |
| 82 // FIXME: We have a bug right now where the zoom will be applied twice t o EX units. | |
| 83 // FIXME: We don't seem to be able to cache fontMetrics related values. | |
| 84 // Trying to access them is triggering some sort of microtask. Serving t he spec's default instead. | |
| 85 factor = m_data.defaultFontSize / 2.0; | |
| 86 break; | |
| 87 case CSSPrimitiveValue::CSS_CHS: | |
| 88 // FIXME: We don't seem to be able to cache fontMetrics related values. | |
| 89 // Trying to access them is triggering some sort of microtask. Serving t he (future) spec default instead. | |
| 90 factor = m_data.defaultFontSize / 2.0; | |
| 91 break; | |
| 92 case CSSPrimitiveValue::CSS_VW: | |
| 93 factor = m_data.viewportWidth / 100; | |
| 94 break; | |
| 95 case CSSPrimitiveValue::CSS_VH: | |
| 96 factor = m_data.viewportHeight / 100; | |
| 97 break; | |
| 98 case CSSPrimitiveValue::CSS_VMIN: | |
| 99 factor = std::min(m_data.viewportWidth, m_data.viewportHeight) / 100; | |
| 100 break; | |
| 101 case CSSPrimitiveValue::CSS_VMAX: | |
| 102 factor = std::max(m_data.viewportWidth, m_data.viewportHeight) / 100; | |
| 103 break; | |
| 104 case CSSPrimitiveValue::CSS_CM: | |
| 105 factor = cssPixelsPerCentimeter; | |
| 106 break; | |
| 107 case CSSPrimitiveValue::CSS_MM: | |
| 108 factor = cssPixelsPerMillimeter; | |
| 109 break; | |
| 110 case CSSPrimitiveValue::CSS_IN: | |
| 111 factor = cssPixelsPerInch; | |
| 112 break; | |
| 113 case CSSPrimitiveValue::CSS_PT: | |
| 114 factor = cssPixelsPerPoint; | |
| 115 break; | |
| 116 case CSSPrimitiveValue::CSS_PC: | |
| 117 factor = cssPixelsPerPica; | |
| 118 break; | |
| 119 default: | |
| 120 return false; | |
| 121 } | |
| 122 | |
| 123 ASSERT(factor > 0); | |
| 124 result = roundForImpreciseConversion<int>(value*factor); | |
| 125 return true; | |
| 126 } | 68 } |
| 127 | 69 |
| 128 bool MediaValuesCached::isSafeToSendToAnotherThread() const | 70 bool MediaValuesCached::isSafeToSendToAnotherThread() const |
| 129 { | 71 { |
| 130 return hasOneRef(); | 72 return hasOneRef(); |
| 131 } | 73 } |
| 132 | 74 |
| 133 int MediaValuesCached::viewportWidth() const | 75 int MediaValuesCached::viewportWidth() const |
| 134 { | 76 { |
| 135 return m_data.viewportWidth; | 77 return m_data.viewportWidth; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 { | 141 { |
| 200 return 0; | 142 return 0; |
| 201 } | 143 } |
| 202 | 144 |
| 203 bool MediaValuesCached::hasValues() const | 145 bool MediaValuesCached::hasValues() const |
| 204 { | 146 { |
| 205 return true; | 147 return true; |
| 206 } | 148 } |
| 207 | 149 |
| 208 } // namespace | 150 } // namespace |
| OLD | NEW |