Commit 622ac8ad authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

[EditingNG] Paint caret in NG contenteditable blocks

This patch makes NGBoxFragmentPainter paint caret by
- Routing back to legacy LayoutBlock to determine if a block has
  carets to paint
- Adding caret painting code to NGBoxFragmentPainter
so that carets can be painted in NG contenteditable blocks.

This patch makes other editing NG development/debugging easier.

It also fixes some image failures with EditingNG flag enabled, e.g.
editing/selection/editable-links.html.

Bug: 876555
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng;luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I29968b24872603d999b8fd2301ffd465cac23406
Reviewed-on: https://chromium-review.googlesource.com/1185499
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586309}
parent 6115c73f
......@@ -4,6 +4,9 @@
#include "third_party/blink/renderer/core/paint/ng/ng_box_fragment_painter.h"
#include "third_party/blink/renderer/core/editing/drag_caret.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/layout/background_bleed_avoidance.h"
#include "third_party/blink/renderer/core/layout/hit_test_location.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
......@@ -17,6 +20,7 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_mixin.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/paint/background_image_geometry.h"
#include "third_party/blink/renderer/core/paint/box_decoration_data.h"
#include "third_party/blink/renderer/core/paint/list_marker_painter.h"
......@@ -260,12 +264,25 @@ void NGBoxFragmentPainter::PaintObject(
if (ShouldPaintSelfOutline(paint_phase))
NGFragmentPainter(box_fragment_).PaintOutline(paint_info, paint_offset);
// TODO(layout-dev): Implement once we have selections in LayoutNG.
// If the caret's node's layout object's containing block is this block, and
// If the caret's node's fragment's containing block is this block, and
// the paint action is PaintPhaseForeground, then paint the caret.
// if (paint_phase == PaintPhase::kForeground &&
// box_fragment_.ShouldPaintCarets())
// PaintCarets(paint_info, paint_offset);
if (paint_phase == PaintPhase::kForeground &&
box_fragment_.ShouldPaintCarets())
PaintCarets(paint_info, paint_offset);
}
void NGBoxFragmentPainter::PaintCarets(const PaintInfo& paint_info,
const LayoutPoint& paint_offset) {
LocalFrame* frame = box_fragment_.GetLayoutObject()->GetFrame();
if (box_fragment_.ShouldPaintCursorCaret())
frame->Selection().PaintCaret(paint_info.context, paint_offset);
if (box_fragment_.ShouldPaintDragCaret()) {
frame->GetPage()->GetDragCaret().PaintDragCaret(frame, paint_info.context,
paint_offset);
}
}
void NGBoxFragmentPainter::PaintBlockFlowContents(
......
......@@ -109,6 +109,7 @@ class NGBoxFragmentPainter : public BoxPainterBase {
void PaintSymbol(const NGPaintFragment&,
const PaintInfo&,
const LayoutPoint& paint_offset);
void PaintCarets(const PaintInfo&, const LayoutPoint& paint_offset);
bool IsInSelfHitTestingPhase(HitTestAction) const;
bool VisibleToHitTestRequest(const HitTestRequest&) const;
......
......@@ -695,6 +695,22 @@ Node* NGPaintFragment::NodeForHitTest() const {
return nullptr;
}
bool NGPaintFragment::ShouldPaintCursorCaret() const {
// TODO(xiaochengh): Merge cursor caret painting functions from LayoutBlock to
// FrameSelection.
if (!GetLayoutObject()->IsLayoutBlock())
return false;
return ToLayoutBlock(GetLayoutObject())->ShouldPaintCursorCaret();
}
bool NGPaintFragment::ShouldPaintDragCaret() const {
// TODO(xiaochengh): Merge drag caret painting functions from LayoutBlock to
// DragCaret.
if (!GetLayoutObject()->IsLayoutBlock())
return false;
return ToLayoutBlock(GetLayoutObject())->ShouldPaintDragCaret();
}
// ----
NGPaintFragment& NGPaintFragment::FragmentRange::front() const {
......
......@@ -144,6 +144,14 @@ class CORE_EXPORT NGPaintFragment : public DisplayItemClient,
// from GetNode() when this fragment is content of a pseudo node.
Node* NodeForHitTest() const;
// Utility functions for caret painting. Note that carets are painted as part
// of the containing block's foreground.
bool ShouldPaintCursorCaret() const;
bool ShouldPaintDragCaret() const;
bool ShouldPaintCarets() const {
return ShouldPaintCursorCaret() || ShouldPaintDragCaret();
}
// A range of fragments for |FragmentsFor()|.
class CORE_EXPORT FragmentRange {
public:
......
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