Commit f5e1a945 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Clean up and simplify SVGContentContainer::UpdateBoundingBoxes()

Replace VisualRectInLocalSVGCoordinates() with StrokeBoundingBox()
since they are now returning the same value. Drop the out-of-date
comment for the same reason.
This also means that the special treatment of containers can also be
simplified to just consider if the object bounding box is valid.

Bug: 1028061
Change-Id: Ic0bcdc5376f253980dbf2448a5ad6330fea414b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2517527Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#824122}
parent d21882f2
...@@ -111,67 +111,50 @@ bool SVGContentContainer::HitTest(HitTestResult& result, ...@@ -111,67 +111,50 @@ bool SVGContentContainer::HitTest(HitTestResult& result,
// box. // box.
static inline void UpdateObjectBoundingBox(FloatRect& object_bounding_box, static inline void UpdateObjectBoundingBox(FloatRect& object_bounding_box,
bool& object_bounding_box_valid, bool& object_bounding_box_valid,
LayoutObject* other,
FloatRect other_bounding_box) { FloatRect other_bounding_box) {
auto* svg_container = DynamicTo<LayoutSVGContainer>(other);
bool other_valid =
svg_container ? svg_container->IsObjectBoundingBoxValid() : true;
if (!other_valid)
return;
if (!object_bounding_box_valid) { if (!object_bounding_box_valid) {
object_bounding_box = other_bounding_box; object_bounding_box = other_bounding_box;
object_bounding_box_valid = true; object_bounding_box_valid = true;
return; return;
} }
object_bounding_box.UniteEvenIfEmpty(other_bounding_box); object_bounding_box.UniteEvenIfEmpty(other_bounding_box);
} }
static bool HasValidBoundingBoxForContainer(const LayoutObject* object) { static bool HasValidBoundingBoxForContainer(const LayoutObject& object) {
if (object->IsSVGShape()) if (object.IsSVGShape())
return !ToLayoutSVGShape(object)->IsShapeEmpty(); return !ToLayoutSVGShape(object).IsShapeEmpty();
if (object->IsSVGText()) if (object.IsSVGText())
return ToLayoutSVGText(object)->IsObjectBoundingBoxValid(); return ToLayoutSVGText(object).IsObjectBoundingBoxValid();
if (object->IsSVGHiddenContainer()) if (auto* svg_container = DynamicTo<LayoutSVGContainer>(object)) {
return false; return svg_container->IsObjectBoundingBoxValid() &&
!svg_container->IsSVGHiddenContainer();
}
if (auto* foreign_object = DynamicTo<LayoutSVGForeignObject>(object)) if (auto* foreign_object = DynamicTo<LayoutSVGForeignObject>(object))
return foreign_object->IsObjectBoundingBoxValid(); return foreign_object->IsObjectBoundingBoxValid();
if (object->IsSVGImage()) if (object.IsSVGImage())
return ToLayoutSVGImage(object)->IsObjectBoundingBoxValid(); return ToLayoutSVGImage(object).IsObjectBoundingBoxValid();
// TODO(fs): Can we refactor this code to include the container case return false;
// in a more natural way?
return true;
} }
bool SVGContentContainer::UpdateBoundingBoxes(bool& object_bounding_box_valid) { bool SVGContentContainer::UpdateBoundingBoxes(bool& object_bounding_box_valid) {
object_bounding_box_valid = false; object_bounding_box_valid = false;
// When computing the strokeBoundingBox, we use the visualRects of
// the container's children so that the container's stroke includes the
// resources applied to the children (such as clips and filters). This allows
// filters applied to containers to correctly bound the children, and also
// improves inlining of SVG content, as the stroke bound is used in that
// situation also.
FloatRect object_bounding_box; FloatRect object_bounding_box;
FloatRect stroke_bounding_box; FloatRect stroke_bounding_box;
for (LayoutObject* current = children_.FirstChild(); current; for (LayoutObject* current = children_.FirstChild(); current;
current = current->NextSibling()) { current = current->NextSibling()) {
// Don't include elements that are not rendered in the union. // Don't include elements that are not rendered.
if (!HasValidBoundingBoxForContainer(current)) if (!HasValidBoundingBoxForContainer(*current))
continue; continue;
const AffineTransform& transform = current->LocalToSVGParentTransform(); const AffineTransform& transform = current->LocalToSVGParentTransform();
UpdateObjectBoundingBox(object_bounding_box, object_bounding_box_valid, UpdateObjectBoundingBox(object_bounding_box, object_bounding_box_valid,
current,
transform.MapRect(current->ObjectBoundingBox())); transform.MapRect(current->ObjectBoundingBox()));
stroke_bounding_box.Unite( stroke_bounding_box.Unite(transform.MapRect(current->StrokeBoundingBox()));
transform.MapRect(current->VisualRectInLocalSVGCoordinates()));
} }
bool changed = false; bool changed = false;
......
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