diff options
author | davve <davve@opera.com> | 2015-11-08 08:44:57 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-08 16:46:03 +0000 |
commit | 2bd5bf90d71c251c9cc777ee8b89e3a283f9cb75 (patch) | |
tree | 7c02ebc0bf5c2b709d83ed76bda84e90a9fb9663 | |
parent | 20fa2832b2650a8654bfd8226561046760ebbfc9 (diff) | |
download | chromium_src-2bd5bf90d71c251c9cc777ee8b89e3a283f9cb75.zip chromium_src-2bd5bf90d71c251c9cc777ee8b89e3a283f9cb75.tar.gz chromium_src-2bd5bf90d71c251c9cc777ee8b89e3a283f9cb75.tar.bz2 |
Avoid using ImageResource->imageSize() to get the marker size
In cases when LayoutListMarker represents an image it has a StyleImage
to determine the size of the the marker. Prior to this patch the
computed size is saved back to the StyleImage for later use. This
should be unnecessary since the size can be computed (or saved
locally) when it's actually needed.
When looking closer at one may notice that the zoom level is stored
inside SVGImageForContainer so that SVGImageForContainer::size()
actually returns the size _including zoom_. When LayoutListMarker
asked for the image size and provided zoom, the zoom level was applied
once more resulting in double zoom. The added test exposes this.
As part of 551419, the aim it to get rid of
ImageResource::setContainerSizeForLayoutObject and friends (storing
SVG image specific data inside ImageResource) and this is a step in
that direction.
BUG=551419, 551808
Review URL: https://codereview.chromium.org/1433503003
Cr-Commit-Position: refs/heads/master@{#358552}
3 files changed, 48 insertions, 14 deletions
diff --git a/third_party/WebKit/LayoutTests/svg/as-list-image/svg-list-image-intrinsic-size-zoom.html b/third_party/WebKit/LayoutTests/svg/as-list-image/svg-list-image-intrinsic-size-zoom.html new file mode 100644 index 0000000..7e9f7f5 --- /dev/null +++ b/third_party/WebKit/LayoutTests/svg/as-list-image/svg-list-image-intrinsic-size-zoom.html @@ -0,0 +1,24 @@ +<!DOCTYPE html> +<title>Zoomed SVG in list-style-image</title> +<script src="../../resources/testharness.js"></script> +<script src="../../resources/testharnessreport.js"></script> +<style> + ul { font-family: Ahem; } + ul li { + list-style-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'><rect width='1' height='1' fill='green'/></svg>"); + font-size: 30px; + color: green; + list-style-position: inside; + line-height: 1em; + } +</style> +<ul><li></ul> +<script> + var ul = document.querySelector('ul'); + [ 2, 3, 4, 5, 1].forEach(function(zoom) { + test(function() { + document.body.style.zoom = zoom; + assert_approx_equals(ul.getBoundingClientRect().height, 30, 0.5); + }, 'Zoom to ' + zoom + " and list height should be equal to line-height"); + }); +</script> diff --git a/third_party/WebKit/Source/core/layout/LayoutListMarker.cpp b/third_party/WebKit/Source/core/layout/LayoutListMarker.cpp index f242a0b..f363022 100644 --- a/third_party/WebKit/Source/core/layout/LayoutListMarker.cpp +++ b/third_party/WebKit/Source/core/layout/LayoutListMarker.cpp @@ -65,6 +65,18 @@ LayoutListMarker* LayoutListMarker::createAnonymous(LayoutListItem* item) return layoutObject; } +IntSize LayoutListMarker::imageBulletSize() const +{ + ASSERT(isImage()); + + // FIXME: This is a somewhat arbitrary default width. Generated images for markers really won't + // become particularly useful until we support the CSS3 marker pseudoclass to allow control over + // the width and height of the marker box. + int bulletWidth = style()->fontMetrics().ascent() / 2; + IntSize defaultBulletSize(bulletWidth, bulletWidth); + return calculateImageIntrinsicDimensions(m_image.get(), defaultBulletSize, DoNotScaleByEffectiveZoom); +} + void LayoutListMarker::styleWillChange(StyleDifference diff, const ComputedStyle& newStyle) { if (style() && (newStyle.listStylePosition() != style()->listStylePosition() || newStyle.listStyleType() != style()->listStyleType())) @@ -125,8 +137,9 @@ void LayoutListMarker::layout() if (isImage()) { updateMarginsAndContent(); - setWidth(m_image->imageSize(this, style()->effectiveZoom()).width()); - setHeight(m_image->imageSize(this, style()->effectiveZoom()).height()); + LayoutSize imageSize(imageBulletSize()); + setWidth(imageSize.width()); + setHeight(imageSize.height()); } else { setLogicalWidth(minPreferredLogicalWidth()); setLogicalHeight(style()->fontMetrics().height()); @@ -151,7 +164,8 @@ void LayoutListMarker::imageChanged(WrappedImagePtr o, const IntRect*) if (o != m_image->data()) return; - if (size() != m_image->imageSize(this, style()->effectiveZoom()) || m_image->errorOccurred()) + LayoutSize imageSize = isImage() ? LayoutSize(imageBulletSize()) : LayoutSize(); + if (size() != imageSize || m_image->errorOccurred()) setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalidationReason::ImageChanged); else setShouldDoFullPaintInvalidation(); @@ -172,15 +186,8 @@ void LayoutListMarker::updateContent() m_text = ""; - if (isImage()) { - // FIXME: This is a somewhat arbitrary width. Generated images for markers really won't become particularly useful - // until we support the CSS3 marker pseudoclass to allow control over the width and height of the marker box. - int bulletWidth = style()->fontMetrics().ascent() / 2; - IntSize defaultBulletSize(bulletWidth, bulletWidth); - IntSize imageSize = calculateImageIntrinsicDimensions(m_image.get(), defaultBulletSize, DoNotScaleByEffectiveZoom); - m_image->setContainerSizeForLayoutObject(this, imageSize, style()->effectiveZoom()); + if (isImage()) return; - } switch (listStyleCategory()) { case ListStyleCategory::None: @@ -214,7 +221,7 @@ void LayoutListMarker::computePreferredLogicalWidths() updateContent(); if (isImage()) { - LayoutSize imageSize = m_image->imageSize(this, style()->effectiveZoom()); + LayoutSize imageSize(imageBulletSize()); m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = style()->isHorizontalWritingMode() ? imageSize.width() : imageSize.height(); clearPreferredLogicalWidthsDirty(); updateMargins(); @@ -394,8 +401,10 @@ bool LayoutListMarker::isInside() const IntRect LayoutListMarker::getRelativeMarkerRect() const { - if (isImage()) - return IntRect(0, 0, m_image->imageSize(this, style()->effectiveZoom()).width(), m_image->imageSize(this, style()->effectiveZoom()).height()); + if (isImage()) { + IntSize imageSize = imageBulletSize(); + return IntRect(0, 0, imageSize.width(), imageSize.height()); + } IntRect relativeRect; switch (listStyleCategory()) { diff --git a/third_party/WebKit/Source/core/layout/LayoutListMarker.h b/third_party/WebKit/Source/core/layout/LayoutListMarker.h index 87f4c08..a56de34 100644 --- a/third_party/WebKit/Source/core/layout/LayoutListMarker.h +++ b/third_party/WebKit/Source/core/layout/LayoutListMarker.h @@ -58,6 +58,7 @@ public: bool isImage() const override; const StyleImage* image() const { return m_image.get(); } const LayoutListItem* listItem() const { return m_listItem; } + IntSize imageBulletSize() const; void listItemStyleDidChange(); |