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

Side by Side 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: Use MediaValuesCached in HTMLImageElement 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 unified diff | Download patch
OLDNEW
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"
11 #include "core/rendering/RenderObject.h" 10 #include "core/rendering/RenderObject.h"
12 11
13 namespace WebCore { 12 namespace WebCore {
14 13
15 PassRefPtr<MediaValues> MediaValuesCached::create(MediaValuesCachedData& data) 14 PassRefPtr<MediaValues> MediaValuesCached::create(MediaValuesCachedData& data)
16 { 15 {
17 return adoptRef(new MediaValuesCached(data)); 16 return adoptRef(new MediaValuesCached(data));
18 } 17 }
19 18
20 PassRefPtr<MediaValues> MediaValuesCached::create(Document& document) 19 PassRefPtr<MediaValues> MediaValuesCached::create(Document& document)
21 { 20 {
22 Document* executingDocument = getExecutingDocument(document); 21 Document* executingDocument = getExecutingDocument(document);
23 return MediaValuesCached::create(executingDocument->frame(), executingDocume nt->renderer()->style()); 22 return MediaValuesCached::create(executingDocument->frame());
24 } 23 }
25 24
26 PassRefPtr<MediaValues> MediaValuesCached::create(LocalFrame* frame, RenderStyle * style) 25 PassRefPtr<MediaValues> MediaValuesCached::create(LocalFrame* frame)
27 { 26 {
28 return adoptRef(new MediaValuesCached(frame, style)); 27 return adoptRef(new MediaValuesCached(frame));
29 } 28 }
30 29
31 MediaValuesCached::MediaValuesCached(LocalFrame* frame, RenderStyle* style) 30 MediaValuesCached::MediaValuesCached(LocalFrame* frame)
32 { 31 {
33 ASSERT(frame && style);
34 ASSERT(isMainThread()); 32 ASSERT(isMainThread());
35 m_data.viewportWidth = calculateViewportWidth(frame); 33 // In case that frame is missing (e.g. for images that their document does n ot have a frame)
36 m_data.viewportHeight = calculateViewportHeight(frame); 34 // We simply leave the MediaValues object with the default MediaValuesCached Data values.
37 m_data.deviceWidth = calculateDeviceWidth(frame); 35 if (frame) {
eseidel 2014/04/18 16:50:13 Early return instead of long indented block?
38 m_data.deviceHeight = calculateDeviceHeight(frame); 36 m_data.viewportWidth = calculateViewportWidth(frame);
eseidel 2014/04/18 16:50:13 I almost wonder if this whole construcor shouldn't
39 m_data.devicePixelRatio = calculateDevicePixelRatio(frame); 37 m_data.viewportHeight = calculateViewportHeight(frame);
40 m_data.colorBitsPerComponent = calculateColorBitsPerComponent(frame); 38 m_data.deviceWidth = calculateDeviceWidth(frame);
41 m_data.monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(fram e); 39 m_data.deviceHeight = calculateDeviceHeight(frame);
42 m_data.pointer = calculateLeastCapablePrimaryPointerDeviceType(frame); 40 m_data.devicePixelRatio = calculateDevicePixelRatio(frame);
43 m_data.defaultFontSize = calculateDefaultFontSize(style); 41 m_data.colorBitsPerComponent = calculateColorBitsPerComponent(frame);
44 m_data.computedFontSize = calculateComputedFontSize(style); 42 m_data.monochromeBitsPerComponent = calculateMonochromeBitsPerComponent( frame);
45 m_data.threeDEnabled = calculateThreeDEnabled(frame); 43 m_data.pointer = calculateLeastCapablePrimaryPointerDeviceType(frame);
46 m_data.scanMediaType = calculateScanMediaType(frame); 44 m_data.defaultFontSize = calculateDefaultFontSize(frame);
47 m_data.screenMediaType = calculateScreenMediaType(frame); 45 m_data.threeDEnabled = calculateThreeDEnabled(frame);
48 m_data.printMediaType = calculatePrintMediaType(frame); 46 m_data.scanMediaType = calculateScanMediaType(frame);
49 m_data.strictMode = calculateStrictMode(frame); 47 m_data.screenMediaType = calculateScreenMediaType(frame);
48 m_data.printMediaType = calculatePrintMediaType(frame);
49 m_data.strictMode = calculateStrictMode(frame);
50 }
50 } 51 }
51 52
52 MediaValuesCached::MediaValuesCached(const MediaValuesCachedData& data) 53 MediaValuesCached::MediaValuesCached(const MediaValuesCachedData& data)
53 : m_data(data) 54 : m_data(data)
54 { 55 {
55 } 56 }
56 57
57 PassRefPtr<MediaValues> MediaValuesCached::copy() const 58 PassRefPtr<MediaValues> MediaValuesCached::copy() const
58 { 59 {
59 return adoptRef(new MediaValuesCached(m_data)); 60 return adoptRef(new MediaValuesCached(m_data));
60 } 61 }
61 62
62 bool MediaValuesCached::computeLength(double value, unsigned short type, int& re sult) const 63 bool MediaValuesCached::computeLength(double value, unsigned short type, int& re sult) const
63 { 64 {
64 // We're running in a background thread, so RenderStyle is not available. 65 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 } 66 }
127 67
128 bool MediaValuesCached::isSafeToSendToAnotherThread() const 68 bool MediaValuesCached::isSafeToSendToAnotherThread() const
129 { 69 {
130 return hasOneRef(); 70 return hasOneRef();
131 } 71 }
132 72
133 int MediaValuesCached::viewportWidth() const 73 int MediaValuesCached::viewportWidth() const
134 { 74 {
135 return m_data.viewportWidth; 75 return m_data.viewportWidth;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 { 139 {
200 return 0; 140 return 0;
201 } 141 }
202 142
203 bool MediaValuesCached::hasValues() const 143 bool MediaValuesCached::hasValues() const
204 { 144 {
205 return true; 145 return true;
206 } 146 }
207 147
208 } // namespace 148 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698