Skip to content

Commit

Permalink
Use new downcast helper for LayoutBoxModelObject and LayoutBox in cor…
Browse files Browse the repository at this point in the history
…e/[f-km-z]*/

* Add MainThreadScrollingReasonsTest::GetScrollableArea() and
  RootScrollerTest::GetScrollableArea() to reduce the number of casts to
  LayoutBoxModelObject.

This CL has no behavior changes.

Bug: 891908
Change-Id: I10d52bff1b228d54f67b7585b0e6c8ff3ba7a51b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2531800
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826574}
  • Loading branch information
tkent-google authored and Commit Bot committed Nov 12, 2020
1 parent 0de19bf commit b5eac01
Show file tree
Hide file tree
Showing 30 changed files with 101 additions and 122 deletions.
19 changes: 10 additions & 9 deletions third_party/blink/renderer/core/frame/local_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ bool LocalFrameView::LayoutFromRootObject(LayoutObject& root) {
}
}

ToLayoutBox(root).LayoutSubtreeRoot();
To<LayoutBox>(root).LayoutSubtreeRoot();
return true;
}

Expand Down Expand Up @@ -1117,7 +1117,7 @@ void LocalFrameView::RunIntersectionObserverSteps() {
// Report the main frame's document intersection with itself.
LayoutObject* layout_object = GetLayoutView();
IntRect main_frame_dimensions =
ToLayoutBox(layout_object)->PixelSnappedLayoutOverflowRect();
To<LayoutBox>(layout_object)->PixelSnappedLayoutOverflowRect();
GetFrame().Client()->OnMainFrameIntersectionChanged(WebRect(
0, 0, main_frame_dimensions.Width(), main_frame_dimensions.Height()));
}
Expand Down Expand Up @@ -1284,7 +1284,7 @@ bool LocalFrameView::RequiresMainThreadScrollingForBackgroundAttachmentFixed()
return true;

