summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/platform/Length.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/platform/Length.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/platform/Length.cpp50
1 files changed, 42 insertions, 8 deletions
diff --git a/chromium/third_party/WebKit/Source/platform/Length.cpp b/chromium/third_party/WebKit/Source/platform/Length.cpp
index c0e64b28764..4ba16e3e7ff 100644
--- a/chromium/third_party/WebKit/Source/platform/Length.cpp
+++ b/chromium/third_party/WebKit/Source/platform/Length.cpp
@@ -26,6 +26,7 @@
#include "platform/Length.h"
#include "platform/CalculationValue.h"
+#include "platform/animation/AnimationUtilities.h"
#include "wtf/ASCIICType.h"
#include "wtf/text/StringBuffer.h"
#include "wtf/text/WTFString.h"
@@ -137,10 +138,10 @@ public:
m_map.remove(index);
}
- CalculationValue* get(int index)
+ CalculationValue& get(int index)
{
ASSERT(m_map.contains(index));
- return m_map.get(index);
+ return *m_map.get(index);
}
void decrementRef(int index)
@@ -149,7 +150,7 @@ public:
CalculationValue* value = m_map.get(index);
if (value->hasOneRef()) {
// Force the CalculationValue destructor early to avoid a potential recursive call inside HashMap remove().
- m_map.set(index, 0);
+ m_map.set(index, nullptr);
m_map.remove(index);
} else {
value->deref();
@@ -177,10 +178,43 @@ Length::Length(PassRefPtr<CalculationValue> calc)
Length Length::blendMixedTypes(const Length& from, double progress, ValueRange range) const
{
- return Length(CalculationValue::create(adoptPtr(new CalcExpressionBlendLength(from, *this, progress)), range));
+ ASSERT(from.isSpecified());
+ ASSERT(isSpecified());
+ PixelsAndPercent fromPixelsAndPercent = from.pixelsAndPercent();
+ PixelsAndPercent toPixelsAndPercent = pixelsAndPercent();
+ const float pixels = WebCore::blend(fromPixelsAndPercent.pixels, toPixelsAndPercent.pixels, progress);
+ const float percent = WebCore::blend(fromPixelsAndPercent.percent, toPixelsAndPercent.percent, progress);
+ return Length(CalculationValue::create(PixelsAndPercent(pixels, percent), range));
}
-CalculationValue* Length::calculationValue() const
+PixelsAndPercent Length::pixelsAndPercent() const
+{
+ switch (type()) {
+ case Fixed:
+ return PixelsAndPercent(value(), 0);
+ case Percent:
+ return PixelsAndPercent(0, value());
+ case Calculated:
+ return calculationValue().pixelsAndPercent();
+ default:
+ ASSERT_NOT_REACHED();
+ return PixelsAndPercent(0, 0);
+ }
+}
+
+Length Length::subtractFromOneHundredPercent() const
+{
+ PixelsAndPercent result = pixelsAndPercent();
+ result.pixels = -result.pixels;
+ result.percent = 100 - result.percent;
+ if (result.pixels && result.percent)
+ return Length(CalculationValue::create(result, ValueRangeAll));
+ if (result.percent)
+ return Length(result.percent, Percent);
+ return Length(result.pixels, Fixed);
+}
+
+CalculationValue& Length::calculationValue() const
{
ASSERT(isCalculated());
return calcHandles().get(calculationHandle());
@@ -189,7 +223,7 @@ CalculationValue* Length::calculationValue() const
void Length::incrementCalculatedRef() const
{
ASSERT(isCalculated());
- calculationValue()->ref();
+ calculationValue().ref();
}
void Length::decrementCalculatedRef() const
@@ -201,7 +235,7 @@ void Length::decrementCalculatedRef() const
float Length::nonNanCalculatedValue(int maxValue) const
{
ASSERT(isCalculated());
- float result = calculationValue()->evaluate(maxValue);
+ float result = calculationValue().evaluate(maxValue);
if (std::isnan(result))
return 0;
return result;
@@ -209,7 +243,7 @@ float Length::nonNanCalculatedValue(int maxValue) const
bool Length::isCalculatedEqual(const Length& o) const
{
- return isCalculated() && (calculationValue() == o.calculationValue() || *calculationValue() == *o.calculationValue());
+ return isCalculated() && (&calculationValue() == &o.calculationValue() || calculationValue() == o.calculationValue());
}
struct SameSizeAsLength {