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

Introduce NGPhysicalFragment::ConvertToLogical()

This patch Introduces |NGPhysicalFragment::ConvertToLogical()| to avoid common
pattern in source code for improving code health.

Change-Id: I49924e8698b4fabce09ebc21212da0e177aab78f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228440
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775022}
parent 65792dc8
......@@ -59,10 +59,7 @@ LayoutUnit LastLineTextLogicalBottom(const NGPhysicalBoxFragment& container,
PhysicalRect line_rect =
line_item->LineBoxFragment()->ScrollableOverflowForLine(
container, container_style, *line_item, cursor);
return line_rect
.ConvertToLogical(container_style.GetWritingMode(),
container_style.Direction(), container.Size(),
cursor.Current().Size())
return container.ConvertToLogical(line_rect, cursor.Current().Size())
.BlockEndOffset();
}
......@@ -80,10 +77,7 @@ LayoutUnit LastLineTextLogicalBottom(const NGPhysicalBoxFragment& container,
PhysicalRect line_rect =
last_line->ScrollableOverflow(container, container_style);
line_rect.Move(last_line_offset);
return line_rect
.ConvertToLogical(container_style.GetWritingMode(),
container_style.Direction(), container.Size(),
last_line->Size())
return container.ConvertToLogical(line_rect, last_line->Size())
.BlockEndOffset();
}
......@@ -108,10 +102,7 @@ LayoutUnit FirstLineTextLogicalTop(const NGPhysicalBoxFragment& container,
PhysicalRect line_rect =
line_item->LineBoxFragment()->ScrollableOverflowForLine(
container, container_style, *line_item, cursor);
return line_rect
.ConvertToLogical(container_style.GetWritingMode(),
container_style.Direction(), container.Size(),
cursor.Current().Size())
return container.ConvertToLogical(line_rect, cursor.Current().Size())
.offset.block_offset;
}
......@@ -120,10 +111,7 @@ LayoutUnit FirstLineTextLogicalTop(const NGPhysicalBoxFragment& container,
PhysicalRect line_rect =
line->ScrollableOverflow(container, container_style);
line_rect.Move(child_link.offset);
return line_rect
.ConvertToLogical(container_style.GetWritingMode(),
container_style.Direction(), container.Size(),
line->Size())
return container.ConvertToLogical(line_rect, line->Size())
.offset.block_offset;
}
}
......
......@@ -506,6 +506,20 @@ bool NGPhysicalFragment::ShouldPaintDragCaret() const {
return false;
}
LogicalRect NGPhysicalFragment::ConvertToLogical(
const PhysicalRect& physical_rect,
PhysicalSize inner_size) const {
return ConvertToLogical(physical_rect, Style().Direction(), inner_size);
}
LogicalRect NGPhysicalFragment::ConvertToLogical(
const PhysicalRect& physical_rect,
TextDirection direction,
PhysicalSize inner_size) const {
return physical_rect.ConvertToLogical(Style().GetWritingMode(), direction,
Size(), inner_size);
}
String NGPhysicalFragment::ToString() const {
StringBuilder output;
output.AppendFormat("Type: '%d' Size: '%s'", Type(),
......
......@@ -337,6 +337,14 @@ class CORE_EXPORT NGPhysicalFragment
// be confused with the CSS 'direction' property.
TextDirection ResolvedDirection() const;
// Helper function to convert to |PhysicalRect| to |LogicalRect| with
// |Style().Direction()|
LogicalRect ConvertToLogical(const PhysicalRect& physical_rect,
PhysicalSize inner_size) const;
LogicalRect ConvertToLogical(const PhysicalRect& physical_rect,
TextDirection direction,
PhysicalSize inner_size) const;
// Utility functions for caret painting. Note that carets are painted as part
// of the containing block's foreground.
bool ShouldPaintCursorCaret() const;
......
......@@ -59,10 +59,10 @@ LogicalRect ComputeLogicalRectFor(const PhysicalRect& physical_rect,
LogicalRect ComputeLogicalRectFor(const PhysicalRect& physical_rect,
const NGPaintFragment& paint_fragment) {
return ComputeLogicalRectFor(
physical_rect, paint_fragment.Style().GetWritingMode(),
paint_fragment.PhysicalFragment().ResolvedDirection(),
paint_fragment.Size());
const NGPhysicalFragment& physical_fragment =
paint_fragment.PhysicalFragment();
return physical_fragment.ConvertToLogical(
physical_rect, physical_fragment.ResolvedDirection(), physical_rect.size);
}
LogicalRect ComputeLogicalRectFor(const PhysicalRect& physical_rect,
......@@ -145,21 +145,6 @@ LogicalRect ExpandSelectionRectToLineHeight(const LogicalRect& rect,
rect, ComputeLogicalRectFor(line_physical_rect, cursor));
}
LogicalOffset ChildLogicalOffsetInParent(const NGPaintFragment& child) {
DCHECK(child.Parent());
const NGPaintFragment& parent = *child.Parent();
return child.Offset().ConvertToLogical(parent.Style().GetWritingMode(),
parent.Style().Direction(),
parent.Size(), child.Size());
}
LogicalSize ChildLogicalSizeInParent(const NGPaintFragment& child) {
DCHECK(child.Parent());
const NGPaintFragment& parent = *child.Parent();
return NGFragment(parent.Style().GetWritingMode(), child.PhysicalFragment())
.Size();
}
base::Optional<PositionWithAffinity> PositionForPointInChild(
const NGPaintFragment& child,
const PhysicalOffset& point) {
......@@ -897,10 +882,11 @@ PositionWithAffinity NGPaintFragment::PositionForPointInInlineLevelBox(
if (child->PhysicalFragment().IsFloating())
continue;
const LayoutUnit child_inline_min =
ChildLogicalOffsetInParent(*child).inline_offset;
const LogicalRect logical_child_rect = PhysicalFragment().ConvertToLogical(
PhysicalRect(child->Offset(), child->Size()), child->Size());
const LayoutUnit child_inline_min = logical_child_rect.offset.inline_offset;
const LayoutUnit child_inline_max =
child_inline_min + ChildLogicalSizeInParent(*child).inline_size;
child_inline_min + logical_child_rect.size.inline_size;
// Try to resolve if |point| falls in any child in inline direction.
if (inline_point >= child_inline_min && inline_point <= child_inline_max) {
......@@ -986,9 +972,10 @@ PositionWithAffinity NGPaintFragment::PositionForPointInInlineFormattingContext(
if (!child->PhysicalFragment().IsLineBox() || child->Children().IsEmpty())
continue;
const LayoutUnit line_min = ChildLogicalOffsetInParent(*child).block_offset;
const LayoutUnit line_max =
line_min + ChildLogicalSizeInParent(*child).block_size;
const LogicalRect logical_child_rect = PhysicalFragment().ConvertToLogical(
PhysicalRect(child->Offset(), child->Size()), child->Size());
const LayoutUnit line_min = logical_child_rect.offset.block_offset;
const LayoutUnit line_max = line_min + logical_child_rect.size.block_size;
// Try to resolve if |point| falls in a line box in block direction.
// Hitting on line bottom doesn't count, to match legacy behavior.
......
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