summaryrefslogtreecommitdiff
path: root/Source/WebCore/css/CSSPrimitiveValue.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/css/CSSPrimitiveValue.h')
-rw-r--r--Source/WebCore/css/CSSPrimitiveValue.h41
1 files changed, 27 insertions, 14 deletions
diff --git a/Source/WebCore/css/CSSPrimitiveValue.h b/Source/WebCore/css/CSSPrimitiveValue.h
index 13e576a3e..78f5cd90e 100644
--- a/Source/WebCore/css/CSSPrimitiveValue.h
+++ b/Source/WebCore/css/CSSPrimitiveValue.h
@@ -42,13 +42,24 @@ class CSSWrapShape;
struct Length;
-template<typename T, T max, T min> inline T roundForImpreciseConversion(double value)
+// Dimension calculations are imprecise, often resulting in values of e.g.
+// 44.99998. We need to go ahead and round if we're really close to the next
+// integer value.
+template<typename T> inline T roundForImpreciseConversion(double value)
{
- // Dimension calculations are imprecise, often resulting in values of e.g.
- // 44.99998. We need to go ahead and round if we're really close to the
- // next integer value.
value += (value < 0) ? -0.01 : +0.01;
- return ((value > max) || (value < min)) ? 0 : static_cast<T>(value);
+ return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_limits<T>::min())) ? 0 : static_cast<T>(value);
+}
+
+template<> inline float roundForImpreciseConversion(double value)
+{
+ double ceiledValue = ceil(value);
+ double proximityToNextInt = ceiledValue - value;
+ if (proximityToNextInt <= 0.01 && value > 0)
+ return static_cast<float>(ceiledValue);
+ if (proximityToNextInt >= 0.99 && value < 0)
+ return static_cast<float>(floor(value));
+ return static_cast<float>(value);
}
class CSSPrimitiveValue : public CSSValue {
@@ -80,6 +91,10 @@ public:
CSS_COUNTER = 23,
CSS_RECT = 24,
CSS_RGBCOLOR = 25,
+ // From CSS Values and Units. Viewport-percentage Lengths (vw/vh/vmin).
+ CSS_VW = 26,
+ CSS_VH = 27,
+ CSS_VMIN = 28,
CSS_PAIR = 100, // We envision this being exposed as a means of getting computed style values for pairs (border-spacing/radius, background-position, etc.)
CSS_DASHBOARD_REGION = 101, // FIXME: Dashboard region should not be a primitive value.
CSS_UNICODE_RANGE = 102,
@@ -118,6 +133,7 @@ public:
UAngle,
UTime,
UFrequency,
+ UViewportPercentageLength,
UOther
};
@@ -153,6 +169,7 @@ public:
bool isCalculated() const { return m_primitiveUnitType == CSS_CALC; }
bool isCalculatedPercentageWithNumber() const { return primitiveType() == CSS_CALC_PERCENTAGE_WITH_NUMBER; }
bool isCalculatedPercentageWithLength() const { return primitiveType() == CSS_CALC_PERCENTAGE_WITH_LENGTH; }
+ bool isViewportPercentageLength() const { return m_primitiveUnitType >= CSS_VW && m_primitiveUnitType <= CSS_VMIN; }
static PassRefPtr<CSSPrimitiveValue> createIdentifier(int identifier) { return adoptRef(new CSSPrimitiveValue(identifier)); }
static PassRefPtr<CSSPrimitiveValue> createColor(unsigned rgbValue) { return adoptRef(new CSSPrimitiveValue(rgbValue)); }
@@ -266,14 +283,14 @@ public:
bool isQuirkValue() { return m_isQuirkValue; }
- void addSubresourceStyleURLs(ListHashSet<KURL>&, const CSSStyleSheet*);
+ void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetInternal*);
-protected:
- CSSPrimitiveValue(ClassType, int ident);
- CSSPrimitiveValue(ClassType, const String&, UnitTypes);
+ Length viewportPercentageLength();
+
+ PassRefPtr<CSSPrimitiveValue> cloneForCSSOM() const;
+ void setCSSOMSafe() { m_isCSSOMSafe = true; }
private:
- CSSPrimitiveValue();
// FIXME: int vs. unsigned overloading is too subtle to distinguish the color and identifier cases.
CSSPrimitiveValue(int ident);
CSSPrimitiveValue(unsigned color); // RGB value
@@ -298,10 +315,6 @@ private:
static void create(unsigned); // compile-time guard
template<typename T> operator T*(); // compile-time guard
- static PassRefPtr<CSSPrimitiveValue> createUncachedIdentifier(int identifier);
- static PassRefPtr<CSSPrimitiveValue> createUncachedColor(unsigned rgbValue);
- static PassRefPtr<CSSPrimitiveValue> createUncached(double value, UnitTypes type);
-
static UnitTypes canonicalUnitTypeForCategory(UnitCategory category);
void init(PassRefPtr<Counter>);