const auto* object =
ToLayoutBoxModelObject(*background_attachment_fixed_objects_.begin());
To<LayoutBoxModelObject>(*background_attachment_fixed_objects_.begin());
// We should not add such object in the set.
DCHECK(!object->BackgroundTransfersToView());
// If the background is viewport background and it paints onto the main
Expand Down Expand Up @@ -1435,7 +1435,7 @@ bool LocalFrameView::InvalidateViewportConstrainedObjects() {
DCHECK(layout_object->StyleRef().HasViewportConstrainedPosition() ||
layout_object->StyleRef().HasStickyConstrainedPosition());
DCHECK(layout_object->HasLayer());
PaintLayer* layer = ToLayoutBoxModelObject(layout_object)->Layer();
PaintLayer* layer = To<LayoutBoxModelObject>(layout_object)->Layer();

if (!RuntimeEnabledFeatures::CompositeAfterPaintEnabled()) {
DisableCompositingQueryAsserts disabler;
Expand Down Expand Up @@ -1628,10 +1628,10 @@ static inline void RemoveFloatingObjectsForSubtreeRoot(LayoutObject& root) {
}

static bool PrepareOrthogonalWritingModeRootForLayout(LayoutObject& root) {
DCHECK(root.IsBox() && ToLayoutBox(root).IsOrthogonalWritingModeRoot());
DCHECK(To<LayoutBox>(root).IsOrthogonalWritingModeRoot());
if (!root.NeedsLayout() || root.IsOutOfFlowPositioned() ||
root.IsColumnSpanAll() || root.StyleRef().LogicalHeight().IsSpecified() ||
ToLayoutBox(root).IsGridItem() || root.IsTablePart())
To<LayoutBox>(root).IsGridItem() || root.IsTablePart())
return false;

if (RuntimeEnabledFeatures::LayoutNGEnabled()) {
Expand All @@ -1646,7 +1646,7 @@ static bool PrepareOrthogonalWritingModeRootForLayout(LayoutObject& root) {
// which called |RunLegacyLayout()|. This parent not only needs to run
// pre-layout, but also clearing |NeedsLayout()| without updating
// |CachedLayoutResult| is harmful.
if (const auto* box = ToLayoutBoxOrNull(&root)) {
if (const auto* box = DynamicTo<LayoutBox>(root)) {
if (box->GetCachedLayoutResult())
return false;
}
Expand Down Expand Up @@ -4556,10 +4556,11 @@ bool LocalFrameView::HasVisibleSlowRepaintViewportConstrainedObjects() const {
if (!ViewportConstrainedObjects())
return false;
for (const LayoutObject* layout_object : *ViewportConstrainedObjects()) {
DCHECK(layout_object->IsBoxModelObject() && layout_object->HasLayer());
DCHECK(layout_object->HasLayer());
DCHECK(layout_object->StyleRef().GetPosition() == EPosition::kFixed ||
layout_object->StyleRef().GetPosition() == EPosition::kSticky);
if (ToLayoutBoxModelObject(layout_object)->IsSlowRepaintConstrainedObject())
if (To<LayoutBoxModelObject>(layout_object)
->IsSlowRepaintConstrainedObject())
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ TEST_F(LocalFrameViewTest,
<div class='container'><div id='sticky'></div></div>
)HTML");

LayoutBoxModelObject* sticky = ToLayoutBoxModelObject(
GetDocument().getElementById("sticky")->GetLayoutObject());
auto* sticky = To<LayoutBoxModelObject>(GetLayoutObjectByElementId("sticky"));

// Deliberately invalidate the ancestor overflow layer. This approximates
// http://crbug.com/696173, in which the ancestor overflow layer can be null
Expand Down
22 changes: 11 additions & 11 deletions third_party/blink/renderer/core/frame/web_frame_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7935,8 +7935,8 @@ TEST_F(WebFrameTest, FullscreenLayerSize) {
EXPECT_EQ(div_fullscreen, Fullscreen::FullscreenElementFrom(*document));

// Verify that the element is sized to the viewport.
LayoutBox* fullscreen_layout_object =
ToLayoutBox(div_fullscreen->GetLayoutObject());
auto* fullscreen_layout_object =
To<LayoutBox>(div_fullscreen->GetLayoutObject());
EXPECT_EQ(viewport_width, fullscreen_layout_object->LogicalWidth().ToInt());
EXPECT_EQ(viewport_height, fullscreen_layout_object->LogicalHeight().ToInt());

Expand Down Expand Up @@ -8088,8 +8088,8 @@ TEST_F(WebFrameTest, FullscreenSubframe) {
UpdateAllLifecyclePhases(web_view_impl);

// Verify that the element is sized to the viewport.
LayoutBox* fullscreen_layout_object =
ToLayoutBox(div_fullscreen->GetLayoutObject());
auto* fullscreen_layout_object =
To<LayoutBox>(div_fullscreen->GetLayoutObject());
EXPECT_EQ(viewport_width, fullscreen_layout_object->LogicalWidth().ToInt());
EXPECT_EQ(viewport_height, fullscreen_layout_object->LogicalHeight().ToInt());

Expand Down Expand Up @@ -8506,7 +8506,7 @@ TEST_F(WebFrameTest, WebXrImmersiveOverlay) {
SK_AlphaTRANSPARENT);

GraphicsLayer* inner_layer =
ToLayoutBoxModelObject(
To<LayoutBoxModelObject>(
frame->GetDocument()->getElementById("inner")->GetLayoutObject())
->Layer()
->GetCompositedLayerMapping()
Expand Down Expand Up @@ -8546,12 +8546,12 @@ TEST_F(WebFrameTest, LayoutBlockPercentHeightDescendants) {
Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument();
LayoutBlock* container =
To<LayoutBlock>(document->getElementById("container")->GetLayoutObject());
LayoutBox* percent_height_in_anonymous =
ToLayoutBox(document->getElementById("percent-height-in-anonymous")
->GetLayoutObject());
LayoutBox* percent_height_direct_child =
ToLayoutBox(document->getElementById("percent-height-direct-child")
->GetLayoutObject());
auto* percent_height_in_anonymous =
To<LayoutBox>(document->getElementById("percent-height-in-anonymous")
->GetLayoutObject());
auto* percent_height_direct_child =
To<LayoutBox>(document->getElementById("percent-height-direct-child")
->GetLayoutObject());

EXPECT_TRUE(
container->HasPercentHeightDescendant(percent_height_in_anonymous));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ viz::FrameSinkId GetRemoteFrameSinkId(const HitTestResult& result) {
return viz::FrameSinkId();

IntPoint local_point = RoundedIntPoint(result.LocalPoint());
if (!ToLayoutBox(object)->ComputedCSSContentBoxRect().Contains(local_point))
if (!To<LayoutBox>(object)->ComputedCSSContentBoxRect().Contains(local_point))
return viz::FrameSinkId();

return remote_frame->GetFrameSinkId();
Expand Down Expand Up @@ -461,10 +461,8 @@ viz::FrameSinkId WebFrameWidgetBase::GetFrameSinkIdAtPoint(
if (remote_frame_sink_id.is_valid()) {
FloatPoint local_point = FloatPoint(result.LocalPoint());
LayoutObject* object = result.GetLayoutObject();
if (object->IsBox()) {
LayoutBox* box = ToLayoutBox(object);
if (auto* box = DynamicTo<LayoutBox>(object))
local_point.MoveBy(-FloatPoint(box->PhysicalContentBoxOffset()));
}

*local_point_in_dips =
widget_base_->BlinkSpaceToDIPs(gfx::PointF(local_point));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ TEST_F(HTMLCanvasElementTest, CreateLayerUpdatesCompositing) {

SetBodyInnerHTML("<canvas id='canvas'></canvas>");
auto* canvas = To<HTMLCanvasElement>(GetDocument().getElementById("canvas"));
auto* layer = ToLayoutBoxModelObject(canvas->GetLayoutObject())->Layer();
auto* layer = GetPaintLayerByElementId("canvas");
ASSERT_TRUE(layer);
EXPECT_EQ(CompositingReason::kNone, layer->DirectCompositingReasons());

EXPECT_FALSE(layer->NeedsCompositingInputsUpdate());
canvas->CreateLayer();
EXPECT_TRUE(layer->NeedsCompositingInputsUpdate());
UpdateAllLifecyclePhasesForTest();
ASSERT_EQ(layer, ToLayoutBoxModelObject(canvas->GetLayoutObject())->Layer());
ASSERT_EQ(layer,
To<LayoutBoxModelObject>(canvas->GetLayoutObject())->Layer());
EXPECT_EQ(CompositingReason::kCanvas, layer->DirectCompositingReasons());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ bool ExternalPopupMenu::ShowInternal() {
LayoutObject* layout_object = owner_element_->GetLayoutObject();
if (!layout_object || !layout_object->IsBox())
return false;
auto* box = To<LayoutBox>(layout_object);
IntRect rect = EnclosingIntRect(
ToLayoutBox(layout_object)
->LocalToAbsoluteRect(
ToLayoutBox(layout_object)->PhysicalBorderBoxRect()));
box->LocalToAbsoluteRect(box->PhysicalBorderBoxRect()));
IntRect rect_in_viewport = local_frame_->View()->FrameToViewport(rect);
float scale_for_emulation = WebLocalFrameImpl::FromFrame(local_frame_)
->LocalRootFrameWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ LayoutBox* HTMLFieldSetElement::GetLayoutBoxForScrolling() const {
return HTMLFormControlElement::GetLayoutBoxForScrolling();
LayoutObject* child = layout_box->SlowFirstChild();
if (child && child->IsAnonymous())
return ToLayoutBox(child);
return To<LayoutBox>(child);
return HTMLFormControlElement::GetLayoutBoxForScrolling();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void SliderThumbElement::SetPositionFromPoint(const LayoutPoint& point) {
LayoutUnit track_size;
LayoutUnit position;
LayoutUnit current_position;
const LayoutBox* input_box = ToLayoutBox(input_object);
const auto* input_box = To<LayoutBox>(input_object);
PhysicalOffset thumb_offset =
thumb_box->LocalToAncestorPoint(PhysicalOffset(), input_box) -
track_box->LocalToAncestorPoint(PhysicalOffset(), input_box);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static void AppendServerMapMousePosition(StringBuilder& url, Event* event) {
// The origin (0,0) is at the upper left of the content area, inside the
// padding and border.
map_point -=
FloatSize(ToLayoutBox(layout_object)->PhysicalContentBoxOffset());
FloatSize(To<LayoutBox>(layout_object)->PhysicalContentBoxOffset());

// CSS zoom is not reflected in the map coordinates.
float scale_factor = 1 / layout_object->Style()->EffectiveZoom();
Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/renderer/core/html/html_area_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ Path HTMLAreaElement::GetPath(const LayoutObject* container_object) const {
Path path;
// No need to zoom because it is already applied in
// containerObject->borderBoxRect().
if (container_object->IsBox())
path.AddRect(FloatRect(ToLayoutBox(container_object)->BorderBoxRect()));
if (const auto* box = DynamicTo<LayoutBox>(container_object))
path.AddRect(FloatRect(box->BorderBoxRect()));
path_ = nullptr;
return path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ TEST_F(HTMLVideoElementTest, ChangeLayerNeedsCompositingUpdate) {
SetFakeCcLayer(layer1.get());
ASSERT_TRUE(video()->GetLayoutObject()->HasLayer());
auto* paint_layer =
ToLayoutBoxModelObject(video()->GetLayoutObject())->Layer();
To<LayoutBoxModelObject>(video()->GetLayoutObject())->Layer();
EXPECT_TRUE(paint_layer->NeedsCompositingInputsUpdate());
UpdateAllLifecyclePhasesForTest();
EXPECT_FALSE(paint_layer->NeedsCompositingInputsUpdate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void TextTrackContainer::UpdateDefaultFontSize(
// for lack of per-spec vh/vw support) but the whole media element is used
// for cue rendering. This is inconsistent. See also the somewhat related
// spec bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28105
LayoutSize video_size = ToLayoutBox(media_layout_object)->ContentSize();
LayoutSize video_size = To<LayoutBox>(media_layout_object)->ContentSize();
LayoutUnit smallest_dimension =
std::min(video_size.Height(), video_size.Width());
float font_size = smallest_dimension * 0.05f;
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/input/scroll_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ bool ScrollManager::LogicalScroll(mojom::blink::ScrollDirection direction,
Node* scroll_chain_node = DOMNodeIds::NodeForId(scroll_chain.TakeLast());
DCHECK(scroll_chain_node);

LayoutBox* box = ToLayoutBox(scroll_chain_node->GetLayoutObject());
auto* box = To<LayoutBox>(scroll_chain_node->GetLayoutObject());
DCHECK(box);

ScrollDirectionPhysical physical_direction =
Expand Down
14 changes: 6 additions & 8 deletions third_party/blink/renderer/core/inspector/inspector_highlight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ const ShapeOutsideInfo* ShapeOutsideInfoForNode(Node* node,
FloatQuad* bounds) {
LayoutObject* layout_object = node->GetLayoutObject();
if (!layout_object || !layout_object->IsBox() ||
!ToLayoutBox(layout_object)->GetShapeOutsideInfo())
!To<LayoutBox>(layout_object)->GetShapeOutsideInfo())
return nullptr;

LocalFrameView* containing_view = node->GetDocument().View();
LayoutBox* layout_box = ToLayoutBox(layout_object);
auto* layout_box = To<LayoutBox>(layout_object);
const ShapeOutsideInfo* shape_outside_info =
layout_box->GetShapeOutsideInfo();

Expand Down Expand Up @@ -847,7 +847,7 @@ Vector<Vector<PhysicalRect>> GetFlexLinesAndItems(LayoutBox* layout_box,
PhysicalOffset fragment_offset = child.Offset();

const LayoutObject* object = child_fragment->GetLayoutObject();
const LayoutBox* box = ToLayoutBox(object);
const auto* box = To<LayoutBox>(object);
PhysicalRect item_rect =
PhysicalRect(fragment_offset.left - box->MarginLeft(),
fragment_offset.top - box->MarginTop(),
Expand Down Expand Up @@ -878,7 +878,7 @@ std::unique_ptr<protocol::DictionaryValue> BuildFlexInfo(
float scale) {
LocalFrameView* containing_view = node->GetDocument().View();
LayoutObject* layout_object = node->GetLayoutObject();
LayoutBox* layout_box = ToLayoutBox(layout_object);
auto* layout_box = To<LayoutBox>(layout_object);
DCHECK(layout_object);
bool is_horizontal = IsHorizontalFlex(layout_object);

Expand Down Expand Up @@ -1247,7 +1247,7 @@ bool InspectorHighlightBase::BuildNodeQuads(Node* node,
border_box = text_rect;
margin_box = text_rect;
} else if (layout_object->IsBox()) {
LayoutBox* layout_box = ToLayoutBox(layout_object);
auto* layout_box = To<LayoutBox>(layout_object);
content_box = layout_box->PhysicalContentBoxRect();

// Include scrollbars and gutters in the padding highlight.
Expand Down Expand Up @@ -1661,9 +1661,7 @@ bool InspectorHighlight::GetBoxModel(

IntRect bounding_box =
view->ConvertToRootFrame(layout_object->AbsoluteBoundingBoxRect());
LayoutBoxModelObject* model_object =
layout_object->IsBoxModelObject() ? ToLayoutBoxModelObject(layout_object)
: nullptr;
auto* model_object = DynamicTo<LayoutBoxModelObject>(layout_object);

*model =
protocol::DOM::BoxModel::create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ PhysicalRect InitializeRootRect(const LayoutObject* root,
// we can zoom out to fit the entire element width.
result = layout_view->OverflowClipRect(PhysicalOffset());
} else if (root->IsBox() && root->IsScrollContainer()) {
result = ToLayoutBox(root)->PhysicalContentBoxRect();
result = To<LayoutBox>(root)->PhysicalContentBoxRect();
} else {
result = PhysicalRect(ToLayoutBoxModelObject(root)->BorderBoundingBox());
result = PhysicalRect(To<LayoutBoxModelObject>(root)->BorderBoundingBox());
}
ApplyMargin(result, margin, root->StyleRef().EffectiveZoom());
return result;
Expand All @@ -107,7 +107,7 @@ PhysicalRect InitializeTargetRect(const LayoutObject* target,
target->IsLayoutEmbeddedContent()) {
result = To<LayoutEmbeddedContent>(target)->ReplacedContentRect();
} else if (target->IsBox()) {
result = PhysicalRect(ToLayoutBoxModelObject(target)->BorderBoundingBox());
result = PhysicalRect(To<LayoutBox>(target)->BorderBoundingBox());
} else if (target->IsLayoutInline()) {
result = target->AbsoluteToLocalRect(
PhysicalRect::EnclosingRect(target->AbsoluteBoundingBoxFloatRect()));
Expand Down Expand Up @@ -446,7 +446,7 @@ bool IntersectionGeometry::ClipToRoot(const LayoutObject* root,
// TODO(szager): the writing mode flipping needs a test.
const LayoutBox* local_ancestor = nullptr;
if (!RootIsImplicit() || root->GetDocument().IsInMainFrame())
local_ancestor = ToLayoutBox(root);
local_ancestor = To<LayoutBox>(root);

unsigned flags = kDefaultVisualRectFlags | kEdgeInclusive |
kDontApplyMainFrameOverflowClip;
Expand Down
11 changes: 3 additions & 8 deletions third_party/blink/renderer/core/page/autoscroll_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ void AutoscrollController::StartAutoscrollForSelection(
if (!scrollable)
return;

pressed_layout_object_ = layout_object && layout_object->IsBox()
? ToLayoutBox(layout_object)
: nullptr;
pressed_layout_object_ = DynamicTo<LayoutBox>(layout_object);
autoscroll_type_ = kAutoscrollForSelection;
autoscroll_layout_object_ = scrollable;
ScheduleMainThreadAnimation();
Expand Down Expand Up @@ -158,13 +156,10 @@ void AutoscrollController::UpdateAutoscrollLayoutObject() {
LayoutObject* layout_object = autoscroll_layout_object_;

while (layout_object && !(layout_object->IsBox() &&
ToLayoutBox(layout_object)->CanAutoscroll()))
To<LayoutBox>(layout_object)->CanAutoscroll()))
layout_object = layout_object->Parent();

autoscroll_layout_object_ = layout_object && layout_object->IsBox()
? ToLayoutBox(layout_object)
: nullptr;

autoscroll_layout_object_ = DynamicTo<LayoutBox>(layout_object);
if (!autoscroll_layout_object_)
autoscroll_type_ = kNoAutoscroll;
}
Expand Down
4 changes: 1 addition & 3 deletions third_party/blink/renderer/core/page/print_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ namespace {
LayoutBoxModelObject* EnclosingBoxModelObject(LayoutObject* object) {
while (object && !object->IsBoxModelObject())
object = object->Parent();
if (!object)
return nullptr;
return ToLayoutBoxModelObject(object);
return To<LayoutBoxModelObject>(object);
}

bool IsCoordinateInPage(int top, int left, const IntRect& page) {
Expand Down
Loading

0 comments on commit b5eac01

Please sign in to comment.