Commit 9a8e7c0c authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[LayoutNG] Templatize NGPaintFragment::InlineFragmentsIncludingCulledFor

This allows callsites to pass in a lambda that does a capture by
reference.

There should be no behaviour change.

Bug: 967830
Change-Id: I0253a9bb7dd8f95b9129d17eeabae1dc6c58c527
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1637588Reviewed-by: default avatarAleks Totic <atotic@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665202}
parent 690cb132
...@@ -1292,14 +1292,11 @@ PhysicalRect LayoutInline::LinesVisualOverflowBoundingBox() const { ...@@ -1292,14 +1292,11 @@ PhysicalRect LayoutInline::LinesVisualOverflowBoundingBox() const {
if (IsInLayoutNGInlineFormattingContext()) { if (IsInLayoutNGInlineFormattingContext()) {
PhysicalRect result; PhysicalRect result;
NGPaintFragment::InlineFragmentsIncludingCulledFor( NGPaintFragment::InlineFragmentsIncludingCulledFor(
*this, *this, [&result](const NGPaintFragment* fragment) {
[](NGPaintFragment* fragment, void* context) {
PhysicalRect* result = static_cast<PhysicalRect*>(context);
PhysicalRect child_rect = fragment->InkOverflow(); PhysicalRect child_rect = fragment->InkOverflow();
child_rect.offset += fragment->InlineOffsetToContainerBox(); child_rect.offset += fragment->InlineOffsetToContainerBox();
result->Unite(child_rect); result.Unite(child_rect);
}, });
&result);
return result; return result;
} }
......
...@@ -493,34 +493,6 @@ NGPaintFragment::FragmentRange NGPaintFragment::InlineFragmentsFor( ...@@ -493,34 +493,6 @@ NGPaintFragment::FragmentRange NGPaintFragment::InlineFragmentsFor(
return FragmentRange(nullptr, false); return FragmentRange(nullptr, false);
} }
void NGPaintFragment::InlineFragmentsIncludingCulledFor(
const LayoutObject& layout_object,
Callback callback,
void* context) {
DCHECK(layout_object.IsInLayoutNGInlineFormattingContext());
auto fragments = InlineFragmentsFor(&layout_object);
if (!fragments.IsEmpty()) {
for (NGPaintFragment* fragment : fragments)
callback(fragment, context);
return;
}
// This is a culled LayoutInline. Iterate children's fragments.
if (const LayoutInline* layout_inline =
ToLayoutInlineOrNull(&layout_object)) {
for (LayoutObject* child = layout_inline->FirstChild(); child;
child = child->NextSibling()) {
// |layout_inline| may still have non-inline children, e.g.,
// 'position:absolute'. Skip them as they don't contribute to the culled
// rects of |layout_inline|.
if (!child->IsInline())
continue;
InlineFragmentsIncludingCulledFor(*child, callback, context);
}
}
}
const NGPaintFragment* NGPaintFragment::LastForSameLayoutObject() const { const NGPaintFragment* NGPaintFragment::LastForSameLayoutObject() const {
return const_cast<NGPaintFragment*>(this)->LastForSameLayoutObject(); return const_cast<NGPaintFragment*>(this)->LastForSameLayoutObject();
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <memory> #include <memory>
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/layout_inline.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_fragment.h" #include "third_party/blink/renderer/core/layout/ng/ng_physical_fragment.h"
#include "third_party/blink/renderer/core/scroll/scroll_types.h" #include "third_party/blink/renderer/core/scroll/scroll_types.h"
#include "third_party/blink/renderer/platform/graphics/paint/display_item_client.h" #include "third_party/blink/renderer/platform/graphics/paint/display_item_client.h"
...@@ -258,10 +259,9 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>, ...@@ -258,10 +259,9 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
// Same as |InlineFragmentsFor()| but this function includes descendants if // Same as |InlineFragmentsFor()| but this function includes descendants if
// the |layout_object| is culled (i.e., did not generate fragments.) // the |layout_object| is culled (i.e., did not generate fragments.)
typedef void (*Callback)(NGPaintFragment*, void*); template <typename Callback>
static void InlineFragmentsIncludingCulledFor(const LayoutObject&, static void InlineFragmentsIncludingCulledFor(const LayoutObject&,
Callback callback, Callback callback);
void* context);
const NGPaintFragment* LastForSameLayoutObject() const; const NGPaintFragment* LastForSameLayoutObject() const;
NGPaintFragment* LastForSameLayoutObject(); NGPaintFragment* LastForSameLayoutObject();
...@@ -375,6 +375,34 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>, ...@@ -375,6 +375,34 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
unsigned is_dirty_inline_ : 1; unsigned is_dirty_inline_ : 1;
}; };
template <typename Callback>
void NGPaintFragment::InlineFragmentsIncludingCulledFor(
const LayoutObject& layout_object,
Callback callback) {
DCHECK(layout_object.IsInLayoutNGInlineFormattingContext());
auto fragments = InlineFragmentsFor(&layout_object);
if (!fragments.IsEmpty()) {
for (const NGPaintFragment* fragment : fragments)
callback(fragment);
return;
}
// This is a culled LayoutInline. Iterate children's fragments.
if (const LayoutInline* layout_inline =
ToLayoutInlineOrNull(&layout_object)) {
for (LayoutObject* child = layout_inline->FirstChild(); child;
child = child->NextSibling()) {
// |layout_inline| may still have non-inline children, e.g.,
// 'position:absolute'. Skip them as they don't contribute to the culled
// rects of |layout_inline|.
if (!child->IsInline())
continue;
InlineFragmentsIncludingCulledFor(*child, callback);
}
}
}
extern template class CORE_EXTERN_TEMPLATE_EXPORT extern template class CORE_EXTERN_TEMPLATE_EXPORT
NGPaintFragment::List<NGPaintFragment::TraverseNextForSameLayoutObject>; NGPaintFragment::List<NGPaintFragment::TraverseNextForSameLayoutObject>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT extern template class CORE_EXTERN_TEMPLATE_EXPORT
......
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