Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Unified Diff: Source/core/css/MediaValuesCached.cpp

Issue 242883002: Remove MediaValues' dependency on RenderStyle (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Modified minimal recalc tests to represent reduced recalc. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/css/MediaValuesCached.cpp
diff --git a/Source/core/css/MediaValuesCached.cpp b/Source/core/css/MediaValuesCached.cpp
index d83a4b919b4bb392e63f6a394e06348971fb12fa..84a759540788de184451794fe68409ea5d13af30 100644
--- a/Source/core/css/MediaValuesCached.cpp
+++ b/Source/core/css/MediaValuesCached.cpp
@@ -5,13 +5,18 @@
#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 {
+PassRefPtr<MediaValues> MediaValuesCached::create()
+{
+ return adoptRef(new MediaValuesCached());
+}
+
PassRefPtr<MediaValues> MediaValuesCached::create(MediaValuesCachedData& data)
{
return adoptRef(new MediaValuesCached(data));
@@ -19,19 +24,28 @@ 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));
+ if (!frame)
+ return adoptRef(new MediaValuesCached());
+ return adoptRef(new MediaValuesCached(frame));
}
-MediaValuesCached::MediaValuesCached(LocalFrame* frame, RenderStyle* style)
+MediaValuesCached::MediaValuesCached()
+{
+}
+
+MediaValuesCached::MediaValuesCached(LocalFrame* frame)
{
- ASSERT(frame && style);
ASSERT(isMainThread());
+ ASSERT(frame);
+ // 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.
m_data.viewportWidth = calculateViewportWidth(frame);
m_data.viewportHeight = calculateViewportHeight(frame);
m_data.deviceWidth = calculateDeviceWidth(frame);
@@ -40,8 +54,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 +74,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

Powered by Google App Engine
This is Rietveld 408576698