Skip to content
Permalink
Browse files
Update LayoutUnit usage in descendants of RenderReplaced
https://bugs.webkit.org/show_bug.cgi?id=80918

Reviewed by Eric Seidel.

Replaced elements have to flow in the new sub-pixel Render Tree, but since the rendering of these
often takes place outside of WebCore (or in cases such as foreign objects, in WebCore after
passing through platform code), care must be taken to determine the final rendered size and
location before render time. This patch brings these classes up to the latest and greatest in the
subpixellayout branch.

See https://trac.webkit.org/wiki/LayoutUnit for more information.

No new tests. No change in behavior.

* rendering/RenderFrameBase.cpp:
(WebCore::RenderFrameBase::layoutWithFlattening): Build Fix.
* rendering/RenderFullScreen.cpp:
(RenderFullScreen::createPlaceholder): Ditto.
* rendering/RenderFullScreen.h:
(RenderFullScreen): Ditto.
* rendering/RenderHTMLCanvas.cpp:
(WebCore::RenderHTMLCanvas::canvasSizeChanged): Ditto.
* rendering/RenderIFrame.cpp:
(WebCore::RenderIFrame::computeLogicalHeight): Ditto.
(WebCore::RenderIFrame::computeLogicalWidth): Ditto.
* rendering/RenderImage.cpp:
(WebCore::RenderImage::updateIntrinsicSizeIfNeeded): Intrinsic sizes are always integers, since they
originate outside of WebCore.
(WebCore::RenderImage::paintIntoRect): Use pixel snapping to paint into an arbitrary rect.
(WebCore::RenderImage::computeReplacedLogicalWidth): Intrinsic size is always integral -- rounding
values to integers.
* rendering/RenderImage.h:
(RenderImage):
* rendering/RenderVideo.cpp:
(WebCore::RenderVideo::videoBox):
(WebCore::RenderVideo::paintReplaced): Painting at integer boundaries.
* rendering/RenderWidget.cpp:
(WebCore):
(WebCore::roundedIntRect): Widgets are rendered outside of WebCore, so we always align them to
integer boundaries. This means we can actually round the size of our ultimate content box. This
function is implemented here specifically to prevent its misuse if we put it elsewhere.
(WebCore::RenderWidget::setWidgetGeometry): We simplify layout by taking a LayoutRect and rounding
it to its final location within this function.
(WebCore::RenderWidget::updateWidgetGeometry): We keep things in LayoutUnits until handing off to
setWidgetGeometry.
(WebCore::RenderWidget::paint): Rounding the paint location before handing painting off to the
widget itself.
* rendering/RenderWidget.h:
(RenderWidget):


Canonical link: https://commits.webkit.org/99018@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@111515 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
leviw committed Mar 21, 2012
1 parent dadf12e commit 1f11b564fd1707ee066010e0ce30ef196c040bc2
Showing 11 changed files with 91 additions and 28 deletions.
@@ -1,3 +1,56 @@
2012-03-21 Levi Weintraub <leviw@chromium.org>

Update LayoutUnit usage in descendants of RenderReplaced
https://bugs.webkit.org/show_bug.cgi?id=80918

Reviewed by Eric Seidel.

Replaced elements have to flow in the new sub-pixel Render Tree, but since the rendering of these
often takes place outside of WebCore (or in cases such as foreign objects, in WebCore after
passing through platform code), care must be taken to determine the final rendered size and
location before render time. This patch brings these classes up to the latest and greatest in the
subpixellayout branch.

See https://trac.webkit.org/wiki/LayoutUnit for more information.

No new tests. No change in behavior.

