Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef MediaValues_h | 5 #ifndef MediaValues_h |
| 6 #define MediaValues_h | 6 #define MediaValues_h |
| 7 | 7 |
| 8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 #include "core/css/PointerProperties.h" | 9 #include "core/css/PointerProperties.h" |
| 10 #include "wtf/RefCounted.h" | 10 #include "wtf/RefCounted.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 virtual PassRefPtr<MediaValues> copy() const = 0; | 30 virtual PassRefPtr<MediaValues> copy() const = 0; |
| 31 virtual bool isSafeToSendToAnotherThread() const = 0; | 31 virtual bool isSafeToSendToAnotherThread() const = 0; |
| 32 | 32 |
| 33 static bool computeLengthImpl(double value, CSSPrimitiveValue::UnitType, uns igned defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, double& result); | 33 static bool computeLengthImpl(double value, CSSPrimitiveValue::UnitType, uns igned defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, double& result); |
| 34 template<typename T> | 34 template<typename T> |
| 35 static bool computeLength(double value, CSSPrimitiveValue::UnitType type, un signed defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, T& resu lt) | 35 static bool computeLength(double value, CSSPrimitiveValue::UnitType type, un signed defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, T& resu lt) |
| 36 { | 36 { |
| 37 double tempResult; | 37 double tempResult; |
| 38 if (!computeLengthImpl(value, type, defaultFontSize, viewportWidth, view portHeight, tempResult)) | 38 if (!computeLengthImpl(value, type, defaultFontSize, viewportWidth, view portHeight, tempResult)) |
| 39 return false; | 39 return false; |
| 40 result = roundForImpreciseConversion<T>(tempResult); | 40 |
| 41 if (tempResult > std::numeric_limits<T>::max()) | |
| 42 result = std::numeric_limits<T>::max(); | |
| 43 else if (tempResult < std::numeric_limits<T>::min()) | |
| 44 result = std::numeric_limits<T>::min(); | |
| 45 else | |
| 46 result = static_cast<T>(tempResult); | |
|
rune
2014/10/08 12:26:39
There is a clampTo templated method you could use.
| |
| 47 | |
| 41 return true; | 48 return true; |
| 42 } | 49 } |
| 43 virtual bool computeLength(double value, CSSPrimitiveValue::UnitType, int& r esult) const = 0; | 50 virtual bool computeLength(double value, CSSPrimitiveValue::UnitType, int& r esult) const = 0; |
| 44 virtual bool computeLength(double value, CSSPrimitiveValue::UnitType, double & result) const = 0; | 51 virtual bool computeLength(double value, CSSPrimitiveValue::UnitType, double & result) const = 0; |
| 45 | 52 |
| 46 virtual int viewportWidth() const = 0; | 53 virtual int viewportWidth() const = 0; |
| 47 virtual int viewportHeight() const = 0; | 54 virtual int viewportHeight() const = 0; |
| 48 virtual int deviceWidth() const = 0; | 55 virtual int deviceWidth() const = 0; |
| 49 virtual int deviceHeight() const = 0; | 56 virtual int deviceHeight() const = 0; |
| 50 virtual float devicePixelRatio() const = 0; | 57 virtual float devicePixelRatio() const = 0; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 76 int calculateAvailablePointerTypes(LocalFrame*) const; | 83 int calculateAvailablePointerTypes(LocalFrame*) const; |
| 77 HoverType calculatePrimaryHoverType(LocalFrame*) const; | 84 HoverType calculatePrimaryHoverType(LocalFrame*) const; |
| 78 int calculateAvailableHoverTypes(LocalFrame*) const; | 85 int calculateAvailableHoverTypes(LocalFrame*) const; |
| 79 static LocalFrame* frameFrom(Document&); | 86 static LocalFrame* frameFrom(Document&); |
| 80 | 87 |
| 81 }; | 88 }; |
| 82 | 89 |
| 83 } // namespace | 90 } // namespace |
| 84 | 91 |
| 85 #endif // MediaValues_h | 92 #endif // MediaValues_h |
| OLD | NEW |