Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1637)

Unified Diff: Source/core/rendering/RenderVideo.cpp

Issue 22482004: Add support for the object-fit CSS property. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Oops, sorry! Forgot to update UseCounter.cpp Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/rendering/RenderVideo.cpp
diff --git a/Source/core/rendering/RenderVideo.cpp b/Source/core/rendering/RenderVideo.cpp
index 580bbf302796b864e0e5642b9d9f041d24372456..ace52f641b48adee7a90bef7aeaf73aacad07285 100644
--- a/Source/core/rendering/RenderVideo.cpp
+++ b/Source/core/rendering/RenderVideo.cpp
@@ -140,35 +140,11 @@ void RenderVideo::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
IntRect RenderVideo::videoBox() const
{
- if (m_cachedImageSize.isEmpty() && videoElement()->shouldDisplayPosterImage())
- return IntRect();
-
- LayoutSize elementSize;
+ const LayoutSize* overriddenIntrinsicSize = 0;
if (videoElement()->shouldDisplayPosterImage())
- elementSize = m_cachedImageSize;
- else
- elementSize = intrinsicSize();
-
- IntRect contentRect = pixelSnappedIntRect(contentBoxRect());
- if (elementSize.isEmpty() || contentRect.isEmpty())
- return IntRect();
-
- LayoutRect renderBox = contentRect;
- LayoutUnit ratio = renderBox.width() * elementSize.height() - renderBox.height() * elementSize.width();
- if (ratio > 0) {
- LayoutUnit newWidth = renderBox.height() * elementSize.width() / elementSize.height();
- // Just fill the whole area if the difference is one pixel or less (in both sides)
- if (renderBox.width() - newWidth > 2)
- renderBox.setWidth(newWidth);
- renderBox.move((contentRect.width() - renderBox.width()) / 2, 0);
- } else if (ratio < 0) {
- LayoutUnit newHeight = renderBox.width() * elementSize.height() / elementSize.width();
- if (renderBox.height() - newHeight > 2)
- renderBox.setHeight(newHeight);
- renderBox.move(0, (contentRect.height() - renderBox.height()) / 2);
- }
+ overriddenIntrinsicSize = &m_cachedImageSize;
- return pixelSnappedIntRect(renderBox);
+ return pixelSnappedIntRect(replacedContentRect(overriddenIntrinsicSize));
}
bool RenderVideo::shouldDisplayVideo() const
@@ -202,12 +178,24 @@ void RenderVideo::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
if (page && paintInfo.phase == PaintPhaseForeground)
page->addRelevantRepaintedObject(this, rect);
+ LayoutRect contentRect = contentBoxRect();
+ contentRect.moveBy(paintOffset);
+ GraphicsContext* context = paintInfo.context;
+ bool clip = !contentRect.contains(rect);
+ if (clip) {
+ context->save();
+ context->clip(contentRect);
+ }
+
if (displayingPoster)
- paintIntoRect(paintInfo.context, rect);
+ paintIntoRect(context, rect);
else if (document()->view() && document()->view()->paintBehavior() & PaintBehaviorFlattenCompositingLayers)
- mediaPlayer->paintCurrentFrameInContext(paintInfo.context, pixelSnappedIntRect(rect));
+ mediaPlayer->paintCurrentFrameInContext(context, pixelSnappedIntRect(rect));
else
- mediaPlayer->paint(paintInfo.context, pixelSnappedIntRect(rect));
+ mediaPlayer->paint(context, pixelSnappedIntRect(rect));
+
+ if (clip)
+ context->restore();
}
void RenderVideo::layout()

Powered by Google App Engine
This is Rietveld 408576698