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

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

Issue 22839023: Add support for the object-position CSS property. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 314 LayoutRect RenderReplaced::replacedContentRect(const LayoutSize* overriddenIntri nsicSize) const
315 { 315 {
316 LayoutRect contentRect = contentBoxRect(); 316 LayoutRect contentRect = contentBoxRect();
317 ObjectFit objectFit = style()->objectFit(); 317 ObjectFit objectFit = style()->objectFit();
318 if (objectFit == ObjectFitFill) 318 if (objectFit == ObjectFitFill && style()->objectPosition() == RenderStyle:: initialObjectPosition())
319 return contentRect; 319 return contentRect;
320 320
321 LayoutSize intrinsicSize = overriddenIntrinsicSize ? *overriddenIntrinsicSiz e : this->intrinsicSize(); 321 LayoutSize intrinsicSize = overriddenIntrinsicSize ? *overriddenIntrinsicSiz e : this->intrinsicSize();
322 if (!intrinsicSize.width() || !intrinsicSize.height()) 322 if (!intrinsicSize.width() || !intrinsicSize.height())
323 return contentRect; 323 return contentRect;
324 324
325 LayoutRect finalRect = contentRect; 325 LayoutRect finalRect = contentRect;
326 switch (objectFit) { 326 switch (objectFit) {
327 case ObjectFitContain: 327 case ObjectFitContain:
328 case ObjectFitScaleDown: 328 case ObjectFitScaleDown:
329 case ObjectFitCover: 329 case ObjectFitCover:
330 finalRect.setSize(finalRect.size().fitToAspectRatio(intrinsicSize, objec tFit == ObjectFitCover ? AspectRatioFitGrow : AspectRatioFitShrink)); 330 finalRect.setSize(finalRect.size().fitToAspectRatio(intrinsicSize, objec tFit == ObjectFitCover ? AspectRatioFitGrow : AspectRatioFitShrink));
331 if (objectFit != ObjectFitScaleDown || finalRect.width() <= intrinsicSiz e.width()) 331 if (objectFit != ObjectFitScaleDown || finalRect.width() <= intrinsicSiz e.width())
332 break; 332 break;
333 // fall through 333 // fall through
334 case ObjectFitNone: 334 case ObjectFitNone:
335 finalRect.setSize(intrinsicSize); 335 finalRect.setSize(intrinsicSize);
336 break; 336 break;
337 case ObjectFitFill: 337 case ObjectFitFill:
338 break;
339 default:
338 ASSERT_NOT_REACHED(); 340 ASSERT_NOT_REACHED();
339 } 341 }
340 342
341 // FIXME: This is where object-position should be taken into account, but si nce it's not 343 LayoutUnit xOffset = minimumValueForLength(style()->objectPosition().x(), co ntentRect.width() - finalRect.width(), view());
342 // implemented yet, assume the initial value of "50% 50%". 344 LayoutUnit yOffset = minimumValueForLength(style()->objectPosition().y(), co ntentRect.height() - finalRect.height(), view());
343 LayoutUnit xOffset = (contentRect.width() - finalRect.width()) / 2;
344 LayoutUnit yOffset = (contentRect.height() - finalRect.height()) / 2;
345 finalRect.move(xOffset, yOffset); 345 finalRect.move(xOffset, yOffset);
346 346
347 return finalRect; 347 return finalRect;
348 } 348 }
349 349
350 void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const 350 void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const
351 { 351 {
352 // 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.
353 ASSERT(!embeddedContentBox()); 353 ASSERT(!embeddedContentBox());
354 isPercentageIntrinsicSize = false; 354 isPercentageIntrinsicSize = false;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 610
611 if (style()) { 611 if (style()) {
612 if (v) 612 if (v)
613 r.inflate(style()->outlineSize()); 613 r.inflate(style()->outlineSize());
614 } 614 }
615 computeRectForRepaint(repaintContainer, r); 615 computeRectForRepaint(repaintContainer, r);
616 return r; 616 return r;
617 } 617 }
618 618
619 } 619 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698