Commit 2d1270f2 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Fix ::first-line edge case and Inspector getPlatformFonts

This patch fixes:
1. ::first-line style is not applied when there are other
   anonymous inline boxes.
2. Inspector getPlatformFonts protocol collects fonts from
   two levels deep. Changed the logic not to include
   anonymous boxes to the depth limit.

Also the incorrect expectation was fixed; legacy counts
glyphs in ::first-letter twice.

Bug: 636993, 714962
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Ia028710b728e8e9172b540a46b42d804c9f57699
Reviewed-on: https://chromium-review.googlesource.com/1245078Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594395}
parent bef92b91
......@@ -426,7 +426,6 @@ crbug.com/591099 idle-callback/test-runner-run-idle-tasks.html [ Crash Pass Time
crbug.com/591099 images/color-profile-image-filter-all.html [ Failure ]
crbug.com/591099 images/rendering-broken-block-flow-images.html [ Failure ]
crbug.com/591099 images/rendering-broken-images.html [ Failure ]
crbug.com/714962 inspector-protocol/css/css-get-platform-fonts.js [ Failure ]
crbug.com/591099 inspector-protocol/dom-snapshot/dom-snapshot-getSnapshot-pseudo-element.js [ Failure ]
crbug.com/591099 inspector-protocol/dom-snapshot/dom-snapshot-getSnapshot.js [ Failure ]
crbug.com/714962 inspector-protocol/layout-fonts/languages-emoji-rare-glyphs.js [ Failure ]
......
Test css.getPlatformFontsForNode method.
Running test: testFirstLetterPseudoClass
Font #0
name: <Some-family-name-0>
glyphCount: 29
isCustomFont: true
Font #1
name: <Some-family-name-1>
glyphCount: 6
isCustomFont: false
Font #2
name: <Some-family-name-2>
glyphCount: 1
isCustomFont: false
Running test: testSelectElementPlatformFonts
Font #0
name: <Some-family-name-0>
glyphCount: 27
isCustomFont: false
......@@ -1162,9 +1162,19 @@ Response InspectorCSSAgent::getComputedStyleForNode(
void InspectorCSSAgent::CollectPlatformFontsForLayoutObject(
LayoutObject* layout_object,
HashCountedSet<std::pair<int, String>>* font_stats) {
if (!layout_object->IsText())
HashCountedSet<std::pair<int, String>>* font_stats,
unsigned descendants_depth) {
if (!layout_object->IsText()) {
if (!descendants_depth)
return;
if (!layout_object->IsAnonymous())
--descendants_depth;
for (LayoutObject* child = layout_object->SlowFirstChild(); child;
child = child->NextSibling()) {
CollectPlatformFontsForLayoutObject(child, font_stats, descendants_depth);
}
return;
}
FontCachePurgePreventer preventer;
LayoutText* layout_text = ToLayoutText(layout_object);
......@@ -1214,15 +1224,9 @@ Response InspectorCSSAgent::getPlatformFontsForNode(
HashCountedSet<std::pair<int, String>> font_stats;
LayoutObject* root = node->GetLayoutObject();
if (root) {
CollectPlatformFontsForLayoutObject(root, &font_stats);
// Iterate upto two layers deep.
for (LayoutObject* child = root->SlowFirstChild(); child;
child = child->NextSibling()) {
CollectPlatformFontsForLayoutObject(child, &font_stats);
for (LayoutObject* child2 = child->SlowFirstChild(); child2;
child2 = child2->NextSibling())
CollectPlatformFontsForLayoutObject(child2, &font_stats);
}
const unsigned descendants_depth = 2;
CollectPlatformFontsForLayoutObject(root, &font_stats, descendants_depth);
}
*platform_fonts = protocol::Array<protocol::CSS::PlatformFontUsage>::create();
for (auto& font : font_stats) {
......
......@@ -274,7 +274,8 @@ class CORE_EXPORT InspectorCSSAgent final
void CollectPlatformFontsForLayoutObject(
LayoutObject*,
HashCountedSet<std::pair<int, String>>*);
HashCountedSet<std::pair<int, String>>*,
unsigned descendants_depth);
InspectorStyleSheet* BindStyleSheet(CSSStyleSheet*);
String UnbindStyleSheet(InspectorStyleSheet*);
......
......@@ -3140,7 +3140,8 @@ void LayoutBlockFlow::AddChild(LayoutObject* new_child,
after_child->AddChild(new_child);
return;
}
LayoutInline* new_wrapper = LayoutInline::CreateAnonymous(&GetDocument());
LayoutInline* new_wrapper =
LayoutInline::CreateAnonymousForFirstLine(&GetDocument());
new_wrapper->SetStyle(ComputedStyle::CreateAnonymousStyleWithDisplay(
StyleRef(), EDisplay::kInline));
LayoutBox::AddChild(new_wrapper, before_child);
......
......@@ -91,9 +91,21 @@ LayoutInline* LayoutInline::CreateAnonymous(Document* document) {
}
bool LayoutInline::IsFirstLineAnonymous() const {
// TODO(kojii): We can add a flag, but this seems enough for now.
return IsAnonymous() && Parent() && Parent()->IsLayoutBlockFlow() &&
!PreviousSibling() && !NextSibling();
return false;
}
// A private class to distinguish anonymous inline box for ::first-line from
// other inline boxes.
class LayoutInlineForFirstLine : public LayoutInline {
public:
LayoutInlineForFirstLine(Element* element) : LayoutInline(element) {}
bool IsFirstLineAnonymous() const final { return true; }
};
LayoutInline* LayoutInline::CreateAnonymousForFirstLine(Document* document) {
LayoutInline* layout_inline = new LayoutInlineForFirstLine(nullptr);
layout_inline->SetDocumentForAnonymous(document);
return layout_inline;
}
void LayoutInline::WillBeDestroyed() {
......
......@@ -119,6 +119,10 @@ class CORE_EXPORT LayoutInline : public LayoutBoxModelObject {
static LayoutInline* CreateAnonymous(Document*);
// Create an anonymous inline box for ::first-line. The instance created by
// this function has IsFirstLineAnonymous() == true.
static LayoutInline* CreateAnonymousForFirstLine(Document*);
LayoutObject* FirstChild() const {
DCHECK_EQ(Children(), VirtualChildren());
return Children()->FirstChild();
......@@ -141,7 +145,7 @@ class CORE_EXPORT LayoutInline : public LayoutBoxModelObject {
// True if this is an anonymous inline box for ::first-line that wraps the
// whole inline formatting context.
bool IsFirstLineAnonymous() const;
virtual bool IsFirstLineAnonymous() const;
LayoutUnit MarginLeft() const final;
LayoutUnit MarginRight() const final;
......
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