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, ...@@ -146,18 +146,14 @@ void LayoutSVGInline::AddChild(LayoutObject* child,
LayoutObject* before_child) { LayoutObject* before_child) {
LayoutInline::AddChild(child, before_child); LayoutInline::AddChild(child, before_child);
SVGResourcesCache::ClientWasAddedToTree(*child); SVGResourcesCache::ClientWasAddedToTree(*child);
LayoutSVGText::NotifySubtreeStructureChanged(
if (LayoutSVGText* text_layout_object = this, layout_invalidation_reason::kChildChanged);
LayoutSVGText::LocateLayoutSVGTextAncestor(this))
text_layout_object->SubtreeChildWasAdded();
} }
void LayoutSVGInline::RemoveChild(LayoutObject* child) { void LayoutSVGInline::RemoveChild(LayoutObject* child) {
SVGResourcesCache::ClientWillBeRemovedFromTree(*child); SVGResourcesCache::ClientWillBeRemovedFromTree(*child);
LayoutSVGText::NotifySubtreeStructureChanged(
if (LayoutSVGText* text_layout_object = this, layout_invalidation_reason::kChildChanged);
LayoutSVGText::LocateLayoutSVGTextAncestor(this))
text_layout_object->SubtreeChildWillBeRemoved();
LayoutInline::RemoveChild(child); LayoutInline::RemoveChild(child);
} }
......
...@@ -59,9 +59,8 @@ LayoutSVGInlineText::LayoutSVGInlineText(Node* n, ...@@ -59,9 +59,8 @@ LayoutSVGInlineText::LayoutSVGInlineText(Node* n,
void LayoutSVGInlineText::TextDidChange() { void LayoutSVGInlineText::TextDidChange() {
SetTextInternal(NormalizeWhitespace(GetText().Impl())); SetTextInternal(NormalizeWhitespace(GetText().Impl()));
LayoutText::TextDidChange(); LayoutText::TextDidChange();
if (LayoutSVGText* text_layout_object = LayoutSVGText::NotifySubtreeStructureChanged(
LayoutSVGText::LocateLayoutSVGTextAncestor(this)) this, layout_invalidation_reason::kTextChanged);
text_layout_object->SubtreeTextDidChange();
} }
void LayoutSVGInlineText::StyleDidChange(StyleDifference diff, void LayoutSVGInlineText::StyleDidChange(StyleDifference diff,
......
...@@ -111,15 +111,8 @@ static inline void CollectDescendantTextNodes( ...@@ -111,15 +111,8 @@ static inline void CollectDescendantTextNodes(
} }
} }
void LayoutSVGText::InvalidatePositioningValues( void LayoutSVGText::SubtreeStructureChanged(
LayoutInvalidationReasonForTracing reason) { LayoutInvalidationReasonForTracing reason) {
descendant_text_nodes_.clear();
SetNeedsPositioningValuesUpdate();
// TODO(fs): Restore the passing of |reason| here.
LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(*this);
}
void LayoutSVGText::SubtreeChildWasAdded() {
if (BeingDestroyed() || !EverHadLayout()) { if (BeingDestroyed() || !EverHadLayout()) {
DCHECK(descendant_text_nodes_.IsEmpty()); DCHECK(descendant_text_nodes_.IsEmpty());
return; return;
...@@ -128,37 +121,20 @@ void LayoutSVGText::SubtreeChildWasAdded() { ...@@ -128,37 +121,20 @@ void LayoutSVGText::SubtreeChildWasAdded() {
return; return;
// The positioning elements cache depends on the size of each text // 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. // rebuilt on the next layout.
InvalidatePositioningValues(layout_invalidation_reason::kChildChanged); descendant_text_nodes_.clear();
SetNeedsTextMetricsUpdate(); SetNeedsPositioningValuesUpdate();
}
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);
SetNeedsTextMetricsUpdate(); SetNeedsTextMetricsUpdate();
// TODO(fs): Restore the passing of |reason| here.
LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(*this);
} }
void LayoutSVGText::SubtreeTextDidChange() { void LayoutSVGText::NotifySubtreeStructureChanged(
DCHECK(!BeingDestroyed()); LayoutObject* object,
if (!EverHadLayout()) { LayoutInvalidationReasonForTracing reason) {
DCHECK(descendant_text_nodes_.IsEmpty()); if (LayoutSVGText* layout_text = LocateLayoutSVGTextAncestor(object))
return; layout_text->SubtreeStructureChanged(reason);
}
// 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();
} }
static inline void UpdateFontAndMetrics(LayoutSVGText& text_root) { static inline void UpdateFontAndMetrics(LayoutSVGText& text_root) {
...@@ -429,12 +405,12 @@ void LayoutSVGText::AddChild(LayoutObject* child, LayoutObject* before_child) { ...@@ -429,12 +405,12 @@ void LayoutSVGText::AddChild(LayoutObject* child, LayoutObject* before_child) {
LayoutSVGBlock::AddChild(child, before_child); LayoutSVGBlock::AddChild(child, before_child);
SVGResourcesCache::ClientWasAddedToTree(*child); SVGResourcesCache::ClientWasAddedToTree(*child);
SubtreeChildWasAdded(); SubtreeStructureChanged(layout_invalidation_reason::kChildChanged);
} }
void LayoutSVGText::RemoveChild(LayoutObject* child) { void LayoutSVGText::RemoveChild(LayoutObject* child) {
SVGResourcesCache::ClientWillBeRemovedFromTree(*child); SVGResourcesCache::ClientWillBeRemovedFromTree(*child);
SubtreeChildWillBeRemoved(); SubtreeStructureChanged(layout_invalidation_reason::kChildChanged);
LayoutSVGBlock::RemoveChild(child); LayoutSVGBlock::RemoveChild(child);
} }
......
...@@ -53,15 +53,14 @@ class LayoutSVGText final : public LayoutSVGBlock { ...@@ -53,15 +53,14 @@ class LayoutSVGText final : public LayoutSVGBlock {
static LayoutSVGText* LocateLayoutSVGTextAncestor(LayoutObject*); static LayoutSVGText* LocateLayoutSVGTextAncestor(LayoutObject*);
static const LayoutSVGText* LocateLayoutSVGTextAncestor(const LayoutObject*); static const LayoutSVGText* LocateLayoutSVGTextAncestor(const LayoutObject*);
static void NotifySubtreeStructureChanged(LayoutObject*,
LayoutInvalidationReasonForTracing);
bool NeedsReordering() const { return needs_reordering_; } bool NeedsReordering() const { return needs_reordering_; }
const Vector<LayoutSVGInlineText*>& DescendantTextNodes() const { const Vector<LayoutSVGInlineText*>& DescendantTextNodes() const {
return descendant_text_nodes_; return descendant_text_nodes_;
} }
void SubtreeChildWasAdded();
void SubtreeChildWillBeRemoved();
void SubtreeTextDidChange();
void RecalcVisualOverflow() override; void RecalcVisualOverflow() override;
const char* GetName() const override { return "LayoutSVGText"; } const char* GetName() const override { return "LayoutSVGText"; }
...@@ -94,7 +93,7 @@ class LayoutSVGText final : public LayoutSVGBlock { ...@@ -94,7 +93,7 @@ class LayoutSVGText final : public LayoutSVGBlock {
RootInlineBox* CreateRootInlineBox() override; RootInlineBox* CreateRootInlineBox() override;
void InvalidatePositioningValues(LayoutInvalidationReasonForTracing); void SubtreeStructureChanged(LayoutInvalidationReasonForTracing);
bool needs_reordering_ : 1; bool needs_reordering_ : 1;
bool needs_positioning_values_update_ : 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