* rendering/RenderFrameBase.cpp:
(WebCore::RenderFrameBase::layoutWithFlattening): Build Fix.
* rendering/RenderFullScreen.cpp:
(RenderFullScreen::createPlaceholder): Ditto.
* rendering/RenderFullScreen.h:
(RenderFullScreen): Ditto.
* rendering/RenderHTMLCanvas.cpp:
(WebCore::RenderHTMLCanvas::canvasSizeChanged): Ditto.
* rendering/RenderIFrame.cpp:
(WebCore::RenderIFrame::computeLogicalHeight): Ditto.
(WebCore::RenderIFrame::computeLogicalWidth): Ditto.
* rendering/RenderImage.cpp:
(WebCore::RenderImage::updateIntrinsicSizeIfNeeded): Intrinsic sizes are always integers, since they
originate outside of WebCore.
(WebCore::RenderImage::paintIntoRect): Use pixel snapping to paint into an arbitrary rect.
(WebCore::RenderImage::computeReplacedLogicalWidth): Intrinsic size is always integral -- rounding
values to integers.
* rendering/RenderImage.h:
(RenderImage):
* rendering/RenderVideo.cpp:
(WebCore::RenderVideo::videoBox):
(WebCore::RenderVideo::paintReplaced): Painting at integer boundaries.
* rendering/RenderWidget.cpp:
(WebCore):
(WebCore::roundedIntRect): Widgets are rendered outside of WebCore, so we always align them to
integer boundaries. This means we can actually round the size of our ultimate content box. This
function is implemented here specifically to prevent its misuse if we put it elsewhere.
(WebCore::RenderWidget::setWidgetGeometry): We simplify layout by taking a LayoutRect and rounding
it to its final location within this function.
(WebCore::RenderWidget::updateWidgetGeometry): We keep things in LayoutUnits until handing off to
setWidgetGeometry.
(WebCore::RenderWidget::paint): Rounding the paint location before handing painting off to the
widget itself.
* rendering/RenderWidget.h:
(RenderWidget):

2012-03-21 Ilya Tikhonovsky <loislo@chromium.org>

Web Inspector: HeapProfiler: support distance column in Summary View.
@@ -78,9 +78,9 @@ void RenderFrameBase::layoutWithFlattening(bool fixedWidth, bool fixedHeight)

// expand the frame by setting frame height = content height
if (isScrollable || !fixedHeight || childRoot->isFrameSet())
setHeight(max(height(), childFrameView->contentsHeight() + vBorder));
setHeight(max<LayoutUnit>(height(), childFrameView->contentsHeight() + vBorder));
if (isScrollable || !fixedWidth || childRoot->isFrameSet())
setWidth(max(width(), childFrameView->contentsWidth() + hBorder));
setWidth(max<LayoutUnit>(width(), childFrameView->contentsWidth() + hBorder));

updateWidgetPosition();

@@ -140,7 +140,7 @@ void RenderFullScreen::setPlaceholder(RenderBlock* placeholder)
m_placeholder = placeholder;
}

void RenderFullScreen::createPlaceholder(PassRefPtr<RenderStyle> style, const IntRect& frameRect)
void RenderFullScreen::createPlaceholder(PassRefPtr<RenderStyle> style, const LayoutRect& frameRect)
{
if (style->width().isAuto())
style->setWidth(Length(frameRect.width(), Fixed));
@@ -39,7 +39,7 @@ class RenderFullScreen : public RenderDeprecatedFlexibleBox {

void setPlaceholder(RenderBlock*);
RenderBlock* placeholder() { return m_placeholder; }
void createPlaceholder(PassRefPtr<RenderStyle>, const IntRect& frameRect);
void createPlaceholder(PassRefPtr<RenderStyle>, const LayoutRect& frameRect);


static RenderObject* wrapRenderer(RenderObject* renderer, Document*);
@@ -88,7 +88,7 @@ void RenderHTMLCanvas::canvasSizeChanged()
if (!preferredLogicalWidthsDirty())
setPreferredLogicalWidthsDirty(true);

IntSize oldSize = size();
LayoutSize oldSize = size();
computeLogicalWidth();
computeLogicalHeight();
if (oldSize == size())
@@ -57,7 +57,7 @@ void RenderIFrame::computeLogicalHeight()
if (!view)
return;
int border = borderTop() + borderBottom();
setHeight(max(height(), view->contentsHeight() + border));
setHeight(max<LayoutUnit>(height(), view->contentsHeight() + border));
}
}

