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

Side by Side Diff: third_party/WebKit/Source/core/css/MediaValues.cpp

Issue 1904523002: Fix double comparisons for Media Queries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unreachable build error Created 4 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 "core/css/MediaValues.h" 5 #include "core/css/MediaValues.h"
6 6
7 #include "core/css/CSSHelper.h" 7 #include "core/css/CSSHelper.h"
8 #include "core/css/MediaValuesCached.h" 8 #include "core/css/MediaValuesCached.h"
9 #include "core/css/MediaValuesDynamic.h" 9 #include "core/css/MediaValuesDynamic.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return frame->settings()->availableHoverTypes(); 152 return frame->settings()->availableHoverTypes();
153 } 153 }
154 154
155 bool MediaValues::computeLengthImpl(double value, CSSPrimitiveValue::UnitType ty pe, unsigned defaultFontSize, double viewportWidth, double viewportHeight, doubl e& result) 155 bool MediaValues::computeLengthImpl(double value, CSSPrimitiveValue::UnitType ty pe, unsigned defaultFontSize, double viewportWidth, double viewportHeight, doubl e& result)
156 { 156 {
157 // The logic in this function is duplicated from CSSToLengthConversionData:: zoomedComputedPixels() 157 // The logic in this function is duplicated from CSSToLengthConversionData:: zoomedComputedPixels()
158 // because MediaValues::computeLength() needs nearly identical logic, but we haven't found a way to make 158 // because MediaValues::computeLength() needs nearly identical logic, but we haven't found a way to make
159 // CSSToLengthConversionData::zoomedComputedPixels() more generic (to solve both cases) without hurting performance. 159 // CSSToLengthConversionData::zoomedComputedPixels() more generic (to solve both cases) without hurting performance.
160 160
161 // FIXME - Unite the logic here with CSSToLengthConversionData in a performa nt way. 161 // FIXME - Unite the logic here with CSSToLengthConversionData in a performa nt way.
162 double factor = 0;
163 switch (type) { 162 switch (type) {
164 case CSSPrimitiveValue::UnitType::Ems: 163 case CSSPrimitiveValue::UnitType::Ems:
165 case CSSPrimitiveValue::UnitType::Rems: 164 case CSSPrimitiveValue::UnitType::Rems:
166 factor = defaultFontSize; 165 result = value * defaultFontSize;
167 break; 166 return true;
168 case CSSPrimitiveValue::UnitType::Pixels: 167 case CSSPrimitiveValue::UnitType::Pixels:
169 case CSSPrimitiveValue::UnitType::UserUnits: 168 case CSSPrimitiveValue::UnitType::UserUnits:
170 factor = 1; 169 result = value;
171 break; 170 return true;
172 case CSSPrimitiveValue::UnitType::Exs: 171 case CSSPrimitiveValue::UnitType::Exs:
173 // FIXME: We have a bug right now where the zoom will be applied twice t o EX units. 172 // FIXME: We have a bug right now where the zoom will be applied twice t o EX units.
173 case CSSPrimitiveValue::UnitType::Chs:
174 // FIXME: We don't seem to be able to cache fontMetrics related values. 174 // FIXME: We don't seem to be able to cache fontMetrics related values.
175 // Trying to access them is triggering some sort of microtask. Serving t he spec's default instead. 175 // Trying to access them is triggering some sort of microtask. Serving t he spec's default instead.
176 factor = defaultFontSize / 2.0; 176 result = (value * defaultFontSize) / 2.0;
177 break; 177 return true;
178 case CSSPrimitiveValue::UnitType::Chs:
179 // FIXME: We don't seem to be able to cache fontMetrics related values.
180 // Trying to access them is triggering some sort of microtask. Serving t he (future) spec default instead.
181 factor = defaultFontSize / 2.0;
182 break;
183 case CSSPrimitiveValue::UnitType::ViewportWidth: 178 case CSSPrimitiveValue::UnitType::ViewportWidth:
184 factor = viewportWidth / 100.0; 179 result = (value * viewportWidth) / 100.0;
185 break; 180 return true;
186 case CSSPrimitiveValue::UnitType::ViewportHeight: 181 case CSSPrimitiveValue::UnitType::ViewportHeight:
187 factor = viewportHeight / 100.0; 182 result = (value * viewportHeight) / 100.0;
188 break; 183 return true;
189 case CSSPrimitiveValue::UnitType::ViewportMin: 184 case CSSPrimitiveValue::UnitType::ViewportMin:
190 factor = std::min(viewportWidth, viewportHeight) / 100.0; 185 result = (value * std::min(viewportWidth, viewportHeight)) / 100.0;
191 break; 186 return true;
192 case CSSPrimitiveValue::UnitType::ViewportMax: 187 case CSSPrimitiveValue::UnitType::ViewportMax:
193 factor = std::max(viewportWidth, viewportHeight) / 100.0; 188 result = (value * std::max(viewportWidth, viewportHeight)) / 100.0;
194 break; 189 return true;
195 case CSSPrimitiveValue::UnitType::Centimeters: 190 case CSSPrimitiveValue::UnitType::Centimeters:
196 factor = cssPixelsPerCentimeter; 191 result = value * cssPixelsPerCentimeter;
197 break; 192 return true;
198 case CSSPrimitiveValue::UnitType::Millimeters: 193 case CSSPrimitiveValue::UnitType::Millimeters:
199 factor = cssPixelsPerMillimeter; 194 result = value * cssPixelsPerMillimeter;
200 break; 195 return true;
201 case CSSPrimitiveValue::UnitType::Inches: 196 case CSSPrimitiveValue::UnitType::Inches:
202 factor = cssPixelsPerInch; 197 result = value * cssPixelsPerInch;
203 break; 198 return true;
204 case CSSPrimitiveValue::UnitType::Points: 199 case CSSPrimitiveValue::UnitType::Points:
205 factor = cssPixelsPerPoint; 200 result = value * cssPixelsPerPoint;
206 break; 201 return true;
207 case CSSPrimitiveValue::UnitType::Picas: 202 case CSSPrimitiveValue::UnitType::Picas:
208 factor = cssPixelsPerPica; 203 result = value * cssPixelsPerPica;
209 break; 204 return true;
210 default: 205 default:
211 return false; 206 return false;
212 } 207 }
213
214 ASSERT(factor >= 0);
215 result = value * factor;
216 return true;
217 } 208 }
218 209
219 LocalFrame* MediaValues::frameFrom(Document& document) 210 LocalFrame* MediaValues::frameFrom(Document& document)
220 { 211 {
221 Document* executingDocument = document.importsController() ? document.import sController()->master() : &document; 212 Document* executingDocument = document.importsController() ? document.import sController()->master() : &document;
222 ASSERT(executingDocument); 213 ASSERT(executingDocument);
223 return executingDocument->frame(); 214 return executingDocument->frame();
224 } 215 }
225 216
226 } // namespace blink 217 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/MediaQueryEvaluatorTest.cpp ('k') | third_party/WebKit/Source/core/css/MediaValuesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698