Commit b130efd4 authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

[LayoutNG] Paint spelling/grammar markers

This patch implements painting spelling/grammar markers by
sharing logic from InlineTextBoxPainter.

This patch fixes:
- paint/markers/marker-early-break-bug.html

Bug: 850448
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: I4ebb3c788c614fde25c5fc28d461b089edb57fa9
Reviewed-on: https://chromium-review.googlesource.com/1100669
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567591}
parent 36f8b2f2
......@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_DOCUMENT_MARKER_PAINTER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_DOCUMENT_MARKER_PAINTER_H_
#include "third_party/blink/renderer/core/editing/markers/document_marker.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink {
......@@ -28,6 +29,11 @@ class DocumentMarkerPainter {
const ComputedStyle& style,
const FloatRect& marker_rect,
LayoutUnit logical_height);
static void PaintDocumentMarker(GraphicsContext& context,
const LayoutPoint& box_origin,
const ComputedStyle& style,
DocumentMarker::MarkerType marker_type,
const LayoutRect& local_rect);
};
} // namespace blink
......
......@@ -818,7 +818,6 @@ void InlineTextBoxPainter::PaintDocumentMarker(GraphicsContext& context,
const ComputedStyle& style,
const Font& font,
bool grammar) {
// Never print spelling/grammar markers (5327887)
if (inline_text_box_.GetLineLayoutItem().GetDocument().Printing())
return;
......@@ -861,7 +860,18 @@ void InlineTextBoxPainter::PaintDocumentMarker(GraphicsContext& context,
start = marker_rect.X() - start_point.X();
width = LayoutUnit(marker_rect.Width());
}
DocumentMarkerPainter::PaintDocumentMarker(
context, box_origin, style, marker.GetType(),
LayoutRect(start, LayoutUnit(), width, inline_text_box_.LogicalHeight()));
}
// TODO(yoichio): Move this to document_marker_painter.cc
void DocumentMarkerPainter::PaintDocumentMarker(
GraphicsContext& context,
const LayoutPoint& box_origin,
const ComputedStyle& style,
DocumentMarker::MarkerType marker_type,
const LayoutRect& local_rect) {
// IMPORTANT: The misspelling underline is not considered when calculating the
// text bounds, so we have to make sure to fit within those bounds. This
// means the top pixel(s) of the underline will overlap the bottom pixel(s) of
......@@ -872,28 +882,24 @@ void InlineTextBoxPainter::PaintDocumentMarker(GraphicsContext& context,
// not so good so we pin to two pixels under the baseline.
int line_thickness = kMisspellingLineThickness;
const SimpleFontData* font_data =
inline_text_box_.GetLineLayoutItem()
.Style(inline_text_box_.IsFirstLineStyle())
->GetFont()
.PrimaryFont();
const SimpleFontData* font_data = style.GetFont().PrimaryFont();
DCHECK(font_data);
int baseline = font_data ? font_data->GetFontMetrics().Ascent() : 0;
int descent = (inline_text_box_.LogicalHeight() - baseline).ToInt();
int baseline = font_data->GetFontMetrics().Ascent();
int descent = (local_rect.Height() - baseline).ToInt();
int underline_offset;
if (descent <= (line_thickness + 2)) {
// Place the underline at the very bottom of the text in small/medium fonts.
underline_offset =
(inline_text_box_.LogicalHeight() - line_thickness).ToInt();
underline_offset = (local_rect.Height() - line_thickness).ToInt();
} else {
// In larger fonts, though, place the underline up near the baseline to
// prevent a big gap.
underline_offset = baseline + 2;
}
DrawDocumentMarker(context,
FloatPoint((box_origin.X() + start).ToFloat(),
FloatPoint((box_origin.X() + local_rect.X()).ToFloat(),
(box_origin.Y() + underline_offset).ToFloat()),
width.ToFloat(), marker.GetType(), style.EffectiveZoom());
local_rect.Width().ToFloat(), marker_type,
style.EffectiveZoom());
}
template <InlineTextBoxPainter::PaintOptions options>
......
......@@ -157,8 +157,17 @@ void PaintDocumentMarkers(GraphicsContext& context,
switch (marker->GetType()) {
// TODO(yoichio): Implement following cases
// case DocumentMarker::kSpelling:
// case DocumentMarker::kGrammar:
case DocumentMarker::kSpelling:
case DocumentMarker::kGrammar: {
if (context.Printing())
return;
if (marker_paint_phase == DocumentMarkerPaintPhase::kBackground)
continue;
DocumentMarkerPainter::PaintDocumentMarker(
context, box_origin, style, marker->GetType(),
text_fragment.LocalRect(paint_start_offset, paint_end_offset)
.ToLayoutRect());
} break;
// case DocumentMarker::kTextMatch:
case DocumentMarker::kComposition:
case DocumentMarker::kActiveSuggestion:
......
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