Commit d404e0ef authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Use display item visual rects for NG box fragments

Bug: 1104064
Change-Id: I518bc448da22853a2e58eb59b9373965d6dfb343
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2304989
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790154}
parent d6373d01
......@@ -513,12 +513,12 @@ void NGBoxFragmentPainter::PaintObject(
const NGPhysicalBoxFragment& physical_box_fragment = PhysicalFragment();
const ComputedStyle& style = box_fragment_.Style();
bool is_visible = IsVisibleToPaint(physical_box_fragment, style);
if (!is_visible)
suppress_box_decoration_background = true;
if (ShouldPaintSelfBlockBackground(paint_phase)) {
PaintBoxDecorationBackground(paint_info, paint_offset,
suppress_box_decoration_background);
if (is_visible) {
PaintBoxDecorationBackground(paint_info, paint_offset,
suppress_box_decoration_background);
}
// We're done. We don't bother painting any children.
if (paint_phase == PaintPhase::kSelfBlockBackgroundOnly)
return;
......@@ -542,9 +542,9 @@ void NGBoxFragmentPainter::PaintObject(
(!physical_box_fragment.Children().empty() ||
physical_box_fragment.HasItems() || inline_box_cursor_) &&
!paint_info.DescendantPaintingBlocked()) {
if (UNLIKELY(paint_phase == PaintPhase::kForeground &&
box_fragment_.IsCSSBox() &&
box_fragment_.Style().HasColumnRule()))
if (is_visible && UNLIKELY(paint_phase == PaintPhase::kForeground &&
box_fragment_.IsCSSBox() &&
box_fragment_.Style().HasColumnRule()))
PaintColumnRules(paint_info, paint_offset);
if (paint_phase != PaintPhase::kFloat) {
......@@ -619,7 +619,7 @@ void NGBoxFragmentPainter::PaintObject(
}
}
if (ShouldPaintSelfOutline(paint_phase)) {
if (is_visible && ShouldPaintSelfOutline(paint_phase)) {
NGFragmentPainter(box_fragment_, GetDisplayItemClient())
.PaintOutline(paint_info, paint_offset);
}
......@@ -893,7 +893,7 @@ void NGBoxFragmentPainter::PaintMask(const PaintInfo& paint_info,
box_fragment_.GetLayoutObject()));
DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(),
paint_info.phase);
paint_info.phase, VisualRect(paint_offset));
PhysicalRect paint_rect(paint_offset, box_fragment_.Size());
const NGBorderEdges& border_edges = BorderEdges();
PaintMaskImages(paint_info, paint_rect, *box_fragment_.GetLayoutObject(),
......@@ -914,6 +914,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
base::Optional<ScopedBoxContentsPaintState> contents_paint_state;
bool painting_scrolling_background =
IsPaintingScrollingBackground(paint_info);
IntRect visual_rect;
if (painting_scrolling_background) {
// For the case where we are painting the background into the scrolling
// contents layer of a composited scroller we need to include the entire
......@@ -931,6 +932,8 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
background_client = &layout_box.GetScrollableArea()
->GetScrollingBackgroundDisplayItemClient();
visual_rect = layout_box.GetScrollableArea()->ScrollingBackgroundVisualRect(
paint_offset);
} else {
paint_rect.offset = paint_offset;
paint_rect.size = box_fragment_.Size();
......@@ -939,6 +942,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
PhysicalSize(ToLayoutBox(layout_object).PixelSnappedSize());
}
background_client = &GetDisplayItemClient();
visual_rect = VisualRect(paint_offset);
}
if (!suppress_box_decoration_background) {
......@@ -951,7 +955,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
PaintBoxDecorationBackgroundWithRect(
contents_paint_state ? contents_paint_state->GetPaintInfo()
: paint_info,
paint_rect, *background_client);
visual_rect, paint_rect, *background_client);
}
}
......@@ -985,6 +989,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
void NGBoxFragmentPainter::PaintBoxDecorationBackgroundWithRect(
const PaintInfo& paint_info,
const IntRect& visual_rect,
const PhysicalRect& paint_rect,
const DisplayItemClient& background_client) {
const LayoutBox& layout_box = ToLayoutBox(*box_fragment_.GetLayoutObject());
......@@ -1004,7 +1009,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackgroundWithRect(
return;
DrawingRecorder recorder(paint_info.context, background_client,
DisplayItem::kBoxDecorationBackground);
DisplayItem::kBoxDecorationBackground, visual_rect);
PaintBoxDecorationBackgroundWithRectImpl(paint_info, paint_rect,
box_decoration_data);
......@@ -1133,7 +1138,7 @@ void NGBoxFragmentPainter::PaintColumnRules(
return;
DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(),
DisplayItem::kColumnRules);
DisplayItem::kColumnRules, IntRect());
const Color& rule_color =
LayoutObject::ResolveColor(style, GetCSSPropertyColumnRuleColor());
......@@ -1211,6 +1216,7 @@ void NGBoxFragmentPainter::PaintColumnRules(
snapped_rule.Y(), snapped_rule.MaxX(),
snapped_rule.MaxY(), box_side, rule_color,
rule_style, 0, 0, true);
recorder.UniteVisualRect(snapped_rule);
previous_column = current_column;
}
......@@ -1509,14 +1515,15 @@ void NGBoxFragmentPainter::PaintBackplate(NGInlineCursor* line_boxes,
DisplayItem::kForcedColorsModeBackplate))
return;
DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(),
DisplayItem::kForcedColorsModeBackplate);
Color backplate_color = PhysicalFragment()
.GetLayoutObject()
->GetDocument()
.GetStyleEngine()
.ForcedBackgroundColor();
const auto& backplates = BuildBackplate(line_boxes, paint_offset);
DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(),
DisplayItem::kForcedColorsModeBackplate,
EnclosingIntRect(UnionRect(backplates)));
for (const auto backplate : backplates)
paint_info.context.FillRect(FloatRect(backplate), backplate_color);
}
......@@ -2522,4 +2529,20 @@ bool NGBoxFragmentPainter::HitTestOverflowControl(
accumulated_offset);
}
IntRect NGBoxFragmentPainter::VisualRect(const PhysicalOffset& paint_offset) {
if (const auto* layout_box =
ToLayoutBoxOrNull(box_fragment_.GetLayoutObject()))
return BoxPainter(*layout_box).VisualRect(paint_offset);
PhysicalRect ink_overflow;
if (paint_fragment_)
ink_overflow = paint_fragment_->InkOverflow();
else if (box_item_)
ink_overflow = box_item_->InkOverflow();
else
NOTREACHED();
ink_overflow.Move(paint_offset);
return EnclosingIntRect(ink_overflow);
}
} // namespace blink
......@@ -75,6 +75,8 @@ class NGBoxFragmentPainter : public BoxPainterBase {
const PhysicalRect&,
const BoxDecorationData&);
IntRect VisualRect(const PhysicalOffset& paint_offset);
protected:
LayoutRectOutsets ComputeBorders() const override;
LayoutRectOutsets ComputePadding() const override;
......@@ -110,8 +112,13 @@ class NGBoxFragmentPainter : public BoxPainterBase {
void PaintBoxDecorationBackground(const PaintInfo&,
const PhysicalOffset& paint_offset,
bool suppress_box_decoration_background);
// |visual_rect| is for the drawing display item, covering overflowing box
// shadows and border image outsets. |paint_rect| is the border box rect in
// paint coordinates.
void PaintBoxDecorationBackgroundWithRect(const PaintInfo&,
const PhysicalRect&,
const IntRect& visual_rect,
const PhysicalRect& paint_rect,
const DisplayItemClient&);
void PaintColumnRules(const PaintInfo&, const PhysicalOffset& paint_offset);
......
......@@ -83,8 +83,9 @@ void NGFieldsetPainter::PaintFieldsetDecorationBackground(
PhysicalRect contracted_rect(paint_rect);
contracted_rect.Contract(fieldset_paint_info.border_outsets);
DrawingRecorder recorder(paint_info.context, *fieldset_.GetLayoutObject(),
paint_info.phase);
DrawingRecorder recorder(
paint_info.context, *fieldset_.GetLayoutObject(), paint_info.phase,
NGBoxFragmentPainter(fieldset_).VisualRect(paint_offset));
NGBoxFragmentPainter fragment_painter(fieldset_);
if (box_decoration_data.ShouldPaintShadow()) {
......
......@@ -44,10 +44,7 @@ void NGMathMLPainter::PaintStretchyOrLargeOperator(
void NGMathMLPainter::PaintFractionBar(
const PaintInfo& info,
const DisplayItemClient& display_item_client,
PhysicalOffset paint_offset) {
DrawingRecorder recorder(info.context, display_item_client, info.phase);
DCHECK(box_fragment_.Style().IsHorizontalWritingMode());
const ComputedStyle& style = box_fragment_.Style();
LayoutUnit line_thickness = FractionLineThickness(style);
......@@ -69,7 +66,6 @@ void NGMathMLPainter::PaintFractionBar(
void NGMathMLPainter::PaintRadicalSymbol(
const PaintInfo& info,
const DisplayItemClient& display_item_client,
PhysicalOffset paint_offset) {
auto children = box_fragment_.Children();
if (children.size() == 0)
......@@ -78,8 +74,6 @@ void NGMathMLPainter::PaintRadicalSymbol(
const auto& base_child = To<NGPhysicalBoxFragment>(*children[0]);
const NGMathMLPaintInfo& parameters = box_fragment_.GetMathMLPaintInfo();
DrawingRecorder recorder(info.context, display_item_client, info.phase);
DCHECK(box_fragment_.Style().IsHorizontalWritingMode());
// Paint the vertical symbol.
......@@ -137,15 +131,18 @@ void NGMathMLPainter::Paint(const PaintInfo& info,
if (DrawingRecorder::UseCachedDrawingIfPossible(
info.context, display_item_client, info.phase))
return;
DrawingRecorder recorder(
info.context, display_item_client, info.phase,
NGBoxFragmentPainter(box_fragment_).VisualRect(paint_offset));
// Fraction
if (box_fragment_.IsMathMLFraction()) {
PaintFractionBar(info, display_item_client, paint_offset);
PaintFractionBar(info, paint_offset);
return;
}
// TODO(rbuis): paint operator
PaintRadicalSymbol(info, display_item_client, paint_offset);
PaintRadicalSymbol(info, paint_offset);
}
} // namespace blink
......@@ -11,7 +11,6 @@ namespace blink {
struct PaintInfo;
struct PhysicalOffset;
class DisplayItemClient;
class IntRect;
class NGPhysicalBoxFragment;
......@@ -26,10 +25,8 @@ class NGMathMLPainter {
private:
void PaintBar(const PaintInfo&, const IntRect&);
void PaintFractionBar(const PaintInfo&,
const DisplayItemClient&,
PhysicalOffset);
void PaintRadicalSymbol(const PaintInfo&,
const DisplayItemClient&,
PhysicalOffset);
void PaintStretchyOrLargeOperator(const PaintInfo&, PhysicalOffset);
......
......@@ -641,15 +641,6 @@ const LayoutObject& NGPaintFragment::VisualRectLayoutObject(
return *containing_block_fragment->GetLayoutObject();
}
IntRect NGPaintFragment::VisualRect() const {
// VisualRect is computed from fragment tree and set to LayoutObject in
// pre-paint. Use the stored value in the LayoutObject.
bool this_as_inline_box;
const auto& layout_object = VisualRectLayoutObject(this_as_inline_box);
DCHECK(!this_as_inline_box);
return layout_object.FragmentsVisualRectBoundingBox();
}
IntRect NGPaintFragment::PartialInvalidationVisualRect() const {
bool this_as_inline_box;
const auto& layout_object = VisualRectLayoutObject(this_as_inline_box);
......
......@@ -177,8 +177,6 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
bool HasOverflowClip() const { return PhysicalFragment().HasOverflowClip(); }
bool ShouldClipOverflow() const;
bool HasSelfPaintingLayer() const;
// This is equivalent to LayoutObject::VisualRect
IntRect VisualRect() const override;
IntRect PartialInvalidationVisualRect() const override;
// Set ShouldDoFullPaintInvalidation flag in the corresponding LayoutObject.
......
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