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, ...@@ -59,10 +59,7 @@ LayoutUnit LastLineTextLogicalBottom(const NGPhysicalBoxFragment& container,
PhysicalRect line_rect = PhysicalRect line_rect =
line_item->LineBoxFragment()->ScrollableOverflowForLine( line_item->LineBoxFragment()->ScrollableOverflowForLine(
container, container_style, *line_item, cursor); container, container_style, *line_item, cursor);
return line_rect return container.ConvertToLogical(line_rect, cursor.Current().Size())
.ConvertToLogical(container_style.GetWritingMode(),
container_style.Direction(), container.Size(),
cursor.Current().Size())
.BlockEndOffset(); .BlockEndOffset();
} }
...@@ -80,10 +77,7 @@ LayoutUnit LastLineTextLogicalBottom(const NGPhysicalBoxFragment& container, ...@@ -80,10 +77,7 @@ LayoutUnit LastLineTextLogicalBottom(const NGPhysicalBoxFragment& container,
PhysicalRect line_rect = PhysicalRect line_rect =
last_line->ScrollableOverflow(container, container_style); last_line->ScrollableOverflow(container, container_style);
line_rect.Move(last_line_offset); line_rect.Move(last_line_offset);
return line_rect return container.ConvertToLogical(line_rect, last_line->Size())
.ConvertToLogical(container_style.GetWritingMode(),
container_style.Direction(), container.Size(),
last_line->Size())
.BlockEndOffset(); .BlockEndOffset();
} }
...@@ -108,10 +102,7 @@ LayoutUnit FirstLineTextLogicalTop(const NGPhysicalBoxFragment& container, ...@@ -108,10 +102,7 @@ LayoutUnit FirstLineTextLogicalTop(const NGPhysicalBoxFragment& container,
PhysicalRect line_rect = PhysicalRect line_rect =
line_item->LineBoxFragment()->ScrollableOverflowForLine( line_item->LineBoxFragment()->ScrollableOverflowForLine(
container, container_style, *line_item, cursor); container, container_style, *line_item, cursor);
return line_rect return container.ConvertToLogical(line_rect, cursor.Current().Size())
.ConvertToLogical(container_style.GetWritingMode(),
container_style.Direction(), container.Size(),
cursor.Current().Size())
.offset.block_offset; .offset.block_offset;
} }
...@@ -120,10 +111,7 @@ LayoutUnit FirstLineTextLogicalTop(const NGPhysicalBoxFragment& container, ...@@ -120,10 +111,7 @@ LayoutUnit FirstLineTextLogicalTop(const NGPhysicalBoxFragment& container,
PhysicalRect line_rect = PhysicalRect line_rect =
line->ScrollableOverflow(container, container_style); line->ScrollableOverflow(container, container_style);
line_rect.Move(child_link.offset); line_rect.Move(child_link.offset);
return line_rect return container.ConvertToLogical(line_rect, line->Size())
.ConvertToLogical(container_style.GetWritingMode(),
container_style.Direction(), container.Size(),
line->Size())
.offset.block_offset; .offset.block_offset;
} }
} }
......
...@@ -506,6 +506,20 @@ bool NGPhysicalFragment::ShouldPaintDragCaret() const { ...@@ -506,6 +506,20 @@ bool NGPhysicalFragment::ShouldPaintDragCaret() const {
return false; 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 { String NGPhysicalFragment::ToString() const {
StringBuilder output; StringBuilder output;
output.AppendFormat("Type: '%d' Size: '%s'", Type(), output.AppendFormat("Type: '%d' Size: '%s'", Type(),
......
...@@ -337,6 +337,14 @@ class CORE_EXPORT NGPhysicalFragment ...@@ -337,6 +337,14 @@ class CORE_EXPORT NGPhysicalFragment
// be confused with the CSS 'direction' property. // be confused with the CSS 'direction' property.
TextDirection ResolvedDirection() const; 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 // Utility functions for caret painting. Note that carets are painted as part
// of the containing block's foreground. // of the containing block's foreground.
bool ShouldPaintCursorCaret() const; bool ShouldPaintCursorCaret() const;
......
...@@ -59,10 +59,10 @@ LogicalRect ComputeLogicalRectFor(const PhysicalRect& physical_rect, ...@@ -59,10 +59,10 @@ LogicalRect ComputeLogicalRectFor(const PhysicalRect& physical_rect,
LogicalRect ComputeLogicalRectFor(const PhysicalRect& physical_rect, LogicalRect ComputeLogicalRectFor(const PhysicalRect& physical_rect,
const NGPaintFragment& paint_fragment) { const NGPaintFragment& paint_fragment) {
return ComputeLogicalRectFor( const NGPhysicalFragment& physical_fragment =
physical_rect, paint_fragment.Style().GetWritingMode(), paint_fragment.PhysicalFragment();
paint_fragment.PhysicalFragment().ResolvedDirection(), return physical_fragment.ConvertToLogical(
paint_fragment.Size()); physical_rect, physical_fragment.ResolvedDirection(), physical_rect.size);
} }
LogicalRect ComputeLogicalRectFor(const PhysicalRect& physical_rect, LogicalRect ComputeLogicalRectFor(const PhysicalRect& physical_rect,
...@@ -145,21 +145,6 @@ LogicalRect ExpandSelectionRectToLineHeight(const LogicalRect& rect, ...@@ -145,21 +145,6 @@ LogicalRect ExpandSelectionRectToLineHeight(const LogicalRect& rect,
rect, ComputeLogicalRectFor(line_physical_rect, cursor)); 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( base::Optional<PositionWithAffinity> PositionForPointInChild(
const NGPaintFragment& child, const NGPaintFragment& child,
const PhysicalOffset& point) { const PhysicalOffset& point) {
...@@ -897,10 +882,11 @@ PositionWithAffinity NGPaintFragment::PositionForPointInInlineLevelBox( ...@@ -897,10 +882,11 @@ PositionWithAffinity NGPaintFragment::PositionForPointInInlineLevelBox(
if (child->PhysicalFragment().IsFloating()) if (child->PhysicalFragment().IsFloating())
continue; continue;
const LayoutUnit child_inline_min = const LogicalRect logical_child_rect = PhysicalFragment().ConvertToLogical(
ChildLogicalOffsetInParent(*child).inline_offset; PhysicalRect(child->Offset(), child->Size()), child->Size());
const LayoutUnit child_inline_min = logical_child_rect.offset.inline_offset;
const LayoutUnit child_inline_max = 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. // Try to resolve if |point| falls in any child in inline direction.
if (inline_point >= child_inline_min && inline_point <= child_inline_max) { if (inline_point >= child_inline_min && inline_point <= child_inline_max) {
...@@ -986,9 +972,10 @@ PositionWithAffinity NGPaintFragment::PositionForPointInInlineFormattingContext( ...@@ -986,9 +972,10 @@ PositionWithAffinity NGPaintFragment::PositionForPointInInlineFormattingContext(
if (!child->PhysicalFragment().IsLineBox() || child->Children().IsEmpty()) if (!child->PhysicalFragment().IsLineBox() || child->Children().IsEmpty())
continue; continue;
const LayoutUnit line_min = ChildLogicalOffsetInParent(*child).block_offset; const LogicalRect logical_child_rect = PhysicalFragment().ConvertToLogical(
const LayoutUnit line_max = PhysicalRect(child->Offset(), child->Size()), child->Size());
line_min + ChildLogicalSizeInParent(*child).block_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. // Try to resolve if |point| falls in a line box in block direction.
// Hitting on line bottom doesn't count, to match legacy behavior. // 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