1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/paint/fragment_data.h"
#include "base/debug/dump_without_crashing.h"
#include "third_party/blink/renderer/core/page/scrolling/sticky_position_scrolling_constraints.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/platform/graphics/paint/geometry_mapper.h"
namespace blink {
// These are defined here because of PaintLayer dependency.
FragmentData::RareData::RareData() = default;
FragmentData::RareData::~RareData() = default;
void FragmentData::RareData::EnsureId() {
if (!unique_id) {
unique_id = NewUniqueObjectId();
}
}
void FragmentData::RareData::SetLayer(PaintLayer* new_layer) {
if (layer && layer != new_layer) {
layer->Destroy();
sticky_constraints = nullptr;
}
layer = new_layer;
}
void FragmentData::RareData::Trace(Visitor* visitor) const {
visitor->Trace(layer);
visitor->Trace(sticky_constraints);
visitor->Trace(additional_fragments);
visitor->Trace(paint_properties);
visitor->Trace(local_border_box_properties);
}
FragmentData::RareData& FragmentData::EnsureRareData() {
if (!rare_data_)
rare_data_ = MakeGarbageCollected<RareData>();
return *rare_data_;
}
void FragmentData::SetLayer(PaintLayer* layer) {
AssertIsFirst();
if (rare_data_ || layer)
EnsureRareData().SetLayer(layer);
}
const TransformPaintPropertyNodeOrAlias& FragmentData::PreTransform() const {
if (const auto* properties = PaintProperties()) {
for (const TransformPaintPropertyNode* transform :
properties->AllCSSTransformPropertiesOutsideToInside()) {
if (transform) {
DCHECK(transform->Parent());
return *transform->Parent();
}
}
}
return LocalBorderBoxProperties().Transform();
}
const TransformPaintPropertyNodeOrAlias& FragmentData::ContentsTransform()
const {
if (const auto* properties = PaintProperties()) {
if (properties->TransformIsolationNode())
return *properties->TransformIsolationNode();
if (properties->ScrollTranslation())
return *properties->ScrollTranslation();
if (properties->ReplacedContentTransform())
return *properties->ReplacedContentTransform();
if (properties->Perspective())
return *properties->Perspective();
}
return LocalBorderBoxProperties().Transform();
}
const ClipPaintPropertyNodeOrAlias& FragmentData::PreClip() const {
if (const auto* properties = PaintProperties()) {
if (const auto* clip = properties->ClipPathClip()) {
DCHECK(clip->Parent());
return *clip->Parent();
}
if (const auto* mask_clip = properties->MaskClip()) {
DCHECK(mask_clip->Parent());
return *mask_clip->Parent();
}
if (const auto* css_clip = properties->CssClip()) {
DCHECK(css_clip->Parent());
return *css_clip->Parent();
}
if (const auto* clip = properties->PixelMovingFilterClipExpander()) {
DCHECK(clip->Parent());
return *clip->Parent();
}
}
return LocalBorderBoxProperties().Clip();
}
const ClipPaintPropertyNodeOrAlias& FragmentData::ContentsClip() const {
if (const auto* properties = PaintProperties()) {
if (properties->ClipIsolationNode())
return *properties->ClipIsolationNode();
if (properties->OverflowClip())
return *properties->OverflowClip();
if (properties->InnerBorderRadiusClip())
return *properties->InnerBorderRadiusClip();
}
return LocalBorderBoxProperties().Clip();
}
const EffectPaintPropertyNodeOrAlias& FragmentData::PreEffect() const {
if (const auto* properties = PaintProperties()) {
if (const auto* effect = properties->Effect()) {
DCHECK(effect->Parent());
return *effect->Parent();
}
if (const auto* filter = properties->Filter()) {
DCHECK(filter->Parent());
return *filter->Parent();
}
}
return LocalBorderBoxProperties().Effect();
}
const EffectPaintPropertyNodeOrAlias& FragmentData::ContentsEffect() const {
if (const auto* properties = PaintProperties()) {
if (properties->EffectIsolationNode())
return *properties->EffectIsolationNode();
}
return LocalBorderBoxProperties().Effect();
}
PropertyTreeStateOrAlias FragmentData::LocalBorderBoxPropertiesFallback()
const {
// TODO(crbug.com/40218657): This should never be reached, but does in
// practice and we haven't been able to find all of the cases where it
// happens yet. crbug.com/40152845 is an example case. crbug.com/396612314
// is an example of fixed cases.
#if DCHECK_IS_ON()
// Crash on DCHECK build.
NOTREACHED();
#else
// Otherwise, dump stack without crashing, and fallback to root. This may
// cause unexpected situation in later stages, which are probably also worked
// around. We can remove this function and all later workarounds if this no
// longer happens.
base::debug::DumpWithoutCrashing();
return PropertyTreeStateOrAlias::Root();
#endif
}
FragmentData& FragmentDataList::AppendNewFragment() {
AssertIsFirst();
FragmentData* new_fragment = MakeGarbageCollected<FragmentData>();
EnsureRareData().additional_fragments.push_back(new_fragment);
return *new_fragment;
}
void FragmentDataList::Shrink(wtf_size_t new_size) {
CHECK_GE(new_size, 1u);
CHECK_LE(new_size, size());
if (rare_data_) {
rare_data_->additional_fragments.resize(new_size - 1);
}
}
FragmentData& FragmentDataList::back() {
AssertIsFirst();
if (rare_data_ && !rare_data_->additional_fragments.empty()) {
return *rare_data_->additional_fragments.back();
}
return *this;
}
const FragmentData& FragmentDataList::back() const {
return const_cast<FragmentDataList*>(this)->back();
}
FragmentData& FragmentDataList::at(wtf_size_t idx) {
AssertIsFirst();
if (idx == 0) {
return *this;
}
CHECK(rare_data_);
return *rare_data_->additional_fragments.at(idx - 1);
}
const FragmentData& FragmentDataList::at(wtf_size_t idx) const {
return const_cast<FragmentDataList*>(this)->at(idx);
}
wtf_size_t FragmentDataList::size() const {
return rare_data_ ? rare_data_->additional_fragments.size() + 1 : 1;
}
} // namespace blink
|