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

Side by Side Diff: Source/core/css/MediaValuesCached.cpp

Issue 240063003: Revert "A sizes attribute parser" (https://codereview.chromium.org/224733011) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/css/MediaValuesCached.h ('k') | Source/core/css/MediaValuesDynamic.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "core/dom/Document.h"
11 #include "core/rendering/RenderObject.h"
12
13 namespace WebCore {
14
15 PassRefPtr<MediaValues> MediaValuesCached::create(MediaValuesCachedData& data)
16 {
17 return adoptRef(new MediaValuesCached(data));
18 }
19
20 PassRefPtr<MediaValues> MediaValuesCached::create(Document& document)
21 {
22 Document* executingDocument = getExecutingDocument(document);
23 return MediaValuesCached::create(executingDocument->frame(), executingDocume nt->renderer()->style());
24 }
25
26 PassRefPtr<MediaValues> MediaValuesCached::create(LocalFrame* frame, RenderStyle * style)
27 {
28 return adoptRef(new MediaValuesCached(frame, style));
29 }
30
31 MediaValuesCached::MediaValuesCached(LocalFrame* frame, RenderStyle* style)
32 {
33 ASSERT(frame && style);
34 m_data.viewportWidth = calculateViewportWidth(frame, style);
35 m_data.viewportHeight = calculateViewportHeight(frame, style);
36 m_data.deviceWidth = calculateDeviceWidth(frame);
37 m_data.deviceHeight = calculateDeviceHeight(frame);
38 m_data.devicePixelRatio = calculateDevicePixelRatio(frame);
39 m_data.colorBitsPerComponent = calculateColorBitsPerComponent(frame);
40 m_data.monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(fram e);
41 m_data.pointer = calculateLeastCapablePrimaryPointerDeviceType(frame);
42 m_data.defaultFontSize = calculateDefaultFontSize(style);
43 m_data.computedFontSize = calculateComputedFontSize(style);
44 m_data.hasXHeight = calculateHasXHeight(style);
45 m_data.xHeight = calculateXHeight(style);
46 m_data.zeroWidth = calculateZeroWidth(style);
47 m_data.threeDEnabled = calculateThreeDEnabled(frame);
48 m_data.scanMediaType = calculateScanMediaType(frame);
49 m_data.screenMediaType = calculateScreenMediaType(frame);
50 m_data.printMediaType = calculatePrintMediaType(frame);
51 m_data.strictMode = calculateStrictMode(frame);
52 }
53
54 MediaValuesCached::MediaValuesCached(const MediaValuesCachedData& data)
55 : m_data(data)
56 {
57 }
58
59 PassRefPtr<MediaValues> MediaValuesCached::copy() const
60 {
61 return adoptRef(new MediaValuesCached(m_data));
62 }
63
64 bool MediaValuesCached::computeLength(double value, unsigned short type, int& re sult) const
65 {
66 // We're running in a background thread, so RenderStyle is not available.
67 // Nevertheless, we can evaluate lengths using cached values.
68 //
69 // The logic in this function is duplicated from CSSPrimitiveValue::computeL engthDouble
70 // because MediaValues::computeLength needs nearly identical logic, but we h aven't found a way to make
71 // CSSPrimitiveValue::computeLengthDouble more generic (to solve both cases) without hurting performance.
72
73 // FIXME - Unite the logic here with CSSPrimitiveValue is a performant way.
74 int factor = 0;
75 switch (type) {
76 case CSSPrimitiveValue::CSS_EMS:
77 case CSSPrimitiveValue::CSS_REMS:
78 factor = m_data.defaultFontSize;
79 break;
80 case CSSPrimitiveValue::CSS_PX:
81 factor = 1;
82 break;
83 case CSSPrimitiveValue::CSS_EXS:
84 // FIXME: We have a bug right now where the zoom will be applied twice t o EX units.
85 // We really need to compute EX using fontMetrics for the original speci fiedSize and not use
86 // our actual constructed rendering font.
87 if (m_data.hasXHeight)
88 factor = m_data.xHeight;
89 else
90 factor = m_data.defaultFontSize / 2.0;
91 break;
92 case CSSPrimitiveValue::CSS_CHS:
93 factor = m_data.zeroWidth;
94 break;
95 case CSSPrimitiveValue::CSS_VW:
96 factor = m_data.viewportWidth / 100;
97 break;
98 case CSSPrimitiveValue::CSS_VH:
99 factor = m_data.viewportHeight / 100;
100 break;
101 case CSSPrimitiveValue::CSS_VMIN:
102 factor = std::min(m_data.viewportWidth, m_data.viewportHeight) / 100;
103 break;
104 case CSSPrimitiveValue::CSS_VMAX:
105 factor = std::max(m_data.viewportWidth, m_data.viewportHeight) / 100;
106 break;
107 case CSSPrimitiveValue::CSS_CM:
108 factor = cssPixelsPerCentimeter;
109 break;
110 case CSSPrimitiveValue::CSS_MM:
111 factor = cssPixelsPerMillimeter;
112 break;
113 case CSSPrimitiveValue::CSS_IN:
114 factor = cssPixelsPerInch;
115 break;
116 case CSSPrimitiveValue::CSS_PT:
117 factor = cssPixelsPerPoint;
118 break;
119 case CSSPrimitiveValue::CSS_PC:
120 factor = cssPixelsPerPica;
121 break;
122 default:
123 return false;
124 }
125
126 ASSERT(factor > 0);
127 result = roundForImpreciseConversion<int>(value*factor);
128 return true;
129 }
130
131 bool MediaValuesCached::isSafeToSendToAnotherThread() const
132 {
133 return hasOneRef();
134 }
135
136 int MediaValuesCached::viewportWidth() const
137 {
138 return m_data.viewportWidth;
139 }
140
141 int MediaValuesCached::viewportHeight() const
142 {
143 return m_data.viewportHeight;
144 }
145
146 int MediaValuesCached::deviceWidth() const
147 {
148 return m_data.deviceWidth;
149 }
150
151 int MediaValuesCached::deviceHeight() const
152 {
153 return m_data.deviceHeight;
154 }
155
156 float MediaValuesCached::devicePixelRatio() const
157 {
158 return m_data.devicePixelRatio;
159 }
160
161 int MediaValuesCached::colorBitsPerComponent() const
162 {
163 return m_data.colorBitsPerComponent;
164 }
165
166 int MediaValuesCached::monochromeBitsPerComponent() const
167 {
168 return m_data.monochromeBitsPerComponent;
169 }
170
171 MediaValues::PointerDeviceType MediaValuesCached::pointer() const
172 {
173 return m_data.pointer;
174 }
175
176 bool MediaValuesCached::threeDEnabled() const
177 {
178 return m_data.threeDEnabled;
179 }
180
181 bool MediaValuesCached::scanMediaType() const
182 {
183 return m_data.scanMediaType;
184 }
185
186 bool MediaValuesCached::screenMediaType() const
187 {
188 return m_data.screenMediaType;
189 }
190
191 bool MediaValuesCached::printMediaType() const
192 {
193 return m_data.printMediaType;
194 }
195
196 bool MediaValuesCached::strictMode() const
197 {
198 return m_data.strictMode;
199 }
200
201 Document* MediaValuesCached::document() const
202 {
203 return 0;
204 }
205
206 bool MediaValuesCached::hasValues() const
207 {
208 return true;
209 }
210
211 } // namespace
OLDNEW
« no previous file with comments | « Source/core/css/MediaValuesCached.h ('k') | Source/core/css/MediaValuesDynamic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698