| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "core/paint/RarePaintData.h" | 5 #include "core/paint/RarePaintData.h" |
| 6 | 6 |
| 7 #include "core/paint/ObjectPaintProperties.h" | 7 #include "core/paint/ObjectPaintProperties.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 RarePaintData::RarePaintData() {} | 11 RarePaintData::RarePaintData() {} |
| 12 | 12 |
| 13 RarePaintData::~RarePaintData() {} | 13 RarePaintData::~RarePaintData() {} |
| 14 | 14 |
| 15 ObjectPaintProperties& RarePaintData::EnsurePaintProperties() { | 15 ObjectPaintProperties& RarePaintData::EnsurePaintProperties() { |
| 16 if (!paint_properties_) | 16 if (!paint_properties_) |
| 17 paint_properties_ = ObjectPaintProperties::Create(); | 17 paint_properties_ = ObjectPaintProperties::Create(); |
| 18 return *paint_properties_.get(); | 18 return *paint_properties_.get(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 void RarePaintData::ClearLocalBorderBoxProperties() { | 21 void RarePaintData::ClearLocalBorderBoxProperties() { |
| 22 local_border_box_properties_ = nullptr; | 22 local_border_box_properties_ = nullptr; |
| 23 | |
| 24 // The contents properties are based on the border box so we need to clear | |
| 25 // the cached value. | |
| 26 contents_properties_ = nullptr; | |
| 27 } | 23 } |
| 28 | 24 |
| 29 void RarePaintData::SetLocalBorderBoxProperties(PropertyTreeState& state) { | 25 void RarePaintData::SetLocalBorderBoxProperties(PropertyTreeState& state) { |
| 30 if (!local_border_box_properties_) | 26 if (!local_border_box_properties_) |
| 31 local_border_box_properties_ = WTF::MakeUnique<PropertyTreeState>(state); | 27 local_border_box_properties_ = WTF::MakeUnique<PropertyTreeState>(state); |
| 32 else | 28 else |
| 33 *local_border_box_properties_ = state; | 29 *local_border_box_properties_ = state; |
| 34 | |
| 35 // The contents properties are based on the border box so we need to clear | |
| 36 // the cached value. | |
| 37 contents_properties_ = nullptr; | |
| 38 } | 30 } |
| 39 | 31 |
| 40 static std::unique_ptr<PropertyTreeState> ComputeContentsProperties( | 32 PropertyTreeState RarePaintData::ContentsProperties() const { |
| 41 PropertyTreeState* local_border_box_properties, | 33 DCHECK(local_border_box_properties_); |
| 42 ObjectPaintProperties* paint_properties) { | 34 PropertyTreeState contents(*local_border_box_properties_); |
| 43 if (!local_border_box_properties) | 35 if (paint_properties_) { |
| 44 return nullptr; | 36 if (paint_properties_->ScrollTranslation()) |
| 45 | 37 contents.SetTransform(paint_properties_->ScrollTranslation()); |
| 46 std::unique_ptr<PropertyTreeState> contents = | 38 if (paint_properties_->OverflowClip()) |
| 47 WTF::MakeUnique<PropertyTreeState>(*local_border_box_properties); | 39 contents.SetClip(paint_properties_->OverflowClip()); |
| 48 | 40 else if (paint_properties_->CssClip()) |
| 49 if (paint_properties) { | 41 contents.SetClip(paint_properties_->CssClip()); |
| 50 if (paint_properties->ScrollTranslation()) | |
| 51 contents->SetTransform(paint_properties->ScrollTranslation()); | |
| 52 if (paint_properties->OverflowClip()) | |
| 53 contents->SetClip(paint_properties->OverflowClip()); | |
| 54 else if (paint_properties->CssClip()) | |
| 55 contents->SetClip(paint_properties->CssClip()); | |
| 56 } | 42 } |
| 57 | 43 |
| 58 // TODO(chrishtr): cssClipFixedPosition needs to be handled somehow. | 44 // TODO(chrishtr): cssClipFixedPosition needs to be handled somehow. |
| 59 | 45 |
| 60 return contents; | 46 return contents; |
| 61 } | 47 } |
| 62 | 48 |
| 63 const PropertyTreeState* RarePaintData::ContentsProperties() const { | |
| 64 if (!contents_properties_) { | |
| 65 if (local_border_box_properties_) { | |
| 66 contents_properties_ = ComputeContentsProperties( | |
| 67 local_border_box_properties_.get(), paint_properties_.get()); | |
| 68 } | |
| 69 } else { | |
| 70 #if DCHECK_IS_ON() | |
| 71 // Check that the cached contents properties are valid by checking that they | |
| 72 // do not change if recalculated. | |
| 73 DCHECK(local_border_box_properties_); | |
| 74 std::unique_ptr<PropertyTreeState> old_properties = | |
| 75 std::move(contents_properties_); | |
| 76 contents_properties_ = ComputeContentsProperties( | |
| 77 local_border_box_properties_.get(), paint_properties_.get()); | |
| 78 DCHECK(*contents_properties_ == *old_properties); | |
| 79 #endif | |
| 80 } | |
| 81 return contents_properties_.get(); | |
| 82 } | |
| 83 | |
| 84 } // namespace blink | 49 } // namespace blink |
| OLD | NEW |