 Chromium Code Reviews
 Chromium Code Reviews Issue 242883002:
  Remove MediaValues' dependency on RenderStyle  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 242883002:
  Remove MediaValues' dependency on RenderStyle  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| Index: Source/core/css/MediaValuesCached.cpp | 
| diff --git a/Source/core/css/MediaValuesCached.cpp b/Source/core/css/MediaValuesCached.cpp | 
| index d83a4b919b4bb392e63f6a394e06348971fb12fa..df0c9b1cc4e92d01a813dba245ec1041ae0ffb18 100644 | 
| --- a/Source/core/css/MediaValuesCached.cpp | 
| +++ b/Source/core/css/MediaValuesCached.cpp | 
| @@ -5,9 +5,9 @@ | 
| #include "config.h" | 
| #include "core/css/MediaValuesCached.h" | 
| -#include "core/css/CSSHelper.h" | 
| #include "core/css/CSSPrimitiveValue.h" | 
| #include "core/dom/Document.h" | 
| +#include "core/html/imports/HTMLImportsController.h" | 
| #include "core/rendering/RenderObject.h" | 
| namespace WebCore { | 
| @@ -19,19 +19,23 @@ PassRefPtr<MediaValues> MediaValuesCached::create(MediaValuesCachedData& data) | 
| PassRefPtr<MediaValues> MediaValuesCached::create(Document& document) | 
| { | 
| - Document* executingDocument = getExecutingDocument(document); | 
| - return MediaValuesCached::create(executingDocument->frame(), executingDocument->renderer()->style()); | 
| + Document* executingDocument = document.importsController() ? document.importsController()->master() : &document; | 
| + ASSERT(executingDocument); | 
| + return MediaValuesCached::create(executingDocument->frame()); | 
| } | 
| -PassRefPtr<MediaValues> MediaValuesCached::create(LocalFrame* frame, RenderStyle* style) | 
| +PassRefPtr<MediaValues> MediaValuesCached::create(LocalFrame* frame) | 
| { | 
| - return adoptRef(new MediaValuesCached(frame, style)); | 
| + return adoptRef(new MediaValuesCached(frame)); | 
| } | 
| -MediaValuesCached::MediaValuesCached(LocalFrame* frame, RenderStyle* style) | 
| +MediaValuesCached::MediaValuesCached(LocalFrame* frame) | 
| { | 
| - ASSERT(frame && style); | 
| ASSERT(isMainThread()); | 
| + // In case that frame is missing (e.g. for images that their document does not have a frame) | 
| + // We simply leave the MediaValues object with the default MediaValuesCachedData values. | 
| + if (!frame) | 
| 
eseidel
2014/04/18 20:41:33
I'm not sure you wnat this.  I would just ASSERT(f
 | 
| + return; | 
| m_data.viewportWidth = calculateViewportWidth(frame); | 
| m_data.viewportHeight = calculateViewportHeight(frame); | 
| m_data.deviceWidth = calculateDeviceWidth(frame); | 
| @@ -40,8 +44,7 @@ MediaValuesCached::MediaValuesCached(LocalFrame* frame, RenderStyle* style) | 
| m_data.colorBitsPerComponent = calculateColorBitsPerComponent(frame); | 
| m_data.monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(frame); | 
| m_data.pointer = calculateLeastCapablePrimaryPointerDeviceType(frame); | 
| - m_data.defaultFontSize = calculateDefaultFontSize(style); | 
| - m_data.computedFontSize = calculateComputedFontSize(style); | 
| + m_data.defaultFontSize = calculateDefaultFontSize(frame); | 
| m_data.threeDEnabled = calculateThreeDEnabled(frame); | 
| m_data.scanMediaType = calculateScanMediaType(frame); | 
| m_data.screenMediaType = calculateScreenMediaType(frame); | 
| @@ -61,68 +64,7 @@ PassRefPtr<MediaValues> MediaValuesCached::copy() const | 
| bool MediaValuesCached::computeLength(double value, unsigned short type, int& result) const | 
| { | 
| - // We're running in a background thread, so RenderStyle is not available. | 
| - // Nevertheless, we can evaluate lengths using cached values. | 
| - // | 
| - // The logic in this function is duplicated from CSSPrimitiveValue::computeLengthDouble | 
| - // because MediaValues::computeLength needs nearly identical logic, but we haven't found a way to make | 
| - // CSSPrimitiveValue::computeLengthDouble more generic (to solve both cases) without hurting performance. | 
| - | 
| - // FIXME - Unite the logic here with CSSPrimitiveValue is a performant way. | 
| - int factor = 0; | 
| - switch (type) { | 
| - case CSSPrimitiveValue::CSS_EMS: | 
| - case CSSPrimitiveValue::CSS_REMS: | 
| - factor = m_data.defaultFontSize; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_PX: | 
| - factor = 1; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_EXS: | 
| - // FIXME: We have a bug right now where the zoom will be applied twice to EX units. | 
| - // FIXME: We don't seem to be able to cache fontMetrics related values. | 
| - // Trying to access them is triggering some sort of microtask. Serving the spec's default instead. | 
| - factor = m_data.defaultFontSize / 2.0; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_CHS: | 
| - // FIXME: We don't seem to be able to cache fontMetrics related values. | 
| - // Trying to access them is triggering some sort of microtask. Serving the (future) spec default instead. | 
| - factor = m_data.defaultFontSize / 2.0; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_VW: | 
| - factor = m_data.viewportWidth / 100; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_VH: | 
| - factor = m_data.viewportHeight / 100; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_VMIN: | 
| - factor = std::min(m_data.viewportWidth, m_data.viewportHeight) / 100; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_VMAX: | 
| - factor = std::max(m_data.viewportWidth, m_data.viewportHeight) / 100; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_CM: | 
| - factor = cssPixelsPerCentimeter; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_MM: | 
| - factor = cssPixelsPerMillimeter; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_IN: | 
| - factor = cssPixelsPerInch; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_PT: | 
| - factor = cssPixelsPerPoint; | 
| - break; | 
| - case CSSPrimitiveValue::CSS_PC: | 
| - factor = cssPixelsPerPica; | 
| - break; | 
| - default: | 
| - return false; | 
| - } | 
| - | 
| - ASSERT(factor > 0); | 
| - result = roundForImpreciseConversion<int>(value*factor); | 
| - return true; | 
| + return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_data.viewportWidth, m_data.viewportHeight, result); | 
| } | 
| bool MediaValuesCached::isSafeToSendToAnotherThread() const |