Commit 3fc2105e authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Optimize visual overflow computation code by devirtualizing some methods.

Before this patch, ComputeVisualOverflow() was virtual, and so was
AddVisualOverflowFromChildren(), which was called by
ComputeVisualOverflow(). This pattern existed to share a bit more
code with LayoutBlock other than the code to collect rects from
children. This CL instead inlines the duplicated code in a few places
and de-virtualizes AddVisualOverflowFromChildren.

Bug: 894244

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Ic9e36c0271ac6d88ee660e9113e1a2b7db8e0148
Reviewed-on: https://chromium-review.googlesource.com/c/1281234Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600156}
parent 9dd0a84e
......@@ -449,11 +449,11 @@ class CORE_EXPORT LayoutBlock : public LayoutBox {
private:
void AddVisualOverflowFromBlockChildren();
void AddVisualOverflowFromTheme();
void AddLayoutOverflowFromPositionedObjects();
void AddLayoutOverflowFromBlockChildren();
protected:
void AddVisualOverflowFromTheme();
virtual void ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats);
......@@ -461,7 +461,7 @@ class CORE_EXPORT LayoutBlock : public LayoutBox {
bool recompute_floats);
virtual void AddLayoutOverflowFromChildren();
virtual void AddVisualOverflowFromChildren();
void AddVisualOverflowFromChildren();
void AddOutlineRects(Vector<LayoutRect>&,
const LayoutPoint& additional_offset,
......
......@@ -2566,11 +2566,20 @@ void LayoutBlockFlow::UpdatePaintFragmentFromCachedLayoutResult(
void LayoutBlockFlow::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
LayoutBlock::ComputeVisualOverflow(previous_visual_overflow_rect,
recompute_floats);
AddVisualOverflowFromChildren();
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (recompute_floats || CreatesNewFormattingContext() ||
HasSelfPaintingLayer())
AddVisualOverflowFromFloats();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
}
void LayoutBlockFlow::ComputeLayoutOverflow(LayoutUnit old_client_after_edge,
......
......@@ -29,6 +29,7 @@
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/layout/layout_list_marker.h"
#include "third_party/blink/renderer/core/paint/list_item_painter.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/platform/wtf/saturated_arithmetic.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
......@@ -289,6 +290,25 @@ bool LayoutListItem::UpdateMarkerLocation() {
return false;
}
void LayoutListItem::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
AddVisualOverflowFromChildren();
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (recompute_floats || CreatesNewFormattingContext() ||
HasSelfPaintingLayer())
AddVisualOverflowFromFloats();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
}
void LayoutListItem::AddVisualOverflowFromChildren() {
LayoutBlockFlow::AddVisualOverflowFromChildren();
UpdateOverflow(Visual);
......
......@@ -70,7 +70,9 @@ class LayoutListItem final : public LayoutBlockFlow {
void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override;
void AddVisualOverflowFromChildren() override;
void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) final;
void AddVisualOverflowFromChildren();
void AddLayoutOverflowFromChildren() override;
void AlignMarkerInBlockDirection();
......
......@@ -29,6 +29,7 @@
#include "third_party/blink/renderer/core/layout/layout_multi_column_flow_thread.h"
#include "third_party/blink/renderer/core/layout/multi_column_fragmentainer_group.h"
#include "third_party/blink/renderer/core/paint/multi_column_set_painter.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
namespace blink {
......@@ -520,6 +521,25 @@ LayoutRect LayoutMultiColumnSet::FragmentsBoundingBox(
return result;
}
void LayoutMultiColumnSet::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
AddVisualOverflowFromChildren();
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (recompute_floats || CreatesNewFormattingContext() ||
HasSelfPaintingLayer())
AddVisualOverflowFromFloats();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
}
void LayoutMultiColumnSet::AddVisualOverflowFromChildren() {
// It's useless to calculate overflow if we haven't determined the page
// logical height yet.
......
......@@ -255,7 +255,9 @@ class CORE_EXPORT LayoutMultiColumnSet : public LayoutBlockFlow {
void PaintObject(const PaintInfo&,
const LayoutPoint& paint_offset) const override;
void AddVisualOverflowFromChildren() override;
void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) final;
void AddVisualOverflowFromChildren();
void AddLayoutOverflowFromChildren() override;
MultiColumnFragmentainerGroupList fragmentainer_groups_;
......
......@@ -910,6 +910,21 @@ void LayoutTable::InvalidateCollapsedBordersForAllCellsIfNeeded() {
}
}
void LayoutTable::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
AddVisualOverflowFromChildren();
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
}
void LayoutTable::AddVisualOverflowFromChildren() {
// Add overflow from borders.
// Technically it's odd that we are incorporating the borders into layout
......
......@@ -474,7 +474,9 @@ class CORE_EXPORT LayoutTable final : public LayoutBlock {
OverlayScrollbarClipBehavior =
kIgnorePlatformOverlayScrollbarSize) const override;
void AddVisualOverflowFromChildren() override;
void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) final;
void AddVisualOverflowFromChildren();
void AddLayoutOverflowFromChildren() override;
void RecalcSections() const;
......
......@@ -34,6 +34,7 @@
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_analyzer.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/text_control_single_line_painter.h"
#include "third_party/blink/renderer/platform/fonts/simple_font_data.h"
......@@ -317,4 +318,23 @@ HTMLInputElement* LayoutTextControlSingleLine::InputElement() const {
return ToHTMLInputElement(GetNode());
}
void LayoutTextControlSingleLine::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
AddVisualOverflowFromChildren();
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (recompute_floats || CreatesNewFormattingContext() ||
HasSelfPaintingLayer())
AddVisualOverflowFromFloats();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
}
} // namespace blink
......@@ -78,10 +78,11 @@ class LayoutTextControlSingleLine : public LayoutTextControl {
LayoutUnit line_height,
LayoutUnit non_content_height) const override;
void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) override;
// If the INPUT content height is smaller than the font height, the
// inner-editor element overflows the INPUT box intentionally, however it
// shouldn't affect outside of the INPUT box. So we ignore child overflow.
void AddVisualOverflowFromChildren() final {}
void AddLayoutOverflowFromChildren() final {}
bool AllowsOverflowClip() const override { return false; }
......
......@@ -19,6 +19,7 @@
#include "third_party/blink/renderer/core/layout/ng/ng_relative_utils.h"
#include "third_party/blink/renderer/core/paint/ng/ng_block_flow_painter.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
namespace blink {
......@@ -65,6 +66,21 @@ const NGPhysicalBoxFragment* LayoutNGMixin<Base>::CurrentFragment() const {
return nullptr;
}
template <typename Base>
void LayoutNGMixin<Base>::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
Base::ComputeVisualOverflow(previous_visual_overflow_rect, recompute_floats);
AddVisualOverflowFromChildren();
if (Base::VisualOverflowRect() != previous_visual_overflow_rect) {
if (Base::Layer())
Base::Layer()->SetNeedsCompositingInputsUpdate();
Base::GetFrameView()->SetIntersectionObservationState(
LocalFrameView::kDesired);
}
}
template <typename Base>
void LayoutNGMixin<Base>::AddVisualOverflowFromChildren() {
// |ComputeOverflow()| calls this, which is called from
......
......@@ -83,7 +83,9 @@ class LayoutNGMixin : public Base {
protected:
bool IsOfType(LayoutObject::LayoutObjectType) const override;
void AddVisualOverflowFromChildren() final;
void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) final;
void AddVisualOverflowFromChildren();
void AddLayoutOverflowFromChildren() final;
private:
......
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