Commit 14138953 authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Use new downcast helper for blink::SVGInlineTextBox

This CL has goal to use To<SVGInlineTextBox> and
DynamicTo<SVGInlineTextBox> as new downcast helper.

Bug: 891908
Change-Id: I56fcdaf41d98eec44e91f73f20542d513bed1f5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2020002Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#736394}
parent 87ed2e67
......@@ -178,10 +178,10 @@ PositionWithAffinity LayoutSVGInlineText::PositionForPoint(
SVGInlineTextBox* closest_distance_box = nullptr;
for (InlineTextBox* box : TextBoxes()) {
if (!box->IsSVGInlineTextBox())
auto* text_box = DynamicTo<SVGInlineTextBox>(box);
if (!text_box)
continue;
SVGInlineTextBox* text_box = ToSVGInlineTextBox(box);
for (const SVGTextFragment& fragment : text_box->TextFragments()) {
FloatRect fragment_rect = fragment.BoundingBox(baseline);
......
......@@ -109,7 +109,12 @@ class SVGInlineTextBox final : public InlineTextBox {
Vector<SVGTextFragment> text_fragments_;
};
DEFINE_INLINE_BOX_TYPE_CASTS(SVGInlineTextBox);
template <>
struct DowncastTraits<SVGInlineTextBox> {
static bool AllowFrom(const InlineBox& box) {
return box.IsSVGInlineTextBox();
}
};
} // namespace blink
......
......@@ -86,8 +86,8 @@ void SVGRootInlineBox::ComputePerCharacterLayoutInformation() {
FloatRect SVGRootInlineBox::LayoutInlineBoxes(InlineBox& box) {
FloatRect rect;
if (box.IsSVGInlineTextBox()) {
rect = ToSVGInlineTextBox(box).CalculateBoundaries();
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(box)) {
rect = svg_inline_text_box->CalculateBoundaries();
} else {
for (InlineBox* child = ToInlineFlowBox(box).FirstChild(); child;
child = child->NextOnLine())
......@@ -101,8 +101,8 @@ FloatRect SVGRootInlineBox::LayoutInlineBoxes(InlineBox& box) {
box.SetX(logical_rect.X());
box.SetY(logical_rect.Y());
box.SetLogicalWidth(logical_rect.Width());
if (box.IsSVGInlineTextBox())
ToSVGInlineTextBox(box).SetLogicalHeight(logical_rect.Height());
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(box))
svg_inline_text_box->SetLogicalHeight(logical_rect.Height());
else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(box))
svg_inline_flow_box->SetLogicalHeight(logical_rect.Height());
else
......@@ -170,10 +170,9 @@ static inline void ReverseInlineBoxRangeAndValueListsIfNeeded(
if (first == last || first == --last)
return;
if ((*last)->IsSVGInlineTextBox() && (*first)->IsSVGInlineTextBox()) {
SVGInlineTextBox* first_text_box = ToSVGInlineTextBox(*first);
SVGInlineTextBox* last_text_box = ToSVGInlineTextBox(*last);
auto* first_text_box = DynamicTo<SVGInlineTextBox>(*first);
auto* last_text_box = DynamicTo<SVGInlineTextBox>(*last);
if (last_text_box && first_text_box) {
// Reordering is only necessary for BiDi text that is _absolutely_
// positioned.
if (first_text_box->Len() == 1 &&
......
......@@ -493,10 +493,11 @@ static inline void WriteSVGInlineTextBoxes(WTF::TextStream& ts,
const LayoutText& text,
int indent) {
for (InlineTextBox* box : text.TextBoxes()) {
if (!box->IsSVGInlineTextBox())
auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(box);
if (!svg_inline_text_box)
continue;
WriteSVGInlineTextBox(ts, ToSVGInlineTextBox(box), indent);
WriteSVGInlineTextBox(ts, svg_inline_text_box, indent);
}
}
......
......@@ -263,9 +263,9 @@ void SVGTextLayoutEngine::LayoutCharactersInTextBoxes(InlineFlowBox* start) {
for (InlineBox* child = start->FirstChild(); child;
child = child->NextOnLine()) {
if (child->IsSVGInlineTextBox()) {
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child)) {
DCHECK(child->GetLineLayoutItem().IsSVGInlineText());
LayoutInlineTextBox(ToSVGInlineTextBox(child));
LayoutInlineTextBox(svg_inline_text_box);
} else {
// Skip generated content.
Node* node = child->GetLineLayoutItem().GetNode();
......
......@@ -93,8 +93,8 @@ static void CollectTextBoxesInFlowBox(InlineFlowBox* flow_box,
continue;
}
if (child->IsSVGInlineTextBox())
text_boxes.push_back(ToSVGInlineTextBox(child));
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child))
text_boxes.push_back(svg_inline_text_box);
}
}
......@@ -139,7 +139,7 @@ static void CollectTextBoxesInLogicalOrder(
text_boxes.Shrink(0);
for (InlineTextBox* text_box = text_line_layout.FirstTextBox(); text_box;
text_box = text_box->NextForSameLayoutObject())
text_boxes.push_back(ToSVGInlineTextBox(text_box));
text_boxes.push_back(To<SVGInlineTextBox>(text_box));
std::sort(text_boxes.begin(), text_boxes.end(),
InlineTextBox::CompareByStart);
}
......
......@@ -21,8 +21,8 @@ void SVGInlineFlowBoxPainter::PaintSelectionBackground(
PaintInfo child_paint_info(paint_info);
for (InlineBox* child = svg_inline_flow_box_.FirstChild(); child;
child = child->NextOnLine()) {
if (child->IsSVGInlineTextBox())
SVGInlineTextBoxPainter(*ToSVGInlineTextBox(child))
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child))
SVGInlineTextBoxPainter(*svg_inline_text_box)
.PaintSelectionBackground(child_paint_info);
else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(child))
SVGInlineFlowBoxPainter(*svg_inline_flow_box)
......
......@@ -36,8 +36,8 @@ void SVGRootInlineBoxPainter::Paint(const PaintInfo& paint_info,
paint_info_before_filtering.phase);
for (InlineBox* child = svg_root_inline_box_.FirstChild(); child;
child = child->NextOnLine()) {
if (child->IsSVGInlineTextBox())
SVGInlineTextBoxPainter(*ToSVGInlineTextBox(child))
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child))
SVGInlineTextBoxPainter(*svg_inline_text_box)
.PaintSelectionBackground(paint_info_before_filtering);
else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(child))
SVGInlineFlowBoxPainter(*svg_inline_flow_box)
......
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