Commit 7f1f6e6a authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Expose subroutines of ComputeInlinePosition

This patch exposes two subroutines of ComputeInlineBoxPosition:
- ComputeInlineAdjustedPosition
- ComputeInlineBoxPositionForInlineAdjustedPosition

After this patch, we can start converting callers of
ComputeInlineBoxPosition with the following pattern:

DoSomeBusiness(position) {
  adjusted = ComputeInlineAdjustedPosition(position);
  if (/* adjusted is laid out with LayoutNG */)
    return NGAlternativeImplementation(adjusted);
  legacy_box_position =
      ComputeInlineBoxPositionForInlineAdjustedPosition(adjusted);
  DoLegacyBusiness(legacy_box_position);
}

Bug: 771398
Change-Id: Iea01925e7ef986c5b00dd5b6e7172f7065c8df9e
Reviewed-on: https://chromium-review.googlesource.com/792453Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521274}
parent 654a8f0c
......@@ -299,7 +299,7 @@ InlineBoxPosition ComputeInlineBoxPositionForAtomicInline(
}
template <typename Strategy>
PositionWithAffinityTemplate<Strategy> ComputeInlineAdjustedPosition(
PositionWithAffinityTemplate<Strategy> ComputeInlineAdjustedPositionAlgorithm(
const PositionWithAffinityTemplate<Strategy>&);
template <typename Strategy>
......@@ -312,8 +312,9 @@ PositionWithAffinityTemplate<Strategy> AdjustBlockFlowPositionToInline(
const PositionTemplate<Strategy>& downstream_equivalent =
DownstreamIgnoringEditingBoundaries(position);
if (downstream_equivalent != position) {
return ComputeInlineAdjustedPosition(PositionWithAffinityTemplate<Strategy>(
downstream_equivalent, TextAffinity::kUpstream));
return ComputeInlineAdjustedPositionAlgorithm(
PositionWithAffinityTemplate<Strategy>(downstream_equivalent,
TextAffinity::kUpstream));
}
const PositionTemplate<Strategy>& upstream_equivalent =
UpstreamIgnoringEditingBoundaries(position);
......@@ -321,14 +322,13 @@ PositionWithAffinityTemplate<Strategy> AdjustBlockFlowPositionToInline(
DownstreamIgnoringEditingBoundaries(upstream_equivalent) == position)
return PositionWithAffinityTemplate<Strategy>();
return ComputeInlineAdjustedPosition(PositionWithAffinityTemplate<Strategy>(
upstream_equivalent, TextAffinity::kUpstream));
return ComputeInlineAdjustedPositionAlgorithm(
PositionWithAffinityTemplate<Strategy>(upstream_equivalent,
TextAffinity::kUpstream));
}
// TODO(xiaochengh): Expose this function for current callers of
// ComputeInlineBoxPosition() for deciding to use legacy or NG implementation.
template <typename Strategy>
PositionWithAffinityTemplate<Strategy> ComputeInlineAdjustedPosition(
PositionWithAffinityTemplate<Strategy> ComputeInlineAdjustedPositionAlgorithm(
const PositionWithAffinityTemplate<Strategy>& position) {
const LayoutObject& layout_object =
GetLayoutObjectSkippingShadowRoot(position.GetPosition());
......@@ -350,9 +350,8 @@ PositionWithAffinityTemplate<Strategy> ComputeInlineAdjustedPosition(
return AdjustBlockFlowPositionToInline(position.GetPosition());
}
// TODO(xiaochengh): Expose this function for code depending on legacy layout.
template <typename Strategy>
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPositionAlgorithm(
const PositionWithAffinityTemplate<Strategy>& adjusted,
TextDirection primary_direction) {
const PositionTemplate<Strategy>& position = adjusted.GetPosition();
......@@ -372,6 +371,13 @@ InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
primary_direction);
}
template <typename Strategy>
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPositionAlgorithm(
const PositionWithAffinityTemplate<Strategy>& position) {
return ComputeInlineBoxPositionForInlineAdjustedPositionAlgorithm(
position, PrimaryDirectionOf(*position.AnchorNode()));
}
template <typename Strategy>
InlineBoxPosition ComputeInlineBoxPositionTemplate(
const PositionWithAffinityTemplate<Strategy>& position,
......@@ -424,4 +430,45 @@ InlineBoxPosition ComputeInlineBoxPosition(
position, primary_direction);
}
PositionWithAffinity ComputeInlineAdjustedPosition(
const PositionWithAffinity& position) {
return ComputeInlineAdjustedPositionAlgorithm(position);
}
PositionInFlatTreeWithAffinity ComputeInlineAdjustedPosition(
const PositionInFlatTreeWithAffinity& position) {
return ComputeInlineAdjustedPositionAlgorithm(position);
}
PositionWithAffinity ComputeInlineAdjustedPosition(
const VisiblePosition& position) {
DCHECK(position.IsValid()) << position;
return ComputeInlineAdjustedPositionAlgorithm(
position.ToPositionWithAffinity());
}
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
const PositionWithAffinity& position) {
return ComputeInlineBoxPositionForInlineAdjustedPositionAlgorithm(position);
}
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
const PositionInFlatTreeWithAffinity& position) {
return ComputeInlineBoxPositionForInlineAdjustedPositionAlgorithm(position);
}
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
const PositionWithAffinity& position,
TextDirection primary_direction) {
return ComputeInlineBoxPositionForInlineAdjustedPositionAlgorithm(
position, primary_direction);
}
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
const PositionInFlatTreeWithAffinity& position,
TextDirection primary_direction) {
return ComputeInlineBoxPositionForInlineAdjustedPositionAlgorithm(
position, primary_direction);
}
} // namespace blink
......@@ -76,6 +76,22 @@ ComputeInlineBoxPosition(const PositionInFlatTreeWithAffinity&,
TextDirection primary_direction);
CORE_EXPORT InlineBoxPosition ComputeInlineBoxPosition(const VisiblePosition&);
PositionWithAffinity ComputeInlineAdjustedPosition(const PositionWithAffinity&);
PositionInFlatTreeWithAffinity ComputeInlineAdjustedPosition(
const PositionInFlatTreeWithAffinity&);
PositionWithAffinity ComputeInlineAdjustedPosition(const VisiblePosition&);
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
const PositionWithAffinity&);
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
const PositionWithAffinity&,
TextDirection primary_direction);
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
const PositionInFlatTreeWithAffinity&);
InlineBoxPosition ComputeInlineBoxPositionForInlineAdjustedPosition(
const PositionInFlatTreeWithAffinity&,
TextDirection primary_direction);
// The print for |InlineBoxPosition| is available only for testing
// in "webkit_unit_tests", and implemented in
// "core/editing/InlineBoxPositionTest.cpp".
......
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