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

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: 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; 162 double nominator = 0;
163 double denominator = 1;
163 switch (type) { 164 switch (type) {
164 case CSSPrimitiveValue::UnitType::Ems: 165 case CSSPrimitiveValue::UnitType::Ems:
165 case CSSPrimitiveValue::UnitType::Rems: 166 case CSSPrimitiveValue::UnitType::Rems:
166 factor = defaultFontSize; 167 nominator = defaultFontSize;
167 break; 168 break;
168 case CSSPrimitiveValue::UnitType::Pixels: 169 case CSSPrimitiveValue::UnitType::Pixels:
169 case CSSPrimitiveValue::UnitType::UserUnits: 170 case CSSPrimitiveValue::UnitType::UserUnits:
170 factor = 1; 171 nominator = 1;
rune 2016/04/20 07:04:46 Wouldn't it be simpler to just set "value" for eac
Yoav Weiss 2016/04/20 07:26:57 Yeah, changed it to suggested form
171 break; 172 break;
172 case CSSPrimitiveValue::UnitType::Exs: 173 case CSSPrimitiveValue::UnitType::Exs:
173 // FIXME: We have a bug right now where the zoom will be applied twice t o EX units. 174 // FIXME: We have a bug right now where the zoom will be applied twice t o EX units.
174 // FIXME: We don't seem to be able to cache fontMetrics related values. 175 // 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. 176 // Trying to access them is triggering some sort of microtask. Serving t he spec's default instead.
176 factor = defaultFontSize / 2.0; 177 nominator = defaultFontSize;
178 denominator = 2.0;
177 break; 179 break;
178 case CSSPrimitiveValue::UnitType::Chs: 180 case CSSPrimitiveValue::UnitType::Chs:
179 // FIXME: We don't seem to be able to cache fontMetrics related values. 181 // 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. 182 // Trying to access them is triggering some sort of microtask. Serving t he (future) spec default instead.
181 factor = defaultFontSize / 2.0; 183 nominator = defaultFontSize;
184 denominator = 2.0;
182 break; 185 break;
183 case CSSPrimitiveValue::UnitType::ViewportWidth: 186 case CSSPrimitiveValue::UnitType::ViewportWidth:
184 factor = viewportWidth / 100.0; 187 nominator = viewportWidth;
188 denominator = 100.0;
185 break; 189 break;
186 case CSSPrimitiveValue::UnitType::ViewportHeight: 190 case CSSPrimitiveValue::UnitType::ViewportHeight:
187 factor = viewportHeight / 100.0; 191 nominator = viewportHeight;
192 denominator = 100.0;
188 break; 193 break;
189 case CSSPrimitiveValue::UnitType::ViewportMin: 194 case CSSPrimitiveValue::UnitType::ViewportMin:
190 factor = std::min(viewportWidth, viewportHeight) / 100.0; 195 nominator = std::min(viewportWidth, viewportHeight);
196 denominator = 100.0;
191 break; 197 break;
192 case CSSPrimitiveValue::UnitType::ViewportMax: 198 case CSSPrimitiveValue::UnitType::ViewportMax:
193 factor = std::max(viewportWidth, viewportHeight) / 100.0; 199 nominator = std::max(viewportWidth, viewportHeight);
200 denominator = 100.0;
194 break; 201 break;
195 case CSSPrimitiveValue::UnitType::Centimeters: 202 case CSSPrimitiveValue::UnitType::Centimeters:
196 factor = cssPixelsPerCentimeter; 203 nominator = cssPixelsPerCentimeter;
197 break; 204 break;
198 case CSSPrimitiveValue::UnitType::Millimeters: 205 case CSSPrimitiveValue::UnitType::Millimeters:
199 factor = cssPixelsPerMillimeter; 206 nominator = cssPixelsPerMillimeter;
200 break; 207 break;
201 case CSSPrimitiveValue::UnitType::Inches: 208 case CSSPrimitiveValue::UnitType::Inches:
202 factor = cssPixelsPerInch; 209 nominator = cssPixelsPerInch;
203 break; 210 break;
204 case CSSPrimitiveValue::UnitType::Points: 211 case CSSPrimitiveValue::UnitType::Points:
205 factor = cssPixelsPerPoint; 212 nominator = cssPixelsPerPoint;
206 break; 213 break;
207 case CSSPrimitiveValue::UnitType::Picas: 214 case CSSPrimitiveValue::UnitType::Picas:
208 factor = cssPixelsPerPica; 215 nominator = cssPixelsPerPica;
209 break; 216 break;
210 default: 217 default:
211 return false; 218 return false;
212 } 219 }
213 220
214 ASSERT(factor >= 0); 221 ASSERT(nominator >= 0);
215 result = value * factor; 222 result = (value * nominator) / denominator;
216 return true; 223 return true;
217 } 224 }
218 225
219 LocalFrame* MediaValues::frameFrom(Document& document) 226 LocalFrame* MediaValues::frameFrom(Document& document)
220 { 227 {
221 Document* executingDocument = document.importsController() ? document.import sController()->master() : &document; 228 Document* executingDocument = document.importsController() ? document.import sController()->master() : &document;
222 ASSERT(executingDocument); 229 ASSERT(executingDocument);
223 return executingDocument->frame(); 230 return executingDocument->frame();
224 } 231 }
225 232
226 } // namespace blink 233 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698