Commit 923f4e28 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Slight reorganization of ComputeInlineBoxPosition

This patch slightly reorganizes the above mentioned function to make the
logic clearer that, the function has three major branches dependig on
the type of |layout_object|: text, block flow with children, or atomic
inline.

Detail: Adding |IsAtomicInlineLevel()| check to the last part of the
function doesn't introduce any behavior change. This is because that
|LayoutBox::InlineBoxWrapper()| returns non-null result only when the
layout object is an atomic inline.

Bug: 771398
Change-Id: Id61830a9ad11de40c5ae7456e3e13b6a4094b1a9
Reviewed-on: https://chromium-review.googlesource.com/775659Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517410}
parent 3cd9e411
...@@ -282,29 +282,40 @@ InlineBoxPosition ComputeInlineBoxPositionTemplate( ...@@ -282,29 +282,40 @@ InlineBoxPosition ComputeInlineBoxPositionTemplate(
return ComputeInlineBoxPositionForTextNode(layout_object, caret_offset, return ComputeInlineBoxPositionForTextNode(layout_object, caret_offset,
affinity, primary_direction); affinity, primary_direction);
} }
if (CanHaveChildrenForEditing(anchor_node) &&
layout_object->IsLayoutBlockFlow() && if (layout_object->IsLayoutBlockFlow()) {
HasRenderedNonAnonymousDescendantsWithHeight(layout_object)) { if (CanHaveChildrenForEditing(anchor_node) &&
// Try a visually equivalent position with possibly opposite HasRenderedNonAnonymousDescendantsWithHeight(layout_object)) {
// editability. This helps in case |this| is in an editable block // Try a visually equivalent position with possibly opposite
// but surrounded by non-editable positions. It acts to negate the // editability. This helps in case |this| is in an editable block
// logic at the beginning of // but surrounded by non-editable positions. It acts to negate the
// |LayoutObject::createPositionWithAffinity()|. // logic at the beginning of
const PositionTemplate<Strategy>& downstream_equivalent = // |LayoutObject::createPositionWithAffinity()|.
DownstreamIgnoringEditingBoundaries(position); const PositionTemplate<Strategy>& downstream_equivalent =
if (downstream_equivalent != position) { DownstreamIgnoringEditingBoundaries(position);
if (downstream_equivalent != position) {
return ComputeInlineBoxPosition(
downstream_equivalent, TextAffinity::kUpstream, primary_direction);
}
const PositionTemplate<Strategy>& upstream_equivalent =
UpstreamIgnoringEditingBoundaries(position);
if (upstream_equivalent == position ||
DownstreamIgnoringEditingBoundaries(upstream_equivalent) == position)
return InlineBoxPosition();
return ComputeInlineBoxPosition( return ComputeInlineBoxPosition(
downstream_equivalent, TextAffinity::kUpstream, primary_direction); upstream_equivalent, TextAffinity::kUpstream, primary_direction);
} }
const PositionTemplate<Strategy>& upstream_equivalent =
UpstreamIgnoringEditingBoundaries(position); // We can't return null here because atomic inlines can also be block flows,
if (upstream_equivalent == position || // e.g., LayoutTextControl.
DownstreamIgnoringEditingBoundaries(upstream_equivalent) == position) // TODO(xiaochengh): Move atomic inline handling before block flow handling
return InlineBoxPosition(); // so that we can directly return null here.
return ComputeInlineBoxPosition(upstream_equivalent,
TextAffinity::kUpstream, primary_direction);
} }
if (!layout_object->IsAtomicInlineLevel())
return InlineBoxPosition();
if (!layout_object->IsBox()) if (!layout_object->IsBox())
return InlineBoxPosition(); return InlineBoxPosition();
InlineBox* const inline_box = ToLayoutBox(layout_object)->InlineBoxWrapper(); InlineBox* const inline_box = ToLayoutBox(layout_object)->InlineBoxWrapper();
......
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