| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) | 4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) |
| 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights |
| 6 * reserved. | 6 * reserved. |
| 7 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) | 7 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 namespace blink { | 31 namespace blink { |
| 32 | 32 |
| 33 class CalculationValueHandleMap { | 33 class CalculationValueHandleMap { |
| 34 USING_FAST_MALLOC(CalculationValueHandleMap); | 34 USING_FAST_MALLOC(CalculationValueHandleMap); |
| 35 WTF_MAKE_NONCOPYABLE(CalculationValueHandleMap); | 35 WTF_MAKE_NONCOPYABLE(CalculationValueHandleMap); |
| 36 | 36 |
| 37 public: | 37 public: |
| 38 CalculationValueHandleMap() : index_(1) {} | 38 CalculationValueHandleMap() : index_(1) {} |
| 39 | 39 |
| 40 int insert(PassRefPtr<CalculationValue> calc_value) { | 40 int insert(PassRefPtr<CalculationValue> calc_value) { |
| 41 ASSERT(index_); | 41 DCHECK(index_); |
| 42 // FIXME calc(): https://bugs.webkit.org/show_bug.cgi?id=80489 | 42 // FIXME calc(): https://bugs.webkit.org/show_bug.cgi?id=80489 |
| 43 // This monotonically increasing handle generation scheme is potentially | 43 // This monotonically increasing handle generation scheme is potentially |
| 44 // wasteful of the handle space. Consider reusing empty handles. | 44 // wasteful of the handle space. Consider reusing empty handles. |
| 45 while (map_.Contains(index_)) | 45 while (map_.Contains(index_)) |
| 46 index_++; | 46 index_++; |
| 47 | 47 |
| 48 map_.Set(index_, std::move(calc_value)); | 48 map_.Set(index_, std::move(calc_value)); |
| 49 | 49 |
| 50 return index_; | 50 return index_; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void Remove(int index) { | 53 void Remove(int index) { |
| 54 ASSERT(map_.Contains(index)); | 54 DCHECK(map_.Contains(index)); |
| 55 map_.erase(index); | 55 map_.erase(index); |
| 56 } | 56 } |
| 57 | 57 |
| 58 CalculationValue& Get(int index) { | 58 CalculationValue& Get(int index) { |
| 59 ASSERT(map_.Contains(index)); | 59 DCHECK(map_.Contains(index)); |
| 60 return *map_.at(index); | 60 return *map_.at(index); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void DecrementRef(int index) { | 63 void DecrementRef(int index) { |
| 64 ASSERT(map_.Contains(index)); | 64 DCHECK(map_.Contains(index)); |
| 65 CalculationValue* value = map_.at(index); | 65 CalculationValue* value = map_.at(index); |
| 66 if (value->HasOneRef()) { | 66 if (value->HasOneRef()) { |
| 67 // Force the CalculationValue destructor early to avoid a potential | 67 // Force the CalculationValue destructor early to avoid a potential |
| 68 // recursive call inside HashMap remove(). | 68 // recursive call inside HashMap remove(). |
| 69 map_.Set(index, nullptr); | 69 map_.Set(index, nullptr); |
| 70 map_.erase(index); | 70 map_.erase(index); |
| 71 } else { | 71 } else { |
| 72 value->Deref(); | 72 value->Deref(); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 int index_; | 77 int index_; |
| 78 HashMap<int, RefPtr<CalculationValue>> map_; | 78 HashMap<int, RefPtr<CalculationValue>> map_; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 static CalculationValueHandleMap& CalcHandles() { | 81 static CalculationValueHandleMap& CalcHandles() { |
| 82 DEFINE_STATIC_LOCAL(CalculationValueHandleMap, handle_map, ()); | 82 DEFINE_STATIC_LOCAL(CalculationValueHandleMap, handle_map, ()); |
| 83 return handle_map; | 83 return handle_map; |
| 84 } | 84 } |
| 85 | 85 |
| 86 Length::Length(PassRefPtr<CalculationValue> calc) | 86 Length::Length(PassRefPtr<CalculationValue> calc) |
| 87 : quirk_(false), type_(kCalculated), is_float_(false) { | 87 : quirk_(false), type_(kCalculated), is_float_(false) { |
| 88 int_value_ = CalcHandles().insert(std::move(calc)); | 88 int_value_ = CalcHandles().insert(std::move(calc)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 Length Length::BlendMixedTypes(const Length& from, | 91 Length Length::BlendMixedTypes(const Length& from, |
| 92 double progress, | 92 double progress, |
| 93 ValueRange range) const { | 93 ValueRange range) const { |
| 94 ASSERT(from.IsSpecified()); | 94 DCHECK(from.IsSpecified()); |
| 95 ASSERT(IsSpecified()); | 95 DCHECK(IsSpecified()); |
| 96 PixelsAndPercent from_pixels_and_percent = from.GetPixelsAndPercent(); | 96 PixelsAndPercent from_pixels_and_percent = from.GetPixelsAndPercent(); |
| 97 PixelsAndPercent to_pixels_and_percent = GetPixelsAndPercent(); | 97 PixelsAndPercent to_pixels_and_percent = GetPixelsAndPercent(); |
| 98 const float pixels = blink::Blend(from_pixels_and_percent.pixels, | 98 const float pixels = blink::Blend(from_pixels_and_percent.pixels, |
| 99 to_pixels_and_percent.pixels, progress); | 99 to_pixels_and_percent.pixels, progress); |
| 100 const float percent = blink::Blend(from_pixels_and_percent.percent, | 100 const float percent = blink::Blend(from_pixels_and_percent.percent, |
| 101 to_pixels_and_percent.percent, progress); | 101 to_pixels_and_percent.percent, progress); |
| 102 return Length( | 102 return Length( |
| 103 CalculationValue::Create(PixelsAndPercent(pixels, percent), range)); | 103 CalculationValue::Create(PixelsAndPercent(pixels, percent), range)); |
| 104 } | 104 } |
| 105 | 105 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 result.pixels *= factor; | 137 result.pixels *= factor; |
| 138 return Length(CalculationValue::Create( | 138 return Length(CalculationValue::Create( |
| 139 result, GetCalculationValue().GetValueRange())); | 139 result, GetCalculationValue().GetValueRange())); |
| 140 } | 140 } |
| 141 default: | 141 default: |
| 142 return *this; | 142 return *this; |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 CalculationValue& Length::GetCalculationValue() const { | 146 CalculationValue& Length::GetCalculationValue() const { |
| 147 ASSERT(IsCalculated()); | 147 DCHECK(IsCalculated()); |
| 148 return CalcHandles().Get(CalculationHandle()); | 148 return CalcHandles().Get(CalculationHandle()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void Length::IncrementCalculatedRef() const { | 151 void Length::IncrementCalculatedRef() const { |
| 152 ASSERT(IsCalculated()); | 152 DCHECK(IsCalculated()); |
| 153 GetCalculationValue().Ref(); | 153 GetCalculationValue().Ref(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void Length::DecrementCalculatedRef() const { | 156 void Length::DecrementCalculatedRef() const { |
| 157 ASSERT(IsCalculated()); | 157 DCHECK(IsCalculated()); |
| 158 CalcHandles().DecrementRef(CalculationHandle()); | 158 CalcHandles().DecrementRef(CalculationHandle()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 float Length::NonNanCalculatedValue(LayoutUnit max_value) const { | 161 float Length::NonNanCalculatedValue(LayoutUnit max_value) const { |
| 162 ASSERT(IsCalculated()); | 162 DCHECK(IsCalculated()); |
| 163 float result = GetCalculationValue().Evaluate(max_value.ToFloat()); | 163 float result = GetCalculationValue().Evaluate(max_value.ToFloat()); |
| 164 if (std::isnan(result)) | 164 if (std::isnan(result)) |
| 165 return 0; | 165 return 0; |
| 166 return result; | 166 return result; |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool Length::IsCalculatedEqual(const Length& o) const { | 169 bool Length::IsCalculatedEqual(const Length& o) const { |
| 170 return IsCalculated() && | 170 return IsCalculated() && |
| 171 (&GetCalculationValue() == &o.GetCalculationValue() || | 171 (&GetCalculationValue() == &o.GetCalculationValue() || |
| 172 GetCalculationValue() == o.GetCalculationValue()); | 172 GetCalculationValue() == o.GetCalculationValue()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 struct SameSizeAsLength { | 175 struct SameSizeAsLength { |
| 176 int32_t value; | 176 int32_t value; |
| 177 int32_t meta_data; | 177 int32_t meta_data; |
| 178 }; | 178 }; |
| 179 static_assert(sizeof(Length) == sizeof(SameSizeAsLength), | 179 static_assert(sizeof(Length) == sizeof(SameSizeAsLength), |
| 180 "length should stay small"); | 180 "length should stay small"); |
| 181 | 181 |
| 182 } // namespace blink | 182 } // namespace blink |
| OLD | NEW |