Commit 17312c42 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Simplify LayoutSVGText structural invalidation

Currently there are three different methods - SubtreeChildWasAdded,
SubtreeChildWillBeRemoved and SubtreeTextDidChange - that are almost
identical. Most callsites call them by first getting a LayoutSVGText
from LocateLayoutSVGTextAncestor and then calling the method if an
appropriate ancestor is found.

Instead add a static LayoutSVGText::NotifySubtreeStructureChanged which
find an ancestor and calls a new merged version of the above methods,
SubtreeStructureChanged. Also fold InvalidatePositioningValues() into
the new method since it is it's only caller.

Change-Id: I797d350acf76f6a3372d0833566313d304d16fd2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087400Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#746792}
parent 52e14df8
......@@ -146,18 +146,14 @@ void LayoutSVGInline::AddChild(LayoutObject* child,
LayoutObject* before_child) {
LayoutInline::AddChild(child, before_child);
SVGResourcesCache::ClientWasAddedToTree(*child);
if (LayoutSVGText* text_layout_object =
LayoutSVGText::LocateLayoutSVGTextAncestor(this))
text_layout_object->SubtreeChildWasAdded();
LayoutSVGText::NotifySubtreeStructureChanged(
this, layout_invalidation_reason::kChildChanged);
}
void LayoutSVGInline::RemoveChild(LayoutObject* child) {
SVGResourcesCache::ClientWillBeRemovedFromTree(*child);
if (LayoutSVGText* text_layout_object =
LayoutSVGText::LocateLayoutSVGTextAncestor(this))
text_layout_object->SubtreeChildWillBeRemoved();
LayoutSVGText::NotifySubtreeStructureChanged(
this, layout_invalidation_reason::kChildChanged);
LayoutInline::RemoveChild(child);
}
......
......@@ -59,9 +59,8 @@ LayoutSVGInlineText::LayoutSVGInlineText(Node* n,
void LayoutSVGInlineText::TextDidChange() {
SetTextInternal(NormalizeWhitespace(GetText().Impl()));
LayoutText::TextDidChange();
if (LayoutSVGText* text_layout_object =
LayoutSVGText::LocateLayoutSVGTextAncestor(this))
text_layout_object->SubtreeTextDidChange();
LayoutSVGText::NotifySubtreeStructureChanged(
this, layout_invalidation_reason::kTextChanged);
}
void LayoutSVGInlineText::StyleDidChange(StyleDifference diff,
......
......@@ -111,15 +111,8 @@ static inline void CollectDescendantTextNodes(
}
}
void LayoutSVGText::InvalidatePositioningValues(
void LayoutSVGText::SubtreeStructureChanged(
LayoutInvalidationReasonForTracing reason) {
descendant_text_nodes_.clear();
SetNeedsPositioningValuesUpdate();
// TODO(fs): Restore the passing of |reason| here.
LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(*this);
}
void LayoutSVGText::SubtreeChildWasAdded() {
if (BeingDestroyed() || !EverHadLayout()) {
DCHECK(descendant_text_nodes_.IsEmpty());
return;
......@@ -128,37 +121,20 @@ void LayoutSVGText::SubtreeChildWasAdded() {
return;
// The positioning elements cache depends on the size of each text
// layoutObject in the subtree. If this changes, clear the cache. It will be
// LayoutObject in the subtree. If this changes, clear the cache. It will be
// rebuilt on the next layout.
InvalidatePositioningValues(layout_invalidation_reason::kChildChanged);
SetNeedsTextMetricsUpdate();
}
void LayoutSVGText::SubtreeChildWillBeRemoved() {
if (BeingDestroyed() || !EverHadLayout()) {
DCHECK(descendant_text_nodes_.IsEmpty());
return;
}
// The positioning elements cache depends on the size of each text
// layoutObject in the subtree. If this changes, clear the cache. It will be
// rebuilt on the next layout.
InvalidatePositioningValues(layout_invalidation_reason::kChildChanged);
descendant_text_nodes_.clear();
SetNeedsPositioningValuesUpdate();
SetNeedsTextMetricsUpdate();
// TODO(fs): Restore the passing of |reason| here.
LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(*this);
}
void LayoutSVGText::SubtreeTextDidChange() {
DCHECK(!BeingDestroyed());
if (!EverHadLayout()) {
DCHECK(descendant_text_nodes_.IsEmpty());
return;
}
// The positioning elements cache depends on the size of each text object in
// the subtree. If this changes, clear the cache and mark it for rebuilding
// in the next layout.
InvalidatePositioningValues(layout_invalidation_reason::kTextChanged);
SetNeedsTextMetricsUpdate();
void LayoutSVGText::NotifySubtreeStructureChanged(
LayoutObject* object,
LayoutInvalidationReasonForTracing reason) {
if (LayoutSVGText* layout_text = LocateLayoutSVGTextAncestor(object))
layout_text->SubtreeStructureChanged(reason);
}
static inline void UpdateFontAndMetrics(LayoutSVGText& text_root) {
......@@ -429,12 +405,12 @@ void LayoutSVGText::AddChild(LayoutObject* child, LayoutObject* before_child) {
LayoutSVGBlock::AddChild(child, before_child);
SVGResourcesCache::ClientWasAddedToTree(*child);
SubtreeChildWasAdded();
SubtreeStructureChanged(layout_invalidation_reason::kChildChanged);
}
void LayoutSVGText::RemoveChild(LayoutObject* child) {
SVGResourcesCache::ClientWillBeRemovedFromTree(*child);
SubtreeChildWillBeRemoved();
SubtreeStructureChanged(layout_invalidation_reason::kChildChanged);
LayoutSVGBlock::RemoveChild(child);
}
......
......@@ -53,15 +53,14 @@ class LayoutSVGText final : public LayoutSVGBlock {
static LayoutSVGText* LocateLayoutSVGTextAncestor(LayoutObject*);
static const LayoutSVGText* LocateLayoutSVGTextAncestor(const LayoutObject*);
static void NotifySubtreeStructureChanged(LayoutObject*,
LayoutInvalidationReasonForTracing);
bool NeedsReordering() const { return needs_reordering_; }
const Vector<LayoutSVGInlineText*>& DescendantTextNodes() const {
return descendant_text_nodes_;
}
void SubtreeChildWasAdded();
void SubtreeChildWillBeRemoved();
void SubtreeTextDidChange();
void RecalcVisualOverflow() override;
const char* GetName() const override { return "LayoutSVGText"; }
......@@ -94,7 +93,7 @@ class LayoutSVGText final : public LayoutSVGBlock {
RootInlineBox* CreateRootInlineBox() override;
void InvalidatePositioningValues(LayoutInvalidationReasonForTracing);
void SubtreeStructureChanged(LayoutInvalidationReasonForTracing);
bool needs_reordering_ : 1;
bool needs_positioning_values_update_ : 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment