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( ...@@ -178,10 +178,10 @@ PositionWithAffinity LayoutSVGInlineText::PositionForPoint(
SVGInlineTextBox* closest_distance_box = nullptr; SVGInlineTextBox* closest_distance_box = nullptr;
for (InlineTextBox* box : TextBoxes()) { for (InlineTextBox* box : TextBoxes()) {
if (!box->IsSVGInlineTextBox()) auto* text_box = DynamicTo<SVGInlineTextBox>(box);
if (!text_box)
continue; continue;
SVGInlineTextBox* text_box = ToSVGInlineTextBox(box);
for (const SVGTextFragment& fragment : text_box->TextFragments()) { for (const SVGTextFragment& fragment : text_box->TextFragments()) {
FloatRect fragment_rect = fragment.BoundingBox(baseline); FloatRect fragment_rect = fragment.BoundingBox(baseline);
......
...@@ -109,7 +109,12 @@ class SVGInlineTextBox final : public InlineTextBox { ...@@ -109,7 +109,12 @@ class SVGInlineTextBox final : public InlineTextBox {
Vector<SVGTextFragment> text_fragments_; 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 } // namespace blink
......
...@@ -86,8 +86,8 @@ void SVGRootInlineBox::ComputePerCharacterLayoutInformation() { ...@@ -86,8 +86,8 @@ void SVGRootInlineBox::ComputePerCharacterLayoutInformation() {
FloatRect SVGRootInlineBox::LayoutInlineBoxes(InlineBox& box) { FloatRect SVGRootInlineBox::LayoutInlineBoxes(InlineBox& box) {
FloatRect rect; FloatRect rect;
if (box.IsSVGInlineTextBox()) { if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(box)) {
rect = ToSVGInlineTextBox(box).CalculateBoundaries(); rect = svg_inline_text_box->CalculateBoundaries();
} else { } else {
for (InlineBox* child = ToInlineFlowBox(box).FirstChild(); child; for (InlineBox* child = ToInlineFlowBox(box).FirstChild(); child;
child = child->NextOnLine()) child = child->NextOnLine())
...@@ -101,8 +101,8 @@ FloatRect SVGRootInlineBox::LayoutInlineBoxes(InlineBox& box) { ...@@ -101,8 +101,8 @@ FloatRect SVGRootInlineBox::LayoutInlineBoxes(InlineBox& box) {
box.SetX(logical_rect.X()); box.SetX(logical_rect.X());
box.SetY(logical_rect.Y()); box.SetY(logical_rect.Y());
box.SetLogicalWidth(logical_rect.Width()); box.SetLogicalWidth(logical_rect.Width());
if (box.IsSVGInlineTextBox()) if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(box))
ToSVGInlineTextBox(box).SetLogicalHeight(logical_rect.Height()); svg_inline_text_box->SetLogicalHeight(logical_rect.Height());
else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(box)) else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(box))
svg_inline_flow_box->SetLogicalHeight(logical_rect.Height()); svg_inline_flow_box->SetLogicalHeight(logical_rect.Height());
else else
...@@ -170,10 +170,9 @@ static inline void ReverseInlineBoxRangeAndValueListsIfNeeded( ...@@ -170,10 +170,9 @@ static inline void ReverseInlineBoxRangeAndValueListsIfNeeded(
if (first == last || first == --last) if (first == last || first == --last)
return; return;
if ((*last)->IsSVGInlineTextBox() && (*first)->IsSVGInlineTextBox()) { auto* first_text_box = DynamicTo<SVGInlineTextBox>(*first);
SVGInlineTextBox* first_text_box = ToSVGInlineTextBox(*first); auto* last_text_box = DynamicTo<SVGInlineTextBox>(*last);
SVGInlineTextBox* last_text_box = ToSVGInlineTextBox(*last); if (last_text_box && first_text_box) {
// Reordering is only necessary for BiDi text that is _absolutely_ // Reordering is only necessary for BiDi text that is _absolutely_
// positioned. // positioned.
if (first_text_box->Len() == 1 && if (first_text_box->Len() == 1 &&
......
...@@ -493,10 +493,11 @@ static inline void WriteSVGInlineTextBoxes(WTF::TextStream& ts, ...@@ -493,10 +493,11 @@ static inline void WriteSVGInlineTextBoxes(WTF::TextStream& ts,
const LayoutText& text, const LayoutText& text,
int indent) { int indent) {
for (InlineTextBox* box : text.TextBoxes()) { for (InlineTextBox* box : text.TextBoxes()) {
if (!box->IsSVGInlineTextBox()) auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(box);
if (!svg_inline_text_box)
continue; continue;
WriteSVGInlineTextBox(ts, ToSVGInlineTextBox(box), indent); WriteSVGInlineTextBox(ts, svg_inline_text_box, indent);
} }
} }
......
...@@ -263,9 +263,9 @@ void SVGTextLayoutEngine::LayoutCharactersInTextBoxes(InlineFlowBox* start) { ...@@ -263,9 +263,9 @@ void SVGTextLayoutEngine::LayoutCharactersInTextBoxes(InlineFlowBox* start) {
for (InlineBox* child = start->FirstChild(); child; for (InlineBox* child = start->FirstChild(); child;
child = child->NextOnLine()) { child = child->NextOnLine()) {
if (child->IsSVGInlineTextBox()) { if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child)) {
DCHECK(child->GetLineLayoutItem().IsSVGInlineText()); DCHECK(child->GetLineLayoutItem().IsSVGInlineText());
LayoutInlineTextBox(ToSVGInlineTextBox(child)); LayoutInlineTextBox(svg_inline_text_box);
} else { } else {
// Skip generated content. // Skip generated content.
Node* node = child->GetLineLayoutItem().GetNode(); Node* node = child->GetLineLayoutItem().GetNode();
......
...@@ -93,8 +93,8 @@ static void CollectTextBoxesInFlowBox(InlineFlowBox* flow_box, ...@@ -93,8 +93,8 @@ static void CollectTextBoxesInFlowBox(InlineFlowBox* flow_box,
continue; continue;
} }
if (child->IsSVGInlineTextBox()) if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child))
text_boxes.push_back(ToSVGInlineTextBox(child)); text_boxes.push_back(svg_inline_text_box);
} }
} }
...@@ -139,7 +139,7 @@ static void CollectTextBoxesInLogicalOrder( ...@@ -139,7 +139,7 @@ static void CollectTextBoxesInLogicalOrder(
text_boxes.Shrink(0); text_boxes.Shrink(0);
for (InlineTextBox* text_box = text_line_layout.FirstTextBox(); text_box; for (InlineTextBox* text_box = text_line_layout.FirstTextBox(); text_box;
text_box = text_box->NextForSameLayoutObject()) 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(), std::sort(text_boxes.begin(), text_boxes.end(),
InlineTextBox::CompareByStart); InlineTextBox::CompareByStart);
} }
......
...@@ -21,8 +21,8 @@ void SVGInlineFlowBoxPainter::PaintSelectionBackground( ...@@ -21,8 +21,8 @@ void SVGInlineFlowBoxPainter::PaintSelectionBackground(
PaintInfo child_paint_info(paint_info); PaintInfo child_paint_info(paint_info);
for (InlineBox* child = svg_inline_flow_box_.FirstChild(); child; for (InlineBox* child = svg_inline_flow_box_.FirstChild(); child;
child = child->NextOnLine()) { child = child->NextOnLine()) {
if (child->IsSVGInlineTextBox()) if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child))
SVGInlineTextBoxPainter(*ToSVGInlineTextBox(child)) SVGInlineTextBoxPainter(*svg_inline_text_box)
.PaintSelectionBackground(child_paint_info); .PaintSelectionBackground(child_paint_info);
else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(child)) else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(child))
SVGInlineFlowBoxPainter(*svg_inline_flow_box) SVGInlineFlowBoxPainter(*svg_inline_flow_box)
......
...@@ -36,8 +36,8 @@ void SVGRootInlineBoxPainter::Paint(const PaintInfo& paint_info, ...@@ -36,8 +36,8 @@ void SVGRootInlineBoxPainter::Paint(const PaintInfo& paint_info,
paint_info_before_filtering.phase); paint_info_before_filtering.phase);
for (InlineBox* child = svg_root_inline_box_.FirstChild(); child; for (InlineBox* child = svg_root_inline_box_.FirstChild(); child;
child = child->NextOnLine()) { child = child->NextOnLine()) {
if (child->IsSVGInlineTextBox()) if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child))
SVGInlineTextBoxPainter(*ToSVGInlineTextBox(child)) SVGInlineTextBoxPainter(*svg_inline_text_box)
.PaintSelectionBackground(paint_info_before_filtering); .PaintSelectionBackground(paint_info_before_filtering);
else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(child)) else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(child))
SVGInlineFlowBoxPainter(*svg_inline_flow_box) 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