Commit 50b48f69 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[FragmentItem] Move more of |NodeForHitTest| to |LayoutObject|

Following r719562 and r719898 to remove the duplicated logic
for |NodeForHitTest| in |NGPaintFragment|, this patch moves
the rest of this logic in |NGPhysicalFragment| to
|LayoutObject| so that it can be shared with |NGFragmentItem|.

There should be no behavior changes.

Bug: 982194
Change-Id: Iae467845281a9d4fcf479b9b85bb2770132f6f6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1942591
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720148}
parent 0ac1809a
......@@ -85,6 +85,7 @@
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/layout/ng/custom/layout_ng_custom.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_block_flow.h"
#include "third_party/blink/renderer/core/layout/ng/list/layout_ng_list_item.h"
#include "third_party/blink/renderer/core/layout/ng/ng_block_node.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_result.h"
#include "third_party/blink/renderer/core/layout/ng/ng_unpositioned_float.h"
......@@ -3342,6 +3343,11 @@ Node* LayoutObject::NodeForHitTest() const {
if (Node* node = parent->GetNode())
return node;
}
} else if (const LayoutNGListItem* list_item =
LayoutNGListItem::FromMarkerOrMarkerContent(*this)) {
// If this is a list marker, or is inside of a list marker, return the
// list item.
return list_item->GetNode();
}
}
......
......@@ -232,6 +232,22 @@ LayoutNGListItem* LayoutNGListItem::FromMarker(const LayoutObject& marker) {
return nullptr;
}
LayoutNGListItem* LayoutNGListItem::FromMarkerOrMarkerContent(
const LayoutObject& object) {
DCHECK(object.IsAnonymous());
if (object.IsLayoutNGListMarkerIncludingInside())
return FromMarker(object);
// Check if this is a marker content.
if (const LayoutObject* parent = object.Parent()) {
if (parent->IsLayoutNGListMarkerIncludingInside())
return FromMarker(*parent);
}
return nullptr;
}
int LayoutNGListItem::Value() const {
DCHECK(GetNode());
return ordinal_.Value(*GetNode());
......
......@@ -45,6 +45,7 @@ class CORE_EXPORT LayoutNGListItem final : public LayoutNGBlockFlow {
// Find the LayoutNGListItem from a marker.
static LayoutNGListItem* FromMarker(const LayoutObject& marker);
static LayoutNGListItem* FromMarkerOrMarkerContent(const LayoutObject&);
const char* GetName() const override { return "LayoutNGListItem"; }
......
......@@ -11,7 +11,6 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_node.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/list/layout_ng_list_item.h"
#include "third_party/blink/renderer/core/layout/ng/ng_block_node.h"
#include "third_party/blink/renderer/core/layout/ng/ng_fragment_builder.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
......@@ -33,21 +32,6 @@ static_assert(sizeof(NGPhysicalFragment) ==
sizeof(SameSizeAsNGPhysicalFragment),
"NGPhysicalFragment should stay small");
const LayoutObject* ListMarkerFromMarkerOrMarkerContent(
const LayoutObject* object) {
if (object->IsLayoutNGListMarkerIncludingInside())
return object;
// Check if this is a marker content.
if (object->IsAnonymous()) {
const LayoutObject* parent = object->Parent();
if (parent && parent->IsLayoutNGListMarkerIncludingInside())
return parent;
}
return nullptr;
}
bool AppendFragmentOffsetAndSize(const NGPhysicalFragment* fragment,
base::Optional<PhysicalOffset> fragment_offset,
StringBuilder* builder,
......@@ -504,22 +488,6 @@ bool NGPhysicalFragment::ShouldPaintDragCaret() const {
return false;
}
Node* NGPhysicalFragment::NodeForHitTest() const {
if (Node* node = layout_object_->NodeForHitTest())
return node;
// When the fragment is a list marker, return the list item.
if (const LayoutObject* marker =
ListMarkerFromMarkerOrMarkerContent(layout_object_)) {
if (const LayoutNGListItem* list_item =
LayoutNGListItem::FromMarker(*marker))
return list_item->GetNode();
return nullptr;
}
return nullptr;
}
String NGPhysicalFragment::ToString() const {
StringBuilder output;
output.AppendFormat("Type: '%d' Size: '%s'", Type(),
......
......@@ -204,7 +204,7 @@ class CORE_EXPORT NGPhysicalFragment
}
// The node to return when hit-testing on this fragment. This can be different
// from GetNode() when this fragment is content of a pseudo node.
Node* NodeForHitTest() const;
Node* NodeForHitTest() const { return layout_object_->NodeForHitTest(); }
// Whether there is a PaintLayer associated with the fragment.
bool HasLayer() const { return IsCSSBox() && layout_object_->HasLayer(); }
......
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