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

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

Issue 82083002: Move viewport unit resolution to style recalc time (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: fix compile on mac Created 7 years 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 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 case CSS_S: 133 case CSS_S:
134 return CSSPrimitiveValue::UTime; 134 return CSSPrimitiveValue::UTime;
135 case CSS_DEG: 135 case CSS_DEG:
136 case CSS_RAD: 136 case CSS_RAD:
137 case CSS_GRAD: 137 case CSS_GRAD:
138 case CSS_TURN: 138 case CSS_TURN:
139 return CSSPrimitiveValue::UAngle; 139 return CSSPrimitiveValue::UAngle;
140 case CSS_HZ: 140 case CSS_HZ:
141 case CSS_KHZ: 141 case CSS_KHZ:
142 return CSSPrimitiveValue::UFrequency; 142 return CSSPrimitiveValue::UFrequency;
143 case CSS_VW:
144 case CSS_VH:
145 case CSS_VMIN:
146 case CSS_VMAX:
147 return CSSPrimitiveValue::UViewportPercentageLength;
148 case CSS_DPPX: 143 case CSS_DPPX:
149 case CSS_DPI: 144 case CSS_DPI:
150 case CSS_DPCM: 145 case CSS_DPCM:
151 return CSSPrimitiveValue::UResolution; 146 return CSSPrimitiveValue::UResolution;
152 default: 147 default:
153 return CSSPrimitiveValue::UOther; 148 return CSSPrimitiveValue::UOther;
154 } 149 }
155 } 150 }
156 151
157 bool CSSPrimitiveValue::colorIsDerivedFromElement() const 152 bool CSSPrimitiveValue::colorIsDerivedFromElement() const
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 switch (length.type()) { 274 switch (length.type()) {
280 case Auto: 275 case Auto:
281 case Intrinsic: 276 case Intrinsic:
282 case MinIntrinsic: 277 case MinIntrinsic:
283 case MinContent: 278 case MinContent:
284 case MaxContent: 279 case MaxContent:
285 case FillAvailable: 280 case FillAvailable:
286 case FitContent: 281 case FitContent:
287 case ExtendToZoom: 282 case ExtendToZoom:
288 case Percent: 283 case Percent:
289 case ViewportPercentageWidth:
290 case ViewportPercentageHeight:
291 case ViewportPercentageMin:
292 case ViewportPercentageMax:
293 init(length); 284 init(length);
294 return; 285 return;
295 case Fixed: 286 case Fixed:
296 m_primitiveUnitType = CSS_PX; 287 m_primitiveUnitType = CSS_PX;
297 m_value.num = length.value() / zoom; 288 m_value.num = length.value() / zoom;
298 return; 289 return;
299 case Calculated: 290 case Calculated:
300 init(CSSCalcValue::create(length.calculationValue(), zoom)); 291 init(CSSCalcValue::create(length.calculationValue(), zoom));
301 return; 292 return;
293 case DeviceWidth:
294 case DeviceHeight:
302 case Undefined: 295 case Undefined:
303 ASSERT_NOT_REACHED(); 296 ASSERT_NOT_REACHED();
304 break; 297 break;
305 } 298 }
306 } 299 }
307 300
308 void CSSPrimitiveValue::init(const Length& length) 301 void CSSPrimitiveValue::init(const Length& length)
309 { 302 {
310 switch (length.type()) { 303 switch (length.type()) {
311 case Auto: 304 case Auto:
(...skipping 30 matching lines...) Expand all
342 break; 335 break;
343 case ExtendToZoom: 336 case ExtendToZoom:
344 m_primitiveUnitType = CSS_VALUE_ID; 337 m_primitiveUnitType = CSS_VALUE_ID;
345 m_value.valueID = CSSValueInternalExtendToZoom; 338 m_value.valueID = CSSValueInternalExtendToZoom;
346 break; 339 break;
347 case Percent: 340 case Percent:
348 m_primitiveUnitType = CSS_PERCENTAGE; 341 m_primitiveUnitType = CSS_PERCENTAGE;
349 ASSERT(std::isfinite(length.percent())); 342 ASSERT(std::isfinite(length.percent()));
350 m_value.num = length.percent(); 343 m_value.num = length.percent();
351 break; 344 break;
352 case ViewportPercentageWidth: 345 case DeviceWidth:
353 m_primitiveUnitType = CSS_VW; 346 case DeviceHeight:
354 m_value.num = length.viewportPercentageLength();
355 break;
356 case ViewportPercentageHeight:
357 m_primitiveUnitType = CSS_VH;
358 m_value.num = length.viewportPercentageLength();
359 break;
360 case ViewportPercentageMin:
361 m_primitiveUnitType = CSS_VMIN;
362 m_value.num = length.viewportPercentageLength();
363 break;
364 case ViewportPercentageMax:
365 m_primitiveUnitType = CSS_VMAX;
366 m_value.num = length.viewportPercentageLength();
367 break;
368 case Calculated: 347 case Calculated:
369 case Undefined: 348 case Undefined:
370 ASSERT_NOT_REACHED(); 349 ASSERT_NOT_REACHED();
371 break; 350 break;
372 } 351 }
373 } 352 }
374 353
375 void CSSPrimitiveValue::init(PassRefPtr<Counter> c) 354 void CSSPrimitiveValue::init(PassRefPtr<Counter> c)
376 { 355 {
377 m_primitiveUnitType = CSS_COUNTER; 356 m_primitiveUnitType = CSS_COUNTER;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 break; 572 break;
594 case CSS_IN: 573 case CSS_IN:
595 factor = cssPixelsPerInch; 574 factor = cssPixelsPerInch;
596 break; 575 break;
597 case CSS_PT: 576 case CSS_PT:
598 factor = cssPixelsPerPoint; 577 factor = cssPixelsPerPoint;
599 break; 578 break;
600 case CSS_PC: 579 case CSS_PC:
601 factor = cssPixelsPerPica; 580 factor = cssPixelsPerPica;
602 break; 581 break;
582 case CSS_VW:
583 factor = conversionData.viewportWidthPercent();
584 break;
585 case CSS_VH:
586 factor = conversionData.viewportHeightPercent();
587 break;
588 case CSS_VMIN:
589 factor = conversionData.viewportMinPercent();
590 break;
591 case CSS_VMAX:
592 factor = conversionData.viewportMaxPercent();
593 break;
603 case CSS_CALC_PERCENTAGE_WITH_LENGTH: 594 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
604 case CSS_CALC_PERCENTAGE_WITH_NUMBER: 595 case CSS_CALC_PERCENTAGE_WITH_NUMBER:
605 ASSERT_NOT_REACHED(); 596 ASSERT_NOT_REACHED();
606 return -1.0; 597 return -1.0;
607 default: 598 default:
608 ASSERT_NOT_REACHED(); 599 ASSERT_NOT_REACHED();
609 return -1.0; 600 return -1.0;
610 } 601 }
611 602
612 // We do not apply the zoom factor when we are computing the value of the fo nt-size property. The zooming 603 // We do not apply the zoom factor when we are computing the value of the fo nt-size property. The zooming
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 case ULength: 704 case ULength:
714 return CSS_PX; 705 return CSS_PX;
715 case UPercent: 706 case UPercent:
716 return CSS_UNKNOWN; // Cannot convert between numbers and percent. 707 return CSS_UNKNOWN; // Cannot convert between numbers and percent.
717 case UTime: 708 case UTime:
718 return CSS_MS; 709 return CSS_MS;
719 case UAngle: 710 case UAngle:
720 return CSS_DEG; 711 return CSS_DEG;
721 case UFrequency: 712 case UFrequency:
722 return CSS_HZ; 713 return CSS_HZ;
723 case UViewportPercentageLength:
724 return CSS_UNKNOWN; // Cannot convert between numbers and relative lengt hs.
725 case UResolution: 714 case UResolution:
726 return CSS_DPPX; 715 return CSS_DPPX;
727 default: 716 default:
728 return CSS_UNKNOWN; 717 return CSS_UNKNOWN;
729 } 718 }
730 } 719 }
731 720
732 bool CSSPrimitiveValue::getDoubleValueInternal(UnitTypes requestedUnitType, doub le* result) const 721 bool CSSPrimitiveValue::getDoubleValueInternal(UnitTypes requestedUnitType, doub le* result) const
733 { 722 {
734 if (!isValidCSSUnitTypeForDoubleConversion(static_cast<UnitTypes>(m_primitiv eUnitType)) || !isValidCSSUnitTypeForDoubleConversion(requestedUnitType)) 723 if (!isValidCSSUnitTypeForDoubleConversion(static_cast<UnitTypes>(m_primitiv eUnitType)) || !isValidCSSUnitTypeForDoubleConversion(requestedUnitType))
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 return shapeValue->hasVariableReference(); 1140 return shapeValue->hasVariableReference();
1152 return isVariableName(); 1141 return isVariableName();
1153 } 1142 }
1154 1143
1155 void CSSPrimitiveValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const S tyleSheetContents* styleSheet) const 1144 void CSSPrimitiveValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const S tyleSheetContents* styleSheet) const
1156 { 1145 {
1157 if (m_primitiveUnitType == CSS_URI) 1146 if (m_primitiveUnitType == CSS_URI)
1158 addSubresourceURL(urls, styleSheet->completeURL(m_value.string)); 1147 addSubresourceURL(urls, styleSheet->completeURL(m_value.string));
1159 } 1148 }
1160 1149
1161 Length CSSPrimitiveValue::viewportPercentageLength()
1162 {
1163 ASSERT(isViewportPercentageLength());
1164 Length viewportLength;
1165 switch (m_primitiveUnitType) {
1166 case CSS_VW:
1167 viewportLength = Length(getDoubleValue(), ViewportPercentageWidth);
1168 break;
1169 case CSS_VH:
1170 viewportLength = Length(getDoubleValue(), ViewportPercentageHeight);
1171 break;
1172 case CSS_VMIN:
1173 viewportLength = Length(getDoubleValue(), ViewportPercentageMin);
1174 break;
1175 case CSS_VMAX:
1176 viewportLength = Length(getDoubleValue(), ViewportPercentageMax);
1177 break;
1178 default:
1179 break;
1180 }
1181 return viewportLength;
1182 }
1183
1184 PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::cloneForCSSOM() const 1150 PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::cloneForCSSOM() const
1185 { 1151 {
1186 RefPtr<CSSPrimitiveValue> result; 1152 RefPtr<CSSPrimitiveValue> result;
1187 1153
1188 switch (m_primitiveUnitType) { 1154 switch (m_primitiveUnitType) {
1189 case CSS_STRING: 1155 case CSS_STRING:
1190 case CSS_URI: 1156 case CSS_URI:
1191 case CSS_ATTR: 1157 case CSS_ATTR:
1192 case CSS_COUNTER_NAME: 1158 case CSS_COUNTER_NAME:
1193 result = CSSPrimitiveValue::create(m_value.string, static_cast<UnitTypes >(m_primitiveUnitType)); 1159 result = CSSPrimitiveValue::create(m_value.string, static_cast<UnitTypes >(m_primitiveUnitType));
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 return m_value.parserOperator == other.m_value.parserOperator; 1297 return m_value.parserOperator == other.m_value.parserOperator;
1332 case CSS_CALC: 1298 case CSS_CALC:
1333 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc); 1299 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc);
1334 case CSS_SHAPE: 1300 case CSS_SHAPE:
1335 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot her.m_value.shape); 1301 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot her.m_value.shape);
1336 } 1302 }
1337 return false; 1303 return false;
1338 } 1304 }
1339 1305
1340 } // namespace WebCore 1306 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698