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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp

Issue 1756763004: Merge image sizing algorithms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unused variable 'styleImage' in release Created 4 years, 9 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 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2010 Google Inc. All rights reserved. 7 * Copyright (C) 2010 Google Inc. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } 683 }
684 684
685 LayoutUnit LayoutBoxModelObject::computedCSSPadding(const Length& padding) const 685 LayoutUnit LayoutBoxModelObject::computedCSSPadding(const Length& padding) const
686 { 686 {
687 LayoutUnit w; 687 LayoutUnit w;
688 if (padding.hasPercent()) 688 if (padding.hasPercent())
689 w = containingBlockLogicalWidthForContent(); 689 w = containingBlockLogicalWidthForContent();
690 return minimumValueForLength(padding, w); 690 return minimumValueForLength(padding, w);
691 } 691 }
692 692
693 static inline LayoutUnit resolveWidthForRatio(LayoutUnit height, const FloatSize & intrinsicRatio)
694 {
695 return LayoutUnit(height * intrinsicRatio.width() / intrinsicRatio.height()) ;
696 }
697
698 static inline LayoutUnit resolveHeightForRatio(LayoutUnit width, const FloatSize & intrinsicRatio)
699 {
700 return LayoutUnit(width * intrinsicRatio.height() / intrinsicRatio.width());
701 }
702
703 static inline LayoutSize resolveAgainstIntrinsicWidthOrHeightAndRatio(const Layo utSize& size, const FloatSize& intrinsicRatio, LayoutUnit useWidth, LayoutUnit u seHeight)
704 {
705 if (intrinsicRatio.isEmpty()) {
706 if (useWidth)
707 return LayoutSize(useWidth, size.height());
708 return LayoutSize(size.width(), useHeight);
709 }
710
711 if (useWidth)
712 return LayoutSize(useWidth, resolveHeightForRatio(useWidth, intrinsicRat io));
713 return LayoutSize(resolveWidthForRatio(useHeight, intrinsicRatio), useHeight );
714 }
715
716 static inline LayoutSize resolveAgainstIntrinsicRatio(const LayoutSize& size, co nst FloatSize& intrinsicRatio)
717 {
718 // Two possible solutions: (size.width(), solutionHeight) or (solutionWidth, size.height())
719 // "... must be assumed to be the largest dimensions..." = easiest answer: t he rect with the largest surface area.
720
721 LayoutUnit solutionWidth = resolveWidthForRatio(size.height(), intrinsicRati o);
722 LayoutUnit solutionHeight = resolveHeightForRatio(size.width(), intrinsicRat io);
723 if (solutionWidth <= size.width()) {
724 if (solutionHeight <= size.height()) {
725 // If both solutions fit, choose the one covering the larger area.
726 LayoutUnit areaOne = solutionWidth * size.height();
727 LayoutUnit areaTwo = size.width() * solutionHeight;
728 if (areaOne < areaTwo)
729 return LayoutSize(size.width(), solutionHeight);
730 return LayoutSize(solutionWidth, size.height());
731 }
732
733 // Only the first solution fits.
734 return LayoutSize(solutionWidth, size.height());
735 }
736
737 // Only the second solution fits, assert that.
738 ASSERT(solutionHeight <= size.height());
739 return LayoutSize(size.width(), solutionHeight);
740 }
741
742 LayoutSize LayoutBoxModelObject::calculateImageIntrinsicDimensions(StyleImage* i mage, const LayoutSize& positioningAreaSize, ScaleByEffectiveZoomOrNot shouldSca leOrNot) const
743 {
744 // A generated image without a fixed size, will always return the container size as intrinsic size.
745 if (image->isGeneratedImage() && image->usesImageContainerSize())
746 return positioningAreaSize;
747
748 FloatSize intrinsicSize;
749 FloatSize intrinsicRatio;
750 image->computeIntrinsicDimensions(this, intrinsicSize, intrinsicRatio);
751
752 LayoutSize resolvedSize(intrinsicSize);
753 LayoutSize minimumSize(resolvedSize.width() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit(),
754 resolvedSize.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit());
755 if (shouldScaleOrNot == ScaleByEffectiveZoom)
756 resolvedSize.scale(style()->effectiveZoom());
757 resolvedSize.clampToMinimumSize(minimumSize);
758
759 if (!resolvedSize.isEmpty())
760 return resolvedSize;
761
762 // If the image has one of either an intrinsic width or an intrinsic height:
763 // * and an intrinsic aspect ratio, then the missing dimension is calculated from the given dimension and the ratio.
764 // * and no intrinsic aspect ratio, then the missing dimension is assumed to be the size of the rectangle that
765 // establishes the coordinate system for the 'background-position' propert y.
766 if (resolvedSize.width() > LayoutUnit() || resolvedSize.height() > LayoutUni t())
767 return resolveAgainstIntrinsicWidthOrHeightAndRatio(positioningAreaSize, intrinsicRatio, resolvedSize.width(), resolvedSize.height());
768
769 // If the image has no intrinsic dimensions and has an intrinsic ratio the d imensions must be assumed to be the
770 // largest dimensions at that ratio such that neither dimension exceeds the dimensions of the rectangle that
771 // establishes the coordinate system for the 'background-position' property.
772 if (!intrinsicRatio.isEmpty())
773 return resolveAgainstIntrinsicRatio(positioningAreaSize, intrinsicRatio) ;
774
775 // If the image has no intrinsic ratio either, then the dimensions must be a ssumed to be the rectangle that
776 // establishes the coordinate system for the 'background-position' property.
777 return positioningAreaSize;
778 }
779
780 bool LayoutBoxModelObject::boxShadowShouldBeAppliedToBackground(BackgroundBleedA voidance bleedAvoidance, const InlineFlowBox* inlineFlowBox) const 693 bool LayoutBoxModelObject::boxShadowShouldBeAppliedToBackground(BackgroundBleedA voidance bleedAvoidance, const InlineFlowBox* inlineFlowBox) const
781 { 694 {
782 if (bleedAvoidance != BackgroundBleedNone) 695 if (bleedAvoidance != BackgroundBleedNone)
783 return false; 696 return false;
784 697
785 if (style()->hasAppearance()) 698 if (style()->hasAppearance())
786 return false; 699 return false;
787 700
788 const ShadowList* shadowList = style()->boxShadow(); 701 const ShadowList* shadowList = style()->boxShadow();
789 if (!shadowList) 702 if (!shadowList)
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 if (rootElementStyle->hasBackground()) 960 if (rootElementStyle->hasBackground())
1048 return false; 961 return false;
1049 962
1050 if (node() != document().firstBodyElement()) 963 if (node() != document().firstBodyElement())
1051 return false; 964 return false;
1052 965
1053 return true; 966 return true;
1054 } 967 }
1055 968
1056 } // namespace blink 969 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698