Commit df9cd410 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

[LayoutNG] Make NGInlineCursor::PositionForPointInChild() to work with...

[LayoutNG] Make NGInlineCursor::PositionForPointInChild() to work with inline-block that has block children

This patch changes |NGPaintFragment::PositionForPoint()| to work with block
children inline-block to make |NGInlineCursor::PositionForPointInChild()| to
work with it.

Bug: 1096110
Change-Id: Ia7d070fe5287a20868cafd4eac370e83a4d81fa3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2286092
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786605}
parent 18f718a1
...@@ -934,12 +934,11 @@ PositionWithAffinity NGInlineCursor::PositionForPointInChild( ...@@ -934,12 +934,11 @@ PositionWithAffinity NGInlineCursor::PositionForPointInChild(
case NGFragmentItem::kBox: case NGFragmentItem::kBox:
if (const NGPhysicalBoxFragment* box_fragment = if (const NGPhysicalBoxFragment* box_fragment =
child_item.BoxFragment()) { child_item.BoxFragment()) {
// We must fallback to legacy for old layout roots. We also fallback (to
// LayoutNGMixin::PositionForPoint()) for NG block layout, so that we
// can utilize LayoutBlock::PositionForPoint() that resolves the
// position in block layout.
// TODO(xiaochengh): Don't fallback to legacy for NG block layout.
if (!box_fragment->IsInlineBox()) { if (!box_fragment->IsInlineBox()) {
// In case of inline block with with block formatting context that
// has block children[1].
// Example: <b style="display:inline-block"><div>b</div></b>
// [1] NGInlineCursorTest.PositionForPointInChildBlockChildren
return child_item.GetLayoutObject()->PositionForPoint( return child_item.GetLayoutObject()->PositionForPoint(
point_in_container - child_item.OffsetInContainerBlock()); point_in_container - child_item.OffsetInContainerBlock());
} }
......
...@@ -884,6 +884,18 @@ TEST_P(NGInlineCursorTest, PositionForPointInChildVerticalRTL) { ...@@ -884,6 +884,18 @@ TEST_P(NGInlineCursorTest, PositionForPointInChildVerticalRTL) {
cursor.PositionForPointInChild(left_top + PhysicalOffset(0, 25))); cursor.PositionForPointInChild(left_top + PhysicalOffset(0, 25)));
} }
// For http://crbug.com/1096110
TEST_P(NGInlineCursorTest, PositionForPointInChildBlockChildren) {
InsertStyleElement("b { display: inline-block; }");
// Note: <b>.ChildrenInline() == false
NGInlineCursor cursor =
SetupCursor("<div id=root>a<b id=target><div>x</div></b></div>");
const Element& target = *GetElementById("target");
cursor.MoveTo(*target.GetLayoutObject());
EXPECT_EQ(PositionWithAffinity(Position(target, 0)),
cursor.PositionForPointInChild(PhysicalOffset()));
}
TEST_P(NGInlineCursorTest, Previous) { TEST_P(NGInlineCursorTest, Previous) {
// TDOO(yosin): Remove <style> once NGFragmentItem don't do culled inline. // TDOO(yosin): Remove <style> once NGFragmentItem don't do culled inline.
InsertStyleElement("b { background: gray; }"); InsertStyleElement("b { background: gray; }");
......
...@@ -996,10 +996,14 @@ PositionWithAffinity NGPaintFragment::PositionForPoint( ...@@ -996,10 +996,14 @@ PositionWithAffinity NGPaintFragment::PositionForPoint(
return PositionForPointInText(point); return PositionForPointInText(point);
if (PhysicalFragment().IsBlockFlow()) { if (PhysicalFragment().IsBlockFlow()) {
// We current fall back to legacy for block formatting contexts, so we const LayoutObject& layout_object = *PhysicalFragment().GetLayoutObject();
// should reach here only for inline formatting contexts. if (layout_object.ChildrenInline())
// TODO(xiaochengh): Do not fall back. return PositionForPointInInlineFormattingContext(point);
return PositionForPointInInlineFormattingContext(point); // |NGInlineCursor::PositionForPointInChild()| calls this function with
// inline block with with block formatting context that has block
// children[1], e.g: <b style="display:inline-block"><div>b</div></b>
// [1] NGInlineCursorTest.PositionForPointInChildBlockChildren
return layout_object.PositionForPoint(point);
} }
DCHECK(PhysicalFragment().IsInline() || PhysicalFragment().IsLineBox()); DCHECK(PhysicalFragment().IsInline() || PhysicalFragment().IsLineBox());
......
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