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

Side by Side Diff: Source/core/rendering/RenderReplaced.cpp

Issue 22482004: Add support for the object-fit CSS property. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Code review 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2000 Dirk Mueller (mueller@kde.org) 3 * Copyright (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
5 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. 5 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // function was added, since all it has done is make the code more unclear. 304 // function was added, since all it has done is make the code more unclear.
305 constrainedSize = intrinsicSize; 305 constrainedSize = intrinsicSize;
306 if (intrinsicRatio && !isPercentageIntrinsicSize && !intrinsicSize.isEmpty() && style()->logicalWidth().isAuto() && style()->logicalHeight().isAuto()) { 306 if (intrinsicRatio && !isPercentageIntrinsicSize && !intrinsicSize.isEmpty() && style()->logicalWidth().isAuto() && style()->logicalHeight().isAuto()) {
307 // We can't multiply or divide by 'intrinsicRatio' here, it breaks tests , like fast/images/zoomed-img-size.html, which 307 // We can't multiply or divide by 'intrinsicRatio' here, it breaks tests , like fast/images/zoomed-img-size.html, which
308 // can only be fixed once subpixel precision is available for things lik e intrinsicWidth/Height - which include zoom! 308 // can only be fixed once subpixel precision is available for things lik e intrinsicWidth/Height - which include zoom!
309 constrainedSize.setWidth(RenderBox::computeReplacedLogicalHeight() * int rinsicSize.width() / intrinsicSize.height()); 309 constrainedSize.setWidth(RenderBox::computeReplacedLogicalHeight() * int rinsicSize.width() / intrinsicSize.height());
310 constrainedSize.setHeight(RenderBox::computeReplacedLogicalWidth() * int rinsicSize.height() / intrinsicSize.width()); 310 constrainedSize.setHeight(RenderBox::computeReplacedLogicalWidth() * int rinsicSize.height() / intrinsicSize.width());
311 } 311 }
312 } 312 }
313 313
314 LayoutRect RenderReplaced::replacedContentRect(const LayoutSize* overriddenIntri nsicSize) const
ojan 2013/08/09 23:27:26 I don't think we typically use pointers to LayoutS
mstensho (USE GERRIT) 2013/08/12 13:39:11 But it's an optional parameter, currently only spe
ojan 2013/08/12 17:25:57 Ah right. Nevermind. What you have here is fine.
315 {
316 LayoutRect contentRect = contentBoxRect();
317 EObjectFit objectFit = style()->objectFit();
318 if (objectFit == ObjectFitFill)
319 return contentRect;
320
321 LayoutSize intrinsicSize = overriddenIntrinsicSize ? *overriddenIntrinsicSiz e : this->intrinsicSize();
322 if (!intrinsicSize.width() || !intrinsicSize.height())
323 return contentRect;
324
325 LayoutRect finalRect = contentRect;
326 switch (objectFit) {
327 case ObjectFitContain:
328 case ObjectFitScaleDown:
329 case ObjectFitCover:
330 finalRect.setSize(finalRect.size().fitToAspectRatio(intrinsicSize, objec tFit == ObjectFitCover ? AspectRatioFitGrow : AspectRatioFitShrink));
331 if (objectFit != ObjectFitScaleDown || finalRect.width() <= intrinsicSiz e.width())
332 break;
333 // fall through
334 case ObjectFitNone:
335 finalRect.setSize(intrinsicSize);
336 break;
337 case ObjectFitFill:
338 ASSERT_NOT_REACHED();
339 }
340
341 // This is where object-position should be taken into account, but since it' s not implemented
ojan 2013/08/09 23:27:26 This should be: // FIXME: This is where...
mstensho (USE GERRIT) 2013/08/12 13:39:11 Done.
342 // yet, assume the initial value of "50% 50%".
343 LayoutUnit xOffset = (contentRect.width() - finalRect.width()) / 2;
344 LayoutUnit yOffset = (contentRect.height() - finalRect.height()) / 2;
345 finalRect.move(xOffset, yOffset);
346
347 return finalRect;
348 }
349
314 void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const 350 void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const
315 { 351 {
316 // If there's an embeddedContentBox() of a remote, referenced document avail able, this code-path should never be used. 352 // If there's an embeddedContentBox() of a remote, referenced document avail able, this code-path should never be used.
317 ASSERT(!embeddedContentBox()); 353 ASSERT(!embeddedContentBox());
318 isPercentageIntrinsicSize = false; 354 isPercentageIntrinsicSize = false;
319 intrinsicSize = FloatSize(intrinsicLogicalWidth(), intrinsicLogicalHeight()) ; 355 intrinsicSize = FloatSize(intrinsicLogicalWidth(), intrinsicLogicalHeight()) ;
320 356
321 // Figure out if we need to compute an intrinsic ratio. 357 // Figure out if we need to compute an intrinsic ratio.
322 if (intrinsicSize.isEmpty() || !rendererHasAspectRatio(this)) 358 if (intrinsicSize.isEmpty() || !rendererHasAspectRatio(this))
323 return; 359 return;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 610
575 if (style()) { 611 if (style()) {
576 if (v) 612 if (v)
577 r.inflate(style()->outlineSize()); 613 r.inflate(style()->outlineSize());
578 } 614 }
579 computeRectForRepaint(repaintContainer, r); 615 computeRectForRepaint(repaintContainer, r);
580 return r; 616 return r;
581 } 617 }
582 618
583 } 619 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698