Commit 1a75b44e authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Implement LayoutSVGInlineText::InvalidateSubtreeLayoutForFontUpdates

If the font changes we need to invalidate the text metrics so that the
text layout data is updated.

Fixed: 1133297
Change-Id: I13579257430e535e139ae57ca53990c053cf8d5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2439072Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#812590}
parent 2f1645ac
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/layout/layout_object.h" #include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/svg/svg_text_element.h"
#include "third_party/blink/renderer/core/testing/sim/sim_request.h" #include "third_party/blink/renderer/core/testing/sim/sim_request.h"
#include "third_party/blink/renderer/core/testing/sim/sim_test.h" #include "third_party/blink/renderer/core/testing/sim/sim_test.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h" #include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
...@@ -82,6 +83,60 @@ TEST_F(FontUpdateInvalidationTest, PartialLayoutInvalidationAfterFontLoading) { ...@@ -82,6 +83,60 @@ TEST_F(FontUpdateInvalidationTest, PartialLayoutInvalidationAfterFontLoading) {
main_resource.Finish(); main_resource.Finish();
} }
TEST_F(FontUpdateInvalidationTest,
PartialLayoutInvalidationAfterFontLoadingSVG) {
SimRequest main_resource("https://example.com", "text/html");
SimSubresourceRequest font_resource("https://example.com/Ahem.woff2",
"font/woff2");
LoadURL("https://example.com");
main_resource.Write(R"HTML(
<!doctype html>
<style>
@font-face {
font-family: custom-font;
src: url(https://example.com/Ahem.woff2) format("woff2");
}
#target {
font: 25px/1 custom-font, monospace;
}
#reference {
font: 25px/1 monospace;
}
</style>
<svg><text id=target dx=0,10>0123456789</text></svg>
<svg><text id=reference dx=0,10>0123456789</text></svg>
)HTML");
// First rendering the page with fallback
Compositor().BeginFrame();
auto* target = To<SVGTextElement>(GetDocument().getElementById("target"));
auto* reference =
To<SVGTextElement>(GetDocument().getElementById("reference"));
EXPECT_GT(250 + 10, target->GetBBox().Width());
EXPECT_GT(250 + 10, reference->GetBBox().Width());
// Finish font loading, and trigger invalidations.
font_resource.Complete(ReadAhemWoff2());
GetDocument().GetStyleEngine().InvalidateStyleAndLayoutForFontUpdates();
// No element is marked for style recalc, since no computed style is changed.
EXPECT_EQ(kNoStyleChange, target->GetStyleChangeType());
EXPECT_EQ(kNoStyleChange, reference->GetStyleChangeType());
// Only elements that had pending custom fonts are marked for relayout.
EXPECT_TRUE(target->GetLayoutObject()->NeedsLayout());
EXPECT_FALSE(reference->GetLayoutObject()->NeedsLayout());
Compositor().BeginFrame();
EXPECT_EQ(250 + 10, target->GetBBox().Width());
EXPECT_GT(250 + 10, reference->GetBBox().Width());
main_resource.Finish();
}
TEST_F(FontUpdateInvalidationTest, TEST_F(FontUpdateInvalidationTest,
PartialLayoutInvalidationAfterFontFaceDeletion) { PartialLayoutInvalidationAfterFontFaceDeletion) {
SimRequest main_resource("https://example.com", "text/html"); SimRequest main_resource("https://example.com", "text/html");
......
...@@ -90,6 +90,19 @@ void LayoutSVGInlineText::StyleDidChange(StyleDifference diff, ...@@ -90,6 +90,19 @@ void LayoutSVGInlineText::StyleDidChange(StyleDifference diff,
} }
} }
void LayoutSVGInlineText::InvalidateSubtreeLayoutForFontUpdates() {
NOT_DESTROYED();
if (!RuntimeEnabledFeatures::
CSSReducedFontLoadingLayoutInvalidationsEnabled() ||
!IsFontFallbackValid()) {
if (LayoutSVGText* text_layout_object =
LayoutSVGText::LocateLayoutSVGTextAncestor(this)) {
text_layout_object->SetNeedsTextMetricsUpdate();
}
}
LayoutText::InvalidateSubtreeLayoutForFontUpdates();
}
InlineTextBox* LayoutSVGInlineText::CreateTextBox(int start, uint16_t length) { InlineTextBox* LayoutSVGInlineText::CreateTextBox(int start, uint16_t length) {
NOT_DESTROYED(); NOT_DESTROYED();
InlineTextBox* box = InlineTextBox* box =
......
...@@ -74,6 +74,7 @@ class LayoutSVGInlineText final : public LayoutText { ...@@ -74,6 +74,7 @@ class LayoutSVGInlineText final : public LayoutText {
private: private:
void TextDidChange() override; void TextDidChange() override;
void StyleDidChange(StyleDifference, const ComputedStyle*) override; void StyleDidChange(StyleDifference, const ComputedStyle*) override;
void InvalidateSubtreeLayoutForFontUpdates() override;
void AddMetricsFromRun(const TextRun&, bool& last_character_was_white_space); void AddMetricsFromRun(const TextRun&, bool& last_character_was_white_space);
......
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