Commit fd7e0290 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Add conversion functions for PositionWithAffinity templates

This patch adds ToPositionInDOMTreeWithAffinity() and
ToPositionInFlatTreeWithAffinity() to make PwA conversion easier.

It is also a preparation patch for adding NG line functions.

Change-Id: I4a802a183288fb7a1003ac9cf6e02fe7cad1d4a5
Reviewed-on: https://chromium-review.googlesource.com/1011392Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550531}
parent ea68b644
...@@ -20,9 +20,8 @@ const LayoutBlockFlow* NGInlineFormattingContextOf( ...@@ -20,9 +20,8 @@ const LayoutBlockFlow* NGInlineFormattingContextOf(
LocalCaretRect ComputeNGLocalCaretRect( LocalCaretRect ComputeNGLocalCaretRect(
const LayoutBlockFlow& context, const LayoutBlockFlow& context,
const PositionInFlatTreeWithAffinity& position) { const PositionInFlatTreeWithAffinity& position) {
const PositionWithAffinity dom_position( return ComputeNGLocalCaretRect(context,
ToPositionInDOMTree(position.GetPosition()), position.Affinity()); ToPositionInDOMTreeWithAffinity(position));
return ComputeNGLocalCaretRect(context, dom_position);
} }
} // namespace blink } // namespace blink
...@@ -33,6 +33,28 @@ bool PositionWithAffinityTemplate<Strategy>::operator==( ...@@ -33,6 +33,28 @@ bool PositionWithAffinityTemplate<Strategy>::operator==(
return affinity_ == other.affinity_ && position_ == other.position_; return affinity_ == other.affinity_ && position_ == other.position_;
} }
PositionWithAffinity ToPositionInDOMTreeWithAffinity(
const PositionWithAffinity& position) {
return position;
}
PositionWithAffinity ToPositionInDOMTreeWithAffinity(
const PositionInFlatTreeWithAffinity& position) {
return PositionWithAffinity(ToPositionInDOMTree(position.GetPosition()),
position.Affinity());
}
PositionInFlatTreeWithAffinity ToPositionInFlatTreeWithAffinity(
const PositionWithAffinity& position) {
return PositionInFlatTreeWithAffinity(
ToPositionInFlatTree(position.GetPosition()), position.Affinity());
}
PositionInFlatTreeWithAffinity ToPositionInFlatTreeWithAffinity(
const PositionInFlatTreeWithAffinity& position) {
return position;
}
template class CORE_TEMPLATE_EXPORT template class CORE_TEMPLATE_EXPORT
PositionWithAffinityTemplate<EditingStrategy>; PositionWithAffinityTemplate<EditingStrategy>;
template class CORE_TEMPLATE_EXPORT template class CORE_TEMPLATE_EXPORT
......
...@@ -65,6 +65,15 @@ using PositionWithAffinity = PositionWithAffinityTemplate<EditingStrategy>; ...@@ -65,6 +65,15 @@ using PositionWithAffinity = PositionWithAffinityTemplate<EditingStrategy>;
using PositionInFlatTreeWithAffinity = using PositionInFlatTreeWithAffinity =
PositionWithAffinityTemplate<EditingInFlatTreeStrategy>; PositionWithAffinityTemplate<EditingInFlatTreeStrategy>;
PositionWithAffinity ToPositionInDOMTreeWithAffinity(
const PositionWithAffinity&);
PositionWithAffinity ToPositionInDOMTreeWithAffinity(
const PositionInFlatTreeWithAffinity&);
PositionInFlatTreeWithAffinity ToPositionInFlatTreeWithAffinity(
const PositionWithAffinity&);
PositionInFlatTreeWithAffinity ToPositionInFlatTreeWithAffinity(
const PositionInFlatTreeWithAffinity&);
template <typename Strategy> template <typename Strategy>
PositionWithAffinityTemplate<Strategy> FromPositionInDOMTree( PositionWithAffinityTemplate<Strategy> FromPositionInDOMTree(
const PositionWithAffinity&); const PositionWithAffinity&);
......
...@@ -192,8 +192,7 @@ PositionInFlatTreeWithAffinity NextWordPosition( ...@@ -192,8 +192,7 @@ PositionInFlatTreeWithAffinity NextWordPosition(
PositionWithAffinity NextWordPosition(const Position& start) { PositionWithAffinity NextWordPosition(const Position& start) {
const PositionInFlatTreeWithAffinity& next = const PositionInFlatTreeWithAffinity& next =
NextWordPosition(ToPositionInFlatTree(start)); NextWordPosition(ToPositionInFlatTree(start));
return PositionWithAffinity(ToPositionInDOMTree(next.GetPosition()), return ToPositionInDOMTreeWithAffinity(next);
next.Affinity());
} }
// TODO(yosin): This function will be removed by replacing call sites to use // TODO(yosin): This function will be removed by replacing call sites to use
......
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