| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/paint/RarePaintData.h" |
| 6 |
| 7 #include "core/paint/ObjectPaintProperties.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 RarePaintData::RarePaintData() {} |
| 12 |
| 13 RarePaintData::~RarePaintData() {} |
| 14 |
| 15 ObjectPaintProperties& RarePaintData::ensurePaintProperties() { |
| 16 if (!m_paintProperties) |
| 17 m_paintProperties = ObjectPaintProperties::create(); |
| 18 return *m_paintProperties.get(); |
| 19 } |
| 20 |
| 21 void RarePaintData::clearLocalBorderBoxProperties() { |
| 22 m_localBorderBoxProperties = nullptr; |
| 23 |
| 24 // The contents properties are based on the border box so we need to clear |
| 25 // the cached value. |
| 26 m_contentsProperties = nullptr; |
| 27 } |
| 28 |
| 29 void RarePaintData::setLocalBorderBoxProperties(PropertyTreeState& state) { |
| 30 if (!m_localBorderBoxProperties) |
| 31 m_localBorderBoxProperties = WTF::makeUnique<PropertyTreeState>(state); |
| 32 else |
| 33 *m_localBorderBoxProperties = state; |
| 34 |
| 35 // The contents properties are based on the border box so we need to clear |
| 36 // the cached value. |
| 37 m_contentsProperties = nullptr; |
| 38 } |
| 39 |
| 40 static std::unique_ptr<PropertyTreeState> computeContentsProperties( |
| 41 PropertyTreeState* localBorderBoxProperties, |
| 42 ObjectPaintProperties* paintProperties) { |
| 43 if (!localBorderBoxProperties) |
| 44 return nullptr; |
| 45 |
| 46 std::unique_ptr<PropertyTreeState> contents = |
| 47 WTF::makeUnique<PropertyTreeState>(*localBorderBoxProperties); |
| 48 |
| 49 if (paintProperties) { |
| 50 if (paintProperties->scrollTranslation()) |
| 51 contents->setTransform(paintProperties->scrollTranslation()); |
| 52 if (paintProperties->overflowClip()) |
| 53 contents->setClip(paintProperties->overflowClip()); |
| 54 else if (paintProperties->cssClip()) |
| 55 contents->setClip(paintProperties->cssClip()); |
| 56 } |
| 57 |
| 58 // TODO(chrishtr): cssClipFixedPosition needs to be handled somehow. |
| 59 |
| 60 return contents; |
| 61 } |
| 62 |
| 63 const PropertyTreeState* RarePaintData::contentsProperties() const { |
| 64 if (!m_contentsProperties) { |
| 65 if (m_localBorderBoxProperties) { |
| 66 m_contentsProperties = computeContentsProperties( |
| 67 m_localBorderBoxProperties.get(), m_paintProperties.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(m_localBorderBoxProperties); |
| 74 std::unique_ptr<PropertyTreeState> oldProperties = |
| 75 std::move(m_contentsProperties); |
| 76 m_contentsProperties = computeContentsProperties( |
| 77 m_localBorderBoxProperties.get(), m_paintProperties.get()); |
| 78 DCHECK(*m_contentsProperties == *oldProperties); |
| 79 #endif |
| 80 } |
| 81 return m_contentsProperties.get(); |
| 82 } |
| 83 |
| 84 } // namespace blink |
| OLD | NEW |