@@ -75,7 +75,7 @@ void RenderIFrame::computeLogicalWidth()
if (!view)
return;
LayoutUnit border = borderLeft() + borderRight();
setWidth(max(width(), view->contentsWidth() + border));
setWidth(max<LayoutUnit>(width(), view->contentsWidth() + border));
}
}

@@ -175,7 +175,7 @@ void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
imageDimensionsChanged(imageSizeChanged, rect);
}

bool RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize, bool imageSizeChanged)
bool RenderImage::updateIntrinsicSizeIfNeeded(const IntSize& newSize, bool imageSizeChanged)
{
if (newSize == intrinsicSize() && !imageSizeChanged)
return false;
@@ -416,18 +416,19 @@ void RenderImage::areaElementFocusChanged(HTMLAreaElement* element)

void RenderImage::paintIntoRect(GraphicsContext* context, const LayoutRect& rect)
{
if (!m_imageResource->hasImage() || m_imageResource->errorOccurred() || rect.width() <= 0 || rect.height() <= 0)
IntRect alignedRect = pixelSnappedIntRect(rect);
if (!m_imageResource->hasImage() || m_imageResource->errorOccurred() || alignedRect.width() <= 0 || alignedRect.height() <= 0)
return;

RefPtr<Image> img = m_imageResource->image(rect.width(), rect.height());
RefPtr<Image> img = m_imageResource->image(alignedRect.width(), alignedRect.height());
if (!img || img->isNull())
return;

HTMLImageElement* imageElt = (node() && node()->hasTagName(imgTag)) ? static_cast<HTMLImageElement*>(node()) : 0;
CompositeOperator compositeOperator = imageElt ? imageElt->compositeOperator() : CompositeSourceOver;
Image* image = m_imageResource->image().get();
bool useLowQualityScaling = shouldPaintAtLowQuality(context, image, image, rect.size());
context->drawImage(m_imageResource->image(rect.width(), rect.height()).get(), style()->colorSpace(), rect, compositeOperator, useLowQualityScaling);
bool useLowQualityScaling = shouldPaintAtLowQuality(context, image, image, alignedRect.size());
context->drawImage(m_imageResource->image(alignedRect.width(), alignedRect.height()).get(), style()->colorSpace(), alignedRect, compositeOperator, useLowQualityScaling);
}

bool RenderImage::backgroundIsObscured() const
@@ -525,8 +526,8 @@ LayoutUnit RenderImage::computeReplacedLogicalWidth(bool includeMaxWidth) const
if (cachedImage && cachedImage->image()) {
containerSize = cachedImage->image()->size();
// FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/63656
containerSize.setWidth(static_cast<LayoutUnit>(containerSize.width() * style()->effectiveZoom()));
containerSize.setHeight(static_cast<LayoutUnit>(containerSize.height() * style()->effectiveZoom()));
containerSize.setWidth(roundToInt(containerSize.width() * style()->effectiveZoom()));
containerSize.setHeight(roundToInt(containerSize.height() * style()->effectiveZoom()));
}
}

@@ -94,7 +94,7 @@ class RenderImage : public RenderReplaced {

IntSize imageSizeForError(CachedImage*) const;
void imageDimensionsChanged(bool imageSizeChanged, const IntRect* = 0);
bool updateIntrinsicSizeIfNeeded(const LayoutSize&, bool imageSizeChanged);
bool updateIntrinsicSizeIfNeeded(const IntSize&, bool imageSizeChanged);

void paintAreaElementFocusRing(PaintInfo&);

@@ -166,7 +166,7 @@ IntRect RenderVideo::videoBox() const
else
elementSize = intrinsicSize();

IntRect contentRect = contentBoxRect();
IntRect contentRect = pixelSnappedIntRect(contentBoxRect());
if (elementSize.isEmpty() || contentRect.isEmpty())
return IntRect();

@@ -225,9 +225,9 @@ void RenderVideo::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
if (displayingPoster)
paintIntoRect(paintInfo.context, rect);
else if (document()->view() && document()->view()->paintBehavior() & PaintBehaviorFlattenCompositingLayers)
mediaPlayer->paintCurrentFrameInContext(paintInfo.context, rect);
mediaPlayer->paintCurrentFrameInContext(paintInfo.context, pixelSnappedIntRect(rect));
else
mediaPlayer->paint(paintInfo.context, rect);
mediaPlayer->paint(paintInfo.context, pixelSnappedIntRect(rect));
}

