Commit 2392c931 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Introduce NGInlineCursor version of ClosestLeafChildForPoint() for AbstractLineBox

This patch Introduces |NGInlineCursor| version of |ClosestLeafChildForPoint()|
for |AbstractLineBox| to reduce usage of |NGPhysicalLineBoxFragment| and
|NGPaintFragment| for prepration of migrating |NGFragmentItem|.


Bug: 982194
Change-Id: Id57b707d4a84fec794f275be6dc8a42e9465d3e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875856
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709812}
parent 3e7f8dd6
......@@ -36,11 +36,9 @@
#include "third_party/blink/renderer/core/editing/visible_units.h"
#include "third_party/blink/renderer/core/layout/api/line_layout_api_shim.h"
#include "third_party/blink/renderer/core/layout/api/line_layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/geometry/logical_rect.h"
#include "third_party/blink/renderer/core/layout/line/root_inline_box.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_line_utils.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
namespace blink {
......@@ -73,12 +71,9 @@ class AbstractLineBox {
if (!logical_size.block_size)
return false;
// Use |ClosestLeafChildForPoint| to check if there's any leaf child.
// TODO(yosin): We should use |NGInlineCursor| version of
// |ClosestLeafChildForPoint()|.
const bool only_editable_leaves = false;
return To<NGPhysicalLineBoxFragment>(
cursor_.CurrentPaintFragment()->PhysicalFragment())
.ClosestLeafChildForPoint(PhysicalOffset(), only_editable_leaves);
return ClosestLeafChildForPoint(cursor_, PhysicalOffset(),
only_editable_leaves);
}
AbstractLineBox PreviousLine() const {
......@@ -133,11 +128,8 @@ class AbstractLineBox {
GetBlock().FlipForWritingMode(point), only_editable_leaves);
}
const PhysicalOffset local_physical_point = point - cursor_.CurrentOffset();
// TODO(yosin): We should use |NGInlineCursor| version of
// |ClosestLeafChildForPoint()|.
return To<NGPhysicalLineBoxFragment>(
cursor_.CurrentPaintFragment()->PhysicalFragment())
.ClosestLeafChildForPoint(local_physical_point, only_editable_leaves);
return ClosestLeafChildForPoint(cursor_, local_physical_point,
only_editable_leaves);
}
private:
......@@ -185,6 +177,48 @@ class AbstractLineBox {
HasEditableStyle(*layout_object->GetNode());
}
static const LayoutObject* ClosestLeafChildForPoint(
const NGInlineCursor& line,
const PhysicalOffset& point,
bool only_editable_leaves) {
const PhysicalSize unit_square(LayoutUnit(1), LayoutUnit(1));
const LogicalOffset logical_point = point.ConvertToLogical(
line.CurrentStyle().GetWritingMode(), line.CurrentBaseDirection(),
line.CurrentSize(), unit_square);
const LayoutUnit inline_offset = logical_point.inline_offset;
const LayoutObject* closest_leaf_child = nullptr;
LayoutUnit closest_leaf_distance;
NGInlineCursor cursor(line);
for (cursor.MoveToNext(); cursor; cursor.MoveToNext()) {
if (!cursor.CurrentLayoutObject())
continue;
if (!cursor.IsInlineLeaf())
continue;
if (only_editable_leaves && !IsEditable(cursor))
continue;
const LogicalRect fragment_logical_rect =
cursor.CurrentRect().ConvertToLogical(
line.CurrentStyle().GetWritingMode(), line.CurrentBaseDirection(),
line.CurrentSize(), cursor.CurrentSize());
const LayoutUnit inline_min = fragment_logical_rect.offset.inline_offset;
const LayoutUnit inline_max = fragment_logical_rect.offset.inline_offset +
fragment_logical_rect.size.inline_size;
if (inline_offset >= inline_min && inline_offset < inline_max)
return cursor.CurrentLayoutObject();
const LayoutUnit distance =
inline_offset < inline_min
? inline_min - inline_offset
: inline_offset - inline_max + LayoutUnit(1);
if (!closest_leaf_child || distance < closest_leaf_distance) {
closest_leaf_child = cursor.CurrentLayoutObject();
closest_leaf_distance = distance;
}
}
return closest_leaf_child;
}
enum class Type { kNull, kOldLayout, kLayoutNG };
const RootInlineBox* root_inline_box_ = nullptr;
......
......@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/layout/geometry/physical_rect.h"
#include "third_party/blink/renderer/core/layout/geometry/logical_rect.h"
#include "third_party/blink/renderer/core/layout/ng/geometry/ng_box_strut.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect.h"
......@@ -12,6 +13,15 @@
namespace blink {
LogicalRect PhysicalRect::ConvertToLogical(WritingMode mode,
TextDirection direction,
PhysicalSize outer_size,
PhysicalSize inner_size) const {
return LogicalRect(
offset.ConvertToLogical(mode, direction, outer_size, inner_size),
size.ConvertToLogical(mode));
}
bool PhysicalRect::Contains(const PhysicalRect& other) const {
return offset.left <= other.offset.left && offset.top <= other.offset.top &&
Right() >= other.Right() && Bottom() >= other.Bottom();
......
......@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_offset.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_rect.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_size.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect.h"
......@@ -20,6 +21,7 @@ class TextStream;
namespace blink {
class ComputedStyle;
struct LogicalRect;
struct NGPhysicalBoxStrut;
// PhysicalRect is the position and size of a rect (typically a fragment)
......@@ -47,6 +49,15 @@ struct CORE_EXPORT PhysicalRect {
PhysicalOffset offset;
PhysicalSize size;
// Converts a physical offset to a logical offset. See:
// https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical
// @param outer_size the size of the rect (typically a fragment).
// @param inner_size the size of the inner rect (typically a child fragment).
LogicalRect ConvertToLogical(WritingMode,
TextDirection,
PhysicalSize outer_size,
PhysicalSize inner_size) const;
constexpr bool IsEmpty() const { return size.IsEmpty(); }
constexpr LayoutUnit X() const { return offset.left; }
......
......@@ -178,7 +178,11 @@ bool NGInlineCursor::IsHiddenForPaint() const {
}
bool NGInlineCursor::IsInlineLeaf() const {
return IsText() || IsAtomicInline();
if (IsText())
return true;
if (!IsAtomicInline())
return false;
return !IsListMarker();
}
bool NGInlineCursor::IsInclusiveDescendantOf(
......
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