void RenderVideo::layout()
@@ -140,12 +140,20 @@ RenderWidget::~RenderWidget()
clearWidget();
}

bool RenderWidget::setWidgetGeometry(const IntRect& frame)
// Widgets are always placed on integer boundaries, so rounding the size is actually
// the desired behavior. This function is here because it's otherwise seldom what we
// want to do with a LayoutRect.
static inline IntRect roundedIntRect(const LayoutRect& rect)
{
return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()));
}

bool RenderWidget::setWidgetGeometry(const LayoutRect& frame)
{
if (!node())
return false;

IntRect clipRect = enclosingLayer()->childrenClipRect();
IntRect clipRect = roundedIntRect(enclosingLayer()->childrenClipRect());
bool clipChanged = m_clipRect != clipRect;
bool boundsChanged = m_widget->frameRect() != frame;

@@ -156,7 +164,7 @@ bool RenderWidget::setWidgetGeometry(const IntRect& frame)

RenderWidgetProtector protector(this);
RefPtr<Node> protectedNode(node());
m_widget->setFrameRect(frame);
m_widget->setFrameRect(roundedIntRect(frame));

#if USE(ACCELERATED_COMPOSITING)
if (hasLayer() && layer()->isComposited())
@@ -168,11 +176,11 @@ bool RenderWidget::setWidgetGeometry(const IntRect& frame)

bool RenderWidget::updateWidgetGeometry()
{
IntRect contentBox = contentBoxRect();
LayoutRect contentBox = contentBoxRect();
if (!m_widget->transformsAffectFrameRect())
return setWidgetGeometry(absoluteContentBox());

IntRect absoluteContentBox = IntRect(localToAbsoluteQuad(FloatQuad(contentBox)).boundingBox());
LayoutRect absoluteContentBox(localToAbsoluteQuad(FloatQuad(contentBox)).boundingBox());
if (m_widget->isFrameView()) {
contentBox.setLocation(absoluteContentBox.location());
return setWidgetGeometry(contentBox);
@@ -276,11 +284,12 @@ void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
if (m_widget) {
// Tell the widget to paint now. This is the only time the widget is allowed
// to paint itself. That way it will composite properly with z-indexed layers.
LayoutPoint widgetLocation = m_widget->frameRect().location();
LayoutPoint paintLocation(adjustedPaintOffset.x() + borderLeft() + paddingLeft(), adjustedPaintOffset.y() + borderTop() + paddingTop());
LayoutRect paintRect = paintInfo.rect;
IntPoint widgetLocation = m_widget->frameRect().location();
IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + borderLeft() + paddingLeft()),
roundToInt(adjustedPaintOffset.y() + borderTop() + paddingTop()));
IntRect paintRect = paintInfo.rect;

LayoutSize widgetPaintOffset = paintLocation - widgetLocation;
IntSize widgetPaintOffset = paintLocation - widgetLocation;
// When painting widgets into compositing layers, tx and ty are relative to the enclosing compositing layer,
// not the root. In this case, shift the CTM and adjust the paintRect to be root-relative to fix plug-in drawing.
if (!widgetPaintOffset.isZero()) {
@@ -70,7 +70,7 @@ class RenderWidget : public RenderReplaced, private OverlapTestRequestClient {
virtual void setSelectionState(SelectionState);
virtual void setOverlapTestResult(bool);

bool setWidgetGeometry(const IntRect&);
bool setWidgetGeometry(const LayoutRect&);
bool updateWidgetGeometry();

RefPtr<Widget> m_widget;

0 comments on commit 1f11b56

Please sign in to comment.